0 Star 2 Fork 1

Cadaqs/XStudio

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
XSourceEditor.xcsm 159.05 KB
一键复制 编辑 原始数据 按行查看 历史
Cadaqs 提交于 2021-07-13 17:34 . 10751
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806
class XSourceEditor : DocumentView {
public QScintilla _sci;
static const int
MARK_BREAKPOINT = 9,
MARK_POINTER = 8,
MARK_MODIFIED = 12,
MARK_SAVED = 13,
ERRORPOINT_INDEX = 14,
WARNING_INDEX = 15;
QComboBox domaincmb = new QComboBox(), objectscmb = new QComboBox();
bool intellisense_modified = false;
QTreeWidget autoWnd;
QTreeWidget debugWnd;
CodeTips __tipsWnd = XStudioApp._theApp.__tipsWnd;
Map<String, long> watchs = new Map<String, long>();
bool bClosed = false;
XIntelliSense.XIntelliResult[] current_autocmp;
bool autoCompShow, debugWndShow;
long auto_position, last_autopos;
XWorkspace _mdi_area;
bool sciisHand = false;
int lastCursor = 0;
String strpretext;
int current_modify_mark, reserve_modify_mark;
QMenu contextMenu = new QMenu();
static QAction [] editor_actions = nilptr;
Map<String, long> autoCompMap = new Map<String, long>();
DebugValueParser __dvp = new DebugValueParser("debug");
static QScintilla.QSciPrinter g_printer;
QLabel statbar;
static const int INDIC_TIPS = 1, INDIC_ERROR = 2, INDIC_WARNING = 5;
static const int INDIC_FIND = 3, INDIC_SELECTED = 4;
XIntelliSense.XIntelliResult []lastxis;
public String defaultCharset = nilptr;
String loadAsCharset = nilptr;
onOverviewListener disableOverview = nilptr;
bool bCmbInit = false;
enum ReadResp{
NO_READONLY = 0,
NO_CHARSET = 1
};
public static class onOverviewListener{
public bool isOverviewEnabled(){
return false;
}
public String preprocessKeyword(String keyword){
return keyword;
}
};
ReadResp readonlyResp = ReadResp.NO_READONLY;
public void setOverviewListener(onOverviewListener bd){
disableOverview = bd;
}
public XSourceEditor(XWorkspace _mdi) {
_mdi_area = _mdi;
}
static String [] codepages = {
"Unicode / UTF-8",
"Unicode / UTF-16BE",
"Unicode / UTF-16LE",
"Unicode / UTF-32BE",
"Unicode / UTF-32LE",
"Unicode / X-ISO-10646-UCS-4-34121",
"Unicode / X-ISO-10646-UCS-4-21431",
"(阿拉伯语)Arabic / ISO-8859-6",
"(阿拉伯语)Arabic / WINDOWS-1256",
"(保加利亚)Bulgarian / ISO-8859-5",
"(保加利亚)Bulgarian / WINDOWS-1251",
"(中文)Chinese / ISO-2022-CN",
"(中文繁体)Chinese / BIG5",
"(中文台湾)Chinese / EUC-TW",
"(中文简体)Chinese / GB18030",
"(中文)Chinese / HZ-GB-2312",
"(丹麦)Danish / ISO-8859-1",
"(丹麦)Danish / ISO-8859-15",
"(丹麦)Danish / WINDOWS-1252",
"(英语)English / ASCII",
"(世界语)Esperanto / ISO-8859-3",
"(法语)French / ISO-8859-1",
"(法语)French / ISO-8859-15",
"(法语)French / WINDOWS-1252",
"(德语)German / ISO-8859-1",
"(德语)German / WINDOWS-1252",
"(希腊语)Greek / ISO-8859-7",
"(希腊语)Greek / WINDOWS-1253",
"(希伯来语)Hebrew / ISO-8859-8",
"(希伯来语)Hebrew / WINDOWS-1255",
"(匈牙利语)Hungarian / ISO-8859-2",
"(匈牙利语)Hungarian / WINDOWS-1250",
"(日语)Japanese / ISO-2022-JP",
"(日语)Japanese / SHIFT_JIS",
"(日语)Japanese / EUC-JP",
"(韩语)Korean / ISO-2022-KR",
"(韩语)Korean / EUC-KR",
"(俄语)Russian / ISO-8859-5",
"(俄语)Russian / KOI8-R",
"(俄语)Russian / WINDOWS-1251",
"(俄语)Russian / MAC-CYRILLIC",
"(俄语)Russian / IBM866",
"(俄语)Russian / IBM855",
"(西班牙语)Spanish / ISO-8859-1",
"(西班牙语)Spanish / ISO-8859-15",
"(西班牙语)Spanish / WINDOWS-1252",
"(泰语)Thai / TIS-620",
"(泰语)Thai / ISO-8859-11",
"(土耳其)Turkish / ISO-8859-3",
"(土耳其)Turkish / ISO-8859-9",
"(越南)Vietnamese / VISCII",
"(越南)Vietnamese / Windows-1258",
"其他 / WINDOWS-1252"
};
static String []cpid = {"UTF-8", "UTF-16BE", "UTF-16LE", "UTF-32BE", "UTF-32LE", "X-ISO-10646-UCS-4-34121", "X-ISO-10646-UCS-4-21431", "ISO-8859-6",
"WINDOWS-1256","ISO-8859-5","WINDOWS-1251","ISO-2022-CN","BIG5","EUC-TW","GB18030","HZ-GB-2312","ISO-8859-1","ISO-8859-15","WINDOWS-1252",
"ASCII","ISO-8859-3","ISO-8859-1","ISO-8859-15","WINDOWS-1252","ISO-8859-1","WINDOWS-1252","ISO-8859-7","WINDOWS-1253","ISO-8859-8",
"WINDOWS-1255","ISO-8859-2","WINDOWS-1250","ISO-2022-JP","SHIFT_JIS","EUC-JP","ISO-2022-KR","EUC-KR","ISO-8859-5","KOI8-R","WINDOWS-1251",
"MAC-CYRILLIC","IBM866","IBM855","ISO-8859-1","ISO-8859-15","WINDOWS-1252","TIS-620","ISO-8859-11","ISO-8859-3","ISO-8859-9","VISCII",
"Windows-1258","WINDOWS-1252"};
String szKeywords1=
"break case catch char class " +
"const continue default do float double else final finally cdecl for " +
"if import interface stdcall fastcall pascal operator " +
"new package include using require synchronized_read synchronized_write " +
"return static super switch synchronized this throws throw " +
"try void while @Declare @NotNilptr public private protected override bool byte long char int long short String _system_ " +
"Thread nilptr Exception Vector Map List Iterator Timer TimerTask true false enum finalize" ;
String szKeywords2 = "";
static const int BREAKPOINT_INDEX = 0,
LINENUMBER_INDEX = 1,
DEBUGPOINT_INDEX = 2,
MODIFIMARK_INDEX = 3,
MARGIN_FOLD_INDEX = 4;
void setHighlightKeyWord(String keyword) {
_sci.sendEditor(QScintilla.SCI_SETKEYWORDS, 1, keyword);
_sci.update();
}
public TextEditorPlugin _textplugins;
public TextEditorController _controller = new TextEditorController() {
String getPath() {
return getFilePath();
}
String getTitle() {
return XSourceEditor.this.getTitle();
}
bool save() {
return saveFile();
}
void reload(String asCharset) {
reloadFile(asCharset);
}
void postreload(String asCharset) {
runOnUi(new Runnable() {
void run() {
reloadFile(asCharset);
}
});
}
void stopFileWatch() {
pauseWatch();
}
void continueFileWatch() {
continueWatch();
}
bool gotoLine(long line, long column) {
goto(line,column);
return true;
}
bool gotoPos(long pos) {
goto(pos);
return true;
}
bool select(long start, long end) {
_sci.setSelect(start,end);
return true;
}
bool gotoAndSelect(long start, long end) {
XSourceEditor.this.gotoAndSelect(start, end);
return true;
}
bool setBreakOn(long line, long column, bool set, bool bActive) {
breakOn(line, column, set, bActive, false);
return true;
}
bool activeEditor() {
XWorkspace.workspace.setActiveSubWindow(XSourceEditor.this);
return true;
}
void clearBreakOn() {
XSourceEditor.this.clearBreakOn();
}
bool toggleBreakpoint(long pos, bool bSet) {
int line = _sci.positionToLine(pos);
BreakPointWnd.toggleBreakPoint(XSourceEditor.this, getFilePath(), line, testMark(line, MARK_BREAKPOINT) == false);
return true;
}
bool toggleBreakpointAtLine(long line, bool bSet) {
BreakPointWnd.toggleBreakPoint(XSourceEditor.this, getFilePath(), line, testMark(line, MARK_BREAKPOINT) == false);
return true;
}
String getText(long start, long end) {
return _sci.getText(start,end);
}
String getText() {
return _sci.getText();
}
long getCurrentPosition() {
return _sci.getCurrentPosition();
}
long getCurrentLine() {
return _sci.getCurrentLine();
}
void triggeInteliSence(){
requestInteliSence();
}
};
public TextEditorController getController() {
return _controller;
}
public static String getEditingContent(@NotNilptr String file) {
DocumentView wnd = findDocumentWindow(nilptr, file, false);
if (wnd != nilptr) {
if (wnd.instanceOf(XSourceEditor)){
return ((XSourceEditor)wnd).getTextContent();
}
}
return nilptr;
}
public static bool openForFileInfo(@NotNilptr XWorkspace parent,@NotNilptr String source,int line, int column, String title, String Tips) {
DocumentView wnd = findDocumentWindow(parent, source, true);
if (wnd != nilptr) {
parent.setActiveSubWindow(wnd);
wnd.goto(line -1, column);
wnd.setFocus();
if (Tips != nilptr) {
wnd.showTips(line - 1, column, title,Tips);
}
return true;
}else
if (QMessageBox.Question("提示", "无法找到源代码文件:" + source + ",是否浏览文件?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No ) == QMessageBox.Yes) {
String filename = source.findFilenameAndExtension();
if (filename.length() == 0) {
filename = source;
}
String file = QFileDialog.getOpenFileName("打开文件:" + filename, source, getDocumentExtension(), XWorkspace.workspace);
if (file != nilptr && file.length() > 0) {
wnd = findDocumentWindow(XWorkspace.workspace, file, true);
if (wnd != nilptr) {
parent.setActiveSubWindow(wnd);
wnd.goto(line -1, column);
wnd.setFocus();
if (Tips != nilptr) {
wnd.showTips(line - 1, column, title, Tips);
}
return true;
}
}
}
return false;
}
public void setSelection(int pos, int len) {
_sci.gotoPos(pos);
_sci.sendEditor(QScintilla.SCI_SETSELECTIONSTART, pos);
_sci.sendEditor(QScintilla.SCI_SETSELECTIONEND, pos + len);
}
public static bool openForFile(@NotNilptr XWorkspace parent,@NotNilptr String sourcepath) {
DocumentView wnd = findDocumentWindow(parent, sourcepath, true);
if (wnd != nilptr) {
parent.setActiveSubWindow(wnd);
return true;
}
return false;
}
public static bool closeAllWindows() {
Map.Iterator<String, DocumentView> iterator = editorMgr.iterator();
while (iterator.hasNext()) {
DocumentView wnd = iterator.getValue();
if (wnd != nilptr && wnd.requestClose() == false) {
return false;
}
iterator.next();
}
return true;
}
public bool isTipsShow(){
return __tipsWnd.isVisible();
}
public void showTips(int line, int column,String title, String content) override{
int position = _sci.getPosition(line) + column;
QPoint qt = _sci.positionToPoint(position);
qt.y += /*domaincmb.height() +*/ _sci.getLineHeight();
qt = _sci.mapToGlobal(qt.x,qt.y);
qt = _mdi_area.mainWindow.mapFromGlobal(qt.x,qt.y);
__tipsWnd.showTips(getFilePath(), qt/*_sci.mapToGlobal(qt.x,qt.y)*/, title, content);
}
public void showTips(int position, String title, String content) override {
QPoint qt = _sci.positionToPoint(position);
qt.y += /*domaincmb.height() +*/ _sci.getLineHeight();
qt = _sci.mapToGlobal(qt.x,qt.y);
qt = _mdi_area.mainWindow.mapFromGlobal(qt.x,qt.y);
__tipsWnd.showTips(getFilePath(),qt/*_sci.mapToGlobal(qt.x,qt.y)*/, title, content);
}
public bool requestClose() override{
bool bclose = false;
_mdi_area.setActiveSubWindow(this);
if (_sci.isModified()) {
int rt = QMessageBox.Question("提示","文档[" + getTitle() + "]有未保存的更改, 是否在关闭前保存文件?", QMessageBox.Cancel | QMessageBox.No | QMessageBox.Save, QMessageBox.Save);
if (rt == QMessageBox.Save) {
saveFile();
bclose = true;
} else if (rt == QMessageBox.No) {
bclose = true;
}
} else {
bclose = true;
}
return bclose;
}
public void reload(){
reloadFile(loadAsCharset);
}
public void goto(int line, int column) {
_sci.goto(line, column);
setActive(true);
}
public void goto(int pos) {
_sci.gotoPos(pos);
setActive(true);
}
public void gotoAndSelect(int line, int column) {
int pos = _sci.sendEditor(QScintilla.SCI_POSITIONFROMLINE, line) + column - 1;
_sci.gotoPos(pos);
_sci.setSelect(pos, pos);
_sci.setFocus();
setActive(true);
}
public void breakOn(int line, int column, bool set, bool active, bool onlyActive) {
if (set) {
_sci.goto(line, 1);
if (onlyActive == false) {
_sci.sendEditor(QScintilla.SCI_MARKERADD, line, MARK_POINTER);
}
setActive(true);
if (active) {
_mdi_area.setActiveSubWindow(this);
}
} else if (onlyActive == false) {
_sci.sendEditor(QScintilla.SCI_MARKERDELETE, line, MARK_POINTER);
}
}
public void clearBreakOn() {
_sci.sendEditor( QScintilla.SCI_MARKERDELETEALL, MARK_POINTER);
}
public void findAgain() {
if (false == _sci.findNext()) {
StatusBarMgr.showStatusMessage("找不到指定文本.");
}
}
public void setIntellisense(XIntelliSense.XIntelliResult [] names) {
lastxis = names;
preProcessXIntellisense();
}
public void setFileSymbols(XIntelliSense.XIntelliResult [] names) {
Vector<String> domains = new Vector<String>();
Vector<String> objects = new Vector<String>();
Vector<XIntelliSense.XIntelliResult> domains_link = new Vector<XIntelliSense.XIntelliResult>();
Vector<XIntelliSense.XIntelliResult> objects_link = new Vector<XIntelliSense.XIntelliResult>();
for (int i = 0, c = names.length; i < c; i++){
XIntelliSense.XIntelliResult it = names[i];
String label = it.get_name();
int line = it.get_line(), row = it.get_row();
if (it.get_type() == 31 || it.get_type() == 28) {
domains.add(label);
domains_link.add(it);
}else
if (it.get_type() == 23){
String descr = "";
XIntelliSense.XIntelliResult classtype = it.get_class();
if (classtype != nilptr){
descr = descr + classtype.get_name() + " ";
}
descr = descr + label + "(";
XIntelliSense.XIntelliResult[] params = it.get_params();
if (params != nilptr){
for (int x = 0; x < params.length; x ++) {
XIntelliSense.XIntelliResult param = params[x];
if (param != nilptr){
XIntelliSense.XIntelliResult param_class = param.get_class();
if (param_class != nilptr){
descr = descr + param_class.get_name() + " " + param.get_name();
}else{
descr = descr + "? " + param.get_name();
}
if (x + 1 < params.length) {
descr = descr + ", ";
}
}
}
}
descr = descr + ")";
objects.add(descr);
objects_link.add(it);
}else
if (it.get_type() != 18){
objects.add(label);
objects_link.add(it);
}
}
runOnUi(new Runnable(){
void run() override{
if (bClosed) {
return ;
}
domaincmb.setTag(domains_link);
objectscmb.setTag(objects_link);
bCmbInit = true;
domaincmb.addItems(domains.toArray(new String[0]));
objectscmb.addItems(objects.toArray(new String[0]));
bCmbInit = false;
}
});
}
public void preProcessXIntellisense() {
XIntelliSense.XIntelliResult[] _lastis = lastxis;
if (_lastis == nilptr || _lastis.length == 0) {
return ;
}
int count = 0;
XIntelliSense.XIntelliResult [] names = new XIntelliSense.XIntelliResult[_lastis.length];
if (strpretext != nilptr) {
String prekey = strpretext.upper();
if (prekey.length() > 0 && isTriggedChar(prekey.charAt(0)) == false) {
String patternkey = ".*";
for (int i = 0, c = prekey.length(); i < c; i++) {
patternkey = patternkey + prekey.substring(i, i + 1) + ".*";
}
try{
for (int i = 0, c = _lastis.length; i < c; i++) {
if (Pattern.test(_lastis[i].get_name().upper(), patternkey, 0, false)) {
names[count] = _lastis[i];
count++;
}
}
}catch(Exception e){
}
} else {
count = _lastis.length;
names = _lastis;
}
} else {
count = _lastis.length;
names = _lastis;
}
if (count > 0) {
runOnUi(new Runnable() {
void run()override {
if (bClosed) {
return ;
}
showComplete(names, count);
}
});
}
}
XIntelliSense.XIntelliResult [] moreData = nilptr;
int morecount = 0;
public void loadAutoComplate(long mitem) {
XIntelliSense.XIntelliResult[] result = moreData;
int c = morecount;
morecount = 0;
moreData = nilptr;
autoWnd.removeItem(mitem);
for (int i = 50; i < c; i ++) {
long item = 0;
XIntelliSense.XIntelliResult names = result[i];
if (names == nilptr ) {
return ;
}
XIntelliSense.XIntelliResult _class = names.get_class();
if (_class == nilptr) {
return ;
}
String _class_name = _class.get_name();
String label = names.get_name();
if (names.get_type() == 23) {
if (names.hasProp('S')) {
item = autoWnd.addItem("res/toolbar/methodstatic.png", label);
} else {
if (names.get_visibility() == 0x40){
item = autoWnd.addItem("res/toolbar/method.png", label);
}else{
item = autoWnd.addItem("res/toolbar/methodprivate.png", label);
}
}
String descr = label + "(";
XIntelliSense.XIntelliResult[] params = names.get_params();
if (params != nilptr){
for (int x = 0; x < params.length; x ++) {
XIntelliSense.XIntelliResult param = params[x];
if (param != nilptr){
XIntelliSense.XIntelliResult param_class = param.get_class();
if (param_class != nilptr){
descr = descr + param_class.get_name() + " " + param.get_name();
}else{
descr = descr + "? " + param.get_name();
}
if (x + 1 < params.length) {
descr = descr + ", ";
}
}
}
}
descr = descr + ")";
autoWnd.setItemText(item, 1, _class_name);
autoWnd.setItemText(item, 2, descr);
autoWnd.setItemColor(item, 1, 0xff7f7f7f);
autoWnd.setItemColor(item, 2, 0xff7f7f7f);
} else {
if (names.hasProp('C')) {
item = autoWnd.addItem("res/toolbar/const.png", label);
} else if (names.hasProp('S')) {
item = autoWnd.addItem("res/toolbar/static.png", label);
} else {
item = autoWnd.addItem("res/toolbar/member.png", label);
}
autoWnd.setItemText(item, 1, _class_name);
autoWnd.setItemColor(item, 1, 0xff7f7f7f);
}
String uname = label.upper();
autoWnd.setItemTag(item, 0, i);
autoCompMap.put(uname, item);
}
}
public void showComplete(XIntelliSense.XIntelliResult[] result, int c) {
if (bClosed) {
return ;
}
autoWnd.clear();
autoCompMap.clear();
long curpos = _sci.currentPosition();
String entenedText = _sci.getText(auto_position, curpos).upper();
bool bMore = false;
if (c > 100) {
moreData = result;
morecount = c;
bMore = true;
c = 50;
}
long selitem = 0;
for (int i = 0; i < c; i ++) {
long item = 0;
XIntelliSense.XIntelliResult names = result[i];
if (names == nilptr){
continue;
}
current_autocmp = result;
if (names.get_type() == 23) {
if (names.hasProp('S')) {
item = autoWnd.addItem("res/toolbar/staticfunction.png", names.get_name());
} else {
item = autoWnd.addItem("res/toolbar/function.png", names.get_name());
}
String descr = names.get_name() + "(";
XIntelliSense.XIntelliResult [] params = names.get_params();
if (params != nilptr){
for (int x = 0; x < params.length; x ++) {
XIntelliSense.XIntelliResult param = params[x];
if (param != nilptr){
XIntelliSense.XIntelliResult pclass = param.get_class();
if (pclass != nilptr){
descr = descr + pclass.get_name() + " " + param.get_name();
}else{
descr = descr + "? " + param.get_name();
}
if (x + 1 < params.length) {
descr = descr + ", ";
}
}
}
}
descr = descr + ")";
XIntelliSense.XIntelliResult pclass = names.get_class();
if (pclass != nilptr){
autoWnd.setItemText(item, 1, pclass.get_name());
}else{
autoWnd.setItemText(item, 1, "?");
}
autoWnd.setItemText(item, 2, descr);
autoWnd.setItemColor(item, 1, 0xff7f7f7f);
autoWnd.setItemColor(item, 2, 0xff7f7f7f);
} else {
if (names.hasProp('C')) {
item = autoWnd.addItem("res/toolbar/const.png", names.get_name());
} else if (names.hasProp('S')) {
item = autoWnd.addItem("res/toolbar/static.png", names.get_name());
} else {
item = autoWnd.addItem("res/toolbar/member.png", names.get_name());
}
XIntelliSense.XIntelliResult pclass = names.get_class();
if (pclass != nilptr){
autoWnd.setItemText(item, 1, pclass.get_name());
}else{
autoWnd.setItemText(item, 1, "?");
}
autoWnd.setItemColor(item, 1, 0xff7f7f7f);
}
String uname = names.get_name().upper();
if (selitem == 0) {
if (uname.startsWith(entenedText)) {
selitem = item;
}
}
autoWnd.setItemTag(item, 0, i);
autoCompMap.put(uname, item);
}
//XSourceEditor.this.autoCompleteChange();
if (bMore) {
autoWnd.addItem(nilptr, "<更多...>");
}
showAutoWnd(auto_position);
if (selitem != 0) {
autoWnd.setCurrentItem(selitem);
}
}
public void showDebugWnd(int position, JsonObject obj){
int x = _sci.xFromPosition(position);
int y = _sci.yFromPosition(position);
QPoint pt = _sci.mapTo(_mdi_area.mainWindow, x, y);
debugWnd.move(pt.x, pt.y + _sci.getLineHeight());
__dvp.sendCommand(new Object[]{DebugValueParser.COMMAND.CMD_DISPLAYWATCH, debugWnd, watchs, obj});
debugWnd.show();
debugWnd.raise();
debugWnd.setFocus();
//setFocus();
synchronized(__dvp){
debugWndShow = true;
}
}
public void showAutoWnd(int position) {
int x = _sci.xFromPosition(position);
int y = _sci.yFromPosition(position);
QPoint pt = _sci.mapTo(_mdi_area.mainWindow, x, y);
autoWnd.move(pt.x, pt.y + _sci.getLineHeight());
autoWnd.show();
autoWnd.raise();
//setFocus();
autoCompShow = true;
}
public void hideDebugWnd(){
synchronized(__dvp){
if (debugWndShow) {
debugWnd.hide();
__dvp.clear(debugWnd);
watchs.clear();
debugWndShow = false;
}
}
}
public void hideAutoWnd() {
if (autoCompShow) {
autoWnd.hide();
autoWnd.clear();
autoCompMap.clear();
strpretext = "";
autoCompShow = false;
}
}
class DebugWndFocus : onFocusEventListener{
bool isFocused, blocked = false;
void onFocusIn(QObject obj, bool focus, int reson) {
if (blocked == false){
isFocused = true;
}
}
void onFocusOut(QObject obj, bool focus, int reson) {
if (blocked == false){
if (isFocused) {
XSourceEditor.this.hideDebugWnd();
}
}
}
public void setBlocked(bool b){
blocked = b;
}
};
public void createDebugWnd(){
debugWnd = new QTreeWidget();
debugWnd.create(_mdi_area.mainWindow);
debugWnd.hide();
debugWnd.resize(600, 200);
debugWnd.setFullRowSelection(true);
debugWnd.setColumnAutoResize(true);
debugWnd.setSortEnable(false);
debugWnd.setTextElidMode(Constant.ElideNone);
String [] columns = {"名称", "类型", "值", "ID"};
debugWnd.setColumns(columns);
debugWnd.setHeaderVisible(false);
DebugWndFocus __ofe = new DebugWndFocus();
debugWnd.setOnFocusEventListener(__ofe);
QOCallback __calback = new QOCallback(){
void callback(JsonObject obj){
runOnUi(new Runnable(){
void run(){
if (bClosed) {
return ;
}
synchronized(__dvp){
if (debugWndShow){
__dvp.sendCommand(new Object[]{DebugValueParser.COMMAND.CMD_LOADOBJECT, debugWnd, obj});
}
}
}
});
}
};
debugWnd.setOnTreeViewItemEvent( new onTreeViewItemEvent(){
TextDetail __td = nilptr;
public void onItemExpanded(QTreeWidget tree,long item)override{
__dvp.expandItem(tree, item, __calback);
}
public void onItemDoubleClicked(QTreeWidget tree,long item, int column)override{
long objectId = 0;
if (column == 2){
objectId = tree.getItemTag(item, 2);
}
String caption = tree.getItemText(item, 0);
String sztype = tree.getItemText(item, 1);
if (objectId != 0 && (sztype.equals("String") || sztype.equals("JsonObject") || sztype.equals("JsonArray"))){
XWorkspace.workspace.debuggee.queryObject("detail:" + caption , "" + objectId, __dvp.getIdentifier(), 0, 0, __calback);
}else
if (__td == nilptr){
String text = tree.getItemText(item, column);
if (text.length() > 0){
__td = new TextDetail(new TextDetail.closeListener(){
void onCreate(){
__ofe.setBlocked(true);
}
void onClose(String text, bool updated){
debugWnd.setFocus();
__ofe.setBlocked(false);
__td = nilptr;
}
});
__td.create(caption, text.replace(" ↩ ", "\n")
.replace(" ↵ ", "\r")
.replace(" ⇥ ", "\t")
.replace(" ⇤ ", "\b"), nilptr, true);
}
}
}
});
}
public void createAutoCompWindow() {
autoWnd = new QTreeWidget();
autoWnd.create(_mdi_area.mainWindow);
autoWnd.hide();
autoWnd.resize(600, 200);
autoWnd.setFullRowSelection(true);
autoWnd.setColumnAutoResize(true);
autoWnd.setSortEnable(true);
autoWnd.setTextElidMode(Constant.ElideNone);
String [] columns = {"名称", "描述", "类型"};
autoWnd.setColumns(columns);
autoWnd.setHeaderVisible(false);
autoWnd.setOnFocusEventListener(new onFocusEventListener () {
bool isFocused;
void onFocusIn(QObject obj, bool focus, int reson) {
isFocused = true;
}
void onFocusOut(QObject obj, bool focus, int reson) {
if (isFocused) {
XSourceEditor.this.hideAutoWnd();
}
}
});
autoWnd.setOnTreeViewItemEvent(new onTreeViewItemEvent() {
void onItemDoubleClicked(QTreeWidget,long item, int column)override {
XSourceEditor.this.autoCompleteDone();
}
});
}
public void showHoverInformation(String texts, int position) {
if (texts != nilptr){
JsonObject root = new JsonObject(texts);
if (root.has("contents")){
JsonObject content = (JsonObject)root.get("contents");
if (content != nilptr){
if (content.has("value")){
String kind = nilptr;
if (content.has("value")){
kind = content.getString("kind");
}
String value = content.getString("value");
if (value != nilptr){
if (kind == "markdown"){
value = value.parseMarkdown();
}
runOnUi(new Runnable(){
void run() override{
if (bClosed) {
return ;
}
showTips(position,"提示:", value);
}
});
}
}
}
}
}
}
int mouse_wait_loop = 0;
void breakHover(){
mouse_wait_loop = -2;
}
public void setSciEvent() {
QWidget viewport = _sci.viewPort();
if (viewport != nilptr){
viewport.setOnMouseEventListener(new onMouseEventListener() {
ICompileInfo tipsci = nilptr;
long __coord = 0;
int __curpos = 0;
Thread tips_thread = nilptr;
Object tips_lock = new Object();
bool button_pressed = false;
void onMouseButtonPress(QObject obj, int Button, int x, int y, int flags, int source)override {
button_pressed = true;
XSourceEditor.this.hideAutoWnd();
__tipsWnd.hide(false);
}
void onMouseButtonRelease(QObject obj, int Button, int x, int y, int flags, int source)override {
button_pressed = false;
onSciMouseButtonPress(Button, x, y, flags, source);
}
void onMouseMove(QObject obj, int Button, int _x, int _y, int flags, int source)override {
if (button_pressed ){
return;
}
mouse_wait_loop = 0;
__coord = _x;
__coord <<= 32;
__coord |= _y;
synchronized (tips_lock) {
if (tips_thread != nilptr){
return;
}
tips_thread = new Thread(){
void run()override{
long coords = __coord;
while (mouse_wait_loop++ < 10){
_system_.sleep(100);
if (mouse_wait_loop < 0){
break;
}
if (coords != __coord){
coords = __coord;
mouse_wait_loop = 0;
}
}
if (mouse_wait_loop >= 10){
runOnUi(new Runnable(){
void run() {
if (bClosed) {
return ;
}
onMouseHover((coords >> 32) & 0xffffffff, coords & 0xffffffff);
}
});
}
synchronized (tips_lock) {
tips_thread = nilptr;
}
}
};
tips_thread.start();
}
}
});
}
}
public void onMouseHover(int _x, int _y){
if (XWorkspace.workspace.isDebugging()) {
if (ThreadManager.isCurrentInterrupt()) {
if (disableOverview != nilptr){
if (disableOverview.isOverviewEnabled() == false){
return ;
}
}
if (debugWndShow == false){
int pos = _sci.positionFromPoint(_x, _y);
showRuntimeInfo(pos);
}
}
}else
if(isTipsShow() == false){
int pos = _sci.positionFromPoint(_x, _y);
int indic = _sci.IndicForPosition(pos);
int _line = _sci.positionToLine(pos);
int _column = pos - _sci.getPosition(_line);
if (((indic & (1 << INDIC_ERROR) )!= 0) || ((indic & (1 << INDIC_WARNING) )!= 0)){
Map.Iterator<long, ICompileInfo> iter = __hoverhelps.findLower(pos,false);
if (iter != nilptr){
ICompileInfo tipsci = iter.getValue();
if (tipsci != nilptr){
new Thread(){
void run()override{
runOnUi(new Runnable(){
void run() {
if (bClosed) {
return ;
}
int line = tipsci.getLine() - 1;
int ipos = _sci.getPosition(line) + tipsci.getRow() - 1;
int iclen = tipsci.getLength();
if (iclen < 1){
iclen = 1;
}
if (pos >= ipos && pos < (ipos + iclen)){
showTips(pos,"诊断信息:",tipsci.getTips());
}
}
});
}
}.start();
}
}else{
showHoverInfor(pos, _line, _column);
}
}else{
showHoverInfor(pos, _line, _column);
}
}
}
public void showHoverInfor(int pos, int _line, int _column){
new Thread(){
void run(){
_mdi_area.hoverDocument(XSourceEditor.this, getFilePath(), getTextContent(), pos, _line, _column);
}
}.start();
}
public void showRuntimeInfo(int pos) {
if (pos < 0){
return;
}
int start = _sci.sendEditor(QScintilla.SCI_WORDSTARTPOSITION, pos, 0);
int end = _sci.sendEditor(QScintilla.SCI_WORDENDPOSITION, pos, 0);
String thekey = _sci.getText(start, end).trim(true);
if (thekey.length() > 0) {
if (isKeyWord(thekey) == false && isDebugWord(thekey) == false){
return;
}
if (disableOverview != nilptr){
thekey = disableOverview.preprocessKeyword(thekey);
}
if (thekey != nilptr && thekey.length() > 0){
new Thread(){
void run(){
watchs.clear();
watchs.put(thekey,debugWnd.addItem(nilptr,thekey));
JsonObject json = XWorkspace.workspace.debuggee.queryObjectByName(ThreadManager.currentThreadId, ThreadManager.currentFrameId, thekey);
if (json != nilptr) {
JsonArray watches;
try {
watches = (JsonArray)json.get("watch");
} catch(Exception e) {
}
if (watches != nilptr) {
if (watches.length() > 0) {
showRtInfos(pos, watches);
}
}
}
}
}.start();
}
}
}
public void showRtInfos(int pos, @NotNilptr JsonArray watches) {
JsonObject obj = (JsonObject)watches.get(0);
if (obj != nilptr) {
runOnUi(new Runnable() {
void run() {
if (bClosed) {
return ;
}
showDebugWnd(pos, obj);
}
});
}
}
public bool testMark(int line, int id) {
if (line < 0) {
return false;
}
int n = _sci.sendEditor(QScintilla.SCI_MARKERGET, line, id);
if ((n & (0x1 << id)) != 0) {
return true;
}
return false;
}
public void toggleBreakpoint() {
long pos = _sci.currentPosition();
int line = _sci.positionToLine(pos);
BreakPointWnd.toggleBreakPoint(this, getFilePath(), line, testMark(line, MARK_BREAKPOINT) == false);
}
public void toggleBreakPoint(int line, bool set) {
if (set) {
if (testMark(line, MARK_BREAKPOINT) == false) {
_sci.sendEditor(QScintilla.SCI_MARKERADD, line, MARK_BREAKPOINT);
}
} else {
if (testMark(line, MARK_BREAKPOINT) == true) {
_sci.sendEditor(QScintilla.SCI_MARKERDELETE, line, MARK_BREAKPOINT);
}
}
}
public void createContextMenu() {
if (editor_actions == nilptr) {
String [] menus = {
"actionundo",
"actionredo",
"-",
"actiontoback",
"actiontofront",
"-",
"actionoverride",
"-",
"actioncut",
"-",
"actioncopy",
"actionpaste",
"-",
"actiondelete",
"actiondelcurline",
"-",
"actionbreakpoint",
"-",
"actiongotodef",
"actionfindreference",
"actionrename",
"-",
"actionupper",
"actionlower",
"-",
"actionmatchbrace",
"actionfind",
"actionreplace",
"actionfindagain",
"-",
"actiongoto"
};
editor_actions = new QAction[menus.length];
for (int i =0; i < menus.length; i++) {
if (menus[i].equals("-")) {
editor_actions[i] = new QAction();
editor_actions[i].create(this);
editor_actions[i].setSeparator(true);
} else {
editor_actions[i] = (QAction)_mdi_area.mainWindow.findByName(menus[i]);
}
}
}
__nilptr_safe(editor_actions);
_sci.addActions(editor_actions);
_sci.setContextMenuPolicy(Constant.ActionsContextMenu);
}
public void gotoCursordef() override {
locationObject(_sci.getCurrentPosition());
}
Thread autoThread = nilptr;
public void matchBrace() {
int lStart = _sci.sendEditor(QScintilla.SCI_GETCURRENTPOS, 0, 0);
int lEnd = _sci.sendEditor(QScintilla.SCI_BRACEMATCH, lStart - 1, 0);
if (lEnd >= 0) {
_sci.gotoPos(lEnd + 1);
}
}
void optimizeCompletion(@NotNilptr QScintilla sci, long position){
String content = sci.getText();
int cur_line = _sci.positionToLine(position);
int column = position - sci.getPosition(cur_line);
_mdi_area.XIntelliSenseL(XSourceEditor.this, getFilePath(), content, cur_line, column);
}
public void continueAutocomp(int pos) {
if (autoCompShow) {
if (pos < auto_position){
hideAutoWnd();
return;
}
Project proj = _mdi_area.getCurrentProject();
if (proj != nilptr) {
if (proj.hasCompletionFilter()){
optimizeCompletion(_sci, pos);
return;
}
}
if (pos != last_autopos) {
last_autopos = pos;
} else {
return ;
}
if (lastxis != nilptr && strpretext != nilptr) {
String content = _sci.getText();
long tl = content.length();
if (auto_position < tl && pos <= tl) {
strpretext = content.substring(auto_position, pos);
if (strpretext.length() == 0 || Pattern.test(strpretext, "^[A-Za-z0-9_]+$", Pattern.NOTEMPTY, true)) {
synchronized(XSourceEditor.this) {
if (autoThread == nilptr) {
autoThread = new Thread() {
void run() {
preProcessXIntellisense();
synchronized(XSourceEditor.this) {
autoThread = nilptr;
}
}
};
autoThread.start();
}
}
} else {
hideAutoWnd();
}
} else {
hideAutoWnd();
}
}
}
}
public bool isspace(int c) {
return (c == ' ' ||c == '\t' ||c == '\r' ||c == '\n' ||c == '\v' ||c == '\f');
}
public void identguide(@NotNilptr QScintilla sci, int lastChar) {
long pos = sci.currentPosition();
int line = sci.positionToLine(pos);
//如果最后输入的字符是右括号的话就自动让当前行缩进和它匹配的左括号所在行一致
if (("})>]".indexOf(lastChar) != -1) && isspace(sci.sendEditor(QScintilla.SCI_GETCHARAT,pos - 2))) {
//找前一个单词起始位置,这里用它来确定右括号左边是否全是空白字符
if(pos > 0){
int startpos = sci.sendEditor(sci.SCI_WORDSTARTPOSITION,pos - 1,0);
int linepos = sci.sendEditor(sci.SCI_POSITIONFROMLINE,line);
if(startpos == linepos) {
int othpos = sci.sendEditor(QScintilla.SCI_BRACEMATCH,pos - 1); //得到对应的左括号所在的位置
int othline = sci.sendEditor(QScintilla.SCI_LINEFROMPOSITION, othpos); //左括号所在行
int nIndent = sci.sendEditor(QScintilla.SCI_GETLINEINDENTATION, othline);//左括号所在行的缩进值
// 替换右括号前面的空白字符,使之与左括号缩进一致
String space = String.fill(' ', 1024);
sci.sendEditor(QScintilla.SCI_SETTARGETSTART, startpos);
sci.sendEditor(QScintilla.SCI_SETTARGETEND, pos - 1);
sci.sendEditor(QScintilla.SCI_REPLACETARGET, nIndent, space);
}
}
}
if (lastChar == '\n') {
if(line > 0) {
// 得到上一行缩进设置
int nIndent = sci.sendEditor(QScintilla.SCI_GETLINEINDENTATION, line - 1);
// 查找上一行最后一个有效字符(非空白字符)
int nPrevLinePos = sci.sendEditor(QScintilla.SCI_POSITIONFROMLINE, line - 1);
int c = ' ';
for(int p = pos - 2; p >= nPrevLinePos && isspace(c); ) {
p--;
c = sci.sendEditor(QScintilla.SCI_GETCHARAT, p);
}
// 如果是左括号,就多缩进四格
if(c != 0 && "{([<".indexOf(c) != -1) {
nIndent += 4;
}
// 缩进...
String space = String.fill(' ', nIndent);
sci.sendEditor(QScintilla.SCI_REPLACESEL, 0, space);
}
}
}
WordRecognizer recongnizer = nilptr;
bool reconGeted = false;
public bool isTriggedChar(char c){
if (reconGeted == false){
recongnizer = _mdi_area.getWordRecognizer(getFilePath());
reconGeted = true;
}
if (recongnizer != nilptr){
return recongnizer.isTriggedChar(c);
}
return false;
}
public bool isDocument(String ext){
if (reconGeted == false){
recongnizer = _mdi_area.getWordRecognizer(getFilePath());
reconGeted = true;
}
if (recongnizer != nilptr){
return recongnizer.isDocument(ext);
}
return false;
}
public bool isDebugWord(String word){
if (word == nilptr || word.length() == 0){
return false;
}
if (word.startsWith("$") || word.isDigit()){
return true;
}
return false;
}
public bool isKeyWord(String word){
if (word == nilptr || word.length() == 0){
return false;
}
for (int i = 0, c = word.length(); i < c; i++){
if (isInWord(word.charAt(i),i == 0) == false){
return false;
}
}
return true;
}
public bool isInWord(char c, bool b){
if (reconGeted == false){
recongnizer = _mdi_area.getWordRecognizer(getFilePath());
reconGeted = true;
}
if (recongnizer != nilptr){
return recongnizer.isWord(c, b);
}
return false;
}
SciEventListener sci_listener = new SciEventListener() {
int lastAddedChar;
void ON_MARGINCLICK(@NotNilptr QScintilla sci, int position, int modifiers, int margin)override {
breakHover();
if (margin == BREAKPOINT_INDEX) {
int line = _sci.positionToLine(position);
BreakPointWnd.toggleBreakPoint(XSourceEditor.this, getFilePath(), line, testMark(line, MARK_BREAKPOINT) == false);
} else if (margin == MARGIN_FOLD_INDEX) {
int line = _sci.positionToLine(position);
_sci.sendEditor(QScintilla.SCI_TOGGLEFOLD, line);
} else if (margin == DEBUGPOINT_INDEX) {
int line = _sci.positionToLine(position);
try{
ICompileInfo iif = __marginhelps.get(line);
if (iif != nilptr){
showTips(position,"诊断信息:",iif.getTips());
}
}catch(Exception e){
}
}
}
void ON_UPDATEUI(@NotNilptr QScintilla sci, int updated)override {
int position = sci.sendEditor(QScintilla.SCI_GETCURRENTPOS, 0, 0);
XWorkspace.recordAction(getFilePath(), position);
displayInfo(position);
int cstyle = sci.getStyleAtPosition(position);
if (cstyle == QScintilla.SCE_C_COMMENT || cstyle == QScintilla.SCE_C_COMMENTLINE || cstyle == QScintilla.SCE_C_COMMENTDOC
|| cstyle == QScintilla.SCE_C_STRING || cstyle == QScintilla.SCE_C_CHARACTER) {
return ;
}
if (position > 0){
long oppos = position - 1;
int lEnd = sci.sendEditor(QScintilla.SCI_BRACEMATCH, oppos, 0);
if (lEnd >= 0) {
sci.sendEditor(QScintilla.SCI_BRACEHIGHLIGHT, oppos, lEnd);
} else {
sci.sendEditor(QScintilla.SCI_BRACEHIGHLIGHT, -1, -1);
}
int start = sci.sendEditor(QScintilla.SCI_WORDSTARTPOSITION, position, 0);
int end = sci.sendEditor(QScintilla.SCI_WORDENDPOSITION, position, 0);
String curKeyWord = _sci.getText(start, end);
XSourceEditor.this.setHighlightKeyWord(curKeyWord.trim(true));
}
if (lastAddedChar != 0 && Setting.isAutoIdent()) {
identguide(sci, lastAddedChar);
lastAddedChar = 0;
}
if (autoCompShow) {
int line = sci.positionToLine(position);
int autoline = sci.positionToLine(auto_position);
if (line != autoline) {
hideAutoWnd();
}
}
}
void QON_SELCHANGED(@NotNilptr QScintilla sci, bool yes) {
XMenuManager.setStatusSel(yes);
}
void ON_MODIFIED(@NotNilptr QScintilla sci,
int position, int modType,
@NotNilptr String text, int length,
int linesAdded, int line,
int foldLevelNow, int foldLevelPrev,
int token, int annotationLinesAdded) {
int cstyle = sci.getStyleAtPosition(position);
if (cstyle == QScintilla.SCE_C_COMMENT || cstyle == QScintilla.SCE_C_COMMENTLINE || cstyle == QScintilla.SCE_C_COMMENTDOC
/*|| cstyle == QScintilla.SCE_C_STRING*/ || cstyle == QScintilla.SCE_C_CHARACTER) {
return ;
}
if ((modType & (QScintilla.SC_MOD_INSERTTEXT | QScintilla.SC_MOD_DELETETEXT | QScintilla.SC_PERFORMED_UNDO | QScintilla.SC_PERFORMED_REDO | QScintilla.SC_MULTISTEPUNDOREDO | QScintilla.SC_LASTSTEPINUNDOREDO | QScintilla.SC_MULTILINEUNDOREDO)) != 0) {
int linep = sci.positionToLine(position);
breakHover();
if ((modType & QScintilla.SC_MOD_INSERTTEXT) != 0){
int lineto = sci.positionToLine(position + length);
for (int i = linep; i < lineto + 1; i++){
sci.sendEditor(QScintilla.SCI_MARKERDELETE, i, reserve_modify_mark);
sci.sendEditor(QScintilla.SCI_MARKERADD, i, current_modify_mark);
}
}else{
sci.sendEditor(QScintilla.SCI_MARKERDELETE, linep, reserve_modify_mark);
sci.sendEditor(QScintilla.SCI_MARKERADD, linep, current_modify_mark);
}
//if (pos >= auto_position) {
if (position > 0 && (modType & QScintilla.SC_MOD_DELETETEXT) == QScintilla.SC_MOD_DELETETEXT) {
continueAutocomp(position - 1);
}
XSourceEditor.this.intellisense_modified = true;
}
}
void ON_CHARADDED(@NotNilptr QScintilla sci,int charadded)override {
lastAddedChar = charadded;
long position = sci.currentPosition();
int cstyle = sci.getStyleAtPosition(position);
bool invalidArea = true;
if (cstyle == QScintilla.SCE_C_COMMENT || cstyle == QScintilla.SCE_C_COMMENTLINE || cstyle == QScintilla.SCE_C_COMMENTDOC
|| cstyle == QScintilla.SCE_C_STRING || cstyle == QScintilla.SCE_C_CHARACTER) {
invalidArea = false;
}
if (invalidArea) {
if (isTriggedChar(charadded)) {
String content = sci.getText();
strpretext = String.format("%c",charadded);
int line = sci.positionToLine(position);
int column = position - sci.getPosition(line);
if (_mdi_area.XIntelliSense(XSourceEditor.this, getFilePath(), content, position, line, column)) {
auto_position = position;
last_autopos = -1;
}
} else if (autoCompShow == false) {
if (isInWord(lastAddedChar, true)) {
String content = sci.getText();
int cur_line = _sci.positionToLine(position);
int p = position;
while (p > 0) {
char c = content.charAt(p - 1);
if (false == isInWord(c, true)) {
break;
}
p--;
}
auto_position = p;
last_autopos = -1;
strpretext = content.substring(auto_position, position);
int column = position - sci.getPosition(cur_line);
_mdi_area.XIntelliSenseL(XSourceEditor.this, getFilePath(), content, cur_line, column);
}
} else {
if (false == isInWord(lastAddedChar, true)) {
hideAutoWnd();
} else {
continueAutocomp(position);
}
}
}else{
continueAutocomp(position);
}
if (Setting.isMatchBrace()) {
char next_char = sci.getChar(position);
bool next_isword = false;
if (isInWord(next_char, false)) {
next_isword = true;
}
switch(charadded) {
case '(':
if (next_isword == false) {
sci.insertText(position, ")");
}
break;
case '[':
if (next_isword == false) {
sci.insertText(position, "]");
}
break;
case '{':
if (next_isword == false) {
sci.insertText(position, "}");
}
break;
case '"':
if (sci.getChar(position) == charadded) {
sci.selectAndReplace(position,position + 1,"");
} else if (next_isword == false) {
sci.insertText(position, "\"");
}
break;
case '\'':
if (sci.getChar(position) == charadded) {
sci.selectAndReplace(position,position + 1,"");
} else if (next_isword == false) {
sci.insertText(position, "'");
}
break;
case '}':
case ')':
case ']':
if (sci.getChar(position) == charadded) {
sci.selectAndReplace(position,position + 1,"");
}
break;
}
}
}
};
public bool deleteBrace(int pos) {
int c = _sci.getChar(pos);
switch(c) {
case '(':
if (_sci.getChar(pos + 1) == ')') {
_sci.selectAndReplace(pos,pos + 2,"");
return false;
}
break;
case ')':
if (_sci.getChar(pos - 1) == '(') {
_sci.selectAndReplace(pos - 1,pos + 1,"");
return false;
}
break;
case '[':
if (_sci.getChar(pos + 1) == ']') {
_sci.selectAndReplace(pos,pos + 2,"");
return false;
}
break;
case ']':
if (_sci.getChar(pos - 1) == '[') {
_sci.selectAndReplace(pos - 1,pos + 1,"");
return false;
}
break;
/*case '{':
if (_sci.getChar(pos + 1) == '}') {
_sci.selectAndReplace(pos,pos + 2,"");
return false;
}
break;
case '}':
if (_sci.getChar(pos - 1) == '{') {
_sci.selectAndReplace(pos - 1,pos + 1,"");
return false;
}
break;*/
case '\'':
if (_sci.getChar(pos + 1) == '\'') {
_sci.selectAndReplace(pos,pos + 2,"");
return false;
} else if (_sci.getChar(pos - 1) == '\'') {
_sci.selectAndReplace(pos - 1,pos + 1,"");
return false;
}
break;
case '"':
if (_sci.getChar(pos + 1) == '"') {
_sci.selectAndReplace(pos,pos + 2,"");
return false;
} else if (_sci.getChar(pos - 1) == '"') {
_sci.selectAndReplace(pos - 1,pos + 1,"");
return false;
}
break;
}
return true;
}
public bool create(@NotNilptr QWidget parent) {
if (super.create(parent)) {
QWidget frame = new QWidget();
frame.create();
frame.setName("editorframe");
QWidget domainframe = new QWidget();
domainframe.create();
QHBoxLayout globalarea = new QHBoxLayout();
globalarea.create(domainframe);
onComboBoxEventListener _cmb_listener = new onComboBoxEventListener(){
public void onItemSelected(QObject obj, int id) {
if (bCmbInit){
return;
}
try{
QComboBox qc = (QComboBox)obj;
Vector<XIntelliSense.XIntelliResult> _link_list = (Vector<XIntelliSense.XIntelliResult>)qc.getTag();
if (_link_list != nilptr){
XIntelliSense.XIntelliResult it = _link_list.get(id);
if (it != nilptr){
goto(it.get_line(),it.get_row());
_sci.setFocus();
}
}
}catch(Exception e){
}
}
};
domaincmb.create(domainframe);
objectscmb.create(domainframe);
domaincmb.setOnComboBoxEventListener(_cmb_listener);
objectscmb.setOnComboBoxEventListener(_cmb_listener);
globalarea.addWidget(domaincmb);
globalarea.addWidget(objectscmb);
globalarea.setContentsMargins(0,0,0,0);
globalarea.setSpacing(0);
domainframe.setLayout(globalarea);
QVBoxLayout qhl = new QVBoxLayout();
qhl.create(frame);
_sci = new QScintilla();
if (_sci.create(frame) == false) {
return false;
}
statbar = new QLabel();
statbar.create(frame);
statbar.setName("editstatus");
statbar.show();
statbar.setAlignment(Constant.AlignRight);
statbar.setText("状态栏");
qhl.addWidget(domainframe);
qhl.addWidget(_sci);
qhl.addWidget(statbar);
frame.setLayout(qhl);
qhl.setSpacing(0);
qhl.setContentsMargins(0,0,0,0);
_sci.unbindInternalShortcut(Constant.ControlModifier | Constant.Key_D);
_sci.unbindInternalShortcut(Constant.ControlModifier | Constant.Key_C);
_sci.unbindInternalShortcut(Constant.ControlModifier | Constant.ShiftModifier | Constant.Key_U);
_sci.unbindInternalShortcut(Constant.ControlModifier | Constant.Key_U);
//_sci.updateInternalShortcut(QScintilla.SCI_LINEDELETE, ControlModifier | Key_D);
//_sci.clearInternalShortcuts();
/*setOnActivateListener(new onActivateListener() {
void onWindowDeactivate(QObject obj) override{
}
void onWindowActivate(QObject )override{
}
});*/
setOnStatusListener(new onStatusListener(){
public void onWindowStateChange(QObject obj, int oldState, int state) {
if ((state & Constant.WindowActive) == Constant.WindowActive){
updateInformationPoint();
}else{
hideAutoWnd();
hideDebugWnd();
_sci.cancelTips();
}
}
});
setSciEvent();
createAutoCompWindow();
createDebugWnd();
setWindowIcon("res/toolbar/source.png");
createContextMenu();
_sci.setOnSciEventListener(sci_listener);
updateTitle();
setWidget(frame);
_textplugins = _mdi_area.getEditorPlugin();
updateConfig();
_sci.show();
setMaximized(true);
_sci.setOnKeyEventListener(new onKeyEventListener() {
bool onKeyPress(QObject obj, int key, bool repeat, int count, String text, int scanCode, int virtualKey, int modifier)override {
if (autoCompShow) {
if (key == Constant.Key_Up) {
XSourceEditor.this.autoCompleteUp();
return false;
}
if (key == Constant.Key_Down) {
XSourceEditor.this.autoCompleteDown();
return false;
}
if (key == Constant.Key_Enter || key == Constant.Key_Return) {
XSourceEditor.this.autoCompleteDone();
return false;
}
if (key == Constant.Key_Escape || key == Constant.Key_Delete || key == Constant.Key_Home || key == Constant.Key_End|| key == Constant.Key_PageUp|| key == Constant.Key_PageDown || key == Constant.Key_HomePage) {
XSourceEditor.this.hideAutoWnd();
hideDebugWnd();
if (key != Constant.Key_Delete){
__tipsWnd.hide();
}
return true;
}
}
if (Setting.isMatchBrace()) {
if (key == Constant.Key_Delete || key == Constant.Key_Backspace) {
int start = _sci.getSelectStart();
int end = _sci.getSelectEnd();
if (start == end) {
return deleteBrace(key == Constant.Key_Delete ? start : start - 1);
}
}
}
if (Setting.isAutoIdent()) {
if (key == Constant.Key_Return || key == Constant.Key_Enter) {
_sci.replaceSelect("");
int pos = _sci.getCurrentPosition();
int c = _sci.getChar(pos);
if (c == '}') {
String tabs = "";
if (Setting.isUseTabstop()) {
tabs = "\t";
} else {
tabs = String.fill(' ',Setting.getTabWidth());
}
_sci.insertText(pos,"\n\n");
_sci.gotoPos(pos + 1);
identguide(_sci, '\n' );
pos = _sci.getCurrentPosition();
_sci.gotoPos(pos + 1);
identguide(_sci, '\n' );
_sci.insertText(pos,tabs);
_sci.gotoPos(pos + tabs.length());
return false;
}
}
}
if (key == Constant.Key_Tab || key == Constant.Key_Enter || key == Constant.Key_Return) {
if (_sci.getSelectStart() == _sci.getSelectEnd()){
hideAutoWnd();
int pos = _sci.getCurrentPosition();
_sci.setIndicCurrent(INDIC_TIPS);
int[] ind = getNextIndic(pos);
if (ind != nilptr) {
if (ind.length > 0) {
_sci.gotoPos(ind[1]);
}
return false;
}
return true;
}
}
if (key == Constant.Key_Control) {
lastCursor = _sci.getCursor();
_sci.setCursor(QScintilla.cursorHand);
sciisHand = true;
}
return true;
}
bool onKeyRelease(QObject obj, int key, bool repeat, int count, String text, int scanCode, int virtualKey, int modifier)override {
if (isModified() == false) {
setModified(_sci.isModified());
if (isModified()) {
XSourceEditor.this.updateTitle();
}
}
if (key == Constant.Key_Control ) {
_sci.setCursor(QScintilla.cursorText);
sciisHand = false;
}
return true;
}
});
_sci.setOnFocusEventListener(new onFocusEventListener() {
void onFocusIn(QObject obj, bool focus, int reson) {
sciisHand = false;
XFindDlg.findinOutput = false;
_sci.setCursor(QScintilla.cursorText);
}
void onFocusOut(QObject obj, bool focus, int reson) {
sciisHand = false;
_sci.setCursor(QScintilla.cursorText);
_sci.cancelTips();
if (autoCompShow) {
if (autoWnd.hasFocus() == false) {
hideAutoWnd();
}
}
}
void onFocusAboutToChange(QObject obj, bool focus, int reson) {
}
});
return true;
}
return false;
}
void displayInfo(int curpos){
int line = _sci.positionToLine(curpos);
int column = curpos - _sci.getPosition(line);
int total = _sci.getLength();
int countOfLine = _sci.countOfLine();
statbar.setText("行:" + (line + 1)+ " 字:" + (column + 1 )+ " 文件长度:" + total + " 总行数:" + countOfLine + " 编码:" + ( (defaultCharset == nilptr) ? "UTF-8" : defaultCharset) + " ");
}
public void onTextEditorCreated() {
IXPlugin plugin = _mdi_area.getCurrentProjectPlugin();
if (plugin != nilptr) {
plugin.onTextEditorCreated(_controller);
}
}
public void onTextEditorClosed() {
IXPlugin plugin = _mdi_area.getCurrentProjectPlugin();
if (plugin != nilptr) {
plugin.onTextEditorClosed(_controller);
}
}
public bool requestPluginClose() {
if (_textplugins != nilptr) {
return _textplugins.requestClose(_controller);
}
return true;
}
public String mapType(@NotNilptr String type) {
int t = type.parseInt();
switch(t) {
case 18:
return "变量/常量";
break;
case 25:
case 23:
return "方法";
break;
case 28:
return "包";
break;
case 27:
return "Native方法";
break;
case 30:
return "接口";
break;
case 31:
return "类";
break;
case 33:
return "匿名类";
break;
}
return "对象";
}
public int [] getNextIndic(int pos) {
int start = _sci.getIndicStart(INDIC_TIPS, pos);
if (start == 0) {
return nilptr;
}
int end = _sci.getIndicEnd(INDIC_TIPS, start);
int[] ret = {start, end};
int dic = _sci.IndicForPosition(start);
if ((dic & (1 << INDIC_TIPS)) == 0) {
if (end == _sci.getLength()) {
int del_len = clearIndic();
_sci.clearIndic(0, _sci.getLength());
_sci.gotoPos(pos + 1 - del_len);
return new int[0];
}
if (end >= 0){
return getNextIndic(end);
}
}
return ret;
}
public void clearInformationPoint(){
__hoverhelps.clear();
__marginhelps.clear();
_sci.setIndicCurrent(INDIC_ERROR);
_sci.clearIndic(0,_sci.getLength());
_sci.setIndicCurrent(INDIC_WARNING);
_sci.clearIndic(0,_sci.getLength());
}
public void clearSelectedMark(){
_sci.setIndicCurrent(INDIC_SELECTED);
_sci.clearIndic(0,_sci.getLength());
}
public void clearFoundMark(){
_sci.setIndicCurrent(INDIC_FIND);
_sci.clearIndic(0,_sci.getLength());
}
public int clearIndic() {
//bool bclr = true;
int start = 0, end = 0;
int del_len = 0;
do {
start = _sci.getIndicStart(INDIC_TIPS, start);
end = _sci.getIndicEnd(INDIC_TIPS, start);
if (end == 0) {
return del_len;
}
int dic = _sci.IndicForPosition(start);
if ((dic & (1 << INDIC_TIPS)) != 0) {
del_len += (end - start);
_sci.selectAndReplace(start, end, "");
} else {
start = end;
}
} while (end != _sci.getLength());
return del_len;
}
/***
@brief 查询重写方法
@param pos 编辑器中的位置
如果代码结构比较复杂则 XISQueryM 可能会耗时导致界面停止响应
所以开新线程处理,然后将处理结果交给UI线程处理
*/
public void overrideObject() {
// 获取当前行
int pos = _sci.currentPosition();
int line = _sci.positionToLine(pos);
int column = pos - _sci.getPosition(line);
// 开一个线程去查询
new Thread() {
void run()override {
// 执行查询
XIntelliSense.XIntelliResult [] res = _mdi_area.XISQueryM(getFilePath(), line);
//将查询结果交还UI线程处理
runOnUi(new Runnable() {
void run()override {
if (bClosed == false) {
if (res != nilptr && res.length > 0) {
OverrideDlg.requesOverrideObject(XSourceEditor.this, pos, res);
} else {
ProgressView pv = ProgressView.showWait(1000);
if (pv != nilptr){
pv.centerScreen();
pv.showResult(true, false);
pv.setTitleText("找不到对象");
pv.dismissAfter(1000);
}
}
}
}
});
}
} .start();
}
public void locationObject(int pos) {
if (pos <0 ){
return ;
}
int start = _sci.sendEditor(QScintilla.SCI_WORDSTARTPOSITION, pos, 0);
int end = _sci.sendEditor(QScintilla.SCI_WORDENDPOSITION, pos, 0);
int line = _sci.positionToLine(start);
String curKeyWord = _sci.getText(start, end).trim(true);
int column = start - _sci.getPosition(line);
String content = _sci.getText();
if (curKeyWord.length() > 0) {
new Thread() {
void run()override {
updateXIntellisence(getFilePath(), content);
XIntelliSense.XIntelliResult [] res = _mdi_area.XISQuery(getFilePath(), line, column, curKeyWord);
runOnUi(new Runnable() {
void run()override {
if (bClosed == false) {
if (res != nilptr && res.length > 0) {
sciisHand = false;
_sci.setCursor(QScintilla.cursorText);
if (res.length == 1) {
localtion(res[0].get_source(), res[0].get_line(), res[0].get_row());
} else {
XFinder.FindResult fres = new XFinder.FindResult();
for (int i = 0; i < res.length; i++) {
String rsrc = res[i].get_source();
if (rsrc != nilptr && rsrc.length() > 0) {
fres.add(new XFinder.FindItem(res[i].get_source(), res[i].get_line(), res[i].get_row(), 1, mapType("" + res[i].get_type())));
}
}
XFindresWnd.ShowResult(fres);
}
} else {
ProgressView pv = ProgressView.showWait(1000);
if (pv != nilptr){
pv.centerScreen();
pv.showResult(true, false);
pv.setTitleText("找不到对象");
pv.dismissAfter(1000);
}
}
}
}
});
}
} .start();
}
}
public void onSciMouseButtonPress(int Button, int x, int y,int flags, int source) {
if (sciisHand && Button == 1) {
String filePath = getFilePath();
if (filePath.length() > 0 && filePath.startsWith("#") == false) {
int pos = _sci.positionFromPoint(x, y);
locationObject(pos);
}
}
}
public static void localtion(String source, int line, int row) {
if (source == nilptr){
return ;
}
DocumentView editor = findDocumentWindow(XWorkspace.workspace, source, true);
if (editor != nilptr) {
editor.gotoAndSelect(line, row);
XWorkspace.workspace.setActiveSubWindow(editor);
} else {
ProgressView pv = ProgressView.showWait(1000);
if (pv != nilptr){
pv.centerScreen();
pv.showResult(true, false);
pv.setTitleText("对象不在源代码中");
pv.dismissAfter(1000);
}
}
}
public static void localtion(@NotNilptr String source, int pos) {
DocumentView editor = findDocumentWindow(XWorkspace.workspace, source, true);
if (editor != nilptr) {
editor.goto(pos);
XWorkspace.workspace.setActiveSubWindow(editor);
}
}
public String getTextContent() {
return _sci.getText();
}
public String getSelectedText() {
return _sci.getSelectedText();
}
public bool isIntellisense_modified() {
return intellisense_modified;
}
public bool onCloseDocument()override {
if (_sci.isModified()) {
bool bclose = false;
int rt = QMessageBox.Question("提示","该文档有未保存的更改, 是否在关闭前保存文件?", QMessageBox.Cancel | QMessageBox.No | QMessageBox.Save, QMessageBox.Save);
if (rt == QMessageBox.Save) {
saveFile();
bclose = true;
} else if (rt == QMessageBox.No) {
bclose = true;
} else if (rt == QMessageBox.Cancel) {
bclose = false;
}
if (bclose) {
bclose = requestPluginClose();
}
if (bclose == false) {
return false;
}
}
Project proj = XWorkspace.workspace.getCurrentProject();
if (proj != nilptr){
proj.didCloseFile(getFilePath());
}
bClosed = true;
onTextEditorClosed();
return true;
}
public void autoCompleteUp() {
if (autoCompShow) {
int id = autoWnd.getCurrentRow();
if (id > 0) {
id--;
} else {
id = 0;
}
autoWnd.setCurrentIndex(id, 0);
}
}
public void autoCompleteDown() {
if (autoCompShow) {
int id = autoWnd.getCurrentRow();
int count = autoWnd.getTopLevelCount();
if ((id + 1) < count) {
id++;
} else {
id = count - 1;
}
autoWnd.setCurrentIndex(id, 0);
}
}
public void autoCompleteDone() {
if (autoCompShow) {
long item = autoWnd.getSelItem();
autoCompShow = false;
if (item != 0) {
String text = autoWnd.getItemText(item, 0);
if (text.equals("<更多...>")) {
autoCompShow = true;
loadAutoComplate(item);
return;
}
String tips = autoWnd.getItemText(item, 2);
long curpos = _sci.currentPosition();
int id = autoWnd.getItemTag(item, 0);
if (current_autocmp != nilptr && id < current_autocmp.length) {
XIntelliSense.XIntelliResult names = current_autocmp[id];
if (names != nilptr && names.get_type() == 23) {
IXIntelliSense.InputDescription input = names.makeInputText();
if (input != nilptr){
_sci.selectAndReplace(auto_position, curpos, input.getInsertText());
int [][] current_idincs = input.getTipsDescription();
if (current_idincs != nilptr){
_sci.setIndicCurrent(1);
for (int i = 0; i < current_idincs.length; i++) {
_sci.applyIndic(auto_position + current_idincs[i][0], current_idincs[i][1] - current_idincs[i][0]);
}
_sci.gotoPos(auto_position + current_idincs[0][1]);
}
}
/**/
} else {
_sci.selectAndReplace(auto_position, curpos, text);
}
if (names != nilptr){
names.accept();
}
} else {
_sci.selectAndReplace(auto_position, curpos, text);
}
if (tips.length() != 0) {
showTips(auto_position, "助手:",autoWnd.getItemText(item, 1) + " " + tips);
}
}
autoCompShow = true;
hideAutoWnd();
_sci.setFocus();
}
}
public void autoCompleteChange() {
if (autoCompShow) {
long curpos = _sci.currentPosition();
if (curpos > auto_position) {
String entenedText = _sci.getText(auto_position, curpos).upper();
/* 获取输入的文字 选取一个和已输入部分匹配的 */
Map.Iterator<String,long> iter = autoCompMap.iterator();
long selItem = 0;
while (iter.hasNext()) {
String key = iter.getKey();
if (key != nilptr && key.startsWith(entenedText)) {
selItem = iter.getValue();
break;
}
iter.next();
}
if (selItem != 0) {
autoWnd.setCurrentItem(selItem);
}
}
if (curpos < auto_position) {
hideAutoWnd();
}
}
}
public void switchSaveMark() {
_sci.sendEditor(QScintilla.SCI_MARKERSETFORE,current_modify_mark,0xff3cc215);
_sci.sendEditor(QScintilla.SCI_MARKERSETBACK,current_modify_mark,0xff3cc215);
_sci.sendEditor(QScintilla.SCI_MARKERSETFORE,reserve_modify_mark,0xff00d8ff);
_sci.sendEditor(QScintilla.SCI_MARKERSETBACK,reserve_modify_mark,0xff00d8ff);
int swap = current_modify_mark;
current_modify_mark = reserve_modify_mark;
reserve_modify_mark = swap;
}
public void replaceText(int start, int len,@NotNilptr String text) {
_sci.sendEditor(QScintilla.SCI_SETTARGETSTART, start);
_sci.sendEditor(QScintilla.SCI_SETTARGETEND, start + len);
_sci.sendEditor(QScintilla.SCI_REPLACETARGET, text.length(), text);
setModified();
}
public void updateConfig() {
bool darkStyle = Setting.isDarkStyle();
_sci.setIndicStyle(INDIC_TIPS, QScintilla.INDIC_BOX);
_sci.setIndicStyle(INDIC_ERROR, QScintilla.INDIC_SQUIGGLE);
_sci.setIndicStyle(INDIC_WARNING, QScintilla.INDIC_SQUIGGLE);
_sci.setIndicStyle(INDIC_FIND, QScintilla.INDIC_ROUNDBOX);
_sci.setIndicStyle(INDIC_SELECTED, QScintilla.INDIC_CONTAINER);
bool updatesuccess = false;
if (_textplugins != nilptr) {
szKeywords1 = _textplugins.getKeyWords();
if (szKeywords1 == nilptr) {
szKeywords1 = "";
}
if (Setting.isCustomColor()){
updatesuccess = true;
_sci.sendEditor(QScintilla.SCI_CLEARDOCUMENTSTYLE, 0, 0);
_sci.sendEditor(QScintilla.SCI_SETLEXER, QScintilla.SCLEX_CPP, 0);
_sci.sendEditor(QScintilla.SCI_SETCODEPAGE, QScintilla.SC_CP_UTF8);
_sci.sendEditor(QScintilla.SCI_STYLESETBACK, QScintilla.STYLE_DEFAULT, Setting.getColorRef("defaultbackcolor"));
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.STYLE_DEFAULT, Setting.getColorRef("defaultforecolor"));
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, 75, Setting.getColorRef("defaultforecolor"));
//_sci.sendEditor(QScintilla.STYLE_LINENUMBER, 1, 0);
//bool bmac = (_system_.getPlatformId() == 2);
_sci.sendEditor(QScintilla.SCI_STYLESETFONT, QScintilla.STYLE_DEFAULT,Setting.getEditorFont());
_sci.sendEditor(QScintilla.SCI_STYLESETSIZEFRACTIONAL, QScintilla.STYLE_DEFAULT,Setting.getEditorFontSize());
_sci.sendEditor(QScintilla.SCI_STYLECLEARALL, 0, 0);
_sci.sendEditor(QScintilla.SCI_SETSELBACK,1,Setting.getColorRef("selectedbackcolor"));
_sci.sendEditor(QScintilla.SCI_SETSELFORE,0,Setting.getColorRef("selectedforecolor"));
//C++语法解析
_sci.sendEditor(QScintilla.SCI_SETLEXER, QScintilla.SCLEX_CPP, 0);
_sci.sendEditor(QScintilla.SCI_SETKEYWORDS, 0, szKeywords1);//设置关键字
_sci.sendEditor(QScintilla.SCI_SETKEYWORDS, 1, szKeywords2);//设置关键字
// 下面设置各种语法元素风格
_sci.sendEditor(QScintilla.SCI_SETEOLMODE, 1, 0);
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, MARK_BREAKPOINT, 0);
_sci.sendEditor(QScintilla.SCI_MARKERSETBACK, MARK_BREAKPOINT,Setting.getColorRef("breakpointbackcolor"));
_sci.sendEditor(QScintilla.SCI_MARKERSETFORE, MARK_BREAKPOINT,Setting.getColorRef("breakpointforecolor"));
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, MARK_POINTER,4);
_sci.sendEditor(QScintilla.SCI_MARKERSETFORE, MARK_POINTER,Setting.getColorRef("markpointbackcolor"));
_sci.sendEditor(QScintilla.SCI_MARKERSETBACK, MARK_POINTER,Setting.getColorRef("markpointforecolor"));
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE,MARK_MODIFIED,25);
_sci.sendEditor(QScintilla.SCI_MARKERSETFORE,MARK_MODIFIED,Setting.getColorRef("modifiedmarkforecolor"));
_sci.sendEditor(QScintilla.SCI_MARKERSETBACK,MARK_MODIFIED,Setting.getColorRef("modifiedmarkbackcolor"));
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE,MARK_SAVED,25);
_sci.sendEditor(QScintilla.SCI_MARKERSETFORE,MARK_SAVED,Setting.getColorRef("savedmarkforecolor"));
_sci.sendEditor(QScintilla.SCI_MARKERSETBACK,MARK_SAVED,Setting.getColorRef("savedmarkbackcolor"));
current_modify_mark = MARK_MODIFIED;
reserve_modify_mark = MARK_SAVED;
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN,BREAKPOINT_INDEX, 15);
_sci.sendEditor(QScintilla.SCI_SETMARGINSENSITIVEN,BREAKPOINT_INDEX, 1);
if (Setting.isIndentGuide()) {
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.STYLE_INDENTGUIDE, Setting.getColorRef("indentguidecolor"));
_sci.sendEditor(QScintilla.SCI_SETINDENTATIONGUIDES, QScintilla.SC_IV_LOOKBOTH);
} else {
_sci.sendEditor(QScintilla.SCI_SETINDENTATIONGUIDES, QScintilla.SC_IV_NONE);
}
if (Setting.isShowLineNumber()) {
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN,LINENUMBER_INDEX, 40);
} else {
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN,LINENUMBER_INDEX, 0);
}
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN,DEBUGPOINT_INDEX, 15);
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN,MODIFIMARK_INDEX, 3);
//_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN,4, 0);
_sci.sendEditor(QScintilla.SCI_SETMARGINTYPEN, BREAKPOINT_INDEX, QScintilla.SC_MARGIN_SYMBOL);
_sci.sendEditor(QScintilla.SCI_SETMARGINMASKN, BREAKPOINT_INDEX, 1 << MARK_BREAKPOINT);
_sci.sendEditor(QScintilla.SCI_SETMARGINTYPEN, LINENUMBER_INDEX, QScintilla.SC_MARGIN_NUMBER);
_sci.sendEditor(QScintilla.SCI_SETMARGINMASKN, LINENUMBER_INDEX, 0);
_sci.sendEditor(QScintilla.SCI_SETMARGINTYPEN, DEBUGPOINT_INDEX, QScintilla.SC_MARGIN_SYMBOL);
_sci.sendEditor(QScintilla.SCI_SETMARGINMASKN, DEBUGPOINT_INDEX, 1 << MARK_POINTER);
_sci.sendEditor(QScintilla.SCI_SETMARGINTYPEN, MODIFIMARK_INDEX, QScintilla.SC_MARGIN_SYMBOL);
_sci.sendEditor(QScintilla.SCI_SETMARGINMASKN, MODIFIMARK_INDEX, (1 << MARK_MODIFIED) | (1 << MARK_SAVED));
_sci.sendEditor(QScintilla.SCI_STYLESETBACK, QScintilla.STYLE_LINENUMBER, Setting.getColorRef("linenumberbackcolor"));
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.STYLE_LINENUMBER, Setting.getColorRef("linenumberforecolor"));
_sci.sendEditor(QScintilla.SCI_SETMARGINLEFT, 0, 0);
_sci.sendEditor(QScintilla.SCI_STYLESETBOLD, QScintilla.STYLE_BRACELIGHT, 1);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.STYLE_BRACELIGHT, Setting.getColorRef("matchedbraceforecolor"));
_sci.sendEditor(QScintilla.SCI_STYLESETBACK, QScintilla.STYLE_BRACEBAD, Setting.getColorRef("matchedbracebackcolor"));
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_COMMENTDOCKEYWORD, Setting.getColorRef("doccommentkeyforecolor"));
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_COMMENTDOCKEYWORDERROR, Setting.getColorRef("doccommenterrforeforecolor"));
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_GLOBALCLASS, Setting.getColorRef("globalclassforecolor"));
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_OPERATOR, Setting.getColorRef("operatorforecolor"));
_sci.sendEditor(QScintilla.SCI_STYLESETBACK, QScintilla.SCE_C_STRINGEOL, Setting.getColorRef("stringeolcolor"));
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_WORD, Setting.getColorRef("wordforecolor"));
//_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_WORD2, Setting.getColorRef("word2forecolor"));
//_sci.sendEditor(QScintilla.SCI_STYLESETBOLD, QScintilla.SCE_C_WORD2, 1);
_sci.sendEditor(QScintilla.SCI_STYLESETBACK, QScintilla.SCE_C_WORD2, Setting.getColorRef("word2backcolor"));
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_STRING, Setting.getColorRef("stringforecolor"));
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_NUMBER, Setting.getColorRef("numberforecolor"));
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_CHARACTER, Setting.getColorRef("charforecolor"));
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_PREPROCESSOR, Setting.getColorRef("preprocessorforecolor"));
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_COMMENT, Setting.getColorRef("commentforecolor"));
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_COMMENTLINE, Setting.getColorRef("commentlineforecolor"));
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_COMMENTDOC, Setting.getColorRef("doccommentforecolor"));
_sci.sendEditor(QScintilla.SCI_CALLTIPSETBACK, Setting.getColorRef("calltipsbackcolor"));
_sci.sendEditor(QScintilla.SCI_CALLTIPSETFORE, Setting.getColorRef("calltipsforecolor"));
//_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_COMMENTDOC, 0xff504f4f);
_sci.sendEditor(QScintilla.SCI_SETCARETFORE,Setting.getColorRef("caretcolor"),0);
_sci.sendEditor(QScintilla.SCI_SETCARETLINEVISIBLE, 1);
_sci.sendEditor(QScintilla.SCI_SETCARETLINEBACK, Setting.getColorRef("caretlinebackcolor"));
_sci.sendEditor(QScintilla.SCI_SETCARETLINEFRAME, 2);
_sci.sendEditor(QScintilla.SCI_SETTABWIDTH, 4);
_sci.sendEditor(QScintilla.SCI_SETEOLMODE, QScintilla.SC_EOL_LF, 0);
_sci.setIndicForeColor(INDIC_TIPS, Setting.getColorRef("indicforecolor"));
_sci.setIndicUnder(INDIC_TIPS, true);
if (Setting.isShowFolding()) {
_sci.sendEditor(QScintilla.SCI_SETPROPERTY,"fold","1");
_sci.sendEditor(QScintilla.SCI_SETPROPERTY,"fold.comment","1");
_sci.sendEditor(QScintilla.SCI_SETMARGINTYPEN, MARGIN_FOLD_INDEX, QScintilla.SC_MARGIN_SYMBOL);//页边类型
_sci.sendEditor(QScintilla.SCI_SETMARGINMASKN, MARGIN_FOLD_INDEX, QScintilla.SC_MASK_FOLDERS); //页边掩码
_sci.sendEditor(QScintilla.SCI_SETFOLDMARGINCOLOUR, 1, Setting.getColorRef("foldmargincolor"));
_sci.sendEditor(QScintilla.SCI_SETFOLDMARGINHICOLOUR, 1, Setting.getColorRef("foldmarginhicolor"));
setFoldHighLight(Setting.getColorRef("foldhicolor"));
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN, MARGIN_FOLD_INDEX, 11); //页边宽度
_sci.sendEditor(QScintilla.SCI_SETMARGINSENSITIVEN, MARGIN_FOLD_INDEX, 1); //响应鼠标消息
// 折叠标签样式 //折叠页边颜色
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, QScintilla.SC_MARKNUM_FOLDER, QScintilla.SC_MARK_BOXPLUS);
_sci.sendEditor(QScintilla.SCI_MARKERSETFORE,QScintilla.SC_MARKNUM_FOLDER,Setting.getColorRef("folderforecolor"));
_sci.sendEditor(QScintilla.SCI_MARKERSETBACK,QScintilla.SC_MARKNUM_FOLDER,Setting.getColorRef("folderbackcolor"));
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, QScintilla.SC_MARKNUM_FOLDEROPEN, QScintilla.SC_MARK_BOXMINUS);
setMarginColor(QScintilla.SC_MARKNUM_FOLDEROPEN,Setting.getColorRef("folderopenforecolor"), Setting.getColorRef("folderopenbackcolor"));
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, QScintilla.SC_MARKNUM_FOLDEREND, QScintilla.SC_MARK_BOXPLUSCONNECTED);
setMarginColor(QScintilla.SC_MARKNUM_FOLDEREND,Setting.getColorRef("folderendforecolor"), Setting.getColorRef("folderendbackcolor"));
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, QScintilla.SC_MARKNUM_FOLDEROPENMID, QScintilla.SC_MARK_BOXMINUSCONNECTED);
setMarginColor(QScintilla.SC_MARKNUM_FOLDEROPENMID,Setting.getColorRef("foldermidforecolor"), Setting.getColorRef("foldermidbackcolor"));
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, QScintilla.SC_MARKNUM_FOLDERMIDTAIL, QScintilla.SC_MARK_TCORNER);
setMarginColor(QScintilla.SC_MARKNUM_FOLDERMIDTAIL,Setting.getColorRef("foldermidtailforecolor"), Setting.getColorRef("foldermidtailbackcolor"));
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, QScintilla.SC_MARKNUM_FOLDERSUB, QScintilla.SC_MARK_VLINE);
setMarginColor(QScintilla.SC_MARKNUM_FOLDERSUB,Setting.getColorRef("foldersubforecolor"), Setting.getColorRef("foldersubbackcolor"));
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, QScintilla.SC_MARKNUM_FOLDERTAIL, QScintilla.SC_MARK_LCORNER);
setMarginColor(QScintilla.SC_MARKNUM_FOLDERTAIL,Setting.getColorRef("foldertailforecolor"), Setting.getColorRef("foldertailbackcolor"));
} else {
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN, MARGIN_FOLD_INDEX, 0); //页边宽度
}
}
else{
SyntaxHighlighting colorConfig = _textplugins.getColorConfigure(darkStyle ? "dark" : "light");
if (colorConfig != nilptr) {
updatesuccess = true;
_sci.sendEditor(QScintilla.SCI_CLEARDOCUMENTSTYLE, 0, 0);
_sci.sendEditor(QScintilla.SCI_SETLEXER, QScintilla.SCLEX_CPP, 0);
_sci.sendEditor(QScintilla.SCI_SETCODEPAGE, QScintilla.SC_CP_UTF8);
_sci.sendEditor(QScintilla.SCI_STYLESETBACK, QScintilla.STYLE_DEFAULT, colorConfig.getDefaultBackColor());
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.STYLE_DEFAULT, colorConfig.getDefaultForeColor());
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, 75, colorConfig.getDefaultForeColor());
//_sci.sendEditor(QScintilla.STYLE_LINENUMBER, 1, 0);
//bool bmac = (_system_.getPlatformId() == 2);
_sci.sendEditor(QScintilla.SCI_STYLESETFONT, QScintilla.STYLE_DEFAULT,Setting.getEditorFont());
_sci.sendEditor(QScintilla.SCI_STYLESETSIZEFRACTIONAL, QScintilla.STYLE_DEFAULT,Setting.getEditorFontSize());
_sci.sendEditor(QScintilla.SCI_STYLECLEARALL, 0, 0);
_sci.sendEditor(QScintilla.SCI_SETSELBACK,1,colorConfig.getSelectedBackColor());
_sci.sendEditor(QScintilla.SCI_SETSELFORE,0,colorConfig.getSelectedForeColor());
//C++语法解析
_sci.sendEditor(QScintilla.SCI_SETLEXER, QScintilla.SCLEX_CPP, 0);
_sci.sendEditor(QScintilla.SCI_SETKEYWORDS, 0, szKeywords1);//设置关键字
_sci.sendEditor(QScintilla.SCI_SETKEYWORDS, 1, szKeywords2);//设置关键字
// 下面设置各种语法元素风格
_sci.sendEditor(QScintilla.SCI_SETEOLMODE, 1, 0);
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, MARK_BREAKPOINT, 0);
_sci.sendEditor(QScintilla.SCI_MARKERSETBACK, MARK_BREAKPOINT,colorConfig.getBreakPointBackColor());
_sci.sendEditor(QScintilla.SCI_MARKERSETFORE, MARK_BREAKPOINT,colorConfig.getBreakPointForeColor());
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, MARK_POINTER,4);
_sci.sendEditor(QScintilla.SCI_MARKERSETFORE, MARK_POINTER,colorConfig.getMarkPointBackColor());
_sci.sendEditor(QScintilla.SCI_MARKERSETBACK, MARK_POINTER,colorConfig.getMarkPointForeColor());
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE,MARK_MODIFIED,25);
_sci.sendEditor(QScintilla.SCI_MARKERSETFORE,MARK_MODIFIED,colorConfig.getModifiedMarkForeColor());
_sci.sendEditor(QScintilla.SCI_MARKERSETBACK,MARK_MODIFIED,colorConfig.getModifiedMarkBackColor());
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE,MARK_SAVED,25);
_sci.sendEditor(QScintilla.SCI_MARKERSETFORE,MARK_SAVED,colorConfig.getSavedMarkForeColor());
_sci.sendEditor(QScintilla.SCI_MARKERSETBACK,MARK_SAVED,colorConfig.getSavedMarkBackColor());
current_modify_mark = MARK_MODIFIED;
reserve_modify_mark = MARK_SAVED;
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN,BREAKPOINT_INDEX, 15);
_sci.sendEditor(QScintilla.SCI_SETMARGINSENSITIVEN,BREAKPOINT_INDEX, 1);
if (Setting.isIndentGuide()) {
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.STYLE_INDENTGUIDE, colorConfig.getIndentGuideColor());
_sci.sendEditor(QScintilla.SCI_SETINDENTATIONGUIDES, QScintilla.SC_IV_LOOKBOTH);
} else {
_sci.sendEditor(QScintilla.SCI_SETINDENTATIONGUIDES, QScintilla.SC_IV_NONE);
}
if (Setting.isShowLineNumber()) {
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN,LINENUMBER_INDEX, 40);
} else {
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN,LINENUMBER_INDEX, 0);
}
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN,DEBUGPOINT_INDEX, 15);
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN,MODIFIMARK_INDEX, 3);
//_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN,4, 0);
_sci.sendEditor(QScintilla.SCI_SETMARGINTYPEN, BREAKPOINT_INDEX, QScintilla.SC_MARGIN_SYMBOL);
_sci.sendEditor(QScintilla.SCI_SETMARGINMASKN, BREAKPOINT_INDEX, 1 << MARK_BREAKPOINT);
_sci.sendEditor(QScintilla.SCI_SETMARGINTYPEN, LINENUMBER_INDEX, QScintilla.SC_MARGIN_NUMBER);
_sci.sendEditor(QScintilla.SCI_SETMARGINMASKN, LINENUMBER_INDEX, 0);
_sci.sendEditor(QScintilla.SCI_SETMARGINTYPEN, DEBUGPOINT_INDEX, QScintilla.SC_MARGIN_SYMBOL);
_sci.sendEditor(QScintilla.SCI_SETMARGINMASKN, DEBUGPOINT_INDEX, (1 << MARK_POINTER));
_sci.sendEditor(QScintilla.SCI_SETMARGINTYPEN, MODIFIMARK_INDEX, QScintilla.SC_MARGIN_SYMBOL);
_sci.sendEditor(QScintilla.SCI_SETMARGINMASKN, MODIFIMARK_INDEX, (1 << MARK_MODIFIED) | (1 << MARK_SAVED) );
_sci.sendEditor(QScintilla.SCI_STYLESETBACK, QScintilla.STYLE_LINENUMBER, colorConfig.getLineNumberBackColor());
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.STYLE_LINENUMBER, colorConfig.getLineNumberForeColor());
_sci.sendEditor(QScintilla.SCI_SETMARGINLEFT, 0, 0);
_sci.sendEditor(QScintilla.SCI_STYLESETBOLD, QScintilla.STYLE_BRACELIGHT, 1);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.STYLE_BRACELIGHT, colorConfig.getMatchedBraceForeColor());
_sci.sendEditor(QScintilla.SCI_STYLESETBACK, QScintilla.STYLE_BRACEBAD, colorConfig.getMatchedBraceBackColor());
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_COMMENTDOCKEYWORD, colorConfig.getDocCommentKeyForeColor());
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_COMMENTDOCKEYWORDERROR, colorConfig.getDocCommentErrForeForeColor());
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_GLOBALCLASS, colorConfig.getGlobalClassForeColor());
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_OPERATOR, colorConfig.getOperatorForeColor()/* 0xff859dd6 0xffFEE7Bf*/);
_sci.sendEditor(QScintilla.SCI_STYLESETBACK, QScintilla.SCE_C_STRINGEOL, colorConfig.getStringEOLColor());
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_WORD, colorConfig.getWordForeColor());
_sci.sendEditor(QScintilla.SCI_STYLESETBOLD, QScintilla.SCE_C_WORD, 1);
//_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_WORD2, colorConfig.getWord2ForeColor());
//_sci.sendEditor(QScintilla.SCI_STYLESETBOLD, QScintilla.SCE_C_WORD2, 1);
_sci.sendEditor(QScintilla.SCI_STYLESETBACK, QScintilla.SCE_C_WORD2, colorConfig.getWord2BackColor());
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_STRING, colorConfig.getStringForeColor());
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_NUMBER, colorConfig.getNumberForeColor());
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_CHARACTER, colorConfig.getCharForeColor());
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_PREPROCESSOR, colorConfig.getPreprocessorForeColor());
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_COMMENT, colorConfig.getCommentForeColor());
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_COMMENTLINE, colorConfig.getCommentLineForeColor());
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_COMMENTDOC, colorConfig.getDocCommentForeColor());
_sci.sendEditor(QScintilla.SCI_CALLTIPSETBACK, colorConfig.getCallTipsBackColor());
_sci.sendEditor(QScintilla.SCI_CALLTIPSETFORE, colorConfig.getCallTipsForeColor());
//_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_COMMENTDOC, 0xff504f4f);
_sci.sendEditor(QScintilla.SCI_SETCARETFORE,colorConfig.getCaretColor(),0);
_sci.sendEditor(QScintilla.SCI_SETCARETLINEVISIBLE, 1);
_sci.sendEditor(QScintilla.SCI_SETCARETLINEBACK, colorConfig.getCaretLineBackColor());
_sci.sendEditor(QScintilla.SCI_SETCARETLINEFRAME, 2);
_sci.sendEditor(QScintilla.SCI_SETTABWIDTH, 4);
_sci.sendEditor(QScintilla.SCI_SETEOLMODE, QScintilla.SC_EOL_LF, 0);
_sci.setIndicForeColor(INDIC_TIPS, colorConfig.getIndicForeColor());
_sci.setIndicUnder(INDIC_TIPS, true);
if (Setting.isShowFolding()) {
_sci.sendEditor(QScintilla.SCI_SETPROPERTY,"fold","1");
_sci.sendEditor(QScintilla.SCI_SETPROPERTY,"fold.comment","1");
_sci.sendEditor(QScintilla.SCI_SETMARGINTYPEN, MARGIN_FOLD_INDEX, QScintilla.SC_MARGIN_SYMBOL);//页边类型
_sci.sendEditor(QScintilla.SCI_SETMARGINMASKN, MARGIN_FOLD_INDEX, QScintilla.SC_MASK_FOLDERS); //页边掩码
_sci.sendEditor(QScintilla.SCI_SETFOLDMARGINCOLOUR, 1, colorConfig.getFoldMarginColor());
_sci.sendEditor(QScintilla.SCI_SETFOLDMARGINHICOLOUR, 1, colorConfig.getFoldMarginHIColor());
setFoldHighLight(colorConfig.getFoldHIColor());
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN, MARGIN_FOLD_INDEX, 11); //页边宽度
_sci.sendEditor(QScintilla.SCI_SETMARGINSENSITIVEN, MARGIN_FOLD_INDEX, 1); //响应鼠标消息
// 折叠标签样式 //折叠页边颜色
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, QScintilla.SC_MARKNUM_FOLDER, QScintilla.SC_MARK_BOXPLUS);
_sci.sendEditor(QScintilla.SCI_MARKERSETFORE,QScintilla.SC_MARKNUM_FOLDER,colorConfig.getFolderForeColor());
_sci.sendEditor(QScintilla.SCI_MARKERSETBACK,QScintilla.SC_MARKNUM_FOLDER,colorConfig.getFolderBackColor());
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, QScintilla.SC_MARKNUM_FOLDEROPEN, QScintilla.SC_MARK_BOXMINUS);
setMarginColor(QScintilla.SC_MARKNUM_FOLDEROPEN,colorConfig.getFolderOpenForeColor(), colorConfig.getFolderOpenBackColor());
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, QScintilla.SC_MARKNUM_FOLDEREND, QScintilla.SC_MARK_BOXPLUSCONNECTED);
setMarginColor(QScintilla.SC_MARKNUM_FOLDEREND,colorConfig.getFolderEndForeColor(), colorConfig.getFolderEndBackColor());
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, QScintilla.SC_MARKNUM_FOLDEROPENMID, QScintilla.SC_MARK_BOXMINUSCONNECTED);
setMarginColor(QScintilla.SC_MARKNUM_FOLDEROPENMID,colorConfig.getFolderMidForeColor(), colorConfig.getFolderMidBackColor());
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, QScintilla.SC_MARKNUM_FOLDERMIDTAIL, QScintilla.SC_MARK_TCORNER);
setMarginColor(QScintilla.SC_MARKNUM_FOLDERMIDTAIL,colorConfig.getFolderMidTailForeColor(), colorConfig.getFolderMidTailBackColor());
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, QScintilla.SC_MARKNUM_FOLDERSUB, QScintilla.SC_MARK_VLINE);
setMarginColor(QScintilla.SC_MARKNUM_FOLDERSUB,colorConfig.getFolderSubForeColor(), colorConfig.getFolderSubBackColor());
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, QScintilla.SC_MARKNUM_FOLDERTAIL, QScintilla.SC_MARK_LCORNER);
setMarginColor(QScintilla.SC_MARKNUM_FOLDERTAIL,colorConfig.getFolderTailForeColor(), colorConfig.getFolderTailBackColor());
} else {
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN, MARGIN_FOLD_INDEX, 0); //页边宽度
}
}
}
}
_sci.sendEditor(QScintilla.SCI_SETMARGINSENSITIVEN, DEBUGPOINT_INDEX, 1); //响应鼠标消息
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE,ERRORPOINT_INDEX,23);
_sci.sendEditor(QScintilla.SCI_MARKERSETFORE,ERRORPOINT_INDEX,0xff0000ff);
_sci.sendEditor(QScintilla.SCI_MARKERSETBACK,ERRORPOINT_INDEX,0xff0000ff);
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE,WARNING_INDEX,23);
_sci.sendEditor(QScintilla.SCI_MARKERSETFORE,WARNING_INDEX,0xff0088ff);
_sci.sendEditor(QScintilla.SCI_MARKERSETBACK,WARNING_INDEX,0xff0088ff);
_sci.sendEditor(QScintilla.SCI_SETMARGINMASKN, DEBUGPOINT_INDEX, (1 << MARK_POINTER) | (1 << WARNING_INDEX) | (1 << ERRORPOINT_INDEX));
_sci.setIndicForeColor(INDIC_WARNING, 0x0088FF);
_sci.setIndicForeColor(INDIC_FIND, 0xffff00);
_sci.setIndicUnder(INDIC_FIND, true);
//_sci.setIndicAlpha(INDIC_FIND, 255);
//_sci.setIndicOutlineAlpha(INDIC_FIND, 255);
_sci.setIndicForeColor(INDIC_SELECTED, 0xff0000);
_sci.setIndicUnder(INDIC_SELECTED, true);
if (updatesuccess == false) {
_sci.setIndicForeColor(INDIC_TIPS, 0xff00ffff);
_sci.setIndicUnder(INDIC_TIPS, true);
syntaxForXlang();
}
if (_textplugins != nilptr){
_textplugins.configEditor(_mdi_area.getCurrentProject(), getFilePath(), _sci, darkStyle);
}
_sci.setIndentationsUseTabs(Setting.isUseTabstop());
_sci.sendEditor(QScintilla.SCI_SETTABWIDTH, Setting.getTabWidth());
_sci.setIndicCurrent(INDIC_TIPS);
_sci.setWrap(Setting.isEditWrap());
_sci.sendEditor(QScintilla.SCI_COLOURISE, 0, -1);
_sci.setLinespacing(1.28f);
_sci.enableScrollBarMarker(true);
_sci.setScrollBarMarker(MARK_MODIFIED, 0, 0xffffd800);
_sci.setScrollBarMarker(MARK_SAVED, 0, 0xff15c23c);
_sci.setScrollBarMarker(ERRORPOINT_INDEX, 1, 0xffff0000);
_sci.setScrollBarMarker(WARNING_INDEX, 1, 0xffff8800);
_sci.setScrollBarMarker(MARK_BREAKPOINT, 2, 0xff8B4C79);
/*_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_COMMENT | 64,0xffeeeeee);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_COMMENTLINE | 64,0xffeeeeee);
*/
/*
WIN32=1 WIN32_LEAN_AND_MEAN NOGDI=0 SCI_SETLEXERLANGUAGE
scintilla.Styles[Style.Cpp.Default + 64].BackColor = Color.LightGray;
scintilla.Styles[Style.Cpp.Comment + 64].BackColor = Color.LightGray;
*/
updateInformationPoint();
}
Map<long, ICompileInfo> __hoverhelps = new Map<long,ICompileInfo>();
Map<long, ICompileInfo> __marginhelps = new Map<long, ICompileInfo>();
public void updateInformationPoint(){
resetInformationPoint();
Vector<ICompileInfo> ii = XWndInfor.GetDocumentPoint(_mdi_area.getCurrentProject(), getFilePath(), ICompileInfo.ERROR);
mergeDiagnosis(ii);
processDiagnosisInfor(ii.toArray(new ICompileInfo[ii.size()]));
}
public void processDiagnosisInfor(ICompileInfo [] ii){
for (int i = 0; i < ii.length; i++){
ICompileInfo ci = ii[i];
int line = ci.getLine() - 1;
int pos = _sci.getPosition(line) + ci.getRow() - 1;
__hoverhelps.put(pos,ci);
if (ci.getType() == ICompileInfo.ERROR){
updateErrorPoint(pos, ci.getLength());
}else
if (ci.getType() == ICompileInfo.WARNING){
updateWarningPoint(pos, ci.getLength());
}
}
}
static class DocumentICompileInfo : ICompileInfo{
DiagnosisInformation di;
String file;
int length;
public DocumentICompileInfo(String f, DiagnosisInformation d, int len){
file = f;
length = len;
di = d;
}
public int getType(){
return di.getType();
}
public String getFile(){
return file;
}
public int getLine(){
return di.getLine(false);
}
public int getLength(){
return length;
}
public int getRow(){
return di.getCharacter(false);
}
public @NotNilptr String getTips(){
return di.getMessage();
}
public @NotNilptr String getTitle(){
return "诊断信息:";
}
};
public void mergeDiagnosis(Vector<ICompileInfo> list){
String file = getFilePath();
DiagnosisInformation [] info = _mdi_area.getDiagnosisInformation(file);
if (info != nilptr){
for (int i = 0; i < info.length ; i++){
int startline = info[i].getLine(false);
int startcolumn = info[i].getCharacter(false);
int endline = info[i].getLine(true);
int endcolumn = info[i].getCharacter(true);
int startpos = _sci.getPosition(startline) + startcolumn;
int endpos = _sci.getPosition(endline) + endcolumn;
list.add(new DocumentICompileInfo(file, info[i], endpos - startpos + 1));
}
}
}
public void updateErrorPoint(int pos, int length){
int line = _sci.positionToLine(pos);
_sci.sendEditor(QScintilla.SCI_MARKERADD, line, ERRORPOINT_INDEX);
_sci.setIndicCurrent(INDIC_ERROR);
_sci.applyIndic(pos, length > 0 ? length : 1);
}
public void updateWarningPoint(int pos, int length){
int line = _sci.positionToLine(pos);
_sci.sendEditor(QScintilla.SCI_MARKERADD, line, WARNING_INDEX);
_sci.setIndicCurrent(INDIC_WARNING);
_sci.applyIndic(pos, length > 0 ? length : 1);
}
public void markSelected(int pos, int length){
_sci.setIndicCurrent(INDIC_SELECTED);
_sci.applyIndic(pos, length > 0 ? length : 1);
}
public void markFound(int pos, int length){
_sci.setIndicCurrent(INDIC_FIND);
_sci.applyIndic(pos, length > 0 ? length : 1);
}
public String contentToString()override{
return _sci.getText();
}
public void setFoldHighLight(int color){
_sci.sendEditor(QScintilla.SCI_MARKERENABLEHIGHLIGHT,1);
_sci.sendEditor(QScintilla.SCI_MARKERSETBACKSELECTED, QScintilla.SC_MARKNUM_FOLDER, color);
_sci.sendEditor(QScintilla.SCI_MARKERSETBACKSELECTED, QScintilla.SC_MARKNUM_FOLDEROPEN, color);
_sci.sendEditor(QScintilla.SCI_MARKERSETBACKSELECTED, QScintilla.SC_MARKNUM_FOLDEREND, color);
_sci.sendEditor(QScintilla.SCI_MARKERSETBACKSELECTED, QScintilla.SC_MARKNUM_FOLDEROPENMID, color);
_sci.sendEditor(QScintilla.SCI_MARKERSETBACKSELECTED, QScintilla.SC_MARKNUM_FOLDERMIDTAIL, color);
_sci.sendEditor(QScintilla.SCI_MARKERSETBACKSELECTED, QScintilla.SC_MARKNUM_FOLDERSUB, color);
_sci.sendEditor(QScintilla.SCI_MARKERSETBACKSELECTED, QScintilla.SC_MARKNUM_FOLDERTAIL, color);
}
public void syntaxForXlangDark() {
//_sci.sendEditor(QScintilla.SCI_STYLECLEARALL, 0, 0);
_sci.sendEditor(QScintilla.SCI_CLEARDOCUMENTSTYLE, 0, 0);
_sci.sendEditor(QScintilla.SCI_SETLEXER, QScintilla.SCLEX_CPP, 0);
_sci.sendEditor(QScintilla.SCI_SETCODEPAGE, QScintilla.SC_CP_UTF8);
_sci.sendEditor(QScintilla.SCI_STYLESETBACK, QScintilla.STYLE_DEFAULT, 0xff222827);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.STYLE_DEFAULT, 0xffefefef);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, 75, 0xffefefef);
//_sci.sendEditor(QScintilla.STYLE_LINENUMBER, 1, 0);
//bool bmac = (_system_.getPlatformId() == 2);
_sci.sendEditor(QScintilla.SCI_STYLESETFONT, QScintilla.STYLE_DEFAULT,Setting.getEditorFont());
_sci.sendEditor(QScintilla.SCI_STYLESETSIZEFRACTIONAL, QScintilla.STYLE_DEFAULT,Setting.getEditorFontSize());
_sci.sendEditor(QScintilla.SCI_STYLECLEARALL, 0, 0);
_sci.sendEditor(QScintilla.SCI_SETSELBACK,1,0xff3e4849);
_sci.sendEditor(QScintilla.SCI_SETSELFORE,0,0);
//C++语法解析
_sci.sendEditor(QScintilla.SCI_SETLEXER, QScintilla.SCLEX_CPP, 0);
_sci.sendEditor(QScintilla.SCI_SETKEYWORDS, 0, szKeywords1);//设置关键字
_sci.sendEditor(QScintilla.SCI_SETKEYWORDS, 1, szKeywords2);//设置关键字
// 下面设置各种语法元素风格
_sci.sendEditor(QScintilla.SCI_SETEOLMODE, 1, 0);
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, MARK_BREAKPOINT, 0);
_sci.sendEditor(QScintilla.SCI_MARKERSETBACK, MARK_BREAKPOINT,0xff0000ff);
_sci.sendEditor(QScintilla.SCI_MARKERSETFORE, MARK_BREAKPOINT,0xffffffff);
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, MARK_POINTER,4);
_sci.sendEditor(QScintilla.SCI_MARKERSETFORE, MARK_POINTER,0xff7f7f00);
_sci.sendEditor(QScintilla.SCI_MARKERSETBACK, MARK_POINTER,0xffcee7ce);
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE,MARK_MODIFIED,25);
_sci.sendEditor(QScintilla.SCI_MARKERSETFORE,MARK_MODIFIED,0xff00d8ff);
_sci.sendEditor(QScintilla.SCI_MARKERSETBACK,MARK_MODIFIED,0xff00d8ff);
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE,MARK_SAVED,25);
_sci.sendEditor(QScintilla.SCI_MARKERSETFORE,MARK_SAVED,0xff00d8ff);
_sci.sendEditor(QScintilla.SCI_MARKERSETBACK,MARK_SAVED,0xff00d8ff);
current_modify_mark = MARK_MODIFIED;
reserve_modify_mark = MARK_SAVED;
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN,BREAKPOINT_INDEX, 15);
_sci.sendEditor(QScintilla.SCI_SETMARGINSENSITIVEN,BREAKPOINT_INDEX, 1);
if (Setting.isIndentGuide()) {
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.STYLE_INDENTGUIDE, 0xff464849);
_sci.sendEditor(QScintilla.SCI_SETINDENTATIONGUIDES, QScintilla.SC_IV_LOOKBOTH);
} else {
_sci.sendEditor(QScintilla.SCI_SETINDENTATIONGUIDES, QScintilla.SC_IV_NONE);
}
if (Setting.isShowLineNumber()) {
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN,LINENUMBER_INDEX, 40);
} else {
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN,LINENUMBER_INDEX, 0);
}
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN,DEBUGPOINT_INDEX, 15);
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN,MODIFIMARK_INDEX, 3);
//_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN,4, 0);
_sci.sendEditor(QScintilla.SCI_SETMARGINTYPEN, BREAKPOINT_INDEX, QScintilla.SC_MARGIN_SYMBOL);
_sci.sendEditor(QScintilla.SCI_SETMARGINMASKN, BREAKPOINT_INDEX, 1 << MARK_BREAKPOINT);
_sci.sendEditor(QScintilla.SCI_SETMARGINTYPEN, LINENUMBER_INDEX, QScintilla.SC_MARGIN_NUMBER);
_sci.sendEditor(QScintilla.SCI_SETMARGINMASKN, LINENUMBER_INDEX, 0);
_sci.sendEditor(QScintilla.SCI_SETMARGINTYPEN, DEBUGPOINT_INDEX, QScintilla.SC_MARGIN_SYMBOL);
_sci.sendEditor(QScintilla.SCI_SETMARGINMASKN, DEBUGPOINT_INDEX, 1 << MARK_POINTER);
_sci.sendEditor(QScintilla.SCI_SETMARGINTYPEN, MODIFIMARK_INDEX, QScintilla.SC_MARGIN_SYMBOL);
_sci.sendEditor(QScintilla.SCI_SETMARGINMASKN, MODIFIMARK_INDEX, (1 << MARK_MODIFIED) | (1 << MARK_SAVED));
_sci.sendEditor(QScintilla.SCI_STYLESETBACK, QScintilla.STYLE_LINENUMBER, 0xff222827);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.STYLE_LINENUMBER, 0xffaf912b);
_sci.sendEditor(QScintilla.SCI_SETMARGINLEFT, 0, 0);
_sci.sendEditor(QScintilla.SCI_STYLESETBOLD, QScintilla.STYLE_BRACELIGHT, 1);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.STYLE_BRACELIGHT, 0xff00ffff);
_sci.sendEditor(QScintilla.SCI_STYLESETBACK, QScintilla.STYLE_BRACEBAD, 0xffff00ff);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_COMMENTDOCKEYWORD, 0xffA06030);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_COMMENTDOCKEYWORDERROR, 0xff204080);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_GLOBALCLASS, 0xff0099dd);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_OPERATOR, 0xff6e28ed/* 0xff859dd6 0xffFEE7Bf*/);
_sci.sendEditor(QScintilla.SCI_STYLESETBACK, QScintilla.SCE_C_STRINGEOL, 0xffE0C0E0);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_WORD, 0xffF0D964);
//_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_WORD2, 0xff2ae27f);
//_sci.sendEditor(QScintilla.SCI_STYLESETBOLD, QScintilla.SCE_C_WORD2, 1);
_sci.sendEditor(QScintilla.SCI_STYLESETBACK, QScintilla.SCE_C_WORD2, 0xff6f3d11);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_STRING, 0xff73DBE6);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_NUMBER, 0xffc563bd/*0xffA8CEB5*/);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_CHARACTER, 0xff73DBE6);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_PREPROCESSOR, 0x00808080);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_COMMENT, 0xff666666);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_COMMENTLINE, 0xff666666);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_COMMENTDOC, 0x00008000);
_sci.sendEditor(QScintilla.SCI_CALLTIPSETBACK, 0xff454242);
_sci.sendEditor(QScintilla.SCI_CALLTIPSETFORE, 0xffefefef);
//_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_COMMENTDOC, 0xff504f4f);
_sci.sendEditor(QScintilla.SCI_SETCARETFORE,0xffffffff,0);
_sci.sendEditor(QScintilla.SCI_SETCARETLINEVISIBLE, 1);
_sci.sendEditor(QScintilla.SCI_SETCARETLINEBACK, 0xff202020);
_sci.sendEditor(QScintilla.SCI_SETCARETLINEFRAME, 2);
_sci.sendEditor(QScintilla.SCI_SETTABWIDTH, 4);
_sci.sendEditor(QScintilla.SCI_SETEOLMODE, QScintilla.SC_EOL_LF, 0);
if (Setting.isShowFolding()) {
_sci.sendEditor(QScintilla.SCI_SETPROPERTY,"fold","1");
_sci.sendEditor(QScintilla.SCI_SETPROPERTY,"fold.comment","1");
_sci.sendEditor(QScintilla.SCI_SETMARGINTYPEN, MARGIN_FOLD_INDEX, QScintilla.SC_MARGIN_SYMBOL);//页边类型
_sci.sendEditor(QScintilla.SCI_SETMARGINMASKN, MARGIN_FOLD_INDEX, QScintilla.SC_MASK_FOLDERS); //页边掩码
_sci.sendEditor(QScintilla.SCI_SETFOLDMARGINCOLOUR, 1, 0xff222827);
_sci.sendEditor(QScintilla.SCI_SETFOLDMARGINHICOLOUR, 1, 0xff404142);
setFoldHighLight(0xffffffff);
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN, MARGIN_FOLD_INDEX, 11); //页边宽度
_sci.sendEditor(QScintilla.SCI_SETMARGINSENSITIVEN, MARGIN_FOLD_INDEX, 1); //响应鼠标消息
// 折叠标签样式 //折叠页边颜色
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, QScintilla.SC_MARKNUM_FOLDER, QScintilla.SC_MARK_BOXPLUS);
_sci.sendEditor(QScintilla.SCI_MARKERSETFORE,QScintilla.SC_MARKNUM_FOLDER,0xff222827);
_sci.sendEditor(QScintilla.SCI_MARKERSETBACK,QScintilla.SC_MARKNUM_FOLDER,0xff7f7f7f);
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, QScintilla.SC_MARKNUM_FOLDEROPEN, QScintilla.SC_MARK_BOXMINUS);
setMarginColor(QScintilla.SC_MARKNUM_FOLDEROPEN,0xff222827, 0xff7f7f7f);
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, QScintilla.SC_MARKNUM_FOLDEREND, QScintilla.SC_MARK_BOXPLUSCONNECTED);
setMarginColor(QScintilla.SC_MARKNUM_FOLDEREND,0xff222827, 0xff7f7f7f);
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, QScintilla.SC_MARKNUM_FOLDEROPENMID, QScintilla.SC_MARK_BOXMINUSCONNECTED);
setMarginColor(QScintilla.SC_MARKNUM_FOLDEROPENMID,0xff222827, 0xff7f7f7f);
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, QScintilla.SC_MARKNUM_FOLDERMIDTAIL, QScintilla.SC_MARK_TCORNER);
setMarginColor(QScintilla.SC_MARKNUM_FOLDERMIDTAIL,0xff222827, 0xff7f7f7f);
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, QScintilla.SC_MARKNUM_FOLDERSUB, QScintilla.SC_MARK_VLINE);
setMarginColor(QScintilla.SC_MARKNUM_FOLDERSUB,0xff222827, 0xff7f7f7f);
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, QScintilla.SC_MARKNUM_FOLDERTAIL, QScintilla.SC_MARK_LCORNER);
setMarginColor(QScintilla.SC_MARKNUM_FOLDERTAIL,0xff222827, 0xff7f7f7f);
} else {
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN, MARGIN_FOLD_INDEX, 0); //页边宽度
}
// 折叠标签颜色
}
public void setMarginColor(int id, int fore, int back) {
_sci.sendEditor(QScintilla.SCI_MARKERSETFORE, id, fore);
_sci.sendEditor(QScintilla.SCI_MARKERSETBACK, id, back);
}
public static void reconfig() {
Map.Iterator<String, DocumentView> iterator = editorMgr.iterator();
while (iterator.hasNext()) {
DocumentView wnd = iterator.getValue();
if (wnd != nilptr){
wnd.updateConfig();
}
iterator.next();
}
}
public void syntaxForXlang() {
if (Setting.isDarkStyle()) {
syntaxForXlangDark();
return ;
}
//_sci.sendEditor(QScintilla.SCI_STYLECLEARALL, 0, 0);
_sci.sendEditor(QScintilla.SCI_CLEARDOCUMENTSTYLE, 0, 0);
_sci.sendEditor(QScintilla.SCI_SETLEXER, QScintilla.SCLEX_CPP, 0);
_sci.sendEditor(QScintilla.SCI_SETCODEPAGE, QScintilla.SC_CP_UTF8);
_sci.sendEditor(QScintilla.SCI_STYLESETBACK, QScintilla.STYLE_DEFAULT, 0xffffffff);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.STYLE_DEFAULT, 0xff222827);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, 75, 0xff222827);
//_sci.sendEditor(QScintilla.STYLE_LINENUMBER, 1, 0);
_sci.sendEditor(QScintilla.SCI_STYLESETFONT, QScintilla.STYLE_DEFAULT,Setting.getEditorFont());
_sci.sendEditor(QScintilla.SCI_STYLESETSIZEFRACTIONAL, QScintilla.STYLE_DEFAULT,Setting.getEditorFontSize());
_sci.sendEditor(QScintilla.SCI_STYLECLEARALL, 0, 0);
_sci.sendEditor(QScintilla.SCI_SETSELBACK,1,0xfff1ebe5);
_sci.sendEditor(QScintilla.SCI_SETSELFORE,0,0);
//C++语法解析
_sci.sendEditor(QScintilla.SCI_SETLEXER, QScintilla.SCLEX_CPP, 0);
_sci.sendEditor(QScintilla.SCI_SETKEYWORDS, 0, szKeywords1);//设置关键字
_sci.sendEditor(QScintilla.SCI_SETKEYWORDS, 1, szKeywords2);//设置关键字
// 下面设置各种语法元素风格
_sci.sendEditor(QScintilla.SCI_SETEOLMODE, 1, 0);
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, MARK_BREAKPOINT, 0);
_sci.sendEditor(QScintilla.SCI_MARKERSETBACK, MARK_BREAKPOINT,0xff0000ff);
_sci.sendEditor(QScintilla.SCI_MARKERSETFORE, MARK_BREAKPOINT,0xffffffff);
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, MARK_POINTER,4);
_sci.sendEditor(QScintilla.SCI_MARKERSETFORE, MARK_POINTER,0xff7f7f00);
_sci.sendEditor(QScintilla.SCI_MARKERSETBACK, MARK_POINTER,0xffcee7ce);
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE,MARK_MODIFIED,25);
_sci.sendEditor(QScintilla.SCI_MARKERSETFORE,MARK_MODIFIED,0xff00d8ff);
_sci.sendEditor(QScintilla.SCI_MARKERSETBACK,MARK_MODIFIED,0xff00d8ff);
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE,MARK_SAVED,25);
_sci.sendEditor(QScintilla.SCI_MARKERSETFORE,MARK_SAVED,0xff00d8ff);
_sci.sendEditor(QScintilla.SCI_MARKERSETBACK,MARK_SAVED,0xff00d8ff);
current_modify_mark = MARK_MODIFIED;
reserve_modify_mark = MARK_SAVED;
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN,BREAKPOINT_INDEX, 15);
_sci.sendEditor(QScintilla.SCI_SETMARGINSENSITIVEN,BREAKPOINT_INDEX, 1);
if (Setting.isIndentGuide()) {
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.STYLE_INDENTGUIDE, 0xff464849);
_sci.sendEditor(QScintilla.SCI_SETINDENTATIONGUIDES, QScintilla.SC_IV_LOOKBOTH);
} else {
_sci.sendEditor(QScintilla.SCI_SETINDENTATIONGUIDES, QScintilla.SC_IV_NONE);
}
if (Setting.isShowLineNumber()) {
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN,LINENUMBER_INDEX, 40);
} else {
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN,LINENUMBER_INDEX, 0);
}
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN,DEBUGPOINT_INDEX, 15);
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN,MODIFIMARK_INDEX, 3);
//_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN,4, 0);
_sci.sendEditor(QScintilla.SCI_SETMARGINTYPEN, BREAKPOINT_INDEX, QScintilla.SC_MARGIN_SYMBOL);
_sci.sendEditor(QScintilla.SCI_SETMARGINMASKN, BREAKPOINT_INDEX, 1 << MARK_BREAKPOINT);
_sci.sendEditor(QScintilla.SCI_SETMARGINTYPEN, LINENUMBER_INDEX, QScintilla.SC_MARGIN_NUMBER);
_sci.sendEditor(QScintilla.SCI_SETMARGINMASKN, LINENUMBER_INDEX, 0);
_sci.sendEditor(QScintilla.SCI_SETMARGINTYPEN, DEBUGPOINT_INDEX, QScintilla.SC_MARGIN_SYMBOL);
_sci.sendEditor(QScintilla.SCI_SETMARGINMASKN, DEBUGPOINT_INDEX, 1 << MARK_POINTER);
_sci.sendEditor(QScintilla.SCI_SETMARGINTYPEN, MODIFIMARK_INDEX, QScintilla.SC_MARGIN_SYMBOL);
_sci.sendEditor(QScintilla.SCI_SETMARGINMASKN, MODIFIMARK_INDEX, (1 << MARK_MODIFIED) | (1 << MARK_SAVED));
_sci.sendEditor(QScintilla.SCI_STYLESETBACK, QScintilla.STYLE_LINENUMBER, 0xffefefef);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.STYLE_LINENUMBER, 0xffaf912b);
_sci.sendEditor(QScintilla.SCI_SETMARGINLEFT, 0, 0);
_sci.sendEditor(QScintilla.SCI_STYLESETBOLD, QScintilla.STYLE_BRACELIGHT, 1);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.STYLE_BRACELIGHT, 0xffff00ff);
_sci.sendEditor(QScintilla.SCI_STYLESETBACK, QScintilla.STYLE_BRACEBAD, 0xff00ffff);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_COMMENTDOCKEYWORD, 0xffA06030);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_COMMENTDOCKEYWORDERROR, 0xff204080);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_GLOBALCLASS, 0xff0099dd);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_OPERATOR, 0xffed286e/* 0xff859dd6 0xffFEE7Bf*/);
_sci.sendEditor(QScintilla.SCI_STYLESETBACK, QScintilla.SCE_C_STRINGEOL, 0xffE0C0E0);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_WORD, 0xffd69c56);
//_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_WORD2, 0xff2ae27f);
//_sci.sendEditor(QScintilla.SCI_STYLESETBOLD, QScintilla.SCE_C_WORD2, 1);
_sci.sendEditor(QScintilla.SCI_STYLESETBACK, QScintilla.SCE_C_WORD2, 0xffE4D5CB);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_STRING, 0xffc56cbd);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_NUMBER, 0xff6e28ed/*0xffA8CEB5*/);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_CHARACTER, 0xff73DBE6);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_PREPROCESSOR, 0x00808080);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_COMMENT, 0xffaaccaa);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_COMMENTLINE, 0xffaaccaa);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_COMMENTDOC, 0x00008000);
/*_sci.sendEditor(QScintilla.SCI_CALLTIPSETBACK, 0xff454242);
_sci.sendEditor(QScintilla.SCI_CALLTIPSETFORE, 0xffefefef);*/
//_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.SCE_C_COMMENTDOC, 0xff504f4f);
_sci.sendEditor(QScintilla.SCI_SETCARETFORE,0xff000000,0);
_sci.sendEditor(QScintilla.SCI_SETCARETLINEVISIBLE, 1);
_sci.sendEditor(QScintilla.SCI_SETCARETLINEBACK, 0xffefefef);
_sci.sendEditor(QScintilla.SCI_SETCARETLINEFRAME, 2);
_sci.sendEditor(QScintilla.SCI_SETTABWIDTH, 4);
_sci.sendEditor(QScintilla.SCI_SETEOLMODE, QScintilla.SC_EOL_LF, 0);
//-----------------------
if (Setting.isShowFolding()) {
_sci.sendEditor(QScintilla.SCI_SETPROPERTY,"fold","1");
_sci.sendEditor(QScintilla.SCI_SETMARGINTYPEN, MARGIN_FOLD_INDEX, QScintilla.SC_MARGIN_SYMBOL);//页边类型
_sci.sendEditor(QScintilla.SCI_SETMARGINMASKN, MARGIN_FOLD_INDEX, QScintilla.SC_MASK_FOLDERS); //页边掩码
_sci.sendEditor(QScintilla.SCI_SETFOLDMARGINCOLOUR, 1, 0xffefefef);
_sci.sendEditor(QScintilla.SCI_SETFOLDMARGINHICOLOUR, 1, 0xffffffff);
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN, MARGIN_FOLD_INDEX, 11); //页边宽度
_sci.sendEditor(QScintilla.SCI_SETMARGINSENSITIVEN, MARGIN_FOLD_INDEX, 1); //响应鼠标消息
// 折叠标签样式 //折叠页边颜色
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, QScintilla.SC_MARKNUM_FOLDER, QScintilla.SC_MARK_BOXPLUS);
_sci.sendEditor(QScintilla.SCI_MARKERSETFORE,QScintilla.SC_MARKNUM_FOLDER,0xffefefef);
_sci.sendEditor(QScintilla.SCI_MARKERSETBACK,QScintilla.SC_MARKNUM_FOLDER,0xff9c9c9c);
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, QScintilla.SC_MARKNUM_FOLDEROPEN, QScintilla.SC_MARK_BOXMINUS);
setMarginColor(QScintilla.SC_MARKNUM_FOLDEROPEN,0xffefefef,0xff9c9c9c);
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, QScintilla.SC_MARKNUM_FOLDEREND, QScintilla.SC_MARK_BOXPLUSCONNECTED);
setMarginColor(QScintilla.SC_MARKNUM_FOLDEREND,0xffefefef,0xff9c9c9c);
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, QScintilla.SC_MARKNUM_FOLDEROPENMID, QScintilla.SC_MARK_BOXMINUSCONNECTED);
setMarginColor(QScintilla.SC_MARKNUM_FOLDEROPENMID,0xffefefef,0xff9c9c9c);
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, QScintilla.SC_MARKNUM_FOLDERMIDTAIL, QScintilla.SC_MARK_TCORNER);
setMarginColor(QScintilla.SC_MARKNUM_FOLDERMIDTAIL,0xffefefef,0xff9c9c9c);
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, QScintilla.SC_MARKNUM_FOLDERSUB, QScintilla.SC_MARK_VLINE);
setMarginColor(QScintilla.SC_MARKNUM_FOLDERSUB, 0xffefefef,0xff9c9c9c);
_sci.sendEditor(QScintilla.SCI_MARKERDEFINE, QScintilla.SC_MARKNUM_FOLDERTAIL, QScintilla.SC_MARK_LCORNER);
setMarginColor(QScintilla.SC_MARKNUM_FOLDERTAIL, 0xffefefef,0xff9c9c9c);
} else {
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN, MARGIN_FOLD_INDEX, 0); //页边宽度
}
}
String lastIntellisence_content = "";
public void updateXIntellisence(String _path, String content){
if (isIntellisense_modified()){
String ext = getFilePath().findExtension();
if (isDocument(ext)) {
if (content != nilptr) {
if (lastIntellisence_content.equals(content) == false){
lastIntellisence_content = content;
_mdi_area.UpdateIntelliSense(_path, content);
}
}
}
}
intellisense_modified = false;
}
public void UpdateCodepage(){
MultiSelectDialog.requestSelect(new InputDialog.onInputListener(){
bool onInputOk(@NotNilptr String text)override{ return true;}
bool onInputCancel()override{ return true;}
bool onSelectOk(int id){
try{
defaultCharset = cpid[id];
if (QMessageBox.Yes == QMessageBox.Question("注意","将以新的编码重新载入文件, 对此文档的改动将丢失!",QMessageBox.Yes | QMessageBox.No,QMessageBox.No)){
reloadFile(defaultCharset);
}
/*String content = _sci.getText();
String newtext = new String(content.getBytes(), defaultCharset);
_sci.setText(newtext);*/
return true;
}catch(Exception e){
}
QMessageBox.Critical("注意","选择的编码不正确",QMessageBox.Ok,QMessageBox.Ok);
return false;
}
String getTitle()override{return "选择编码";}
String getTips()override{return "选择编码";}
String getDefault()override{
return "0";
}
},codepages);
}
public void convertCharset(){
MultiSelectDialog.requestSelect(new InputDialog.onInputListener(){
bool onInputOk(@NotNilptr String text)override{ return true;}
bool onInputCancel()override{ return true;}
bool onSelectOk(int id){
try{
defaultCharset = cpid[id];
QMessageBox.Information("注意","该文件将以新的编码 [" + defaultCharset + "] 进行储存",QMessageBox.Ok,QMessageBox.Ok);
return true;
}catch(Exception e){
}
QMessageBox.Critical("注意","选择的编码不正确",QMessageBox.Ok,QMessageBox.Ok);
return false;
}
String getTitle()override{return "选择编码";}
String getTips()override{return "选择编码";}
String getDefault()override{
if (defaultCharset != nilptr){
for (int i = 0; i < cpid.length; i++){
if (cpid[i].equalsIgnoreCase(defaultCharset)){
return "" + i;
}
}
}
return "0";
}
},codepages);
}
public void setEditorText(String fullpath,@NotNilptr byte [] data, String asCharset){
bool readOnly = false;
String content = "";
String charset = asCharset;
if (charset == nilptr){
charset = loadAsCharset;
}
if (charset == nilptr){
charset = getCharsetCache(fullpath);
}
if (charset == nilptr){
try{
charset = String.detectCharset(data, 0, data.length);
}catch(Exception e){
}
}
try{
bool retry = false, bMana = false;
do{
retry = false;
if (charset == nilptr || (charset.equals("UTF-8") == false && charset.equals("ASCII") == false)){
if (charset != nilptr){
defaultCharset = charset;
try{
content = new String(data, charset);
if (asCharset != nilptr){
loadAsCharset = asCharset;
addToCharset(fullpath, loadAsCharset);
}
}catch(Exception e){
bMana = true;
}
}else{
bMana = true;
}
if (bMana){
QMessageBox.Information("注意","无法识别此文件编码,请手动选择一个文件编码尝试载入",QMessageBox.Ok,QMessageBox.Ok);
retry = MultiSelectDialog.requestSelect(new InputDialog.onInputListener(){
bool onInputOk(@NotNilptr String text)override{ return true;}
bool onInputCancel()override{
retry = false;
return true;
}
bool onSelectOk(int id){
try{
charset = cpid[id];
retry = true;
return true;
}catch(Exception e){
}
QMessageBox.Critical("注意","选择的编码不正确",QMessageBox.Ok,QMessageBox.Ok);
return false;
}
String getTitle()override{return "选择编码";}
String getTips()override{return "选择编码";}
String getDefault()override{
if (charset != nilptr){
for (int i = 0; i < cpid.length; i++){
if (cpid[i].equalsIgnoreCase(charset)){
return "" + i;
}
}
}
return "0";
}
},codepages) == 1;
if (!retry){
content = new String(data, 0, data.length, "RAW");
QMessageBox.Critical("注意","未选择有效的编码,文件将锁定为只读,保存或者编辑将使文件损坏.",QMessageBox.Ok,QMessageBox.Ok);
readOnly = true;
setModified(false);
readonlyResp = ReadResp.NO_CHARSET;
}
}
}else{
content = new String(data);
}
}while (retry);
}catch(Exception e){
content = new String(data);
}
_sci.setText(content);
if (readOnly){
_sci.clearUndo();
resetAllModified();
_sci.setSavePoint();
_sci.setReadOnly(true);
}
}
public void setText(String text){
_sci.setText(text);
}
public void requestInteliSence(){
long position = _sci.currentPosition();
String content = _sci.getText();
int line = _sci.positionToLine(position);
int column = position - _sci.getPosition(line);
if (_mdi_area.XIntelliSense(XSourceEditor.this, getFilePath(), content, position, line, column)) {
auto_position = position;
last_autopos = -1;
}
}
public void reloadFile(String asCharset) {
try {
FileInputStream fis = new FileInputStream(getFilePath());
byte [] data = fis.read();
try {
int line = _sci.getFirstVisibleLine();
long pos = _sci.currentPosition();
if (data != nilptr){
setEditorText(getFilePath(), data, asCharset);
}
_sci.setSavePoint();
resetAllModified();
fis.close();
_sci.setFirstVisibleLine(line);
_sci.update();
_sci.gotoPos(pos);
} catch(Exception e) {
}
updateInformationPoint();
} catch(Exception e) {
Critical("注意", "找不到该文件或者文件正被其他程序使用:" + getFilePath(), QMessageBox.Ok, QMessageBox.Ok);
}
}
public bool loadFile(@NotNilptr String file, String asCharset) {
try {
FileInputStream fis = new FileInputStream(file);
try {
byte [] data = fis.read();
if (data != nilptr){
setEditorText(file, data, asCharset);
}
String filePath = String.formatPath(file,false).replace("\\","/");
setFilePath(filePath);
_sci.setSavePoint();
_sci.clearUndo();
_sci.update();
updateTitle();
resetAllModified();
_mdi_area.updateDocumentStatus();
XWorkspace.workspace.closeIndexPage();
Project proj = XWorkspace.workspace.getCurrentProject();
if (proj != nilptr){
proj.didOpenFile(file);
}
if (_textplugins != nilptr) {
_textplugins.configEditor(_mdi_area.getCurrentProject(), filePath, _sci, Setting.isDarkStyle());
}
updateInformationPoint();
_mdi_area.XIntelliSenseFile(XSourceEditor.this, getFilePath(), "");
return true;
} catch(Exception e) {
Critical("注意", "载入文件时发生错误:" + file, QMessageBox.Ok, QMessageBox.Ok);
} finally {
fis.close();
}
} catch(Exception e) {
Critical("注意", "找不到该文件或者文件正被其他程序使用:" + file, QMessageBox.Ok, QMessageBox.Ok);
}
return false;
}
void resetInformationPoint(){
clearInformationPoint();
_sci.sendEditor(QScintilla.SCI_MARKERDELETEALL,ERRORPOINT_INDEX);
_sci.sendEditor(QScintilla.SCI_MARKERDELETEALL,WARNING_INDEX);
}
public bool saveFile() {
if (isModified() == false) {
return true;
}
if (readonlyResp == ReadResp.NO_CHARSET){
QMessageBox.Critical("注意","未选择有效的编码,文件将锁定为只读,保存或者编辑将使文件损坏.",QMessageBox.Ok,QMessageBox.Ok);
return false;
}
clearIndic();
resetInformationPoint();
String savepath = getFilePath();
bool saved = false;
while (saved == false) {
if (savepath != nilptr && savepath.startsWith("#")) {
while (saved == false) {
String file = QFileDialog.getSaveFileName("保存文件", savepath, getDocumentExtension(), this);
if (file != nilptr && file.length() > 0) {
//另存
saved = saveAs(file);
} else {
//取消保存
return false;
}
}
} else
if (savepath != nilptr){
pauseWatch();
try {
String content = _sci.getText();
byte [] data = nilptr;
if (defaultCharset != nilptr){
try{
data = content.getBytes(defaultCharset);
}catch(Exception e){
QMessageBox.Warning("注意","文件不能以编码 " + defaultCharset + " 进行保存, 将存储为 UTF-8 编码.",QMessageBox.Ok,QMessageBox.Ok);
defaultCharset = nilptr;
data = content.getBytes();
}
}else{
data = content.getBytes();
}
FileOutputStream fis = new FileOutputStream(savepath);
fis.write(data);
fis.close();//必须close 不然GC 关闭文件的时候在watch之后 , watch 会报告被更改
_sci.setSavePoint();
removeAllModified();
updateTitle();
saved = true;
String ext = savepath.findExtension();
if (isDocument(ext)) {
updateXIntellisence(savepath, content);
}
} catch(Exception e) {
//保存失败 跳到另存
Critical("注意", "文件无法在此位置保存,或者此文件正被其他程序使用,请重新选择路径", QMessageBox.Ok, QMessageBox.Ok);
savepath = "#";
}
continueWatch();
}
}
return saved;
}
public void removeAllModified() {
setModified(false);
_sci.sendEditor(QScintilla.SCI_MARKERDELETEALL,reserve_modify_mark);
switchSaveMark();
}
public void resetAllModified() {
_sci.sendEditor(QScintilla.SCI_MARKERDELETEALL,MARK_MODIFIED);
_sci.sendEditor(QScintilla.SCI_MARKERDELETEALL,MARK_SAVED);
}
public void saveFileAs() {
if (readonlyResp == ReadResp.NO_CHARSET){
QMessageBox.Critical("注意","未选择有效的编码,文件将锁定为只读,保存或者编辑将使文件损坏.",QMessageBox.Ok,QMessageBox.Ok);
return;
}
String file = QFileDialog.getSaveFileName("保存文件", getFilePath(), getDocumentExtension(), this);
if (file != nilptr && file.length() > 0) {
saveAs(file);
}
}
public bool saveAs(@NotNilptr String path) {
pauseWatch();
try {
FileOutputStream fis = new FileOutputStream(path);
try {
String content = _sci.getText();
byte [] data;
if (defaultCharset != nilptr){
try{
data = content.getBytes(defaultCharset);
}catch(Exception e){
QMessageBox.Warning("注意","文件不能以编码 " + defaultCharset + " 进行保存, 将存储为 UTF-8 编码.",QMessageBox.Ok,QMessageBox.Ok);
data = content.getBytes();
}
}else{
data = content.getBytes();
}
fis.write(data);
fis.close();//必须close 不然GC 关闭文件的时候在watch之后 , watch 会报告被更改
_sci.setSavePoint();
removeAllModified();
setFilePath(String.formatPath(path,false).replace("\\","/"));
continueWatch();
return true;
} catch(Exception e) {
}
} catch(Exception e) {
Critical("注意", "文件无法在此位置保存,或者此文件正被其他程序使用,请重新选择路径", QMessageBox.Ok, QMessageBox.Ok);
}
continueWatch();
return false;
}
public void UnDo() {
_sci.Undo();
}
public void ReDo() {
_sci.Redo();
}
public void insertNewLine() {
int curpos = _sci.getCurrentPosition();
int line = _sci.positionToLine(curpos);
int start = _sci.getPosition(line);
_sci.insertText(start,"\n");
_sci.gotoPos(start);
if (Setting.isAutoIdent()) {
identguide(_sci, '\n');
}
}
public void appendNewLine() {
int curpos = _sci.getCurrentPosition();
int line = _sci.positionToLine(curpos);
int start = _sci.getEndOfLine(line);
_sci.insertText(start,"\n");
_sci.gotoPos(start + 1);
if (Setting.isAutoIdent()) {
identguide(_sci, '\n');
}
}
public int getContentLength ()override{return _sci.getLength();}
public int getSelectStart()override{return _sci.getSelectStart();}
public int getSelectEnd()override{return _sci.getSelectEnd();}
public QPoint getSelectMarkRange()override{
int start = 0, end = 0;
int contentlen = _sci.getLength();
do {
start = _sci.getIndicStart(INDIC_SELECTED, start);
end = _sci.getIndicEnd(INDIC_SELECTED, start);
if (end == 0) {
return nilptr;
}
int dic = _sci.IndicForPosition(start);
if ((dic & (1 << INDIC_SELECTED)) != 0) {
return new QPoint(start, end);
} else {
start = end;
}
} while (end != contentlen);
return nilptr;
}
public String getText(int s,int e)override{return _sci.getText(s,e);}
public void Copy() {
if (_sci.getSelectStart() == _sci.getSelectEnd()) {
int curpos = _sci.getCurrentPosition();
int line = _sci.positionToLine(curpos);
int start = _sci.getPosition(line);
int end = _sci.getEndOfLine(line);
_sci.setSelect(start,end);
_sci.Copy();
_sci.gotoPos(curpos);
} else {
_sci.Copy();
}
}
public void Paste() {
_sci.Paste();
}
public void Cut() {
_sci.Cut();
}
public void Delete() {
if (Setting.isMatchBrace()) {
if (deleteBrace(_sci.getCurrentPosition())) {
_sci.Delete();
}
} else {
_sci.Delete();
}
}
public void DeleteCurLine() {
_sci.sendEditor(QScintilla.SCI_LINEDELETE,0);
}
public static void clearBreakInfo(@NotNilptr Map<long, XStackInfor.BreakPosition> breakList) {
Map.Iterator<long, XStackInfor.BreakPosition> iter = breakList.iterator();
while (iter.hasNext()) {
XStackInfor.BreakPosition bp = iter.getValue();
if (bp != nilptr){
DocumentView wnd = findDocumentWindow(nilptr, bp.file, false);
if (wnd != nilptr) {
//wnd.breakOn(bp.line, bp.row, false, bp.active);
wnd.clearBreakOn();
}
}
iter.next();
}
}
public static void removeBreak(@NotNilptr XStackInfor.BreakPosition bp) {
DocumentView wnd = findDocumentWindow(nilptr, bp.file, false);
if (wnd != nilptr) {
wnd.breakOn(bp.line, bp.row, false, bp.active, false);
}
}
public static void setBreak(@NotNilptr XStackInfor.BreakPosition bp, bool onlyActive, bool bSender) {
DocumentView wnd = findDocumentWindow(XWorkspace.workspace, bp.file, bp.active);
if (wnd != nilptr) {
wnd.breakOn(bp.line, bp.row, true, bp.active, onlyActive);
} else
if (bp.file != nilptr){
if (bSender && QMessageBox.Question("提示", "无法找到源代码文件:" + bp.file + ",是否浏览文件?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No ) == QMessageBox.Yes) {
String filename = bp.file.findFilenameAndExtension();
if (filename.length() == 0) {
filename = bp.file;
}
String file = QFileDialog.getOpenFileName("打开文件:" + filename, bp.file, getDocumentExtension(), XWorkspace.workspace);
if (file != nilptr && file.length() > 0) {
wnd = findDocumentWindow(XWorkspace.workspace, file, bp.active);
if (wnd != nilptr) {
wnd.breakOn(bp.line, bp.row, true, bp.active, onlyActive);
updateDocumentTo(file, bp.file);
}
}
}
}
}
public void CursorUp() {
_sci.sendEditor(QScintilla.SCI_LINEUP, 0);
}
public void CursorLeft() {
_sci.gotoPos(_sci.getCurrentPosition() - 1);
}
public void CursorRight() {
_sci.gotoPos(_sci.getCurrentPosition() + 1);
}
public void CursorDown() {
_sci.sendEditor(QScintilla.SCI_LINEDOWN, 0);
}
public void CursorLineBegin() {
_sci.sendEditor(QScintilla.SCI_VCHOME, 0);
}
public void CursorLineEnd() {
_sci.sendEditor(QScintilla.SCI_LINEEND, 0);
}
public void CursorPrevPage() {
_sci.sendEditor(QScintilla.SCI_PAGEUP, 0);
}
public void CursorNextPage() {
_sci.sendEditor(QScintilla.SCI_PAGEDOWN, 0);
}
public void CursortoTop() {
_sci.gotoPos(0);
}
public void CursortoBottom() {
_sci.gotoPos(_sci.getLength() - 1);
}
public void setUpper() {
_sci.sendEditor(QScintilla.SCI_UPPERCASE, 0);
}
public void doPrint(){
if (g_printer == nilptr){
g_printer = new QScintilla.QSciPrinter();
}
if (g_printer != nilptr){
QPrintDialog printdlg = new QPrintDialog(this, g_printer);
if (printdlg.exec() != 0){
g_printer.printRange(_sci, -1, -1);
}
}
}
public void setLower() {
_sci.sendEditor(QScintilla.SCI_LOWERCASE, 0);
}
/*static void updateBreakInfo(Map<int, XStackInfor.BreakPosition> breakList){
Map.Iterator<int, XStackInfor.BreakPosition> iter = breakList.iterator();
while (iter.hasNext()){
XStackInfor.BreakPosition bp = iter.getValue();
if (bp.isUpdated()){
XSourceEditor wnd = findDocumentWindow(XWorkspace.workspace, bp.file, bp.active);
if (wnd != nilptr){
wnd.breakOn(bp.line, bp.row, true, bp.active);
}
}
iter.next();
}
}*/
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/ixlang/XStudio.git
git@gitee.com:ixlang/XStudio.git
ixlang
XStudio
XStudio
master

搜索帮助