@@ -30,7 +30,8 @@ using namespace qReal;
3030using namespace text ;
3131
3232TextManager::TextManager (SystemEvents &systemEvents, gui::MainWindowInterpretersInterface &mainWindow)
33- : mMainWindow(mainWindow)
33+ : mRecentFilesLimit(SettingsManager::value(" recentFilesLimit" ).toInt())
34+ , mMainWindow(mainWindow)
3435 , mSystemEvents(systemEvents)
3536{
3637 connect (&mSystemEvents , &SystemEvents::codeTabClosed, this , &TextManager::onTabClosed);
@@ -238,6 +239,31 @@ void TextManager::showInTextEditor(const QFileInfo &fileInfo
238239 }
239240}
240241
242+ void TextManager::refreshRecentFilesList (const QString &fileName) {
243+ QString previousString = SettingsManager::value (" recentFiles" ).toString ();
244+ QStringList 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+
241267void TextManager::showInTextEditor (const QFileInfo &fileInfo, const text::LanguageInfo &language)
242268{
243269 Q_ASSERT (!fileInfo.completeBaseName ().isEmpty ());
@@ -254,6 +280,7 @@ void TextManager::showInTextEditor(const QFileInfo &fileInfo, const text::Langua
254280 return ;
255281 }
256282
283+ refreshRecentFilesList (filePath);
257284 area->show ();
258285
259286 // Need to bind diagram and code file only if code is just generated
@@ -289,7 +316,6 @@ bool TextManager::saveText(bool saveAs)
289316
290317 if (!fileInfo.fileName ().isEmpty ()) {
291318 mMainWindow .setTabText (area, fileInfo.fileName ());
292-
293319 utils::OutFile out (fileInfo.absoluteFilePath ());
294320
295321 out () << area->text ();
@@ -304,6 +330,8 @@ bool TextManager::saveText(bool saveAs)
304330 if (saveAs && !diagram.isNull ()) {
305331 emit mSystemEvents .codePathChanged (diagram, path (area), fileInfo);
306332 }
333+
334+ refreshRecentFilesList (fileInfo.absoluteFilePath ());
307335 }
308336
309337 return true ;
0 commit comments