From 496421e97de16dfbc41d2ae6b9f6d960336717a4 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Fri, 11 Aug 2023 17:09:30 +0800 Subject: [PATCH] - fix: Wrong compiler settings if xcode is not installed in mac os. - enhancement: Name for new files will not be different from files openned. --- NEWS.md | 1 + RedPandaIDE/editorlist.cpp | 35 +++++++++++++++++++++++++++-------- RedPandaIDE/editorlist.h | 11 ++++++----- RedPandaIDE/mainwindow.cpp | 21 +++++++++++++-------- RedPandaIDE/settings.cpp | 2 +- 5 files changed, 48 insertions(+), 22 deletions(-) diff --git a/NEWS.md b/NEWS.md index 7b219363..ff7a17a1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -25,6 +25,7 @@ Red Panda C++ Version 2.24 - change: Remove option "clear all symbols when current editor is hidden". - fix: When opening multiple files, only the active file should be parsed. - fix: Wrong compiler settings if xcode is not installed in mac os. + - enhancement: Name for new files will not be different from files openned. Red Panda C++ Version 2.23 diff --git a/RedPandaIDE/editorlist.cpp b/RedPandaIDE/editorlist.cpp index 2ddcf1a6..82ea1db6 100644 --- a/RedPandaIDE/editorlist.cpp +++ b/RedPandaIDE/editorlist.cpp @@ -315,24 +315,43 @@ void EditorList::applyColorSchemes(const QString& name) } } -bool EditorList::isFileOpened(const QString &name) +bool EditorList::isFileOpened(const QString &fullfilepath) const { - QFileInfo fileInfo(name); + QFileInfo fileInfo(fullfilepath); QString filename = fileInfo.absoluteFilePath(); for (int i=0;icount();i++) { Editor* e = static_cast(mLeftPageWidget->widget(i)); - if (e->filename().compare(filename)==0 || e->filename().compare(name)==0) + if (e->filename().compare(filename)==0 || e->filename().compare(fullfilepath)==0) return true; } for (int i=0;icount();i++) { Editor* e = static_cast(mRightPageWidget->widget(i)); - if (e->filename().compare(filename)==0 || e->filename().compare(name)==0) + if (e->filename().compare(filename)==0 || e->filename().compare(fullfilepath)==0) return true; } return false; } -int EditorList::pageCount() +bool EditorList::hasFilename(const QString &filename) const +{ + for (int i=0;icount();i++) { + Editor* e = static_cast(mLeftPageWidget->widget(i)); + QFileInfo fileInfo(e->filename()); + QString name = fileInfo.fileName(); + if (name.compare(filename, PATH_SENSITIVITY)==0 ) + return true; + } + for (int i=0;icount();i++) { + Editor* e = static_cast(mRightPageWidget->widget(i)); + QFileInfo fileInfo(e->filename()); + QString name = fileInfo.fileName(); + if (name.compare(filename, PATH_SENSITIVITY)==0 ) + return true; + } + return false; +} + +int EditorList::pageCount() const { return mLeftPageWidget->count()+mRightPageWidget->count(); } @@ -416,7 +435,7 @@ void EditorList::forceCloseEditor(Editor *editor) emit editorClosed(); } -Editor* EditorList::getOpenedEditorByFilename(QString filename) +Editor* EditorList::getOpenedEditorByFilename(QString filename) const { if (filename.isEmpty()) return nullptr; @@ -439,7 +458,7 @@ Editor* EditorList::getOpenedEditorByFilename(QString filename) return nullptr; } -bool EditorList::getContentFromOpenedEditor(const QString &filename, QStringList &buffer) +bool EditorList::getContentFromOpenedEditor(const QString &filename, QStringList &buffer) const { if (pMainWindow->isQuitting()) return false; @@ -450,7 +469,7 @@ bool EditorList::getContentFromOpenedEditor(const QString &filename, QStringList return true; } -void EditorList::getVisibleEditors(Editor *&left, Editor *&right) +void EditorList::getVisibleEditors(Editor *&left, Editor *&right) const { switch(mLayout) { case LayoutShowType::lstLeft: diff --git a/RedPandaIDE/editorlist.h b/RedPandaIDE/editorlist.h index 20e27386..43a9d7c4 100644 --- a/RedPandaIDE/editorlist.h +++ b/RedPandaIDE/editorlist.h @@ -60,19 +60,20 @@ public: void forceCloseEditor(Editor* editor); - Editor* getOpenedEditorByFilename(QString filename); + Editor* getOpenedEditorByFilename(QString filename) const; - bool getContentFromOpenedEditor(const QString& filename, QStringList& buffer); + bool getContentFromOpenedEditor(const QString& filename, QStringList& buffer) const; - void getVisibleEditors(Editor*& left, Editor*& right); + void getVisibleEditors(Editor*& left, Editor*& right) const; void updateLayout(); void beginUpdate(); void endUpdate(); void applySettings(); void applyColorSchemes(const QString& name); - bool isFileOpened(const QString& name); - int pageCount(); + bool isFileOpened(const QString& fullfilepath) const; + bool hasFilename(const QString& filename) const; + int pageCount() const; void selectNextPage(); void selectPreviousPage(); diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 3182e402..bad50f4d 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -3362,14 +3362,19 @@ void MainWindow::updateTools() void MainWindow::newEditor(const QString& suffix) { try { - QString filename=QString("untitled%1").arg(getNewFileNumber()); - if (suffix.isEmpty()) { - if (pSettings->editor().defaultFileCpp()) - filename+=".cpp"; - else - filename+=".c"; - } else - filename+= "." + suffix; + QString filename; + + do { + filename = QString("untitled%1").arg(getNewFileNumber()); + if (suffix.isEmpty()) { + if (pSettings->editor().defaultFileCpp()) + filename+=".cpp"; + else + filename+=".c"; + } else + filename+= "." + suffix; + + } while(mEditorList->hasFilename(filename)); Editor * editor=mEditorList->newEditor(filename, pSettings->editor().defaultEncoding(), nullptr,true); diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index bd19e6ed..057a66eb 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -4385,7 +4385,7 @@ void Settings::CodeCompletion::doLoad() mHideSymbolsStartsWithUnderLine = boolValue("hide_symbols_start_with_underline", false); bool shouldShare= true; - bool doClear = false; +// bool doClear = false; //#ifdef Q_OS_WIN // MEMORYSTATUSEX statex;