From d2ca1990249452bff2e90d670f9aac7c22d26385 Mon Sep 17 00:00:00 2001 From: royqh1979 Date: Fri, 22 Oct 2021 07:42:51 +0800 Subject: [PATCH] work save --- RedPandaIDE/mainwindow.cpp | 95 +++++++++++++++---- RedPandaIDE/mainwindow.h | 12 +++ RedPandaIDE/mainwindow.ui | 26 +++++ RedPandaIDE/settings.cpp | 12 +++ RedPandaIDE/settings.h | 5 + RedPandaIDE/settingsdialog/settingswidget.cpp | 22 ++++- 6 files changed, 152 insertions(+), 20 deletions(-) diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index d26b7837..e575fe78 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -90,10 +90,23 @@ MainWindow::MainWindow(QWidget *parent) ui->tblStackTrace->setModel(mDebugger->backtraceModel()); ui->watchView->setModel(mDebugger->watchModel()); - mDebugger->breakpointModel()->load(includeTrailingPathDelimiter(pSettings->dirs().config()) - +DEV_BREAKPOINTS_FILE); - mDebugger->watchModel()->load(includeTrailingPathDelimiter(pSettings->dirs().config()) + try { + mDebugger->breakpointModel()->load(includeTrailingPathDelimiter(pSettings->dirs().config()) + +DEV_BREAKPOINTS_FILE); + } catch (FileError &e) { + QMessageBox::warning(nullptr, + tr("Error"), + e.reason()); + } + try { + mDebugger->watchModel()->load(includeTrailingPathDelimiter(pSettings->dirs().config()) +DEV_WATCH_FILE); + } catch (FileError &e) { + QMessageBox::warning(nullptr, + tr("Error"), + e.reason()); + } + // ui->actionIndent->setShortcut(Qt::Key_Tab); // ui->actionUnIndent->setShortcut(Qt::Key_Tab | Qt::ShiftModifier); @@ -149,14 +162,39 @@ MainWindow::MainWindow(QWidget *parent) mTodoParser = std::make_shared(); mSymbolUsageManager = std::make_shared(); - mSymbolUsageManager->load(); + try { + mSymbolUsageManager->load(); + } catch (FileError &e) { + QMessageBox::warning(nullptr, + tr("Error"), + e.reason()); + } + mCodeSnippetManager = std::make_shared(); - mCodeSnippetManager->load(); + try { + mCodeSnippetManager->load(); + } catch (FileError &e) { + QMessageBox::warning(nullptr, + tr("Error"), + e.reason()); + } mToolsManager = std::make_shared(); - mToolsManager->load(); + try { + mToolsManager->load(); + } catch (FileError &e) { + QMessageBox::warning(nullptr, + tr("Error"), + e.reason()); + } mBookmarkModel = std::make_shared(); - mBookmarkModel->load(includeTrailingPathDelimiter(pSettings->dirs().config()) + try { + mBookmarkModel->load(includeTrailingPathDelimiter(pSettings->dirs().config()) +DEV_BOOKMARK_FILE); + } catch (FileError &e) { + QMessageBox::warning(nullptr, + tr("Error"), + e.reason()); + } ui->tableBookmark->setModel(mBookmarkModel.get()); mSearchResultTreeModel = std::make_shared(&mSearchResultModel); mSearchResultListModel = std::make_shared(&mSearchResultModel); @@ -169,6 +207,10 @@ MainWindow::MainWindow(QWidget *parent) ui->searchView,&QTreeView::expandAll); ui->replacePanel->setVisible(false); + + ui->treeFiles->setModel(&mFileSystemModel); + mFileSystemModel.setRootPath(pSettings->environment().currentFolder()); + ui->treeFiles->setRootIndex(mFileSystemModel.index(pSettings->environment().currentFolder())); //class browser ui->classBrowser->setModel(&mClassBrowserModel); @@ -2030,6 +2072,8 @@ void MainWindow::buildContextMenus() mFileEncodingStatus->setContextMenuPolicy(Qt::CustomContextMenu); connect(mFileEncodingStatus,&QWidget::customContextMenuRequested, this, &MainWindow::onFileEncodingContextMenu); + + // } void MainWindow::buildEncodingMenu() @@ -2710,18 +2754,37 @@ void MainWindow::closeEvent(QCloseEvent *event) { settings.setLeftPanelIndex(ui->tabInfos->currentIndex()); settings.setLeftPanelOpenned(mLeftPanelOpenned); settings.save(); - mBookmarkModel->save(includeTrailingPathDelimiter(pSettings->dirs().config()) + try { + mBookmarkModel->save(includeTrailingPathDelimiter(pSettings->dirs().config()) +DEV_BOOKMARK_FILE); - if (pSettings->debugger().autosaveBreakpoints()) - mDebugger->breakpointModel()->save(includeTrailingPathDelimiter(pSettings->dirs().config()) - +DEV_BREAKPOINTS_FILE); - else + } catch (FileError& e) { + QMessageBox::warning(nullptr, + tr("Save Error"), + e.reason()); + } + + if (pSettings->debugger().autosaveBreakpoints()) { + try { + mDebugger->breakpointModel()->save(includeTrailingPathDelimiter(pSettings->dirs().config()) + +DEV_BREAKPOINTS_FILE); + } catch (FileError& e) { + QMessageBox::warning(nullptr, + tr("Save Error"), + e.reason()); + } + } else removeFile(includeTrailingPathDelimiter(pSettings->dirs().config()) +DEV_BREAKPOINTS_FILE); - if (pSettings->debugger().autosaveWatches()) - mDebugger->watchModel()->save(includeTrailingPathDelimiter(pSettings->dirs().config()) - +DEV_WATCH_FILE); - else + if (pSettings->debugger().autosaveWatches()) { + try { + mDebugger->watchModel()->save(includeTrailingPathDelimiter(pSettings->dirs().config()) + +DEV_WATCH_FILE); + } catch (FileError& e) { + QMessageBox::warning(nullptr, + tr("Save Error"), + e.reason()); + } + } else removeFile(includeTrailingPathDelimiter(pSettings->dirs().config()) +DEV_WATCH_FILE); diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index 0689075c..44eb95ce 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "common.h" #include "widgets/searchresultview.h" #include "widgets/classbrowser.h" @@ -458,6 +459,7 @@ private: PCodeSnippetManager mCodeSnippetManager; PTodoParser mTodoParser; PToolsManager mToolsManager; + QFileSystemModel mFileSystemModel; bool mCheckSyntaxInBack; bool mOpenClosingBottomPanel; @@ -504,6 +506,16 @@ private: QAction * mClassBrowser_goto_definition; QWidget * mClassBrowserToolbar; + //actions for files view + QAction * mFilesView_Open; + QAction * mFilesView_OpenWithExternal; + QAction * mFilesView_OpenInTerminal; + QAction * mFilesView_OpenInExplorer; + QAction * mFilesView_OnlyShowDevFiles; + QAction * mFilesView_LocateCurrent; + + QWidget * mFilesViewToolbar; + //action for debug console QAction * mDebugConsole_ShowCommandLog; QAction * mDebugConsole_Clear; diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui index d207278e..1666e1fa 100644 --- a/RedPandaIDE/mainwindow.ui +++ b/RedPandaIDE/mainwindow.ui @@ -204,6 +204,32 @@ + + + + :/icons/images/newlook24/018-copy.png:/icons/images/newlook24/018-copy.png + + + Files + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index 2191a5ed..a43075e0 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -2618,6 +2618,7 @@ void Settings::Environment::doLoad() mInterfaceFont = stringValue("interface font","Segoe UI"); mInterfaceFontSize = intValue("interface font size",10); mLanguage = stringValue("language", QLocale::system().name()); + mCurrentFolder = stringValue("current_folder",QDir::currentPath()); } int Settings::Environment::interfaceFontSize() const @@ -2640,6 +2641,16 @@ void Settings::Environment::setLanguage(const QString &language) mLanguage = language; } +const QString &Settings::Environment::currentFolder() const +{ + return mCurrentFolder; +} + +void Settings::Environment::setCurrentFolder(const QString &newCurrentFolder) +{ + mCurrentFolder = newCurrentFolder; +} + void Settings::Environment::doSave() { //Appearence @@ -2647,6 +2658,7 @@ void Settings::Environment::doSave() saveValue("interface font", mInterfaceFont); saveValue("interface font size", mInterfaceFontSize); saveValue("language", mLanguage); + saveValue("current_folder",mCurrentFolder); } QString Settings::Environment::interfaceFont() const diff --git a/RedPandaIDE/settings.h b/RedPandaIDE/settings.h index 102a1332..906077ed 100644 --- a/RedPandaIDE/settings.h +++ b/RedPandaIDE/settings.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "qsynedit/SynEdit.h" /** @@ -455,6 +456,9 @@ public: QString language() const; void setLanguage(const QString &language); + const QString ¤tFolder() const; + void setCurrentFolder(const QString &newCurrentFolder); + private: //Appearence @@ -462,6 +466,7 @@ public: QString mInterfaceFont; int mInterfaceFontSize; QString mLanguage; + QString mCurrentFolder; // _Base interface protected: void doSave() override; diff --git a/RedPandaIDE/settingsdialog/settingswidget.cpp b/RedPandaIDE/settingsdialog/settingswidget.cpp index 58c00b65..1375594d 100644 --- a/RedPandaIDE/settingsdialog/settingswidget.cpp +++ b/RedPandaIDE/settingsdialog/settingswidget.cpp @@ -6,10 +6,12 @@ #include #include #include +#include #include #include #include #include "../widgets/coloredit.h" +#include "../utils.h" SettingsWidget::SettingsWidget(const QString &name, const QString &group, QWidget *parent): QWidget(parent), @@ -27,14 +29,26 @@ void SettingsWidget::init() void SettingsWidget::load() { - doLoad(); - clearSettingsChanged(); + try { + doLoad(); + clearSettingsChanged(); + } catch (FileError & e) { + QMessageBox::warning(nullptr, + tr("Load Error"), + e.reason()); + } } void SettingsWidget::save() { - doSave(); - clearSettingsChanged(); + try { + doSave(); + clearSettingsChanged(); + } catch (FileError & e) { + QMessageBox::warning(nullptr, + tr("Save Error"), + e.reason()); + } } void SettingsWidget::connectAbstractItemView(QAbstractItemView *pView)