From 9d829876b30db13b6a49210f7d3aa50cf1667e29 Mon Sep 17 00:00:00 2001 From: "royqh1979@gmail.com" Date: Fri, 22 Oct 2021 16:43:53 +0800 Subject: [PATCH] - fix: app's title not update when editor closed - fix: editor's modified status not correctly updated when using new file template --- NEWS.md | 1 + RedPandaIDE/editor.cpp | 16 +++++++++++----- RedPandaIDE/editorlist.cpp | 12 +++++++++--- RedPandaIDE/editorlist.h | 4 ++-- RedPandaIDE/systemconsts.h | 2 +- RedPandaIDE/widgets/bookmarkmodel.cpp | 3 +-- RedPandaIDE/widgets/bookmarkmodel.h | 3 +-- 7 files changed, 26 insertions(+), 15 deletions(-) diff --git a/NEWS.md b/NEWS.md index 605cdb47..d40958e5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -12,6 +12,7 @@ Version 0.7.0 - enhancement: autosave/load breakpoints - enhancement: autosave/load watches - implement: files view + - fix: app's title not update when editor closed Version 0.6.8 - enhancement: add link to cppreference in the help menu diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 16840631..0f433b16 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -77,6 +77,7 @@ Editor::Editor(QWidget *parent, const QString& filename, mSelectionWord(), mSaving(false) { + mFilename.replace("/",QDir::separator()); mUseCppSyntax = pSettings->editor().defaultFileCpp(); if (mFilename.isEmpty()) { mFilename = tr("untitled")+QString("%1").arg(getNewFileNumber()); @@ -97,9 +98,6 @@ Editor::Editor(QWidget *parent, const QString& filename, else mFileEncoding = mEncodingOption; highlighter=highlighterManager.getCppHighlighter(); - if (parentPageControl!=nullptr) { - insertCodeSnippet(pMainWindow->codeSnippetManager()->newFileTemplate()); - } } if (highlighter) { @@ -152,8 +150,16 @@ Editor::Editor(QWidget *parent, const QString& filename, connect(this, &QWidget::customContextMenuRequested, pMainWindow, &MainWindow::onEditorContextMenu); - resetBookmarks(); - resetBreakpoints(); + if (isNew && parentPageControl!=nullptr) { + QString fileTemplate = pMainWindow->codeSnippetManager()->newFileTemplate(); + if (!fileTemplate.isEmpty()) { + insertCodeSnippet(fileTemplate); + } + } + if (!isNew && parentPageControl!=nullptr) { + resetBookmarks(); + resetBreakpoints(); + } } Editor::~Editor() { diff --git a/RedPandaIDE/editorlist.cpp b/RedPandaIDE/editorlist.cpp index f3bdb504..7f8adc88 100644 --- a/RedPandaIDE/editorlist.cpp +++ b/RedPandaIDE/editorlist.cpp @@ -6,6 +6,7 @@ #include #include "settings.h" #include "project.h" +#include "systemconsts.h" EditorList::EditorList(QTabWidget* leftPageWidget, QTabWidget* rightPageWidget, @@ -299,15 +300,18 @@ void EditorList::forceCloseEditor(Editor *editor) endUpdate(); } -Editor* EditorList::getOpenedEditorByFilename(const QString &filename) +Editor* EditorList::getOpenedEditorByFilename(QString filename) { if (filename.isEmpty()) return nullptr; + filename.replace("/",QDir::separator()); QFileInfo fileInfo(filename); QString fullname = fileInfo.absoluteFilePath(); + fullname.replace("/",QDir::separator()); for (int i=0;icount();i++) { Editor* e = static_cast(mLeftPageWidget->widget(i)); - if (e->filename().compare(filename)==0 || e->filename().compare(fullname)==0) { + if (e->filename().compare(filename, PATH_SENSITIVITY)==0 || + e->filename().compare(fullname, PATH_SENSITIVITY)==0) { return e; } } @@ -320,10 +324,11 @@ Editor* EditorList::getOpenedEditorByFilename(const QString &filename) return nullptr; } -Editor *EditorList::getEditorByFilename(const QString &filename) +Editor *EditorList::getEditorByFilename(QString filename) { if (filename.isEmpty()) return nullptr; + filename.replace("/",QDir::separator()); //check if an editor is already openned Editor* e=getOpenedEditorByFilename(filename); if (e!=nullptr) @@ -333,6 +338,7 @@ Editor *EditorList::getEditorByFilename(const QString &filename) //Create a new editor QFileInfo fileInfo(filename); QString fullname = fileInfo.absoluteFilePath(); + fullname.replace("/",QDir::separator()); if (fileInfo.exists()) return newEditor(fullname,ENCODING_AUTO_DETECT,false,false); return nullptr; diff --git a/RedPandaIDE/editorlist.h b/RedPandaIDE/editorlist.h index 8d8cd775..1b150275 100644 --- a/RedPandaIDE/editorlist.h +++ b/RedPandaIDE/editorlist.h @@ -35,9 +35,9 @@ public: void forceCloseEditor(Editor* editor); - Editor* getOpenedEditorByFilename(const QString& filename); + Editor* getOpenedEditorByFilename(QString filename); - Editor* getEditorByFilename(const QString& filename); + Editor* getEditorByFilename(QString filename); bool getContentFromOpenedEditor(const QString& filename, QStringList& buffer); diff --git a/RedPandaIDE/systemconsts.h b/RedPandaIDE/systemconsts.h index 903a5f7f..b15a92ed 100644 --- a/RedPandaIDE/systemconsts.h +++ b/RedPandaIDE/systemconsts.h @@ -3,7 +3,7 @@ #include -#define DEVCPP_VERSION "0.6.9" +#define DEVCPP_VERSION "0.7.0" #define APP_SETTSINGS_FILENAME "redpandacpp.ini" #ifdef Q_OS_WIN diff --git a/RedPandaIDE/widgets/bookmarkmodel.cpp b/RedPandaIDE/widgets/bookmarkmodel.cpp index 43977384..75f8dc0e 100644 --- a/RedPandaIDE/widgets/bookmarkmodel.cpp +++ b/RedPandaIDE/widgets/bookmarkmodel.cpp @@ -188,7 +188,6 @@ void BookmarkModel::removeBookmarkAt(int i) endRemoveRows(); } -#ifdef QT_DEBUG bool BookmarkModel::isBookmarkExists(const QString &filename, int line) { foreach (const PBookmark& bookmark, mBookmarks) { @@ -245,4 +244,4 @@ QVariant BookmarkModel::headerData(int section, Qt::Orientation orientation, int } return QVariant(); } -#endif + diff --git a/RedPandaIDE/widgets/bookmarkmodel.h b/RedPandaIDE/widgets/bookmarkmodel.h index 39bacfa0..8b100658 100644 --- a/RedPandaIDE/widgets/bookmarkmodel.h +++ b/RedPandaIDE/widgets/bookmarkmodel.h @@ -33,9 +33,8 @@ public slots: void onFileDeleteLines(const QString& filename, int startLine, int count); void onFileInsertLines(const QString& filename, int startLine, int count); private: -#ifdef QT_DEBUG bool isBookmarkExists(const QString&filename, int line); -#endif + private: QList mBookmarks;