Fixed weird widget priority behaviour and fix #514

This commit is contained in:
xarkes 2018-07-01 13:47:15 +02:00
parent 1e721ff32e
commit 22465615a4
3 changed files with 25 additions and 7 deletions

View File

@ -166,11 +166,6 @@ QString CutterCore::cmd(const QString &str)
r_mem_free(res);
if (offset != core_->offset) {
emit seekChanged(core_->offset);
// Switch from graph to disassembly if there is no function
if (this->cmd("afi.").trimmed().isEmpty() && memoryWidgetPriority == MemoryWidgetType::Graph) {
memoryWidgetPriority = MemoryWidgetType::Disassembly;
}
}
return o;
}

View File

@ -10,6 +10,7 @@
#include <QTextDocument>
#include <QFileDialog>
#include <QFile>
#include <QVBoxLayout>
#include "Cutter.h"
#include "utils/Colors.h"
@ -157,6 +158,23 @@ void DisassemblerGraphView::loadCurrentGraph()
disassembly_blocks.clear();
blocks.clear();
bool emptyGraph = functions.isEmpty();
if (emptyGraph) {
// If there's no function to print, just move to disassembly and add a message
Core()->setMemoryWidgetPriority(CutterCore::MemoryWidgetType::Disassembly);
if (!emptyText) {
QVBoxLayout *layout = new QVBoxLayout(this);
emptyText = new QLabel(this);
emptyText->setText(tr("No function detected. Cannot display graph."));
emptyText->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
layout->addWidget(emptyText);
layout->setAlignment(emptyText, Qt::AlignHCenter);
}
emptyText->setVisible(true);
} else {
emptyText->setVisible(false);
}
Analysis anal;
anal.ready = true;
@ -168,7 +186,9 @@ void DisassemblerGraphView::loadCurrentGraph()
windowTitle = tr("Graph");
QString funcName = func["name"].toString().trimmed();
if (!funcName.isEmpty()) {
if (emptyGraph) {
windowTitle += " (Empty)";
} else if (!funcName.isEmpty()) {
windowTitle += " (" + funcName + ")";
}
if (!seekable->getSyncWithCore()) {
@ -262,7 +282,6 @@ void DisassemblerGraphView::loadCurrentGraph()
}
}
void DisassemblerGraphView::prepareGraphNode(GraphBlock &block)
{
DisassemblyBlock &db = disassembly_blocks[block.entry];
@ -714,6 +733,7 @@ void DisassemblerGraphView::on_actionExportGraph_triggered()
QTextStream fileOut(&file);
fileOut << Core()->cmd("ag -");
}
void DisassemblerGraphView::wheelEvent(QWheelEvent *event)
{
// when CTRL is pressed, we zoom in/out with mouse wheel

View File

@ -6,6 +6,7 @@
#include <QWidget>
#include <QPainter>
#include <QShortcut>
#include <QLabel>
#include "widgets/GraphView.h"
#include "menus/DisassemblyContextMenu.h"
@ -222,6 +223,8 @@ private:
QAction actionExportGraph;
QAction actionSyncOffset;
QLabel *emptyText = nullptr;
};
#endif // DISASSEMBLERGRAPHVIEW_H