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
|
|
24 | 24 | |
25 | 25 | #undef B_TRANSLATION_CONTEXT |
26 | 26 | #define B_TRANSLATION_CONTEXT "FindandReplaceWindow" |
27 | | |
| 27 | bool FindWindow::alredyExist = false; |
28 | 28 | |
29 | 29 | FindWindow::FindWindow(BRect frame, BHandler* _handler, BString* searchString, |
30 | 30 | bool caseState, bool wrapState, bool backState) |
31 | | : BWindow(frame, "FindWindow", B_MODAL_WINDOW, |
| 31 | : BWindow(frame, B_TRANSLATE("Find Window"), B_FLOATING_WINDOW, |
32 | 32 | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS, |
33 | 33 | B_CURRENT_WORKSPACE) |
34 | 34 | { |
| 35 | alredyExist = true; |
| 36 | |
35 | 37 | AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED)); |
36 | 38 | |
37 | 39 | fSearchString = new BTextControl("", B_TRANSLATE("Find:"), NULL, NULL); |
… |
… |
FindWindow::FindWindow(BRect frame, BHandler* _handler, BString* searchString,
|
74 | 76 | } |
75 | 77 | |
76 | 78 | |
| 79 | FindWindow::~FindWindow() |
| 80 | { |
| 81 | alredyExist = false; |
| 82 | } |
| 83 | |
| 84 | |
77 | 85 | void |
78 | 86 | FindWindow::MessageReceived(BMessage* msg) |
79 | 87 | { |
diff --git a/src/apps/stylededit/FindWindow.h b/src/apps/stylededit/FindWindow.h
index e8720c8..966e474 100644
a
|
b
|
class FindWindow : public BWindow {
|
23 | 23 | FindWindow(BRect frame, BHandler* handler, |
24 | 24 | BString* searchString, bool caseState, |
25 | 25 | bool wrapState, bool backState); |
| 26 | ~FindWindow(); |
26 | 27 | |
27 | 28 | virtual void MessageReceived(BMessage* message); |
28 | 29 | virtual void DispatchMessage(BMessage* message, BHandler* handler); |
| 30 | |
| 31 | static bool alredyExist; |
29 | 32 | |
30 | 33 | private: |
31 | 34 | void _SendMessage(); |
diff --git a/src/apps/stylededit/ReplaceWindow.cpp b/src/apps/stylededit/ReplaceWindow.cpp
index 9b63c5b..bd5b562 100644
a
|
b
|
|
27 | 27 | |
28 | 28 | #undef B_TRANSLATION_CONTEXT |
29 | 29 | #define B_TRANSLATION_CONTEXT "FindandReplaceWindow" |
| 30 | bool ReplaceWindow::alredyExist = false; |
30 | 31 | |
31 | 32 | ReplaceWindow::ReplaceWindow(BRect frame, BHandler* _handler, |
32 | 33 | BString* searchString, BString* replaceString, |
33 | 34 | bool caseState, bool wrapState, bool backState) |
34 | | : BWindow(frame, "ReplaceWindow", B_MODAL_WINDOW, |
| 35 | : BWindow(frame, B_TRANSLATE("Replace Window"), B_FLOATING_WINDOW, |
35 | 36 | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS, |
36 | 37 | B_CURRENT_WORKSPACE) |
37 | 38 | { |
| 39 | alredyExist = true; |
| 40 | |
38 | 41 | AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED)); |
39 | 42 | |
40 | 43 | fSearchString = new BTextControl("", B_TRANSLATE("Find:"), NULL, NULL); |
… |
… |
ReplaceWindow::ReplaceWindow(BRect frame, BHandler* _handler,
|
92 | 95 | } |
93 | 96 | |
94 | 97 | |
| 98 | ReplaceWindow::~ReplaceWindow() |
| 99 | { |
| 100 | alredyExist = false; |
| 101 | } |
| 102 | |
| 103 | |
95 | 104 | void |
96 | 105 | ReplaceWindow::MessageReceived(BMessage* msg) |
97 | 106 | { |
diff --git a/src/apps/stylededit/ReplaceWindow.h b/src/apps/stylededit/ReplaceWindow.h
index ddcff4c..677fc9c 100644
a
|
b
|
class ReplaceWindow : public BWindow {
|
26 | 26 | ReplaceWindow(BRect frame, BHandler* _handler, |
27 | 27 | BString* searchString, BString* replaceString, |
28 | 28 | bool caseState, bool wrapState, bool backState); |
| 29 | ~ReplaceWindow(); |
29 | 30 | |
30 | 31 | virtual void MessageReceived(BMessage* message); |
31 | 32 | virtual void DispatchMessage(BMessage* message, BHandler* handler); |
| 33 | |
| 34 | static bool alredyExist; |
32 | 35 | |
33 | 36 | private: |
34 | 37 | void _SendMessage(uint32 what); |
diff --git a/src/apps/stylededit/StyledEditWindow.cpp b/src/apps/stylededit/StyledEditWindow.cpp
index 4876e78..a31d881 100644
a
|
b
|
StyledEditWindow::MessageReceived(BMessage* message)
|
235 | 235 | break; |
236 | 236 | case MENU_FIND: |
237 | 237 | { |
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 | } |
242 | 244 | break; |
243 | 245 | } |
244 | 246 | case MSG_SEARCH: |
… |
… |
StyledEditWindow::_LoadAttrs()
|
1353 | 1355 | } |
1354 | 1356 | |
1355 | 1357 | // info about position of caret may live in the file attributes |
1356 | | int32 position = 0; |
| 1358 | int32 position; |
1357 | 1359 | 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 | } |
1363 | 1368 | } |
1364 | 1369 | |
1365 | 1370 | |
… |
… |
StyledEditWindow::_Search(BString string, bool caseSensitive, bool wrap,
|
1669 | 1674 | return true; |
1670 | 1675 | } |
1671 | 1676 | |
| 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 | |
1672 | 1700 | return false; |
1673 | 1701 | } |
1674 | 1702 | |