cutter/src/widgets/Omnibar.cpp

189 lines
5.3 KiB
C++
Raw Normal View History

#include "Omnibar.h"
2017-10-01 19:09:42 +00:00
#include "MainWindow.h"
#include <QStringListModel>
#include <QCompleter>
#include <QShortcut>
2017-04-27 23:48:21 +00:00
#include <QAbstractItemView>
Omnibar::Omnibar(MainWindow *main, QWidget *parent) :
QLineEdit(parent),
main(main),
2017-06-03 12:27:23 +00:00
commands(
{
": Comments toggle",
": Dashboard toggle",
": Exports toggle",
": Flags toggle",
": Functions toggle",
": Imports toggle",
": Lock/Unlock interface",
": Notepad toggle",
": Refresh contents",
": Relocs toggle",
": Run Script",
": Sections toggle",
": Strings toggle",
": Symbols toggle",
": Tabs up/down",
": Theme switch",
": Web server start/stop"
})
{
// QLineEdit basic features
this->setMinimumHeight(16);
this->setMaximumHeight(16);
this->setFrame(false);
this->setPlaceholderText("Type flag name or address here");
this->setStyleSheet("border-radius: 5px;");
this->setTextMargins(10, 0, 0, 0);
this->setClearButtonEnabled(true);
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);
connect(clear_shortcut, SIGNAL(activated()), this, SLOT(clear()));
2017-05-18 10:20:53 +00:00
clear_shortcut->setContext(Qt::WidgetWithChildrenShortcut);
}
2017-04-09 19:55:06 +00:00
void Omnibar::setupCompleter()
{
// Set gotoEntry completer for jump history
QCompleter *completer = new QCompleter(flags + commands, this);
completer->setMaxVisibleItems(20);
completer->setCompletionMode(QCompleter::PopupCompletion);
completer->setModelSorting(QCompleter::CaseSensitivelySortedModel);
completer->setCaseSensitivity(Qt::CaseInsensitive);
completer->setFilterMode(Qt::MatchContains);
this->setCompleter(completer);
}
void Omnibar::refresh(const QStringList &flagList)
{
flags = flagList;
setupCompleter();
}
void Omnibar::restoreCompleter()
{
QCompleter *completer = this->completer();
completer->setFilterMode(Qt::MatchContains);
}
2017-04-09 19:55:06 +00:00
void Omnibar::showCommands()
{
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-27 23:48:21 +00:00
void Omnibar::clear()
{
QLineEdit::clear();
// Close the potential shown completer popup
clearFocus();
setFocus();
}
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"))
{
this->main->on_actionLock_triggered();
2017-04-09 19:55:06 +00:00
}
else if (str.contains("Functions"))
{
this->main->on_actionFunctions_triggered();
2017-04-09 19:55:06 +00:00
}
else if (str.contains("Flags"))
{
this->main->on_actionFlags_triggered();
2017-04-09 19:55:06 +00:00
}
else if (str.contains("Sections"))
{
this->main->on_actionSections_triggered();
2017-04-09 19:55:06 +00:00
}
else if (str.contains("Strings"))
{
this->main->on_actionStrings_triggered();
2017-04-09 19:55:06 +00:00
}
else if (str.contains("Imports"))
{
this->main->on_actionImports_triggered();
2017-04-09 19:55:06 +00:00
}
2017-05-19 07:49:33 +00:00
else if (str.contains("Exports"))
{
this->main->on_actionExports_triggered();
}
2017-04-09 19:55:06 +00:00
else if (str.contains("Symbols"))
{
this->main->on_actionSymbols_triggered();
2017-04-09 19:55:06 +00:00
}
else if (str.contains("Refresh"))
{
this->main->refreshVisibleDockWidgets();
}
2017-04-09 19:55:06 +00:00
else if (str.contains("Relocs"))
{
this->main->on_actionReloc_triggered();
2017-04-09 19:55:06 +00:00
}
else if (str.contains("Comments"))
{
this->main->on_actionComents_triggered();
2017-04-09 19:55:06 +00:00
}
else if (str.contains("Notepad"))
{
this->main->on_actionNotepad_triggered();
2017-04-09 19:55:06 +00:00
}
else if (str.contains("Dashboard"))
{
this->main->on_actionDashboard_triggered();
2017-04-09 19:55:06 +00:00
}
else if (str.contains("Theme"))
{
2017-11-18 14:57:00 +00:00
this->main->toggleTheme();
2017-04-09 19:55:06 +00:00
}
else if (str.contains("Script"))
{
this->main->on_actionRun_Script_triggered();
2017-04-09 19:55:06 +00:00
}
else if (str.contains("Tabs"))
{
this->main->on_actionTabs_triggered();
}
2017-04-09 19:55:06 +00:00
}
else
{
2017-10-09 18:08:35 +00:00
//CutterCore::getInstance()->seek(CutterCore::getInstance()->cmd("?v " + this->text()), this->text());
QString off = CutterCore::getInstance()->cmd("afo " + this->text());
CutterCore::getInstance()->seek(off.trimmed().toInt());
}
}
// check which tab is open? update all tabs? hex, graph?
//refreshMem( this->gotoEntry->text() );
this->setText("");
this->clearFocus();
this->restoreCompleter();
}