@@ -50,12 +50,14 @@ void MainWindow::addFiles()
50
50
{
51
51
for (QString file : fileNames)
52
52
{
53
+ qDebug ()<<" add file " ;
53
54
mView ->addFile (file);
55
+ addRecent (file);
54
56
}
55
57
}
56
58
57
59
statusBar ()->showMessage (QString (tr (" Running on %1 threads" )).arg (QThreadPool::globalInstance ()->activeThreadCount ()));
58
-
60
+ updateRecentMenu ();
59
61
}
60
62
61
63
void MainWindow::remFiles ()
@@ -134,11 +136,15 @@ void MainWindow::setupActions()
134
136
// File menu
135
137
QMenu * fileMenu = menuBar ()->addMenu (tr (" &File" ));
136
138
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
+
137
144
QAction * exportSelAction = fileMenu->addAction (QFontIcon::icon (0xf0c7 ),tr (" &Export" ),this , SLOT (exportSelection ()), QKeySequence::Save);
138
145
openAction->setToolTip (tr (" Add Fastq(s) files for analysis" ));
139
146
exportSelAction->setToolTip (tr (" Export selected analyses" ));
140
147
141
- fileMenu->addSeparator ();
142
148
fileMenu->addAction (QFontIcon::icon (0xf00d ),tr (" &Close" ),qApp, SLOT (closeAllWindows ()), QKeySequence::Close);
143
149
144
150
@@ -172,7 +178,7 @@ void MainWindow::setupActions()
172
178
173
179
QToolBar * bar = addToolBar (tr (" Open" ));
174
180
bar->setToolButtonStyle (Qt::ToolButtonTextBesideIcon);
175
- // bar->setIconSize(QSize(22,22));
181
+ // bar->setIconSize(QSize(22,22));
176
182
bar->addAction (openAction);
177
183
bar->addAction (remAction);
178
184
bar->addSeparator ();
@@ -187,5 +193,52 @@ void MainWindow::setupActions()
187
193
188
194
}
189
195
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
+
190
243
191
244
0 commit comments