2017-03-29 10:18:37 +00:00
|
|
|
#include "omnibar.h"
|
|
|
|
#include "mainwindow.h"
|
|
|
|
|
|
|
|
#include <QStringListModel>
|
|
|
|
#include <QCompleter>
|
|
|
|
#include <QShortcut>
|
|
|
|
|
|
|
|
Omnibar::Omnibar(MainWindow *main, QWidget *parent) :
|
|
|
|
QLineEdit(parent)
|
|
|
|
{
|
|
|
|
// Radare core found in:
|
|
|
|
this->main = main;
|
|
|
|
|
|
|
|
// QLineEdit basic features
|
|
|
|
this->setMinimumHeight(16);
|
|
|
|
this->setMaximumHeight(16);
|
|
|
|
this->setFrame(false);
|
2017-04-10 09:31:34 +00:00
|
|
|
this->setPlaceholderText("Type flag name or address here");
|
2017-03-29 10:18:37 +00:00
|
|
|
this->setStyleSheet("border-radius: 5px;");
|
|
|
|
this->setTextMargins(10, 0, 0, 0);
|
|
|
|
this->setClearButtonEnabled(true);
|
|
|
|
|
|
|
|
this->commands << ": Comments toggle"
|
|
|
|
<< ": Dashboard toggle"
|
|
|
|
<< ": Flags toggle"
|
|
|
|
<< ": Functions toggle"
|
|
|
|
<< ": Imports toggle"
|
|
|
|
<< ": Notepad toggle"
|
|
|
|
<< ": Relocs toggle"
|
|
|
|
<< ": Run Script"
|
|
|
|
<< ": Sections toggle"
|
|
|
|
<< ": Strings toggle"
|
|
|
|
<< ": Symbols toggle"
|
|
|
|
<< ": Tabs up/down"
|
|
|
|
<< ": Theme switch"
|
|
|
|
<< ": Lock/Unlock interface"
|
|
|
|
<< ": Web server start/stop";
|
|
|
|
|
|
|
|
connect(this, SIGNAL(returnPressed()), this, SLOT(on_gotoEntry_returnPressed()));
|
|
|
|
|
|
|
|
// Esc clears omnibar
|
2017-04-09 19:55:06 +00:00
|
|
|
QShortcut *clear_shortcut = new QShortcut(QKeySequence(Qt::Key_Escape), this);
|
2017-03-29 10:18:37 +00:00
|
|
|
connect(clear_shortcut, SIGNAL(activated()), this, SLOT(clearContents()));
|
2017-04-05 09:35:19 +00:00
|
|
|
clear_shortcut->setContext(Qt::WidgetShortcut);
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 19:55:06 +00:00
|
|
|
void Omnibar::setupCompleter()
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
// Set gotoEntry completer for jump history
|
|
|
|
QStringList flagsList = this->getFlags();
|
|
|
|
QCompleter *completer = new QCompleter(flagsList, this);
|
|
|
|
completer->setMaxVisibleItems(20);
|
|
|
|
completer->setCompletionMode(QCompleter::PopupCompletion);
|
|
|
|
completer->setModelSorting(QCompleter::CaseSensitivelySortedModel);
|
|
|
|
completer->setCaseSensitivity(Qt::CaseInsensitive);
|
|
|
|
completer->setFilterMode(Qt::MatchContains);
|
|
|
|
|
2017-04-09 19:55:06 +00:00
|
|
|
QStringListModel *completerModel = (QStringListModel *)(completer->model());
|
2017-03-29 10:18:37 +00:00
|
|
|
completerModel->setStringList(completerModel->stringList() << this->commands);
|
|
|
|
|
|
|
|
this->setCompleter(completer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Omnibar::restoreCompleter()
|
|
|
|
{
|
|
|
|
QCompleter *completer = this->completer();
|
|
|
|
completer->setFilterMode(Qt::MatchContains);
|
|
|
|
}
|
|
|
|
|
2017-04-09 19:55:06 +00:00
|
|
|
void Omnibar::showCommands()
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
this->setFocus();
|
|
|
|
this->setText(": ");
|
|
|
|
|
|
|
|
QCompleter *completer = this->completer();
|
|
|
|
completer->setCompletionMode(QCompleter::PopupCompletion);
|
|
|
|
completer->setModelSorting(QCompleter::CaseSensitivelySortedModel);
|
|
|
|
completer->setCaseSensitivity(Qt::CaseInsensitive);
|
|
|
|
completer->setFilterMode(Qt::MatchStartsWith);
|
|
|
|
|
|
|
|
completer->setMaxVisibleItems(20);
|
|
|
|
|
|
|
|
completer->setCompletionPrefix(": ");
|
|
|
|
completer->complete();
|
|
|
|
}
|
|
|
|
|
2017-04-09 19:55:06 +00:00
|
|
|
void Omnibar::clearContents()
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
this->setText("");
|
2017-04-05 09:35:19 +00:00
|
|
|
// Necessary hack to make it work properly
|
2017-03-29 10:18:37 +00:00
|
|
|
this->clearFocus();
|
2017-04-05 09:35:19 +00:00
|
|
|
this->setFocus();
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Omnibar::on_gotoEntry_returnPressed()
|
|
|
|
{
|
|
|
|
QString str = this->text();
|
2017-04-09 19:55:06 +00:00
|
|
|
if (str.length() > 0)
|
|
|
|
{
|
|
|
|
if (str.contains(": "))
|
|
|
|
{
|
|
|
|
if (str.contains("Lock"))
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
this->main->on_actionLock_triggered();
|
2017-04-09 19:55:06 +00:00
|
|
|
}
|
|
|
|
else if (str.contains("Functions"))
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
this->main->on_actionFunctions_triggered();
|
2017-04-09 19:55:06 +00:00
|
|
|
}
|
|
|
|
else if (str.contains("Flags"))
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
this->main->on_actionFlags_triggered();
|
2017-04-09 19:55:06 +00:00
|
|
|
}
|
|
|
|
else if (str.contains("Sections"))
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
this->main->on_actionSections_triggered();
|
2017-04-09 19:55:06 +00:00
|
|
|
}
|
|
|
|
else if (str.contains("Strings"))
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
this->main->on_actionStrings_triggered();
|
2017-04-09 19:55:06 +00:00
|
|
|
}
|
|
|
|
else if (str.contains("Imports"))
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
this->main->on_actionImports_triggered();
|
2017-04-09 19:55:06 +00:00
|
|
|
}
|
|
|
|
else if (str.contains("Symbols"))
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
this->main->on_actionSymbols_triggered();
|
2017-04-09 19:55:06 +00:00
|
|
|
}
|
|
|
|
else if (str.contains("Relocs"))
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
this->main->on_actionReloc_triggered();
|
2017-04-09 19:55:06 +00:00
|
|
|
}
|
|
|
|
else if (str.contains("Comments"))
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
this->main->on_actionComents_triggered();
|
2017-04-09 19:55:06 +00:00
|
|
|
}
|
|
|
|
else if (str.contains("Notepad"))
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
this->main->on_actionNotepad_triggered();
|
2017-04-09 19:55:06 +00:00
|
|
|
}
|
|
|
|
else if (str.contains("Dashboard"))
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
this->main->on_actionDashboard_triggered();
|
2017-04-09 19:55:06 +00:00
|
|
|
}
|
|
|
|
else if (str.contains("Theme"))
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
this->main->sideBar->themesButtonToggle();
|
2017-04-09 19:55:06 +00:00
|
|
|
}
|
|
|
|
else if (str.contains("Script"))
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
this->main->on_actionRun_Script_triggered();
|
2017-04-09 19:55:06 +00:00
|
|
|
}
|
|
|
|
else if (str.contains("Tabs"))
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
this->main->on_actionTabs_triggered();
|
|
|
|
}
|
2017-04-09 19:55:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
//this->main->seek(this->main->core->cmd("?v " + this->text()), this->text());
|
|
|
|
QString off = this->main->core->cmd("afo " + this->text());
|
|
|
|
this->main->seek(off.trimmed(), this->text());
|
|
|
|
}
|
2017-04-09 17:09:35 +00:00
|
|
|
}
|
|
|
|
|
2017-03-29 10:18:37 +00:00
|
|
|
// check which tab is open? update all tabs? hex, graph?
|
|
|
|
//refreshMem( this->gotoEntry->text() );
|
|
|
|
this->setText("");
|
|
|
|
this->clearFocus();
|
|
|
|
this->restoreCompleter();
|
|
|
|
}
|
|
|
|
|
2017-04-09 19:55:06 +00:00
|
|
|
void Omnibar::fillFlags(QString flag)
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
this->flags << flag;
|
|
|
|
}
|
|
|
|
|
2017-04-09 19:55:06 +00:00
|
|
|
void Omnibar::clearFlags()
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
this->flags.clear();
|
|
|
|
}
|
|
|
|
|
2017-04-09 19:55:06 +00:00
|
|
|
QStringList Omnibar::getFlags()
|
|
|
|
{
|
2017-03-29 10:18:37 +00:00
|
|
|
return this->flags;
|
|
|
|
}
|