Skip to content

Commit cb826bb

Browse files
committed
TextManager should not know anything about the SettingsManager
1 parent 0bca74b commit cb826bb

File tree

9 files changed

+42
-43
lines changed

9 files changed

+42
-43
lines changed

qrgui/mainWindow/mainWindow.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ void MainWindow::connectActions()
342342
connect(mUi->tabs, &QTabWidget::currentChanged, this, &MainWindow::sceneSelectionChanged);
343343
connect(&*mTextManager, &text::TextManager::textChanged, this, &MainWindow::setTextChanged);
344344
connect(&*mTextManager, &text::TextManager::textChanged, mUi->actionUndo, &QAction::setEnabled);
345+
connect(&*mTextManager, &text::TextManager::needRefreshRecentFileList, this, &MainWindow::refreshRecentFilesList);
345346

346347
connect(&*mProjectManager, &ProjectManager::afterOpen, mUi->paletteTree, &PaletteTree::refreshUserPalettes);
347348
connect(&*mProjectManager, &ProjectManager::closed, mUi->paletteTree, &PaletteTree::refreshUserPalettes);
@@ -597,6 +598,31 @@ void MainWindow::refreshRecentProjectsList(const QString &fileName)
597598
SettingsManager::setValue("recentProjects", previousString);
598599
}
599600

601+
void MainWindow::refreshRecentFilesList(const QString &fileName) {
602+
auto previousString = SettingsManager::value("recentFiles").toString();
603+
auto previousList = previousString.split(";", QString::SkipEmptyParts);
604+
previousList.removeOne(fileName);
605+
606+
if (!previousList.isEmpty() && (previousList.size() == mRecentFilesLimit)) {
607+
previousList.removeLast();
608+
}
609+
610+
previousString.clear();
611+
if (mRecentFilesLimit > 0) {
612+
previousList.push_front(fileName);
613+
QStringListIterator iterator(previousList);
614+
while (iterator.hasNext()) {
615+
const auto recentFileName = iterator.next();
616+
const QFileInfo fileInfo(recentFileName);
617+
if (fileInfo.exists() && fileInfo.isFile()) {
618+
previousString = previousString + recentFileName + ";";
619+
}
620+
}
621+
}
622+
623+
SettingsManager::setValue("recentFiles", previousString);
624+
}
625+
600626
void MainWindow::openRecentProjectsMenu()
601627
{
602628
mRecentProjectsMenu->clear();

qrgui/mainWindow/mainWindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ public slots:
195195
void closeStartTab();
196196
void closeAllTabs();
197197
void refreshRecentProjectsList(const QString &fileName);
198+
void refreshRecentFilesList(const QString &fileName);
198199
void createDiagram(const QString &idString);
199200
/// Creates project with specified root diagram
200201
bool createProject(const QString &diagramIdString);

qrgui/textEditor/textManager.cpp

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ using namespace qReal;
3030
using namespace text;
3131

3232
TextManager::TextManager(SystemEvents &systemEvents, gui::MainWindowInterpretersInterface &mainWindow)
33-
: mRecentFilesLimit(SettingsManager::value("recentFilesLimit").toInt())
34-
, mMainWindow(mainWindow)
33+
: mMainWindow(mainWindow)
3534
, mSystemEvents(systemEvents)
3635
{
3736
connect(&mSystemEvents, &SystemEvents::codeTabClosed, this, &TextManager::onTabClosed);
@@ -239,31 +238,6 @@ void TextManager::showInTextEditor(const QFileInfo &fileInfo
239238
}
240239
}
241240

242-
void TextManager::refreshRecentFilesList(const QString &fileName) {
243-
auto previousString = SettingsManager::value("recentFiles").toString();
244-
auto previousList = previousString.split(";", QString::SkipEmptyParts);
245-
previousList.removeOne(fileName);
246-
247-
if (!previousList.isEmpty() && (previousList.size() == mRecentFilesLimit)) {
248-
previousList.removeLast();
249-
}
250-
251-
previousString.clear();
252-
if (mRecentFilesLimit > 0) {
253-
previousList.push_front(fileName);
254-
QStringListIterator iterator(previousList);
255-
while (iterator.hasNext()) {
256-
const auto recentFileName = iterator.next();
257-
const QFileInfo fileInfo(recentFileName);
258-
if (fileInfo.exists() && fileInfo.isFile()) {
259-
previousString = previousString + recentFileName + ";";
260-
}
261-
}
262-
}
263-
264-
SettingsManager::setValue("recentFiles", previousString);
265-
}
266-
267241
void TextManager::showInTextEditor(const QFileInfo &fileInfo, const text::LanguageInfo &language)
268242
{
269243
Q_ASSERT(!fileInfo.completeBaseName().isEmpty());
@@ -280,7 +254,7 @@ void TextManager::showInTextEditor(const QFileInfo &fileInfo, const text::Langua
280254
return;
281255
}
282256

283-
refreshRecentFilesList(filePath);
257+
emit needRefreshRecentFileList(filePath);
284258
area->show();
285259

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

334-
refreshRecentFilesList(fileInfo.absoluteFilePath());
308+
emit needRefreshRecentFileList(fileInfo.absoluteFilePath());
335309
}
336310

337311
return true;

qrgui/textEditor/textManager.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <QtCore/QObject>
1818
#include <QtCore/QMap>
1919
#include <QtCore/QMultiHash>
20-
#include <qrkernel/settingsManager.h>
2120
#include "qrgui/textEditor/textEditorDeclSpec.h"
2221
#include "qrgui/textEditor/textManagerInterface.h"
2322
#include "qrgui/textEditor/codeBlockManager.h"
@@ -82,14 +81,12 @@ private slots:
8281
void onTabClosed(const QFileInfo &file);
8382

8483
private:
85-
86-
void refreshRecentFilesList(const QString &fileName);
8784
QMap<QString, text::QScintillaTextEdit*> mText; // No ownership
8885
QMap<text::QScintillaTextEdit*, QString> mPath; // No ownership
8986

9087
/// If default path - true.
9188
QMap<QString, bool> mPathType;
92-
int mRecentFilesLimit {};
89+
9390
/// Contains names of generator, which generate each file
9491
QMap<QString, QString> mGeneratorName;
9592

qrgui/textEditor/textManagerInterface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class QRGUI_TEXT_EDITOR_EXPORT TextManagerInterface : public QObject
5656

5757
signals:
5858
void textChanged(text::QScintillaTextEdit *editor, bool changed);
59+
void needRefreshRecentFileList(const QString &fileName);
5960
};
6061

6162
}

qrtranslations/fr/qrgui_mainWindow_fr.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@
708708
<context>
709709
<name>qReal::MainWindow</name>
710710
<message>
711-
<location filename="../../qrgui/mainWindow/mainWindow.cpp" line="+641"/>
711+
<location filename="../../qrgui/mainWindow/mainWindow.cpp" line="+667"/>
712712
<source>Could not save file, try to save it to another place</source>
713713
<translation type="unfinished"></translation>
714714
</message>
@@ -717,7 +717,7 @@
717717
<translation type="vanished">À propo de QReal</translation>
718718
</message>
719719
<message>
720-
<location line="-445"/>
720+
<location line="-471"/>
721721
<source>Restore default settings</source>
722722
<translation type="unfinished"></translation>
723723
</message>
@@ -729,7 +729,7 @@ WARNING: The settings will be restored after application restart</source>
729729
<translation type="unfinished"></translation>
730730
</message>
731731
<message>
732-
<location line="+693"/>
732+
<location line="+719"/>
733733
<location line="+11"/>
734734
<source>Error</source>
735735
<translation>Erreur</translation>

qrtranslations/fr/qrgui_textEditor_fr.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<context>
55
<name>qReal::text::TextManager</name>
66
<message>
7-
<location filename="../../qrgui/textEditor/textManager.cpp" line="+87"/>
7+
<location filename="../../qrgui/textEditor/textManager.cpp" line="+86"/>
88
<source>Confirmation</source>
99
<translation type="unfinished"></translation>
1010
</message>
@@ -14,7 +14,7 @@
1414
<translation type="unfinished"></translation>
1515
</message>
1616
<message>
17-
<location line="+218"/>
17+
<location line="+193"/>
1818
<source>All files (*)</source>
1919
<translation>Tous les fichiers (*)</translation>
2020
</message>

qrtranslations/ru/qrgui_mainWindow_ru.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@
735735
<translation type="vanished">О QReal</translation>
736736
</message>
737737
<message>
738-
<location filename="../../qrgui/mainWindow/mainWindow.cpp" line="+890"/>
738+
<location filename="../../qrgui/mainWindow/mainWindow.cpp" line="+916"/>
739739
<location line="+11"/>
740740
<source>Error</source>
741741
<translation>Ошибка</translation>
@@ -788,7 +788,7 @@
788788
<translation>Создать диаграмму</translation>
789789
</message>
790790
<message>
791-
<location line="-1067"/>
791+
<location line="-1093"/>
792792
<source>Restore default settings</source>
793793
<translation>Восстановить настройки по-умолчанию</translation>
794794
</message>
@@ -802,7 +802,7 @@ WARNING: The settings will be restored after application restart</source>
802802
ВНИМАНИЕ: Настройки будут сброшены после перезапуска приложения</translation>
803803
</message>
804804
<message>
805-
<location line="+444"/>
805+
<location line="+470"/>
806806
<source>Could not save file, try to save it to another place</source>
807807
<translation>Не удалось сохранить файл, попробуйте сохранить его в другое место</translation>
808808
</message>

qrtranslations/ru/qrgui_textEditor_ru.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<context>
4343
<name>qReal::text::TextManager</name>
4444
<message>
45-
<location filename="../../qrgui/textEditor/textManager.cpp" line="+87"/>
45+
<location filename="../../qrgui/textEditor/textManager.cpp" line="+86"/>
4646
<source>Confirmation</source>
4747
<translation>Подтвердите</translation>
4848
</message>
@@ -56,7 +56,7 @@
5656
<translation>Сохранить перед закрытием?</translation>
5757
</message>
5858
<message>
59-
<location line="+218"/>
59+
<location line="+193"/>
6060
<source>All files (*)</source>
6161
<translation>Все файлы (*)</translation>
6262
</message>

0 commit comments

Comments
 (0)