DiskProbe: Make block offset and file offset editable
Fix #4046 Signed-off-by: François Revol <[email protected]> GCI2014 task https://www.google-melange.com/gci/task/view/google/gci2014/5488784896425984
This commit is contained in:
committed by
François Revol
parent
d35b138450
commit
ef69f5d941
@@ -131,7 +131,7 @@ class HeaderView : public BGridView, public BInvoker {
|
|||||||
base_type Base() const { return fBase; }
|
base_type Base() const { return fBase; }
|
||||||
void SetBase(base_type);
|
void SetBase(base_type);
|
||||||
|
|
||||||
off_t CursorOffset() const { return fOffset; }
|
off_t CursorOffset() const { return fPosition % fBlockSize; }
|
||||||
off_t Position() const { return fPosition; }
|
off_t Position() const { return fPosition; }
|
||||||
uint32 BlockSize() const { return fBlockSize; }
|
uint32 BlockSize() const { return fBlockSize; }
|
||||||
void SetTo(off_t position, uint32 blockSize);
|
void SetTo(off_t position, uint32 blockSize);
|
||||||
@@ -148,7 +148,6 @@ class HeaderView : public BGridView, public BInvoker {
|
|||||||
const char *fAttribute;
|
const char *fAttribute;
|
||||||
off_t fFileSize;
|
off_t fFileSize;
|
||||||
uint32 fBlockSize;
|
uint32 fBlockSize;
|
||||||
off_t fOffset;
|
|
||||||
base_type fBase;
|
base_type fBase;
|
||||||
off_t fPosition;
|
off_t fPosition;
|
||||||
off_t fLastPosition;
|
off_t fLastPosition;
|
||||||
@@ -157,8 +156,8 @@ class HeaderView : public BGridView, public BInvoker {
|
|||||||
BTextControl *fPositionControl;
|
BTextControl *fPositionControl;
|
||||||
BStringView *fPathView;
|
BStringView *fPathView;
|
||||||
BStringView *fSizeView;
|
BStringView *fSizeView;
|
||||||
BStringView *fOffsetView;
|
BTextControl *fOffsetControl;
|
||||||
BStringView *fFileOffsetView;
|
BTextControl *fFileOffsetControl;
|
||||||
PositionSlider *fPositionSlider;
|
PositionSlider *fPositionSlider;
|
||||||
IconView *fIconView;
|
IconView *fIconView;
|
||||||
BButton *fStopButton;
|
BButton *fStopButton;
|
||||||
@@ -477,7 +476,6 @@ HeaderView::HeaderView(const entry_ref *ref, DataEditor &editor)
|
|||||||
fAttribute(editor.Attribute()),
|
fAttribute(editor.Attribute()),
|
||||||
fFileSize(editor.FileSize()),
|
fFileSize(editor.FileSize()),
|
||||||
fBlockSize(editor.BlockSize()),
|
fBlockSize(editor.BlockSize()),
|
||||||
fOffset(0),
|
|
||||||
fBase(kHexBase),
|
fBase(kHexBase),
|
||||||
fPosition(0),
|
fPosition(0),
|
||||||
fLastPosition(0)
|
fLastPosition(0)
|
||||||
@@ -551,13 +549,14 @@ HeaderView::HeaderView(const entry_ref *ref, DataEditor &editor)
|
|||||||
stringView->SetFont(&boldFont);
|
stringView->SetFont(&boldFont);
|
||||||
line->AddChild(stringView);
|
line->AddChild(stringView);
|
||||||
|
|
||||||
|
BMessage* msg = new BMessage(kMsgPositionUpdate);
|
||||||
|
msg->AddBool("fPositionControl", true);
|
||||||
// BTextControl oddities
|
// BTextControl oddities
|
||||||
fPositionControl = new BTextControl(B_EMPTY_STRING, NULL, "0x0",
|
fPositionControl = new BTextControl(B_EMPTY_STRING, NULL, "0x0", msg);
|
||||||
new BMessage(kMsgPositionUpdate));
|
|
||||||
fPositionControl->SetDivider(0.0);
|
fPositionControl->SetDivider(0.0);
|
||||||
fPositionControl->SetFont(&plainFont);
|
fPositionControl->SetFont(&plainFont);
|
||||||
fPositionControl->TextView()->SetFontAndColor(&plainFont);
|
fPositionControl->TextView()->SetFontAndColor(&plainFont);
|
||||||
fPositionControl->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT);
|
fPositionControl->SetAlignment(B_ALIGN_LEFT, B_ALIGN_LEFT);
|
||||||
line->AddChild(fPositionControl);
|
line->AddChild(fPositionControl);
|
||||||
|
|
||||||
fSizeView = new BStringView(B_EMPTY_STRING, B_TRANSLATE_COMMENT("of "
|
fSizeView = new BStringView(B_EMPTY_STRING, B_TRANSLATE_COMMENT("of "
|
||||||
@@ -572,9 +571,14 @@ HeaderView::HeaderView(const entry_ref *ref, DataEditor &editor)
|
|||||||
stringView->SetFont(&boldFont);
|
stringView->SetFont(&boldFont);
|
||||||
line->AddChild(stringView);
|
line->AddChild(stringView);
|
||||||
|
|
||||||
fOffsetView = new BStringView(B_EMPTY_STRING, "0x0");
|
msg = new BMessage(kMsgPositionUpdate);
|
||||||
fOffsetView->SetFont(&plainFont);
|
msg->AddBool("fOffsetControl", false);
|
||||||
line->AddChild(fOffsetView);
|
fOffsetControl = new BTextControl(B_EMPTY_STRING, NULL, "0x0", msg);
|
||||||
|
fOffsetControl->SetDivider(0.0);
|
||||||
|
fOffsetControl->SetFont(&plainFont);
|
||||||
|
fOffsetControl->TextView()->SetFontAndColor(&plainFont);
|
||||||
|
fOffsetControl->SetAlignment(B_ALIGN_LEFT, B_ALIGN_LEFT);
|
||||||
|
line->AddChild(fOffsetControl);
|
||||||
UpdateOffsetViews(false);
|
UpdateOffsetViews(false);
|
||||||
|
|
||||||
stringView = new BStringView(B_EMPTY_STRING, editor.IsAttribute()
|
stringView = new BStringView(B_EMPTY_STRING, editor.IsAttribute()
|
||||||
@@ -583,9 +587,14 @@ HeaderView::HeaderView(const entry_ref *ref, DataEditor &editor)
|
|||||||
stringView->SetFont(&boldFont);
|
stringView->SetFont(&boldFont);
|
||||||
line->AddChild(stringView);
|
line->AddChild(stringView);
|
||||||
|
|
||||||
fFileOffsetView = new BStringView(B_EMPTY_STRING, "0x0");
|
msg = new BMessage(kMsgPositionUpdate);
|
||||||
fFileOffsetView->SetFont(&plainFont);
|
msg->AddBool("fFileOffsetControl", false);
|
||||||
line->AddChild(fFileOffsetView);
|
fFileOffsetControl = new BTextControl(B_EMPTY_STRING, NULL, "0x0", msg);
|
||||||
|
fFileOffsetControl->SetDivider(0.0);
|
||||||
|
fFileOffsetControl->SetFont(&plainFont);
|
||||||
|
fFileOffsetControl->TextView()->SetFontAndColor(&plainFont);
|
||||||
|
fFileOffsetControl->SetAlignment(B_ALIGN_LEFT, B_ALIGN_LEFT);
|
||||||
|
line->AddChild(fFileOffsetControl);
|
||||||
|
|
||||||
BGroupLayoutBuilder(line).AddGlue();
|
BGroupLayoutBuilder(line).AddGlue();
|
||||||
|
|
||||||
@@ -609,6 +618,8 @@ HeaderView::AttachedToWindow()
|
|||||||
|
|
||||||
fStopButton->SetTarget(Parent());
|
fStopButton->SetTarget(Parent());
|
||||||
fPositionControl->SetTarget(this);
|
fPositionControl->SetTarget(this);
|
||||||
|
fOffsetControl->SetTarget(this);
|
||||||
|
fFileOffsetControl->SetTarget(this);
|
||||||
fPositionSlider->SetTarget(this);
|
fPositionSlider->SetTarget(this);
|
||||||
|
|
||||||
BMessage *message;
|
BMessage *message;
|
||||||
@@ -660,8 +671,8 @@ HeaderView::UpdatePositionViews(bool all)
|
|||||||
fPositionControl->SetText(buffer);
|
fPositionControl->SetText(buffer);
|
||||||
|
|
||||||
if (all) {
|
if (all) {
|
||||||
FormatValue(buffer, sizeof(buffer), fPosition + fOffset);
|
FormatValue(buffer, sizeof(buffer), fPosition);
|
||||||
fFileOffsetView->SetText(buffer);
|
fFileOffsetControl->SetText(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -670,12 +681,12 @@ void
|
|||||||
HeaderView::UpdateOffsetViews(bool all)
|
HeaderView::UpdateOffsetViews(bool all)
|
||||||
{
|
{
|
||||||
char buffer[64];
|
char buffer[64];
|
||||||
FormatValue(buffer, sizeof(buffer), fOffset);
|
FormatValue(buffer, sizeof(buffer), fPosition % fBlockSize);
|
||||||
fOffsetView->SetText(buffer);
|
fOffsetControl->SetText(buffer);
|
||||||
|
|
||||||
if (all) {
|
if (all) {
|
||||||
FormatValue(buffer, sizeof(buffer), fPosition + fOffset);
|
FormatValue(buffer, sizeof(buffer), fPosition);
|
||||||
fFileOffsetView->SetText(buffer);
|
fFileOffsetControl->SetText(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -743,7 +754,8 @@ HeaderView::MessageReceived(BMessage *message)
|
|||||||
case kDataViewCursorPosition:
|
case kDataViewCursorPosition:
|
||||||
off_t offset;
|
off_t offset;
|
||||||
if (message->FindInt64("position", &offset) == B_OK) {
|
if (message->FindInt64("position", &offset) == B_OK) {
|
||||||
fOffset = offset;
|
fPosition = (fPosition / fBlockSize) * fBlockSize
|
||||||
|
+ offset;
|
||||||
UpdateOffsetViews();
|
UpdateOffsetViews();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -810,6 +822,7 @@ HeaderView::MessageReceived(BMessage *message)
|
|||||||
|
|
||||||
off_t position;
|
off_t position;
|
||||||
int32 delta;
|
int32 delta;
|
||||||
|
bool round = true;
|
||||||
if (message->FindInt64("position", &position) == B_OK)
|
if (message->FindInt64("position", &position) == B_OK)
|
||||||
fPosition = position;
|
fPosition = position;
|
||||||
else if (message->FindInt64("block", &position) == B_OK) {
|
else if (message->FindInt64("block", &position) == B_OK) {
|
||||||
@@ -822,8 +835,19 @@ HeaderView::MessageReceived(BMessage *message)
|
|||||||
try {
|
try {
|
||||||
ExpressionParser parser;
|
ExpressionParser parser;
|
||||||
parser.SetSupportHexInput(true);
|
parser.SetSupportHexInput(true);
|
||||||
fPosition = parser.EvaluateToInt64(
|
if (message->FindBool("fPositionControl", &round)
|
||||||
fPositionControl->Text()) * fBlockSize;
|
== B_OK) {
|
||||||
|
fPosition = parser.EvaluateToInt64(
|
||||||
|
fPositionControl->Text()) * fBlockSize;
|
||||||
|
} else if (message->FindBool("fOffsetControl", &round)
|
||||||
|
== B_OK) {
|
||||||
|
fPosition = (fPosition / fBlockSize) * fBlockSize +
|
||||||
|
parser.EvaluateToInt64(fOffsetControl->Text());
|
||||||
|
} else if (message->FindBool("fFileOffsetControl", &round)
|
||||||
|
== B_OK) {
|
||||||
|
fPosition = parser.EvaluateToInt64(
|
||||||
|
fFileOffsetControl->Text());
|
||||||
|
}
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
beep();
|
beep();
|
||||||
break;
|
break;
|
||||||
@@ -831,7 +855,9 @@ HeaderView::MessageReceived(BMessage *message)
|
|||||||
}
|
}
|
||||||
|
|
||||||
fLastPosition = lastPosition;
|
fLastPosition = lastPosition;
|
||||||
fPosition = (fPosition / fBlockSize) * fBlockSize;
|
|
||||||
|
if (round)
|
||||||
|
fPosition = (fPosition / fBlockSize) * fBlockSize;
|
||||||
// round to block size
|
// round to block size
|
||||||
|
|
||||||
if (fPosition < 0)
|
if (fPosition < 0)
|
||||||
@@ -975,6 +1001,11 @@ EditorLooper::MessageReceived(BMessage *message)
|
|||||||
if (message->FindInt64("position", &position) == B_OK) {
|
if (message->FindInt64("position", &position) == B_OK) {
|
||||||
BAutolock locker(fEditor);
|
BAutolock locker(fEditor);
|
||||||
fEditor.SetViewOffset(position);
|
fEditor.SetViewOffset(position);
|
||||||
|
|
||||||
|
BMessage message(kMsgSetSelection);
|
||||||
|
message.AddInt64("start", position - fEditor.ViewOffset());
|
||||||
|
message.AddInt64("end", position - fEditor.ViewOffset());
|
||||||
|
fMessenger.SendMessage(&message);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user