Ticket #4046: 0001-DiskProbe-Make-block-offset-and-file-offset-editable.patch

File 0001-DiskProbe-Make-block-offset-and-file-offset-editable.patch, 7.2 KB (added by TwoFx, 9 years ago)
  • src/apps/diskprobe/ProbeView.cpp

    From 7f6226e52884b13e7b24ed5c53da7bdfd51ea147 Mon Sep 17 00:00:00 2001
    From: Markus Himmel <markus@himmel-villmar.de>
    Date: Thu, 1 Jan 2015 19:51:25 +0000
    Subject: [PATCH] DiskProbe: Make block offset and file offset editable
    
    Fix #4046
    ---
     src/apps/diskprobe/ProbeView.cpp | 79 ++++++++++++++++++++++++++++------------
     1 file changed, 55 insertions(+), 24 deletions(-)
    
    diff --git a/src/apps/diskprobe/ProbeView.cpp b/src/apps/diskprobe/ProbeView.cpp
    index e0a7a4c..1a4e2e4 100644
    a b class HeaderView : public BGridView, public BInvoker {  
    131131        base_type Base() const { return fBase; }
    132132        void SetBase(base_type);
    133133
    134         off_t CursorOffset() const { return fOffset; }
     134        off_t CursorOffset() const { return fPosition % fBlockSize; }
    135135        off_t Position() const { return fPosition; }
    136136        uint32 BlockSize() const { return fBlockSize; }
    137137        void SetTo(off_t position, uint32 blockSize);
    class HeaderView : public BGridView, public BInvoker {  
    148148        const char      *fAttribute;
    149149        off_t           fFileSize;
    150150        uint32          fBlockSize;
    151         off_t           fOffset;
    152151        base_type       fBase;
    153152        off_t           fPosition;
    154153        off_t           fLastPosition;
    class HeaderView : public BGridView, public BInvoker {  
    157156        BTextControl    *fPositionControl;
    158157        BStringView     *fPathView;
    159158        BStringView     *fSizeView;
    160         BStringView     *fOffsetView;
    161         BStringView     *fFileOffsetView;
     159        BTextControl    *fOffsetControl;
     160        BTextControl    *fFileOffsetControl;
    162161        PositionSlider  *fPositionSlider;
    163162        IconView        *fIconView;
    164163        BButton         *fStopButton;
    HeaderView::HeaderView(const entry_ref *ref, DataEditor &editor)  
    477476    fAttribute(editor.Attribute()),
    478477    fFileSize(editor.FileSize()),
    479478    fBlockSize(editor.BlockSize()),
    480     fOffset(0),
    481479    fBase(kHexBase),
    482480    fPosition(0),
    483481    fLastPosition(0)
    HeaderView::HeaderView(const entry_ref *ref, DataEditor &editor)  
    551549    stringView->SetFont(&boldFont);
    552550    line->AddChild(stringView);
    553551
     552    BMessage* msg = new BMessage(kMsgPositionUpdate);
     553    msg->AddBool("fPositionControl", true);
    554554        // BTextControl oddities
    555     fPositionControl = new BTextControl(B_EMPTY_STRING, NULL, "0x0",
    556         new BMessage(kMsgPositionUpdate));
     555    fPositionControl = new BTextControl(B_EMPTY_STRING, NULL, "0x0", msg);
    557556    fPositionControl->SetDivider(0.0);
    558557    fPositionControl->SetFont(&plainFont);
    559558    fPositionControl->TextView()->SetFontAndColor(&plainFont);
    560     fPositionControl->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT);
     559    fPositionControl->SetAlignment(B_ALIGN_LEFT, B_ALIGN_LEFT);
    561560    line->AddChild(fPositionControl);
    562561
    563562    fSizeView = new BStringView(B_EMPTY_STRING, B_TRANSLATE_COMMENT("of "
    HeaderView::HeaderView(const entry_ref *ref, DataEditor &editor)  
    572571    stringView->SetFont(&boldFont);
    573572    line->AddChild(stringView);
    574573
    575     fOffsetView = new BStringView(B_EMPTY_STRING, "0x0");
    576     fOffsetView->SetFont(&plainFont);
    577     line->AddChild(fOffsetView);
     574    msg = new BMessage(kMsgPositionUpdate);
     575    msg->AddBool("fOffsetControl", false);
     576    fOffsetControl = new BTextControl(B_EMPTY_STRING, NULL, "0x0", msg);
     577    fOffsetControl->SetDivider(0.0);
     578    fOffsetControl->SetFont(&plainFont);
     579    fOffsetControl->TextView()->SetFontAndColor(&plainFont);
     580    fOffsetControl->SetAlignment(B_ALIGN_LEFT, B_ALIGN_LEFT);
     581    line->AddChild(fOffsetControl);
    578582    UpdateOffsetViews(false);
    579583
    580584    stringView = new BStringView(B_EMPTY_STRING, editor.IsAttribute()
    HeaderView::HeaderView(const entry_ref *ref, DataEditor &editor)  
    583587    stringView->SetFont(&boldFont);
    584588    line->AddChild(stringView);
    585589
    586     fFileOffsetView = new BStringView(B_EMPTY_STRING, "0x0");
    587     fFileOffsetView->SetFont(&plainFont);
    588     line->AddChild(fFileOffsetView);
     590    msg = new BMessage(kMsgPositionUpdate);
     591    msg->AddBool("fFileOffsetControl", false);
     592    fFileOffsetControl = new BTextControl(B_EMPTY_STRING, NULL, "0x0", msg);
     593    fFileOffsetControl->SetDivider(0.0);
     594    fFileOffsetControl->SetFont(&plainFont);
     595    fFileOffsetControl->TextView()->SetFontAndColor(&plainFont);
     596    fFileOffsetControl->SetAlignment(B_ALIGN_LEFT, B_ALIGN_LEFT);
     597    line->AddChild(fFileOffsetControl);
    589598
    590599    BGroupLayoutBuilder(line).AddGlue();
    591600
    HeaderView::AttachedToWindow()  
    609618
    610619    fStopButton->SetTarget(Parent());
    611620    fPositionControl->SetTarget(this);
     621    fOffsetControl->SetTarget(this);
     622    fFileOffsetControl->SetTarget(this);
    612623    fPositionSlider->SetTarget(this);
    613624
    614625    BMessage *message;
    HeaderView::UpdatePositionViews(bool all)  
    660671    fPositionControl->SetText(buffer);
    661672
    662673    if (all) {
    663         FormatValue(buffer, sizeof(buffer), fPosition + fOffset);
    664         fFileOffsetView->SetText(buffer);
     674        FormatValue(buffer, sizeof(buffer), fPosition);
     675        fFileOffsetControl->SetText(buffer);
    665676    }
    666677}
    667678
    void  
    670681HeaderView::UpdateOffsetViews(bool all)
    671682{
    672683    char buffer[64];
    673     FormatValue(buffer, sizeof(buffer), fOffset);
    674     fOffsetView->SetText(buffer);
     684    FormatValue(buffer, sizeof(buffer), fPosition % fBlockSize);
     685    fOffsetControl->SetText(buffer);
    675686
    676687    if (all) {
    677         FormatValue(buffer, sizeof(buffer), fPosition + fOffset);
    678         fFileOffsetView->SetText(buffer);
     688        FormatValue(buffer, sizeof(buffer), fPosition);
     689        fFileOffsetControl->SetText(buffer);
    679690    }
    680691}
    681692
    HeaderView::MessageReceived(BMessage *message)  
    743754                case kDataViewCursorPosition:
    744755                    off_t offset;
    745756                    if (message->FindInt64("position", &offset) == B_OK) {
    746                         fOffset = offset;
     757                        fPosition = (fPosition / fBlockSize) * fBlockSize
     758                            + offset;
    747759                        UpdateOffsetViews();
    748760                    }
    749761                    break;
    HeaderView::MessageReceived(BMessage *message)  
    810822
    811823            off_t position;
    812824            int32 delta;
     825            bool round = true;
    813826            if (message->FindInt64("position", &position) == B_OK)
    814827                fPosition = position;
    815828            else if (message->FindInt64("block", &position) == B_OK) {
    HeaderView::MessageReceived(BMessage *message)  
    822835                try {
    823836                    ExpressionParser parser;
    824837                    parser.SetSupportHexInput(true);
    825                     fPosition = parser.EvaluateToInt64(
    826                         fPositionControl->Text()) * fBlockSize;
     838                    if (message->FindBool("fPositionControl", &round)
     839                        == B_OK) {
     840                        fPosition = parser.EvaluateToInt64(
     841                            fPositionControl->Text()) * fBlockSize;
     842                    } else if (message->FindBool("fOffsetControl", &round)
     843                    == B_OK) {
     844                        fPosition = (fPosition / fBlockSize) * fBlockSize +
     845                            parser.EvaluateToInt64(fOffsetControl->Text());
     846                    } else if (message->FindBool("fFileOffsetControl", &round)
     847                        == B_OK) {
     848                        fPosition = parser.EvaluateToInt64(
     849                            fFileOffsetControl->Text());
     850                    }
    827851                } catch (...) {
    828852                    beep();
    829853                    break;
    HeaderView::MessageReceived(BMessage *message)  
    831855            }
    832856
    833857            fLastPosition = lastPosition;
    834             fPosition = (fPosition / fBlockSize) * fBlockSize;
     858
     859            if (round)
     860                fPosition = (fPosition / fBlockSize) * fBlockSize;
    835861                // round to block size
    836862
    837863            if (fPosition < 0)
    EditorLooper::MessageReceived(BMessage *message)  
    9751001            if (message->FindInt64("position", &position) == B_OK) {
    9761002                BAutolock locker(fEditor);
    9771003                fEditor.SetViewOffset(position);
     1004
     1005                BMessage message(kMsgSetSelection);
     1006                message.AddInt64("start", position - fEditor.ViewOffset());
     1007                message.AddInt64("end", position - fEditor.ViewOffset());
     1008                fMessenger.SendMessage(&message);
    9781009            }
    9791010            break;
    9801011        }