Skip to content

Commit ff5cf3e

Browse files
committed
MainWindow: Add project files to list of recently opened files
When opening a project file add it to the list of recently opened files instead of the database file associated with it.
1 parent b841025 commit ff5cf3e

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

src/MainWindow.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ void MainWindow::clearCompleterModelsFields()
180180
completerModelsFields.clear();
181181
}
182182

183-
bool MainWindow::fileOpen(const QString& fileName)
183+
bool MainWindow::fileOpen(const QString& fileName, bool dontAddToRecentFiles)
184184
{
185185
bool retval = false;
186186

@@ -199,6 +199,8 @@ bool MainWindow::fileOpen(const QString& fileName)
199199
{
200200
statusEncodingLabel->setText(db.getPragma("encoding"));
201201
setCurrentFile(wFile);
202+
if(!dontAddToRecentFiles)
203+
addToRecentFilesMenu(wFile);
202204
retval = true;
203205
} else {
204206
// Failed opening file; so it might be a project file instead
@@ -224,6 +226,7 @@ void MainWindow::fileNew()
224226
QFile::remove(fileName);
225227
db.create(fileName);
226228
setCurrentFile(fileName);
229+
addToRecentFilesMenu(fileName);
227230
statusEncodingLabel->setText(db.getPragma("encoding"));
228231
loadExtensionsFromSettings();
229232
populateStructure();
@@ -1014,10 +1017,13 @@ void MainWindow::setCurrentFile(const QString &fileName)
10141017
setWindowFilePath(fileName);
10151018
setWindowTitle( QApplication::applicationName() +" - "+fileName);
10161019
activateFields(true);
1020+
}
10171021

1022+
void MainWindow::addToRecentFilesMenu(const QString& filename)
1023+
{
10181024
QStringList files = PreferencesDialog::getSettingsValue("General", "recentFileList").toStringList();
1019-
files.removeAll(fileName);
1020-
files.prepend(fileName);
1025+
files.removeAll(filename);
1026+
files.prepend(filename);
10211027
while (files.size() > MaxRecentFiles)
10221028
files.removeLast();
10231029

@@ -1741,6 +1747,8 @@ bool MainWindow::loadProject(QString filename)
17411747
return false;
17421748
}
17431749

1750+
addToRecentFilesMenu(filename);
1751+
17441752
while(!xml.atEnd() && !xml.hasError())
17451753
{
17461754
// Read next token
@@ -1755,7 +1763,7 @@ bool MainWindow::loadProject(QString filename)
17551763
QString dbfilename = xml.attributes().value("path").toString();
17561764
if(!QFile::exists(dbfilename))
17571765
dbfilename = QFileInfo(filename).absolutePath() + QDir::separator() + dbfilename;
1758-
fileOpen(dbfilename);
1766+
fileOpen(dbfilename, true);
17591767
ui->dbTreeWidget->collapseAll();
17601768
} else if(xml.name() == "window") {
17611769
// Window settings

src/MainWindow.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class MainWindow : public QMainWindow
102102

103103
void updateRecentFileActions();
104104
void setCurrentFile(const QString& fileName);
105+
void addToRecentFilesMenu(const QString& filename);
105106
void activateFields(bool enable = true);
106107
void loadExtensionsFromSettings();
107108

@@ -112,7 +113,7 @@ class MainWindow : public QMainWindow
112113
void resizeEvent(QResizeEvent *event);
113114

114115
public slots:
115-
bool fileOpen(const QString& fileName = QString());
116+
bool fileOpen(const QString& fileName = QString(), bool dontAddToRecentFiles = false);
116117
void logSql(const QString &sql, int msgtype);
117118
void dbState(bool dirty);
118119
void browseRefresh();

0 commit comments

Comments
 (0)