Commit c2ec9257 authored by ck's avatar ck
Browse files

BinEditor: Add "jump to address" functionality.

Task-number: QTCREATORBUG-1607
parent 07c83490
...@@ -439,6 +439,7 @@ void BinEditor::setLazyData(quint64 startAddr, int range, int blockSize) ...@@ -439,6 +439,7 @@ void BinEditor::setLazyData(quint64 startAddr, int range, int blockSize)
init(); init();
setCursorPosition(startAddr - m_baseAddr); setCursorPosition(startAddr - m_baseAddr);
viewport()->update();
} }
void BinEditor::resizeEvent(QResizeEvent *) void BinEditor::resizeEvent(QResizeEvent *)
...@@ -926,11 +927,6 @@ int BinEditor::cursorPosition() const ...@@ -926,11 +927,6 @@ int BinEditor::cursorPosition() const
void BinEditor::setCursorPosition(int pos, MoveMode moveMode) void BinEditor::setCursorPosition(int pos, MoveMode moveMode)
{ {
pos = qMin(m_size-1, qMax(0, pos)); pos = qMin(m_size-1, qMax(0, pos));
if (pos == m_cursorPosition
&& (m_anchorPosition == m_cursorPosition || moveMode == KeepAnchor)
&& !m_lowNibble)
return;
int oldCursorPosition = m_cursorPosition; int oldCursorPosition = m_cursorPosition;
bool hasSelection = m_anchorPosition != m_cursorPosition; bool hasSelection = m_anchorPosition != m_cursorPosition;
......
...@@ -85,6 +85,7 @@ public: ...@@ -85,6 +85,7 @@ public:
int cursorPosition() const; int cursorPosition() const;
void setCursorPosition(int pos, MoveMode moveMode = MoveAnchor); void setCursorPosition(int pos, MoveMode moveMode = MoveAnchor);
void jumpToAddress(quint64 address);
void setModified(bool); void setModified(bool);
bool isModified() const; bool isModified() const;
...@@ -212,7 +213,6 @@ private: ...@@ -212,7 +213,6 @@ private:
void setupJumpToMenuAction(QMenu *menu, QAction *actionHere, QAction *actionNew, void setupJumpToMenuAction(QMenu *menu, QAction *actionHere, QAction *actionNew,
quint64 addr); quint64 addr);
void jumpToAddress(quint64 address);
struct BinEditorEditCommand { struct BinEditorEditCommand {
int position; int position;
......
...@@ -36,10 +36,13 @@ ...@@ -36,10 +36,13 @@
#include <QtCore/QFile> #include <QtCore/QFile>
#include <QtCore/QFileInfo> #include <QtCore/QFileInfo>
#include <QtCore/QDebug> #include <QtCore/QDebug>
#include <QtCore/QRegExp>
#include <QtGui/QMenu> #include <QtGui/QMenu>
#include <QtGui/QAction> #include <QtGui/QAction>
#include <QtGui/QMainWindow> #include <QtGui/QMainWindow>
#include <QtGui/QHBoxLayout> #include <QtGui/QHBoxLayout>
#include <QtGui/QLineEdit>
#include <QtGui/QRegExpValidator>
#include <QtGui/QToolBar> #include <QtGui/QToolBar>
#include <coreplugin/actionmanager/actionmanager.h> #include <coreplugin/actionmanager/actionmanager.h>
...@@ -54,7 +57,6 @@ ...@@ -54,7 +57,6 @@
#include <find/ifindsupport.h> #include <find/ifindsupport.h>
#include <texteditor/fontsettings.h> #include <texteditor/fontsettings.h>
#include <texteditor/texteditorsettings.h> #include <texteditor/texteditorsettings.h>
#include <utils/linecolumnlabel.h>
#include <utils/reloadpromptutils.h> #include <utils/reloadpromptutils.h>
using namespace BINEditor; using namespace BINEditor;
...@@ -301,21 +303,29 @@ public: ...@@ -301,21 +303,29 @@ public:
m_file = new BinEditorFile(m_editor); m_file = new BinEditorFile(m_editor);
m_context << uidm->uniqueIdentifier(Core::Constants::K_DEFAULT_BINARY_EDITOR_ID); m_context << uidm->uniqueIdentifier(Core::Constants::K_DEFAULT_BINARY_EDITOR_ID);
m_context << uidm->uniqueIdentifier(Constants::C_BINEDITOR); m_context << uidm->uniqueIdentifier(Constants::C_BINEDITOR);
m_cursorPositionLabel = new Utils::LineColumnLabel; m_addressEdit = new QLineEdit;
QRegExpValidator * const addressValidator
= new QRegExpValidator(QRegExp(QLatin1String("[0-9a-fA-F]{1,16}")),
m_addressEdit);
m_addressEdit->setValidator(addressValidator);
QHBoxLayout *l = new QHBoxLayout; QHBoxLayout *l = new QHBoxLayout;
QWidget *w = new QWidget; QWidget *w = new QWidget;
l->setMargin(0); l->setMargin(0);
l->setContentsMargins(0, 0, 5, 0); l->setContentsMargins(0, 0, 5, 0);
l->addStretch(1); l->addStretch(1);
l->addWidget(m_cursorPositionLabel); l->addWidget(m_addressEdit);
w->setLayout(l); w->setLayout(l);
m_toolBar = new QToolBar; m_toolBar = new QToolBar;
m_toolBar->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); m_toolBar->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
m_toolBar->addWidget(w); m_toolBar->addWidget(w);
connect(m_editor, SIGNAL(cursorPositionChanged(int)), this, SLOT(updateCursorPosition(int))); connect(m_editor, SIGNAL(cursorPositionChanged(int)), this,
SLOT(updateCursorPosition(int)));
connect(m_addressEdit, SIGNAL(editingFinished()), this,
SLOT(jumpToAddress()));
updateCursorPosition(m_editor->cursorPosition());
} }
~BinEditorInterface() { ~BinEditorInterface() {
delete m_editor; delete m_editor;
...@@ -348,10 +358,14 @@ public: ...@@ -348,10 +358,14 @@ public:
bool isTemporary() const { return false; } bool isTemporary() const { return false; }
public slots: private slots:
void updateCursorPosition(int position) { void updateCursorPosition(int position) {
m_cursorPositionLabel->setText(m_editor->addressString(m_editor->baseAddress() + position), m_addressEdit->setText(QString::number(m_editor->baseAddress() + position, 16));
m_editor->addressString(m_editor->baseAddress() + m_editor->data().size())); }
void jumpToAddress() {
m_editor->jumpToAddress(m_addressEdit->text().toULongLong(0, 16));
updateCursorPosition(m_editor->cursorPosition());
} }
private: private:
...@@ -360,7 +374,7 @@ private: ...@@ -360,7 +374,7 @@ private:
BinEditorFile *m_file; BinEditorFile *m_file;
QList<int> m_context; QList<int> m_context;
QToolBar *m_toolBar; QToolBar *m_toolBar;
Utils::LineColumnLabel *m_cursorPositionLabel; QLineEdit *m_addressEdit;
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment