Skip to content

Commit d6bbc58

Browse files
Open recent menu. Close #4.
1 parent eed4a07 commit d6bbc58

File tree

4 files changed

+82
-8
lines changed

4 files changed

+82
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ These decodings are not yet solved, which might make them an interesting target.
4242
`master` -- GoodASM REPL now has working autocompletion on Windows.
4343
Dropping support for x86_64 macOS. Optional support for Yara-X. HSL
4444
color space for bit thresholds, with bit color histograms that are
45-
easier on the eyes.
45+
easier on the eyes. Open recent menu, QSettings.
4646

4747
2025-06-01 -- CLI and GUI features to work with ambiguous/damaged
4848
bits, useful when part of an implant ROM is poorly exposed. Solver

maskromtool.cpp

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ MaskRomTool::MaskRomTool(QWidget *parent, bool opengl)
7474
: QMainWindow(parent)
7575
, ui(new Ui::MaskRomTool) {
7676

77+
//Set our Qt configuration, needed for settings.
78+
QCoreApplication::setOrganizationName("TravisGoodspeed");
79+
QCoreApplication::setOrganizationDomain("kk4vcz.com");
80+
QCoreApplication::setApplicationName("MaskRomTool");
81+
7782
//Setup caches
7883
QPixmapCache::setCacheLimit(0x100000); //1GB
7984
if(verbose) qDebug()<<"Cache limit is "<<QPixmapCache::cacheLimit()<<"kb";
@@ -117,6 +122,9 @@ MaskRomTool::MaskRomTool(QWidget *parent, bool opengl)
117122
//Set up the second view.
118123
second.view->setScene(scene);
119124

125+
//Build a history of past entries.
126+
buildFileHistoryList();
127+
120128
//Enable OpenGL without antialiasing, now that it's stable.
121129
if(opengl)
122130
enableOpenGL(0);
@@ -1370,6 +1378,61 @@ void MaskRomTool::getAlignSkipCountThreshold(uint32_t &count){
13701378
count=alignSkipThreshold;
13711379
}
13721380

1381+
//Records a file in settings for the history.
1382+
void MaskRomTool::recordFileHistory(QFileInfo file){
1383+
/* What we do here is build a stack of the old filenames,
1384+
* cull the new filename from that stack, and then ensure
1385+
* that the new filename comes first in the new listing.
1386+
*/
1387+
QSettings settings;
1388+
QString path=file.absoluteFilePath();
1389+
QStack<QString> filenames; //Ordered list of filenames.
1390+
1391+
//Build the new list.
1392+
filenames.append(path); //New file always comes first.
1393+
for(int i=0; i<10; i++){
1394+
QString k="filename"+QString::number(i);
1395+
QVariant v=settings.value(k);
1396+
if(v.isValid()){
1397+
if(path!=v.toString())
1398+
filenames.append(v.toString());
1399+
}
1400+
}
1401+
1402+
//Write back the new list.
1403+
int i=0;
1404+
foreach(QString f, filenames){
1405+
QString k="filename"+QString::number(i);
1406+
settings.setValue(k, f);
1407+
i++;
1408+
}
1409+
}
1410+
1411+
//Builds the history menu entries.
1412+
void MaskRomTool::buildFileHistoryList(){
1413+
QMenu* recents=ui->menuOpen_Recent;
1414+
recents->clear();
1415+
1416+
QSettings settings;
1417+
for(int i=0; i<10; i++){
1418+
QString k="filename"+QString::number(i);
1419+
QVariant v=settings.value(k);
1420+
if(v.isValid()){
1421+
QAction *action=new QAction(recents);
1422+
action->setText(v.toString());
1423+
recents->addAction(action);
1424+
QObject::connect(action, SIGNAL(triggered(bool)),
1425+
this, SLOT(openHistory()));
1426+
}
1427+
}
1428+
}
1429+
1430+
//Opens whichever entry in the history was selected.
1431+
void MaskRomTool::openHistory(){
1432+
QAction *action = (QAction*) this->sender();
1433+
fileOpen(action->text());
1434+
}
1435+
13731436
//Opens *either* an image or a JSON description of lines.
13741437
void MaskRomTool::fileOpen(QString filename){
13751438
//On macOS, each window likes to have a file attached.
@@ -1392,8 +1455,12 @@ void MaskRomTool::fileOpen(QString filename){
13921455

13931456

13941457
//We load the image as a background, so it's not really a part of the scene.
1458+
QFileInfo info(imagefilename);
1459+
recordFileHistory(info);
1460+
buildFileHistoryList();
13951461
if(verbose)
1396-
qDebug()<<"Loading background image: "<<imagefilename;
1462+
qDebug()<<"Loading background image: "<<info.absoluteFilePath();
1463+
13971464
background=QImage(imagefilename);
13981465
backgroundpixmap = scene->addPixmap(QPixmap(imagefilename));
13991466
backgroundpixmap->setZValue(-10);

maskromtool.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ class MaskRomTool : public QMainWindow{
4444
~MaskRomTool();
4545
void closeEvent(QCloseEvent *event);
4646

47+
//Records a file in settings for the history.
48+
void recordFileHistory(QFileInfo file);
49+
void buildFileHistoryList();
50+
4751
void enableVerbose(unsigned int level=1);
4852
void enableOpenGL(unsigned int antialiasing=0);
4953

@@ -254,6 +258,7 @@ class MaskRomTool : public QMainWindow{
254258

255259
private slots:
256260
void on_openButton_triggered();
261+
void openHistory(); //Called by any of the file history entries.
257262
void on_saveButton_triggered();
258263

259264
void on_alignconstrainButton_triggered();
@@ -269,7 +274,7 @@ private slots:
269274
void on_asciiButton_triggered();
270275
void on_actionHexView_triggered();
271276

272-
//Import from a file. (Loose definition.
277+
//Import from a file. (Loose definition.)
273278
void on_importDiff_triggered();
274279

275280
//Export to a file.
@@ -306,13 +311,9 @@ private slots:
306311
void on_selectioncolorButton_triggered();
307312
void on_crosshaircolorButton_triggered();
308313
void on_exportSolverSetBytes_triggered();
309-
310314
void on_actionHexDamage_triggered();
311-
312315
void on_actionAsciiDamage_triggered();
313-
314316
void on_exportAsciiDamage_triggered();
315-
316317
void on_exportDamageBytes_triggered();
317318

318319
private:

maskromtool.ui

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
<x>0</x>
4444
<y>0</y>
4545
<width>1095</width>
46-
<height>24</height>
46+
<height>20</height>
4747
</rect>
4848
</property>
4949
<widget class="QMenu" name="menuFile">
@@ -72,11 +72,17 @@
7272
</property>
7373
<addaction name="importDiff"/>
7474
</widget>
75+
<widget class="QMenu" name="menuOpen_Recent">
76+
<property name="title">
77+
<string>Open Recent</string>
78+
</property>
79+
</widget>
7580
<addaction name="openButton"/>
7681
<addaction name="saveButton"/>
7782
<addaction name="menuImport"/>
7883
<addaction name="menuExport"/>
7984
<addaction name="actionPrint"/>
85+
<addaction name="menuOpen_Recent"/>
8086
</widget>
8187
<widget class="QMenu" name="menuView">
8288
<property name="title">

0 commit comments

Comments
 (0)