1
0
Fork 0

GUI: recent files in ScriptView

This commit is contained in:
mrexodia 2017-03-14 10:46:26 +01:00
parent e267eedec0
commit f16c24b17c
No known key found for this signature in database
GPG Key ID: FC89E0AAA0C1AAD8
4 changed files with 33 additions and 12 deletions

View File

@ -6,6 +6,7 @@
#include "Bridge.h"
#include "RichTextPainter.h"
#include "LineEditDialog.h"
#include "MRUList.h"
ScriptView::ScriptView(StdTable* parent) : StdTable(parent)
{
@ -31,6 +32,11 @@ ScriptView::ScriptView(StdTable* parent) : StdTable(parent)
msg->setModal(false);
connect(msg, SIGNAL(finished(int)), this, SLOT(messageResult(int)));
// recent script
mMRUList = new MRUList(this, "Recent Scripts");
connect(mMRUList, SIGNAL(openFile(QString)), this, SLOT(openRecentFile(QString)));
mMRUList->load();
// Slots
connect(Bridge::getBridge(), SIGNAL(scriptAdd(int, const char**)), this, SLOT(add(int, const char**)));
connect(Bridge::getBridge(), SIGNAL(scriptClear()), this, SLOT(clear()));
@ -368,10 +374,16 @@ void ScriptView::keyPressEvent(QKeyEvent* event)
void ScriptView::setupContextMenu()
{
mMenu = new MenuBuilder(this);
MenuBuilder* mLoadMenu = new MenuBuilder(this);
mLoadMenu->addAction(makeShortcutAction(DIcon("folder-horizontal-open.png"), tr("&Open..."), SLOT(openFile()), "ActionLoadScript"));
mLoadMenu->addAction(makeShortcutAction(DIcon("binary_paste.png"), tr("&Paste"), SLOT(paste()), "ActionBinaryPaste"));
mMenu->addMenu(makeMenu(tr("Load Script")), mLoadMenu);
MenuBuilder* loadMenu = new MenuBuilder(this);
loadMenu->addAction(makeShortcutAction(DIcon("folder-horizontal-open.png"), tr("&Open..."), SLOT(openFile()), "ActionLoadScript"));
loadMenu->addAction(makeShortcutAction(DIcon("binary_paste.png"), tr("&Paste"), SLOT(paste()), "ActionBinaryPaste"));
loadMenu->addSeparator();
loadMenu->addBuilder(new MenuBuilder(this, [this](QMenu * menu)
{
mMRUList->appendMenu(menu);
return true;
}));
mMenu->addMenu(makeMenu(DIcon("load-script.png"), tr("Load Script")), loadMenu);
auto isempty = [this](QMenu*)
{
return getRowCount() != 0;
@ -463,29 +475,34 @@ void ScriptView::setInfoLine(int line, QString info)
reloadData(); //repaint
}
void ScriptView::openRecentFile(QString file)
{
filename = file;
DbgScriptUnload();
DbgScriptLoad(filename.toUtf8().constData());
mMRUList->addEntry(filename);
mMRUList->save();
}
void ScriptView::openFile()
{
filename = QFileDialog::getOpenFileName(this, tr("Select script"), 0, tr("Script files (*.txt *.scr);;All files (*.*)"));
if(!filename.length())
return;
filename = QDir::toNativeSeparators(filename); //convert to native path format (with backlashes)
DbgScriptUnload();
DbgScriptLoad(filename.toUtf8().constData());
openRecentFile(filename);
}
void ScriptView::paste()
{
DbgScriptUnload();
filename.clear();
DbgScriptUnload();
DbgScriptLoad("x64dbg://localhost/clipboard");
}
void ScriptView::reload()
{
if(!filename.length())
return;
DbgScriptUnload();
DbgScriptLoad(filename.toUtf8().constData());
openRecentFile(filename);
}
void ScriptView::unload()

View File

@ -4,6 +4,7 @@
#include "StdTable.h"
class QMessageBox;
class MRUList;
class ScriptView : public StdTable
{
@ -27,6 +28,7 @@ public slots:
void error(int line, QString message);
void setTitle(QString title);
void setInfoLine(int line, QString info);
void openRecentFile(QString file);
void openFile();
void paste();
void reload();
@ -57,7 +59,8 @@ private:
QString filename;
MenuBuilder* mMenu;
QMessageBox* msg = nullptr;
QMessageBox* msg;
MRUList* mMRUList;
};
#endif // SCRIPTVIEW_H

Binary file not shown.

After

Width:  |  Height:  |  Size: 556 B

View File

@ -295,5 +295,6 @@
<file>images/layout.png</file>
<file>images/summary.png</file>
<file>images/edit-script.png</file>
<file>images/load-script.png</file>
</qresource>
</RCC>