From b449e16b8159a0f7cb1bbdd8d7290672030ef1c7 Mon Sep 17 00:00:00 2001 From: Thomas HOCEDEZ Date: Thu, 18 Feb 2016 12:18:14 +0100 Subject: [PATCH 1/4] #385 : final version --HG-- branch : feature --- src/app/tape/tmainwindow.cpp | 73 +++++++++++++++++++++++++++++++++++- src/app/tape/tmainwindow.h | 6 +++ 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 4581ad96d..7af449841 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -117,6 +117,12 @@ TMainWindow::TMainWindow(QWidget *parent) ui->mainToolBar->setContextMenuPolicy(Qt::PreventContextMenu); ui->toolBarGradation->setContextMenuPolicy(Qt::PreventContextMenu); + for (int i = 0; i < MaxRecentFiles; ++i) + { + recentFileActs[i] = nullptr; + } + separatorAct=nullptr; + SetupMenu(); setWindowTitle(tr("untitled %1").arg(qApp->MainWindows().size()+1)); @@ -165,7 +171,7 @@ void TMainWindow::RetranslateTable() } } -//--------------------------------------------------------------------------------------------------------------------- +//--------separatorAct------------------------------------------------------------------------------------------------------------- void TMainWindow::SetBaseMHeight(int height) { if (m != nullptr) @@ -1735,6 +1741,20 @@ void TMainWindow::SetupMenu() connect(ui->actionReadOnly, &QAction::triggered, this, &TMainWindow::ReadOnly); connect(ui->actionPreferences, &QAction::triggered, this, &TMainWindow::Preferences); + for (int i = 0; i < MaxRecentFiles; ++i) + { + recentFileActs[i] = new QAction(this); + connect(recentFileActs[i], &QAction::triggered, this, &TMainWindow::OpenRecentFile); + ui->menuFile->insertAction(ui->actionPreferences, recentFileActs[i]); + recentFileActs[i]->setVisible(false); + } + + separatorAct = new QAction(this); + separatorAct->setSeparator(true); + separatorAct->setVisible(false); + ui->menuFile->insertAction(ui->actionPreferences, separatorAct ); + + connect(ui->actionQuit, &QAction::triggered, this, &TMainWindow::close); ui->actionQuit->setShortcuts(QKeySequence::Quit); @@ -1755,6 +1775,10 @@ void TMainWindow::SetupMenu() // Help connect(ui->actionAboutQt, &QAction::triggered, this, &TMainWindow::AboutQt); connect(ui->actionAboutTape, &QAction::triggered, this, &TMainWindow::AboutApplication); + + //Actions for recent files loaded by a tape window application. + UpdateRecentFileActions(); + } //--------------------------------------------------------------------------------------------------------------------- @@ -2025,6 +2049,16 @@ void TMainWindow::SetCurrentFile(const QString &fileName) ui->lineEditPathToFile->setText(QDir::toNativeSeparators(curFile)); ui->lineEditPathToFile->setToolTip(QDir::toNativeSeparators(curFile)); ui->pushButtonShowInExplorer->setEnabled(true); + VTapeSettings *settings = qApp->TapeSettings(); + QStringList files = settings->GetRecentFileList(); + files.removeAll(fileName); + files.prepend(fileName); + while (files.size() > MaxRecentFiles) + { + files.removeLast(); + } + settings->SetRecentFileList(files); + UpdateRecentFileActions(); } shownName += "[*]"; setWindowTitle(shownName); @@ -2689,6 +2723,30 @@ bool TMainWindow::LoadFromExistingFile(const QString &path) return true; } +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::UpdateRecentFileActions() +{ + qCDebug(tMainWindow, "Updating recent file actions."); + const QStringList files = qApp->TapeSettings()->GetRecentFileList(); + const int numRecentFiles = qMin(files.size(), static_cast(MaxRecentFiles)); + qCDebug(tMainWindow, "Updating recent file actions = %i ",numRecentFiles); + + for (int i = 0; i < numRecentFiles; ++i) + { + QString text = QString("&%1. %2").arg(i + 1).arg(StrippedName(files.at(i))); + qCDebug(tMainWindow, "file %i = %s",numRecentFiles,text); + recentFileActs[i]->setText(text); + recentFileActs[i]->setData(files.at(i)); + recentFileActs[i]->setVisible(true); + } + + for (int j = numRecentFiles; j < MaxRecentFiles; ++j) + { + recentFileActs[j]->setVisible(false); + } + + separatorAct->setVisible(numRecentFiles>0); +} //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::CreateWindowMenu(QMenu *menu) @@ -2722,6 +2780,19 @@ void TMainWindow::CreateWindowMenu(QMenu *menu) } } +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::OpenRecentFile() +{ + if (auto action=qobject_cast(sender())) + { + const QString filePath = action->data().toString(); + if (not filePath.isEmpty()) + { + LoadFile(filePath); + } + } +} + //--------------------------------------------------------------------------------------------------------------------- bool TMainWindow::IgnoreLocking(int error, const QString &path) { diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index e9225a279..49704b1c3 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -69,6 +69,7 @@ public slots: void OpenStandard(); void OpenTemplate(); void CreateFromExisting(); + void OpenRecentFile(); protected: virtual void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE; @@ -152,6 +153,10 @@ private: QAction *actionDockDiagram; bool dockDiagramVisible; bool isInitialized; + enum { MaxRecentFiles = 5 }; + QAction *recentFileActs[MaxRecentFiles]; + QAction *separatorAct; + void SetupMenu(); void InitWindow(); @@ -163,6 +168,7 @@ private: void ShowUnits(); void ShowHeaderUnits(QTableWidget *table, int column, const QString &unit); + void UpdateRecentFileActions(); void MeasurementsWasSaved(bool saved); void SetCurrentFile(const QString &fileName); From 207055925060cc62e3246132fdfaab63388c730d Mon Sep 17 00:00:00 2001 From: Thomas HOCEDEZ Date: Thu, 18 Feb 2016 11:23:00 +0000 Subject: [PATCH 2/4] =?UTF-8?q?tmainwindow.cpp=20=C3=A9dit=C3=A9=20en=20li?= =?UTF-8?q?gne=20via=20Bitbucket?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --HG-- branch : feature --- src/app/tape/tmainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 7af449841..6cdccfe26 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -171,7 +171,7 @@ void TMainWindow::RetranslateTable() } } -//--------separatorAct------------------------------------------------------------------------------------------------------------- +//--------------------------------------------------------------------------------------------------------------------- void TMainWindow::SetBaseMHeight(int height) { if (m != nullptr) From f58cd8c352628e0cf69f33d948a2ddf8f1292fd6 Mon Sep 17 00:00:00 2001 From: Thomas HOCEDEZ Date: Thu, 18 Feb 2016 14:56:37 +0000 Subject: [PATCH 3/4] =?UTF-8?q?ChangeLog.txt=20=C3=A9dit=C3=A9=20en=20lign?= =?UTF-8?q?e=20via=20Bitbucket?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --HG-- branch : thomas_hocedez/changelogtxt-dit-en-ligne-via-bitbucket-1455807397194 --- ChangeLog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index 503a48765..44eaabe80 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -7,6 +7,7 @@ - Added language Chinese (China). - New icon for VAL file. Updated Tape logo. Updated ico for standard measurements. - [#325] Check pattern for inverse compatibility. +- [#385] : Add 'Open Recent' option in Tape.exe, 'File' dropdown menu. # Version 0.4.2 - Fixed getting correct reversed segment for single in the list curve.