Commit ce6460e2 authored by ck's avatar ck
Browse files

BinEditor: Implement "Jump to start/end of file" for lazy data.

parent 36427718
......@@ -1042,7 +1042,7 @@ bool BinEditor::event(QEvent *e) {
selEnd = selStart + 1;
byteCount = 1;
}
if (byteCount <= 8) {
if (m_hexCursor && byteCount <= 8) {
const QPoint &startPoint = offsetToPos(selStart);
const QPoint &endPoint = offsetToPos(selEnd);
const QPoint expandedEndPoint
......@@ -1138,14 +1138,25 @@ void BinEditor::keyPressEvent(QKeyEvent *e)
} break;
case Qt::Key_Home:
setCursorPosition((e->modifiers() & Qt::ControlModifier) ?
0 : (m_cursorPosition/16 * 16), moveMode);
if (e->modifiers() & Qt::ControlModifier) {
if (m_inLazyMode)
emit startOfFileRequested(editorInterface());
else
setCursorPosition(0);
} else {
setCursorPosition(m_cursorPosition/16 * 16, moveMode);
}
break;
case Qt::Key_End:
setCursorPosition((e->modifiers() & Qt::ControlModifier) ?
(m_size-1) : (m_cursorPosition/16 * 16 + 15), moveMode);
if (e->modifiers() & Qt::ControlModifier) {
if (m_inLazyMode)
emit endOfFileRequested(editorInterface());
else
setCursorPosition(m_size - 1);
} else {
setCursorPosition(m_cursorPosition/16 * 16 + 15, moveMode);
}
break;
default:
if (m_readOnly)
break;
......@@ -1380,7 +1391,7 @@ void BinEditor::jumpToAddress(quint64 address)
{
if (address >= m_baseAddr && address < m_baseAddr + m_data.size())
setCursorPosition(address - m_baseAddr);
else
else if (m_inLazyMode)
emit newRangeRequested(editorInterface(), address);
}
......@@ -1392,7 +1403,7 @@ void BinEditor::setNewWindowRequestAllowed()
QPoint BinEditor::offsetToPos(int offset)
{
const int x = m_labelWidth + (offset % 16) * m_columnWidth;
const int y = (offset / 16) * m_lineHeight;
const int y = (offset / 16 - verticalScrollBar()->value()) * m_lineHeight;
return QPoint(x, y);
}
......
......@@ -84,7 +84,7 @@ public:
};
int cursorPosition() const;
void setCursorPosition(int pos, MoveMode moveMode = MoveAnchor);
Q_INVOKABLE void setCursorPosition(int pos, MoveMode moveMode = MoveAnchor);
void jumpToAddress(quint64 address);
void setModified(bool);
......@@ -133,6 +133,8 @@ Q_SIGNALS:
void lazyDataRequested(Core::IEditor *editor, quint64 block, bool synchronous);
void newWindowRequested(quint64 address);
void newRangeRequested(Core::IEditor *, quint64 address);
void startOfFileRequested(Core::IEditor *);
void endOfFileRequested(Core::IEditor *);
protected:
void scrollContentsBy(int dx, int dy);
......
......@@ -183,6 +183,10 @@ public:
this, SLOT(provideData(Core::IEditor *, quint64)));
connect(m_editor, SIGNAL(newRangeRequested(Core::IEditor*,quint64)),
this, SLOT(provideNewRange(Core::IEditor*,quint64)));
connect(m_editor, SIGNAL(startOfFileRequested(Core::IEditor*)), this,
SLOT(handleStartOfFileRequested(Core::IEditor*)));
connect(m_editor, SIGNAL(endOfFileRequested(Core::IEditor*)), this,
SLOT(handleEndOfFileRequested(Core::IEditor*)));
}
~BinEditorFile() {}
......@@ -206,7 +210,7 @@ public:
&& file.open(QIODevice::ReadOnly)) {
m_fileName = fileName;
qint64 maxRange = 64 * 1024 * 1024;
if (file.isSequential() && file.size() <= maxRange) {
if (file.size() <= maxRange) {
m_editor->setData(file.readAll());
} else {
m_editor->setLazyData(offset, maxRange);
......@@ -238,6 +242,14 @@ private slots:
open(m_fileName, offset);
}
void handleStartOfFileRequested(Core::IEditor *) {
open(m_fileName, 0);
}
void handleEndOfFileRequested(Core::IEditor *) {
open(m_fileName, QFileInfo(m_fileName).size() - 1);
}
public:
void setFilename(const QString &filename) {
......
......@@ -46,6 +46,7 @@
#include <utils/qtcassert.h>
#include <QtCore/QDebug>
#include <QtCore/QMetaObject>
#include <QtGui/QMessageBox>
#include <QtGui/QPlainTextEdit>
......@@ -71,6 +72,8 @@ namespace Internal {
it handles communication between the engine and the bineditor.
*/
namespace { const int DataRange = 1024 * 1024; }
MemoryViewAgent::MemoryViewAgent(DebuggerManager *manager, quint64 addr)
: QObject(manager), m_engine(manager->currentEngine()), m_manager(manager)
{
......@@ -108,11 +111,15 @@ void MemoryViewAgent::createBinEditor(quint64 addr)
connect(editor->widget(),
SIGNAL(newRangeRequested(Core::IEditor *, quint64)), this,
SLOT(provideNewRange(Core::IEditor*,quint64)));
connect(editor->widget(), SIGNAL(startOfFileRequested(Core::IEditor *)),
this, SLOT(handleStartOfFileRequested(Core::IEditor*)));
connect(editor->widget(), SIGNAL(endOfFileRequested(Core::IEditor *)),
this, SLOT(handleEndOfFileRequested(Core::IEditor*)));
m_editors << editor;
editorManager->activateEditor(editor);
QMetaObject::invokeMethod(editor->widget(), "setNewWindowRequestAllowed");
QMetaObject::invokeMethod(editor->widget(), "setLazyData",
Q_ARG(quint64, addr), Q_ARG(int, 1024 * 1024), Q_ARG(int, BinBlockSize));
Q_ARG(quint64, addr), Q_ARG(int, DataRange), Q_ARG(int, BinBlockSize));
} else {
m_manager->showMessageBox(QMessageBox::Warning,
tr("No memory viewer available"),
......@@ -143,10 +150,26 @@ void MemoryViewAgent::addLazyData(QObject *editorToken, quint64 addr,
void MemoryViewAgent::provideNewRange(Core::IEditor *editor, quint64 address)
{
QMetaObject::invokeMethod(editor->widget(), "setLazyData",
Q_ARG(quint64, address), Q_ARG(int, 1024 * 1024),
Q_ARG(quint64, address), Q_ARG(int, DataRange),
Q_ARG(int, BinBlockSize));
}
// Since we are not dealing with files, we take these signals to mean
// "move to start/end of range". This seems to make more sense than
// jumping to the start or end of the address space, respectively.
void MemoryViewAgent::handleStartOfFileRequested(Core::IEditor *editor)
{
QMetaObject::invokeMethod(editor->widget(),
"setCursorPosition", Q_ARG(int, 0));
}
void MemoryViewAgent::handleEndOfFileRequested(Core::IEditor *editor)
{
QMetaObject::invokeMethod(editor->widget(),
"setCursorPosition", Q_ARG(int, DataRange - 1));
}
///////////////////////////////////////////////////////////////////////
//
......
......@@ -64,6 +64,8 @@ private:
Q_SLOT void createBinEditor(quint64 startAddr);
Q_SLOT void fetchLazyData(Core::IEditor *, quint64 block, bool sync);
Q_SLOT void provideNewRange(Core::IEditor *editor, quint64 address);
Q_SLOT void handleStartOfFileRequested(Core::IEditor *editor);
Q_SLOT void handleEndOfFileRequested(Core::IEditor *editor);
QPointer<IDebuggerEngine> m_engine;
QList<QPointer<Core::IEditor> > m_editors;
......
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