Ticket #10053: 0001-improved-find-and-replace-in-styleedit.patch

File 0001-improved-find-and-replace-in-styleedit.patch, 6.1 KB (added by Ezodev, 11 years ago)
  • src/apps/stylededit/FindWindow.cpp

    From 7dce4cc037006100e05799edd6408d79a432d426 Mon Sep 17 00:00:00 2001
    From: Ezo <ezo.dev@gmail.com>
    Date: Mon, 25 Nov 2013 19:34:40 +0000
    Subject: [PATCH] improved find and replace in styleedit
    
    ---
     src/apps/stylededit/FindWindow.cpp       | 12 ++++++--
     src/apps/stylededit/FindWindow.h         |  3 ++
     src/apps/stylededit/ReplaceWindow.cpp    | 11 +++++++-
     src/apps/stylededit/ReplaceWindow.h      |  3 ++
     src/apps/stylededit/StyledEditWindow.cpp | 48 +++++++++++++++++++++++++-------
     5 files changed, 64 insertions(+), 13 deletions(-)
    
    diff --git a/src/apps/stylededit/FindWindow.cpp b/src/apps/stylededit/FindWindow.cpp
    index 20187d7..29ba876 100644
    a b  
    2424
    2525#undef B_TRANSLATION_CONTEXT
    2626#define B_TRANSLATION_CONTEXT "FindandReplaceWindow"
    27 
     27bool FindWindow::alredyExist = false;
    2828
    2929FindWindow::FindWindow(BRect frame, BHandler* _handler, BString* searchString,
    3030    bool caseState, bool wrapState, bool backState)
    31     : BWindow(frame, "FindWindow", B_MODAL_WINDOW,
     31    : BWindow(frame, B_TRANSLATE("Find Window"), B_FLOATING_WINDOW,
    3232        B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS,
    3333        B_CURRENT_WORKSPACE)
    3434{
     35    alredyExist = true;
     36   
    3537    AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED));
    3638
    3739    fSearchString = new BTextControl("", B_TRANSLATE("Find:"), NULL, NULL);
    FindWindow::FindWindow(BRect frame, BHandler* _handler, BString* searchString,  
    7476}
    7577
    7678
     79FindWindow::~FindWindow()
     80{
     81    alredyExist = false;   
     82}
     83
     84
    7785void
    7886FindWindow::MessageReceived(BMessage* msg)
    7987{
  • src/apps/stylededit/FindWindow.h

    diff --git a/src/apps/stylededit/FindWindow.h b/src/apps/stylededit/FindWindow.h
    index e8720c8..966e474 100644
    a b class FindWindow : public BWindow {  
    2323                        FindWindow(BRect frame, BHandler* handler,
    2424                            BString* searchString, bool caseState,
    2525                            bool wrapState, bool backState);
     26                        ~FindWindow();
    2627
    2728        virtual void    MessageReceived(BMessage* message);
    2829        virtual void    DispatchMessage(BMessage* message, BHandler* handler);
     30       
     31        static bool     alredyExist;
    2932
    3033    private:
    3134        void            _SendMessage();
  • src/apps/stylededit/ReplaceWindow.cpp

    diff --git a/src/apps/stylededit/ReplaceWindow.cpp b/src/apps/stylededit/ReplaceWindow.cpp
    index 9b63c5b..bd5b562 100644
    a b  
    2727
    2828#undef B_TRANSLATION_CONTEXT
    2929#define B_TRANSLATION_CONTEXT "FindandReplaceWindow"
     30bool ReplaceWindow::alredyExist = false;
    3031
    3132ReplaceWindow::ReplaceWindow(BRect frame, BHandler* _handler,
    3233    BString* searchString,  BString* replaceString,
    3334    bool caseState, bool wrapState, bool backState)
    34     : BWindow(frame, "ReplaceWindow", B_MODAL_WINDOW,
     35    : BWindow(frame, B_TRANSLATE("Replace Window"), B_FLOATING_WINDOW,
    3536        B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS,
    3637        B_CURRENT_WORKSPACE)
    3738{
     39    alredyExist = true;
     40   
    3841    AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED));
    3942
    4043    fSearchString = new BTextControl("", B_TRANSLATE("Find:"), NULL, NULL);
    ReplaceWindow::ReplaceWindow(BRect frame, BHandler* _handler,  
    9295}
    9396
    9497
     98ReplaceWindow::~ReplaceWindow()
     99{
     100    alredyExist = false;
     101}
     102
     103
    95104void
    96105ReplaceWindow::MessageReceived(BMessage* msg)
    97106{
  • src/apps/stylededit/ReplaceWindow.h

    diff --git a/src/apps/stylededit/ReplaceWindow.h b/src/apps/stylededit/ReplaceWindow.h
    index ddcff4c..677fc9c 100644
    a b class ReplaceWindow : public BWindow {  
    2626                        ReplaceWindow(BRect frame, BHandler* _handler,
    2727                            BString* searchString, BString* replaceString,
    2828                            bool caseState, bool wrapState, bool backState);
     29                        ~ReplaceWindow();
    2930
    3031        virtual void    MessageReceived(BMessage* message);
    3132        virtual void    DispatchMessage(BMessage* message, BHandler* handler);
     33       
     34        static bool         alredyExist;
    3235
    3336    private:
    3437        void            _SendMessage(uint32 what);
  • src/apps/stylededit/StyledEditWindow.cpp

    diff --git a/src/apps/stylededit/StyledEditWindow.cpp b/src/apps/stylededit/StyledEditWindow.cpp
    index 4876e78..a31d881 100644
    a b StyledEditWindow::MessageReceived(BMessage* message)  
    235235            break;
    236236        case MENU_FIND:
    237237        {
    238             BRect findWindowFrame(100, 100, 400, 235);
    239             BWindow* window = new FindWindow(findWindowFrame, this,
    240                 &fStringToFind, fCaseSensitive, fWrapAround, fBackSearch);
    241             window->Show();
     238            if (!FindWindow::alredyExist) {
     239                BRect findWindowFrame(100, 100, 400, 235);
     240                BWindow* window = new FindWindow(findWindowFrame, this,
     241                    &fStringToFind, fCaseSensitive, fWrapAround, fBackSearch);
     242                window->Show();
     243            }
    242244            break;
    243245        }
    244246        case MSG_SEARCH:
    StyledEditWindow::_LoadAttrs()  
    13531355    }
    13541356
    13551357    // info about position of caret may live in the file attributes
    1356     int32 position = 0;
     1358    int32 position;
    13571359    if (documentNode.ReadAttr("be:caret_position", B_INT32_TYPE, 0,
    1358             &position, sizeof(position)) != sizeof(position))
    1359         position = 0;
    1360 
    1361     fTextView->Select(position, position);
    1362     fTextView->ScrollToOffset(position);
     1360            &position, sizeof(position)) == sizeof(position))
     1361    {
     1362        fTextView->Select(position, position);
     1363        fTextView->ScrollToOffset(position);
     1364    } else {   
     1365        fTextView->Select(0, 0);
     1366        fTextView->ScrollToOffset(0);
     1367    }
    13631368}
    13641369
    13651370
    StyledEditWindow::_Search(BString string, bool caseSensitive, bool wrap,  
    16691674        return true;
    16701675    }
    16711676
     1677    if ((start = viewText.FindFirst(string, 0)) == B_ERROR) {
     1678        BAlert* alert = new BAlert(B_TRANSLATE("Not found"),
     1679            B_TRANSLATE("Nothing was found in the entre file."),
     1680                B_TRANSLATE("Ok"));
     1681        alert->SetShortcut(0, B_ENTER);
     1682        alert->Go();
     1683    } else {
     1684        BAlert* alert = new BAlert(B_TRANSLATE("End of file"),
     1685            B_TRANSLATE("End of file reached. "
     1686                "Continue from the start of document?"),
     1687                B_TRANSLATE("Yes"), B_TRANSLATE("No"));
     1688        alert->SetShortcut(0, B_ENTER);
     1689        alert->SetShortcut(1, B_ESCAPE);
     1690        int32 answer = alert->Go();
     1691        if(answer == 0) {
     1692            finish = start + length;
     1693            fTextView->Select(start, finish);
     1694            if(scrollToOccurence)
     1695                fTextView->ScrollToSelection();
     1696        }
     1697        return true;
     1698    }
     1699   
    16721700    return false;
    16731701}
    16741702