Skip to content

Commit

Permalink
TextManager should not know anything about the SettingsManager
Browse files Browse the repository at this point in the history
  • Loading branch information
MinyazevR authored and iakov committed Jan 27, 2025
1 parent 70c2cad commit 78df9dd
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 43 deletions.
26 changes: 26 additions & 0 deletions qrgui/mainWindow/mainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,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 @@ -597,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 Down
1 change: 1 addition & 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
32 changes: 3 additions & 29 deletions qrgui/textEditor/textManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ using namespace qReal;
using namespace text;

TextManager::TextManager(SystemEvents &systemEvents, gui::MainWindowInterpretersInterface &mainWindow)
: mRecentFilesLimit(SettingsManager::value("recentFilesLimit").toInt())
, mMainWindow(mainWindow)
: mMainWindow(mainWindow)
, mSystemEvents(systemEvents)
{
connect(&mSystemEvents, &SystemEvents::codeTabClosed, this, &TextManager::onTabClosed);
Expand Down Expand Up @@ -239,31 +238,6 @@ void TextManager::showInTextEditor(const QFileInfo &fileInfo
}
}

void TextManager::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 TextManager::showInTextEditor(const QFileInfo &fileInfo, const text::LanguageInfo &language)
{
Q_ASSERT(!fileInfo.completeBaseName().isEmpty());
Expand All @@ -280,7 +254,7 @@ void TextManager::showInTextEditor(const QFileInfo &fileInfo, const text::Langua
return;
}

refreshRecentFilesList(filePath);
emit needRefreshRecentFileList(filePath);
area->show();

// Need to bind diagram and code file only if code is just generated
Expand Down Expand Up @@ -331,7 +305,7 @@ bool TextManager::saveText(bool saveAs)
emit mSystemEvents.codePathChanged(diagram, path(area), fileInfo);
}

refreshRecentFilesList(fileInfo.absoluteFilePath());
emit needRefreshRecentFileList(fileInfo.absoluteFilePath());
}

return true;
Expand Down
5 changes: 1 addition & 4 deletions 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 <qrkernel/settingsManager.h>
#include "qrgui/textEditor/textEditorDeclSpec.h"
#include "qrgui/textEditor/textManagerInterface.h"
#include "qrgui/textEditor/codeBlockManager.h"
Expand Down Expand Up @@ -82,14 +81,12 @@ private slots:
void onTabClosed(const QFileInfo &file);

private:

void refreshRecentFilesList(const QString &fileName);
QMap<QString, text::QScintillaTextEdit*> mText; // No ownership
QMap<text::QScintillaTextEdit*, QString> mPath; // No ownership

/// If default path - true.
QMap<QString, bool> mPathType;
int mRecentFilesLimit {};

/// Contains names of generator, which generate each file
QMap<QString, QString> mGeneratorName;

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);
};

}
6 changes: 3 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="+641"/>
<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="-445"/>
<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="+693"/>
<location line="+719"/>
<location line="+11"/>
<source>Error</source>
<translation>Erreur</translation>
Expand Down
4 changes: 2 additions & 2 deletions qrtranslations/fr/qrgui_textEditor_fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<context>
<name>qReal::text::TextManager</name>
<message>
<location filename="../../qrgui/textEditor/textManager.cpp" line="+87"/>
<location filename="../../qrgui/textEditor/textManager.cpp" line="+86"/>
<source>Confirmation</source>
<translation type="unfinished"></translation>
</message>
Expand All @@ -14,7 +14,7 @@
<translation type="unfinished"></translation>
</message>
<message>
<location line="+218"/>
<location line="+193"/>
<source>All files (*)</source>
<translation>Tous les fichiers (*)</translation>
</message>
Expand Down
6 changes: 3 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="+890"/>
<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="-1067"/>
<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="+444"/>
<location line="+470"/>
<source>Could not save file, try to save it to another place</source>
<translation>Не удалось сохранить файл, попробуйте сохранить его в другое место</translation>
</message>
Expand Down
4 changes: 2 additions & 2 deletions qrtranslations/ru/qrgui_textEditor_ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<context>
<name>qReal::text::TextManager</name>
<message>
<location filename="../../qrgui/textEditor/textManager.cpp" line="+87"/>
<location filename="../../qrgui/textEditor/textManager.cpp" line="+86"/>
<source>Confirmation</source>
<translation>Подтвердите</translation>
</message>
Expand All @@ -56,7 +56,7 @@
<translation>Сохранить перед закрытием?</translation>
</message>
<message>
<location line="+218"/>
<location line="+193"/>
<source>All files (*)</source>
<translation>Все файлы (*)</translation>
</message>
Expand Down

0 comments on commit 78df9dd

Please sign in to comment.