diff --git a/qrgui/mainWindow/mainWindow.cpp b/qrgui/mainWindow/mainWindow.cpp index c84c4b02f0..2392bc3b4e 100644 --- a/qrgui/mainWindow/mainWindow.cpp +++ b/qrgui/mainWindow/mainWindow.cpp @@ -111,6 +111,7 @@ MainWindow::MainWindow(const QString &fileToOpen) , mRootIndex(QModelIndex()) , mPreferencesDialog(new gui::PreferencesDialog(this)) , mRecentProjectsLimit(SettingsManager::value("recentProjectsLimit").toInt()) + , mRecentFilesLimit(SettingsManager::value("recentFilesLimit").toInt()) , mSceneCustomizer(new SceneCustomizer()) , mInitialFileToOpen(fileToOpen) { @@ -341,6 +342,7 @@ void MainWindow::connectActions() connect(mUi->tabs, &QTabWidget::currentChanged, this, &MainWindow::sceneSelectionChanged); connect(&*mTextManager, &text::TextManager::textChanged, this, &MainWindow::setTextChanged); connect(&*mTextManager, &text::TextManager::textChanged, mUi->actionUndo, &QAction::setEnabled); + connect(&*mTextManager, &text::TextManager::needRefreshRecentFileList, this, &MainWindow::refreshRecentFilesList); connect(&*mProjectManager, &ProjectManager::afterOpen, mUi->paletteTree, &PaletteTree::refreshUserPalettes); connect(&*mProjectManager, &ProjectManager::closed, mUi->paletteTree, &PaletteTree::refreshUserPalettes); @@ -596,6 +598,31 @@ void MainWindow::refreshRecentProjectsList(const QString &fileName) SettingsManager::setValue("recentProjects", previousString); } +void MainWindow::refreshRecentFilesList(const QString &fileName) { + auto previousString = SettingsManager::value("recentFiles").toString(); + auto previousList = previousString.split(";", QString::SkipEmptyParts); + previousList.removeOne(fileName); + + if (!previousList.isEmpty() && (previousList.size() == mRecentFilesLimit)) { + previousList.removeLast(); + } + + previousString.clear(); + if (mRecentFilesLimit > 0) { + previousList.push_front(fileName); + QStringListIterator iterator(previousList); + while (iterator.hasNext()) { + const auto recentFileName = iterator.next(); + const QFileInfo fileInfo(recentFileName); + if (fileInfo.exists() && fileInfo.isFile()) { + previousString = previousString + recentFileName + ";"; + } + } + } + + SettingsManager::setValue("recentFiles", previousString); +} + void MainWindow::openRecentProjectsMenu() { mRecentProjectsMenu->clear(); @@ -614,6 +641,26 @@ void MainWindow::openRecentProjectsMenu() } } +void MainWindow::openRecentFilesMenu() +{ + mRecentFilesMenu->clear(); + const auto stringList = SettingsManager::value("recentFiles").toString(); + auto recentFiles = stringList.split(";", QString::SkipEmptyParts); + mRecentFilesLimit = SettingsManager::value("recentFilesLimit", mRecentFilesLimit).toInt(); + while (recentFiles.size() > mRecentFilesLimit) { + recentFiles.pop_front(); + } + + for (auto &&filePath : recentFiles) { + const QFileInfo fileInfo(filePath); + if (fileInfo.exists() && fileInfo.isFile()) { + mRecentFilesMenu->addAction(filePath); + QObject::connect(mRecentFilesMenu->actions().last(), &QAction::triggered + , &*mProjectManager, [this, filePath](){ mProjectManager->openExisting(filePath);}); + } + } +} + void MainWindow::tryToSave() { if(!mProjectManager->saveText() && !mProjectManager->saveOrSuggestToSaveAs()) { @@ -2117,6 +2164,10 @@ void MainWindow::initRecentProjectsMenu() mRecentProjectsMenu = new QMenu(tr("Recent projects"), mUi->menu_File); mUi->menu_File->insertMenu(mUi->menu_File->actions().at(1), mRecentProjectsMenu); connect(mRecentProjectsMenu, &QMenu::aboutToShow, this, &MainWindow::openRecentProjectsMenu); + + mRecentFilesMenu = new QMenu(tr("Recent files"), mUi->menu_File); + mUi->menu_File->insertMenu(mUi->menu_File->actions().at(2), mRecentFilesMenu); + connect(mRecentFilesMenu, &QMenu::aboutToShow, this, &MainWindow::openRecentFilesMenu); } void MainWindow::saveDiagramAsAPictureToFile(const QString &fileName) diff --git a/qrgui/mainWindow/mainWindow.h b/qrgui/mainWindow/mainWindow.h index 75ced6cba7..9edb11dfb3 100644 --- a/qrgui/mainWindow/mainWindow.h +++ b/qrgui/mainWindow/mainWindow.h @@ -195,6 +195,7 @@ public slots: void closeStartTab(); void closeAllTabs(); void refreshRecentProjectsList(const QString &fileName); + void refreshRecentFilesList(const QString &fileName); void createDiagram(const QString &idString); /// Creates project with specified root diagram bool createProject(const QString &diagramIdString); @@ -230,6 +231,7 @@ private slots: void hideBottomDocks(); void openRecentProjectsMenu(); + void openRecentFilesMenu(); void tryToSave(); void saveDiagramAsAPicture(); @@ -395,7 +397,9 @@ private slots: qReal::gui::PreferencesDialog *mPreferencesDialog; //Has ownership int mRecentProjectsLimit {}; + int mRecentFilesLimit {}; QMenu *mRecentProjectsMenu {}; // Has ownership + QMenu *mRecentFilesMenu {}; // Has ownership QScopedPointer mFindHelper; StartWidget *mStartWidget {}; // Has ownership diff --git a/qrgui/systemFacade/components/nullTextManager.h b/qrgui/systemFacade/components/nullTextManager.h index 31533b8675..f15af3a249 100644 --- a/qrgui/systemFacade/components/nullTextManager.h +++ b/qrgui/systemFacade/components/nullTextManager.h @@ -46,6 +46,7 @@ class QRGUI_SYSTEM_FACADE_EXPORT NullTextManager : public TextManagerInterface void showInTextEditor(const QFileInfo &fileInfo, const QString &genName , const text::LanguageInfo &language) override; + void showInTextEditor(const QFileInfo &fileInfo, const text::LanguageInfo &language) override; bool saveText(bool saveAs) override; diff --git a/qrgui/textEditor/textManager.cpp b/qrgui/textEditor/textManager.cpp index 59a5040126..9b6bba126f 100644 --- a/qrgui/textEditor/textManager.cpp +++ b/qrgui/textEditor/textManager.cpp @@ -254,6 +254,7 @@ void TextManager::showInTextEditor(const QFileInfo &fileInfo, const text::Langua return; } + emit needRefreshRecentFileList(filePath); area->show(); // Need to bind diagram and code file only if code is just generated @@ -289,7 +290,6 @@ bool TextManager::saveText(bool saveAs) if (!fileInfo.fileName().isEmpty()) { mMainWindow.setTabText(area, fileInfo.fileName()); - utils::OutFile out(fileInfo.absoluteFilePath()); out() << area->text(); @@ -304,6 +304,8 @@ bool TextManager::saveText(bool saveAs) if (saveAs && !diagram.isNull()) { emit mSystemEvents.codePathChanged(diagram, path(area), fileInfo); } + + emit needRefreshRecentFileList(fileInfo.absoluteFilePath()); } return true; diff --git a/qrgui/textEditor/textManager.h b/qrgui/textEditor/textManager.h index 6a2a3f7195..2946cdadb5 100644 --- a/qrgui/textEditor/textManager.h +++ b/qrgui/textEditor/textManager.h @@ -17,7 +17,6 @@ #include #include #include - #include "qrgui/textEditor/textEditorDeclSpec.h" #include "qrgui/textEditor/textManagerInterface.h" #include "qrgui/textEditor/codeBlockManager.h" diff --git a/qrgui/textEditor/textManagerInterface.h b/qrgui/textEditor/textManagerInterface.h index a47767156f..9c6873543d 100644 --- a/qrgui/textEditor/textManagerInterface.h +++ b/qrgui/textEditor/textManagerInterface.h @@ -56,6 +56,7 @@ class QRGUI_TEXT_EDITOR_EXPORT TextManagerInterface : public QObject signals: void textChanged(text::QScintillaTextEdit *editor, bool changed); + void needRefreshRecentFileList(const QString &fileName); }; } diff --git a/qrkernel/settingsDefaultValues b/qrkernel/settingsDefaultValues index 0abbb18cbe..0b69b62c81 100644 --- a/qrkernel/settingsDefaultValues +++ b/qrkernel/settingsDefaultValues @@ -67,6 +67,7 @@ pythonPath=python generationTimeout=100 nodesStateButtonExpands=true recentProjectsLimit=5 +recentFilesLimit=7 dragArea = 12 touchMode=false scriptInterpretation=false diff --git a/qrtranslations/fr/qrgui_mainWindow_fr.ts b/qrtranslations/fr/qrgui_mainWindow_fr.ts index 99ff9c30a2..424848b06a 100644 --- a/qrtranslations/fr/qrgui_mainWindow_fr.ts +++ b/qrtranslations/fr/qrgui_mainWindow_fr.ts @@ -708,7 +708,7 @@ qReal::MainWindow - + Could not save file, try to save it to another place @@ -717,7 +717,7 @@ À propo de QReal - + Restore default settings @@ -729,7 +729,7 @@ WARNING: The settings will be restored after application restart - + Error Erreur @@ -861,6 +861,11 @@ WARNING: The settings will be restored after application restart Recent projects Projets récents + + + Recent files + + Save File diff --git a/qrtranslations/fr/qrgui_textEditor_fr.ts b/qrtranslations/fr/qrgui_textEditor_fr.ts index 9ba4933b69..cc9b44c798 100644 --- a/qrtranslations/fr/qrgui_textEditor_fr.ts +++ b/qrtranslations/fr/qrgui_textEditor_fr.ts @@ -14,7 +14,7 @@ - + All files (*) Tous les fichiers (*) diff --git a/qrtranslations/ru/qrgui_mainWindow_ru.ts b/qrtranslations/ru/qrgui_mainWindow_ru.ts index 62ee5f5e24..80b270af2a 100644 --- a/qrtranslations/ru/qrgui_mainWindow_ru.ts +++ b/qrtranslations/ru/qrgui_mainWindow_ru.ts @@ -735,7 +735,7 @@ О QReal - + Error Ошибка @@ -788,7 +788,7 @@ Создать диаграмму - + Restore default settings Восстановить настройки по-умолчанию @@ -802,7 +802,7 @@ WARNING: The settings will be restored after application restart ВНИМАНИЕ: Настройки будут сброшены после перезапуска приложения - + Could not save file, try to save it to another place Не удалось сохранить файл, попробуйте сохранить его в другое место @@ -886,6 +886,11 @@ WARNING: The settings will be restored after application restart Recent projects Недавние проекты + + + Recent files + Недавние файлы + Save File diff --git a/qrtranslations/ru/qrgui_textEditor_ru.ts b/qrtranslations/ru/qrgui_textEditor_ru.ts index 51ba34b7e7..11a17841ce 100644 --- a/qrtranslations/ru/qrgui_textEditor_ru.ts +++ b/qrtranslations/ru/qrgui_textEditor_ru.ts @@ -56,7 +56,7 @@ Сохранить перед закрытием? - + All files (*) Все файлы (*)