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

View File

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

View File

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

View File

@ -122,6 +122,9 @@ MainWindow::MainWindow(QWidget *parent)
//class browser
ui->classBrowser->setModel(&mClassBrowserModel);
connect(&mFileSystemWatcher,&QFileSystemWatcher::fileChanged,
this, &MainWindow::onFileChanged);
mCompletionPopup = std::make_shared<CodeCompletionPopup>();
mHeaderCompletionPopup = std::make_shared<HeaderCompletionPopup>();
@ -277,6 +280,11 @@ void MainWindow::applySettings()
updateDebuggerSettings();
}
QFileSystemWatcher *MainWindow::fileSystemWatcher()
{
return &mFileSystemWatcher;
}
void MainWindow::removeActiveBreakpoints()
{
for (int i=0;i<mEditorList->pageCount();i++) {
@ -506,10 +514,14 @@ void MainWindow::openFile(const QString &filename)
editor->activate();
return;
}
try {
editor = mEditorList->newEditor(filename,ENCODING_AUTO_DETECT,
false,false);
editor->activate();
this->updateForEncodingInfo();
} catch (FileError e) {
QMessageBox::critical(this,tr("Error"),e.reason());
}
}
void MainWindow::setupActions() {
@ -1032,6 +1044,36 @@ void MainWindow::onAutoSaveTimeout()
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
{
return mHeaderCompletionPopup;

View File

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

View File

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