Skip to content

Commit 71d1915

Browse files
committed
Merge branch 'devel'
2 parents 0650f06 + db5d9b4 commit 71d1915

File tree

3 files changed

+62
-3
lines changed

3 files changed

+62
-3
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/)
1414
## [0.2.3] - 2017-29-03
1515
### Changed
1616
- Exporting file displays a progress dialog
17+
- Add recent menu
1718

1819
>>>>>>> devel
1920

ui/mainwindow.cpp

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@ void MainWindow::addFiles()
5050
{
5151
for (QString file : fileNames)
5252
{
53+
qDebug()<<"add file ";
5354
mView->addFile(file);
55+
addRecent(file);
5456
}
5557
}
5658

5759
statusBar()->showMessage(QString(tr("Running on %1 threads")).arg(QThreadPool::globalInstance()->activeThreadCount()));
58-
60+
updateRecentMenu();
5961
}
6062

6163
void MainWindow::remFiles()
@@ -134,11 +136,15 @@ void MainWindow::setupActions()
134136
// File menu
135137
QMenu * fileMenu = menuBar()->addMenu(tr("&File"));
136138
QAction * openAction = fileMenu->addAction(QFontIcon::icon(0xf067), tr("&Add files"),this, SLOT(addFiles()), QKeySequence::Open);
139+
140+
mRecentMenu = fileMenu->addMenu(tr("Fichiers récents"));
141+
updateRecentMenu();
142+
143+
137144
QAction * exportSelAction = fileMenu->addAction(QFontIcon::icon(0xf0c7),tr("&Export"),this, SLOT(exportSelection()), QKeySequence::Save);
138145
openAction->setToolTip(tr("Add Fastq(s) files for analysis"));
139146
exportSelAction->setToolTip(tr("Export selected analyses" ));
140147

141-
fileMenu->addSeparator();
142148
fileMenu->addAction(QFontIcon::icon(0xf00d),tr("&Close"),qApp, SLOT(closeAllWindows()), QKeySequence::Close);
143149

144150

@@ -172,7 +178,7 @@ void MainWindow::setupActions()
172178

173179
QToolBar * bar = addToolBar(tr("Open"));
174180
bar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
175-
// bar->setIconSize(QSize(22,22));
181+
// bar->setIconSize(QSize(22,22));
176182
bar->addAction(openAction);
177183
bar->addAction(remAction);
178184
bar->addSeparator();
@@ -187,5 +193,52 @@ void MainWindow::setupActions()
187193

188194
}
189195

196+
void MainWindow::addRecent(const QString &path)
197+
{
198+
QStringList recents = loadRecent();
199+
recents.prepend(path);
200+
recents.removeDuplicates();
201+
202+
QSettings settings;
203+
settings.beginWriteArray("recents");
204+
settings.clear();
205+
int max = recents.size() > MAX_RECENT ? MAX_RECENT : recents.size();
206+
207+
for (int i=0; i<max; ++i)
208+
{
209+
settings.setArrayIndex(i);
210+
settings.setValue("path",recents.at(i));
211+
}
212+
213+
settings.endArray();
214+
}
215+
216+
QStringList MainWindow::loadRecent()
217+
{
218+
QStringList recents;
219+
QSettings settings;
220+
int size = settings.beginReadArray("recents");
221+
int max = size > MAX_RECENT ? MAX_RECENT : size;
222+
223+
for (int i=0; i<max; ++i)
224+
{
225+
settings.setArrayIndex(i);
226+
recents.append(settings.value("path").toString());
227+
}
228+
229+
settings.endArray();
230+
231+
return recents;
232+
}
233+
234+
void MainWindow::updateRecentMenu()
235+
{
236+
mRecentMenu->clear();
237+
for (QString recent : loadRecent())
238+
{
239+
mRecentMenu->addAction(recent,this, [recent,this](){mView->addFile(recent);});
240+
}
241+
}
242+
190243

191244

ui/mainwindow.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ public Q_SLOTS:
5454

5555
protected:
5656
void setupActions();
57+
void addRecent(const QString& path);
58+
QStringList loadRecent();
59+
void updateRecentMenu();
5760

5861
private:
5962
void printEasterEggs();
@@ -64,6 +67,8 @@ public Q_SLOTS:
6467
MainAnalyseView * mView;
6568
QFuture<void> mRunFuture;
6669
QStatusBar * mStatusBar;
70+
QMenu * mRecentMenu;
71+
static const int MAX_RECENT=10;
6772
};
6873

6974
#endif // MAINWINDOW_H

0 commit comments

Comments
 (0)