- feature: watch external file modifications

- fix: crash when load history file that doesn't exist
 - fix: only highlight fully selected word
This commit is contained in:
royqh1979 2021-08-31 14:40:41 +08:00
parent 085f9c9baa
commit 72b8d51092
7 changed files with 241 additions and 96 deletions

Binary file not shown.

View File

@ -4,17 +4,17 @@
<context> <context>
<name>BacktraceModel</name> <name>BacktraceModel</name>
<message> <message>
<location filename="debugger.cpp" line="1556"/> <location filename="debugger.cpp" line="1561"/>
<source>Function</source> <source>Function</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="debugger.cpp" line="1558"/> <location filename="debugger.cpp" line="1563"/>
<source>Filename</source> <source>Filename</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="debugger.cpp" line="1560"/> <location filename="debugger.cpp" line="1565"/>
<source>Line</source> <source>Line</source>
<translation></translation> <translation></translation>
</message> </message>
@ -22,17 +22,17 @@
<context> <context>
<name>BreakpointModel</name> <name>BreakpointModel</name>
<message> <message>
<location filename="debugger.cpp" line="1462"/> <location filename="debugger.cpp" line="1467"/>
<source>Filename</source> <source>Filename</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="debugger.cpp" line="1464"/> <location filename="debugger.cpp" line="1469"/>
<source>Line</source> <source>Line</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="debugger.cpp" line="1466"/> <location filename="debugger.cpp" line="1471"/>
<source>Condition</source> <source>Condition</source>
<translation></translation> <translation></translation>
</message> </message>
@ -491,27 +491,27 @@ Are you really want to continue?</source>
</message> </message>
<message> <message>
<location filename="debugger.cpp" line="225"/> <location filename="debugger.cpp" line="225"/>
<location filename="debugger.cpp" line="299"/> <location filename="debugger.cpp" line="304"/>
<source>Execute to evaluate</source> <source>Execute to evaluate</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="debugger.cpp" line="297"/> <location filename="debugger.cpp" line="302"/>
<source>Not found in current context</source> <source>Not found in current context</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="debugger.cpp" line="394"/> <location filename="debugger.cpp" line="399"/>
<source>Compile</source> <source>Compile</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="debugger.cpp" line="395"/> <location filename="debugger.cpp" line="400"/>
<source>Source file is more recent than executable.</source> <source>Source file is more recent than executable.</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="debugger.cpp" line="395"/> <location filename="debugger.cpp" line="400"/>
<source>Recompile?</source> <source>Recompile?</source>
<translation></translation> <translation></translation>
</message> </message>
@ -534,11 +534,11 @@ Are you really want to continue?</source>
<message> <message>
<location filename="editor.cpp" line="180"/> <location filename="editor.cpp" line="180"/>
<location filename="editor.cpp" line="192"/> <location filename="editor.cpp" line="192"/>
<location filename="editor.cpp" line="224"/> <location filename="editor.cpp" line="227"/>
<location filename="editor.cpp" line="792"/> <location filename="editor.cpp" line="807"/>
<location filename="editor.cpp" line="797"/> <location filename="editor.cpp" line="812"/>
<location filename="editor.cpp" line="815"/> <location filename="editor.cpp" line="830"/>
<location filename="editor.cpp" line="820"/> <location filename="editor.cpp" line="835"/>
<source>Error</source> <source>Error</source>
<translation></translation> <translation></translation>
</message> </message>
@ -553,40 +553,40 @@ Are you really want to continue?</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="editor.cpp" line="793"/> <location filename="editor.cpp" line="808"/>
<source>The text to be copied exceeds count limit!</source> <source>The text to be copied exceeds count limit!</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="editor.cpp" line="798"/> <location filename="editor.cpp" line="813"/>
<source>The text to be copied exceeds character limit!</source> <source>The text to be copied exceeds character limit!</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="editor.cpp" line="816"/> <location filename="editor.cpp" line="831"/>
<source>The text to be cut exceeds count limit!</source> <source>The text to be cut exceeds count limit!</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="editor.cpp" line="821"/> <location filename="editor.cpp" line="836"/>
<source>The text to be cut exceeds character limit!</source> <source>The text to be cut exceeds character limit!</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="editor.cpp" line="1990"/> <location filename="editor.cpp" line="2005"/>
<location filename="editor.cpp" line="2027"/> <location filename="editor.cpp" line="2042"/>
<location filename="editor.cpp" line="2078"/> <location filename="editor.cpp" line="2093"/>
<source>Ctrl+click for more info</source> <source>Ctrl+click for more info</source>
<translation>Ctrl+</translation> <translation>Ctrl+</translation>
</message> </message>
<message> <message>
<location filename="editor.cpp" line="2096"/> <location filename="editor.cpp" line="2111"/>
<location filename="editor.cpp" line="2126"/> <location filename="editor.cpp" line="2141"/>
<source>Symbol &apos;%1&apos; not found!</source> <source>Symbol &apos;%1&apos; not found!</source>
<translation>&apos;%1&apos;!</translation> <translation>&apos;%1&apos;!</translation>
</message> </message>
<message> <message>
<location filename="editor.cpp" line="2636"/> <location filename="editor.cpp" line="2651"/>
<source>Readonly</source> <source>Readonly</source>
<translation></translation> <translation></translation>
</message> </message>
@ -1337,7 +1337,7 @@ Are you really want to continue?</source>
</message> </message>
<message> <message>
<location filename="mainwindow.ui" line="267"/> <location filename="mainwindow.ui" line="267"/>
<location filename="mainwindow.cpp" line="1178"/> <location filename="mainwindow.cpp" line="1228"/>
<source>Issues</source> <source>Issues</source>
<translation></translation> <translation></translation>
</message> </message>
@ -1530,8 +1530,10 @@ Are you really want to continue?</source>
<message> <message>
<location filename="mainwindow.ui" line="994"/> <location filename="mainwindow.ui" line="994"/>
<location filename="mainwindow.ui" line="997"/> <location filename="mainwindow.ui" line="997"/>
<location filename="mainwindow.cpp" line="790"/> <location filename="mainwindow.cpp" line="804"/>
<location filename="mainwindow.cpp" line="801"/> <location filename="mainwindow.cpp" line="815"/>
<location filename="mainwindow.cpp" line="1053"/>
<location filename="mainwindow.cpp" line="1064"/>
<source>Compile</source> <source>Compile</source>
<translation></translation> <translation></translation>
</message> </message>
@ -1812,6 +1814,21 @@ Are you really want to continue?</source>
<source>Shift+F3</source> <source>Shift+F3</source>
<translation>Shift+F3</translation> <translation>Shift+F3</translation>
</message> </message>
<message>
<location filename="mainwindow.ui" line="1350"/>
<source>Remove Watch</source>
<translation></translation>
</message>
<message>
<location filename="mainwindow.ui" line="1355"/>
<source>Remove All</source>
<translation></translation>
</message>
<message>
<location filename="mainwindow.ui" line="1360"/>
<source>Modify Watch...</source>
<translation></translation>
</message>
<message> <message>
<location filename="mainwindow.cpp" line="81"/> <location filename="mainwindow.cpp" line="81"/>
<source>File Encoding</source> <source>File Encoding</source>
@ -1823,20 +1840,20 @@ Are you really want to continue?</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="315"/> <location filename="mainwindow.cpp" line="325"/>
<location filename="mainwindow.cpp" line="317"/> <location filename="mainwindow.cpp" line="327"/>
<source>Debugging</source> <source>Debugging</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="320"/> <location filename="mainwindow.cpp" line="330"/>
<location filename="mainwindow.cpp" line="322"/> <location filename="mainwindow.cpp" line="332"/>
<source>Running</source> <source>Running</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="325"/> <location filename="mainwindow.cpp" line="335"/>
<location filename="mainwindow.cpp" line="327"/> <location filename="mainwindow.cpp" line="337"/>
<source>Compiling</source> <source>Compiling</source>
<translation></translation> <translation></translation>
</message> </message>
@ -1845,150 +1862,172 @@ Are you really want to continue?</source>
<translation type="vanished">:%1 :%2 :%3 :%4 :%5</translation> <translation type="vanished">:%1 :%2 :%3 :%4 :%5</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="453"/> <location filename="mainwindow.cpp" line="463"/>
<source>Line:%1 Col:%2 Selected:%3 Lines:%4 Length:%5</source> <source>Line:%1 Col:%2 Selected:%3 Lines:%4 Length:%5</source>
<translation>:%1 :%2 :%3 :%4 :%5</translation> <translation>:%1 :%2 :%3 :%4 :%5</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="471"/> <location filename="mainwindow.cpp" line="481"/>
<source>Read Only</source> <source>Read Only</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="473"/> <location filename="mainwindow.cpp" line="483"/>
<source>Insert</source> <source>Insert</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="475"/> <location filename="mainwindow.cpp" line="485"/>
<source>Overwrite</source> <source>Overwrite</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="600"/> <location filename="mainwindow.cpp" line="614"/>
<location filename="mainwindow.cpp" line="615"/> <location filename="mainwindow.cpp" line="629"/>
<source>Confirm</source> <source>Confirm</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="601"/> <location filename="mainwindow.cpp" line="615"/>
<location filename="mainwindow.cpp" line="609"/> <location filename="mainwindow.cpp" line="623"/>
<location filename="mainwindow.cpp" line="791"/> <location filename="mainwindow.cpp" line="805"/>
<source>Source file is not compiled.</source> <source>Source file is not compiled.</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="602"/> <location filename="mainwindow.cpp" line="616"/>
<location filename="mainwindow.cpp" line="791"/> <location filename="mainwindow.cpp" line="805"/>
<source>Compile now?</source> <source>Compile now?</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="616"/> <location filename="mainwindow.cpp" line="630"/>
<location filename="mainwindow.cpp" line="802"/> <location filename="mainwindow.cpp" line="816"/>
<source>Source file is more recent than executable.</source> <source>Source file is more recent than executable.</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="617"/> <location filename="mainwindow.cpp" line="631"/>
<source>Recompile now?</source> <source>Recompile now?</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="669"/> <location filename="mainwindow.cpp" line="683"/>
<source>No compiler set</source> <source>No compiler set</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="670"/> <location filename="mainwindow.cpp" line="684"/>
<source>No compiler set is configured.</source> <source>No compiler set is configured.</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="670"/> <location filename="mainwindow.cpp" line="684"/>
<source>Can&apos;t start debugging.</source> <source>Can&apos;t start debugging.</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="759"/> <location filename="mainwindow.cpp" line="773"/>
<source>Enable debugging</source> <source>Enable debugging</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="760"/> <location filename="mainwindow.cpp" line="774"/>
<source>You have not enabled debugging info (-g3) and/or stripped it from the executable (-s) in Compiler Options.&lt;BR /&gt;&lt;BR /&gt;Do you want to correct this now?</source> <source>You have not enabled debugging info (-g3) and/or stripped it from the executable (-s) in Compiler Options.&lt;BR /&gt;&lt;BR /&gt;Do you want to correct this now?</source>
<translation>(-g3)(-s)&lt;br /&gt;&lt;br/&gt;</translation> <translation>(-g3)(-s)&lt;br /&gt;&lt;br/&gt;</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="802"/> <location filename="mainwindow.cpp" line="816"/>
<source>Recompile?</source> <source>Recompile?</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="1021"/> <location filename="mainwindow.cpp" line="1044"/>
<source>%1 files autosaved</source> <source>%1 files autosaved</source>
<translation>%1</translation> <translation>%1</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="1067"/> <location filename="mainwindow.cpp" line="523"/>
<location filename="mainwindow.cpp" line="1091"/> <location filename="mainwindow.cpp" line="1060"/>
<location filename="mainwindow.cpp" line="1113"/> <location filename="mainwindow.cpp" line="1117"/>
<location filename="mainwindow.cpp" line="1125"/> <location filename="mainwindow.cpp" line="1141"/>
<location filename="mainwindow.cpp" line="1421"/> <location filename="mainwindow.cpp" line="1163"/>
<location filename="mainwindow.cpp" line="1433"/> <location filename="mainwindow.cpp" line="1175"/>
<location filename="mainwindow.cpp" line="1471"/>
<location filename="mainwindow.cpp" line="1483"/>
<source>Error</source> <source>Error</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="1087"/> <location filename="mainwindow.cpp" line="1054"/>
<source>File &apos;%1&apos; was changed.</source>
<translation>&apos;%1&apos;</translation>
</message>
<message>
<location filename="mainwindow.cpp" line="1054"/>
<source>Reload its content from disk?</source>
<translation></translation>
</message>
<message>
<location filename="mainwindow.cpp" line="1065"/>
<source>File &apos;%1&apos; was removed.</source>
<translation>&apos;%1&apos;</translation>
</message>
<message>
<location filename="mainwindow.cpp" line="1065"/>
<source>Keep it open?</source>
<translation>C++</translation>
</message>
<message>
<location filename="mainwindow.cpp" line="1137"/>
<source>Open</source> <source>Open</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="1269"/> <location filename="mainwindow.cpp" line="1319"/>
<source>Compile Failed</source> <source>Compile Failed</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="1274"/> <location filename="mainwindow.cpp" line="1324"/>
<source>Run Failed</source> <source>Run Failed</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="1450"/> <location filename="mainwindow.cpp" line="1500"/>
<location filename="mainwindow.cpp" line="1464"/> <location filename="mainwindow.cpp" line="1514"/>
<source>Confirm Convertion</source> <source>Confirm Convertion</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="1451"/> <location filename="mainwindow.cpp" line="1501"/>
<location filename="mainwindow.cpp" line="1465"/> <location filename="mainwindow.cpp" line="1515"/>
<source>The editing file will be saved using %1 encoding. &lt;br /&gt;This operation can&apos;t be reverted. &lt;br /&gt;Are you sure to continue?</source> <source>The editing file will be saved using %1 encoding. &lt;br /&gt;This operation can&apos;t be reverted. &lt;br /&gt;Are you sure to continue?</source>
<translation>使%1&lt;br /&gt;&lt;br /&gt;</translation> <translation>使%1&lt;br /&gt;&lt;br /&gt;</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="1640"/> <location filename="mainwindow.cpp" line="1690"/>
<source>New Watch Expression</source> <source>New Watch Expression</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="1641"/> <location filename="mainwindow.cpp" line="1691"/>
<source>Enter Watch Expression (it is recommended to use &apos;this-&gt;&apos; for class members):</source> <source>Enter Watch Expression (it is recommended to use &apos;this-&gt;&apos; for class members):</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="1687"/> <location filename="mainwindow.cpp" line="1737"/>
<source>Parsing file %1 of %2: &quot;%3&quot;</source> <source>Parsing file %1 of %2: &quot;%3&quot;</source>
<translation>%1/%2&quot;%3&quot;</translation> <translation>%1/%2&quot;%3&quot;</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="1709"/> <location filename="mainwindow.cpp" line="1759"/>
<location filename="mainwindow.cpp" line="1715"/> <location filename="mainwindow.cpp" line="1765"/>
<source>Done parsing %1 files in %2 seconds</source> <source>Done parsing %1 files in %2 seconds</source>
<translation>%1,%2</translation> <translation>%1,%2</translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="1712"/> <location filename="mainwindow.cpp" line="1762"/>
<source>(%1 files per second)</source> <source>(%1 files per second)</source>
<translation>(%1</translation> <translation>(%1</translation>
</message> </message>
@ -2004,12 +2043,12 @@ Are you really want to continue?</source>
<context> <context>
<name>QObject</name> <name>QObject</name>
<message> <message>
<location filename="editorlist.cpp" line="73"/> <location filename="editorlist.cpp" line="76"/>
<source>Save</source> <source>Save</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="editorlist.cpp" line="74"/> <location filename="editorlist.cpp" line="77"/>
<source>Save changes to %1?</source> <source>Save changes to %1?</source>
<translation>&quot;%1&quot;</translation> <translation>&quot;%1&quot;</translation>
</message> </message>
@ -2584,17 +2623,17 @@ Are you really want to continue?</source>
<context> <context>
<name>RegisterModel</name> <name>RegisterModel</name>
<message> <message>
<location filename="debugger.cpp" line="1807"/> <location filename="debugger.cpp" line="1820"/>
<source>Register</source> <source>Register</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="debugger.cpp" line="1809"/> <location filename="debugger.cpp" line="1822"/>
<source>Value(Hex)</source> <source>Value(Hex)</source>
<translation>(HEX)</translation> <translation>(HEX)</translation>
</message> </message>
<message> <message>
<location filename="debugger.cpp" line="1811"/> <location filename="debugger.cpp" line="1824"/>
<source>Value(Dec)</source> <source>Value(Dec)</source>
<translation>(DEC)</translation> <translation>(DEC)</translation>
</message> </message>
@ -3012,12 +3051,12 @@ Are you really want to continue?</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="settingsdialog/settingsdialog.cpp" line="174"/> <location filename="settingsdialog/settingsdialog.cpp" line="178"/>
<source>Save Changes</source> <source>Save Changes</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="settingsdialog/settingsdialog.cpp" line="175"/> <location filename="settingsdialog/settingsdialog.cpp" line="179"/>
<source>There are changes in the settings, do you want to save them before swtich to other page?</source> <source>There are changes in the settings, do you want to save them before swtich to other page?</source>
<translation></translation> <translation></translation>
</message> </message>

View File

@ -68,6 +68,8 @@ Editor::Editor(QWidget *parent, const QString& filename,
mActiveBreakpointLine(-1), mActiveBreakpointLine(-1),
mLastIdCharPressed(0), mLastIdCharPressed(0),
mCurrentWord(), mCurrentWord(),
mSelectionWord(),
mOldSelectionWord(),
mCurrentTipType(TipType::None) mCurrentTipType(TipType::None)
{ {
mUseCppSyntax = pSettings->editor().defaultFileCpp(); mUseCppSyntax = pSettings->editor().defaultFileCpp();
@ -153,6 +155,12 @@ void Editor::loadFile() {
default: default:
mUseCppSyntax = pSettings->editor().defaultFileCpp(); mUseCppSyntax = pSettings->editor().defaultFileCpp();
} }
if (highlighter() && mParser) {
reparse();
if (pSettings->editor().syntaxCheck() && pSettings->editor().syntaxCheckWhenLineChanged()) {
pMainWindow->checkSyntaxInBack(this);
}
}
} }
void Editor::saveFile(const QString &filename) { void Editor::saveFile(const QString &filename) {
@ -182,8 +190,10 @@ bool Editor::save(bool force, bool doReparse) {
return false; return false;
} }
if (this->modified()|| force) { if (this->modified()|| force) {
pMainWindow->fileSystemWatcher()->removePath(mFilename);
try { try {
saveFile(mFilename); saveFile(mFilename);
pMainWindow->fileSystemWatcher()->addPath(mFilename);
setModified(false); setModified(false);
mIsNew = false; mIsNew = false;
this->updateCaption(); this->updateCaption();
@ -192,6 +202,7 @@ bool Editor::save(bool force, bool doReparse) {
QMessageBox::critical(pMainWindow,tr("Error"), QMessageBox::critical(pMainWindow,tr("Error"),
exception.reason()); exception.reason());
} }
pMainWindow->fileSystemWatcher()->addPath(mFilename);
return false; return false;
} }
} }
@ -214,6 +225,9 @@ bool Editor::saveAs(){
if (newName.isEmpty()) { if (newName.isEmpty()) {
return false; return false;
} }
pMainWindow->fileSystemWatcher()->removePath(mFilename);
if (pSettings->codeCompletion().enabled() && mParser)
mParser->invalidateFile(mFilename);
try { try {
mFilename = newName; mFilename = newName;
saveFile(mFilename); saveFile(mFilename);
@ -225,6 +239,7 @@ bool Editor::saveAs(){
exception.reason()); exception.reason());
return false; return false;
} }
pMainWindow->fileSystemWatcher()->addPath(mFilename);
switch(getFileType(mFilename)) { switch(getFileType(mFilename)) {
case FileType::CppSource: case FileType::CppSource:
mUseCppSyntax = true; mUseCppSyntax = true;
@ -236,11 +251,22 @@ bool Editor::saveAs(){
mUseCppSyntax = pSettings->editor().defaultFileCpp(); mUseCppSyntax = pSettings->editor().defaultFileCpp();
} }
//todo: update (reassign highlighter)
//todo: remove old file from parser and reparse file //update (reassign highlighter)
//todo: unmoniter/ monitor file PSynHighlighter newHighlighter = HighlighterManager().getHighlighter(mFilename);
//todo: update windows caption if (newHighlighter) {
//todo: update class browser; setUseCodeFolding(true);
} else {
setUseCodeFolding(false);
}
setHighlighter(newHighlighter);
applyColorScheme(pSettings->editor().colorScheme());
reparse();
if (highlighter() && pSettings->editor().syntaxCheck() && pSettings->editor().syntaxCheckWhenLineChanged())
pMainWindow->checkSyntaxInBack(this);
return true; return true;
} }
@ -586,7 +612,7 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
|| (attr->name() == SYNS_AttrReservedWord) || (attr->name() == SYNS_AttrReservedWord)
|| (attr->name() == SYNS_AttrPreprocessor) || (attr->name() == SYNS_AttrPreprocessor)
) )
&& (token == selText())) { && (token == mSelectionWord)) {
foreground = selectedForeground(); foreground = selectedForeground();
background = selectedBackground(); background = selectedBackground();
return; return;
@ -629,7 +655,7 @@ bool Editor::event(QEvent *event)
int line ; int line ;
if (reason == TipType::Error) { if (reason == TipType::Error) {
pError = getSyntaxIssueAtPosition(p); pError = getSyntaxIssueAtPosition(p);
} else if ((reason == TipType::None) && PointToLine(helpEvent->pos(),line)) { } else if (PointToLine(helpEvent->pos(),line)) {
//it's on gutter //it's on gutter
//see if its error; //see if its error;
PSyntaxIssueList issues = getSyntaxIssuesAtLine(line); PSyntaxIssueList issues = getSyntaxIssuesAtLine(line);
@ -671,7 +697,7 @@ bool Editor::event(QEvent *event)
return true; return true;
} }
// qDebug()<<s<<" -- "<<(int)reason; //qDebug()<<s<<" -- "<<(int)reason;
// Don't rescan the same stuff over and over again (that's slow) // Don't rescan the same stuff over and over again (that's slow)
// if (s = fCurrentWord) and (fText.Hint<>'') then // if (s = fCurrentWord) and (fText.Hint<>'') then
s = s.trimmed(); s = s.trimmed();
@ -994,7 +1020,7 @@ void Editor::onStatusChanged(SynStatusChanges changes)
&& (lines()->count()!=mLineCount) && (lines()->count()!=mLineCount)
&& (lines()->count()!=0) && ((mLineCount>0) || (lines()->count()>1))) { && (lines()->count()!=0) && ((mLineCount>0) || (lines()->count()>1))) {
reparse(); reparse();
if (!readOnly() && pSettings->editor().syntaxCheck() && pSettings->editor().syntaxCheckWhenLineChanged()) if (!readOnly() && highlighter() && pSettings->editor().syntaxCheck() && pSettings->editor().syntaxCheckWhenLineChanged())
pMainWindow->checkSyntaxInBack(this); pMainWindow->checkSyntaxInBack(this);
} }
mLineCount = lines()->count(); mLineCount = lines()->count();
@ -1017,6 +1043,32 @@ void Editor::onStatusChanged(SynStatusChanges changes)
// scSelection includes anything caret related // scSelection includes anything caret related
if (changes.testFlag(SynStatusChange::scSelection)) { if (changes.testFlag(SynStatusChange::scSelection)) {
mSelectionWord="";
if (selAvail()) {
BufferCoord wordBegin,wordEnd,bb,be;
bb = blockBegin();
be = blockEnd();
wordBegin = WordStartEx(bb);
wordEnd = WordEndEx(be);
if (wordBegin.Line == bb.Line
&& wordBegin.Char == bb.Char
&& wordEnd.Line == be.Line
&& wordEnd.Char == be.Char) {
if (wordBegin.Line>=1 && wordBegin.Line<=lines()->count()) {
QString line = lines()->getString(wordBegin.Line-1);
mSelectionWord = line.mid(wordBegin.Char-1,wordEnd.Char-wordBegin.Char);
}
}
// qDebug()<<QString("(%1,%2)").arg(bb.Line).arg(bb.Char)
// <<" - "<<QString("(%1,%2)").arg(be.Line).arg(be.Char)
// <<" - "<<QString("(%1,%2)").arg(wordBegin.Line).arg(wordBegin.Char)
// <<" - "<<QString("(%1,%2)").arg(wordEnd.Line).arg(wordEnd.Char)
// <<" : "<<mSelectionWord;
}
if (mOldSelectionWord != mSelectionWord) {
invalidate();
mOldSelectionWord = mSelectionWord;
}
pMainWindow->updateStatusbarForLineCol(); pMainWindow->updateStatusbarForLineCol();
// // Update the function tip // // Update the function tip

View File

@ -28,6 +28,9 @@ Editor* EditorList::newEditor(const QString& filename, const QByteArray& encodin
parentPageControl = getNewEditorPageControl(); parentPageControl = getNewEditorPageControl();
else else
parentPageControl = page; parentPageControl = page;
if (!filename.isEmpty() && QFile(filename).exists()) {
pMainWindow->fileSystemWatcher()->addPath(filename);
}
return new Editor(parentPageControl,filename,encoding,inProject,newFile,parentPageControl); return new Editor(parentPageControl,filename,encoding,inProject,newFile,parentPageControl);
//UpdateLayout; //UpdateLayout;
} }
@ -90,6 +93,7 @@ bool EditorList::closeEditor(Editor* editor, bool transferFocus, bool force) {
pMainWindow->rebuildOpenedFileHisotryMenu(); pMainWindow->rebuildOpenedFileHisotryMenu();
} }
pMainWindow->fileSystemWatcher()->removePath(editor->filename());
//editor->deleteLater(); //editor->deleteLater();
delete editor; delete editor;

View File

@ -122,6 +122,9 @@ MainWindow::MainWindow(QWidget *parent)
//class browser //class browser
ui->classBrowser->setModel(&mClassBrowserModel); ui->classBrowser->setModel(&mClassBrowserModel);
connect(&mFileSystemWatcher,&QFileSystemWatcher::fileChanged,
this, &MainWindow::onFileChanged);
mCompletionPopup = std::make_shared<CodeCompletionPopup>(); mCompletionPopup = std::make_shared<CodeCompletionPopup>();
mHeaderCompletionPopup = std::make_shared<HeaderCompletionPopup>(); mHeaderCompletionPopup = std::make_shared<HeaderCompletionPopup>();
@ -277,6 +280,11 @@ void MainWindow::applySettings()
updateDebuggerSettings(); updateDebuggerSettings();
} }
QFileSystemWatcher *MainWindow::fileSystemWatcher()
{
return &mFileSystemWatcher;
}
void MainWindow::removeActiveBreakpoints() void MainWindow::removeActiveBreakpoints()
{ {
for (int i=0;i<mEditorList->pageCount();i++) { for (int i=0;i<mEditorList->pageCount();i++) {
@ -506,10 +514,14 @@ void MainWindow::openFile(const QString &filename)
editor->activate(); editor->activate();
return; return;
} }
editor = mEditorList->newEditor(filename,ENCODING_AUTO_DETECT, try {
false,false); editor = mEditorList->newEditor(filename,ENCODING_AUTO_DETECT,
editor->activate(); false,false);
this->updateForEncodingInfo(); editor->activate();
this->updateForEncodingInfo();
} catch (FileError e) {
QMessageBox::critical(this,tr("Error"),e.reason());
}
} }
void MainWindow::setupActions() { void MainWindow::setupActions() {
@ -1032,6 +1044,36 @@ void MainWindow::onAutoSaveTimeout()
updateStatusbarMessage(tr("%1 files autosaved").arg(updateCount)); updateStatusbarMessage(tr("%1 files autosaved").arg(updateCount));
} }
void MainWindow::onFileChanged(const QString &path)
{
Editor *e = mEditorList->getOpenedEditorByFilename(path);
if (e) {
if (QFile(path).exists()) {
e->activate();
if (QMessageBox::question(this,tr("Compile"),
tr("File '%1' was changed.").arg(path)+"<BR /><BR />" + tr("Reload its content from disk?"),
QMessageBox::Yes|QMessageBox::No,
QMessageBox::No) == QMessageBox::Yes) {
try {
e->loadFile();
} catch(FileError e) {
QMessageBox::critical(this,tr("Error"),e.reason());
}
}
} else {
if (QMessageBox::question(this,tr("Compile"),
tr("File '%1' was removed.").arg(path)+"<BR /><BR />" + tr("Keep it open?"),
QMessageBox::Yes|QMessageBox::No,
QMessageBox::Yes) == QMessageBox::No) {
mEditorList->closeEditor(e);
} else {
e->setModified(true);
e->updateCaption();
}
}
}
}
const std::shared_ptr<HeaderCompletionPopup> &MainWindow::headerCompletionPopup() const const std::shared_ptr<HeaderCompletionPopup> &MainWindow::headerCompletionPopup() const
{ {
return mHeaderCompletionPopup; return mHeaderCompletionPopup;

View File

@ -1,6 +1,7 @@
#ifndef MAINWINDOW_H #ifndef MAINWINDOW_H
#define MAINWINDOW_H #define MAINWINDOW_H
#include <QFileSystemWatcher>
#include <QMainWindow> #include <QMainWindow>
#include <QTimer> #include <QTimer>
#include "common.h" #include "common.h"
@ -68,6 +69,7 @@ public:
void showSearchPanel(); void showSearchPanel();
void applySettings(); void applySettings();
QFileSystemWatcher* fileSystemWatcher();
void removeActiveBreakpoints(); void removeActiveBreakpoints();
void setActiveBreakpoint(QString FileName, int Line, bool setFocus=true); void setActiveBreakpoint(QString FileName, int Line, bool setFocus=true);
@ -127,6 +129,7 @@ private:
private slots: private slots:
void onAutoSaveTimeout(); void onAutoSaveTimeout();
void onFileChanged(const QString& path);
void on_actionNew_triggered(); void on_actionNew_triggered();
@ -247,6 +250,7 @@ private:
QList<QAction *> mRecentFileActions; QList<QAction *> mRecentFileActions;
bool mQuitting; bool mQuitting;
QElapsedTimer mParserTimer; QElapsedTimer mParserTimer;
QFileSystemWatcher mFileSystemWatcher;
std::shared_ptr<CodeCompletionPopup> mCompletionPopup; std::shared_ptr<CodeCompletionPopup> mCompletionPopup;
std::shared_ptr<HeaderCompletionPopup> mHeaderCompletionPopup; std::shared_ptr<HeaderCompletionPopup> mHeaderCompletionPopup;

View File

@ -3379,7 +3379,7 @@ QString CppParser::splitPhrase(const QString &phrase, QString &sClazz, QString &
firstOpEnd = i+2; firstOpEnd = i+2;
sOperator = "::"; sOperator = "::";
break; break;
} else if ((phrase[i] == '.') && (bracketLevel=0)) { } else if ((phrase[i] == '.') && (bracketLevel==0)) {
firstOpStart = i; firstOpStart = i;
firstOpEnd = i+1; firstOpEnd = i+1;
sOperator = "."; sOperator = ".";
@ -3771,6 +3771,8 @@ void CppFileListParserThread::run()
void parseFile(PCppParser parser, const QString& fileName, bool inProject, bool onlyIfNotParsed, bool updateView) void parseFile(PCppParser parser, const QString& fileName, bool inProject, bool onlyIfNotParsed, bool updateView)
{ {
if (!parser)
return;
CppFileParserThread* thread = new CppFileParserThread(parser,fileName,inProject,onlyIfNotParsed,updateView); CppFileParserThread* thread = new CppFileParserThread(parser,fileName,inProject,onlyIfNotParsed,updateView);
thread->connect(thread, thread->connect(thread,
&QThread::finished, &QThread::finished,
@ -3781,6 +3783,8 @@ void parseFile(PCppParser parser, const QString& fileName, bool inProject, bool
void parseFileList(PCppParser parser, bool updateView) void parseFileList(PCppParser parser, bool updateView)
{ {
if (!parser)
return;
CppFileListParserThread *thread = new CppFileListParserThread(parser,updateView); CppFileListParserThread *thread = new CppFileListParserThread(parser,updateView);
thread->connect(thread, thread->connect(thread,
&QThread::finished, &QThread::finished,