Cleanup Nodepad

This commit is contained in:
Florian Märkl 2017-12-03 21:50:20 +01:00
parent a7eec66110
commit f80cf8eb03
4 changed files with 37 additions and 219 deletions

View File

@ -353,8 +353,6 @@ void MainWindow::finalizeOpen()
addOutput("\n" + core->cmd("fo"));
//previewDock->setWindowTitle("entry0");
showMaximized();
// Initialize syntax highlighters
notepadDock->highlightPreview();
}
bool MainWindow::saveProject(bool quit)

View File

@ -28,17 +28,12 @@ Notepad::Notepad(MainWindow *main, QWidget *parent) :
this->main = main;
highlighter = new MdHighlighter(ui->notepadTextEdit->document());
ui->splitter->setStretchFactor(0, 2);
isFirstTime = true;
this->notesTextEdit = ui->notepadTextEdit;
// Increase notes document inner margin
QTextDocument *docu = this->notesTextEdit->document();
docu->setDocumentMargin(10);
// Increase preview notes document inner margin
QPlainTextEdit *preview = ui->previewTextEdit;
QTextDocument *preview_docu = preview->document();
preview_docu->setDocumentMargin(10);
// Context menu
ui->notepadTextEdit->setContextMenuPolicy(Qt::CustomContextMenu);
@ -70,7 +65,6 @@ void Notepad::on_fontButton_clicked()
void Notepad::setFonts(QFont font)
{
ui->notepadTextEdit->setFont(font);
ui->previewTextEdit->setFont(font);
}
void Notepad::on_boldButton_clicked()
@ -162,11 +156,6 @@ void Notepad::on_redoButton_clicked()
doc->redo();
}
void Notepad::highlightPreview()
{
disasm_highlighter = new Highlighter(ui->previewTextEdit->document());
}
void Notepad::on_searchEdit_returnPressed()
{
QString searchString = ui->searchEdit->text();
@ -289,29 +278,22 @@ void Notepad::showNotepadContextMenu(const QPoint &pt)
QTextCursor cur = ui->notepadTextEdit->textCursor();
QAction *first = menu->actions().at(0);
if (cur.hasSelection())
if (!cur.hasSelection())
{
// Get selected text
//this->main->add_debug_output("Selected text: " + cur.selectedText());
this->addr = cur.selectedText();
}
else
{
// Get word under the cursor
cur.select(QTextCursor::WordUnderCursor);
//this->main->add_debug_output("Word: " + cur.selectedText());
this->addr = cur.selectedText();
}
ui->actionDisassmble_bytes->setText("Disassemble bytes at: " + this->addr);
ui->actionDisassmble_function->setText("Disassemble function at: " + this->addr);
ui->actionHexdump_bytes->setText("Hexdump bytes at: " + this->addr);
ui->actionCompact_Hexdump->setText("Compact Hexdump at: " + this->addr);
ui->actionHexdump_function->setText("Hexdump function at: " + this->addr);
menu->insertAction(first, ui->actionDisassmble_bytes);
menu->insertAction(first, ui->actionDisassmble_function);
menu->insertAction(first, ui->actionHexdump_bytes);
menu->insertAction(first, ui->actionCompact_Hexdump);
menu->insertAction(first, ui->actionHexdump_function);
addr = cur.selectedText();
static const int maxLength = 20;
if(addr.length() > maxLength)
{
addr = addr.left(maxLength-1) + "\u2026";
}
ui->actionSeekToSelection->setText(tr("Seek to \"%1\"").arg(addr));
menu->insertAction(first, ui->actionSeekToSelection);
menu->insertSeparator(first);
ui->notepadTextEdit->setContextMenuPolicy(Qt::DefaultContextMenu);
menu->exec(ui->notepadTextEdit->mapToGlobal(pt));
@ -319,29 +301,9 @@ void Notepad::showNotepadContextMenu(const QPoint &pt)
ui->notepadTextEdit->setContextMenuPolicy(Qt::CustomContextMenu);
}
void Notepad::on_actionDisassmble_bytes_triggered()
void Notepad::on_actionSeekToSelection_triggered()
{
ui->previewTextEdit->setPlainText(CutterCore::getInstance()->cmd("pd 100 @ " + this->addr));
}
void Notepad::on_actionDisassmble_function_triggered()
{
ui->previewTextEdit->setPlainText(CutterCore::getInstance()->cmd("pdf @ " + this->addr));
}
void Notepad::on_actionHexdump_bytes_triggered()
{
ui->previewTextEdit->setPlainText(CutterCore::getInstance()->cmd("px 1024 @ " + this->addr));
}
void Notepad::on_actionCompact_Hexdump_triggered()
{
ui->previewTextEdit->setPlainText(CutterCore::getInstance()->cmd("pxi 1024 @ " + this->addr));
}
void Notepad::on_actionHexdump_function_triggered()
{
ui->previewTextEdit->setPlainText(CutterCore::getInstance()->cmd("pxf @ " + this->addr));
Core()->seek(addr);
}
void Notepad::updateNotes(const QString &notes)

View File

@ -45,11 +45,7 @@ private slots:
void showNotepadContextMenu(const QPoint &pt);
void on_actionDisassmble_bytes_triggered();
void on_actionDisassmble_function_triggered();
void on_actionHexdump_bytes_triggered();
void on_actionCompact_Hexdump_triggered();
void on_actionHexdump_function_triggered();
void on_actionSeekToSelection_triggered();
void updateNotes(const QString &notes);
void textChanged();

View File

@ -388,53 +388,6 @@ QToolTip {
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="underlineButton">
<property name="font">
<font>
<pointsize>15</pointsize>
<underline>true</underline>
</font>
</property>
<property name="toolTip">
<string notr="true">Underline</string>
</property>
<property name="styleSheet">
<string notr="true">QToolButton { /* all types of tool button */
border: 5px solid #333;
border-left: 10px solid #333;
border-right: 10px solid #333;
border-radius: 0px;
background-color: #333;
color: rgb(172, 174, 175);
}
QToolButton:hover {
border: 5px solid #444;
border-radius: 0px;
background-color: #444;
}
QToolButton:pressed {
border: 5px solid #2180a9;
border-radius: 0px;
background-color: #2180a9;
}
QToolTip {
background-color: #444;
border: 3px solid #444;
color: rgb(232, 232, 232);
}</string>
</property>
<property name="text">
<string notr="true">U</string>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextOnly</enum>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
@ -644,93 +597,37 @@ QToolTip {
</widget>
</item>
<item>
<widget class="QSplitter" name="splitter">
<widget class="QPlainTextEdit" name="notepadTextEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<family>Monaco</family>
<pointsize>12</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">QSplitter::handle {
height: 2px;
background-color: rgb(255, 255, 255);
image: url(:/img/icons/tabs.svg);
}</string>
<string notr="true"/>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="lineWrapMode">
<enum>QPlainTextEdit::NoWrap</enum>
</property>
<property name="plainText">
<string/>
</property>
<widget class="QPlainTextEdit" name="notepadTextEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<family>Monaco</family>
<pointsize>12</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="lineWrapMode">
<enum>QPlainTextEdit::NoWrap</enum>
</property>
<property name="plainText">
<string/>
</property>
</widget>
<widget class="QPlainTextEdit" name="previewTextEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<family>Anonymous Pro</family>
<pointsize>13</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="lineWrapMode">
<enum>QPlainTextEdit::NoWrap</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="plainText">
<string/>
</property>
</widget>
</widget>
</item>
</layout>
@ -739,44 +636,9 @@ QToolTip {
</item>
</layout>
</widget>
<action name="actionDisassmble_bytes">
<action name="actionSeekToSelection">
<property name="text">
<string>Disassmble bytes at </string>
</property>
<property name="toolTip">
<string>Disassmble bytes at </string>
</property>
</action>
<action name="actionDisassmble_function">
<property name="text">
<string>Disassmble function at </string>
</property>
<property name="toolTip">
<string>Disassmble function at </string>
</property>
</action>
<action name="actionHexdump_bytes">
<property name="text">
<string>Hexdump bytes at </string>
</property>
<property name="toolTip">
<string>Hexdump bytes at </string>
</property>
</action>
<action name="actionCompact_Hexdump">
<property name="text">
<string>Compact Hexdump at </string>
</property>
<property name="toolTip">
<string>Compact Hexdump at </string>
</property>
</action>
<action name="actionHexdump_function">
<property name="text">
<string>Hexdump function at</string>
</property>
<property name="toolTip">
<string>Hexdump function at</string>
<string>Seek to</string>
</property>
</action>
</widget>