StyleEdit: non-modal Find/Replace windows implementation

* Switch to non-modal floating windows for Find/Replace dialogs,
  preserve parameters of the previous search in this editor session;
* Fixes #10053.

- GCI 2013
This commit is contained in:
Ezo
2013-12-10 21:25:10 +01:00
committed by Siarzhuk Zharski
parent b28411fdfe
commit 579c4d6e5f
7 changed files with 60 additions and 29 deletions
+1
View File
@@ -42,6 +42,7 @@ const uint32 MENU_REPLACE_SAME = 'MErs';
const uint32 MSG_SEARCH = 'msea'; const uint32 MSG_SEARCH = 'msea';
const uint32 MSG_REPLACE = 'msre'; const uint32 MSG_REPLACE = 'msre';
const uint32 MSG_REPLACE_ALL = 'mrea'; const uint32 MSG_REPLACE_ALL = 'mrea';
const uint32 MSG_HIDE_WINDOW = 'mhdw';
// "Font"-menu // "Font"-menu
const uint32 FONT_SIZE = 'FMsi'; const uint32 FONT_SIZE = 'FMsi';
+8 -7
View File
@@ -28,18 +28,18 @@
FindWindow::FindWindow(BRect frame, BHandler* _handler, BString* searchString, FindWindow::FindWindow(BRect frame, BHandler* _handler, BString* searchString,
bool caseState, bool wrapState, bool backState) bool caseState, bool wrapState, bool backState)
: BWindow(frame, "FindWindow", B_MODAL_WINDOW, : BWindow(frame, B_TRANSLATE("Find"), B_FLOATING_WINDOW,
B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS, B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS,
B_CURRENT_WORKSPACE) B_CURRENT_WORKSPACE)
{ {
AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED)); AddShortcut('W', B_COMMAND_KEY, new BMessage(MSG_HIDE_WINDOW));
fSearchString = new BTextControl("", B_TRANSLATE("Find:"), NULL, NULL); fSearchString = new BTextControl("", B_TRANSLATE("Find:"), NULL, NULL);
fCaseSensBox = new BCheckBox("", B_TRANSLATE("Case-sensitive"), NULL); fCaseSensBox = new BCheckBox("", B_TRANSLATE("Case-sensitive"), NULL);
fWrapBox = new BCheckBox("", B_TRANSLATE("Wrap-around search"), NULL); fWrapBox = new BCheckBox("", B_TRANSLATE("Wrap-around search"), NULL);
fBackSearchBox = new BCheckBox("", B_TRANSLATE("Search backwards"), NULL); fBackSearchBox = new BCheckBox("", B_TRANSLATE("Search backwards"), NULL);
fCancelButton = new BButton("", B_TRANSLATE("Cancel"), fCancelButton = new BButton("", B_TRANSLATE("Cancel"),
new BMessage(B_QUIT_REQUESTED)); new BMessage(MSG_HIDE_WINDOW));
fSearchButton = new BButton("", B_TRANSLATE("Find"), fSearchButton = new BButton("", B_TRANSLATE("Find"),
new BMessage(MSG_SEARCH)); new BMessage(MSG_SEARCH));
@@ -78,8 +78,9 @@ void
FindWindow::MessageReceived(BMessage* msg) FindWindow::MessageReceived(BMessage* msg)
{ {
switch (msg->what) { switch (msg->what) {
case B_QUIT_REQUESTED: case MSG_HIDE_WINDOW:
Quit(); if (!IsHidden())
Hide();
break; break;
case MSG_SEARCH: case MSG_SEARCH:
_SendMessage(); _SendMessage();
@@ -100,7 +101,7 @@ FindWindow::DispatchMessage(BMessage* message, BHandler* handler)
if (message->FindInt8("byte", 0, &key) == B_OK) { if (message->FindInt8("byte", 0, &key) == B_OK) {
if (key == B_ESCAPE) { if (key == B_ESCAPE) {
message->MakeEmpty(); message->MakeEmpty();
message->what = B_QUIT_REQUESTED; message->what = MSG_HIDE_WINDOW;
} }
} }
} }
@@ -124,5 +125,5 @@ FindWindow::_SendMessage()
fHandler->Looper()->PostMessage(&message, fHandler); fHandler->Looper()->PostMessage(&message, fHandler);
PostMessage(B_QUIT_REQUESTED); PostMessage(MSG_HIDE_WINDOW);
} }
+10 -6
View File
@@ -31,11 +31,11 @@
ReplaceWindow::ReplaceWindow(BRect frame, BHandler* _handler, ReplaceWindow::ReplaceWindow(BRect frame, BHandler* _handler,
BString* searchString, BString* replaceString, BString* searchString, BString* replaceString,
bool caseState, bool wrapState, bool backState) bool caseState, bool wrapState, bool backState)
: BWindow(frame, "ReplaceWindow", B_MODAL_WINDOW, : BWindow(frame, B_TRANSLATE("Replace"), B_FLOATING_WINDOW,
B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS, B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS,
B_CURRENT_WORKSPACE) B_CURRENT_WORKSPACE)
{ {
AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED)); AddShortcut('W', B_COMMAND_KEY, new BMessage(MSG_HIDE_WINDOW));
fSearchString = new BTextControl("", B_TRANSLATE("Find:"), NULL, NULL); fSearchString = new BTextControl("", B_TRANSLATE("Find:"), NULL, NULL);
fReplaceString = new BTextControl("", B_TRANSLATE("Replace with:"), fReplaceString = new BTextControl("", B_TRANSLATE("Replace with:"),
@@ -50,7 +50,7 @@ ReplaceWindow::ReplaceWindow(BRect frame, BHandler* _handler,
fReplaceAllButton = new BButton("", B_TRANSLATE("Replace all"), fReplaceAllButton = new BButton("", B_TRANSLATE("Replace all"),
new BMessage(MSG_REPLACE_ALL)); new BMessage(MSG_REPLACE_ALL));
fCancelButton = new BButton("", B_TRANSLATE("Cancel"), fCancelButton = new BButton("", B_TRANSLATE("Cancel"),
new BMessage(B_QUIT_REQUESTED)); new BMessage(MSG_HIDE_WINDOW));
fReplaceButton = new BButton("", B_TRANSLATE("Replace"), fReplaceButton = new BButton("", B_TRANSLATE("Replace"),
new BMessage(MSG_REPLACE)); new BMessage(MSG_REPLACE));
@@ -106,6 +106,10 @@ ReplaceWindow::MessageReceived(BMessage* msg)
_SendMessage(MSG_REPLACE_ALL); _SendMessage(MSG_REPLACE_ALL);
break; break;
case MSG_HIDE_WINDOW:
if (!IsHidden())
Hide();
break;
default: default:
BWindow::MessageReceived(msg); BWindow::MessageReceived(msg);
break; break;
@@ -139,12 +143,12 @@ ReplaceWindow::DispatchMessage(BMessage* message, BHandler* handler)
if (message->FindInt8("byte", 0, &key) == B_OK) { if (message->FindInt8("byte", 0, &key) == B_OK) {
if (key == B_ESCAPE) { if (key == B_ESCAPE) {
message->MakeEmpty(); message->MakeEmpty();
message->what = B_QUIT_REQUESTED; message->what = MSG_HIDE_WINDOW;
// This is a hack, but it actually does what is expected, // This is a hack, but it actually does what is expected,
// unlike the hack above. This kind of key filtering probably // unlike the hack above. This kind of key filtering probably
// ought to be handled by a BMessageFilter, though. // ought to be handled by a BMessageFilter, though.
BMessenger (this).SendMessage(B_QUIT_REQUESTED); BMessenger (this).SendMessage(MSG_HIDE_WINDOW);
} }
} }
} }
@@ -170,6 +174,6 @@ ReplaceWindow::_SendMessage(uint32 what)
fHandler->Looper()->PostMessage(&message, fHandler); fHandler->Looper()->PostMessage(&message, fHandler);
PostMessage(B_QUIT_REQUESTED); PostMessage(MSG_HIDE_WINDOW);
} }
+32 -10
View File
@@ -82,7 +82,8 @@ bs_printf(BString* string, const char* format, ...)
StyledEditWindow::StyledEditWindow(BRect frame, int32 id, uint32 encoding) StyledEditWindow::StyledEditWindow(BRect frame, int32 id, uint32 encoding)
: BWindow(frame, "untitled", B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS) : BWindow(frame, "untitled", B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS),
fFindWindow(NULL), fReplaceWindow(NULL)
{ {
_InitWindow(encoding); _InitWindow(encoding);
BString unTitled(B_TRANSLATE("Untitled ")); BString unTitled(B_TRANSLATE("Untitled "));
@@ -95,7 +96,8 @@ StyledEditWindow::StyledEditWindow(BRect frame, int32 id, uint32 encoding)
StyledEditWindow::StyledEditWindow(BRect frame, entry_ref* ref, uint32 encoding) StyledEditWindow::StyledEditWindow(BRect frame, entry_ref* ref, uint32 encoding)
: BWindow(frame, "untitled", B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS) : BWindow(frame, "untitled", B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS),
fFindWindow(NULL), fReplaceWindow(NULL)
{ {
_InitWindow(encoding); _InitWindow(encoding);
OpenFile(ref); OpenFile(ref);
@@ -236,10 +238,20 @@ StyledEditWindow::MessageReceived(BMessage* message)
break; break;
case MENU_FIND: case MENU_FIND:
{ {
BRect findWindowFrame(100, 100, 400, 235); if (fFindWindow == NULL) {
BWindow* window = new FindWindow(findWindowFrame, this, BRect findWindowFrame(Frame());
findWindowFrame.InsetBy(
(findWindowFrame.Width() - 400) / 2,
(findWindowFrame.Height() - 235) / 2);
fFindWindow = new FindWindow(findWindowFrame, this,
&fStringToFind, fCaseSensitive, fWrapAround, fBackSearch); &fStringToFind, fCaseSensitive, fWrapAround, fBackSearch);
window->Show(); fFindWindow->Show();
} else if (fFindWindow->IsHidden())
fFindWindow->Show();
else
fFindWindow->Activate();
break; break;
} }
case MSG_SEARCH: case MSG_SEARCH:
@@ -259,11 +271,21 @@ StyledEditWindow::MessageReceived(BMessage* message)
break; break;
case MENU_REPLACE: case MENU_REPLACE:
{ {
BRect replaceWindowFrame(100, 100, 400, 284); if (fReplaceWindow == NULL) {
BWindow* window = new ReplaceWindow(replaceWindowFrame, this, BRect replaceWindowFrame(Frame());
&fStringToFind, &fReplaceString, fCaseSensitive, fWrapAround, replaceWindowFrame.InsetBy(
fBackSearch); (replaceWindowFrame.Width() - 400) / 2,
window->Show(); (replaceWindowFrame.Height() - 284) / 2);
fReplaceWindow = new ReplaceWindow(replaceWindowFrame, this,
&fStringToFind, &fReplaceString, fCaseSensitive,
fWrapAround, fBackSearch);
fReplaceWindow->Show();
} else if (fReplaceWindow->IsHidden())
fReplaceWindow->Show();
else
fReplaceWindow->Activate();
break; break;
} }
case MSG_REPLACE: case MSG_REPLACE:
+3
View File
@@ -171,6 +171,9 @@ private:
node_ref fNodeRef; node_ref fNodeRef;
node_ref fFolderNodeRef; node_ref fFolderNodeRef;
bool fNagOnNodeChange; bool fNagOnNodeChange;
BWindow* fFindWindow;
BWindow* fReplaceWindow;
}; };