mirror of
https://github.com/subsurface/subsurface.git
synced 2024-12-01 06:30:26 +00:00
Add recent files to main menu.
Add(up to four) recent files to File main menu. Signed-off-by: Boris Barbulovski <bbarbulovski@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
933d44083e
commit
51220f26ef
4 changed files with 193 additions and 0 deletions
|
@ -151,6 +151,7 @@ void init_ui(int *argcp, char ***argvp)
|
||||||
s.endGroup();
|
s.endGroup();
|
||||||
|
|
||||||
window = new MainWindow();
|
window = new MainWindow();
|
||||||
|
window->loadRecentFiles(&s);
|
||||||
window->show();
|
window->show();
|
||||||
if (existing_filename && existing_filename[0] != '\0')
|
if (existing_filename && existing_filename[0] != '\0')
|
||||||
window->setTitle(MWTF_FILENAME);
|
window->setTitle(MWTF_FILENAME);
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
#include <QTableView>
|
#include <QTableView>
|
||||||
#include <QDesktopWidget>
|
#include <QDesktopWidget>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QSettings>
|
||||||
#include "divelistview.h"
|
#include "divelistview.h"
|
||||||
#include "starwidget.h"
|
#include "starwidget.h"
|
||||||
|
|
||||||
|
@ -56,6 +58,10 @@ MainWindow::MainWindow() : QMainWindow(),
|
||||||
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), ui.divePlanner, SLOT(settingsChanged()));
|
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), ui.divePlanner, SLOT(settingsChanged()));
|
||||||
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), ui.divePlannerWidget, SLOT(settingsChanged()));
|
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), ui.divePlannerWidget, SLOT(settingsChanged()));
|
||||||
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), TankInfoModel::instance(), SLOT(update()));
|
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), TankInfoModel::instance(), SLOT(update()));
|
||||||
|
connect(ui.actionRecent1, SIGNAL(triggered(bool)), this, SLOT(recentFileTriggered(bool)));
|
||||||
|
connect(ui.actionRecent2, SIGNAL(triggered(bool)), this, SLOT(recentFileTriggered(bool)));
|
||||||
|
connect(ui.actionRecent3, SIGNAL(triggered(bool)), this, SLOT(recentFileTriggered(bool)));
|
||||||
|
connect(ui.actionRecent4, SIGNAL(triggered(bool)), this, SLOT(recentFileTriggered(bool)));
|
||||||
|
|
||||||
ui.mainErrorMessage->hide();
|
ui.mainErrorMessage->hide();
|
||||||
initialUiSetup();
|
initialUiSetup();
|
||||||
|
@ -688,6 +694,160 @@ MainTab* MainWindow::information()
|
||||||
return ui.InfoWidget;
|
return ui.InfoWidget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::loadRecentFiles(QSettings *s)
|
||||||
|
{
|
||||||
|
QStringList files;
|
||||||
|
bool modified = false;
|
||||||
|
|
||||||
|
s->beginGroup("Recent_Files");
|
||||||
|
for (int c = 1; c <= 4; c++)
|
||||||
|
{
|
||||||
|
QString key = QString("File_%1").arg(c);
|
||||||
|
if (s->contains(key))
|
||||||
|
{
|
||||||
|
QString file = s->value(key).toString();
|
||||||
|
|
||||||
|
if (QFile::exists(file))
|
||||||
|
{
|
||||||
|
files.append(file);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (modified)
|
||||||
|
{
|
||||||
|
for (int c = 0; c < 4; c++)
|
||||||
|
{
|
||||||
|
QString key = QString("File_%1").arg(c + 1);
|
||||||
|
|
||||||
|
if (files.count() > c)
|
||||||
|
{
|
||||||
|
s->setValue(key, files.at(c));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (s->contains(key))
|
||||||
|
{
|
||||||
|
s->remove(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
s->sync();
|
||||||
|
}
|
||||||
|
s->endGroup();
|
||||||
|
|
||||||
|
for (int c = 0; c < 4; c++)
|
||||||
|
{
|
||||||
|
QAction *action = this->findChild<QAction *>(QString("actionRecent%1").arg(c + 1));
|
||||||
|
|
||||||
|
if (files.count() > c)
|
||||||
|
{
|
||||||
|
QFileInfo fi(files.at(c));
|
||||||
|
action->setText(fi.fileName());
|
||||||
|
action->setToolTip(fi.absoluteFilePath());
|
||||||
|
action->setVisible(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
action->setVisible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::addRecentFile(const QStringList &newFiles)
|
||||||
|
{
|
||||||
|
QStringList files;
|
||||||
|
QSettings s;
|
||||||
|
|
||||||
|
if (newFiles.isEmpty())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
s.beginGroup("Recent_Files");
|
||||||
|
|
||||||
|
for (int c = 1; c <= 4; c++)
|
||||||
|
{
|
||||||
|
QString key = QString("File_%1").arg(c);
|
||||||
|
if (s.contains(key))
|
||||||
|
{
|
||||||
|
QString file = s.value(key).toString();
|
||||||
|
|
||||||
|
files.append(file);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach(const QString &file, newFiles)
|
||||||
|
{
|
||||||
|
int index = files.indexOf(file);
|
||||||
|
|
||||||
|
if (index >= 0)
|
||||||
|
{
|
||||||
|
files.removeAt(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach(const QString &file, newFiles)
|
||||||
|
{
|
||||||
|
if (QFile::exists(file))
|
||||||
|
{
|
||||||
|
files.prepend(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while(files.count() > 4)
|
||||||
|
{
|
||||||
|
files.removeLast();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int c = 0; c < 4; c++)
|
||||||
|
{
|
||||||
|
QString key = QString("File_%1").arg(c + 1);
|
||||||
|
|
||||||
|
if (files.count() > c)
|
||||||
|
{
|
||||||
|
s.setValue(key, files.at(c));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (s.contains(key))
|
||||||
|
{
|
||||||
|
s.remove(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s.endGroup();
|
||||||
|
s.sync();
|
||||||
|
|
||||||
|
loadRecentFiles(&s);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::recentFileTriggered(bool checked)
|
||||||
|
{
|
||||||
|
Q_UNUSED(checked);
|
||||||
|
|
||||||
|
QAction *actionRecent = (QAction *)sender();
|
||||||
|
|
||||||
|
const QString &filename = actionRecent->toolTip();
|
||||||
|
|
||||||
|
updateLastUsedDir(QFileInfo(filename).dir().path());
|
||||||
|
on_actionClose_triggered();
|
||||||
|
loadFiles(QStringList() << filename);
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::file_save_as(void)
|
void MainWindow::file_save_as(void)
|
||||||
{
|
{
|
||||||
QString filename;
|
QString filename;
|
||||||
|
@ -708,6 +868,7 @@ void MainWindow::file_save_as(void)
|
||||||
set_filename(filename.toUtf8().data(), true);
|
set_filename(filename.toUtf8().data(), true);
|
||||||
setTitle(MWTF_FILENAME);
|
setTitle(MWTF_FILENAME);
|
||||||
mark_divelist_changed(false);
|
mark_divelist_changed(false);
|
||||||
|
addRecentFile(QStringList() << filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -731,6 +892,7 @@ void MainWindow::file_save(void)
|
||||||
}
|
}
|
||||||
save_dives(existing_filename);
|
save_dives(existing_filename);
|
||||||
mark_divelist_changed(false);
|
mark_divelist_changed(false);
|
||||||
|
addRecentFile(QStringList() << QString(existing_filename));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::showError(QString message)
|
void MainWindow::showError(QString message)
|
||||||
|
@ -803,6 +965,7 @@ void MainWindow::loadFiles(const QStringList fileNames)
|
||||||
}
|
}
|
||||||
|
|
||||||
process_dives(false, false);
|
process_dives(false, false);
|
||||||
|
addRecentFile(fileNames);
|
||||||
|
|
||||||
refreshDisplay();
|
refreshDisplay();
|
||||||
ui.actionAutoGroup->setChecked(autogroup);
|
ui.actionAutoGroup->setChecked(autogroup);
|
||||||
|
|
|
@ -45,6 +45,8 @@ public:
|
||||||
static MainWindow *instance();
|
static MainWindow *instance();
|
||||||
ProfileGraphicsView *graphics();
|
ProfileGraphicsView *graphics();
|
||||||
MainTab *information();
|
MainTab *information();
|
||||||
|
void loadRecentFiles(QSettings *s);
|
||||||
|
void addRecentFile(const QStringList &newFiles);
|
||||||
DiveListView *dive_list();
|
DiveListView *dive_list();
|
||||||
GlobeGPS *globe();
|
GlobeGPS *globe();
|
||||||
void showError(QString message);
|
void showError(QString message);
|
||||||
|
@ -60,6 +62,7 @@ public:
|
||||||
QTabWidget *tabWidget();
|
QTabWidget *tabWidget();
|
||||||
private slots:
|
private slots:
|
||||||
/* file menu action */
|
/* file menu action */
|
||||||
|
void recentFileTriggered(bool checked);
|
||||||
void on_actionNew_triggered();
|
void on_actionNew_triggered();
|
||||||
void on_actionOpen_triggered();
|
void on_actionOpen_triggered();
|
||||||
void on_actionSave_triggered();
|
void on_actionSave_triggered();
|
||||||
|
|
|
@ -607,6 +607,12 @@
|
||||||
<addaction name="actionExportUDDF"/>
|
<addaction name="actionExportUDDF"/>
|
||||||
<addaction name="actionPrint"/>
|
<addaction name="actionPrint"/>
|
||||||
<addaction name="actionPreferences"/>
|
<addaction name="actionPreferences"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
|
<addaction name="actionRecent1"/>
|
||||||
|
<addaction name="actionRecent2"/>
|
||||||
|
<addaction name="actionRecent3"/>
|
||||||
|
<addaction name="actionRecent4"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
<addaction name="actionQuit"/>
|
<addaction name="actionQuit"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenu" name="menuLog">
|
<widget class="QMenu" name="menuLog">
|
||||||
|
@ -937,6 +943,26 @@
|
||||||
<string>F11</string>
|
<string>F11</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionRecent1">
|
||||||
|
<property name="visible">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionRecent2">
|
||||||
|
<property name="visible">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionRecent3">
|
||||||
|
<property name="visible">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionRecent4">
|
||||||
|
<property name="visible">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
|
|
Loading…
Reference in a new issue