Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a list of recent files #1885

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions qrgui/mainWindow/mainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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()) {
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions qrgui/mainWindow/mainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -230,6 +231,7 @@ private slots:
void hideBottomDocks();

void openRecentProjectsMenu();
void openRecentFilesMenu();

void tryToSave();
void saveDiagramAsAPicture();
Expand Down Expand Up @@ -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<FindManager> mFindHelper;
StartWidget *mStartWidget {}; // Has ownership
Expand Down
1 change: 1 addition & 0 deletions qrgui/systemFacade/components/nullTextManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion qrgui/textEditor/textManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down
1 change: 0 additions & 1 deletion qrgui/textEditor/textManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <QtCore/QObject>
#include <QtCore/QMap>
#include <QtCore/QMultiHash>

#include "qrgui/textEditor/textEditorDeclSpec.h"
#include "qrgui/textEditor/textManagerInterface.h"
#include "qrgui/textEditor/codeBlockManager.h"
Expand Down
1 change: 1 addition & 0 deletions qrgui/textEditor/textManagerInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

}
1 change: 1 addition & 0 deletions qrkernel/settingsDefaultValues
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pythonPath=python
generationTimeout=100
nodesStateButtonExpands=true
recentProjectsLimit=5
recentFilesLimit=7
dragArea = 12
touchMode=false
scriptInterpretation=false
Expand Down
11 changes: 8 additions & 3 deletions qrtranslations/fr/qrgui_mainWindow_fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@
<context>
<name>qReal::MainWindow</name>
<message>
<location filename="../../qrgui/mainWindow/mainWindow.cpp" line="+620"/>
<location filename="../../qrgui/mainWindow/mainWindow.cpp" line="+667"/>
<source>Could not save file, try to save it to another place</source>
<translation type="unfinished"></translation>
</message>
Expand All @@ -717,7 +717,7 @@
<translation type="vanished">À propo de QReal</translation>
</message>
<message>
<location line="-425"/>
<location line="-471"/>
<source>Restore default settings</source>
<translation type="unfinished"></translation>
</message>
Expand All @@ -729,7 +729,7 @@ WARNING: The settings will be restored after application restart</source>
<translation type="unfinished"></translation>
</message>
<message>
<location line="+673"/>
<location line="+719"/>
<location line="+11"/>
<source>Error</source>
<translation>Erreur</translation>
Expand Down Expand Up @@ -861,6 +861,11 @@ WARNING: The settings will be restored after application restart</source>
<source>Recent projects</source>
<translation>Projets récents</translation>
</message>
<message>
<location line="+4"/>
<source>Recent files</source>
<translation type="unfinished"></translation>
</message>
<message>
<location line="+31"/>
<source>Save File</source>
Expand Down
2 changes: 1 addition & 1 deletion qrtranslations/fr/qrgui_textEditor_fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<translation type="unfinished"></translation>
</message>
<message>
<location line="+192"/>
<location line="+193"/>
<source>All files (*)</source>
<translation>Tous les fichiers (*)</translation>
</message>
Expand Down
11 changes: 8 additions & 3 deletions qrtranslations/ru/qrgui_mainWindow_ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@
<translation type="vanished">О QReal</translation>
</message>
<message>
<location filename="../../qrgui/mainWindow/mainWindow.cpp" line="+869"/>
<location filename="../../qrgui/mainWindow/mainWindow.cpp" line="+916"/>
<location line="+11"/>
<source>Error</source>
<translation>Ошибка</translation>
Expand Down Expand Up @@ -788,7 +788,7 @@
<translation>Создать диаграмму</translation>
</message>
<message>
<location line="-1047"/>
<location line="-1093"/>
<source>Restore default settings</source>
<translation>Восстановить настройки по-умолчанию</translation>
</message>
Expand All @@ -802,7 +802,7 @@ WARNING: The settings will be restored after application restart</source>
ВНИМАНИЕ: Настройки будут сброшены после перезапуска приложения</translation>
</message>
<message>
<location line="+424"/>
<location line="+470"/>
<source>Could not save file, try to save it to another place</source>
<translation>Не удалось сохранить файл, попробуйте сохранить его в другое место</translation>
</message>
Expand Down Expand Up @@ -886,6 +886,11 @@ WARNING: The settings will be restored after application restart</source>
<source>Recent projects</source>
<translation>Недавние проекты</translation>
</message>
<message>
<location line="+4"/>
<source>Recent files</source>
<translation>Недавние файлы</translation>
</message>
<message>
<location line="+31"/>
<source>Save File</source>
Expand Down
2 changes: 1 addition & 1 deletion qrtranslations/ru/qrgui_textEditor_ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<translation>Сохранить перед закрытием?</translation>
</message>
<message>
<location line="+192"/>
<location line="+193"/>
<source>All files (*)</source>
<translation>Все файлы (*)</translation>
</message>
Expand Down
Loading