mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-24 13:55:26 +00:00
Add ConsoleWidget
Moved the existing console functionality to a separate widget for easier extension
This commit is contained in:
parent
0062ff424e
commit
6731032495
@ -61,7 +61,8 @@ SOURCES += \
|
|||||||
widgets/dashboard.cpp \
|
widgets/dashboard.cpp \
|
||||||
dialogs/xrefsdialog.cpp \
|
dialogs/xrefsdialog.cpp \
|
||||||
hexhighlighter.cpp \
|
hexhighlighter.cpp \
|
||||||
widgets/sectionsdock.cpp
|
widgets/sectionsdock.cpp \
|
||||||
|
widgets/consolewidget.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
mainwindow.h \
|
mainwindow.h \
|
||||||
@ -98,7 +99,8 @@ HEADERS += \
|
|||||||
dialogs/xrefsdialog.h \
|
dialogs/xrefsdialog.h \
|
||||||
hexhighlighter.h \
|
hexhighlighter.h \
|
||||||
widgets/sectionsdock.h \
|
widgets/sectionsdock.h \
|
||||||
widgets/dockwidget.h
|
widgets/dockwidget.h \
|
||||||
|
widgets/consolewidget.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
mainwindow.ui \
|
mainwindow.ui \
|
||||||
@ -121,7 +123,8 @@ FORMS += \
|
|||||||
widgets/sidebar.ui \
|
widgets/sidebar.ui \
|
||||||
widgets/dashboard.ui \
|
widgets/dashboard.ui \
|
||||||
dialogs/xrefsdialog.ui \
|
dialogs/xrefsdialog.ui \
|
||||||
widgets/sectionsdock.ui
|
widgets/sectionsdock.ui \
|
||||||
|
widgets/consolewidget.ui
|
||||||
|
|
||||||
RESOURCES += \
|
RESOURCES += \
|
||||||
resources.qrc
|
resources.qrc
|
||||||
|
189
src/widgets/consolewidget.cpp
Normal file
189
src/widgets/consolewidget.cpp
Normal file
@ -0,0 +1,189 @@
|
|||||||
|
#include "consolewidget.h"
|
||||||
|
#include "ui_consolewidget.h"
|
||||||
|
|
||||||
|
#include "helpers.h"
|
||||||
|
#include "qrcore.h"
|
||||||
|
|
||||||
|
#include <QScrollBar>
|
||||||
|
#include <QMenu>
|
||||||
|
#include <QCompleter>
|
||||||
|
//TODO: delete
|
||||||
|
#include <QStringListModel>
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: Find a way to get to this without copying it here
|
||||||
|
// source: libr/core/core.c:585..
|
||||||
|
#define CMDS (sizeof (radare_argv)/sizeof(const char*))
|
||||||
|
static const char *radare_argv[] = {
|
||||||
|
"?", "?v", "whereis", "which", "ls", "rm", "mkdir", "pwd", "cat", "less",
|
||||||
|
"dH", "ds", "dso", "dsl", "dc", "dd", "dm", "db ", "db-",
|
||||||
|
"dp", "dr", "dcu", "dmd", "dmp", "dml",
|
||||||
|
"ec","ecs", "eco",
|
||||||
|
"S", "S.", "S*", "S-", "S=", "Sa", "Sa-", "Sd", "Sl", "SSj", "Sr",
|
||||||
|
"s", "s+", "s++", "s-", "s--", "s*", "sa", "sb", "sr",
|
||||||
|
"!", "!!",
|
||||||
|
"#sha1", "#crc32", "#pcprint", "#sha256", "#sha512", "#md4", "#md5",
|
||||||
|
"#!python", "#!perl", "#!vala",
|
||||||
|
"V", "v",
|
||||||
|
"aa", "ab", "af", "ar", "ag", "at", "a?", "ax", "ad",
|
||||||
|
"ae", "aec", "aex", "aep", "aea", "aeA", "aes", "aeso", "aesu", "aesue", "aer", "aei", "aeim", "aef",
|
||||||
|
"aaa", "aac","aae", "aai", "aar", "aan", "aas", "aat", "aap", "aav",
|
||||||
|
"af", "afa", "afan", "afc", "afC", "afi", "afb", "afbb", "afn", "afr", "afs", "af*", "afv", "afvn",
|
||||||
|
"aga", "agc", "agd", "agl", "agfl",
|
||||||
|
"e", "et", "e-", "e*", "e!", "e?", "env ",
|
||||||
|
"i", "ii", "iI", "is", "iS", "iz",
|
||||||
|
"q", "q!",
|
||||||
|
"f", "fl", "fr", "f-", "f*", "fs", "fS", "fr", "fo", "f?",
|
||||||
|
"m", "m*", "ml", "m-", "my", "mg", "md", "mp", "m?",
|
||||||
|
"o", "o+", "oc", "on", "op", "o-", "x", "wf", "wF", "wta", "wtf", "wp",
|
||||||
|
"t", "to", "t-", "tf", "td", "td-", "tb", "tn", "te", "tl", "tk", "ts", "tu",
|
||||||
|
"(", "(*", "(-", "()", ".", ".!", ".(", "./",
|
||||||
|
"r", "r+", "r-",
|
||||||
|
"b", "bf", "b?",
|
||||||
|
"/", "//", "/a", "/c", "/h", "/m", "/x", "/v", "/v2", "/v4", "/v8", "/r", "/re",
|
||||||
|
"y", "yy", "y?",
|
||||||
|
"wx", "ww", "w?", "wxf",
|
||||||
|
"p6d", "p6e", "p8", "pb", "pc",
|
||||||
|
"pd", "pda", "pdb", "pdc", "pdj", "pdr", "pdf", "pdi", "pdl", "pds", "pdt",
|
||||||
|
"pD", "px", "pX", "po", "pf", "pf.", "pf*", "pf*.", "pfd", "pfd.", "pv", "p=", "p-",
|
||||||
|
"pfj", "pfj.", "pfv", "pfv.",
|
||||||
|
"pm", "pr", "pt", "ptd", "ptn", "pt?", "ps", "pz", "pu", "pU", "p?",
|
||||||
|
"z", "z*", "zj", "z-", "z-*",
|
||||||
|
"za", "zaf", "zaF",
|
||||||
|
"zo", "zoz", "zos",
|
||||||
|
"zfd", "zfs", "zfz",
|
||||||
|
"z/", "z/*",
|
||||||
|
"zc",
|
||||||
|
"zs", "zs+", "zs-", "zs-*", "zsr",
|
||||||
|
"#!pipe",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
ConsoleWidget::ConsoleWidget(QRCore *core, QWidget *parent) :
|
||||||
|
QWidget(parent),
|
||||||
|
ui(new Ui::ConsoleWidget),
|
||||||
|
core(core)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
// Adjust console lineedit
|
||||||
|
ui->consoleInputLineEdit->setTextMargins(10, 0, 0, 0);
|
||||||
|
|
||||||
|
/*
|
||||||
|
ui->consoleOutputTextEdit->setFont(QFont("Monospace", 8));
|
||||||
|
ui->consoleOutputTextEdit->setStyleSheet("background-color:black;color:gray;");
|
||||||
|
ui->consoleInputLineEdit->setStyleSheet("background-color:black;color:gray;");
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Adjust text margins of consoleOutputTextEdit
|
||||||
|
QTextDocument *console_docu = ui->consoleOutputTextEdit->document();
|
||||||
|
console_docu->setDocumentMargin(10);
|
||||||
|
|
||||||
|
// Fix output panel font
|
||||||
|
qhelpers::normalizeFont(ui->consoleOutputTextEdit);
|
||||||
|
|
||||||
|
// Set console output context menu
|
||||||
|
ui->consoleOutputTextEdit->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
|
connect(ui->consoleOutputTextEdit, SIGNAL(customContextMenuRequested(const QPoint &)),
|
||||||
|
this, SLOT(showConsoleContextMenu(const QPoint &)));
|
||||||
|
}
|
||||||
|
|
||||||
|
ConsoleWidget::~ConsoleWidget()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConsoleWidget::addOutput(const QString &msg)
|
||||||
|
{
|
||||||
|
ui->consoleOutputTextEdit->appendPlainText(msg);
|
||||||
|
ui->consoleOutputTextEdit->verticalScrollBar()->setValue(ui->consoleOutputTextEdit->verticalScrollBar()->maximum());
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConsoleWidget::addDebugOutput(const QString &msg)
|
||||||
|
{
|
||||||
|
ui->consoleOutputTextEdit->appendHtml("<font color=\"red\"> [DEBUG]:\t" + msg + "</font>");
|
||||||
|
ui->consoleOutputTextEdit->verticalScrollBar()->setValue(ui->consoleOutputTextEdit->verticalScrollBar()->maximum());
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConsoleWidget::focusInputLineEdit()
|
||||||
|
{
|
||||||
|
ui->consoleInputLineEdit->setFocus();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConsoleWidget::on_consoleInputLineEdit_returnPressed()
|
||||||
|
{
|
||||||
|
if (this->core)
|
||||||
|
{
|
||||||
|
QString input = ui->consoleInputLineEdit->text();
|
||||||
|
ui->consoleOutputTextEdit->appendPlainText(this->core->cmd(input));
|
||||||
|
ui->consoleOutputTextEdit->verticalScrollBar()->setValue(ui->consoleOutputTextEdit->verticalScrollBar()->maximum());
|
||||||
|
// Add new command to history
|
||||||
|
QCompleter *completer = ui->consoleInputLineEdit->completer();
|
||||||
|
if (completer != NULL)
|
||||||
|
{
|
||||||
|
QStringListModel *completerModel = (QStringListModel *)(completer->model());
|
||||||
|
if (completerModel != NULL)
|
||||||
|
completerModel->setStringList(completerModel->stringList() << input);
|
||||||
|
}
|
||||||
|
|
||||||
|
ui->consoleInputLineEdit->setText("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConsoleWidget::on_consoleExecButton_clicked()
|
||||||
|
{
|
||||||
|
on_consoleInputLineEdit_returnPressed();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConsoleWidget::showConsoleContextMenu(const QPoint &pt)
|
||||||
|
{
|
||||||
|
// Set console output popup menu
|
||||||
|
QMenu *menu = ui->consoleOutputTextEdit->createStandardContextMenu();
|
||||||
|
menu->clear();
|
||||||
|
// TODO:
|
||||||
|
// menu->addAction(ui->actionClear_ConsoleOutput);
|
||||||
|
// menu->addAction(ui->actionConsoleSync_with_core);
|
||||||
|
//ui->actionConsoleSync_with_core->setChecked(true);
|
||||||
|
ui->consoleOutputTextEdit->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
|
|
||||||
|
menu->exec(ui->consoleOutputTextEdit->mapToGlobal(pt));
|
||||||
|
delete menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConsoleWidget::on_actionConsoleSync_with_core_triggered()
|
||||||
|
{
|
||||||
|
// TODO:
|
||||||
|
// if (ui->actionConsoleSync_with_core->isChecked())
|
||||||
|
// {
|
||||||
|
// //Enable core syncronization
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// // Disable core sync
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConsoleWidget::on_actionClear_ConsoleOutput_triggered()
|
||||||
|
{
|
||||||
|
ui->consoleOutputTextEdit->clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ConsoleWidget::on_showHistoToolButton_clicked()
|
||||||
|
{
|
||||||
|
QCompleter *completer = ui->consoleInputLineEdit->completer();
|
||||||
|
if (completer == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (ui->showHistoToolButton->isChecked())
|
||||||
|
{
|
||||||
|
completer->setCompletionMode(QCompleter::UnfilteredPopupCompletion);
|
||||||
|
// Uhm... shouldn't it be called always?
|
||||||
|
completer->complete();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
completer->setCompletionMode(QCompleter::PopupCompletion);
|
||||||
|
}
|
||||||
|
}
|
44
src/widgets/consolewidget.h
Normal file
44
src/widgets/consolewidget.h
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#ifndef CONSOLEWIDGET_H
|
||||||
|
#define CONSOLEWIDGET_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
class QRCore;
|
||||||
|
|
||||||
|
namespace Ui
|
||||||
|
{
|
||||||
|
class ConsoleWidget;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ConsoleWidget : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ConsoleWidget(QRCore *core, QWidget *parent = 0);
|
||||||
|
~ConsoleWidget();
|
||||||
|
|
||||||
|
void addOutput(const QString &msg);
|
||||||
|
void addDebugOutput(const QString &msg);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void focusInputLineEdit();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void on_consoleInputLineEdit_returnPressed();
|
||||||
|
|
||||||
|
void on_consoleExecButton_clicked();
|
||||||
|
|
||||||
|
void showConsoleContextMenu(const QPoint &pt);
|
||||||
|
|
||||||
|
void on_actionClear_ConsoleOutput_triggered();
|
||||||
|
void on_actionConsoleSync_with_core_triggered();
|
||||||
|
|
||||||
|
void on_showHistoToolButton_clicked();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::ConsoleWidget *ui;
|
||||||
|
QRCore *core;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CONSOLEWIDGET_H
|
194
src/widgets/consolewidget.ui
Normal file
194
src/widgets/consolewidget.ui
Normal file
@ -0,0 +1,194 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>ConsoleWidget</class>
|
||||||
|
<widget class="QWidget" name="ConsoleWidget">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>583</width>
|
||||||
|
<height>534</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Form</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<property name="spacing">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QPlainTextEdit" name="consoleOutputTextEdit">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<family>Monaco</family>
|
||||||
|
<pointsize>11</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="styleSheet">
|
||||||
|
<string notr="true">/*QPlainTextEdit { background: rgb(226, 230, 235) }*/</string>
|
||||||
|
</property>
|
||||||
|
<property name="frameShape">
|
||||||
|
<enum>QFrame::NoFrame</enum>
|
||||||
|
</property>
|
||||||
|
<property name="lineWidth">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="undoRedoEnabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="readOnly">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="plainText">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<property name="spacing">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>5</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>3</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>5</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>3</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="consoleInputLineEdit">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>12</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="styleSheet">
|
||||||
|
<string notr="true">border-top: 1px solid rgb(255, 255, 255);</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="frame">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="placeholderText">
|
||||||
|
<string> Type "?" for help</string>
|
||||||
|
</property>
|
||||||
|
<property name="clearButtonEnabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="showHistoToolButton">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>16777215</width>
|
||||||
|
<height>18</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Show commands history</string>
|
||||||
|
</property>
|
||||||
|
<property name="styleSheet">
|
||||||
|
<string notr="true">background-color: white;</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>...</string>
|
||||||
|
</property>
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="autoRaise">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="arrowType">
|
||||||
|
<enum>Qt::DownArrow</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeType">
|
||||||
|
<enum>QSizePolicy::Fixed</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>10</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="consoleExecButton">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Execute command</string>
|
||||||
|
</property>
|
||||||
|
<property name="styleSheet">
|
||||||
|
<string notr="true">/*
|
||||||
|
border: none;
|
||||||
|
padding: 2px;
|
||||||
|
*/
|
||||||
|
|
||||||
|
QToolButton { /* all types of tool button */
|
||||||
|
border: 0px solid rgb(255, 255, 255);
|
||||||
|
border-radius: 6px;
|
||||||
|
border-top: 2px solid rgb(255, 255, 255);
|
||||||
|
border-bottom: 2px solid rgb(255, 255, 255);
|
||||||
|
border-left: 8px solid rgb(255, 255, 255);
|
||||||
|
border-right: 5px solid rgb(255, 255, 255);
|
||||||
|
margin-bottom: 1px;
|
||||||
|
margin-top: 1px;
|
||||||
|
background-color: rgb(255, 255, 255);
|
||||||
|
}</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>...</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="../resources.qrc">
|
||||||
|
<normaloff>:/new/prefix1/img/icons/play.png</normaloff>:/new/prefix1/img/icons/play.png</iconset>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources>
|
||||||
|
<include location="../resources.qrc"/>
|
||||||
|
</resources>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
Loading…
Reference in New Issue
Block a user