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_REPLACE = 'msre';
const uint32 MSG_REPLACE_ALL = 'mrea';
const uint32 MSG_HIDE_WINDOW = 'mhdw';
// "Font"-menu
const uint32 FONT_SIZE = 'FMsi';
+8 -7
View File
@@ -28,18 +28,18 @@
FindWindow::FindWindow(BRect frame, BHandler* _handler, BString* searchString,
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_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);
fCaseSensBox = new BCheckBox("", B_TRANSLATE("Case-sensitive"), NULL);
fWrapBox = new BCheckBox("", B_TRANSLATE("Wrap-around search"), NULL);
fBackSearchBox = new BCheckBox("", B_TRANSLATE("Search backwards"), NULL);
fCancelButton = new BButton("", B_TRANSLATE("Cancel"),
new BMessage(B_QUIT_REQUESTED));
new BMessage(MSG_HIDE_WINDOW));
fSearchButton = new BButton("", B_TRANSLATE("Find"),
new BMessage(MSG_SEARCH));
@@ -78,8 +78,9 @@ void
FindWindow::MessageReceived(BMessage* msg)
{
switch (msg->what) {
case B_QUIT_REQUESTED:
Quit();
case MSG_HIDE_WINDOW:
if (!IsHidden())
Hide();
break;
case MSG_SEARCH:
_SendMessage();
@@ -100,7 +101,7 @@ FindWindow::DispatchMessage(BMessage* message, BHandler* handler)
if (message->FindInt8("byte", 0, &key) == B_OK) {
if (key == B_ESCAPE) {
message->MakeEmpty();
message->what = B_QUIT_REQUESTED;
message->what = MSG_HIDE_WINDOW;
}
}
}
@@ -124,5 +125,5 @@ FindWindow::_SendMessage()
fHandler->Looper()->PostMessage(&message, fHandler);
PostMessage(B_QUIT_REQUESTED);
PostMessage(MSG_HIDE_WINDOW);
}
+2 -2
View File
@@ -6,8 +6,8 @@
* Mattias Sundblad
* Andrew Bachmann
*/
#ifndef FIND_WINDOW_H
#define FIND_WINDOW_H
#ifndef FIND_WINDOW_H
#define FIND_WINDOW_H
#include <Window.h>
+10 -6
View File
@@ -31,11 +31,11 @@
ReplaceWindow::ReplaceWindow(BRect frame, BHandler* _handler,
BString* searchString, BString* replaceString,
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_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);
fReplaceString = new BTextControl("", B_TRANSLATE("Replace with:"),
@@ -50,7 +50,7 @@ ReplaceWindow::ReplaceWindow(BRect frame, BHandler* _handler,
fReplaceAllButton = new BButton("", B_TRANSLATE("Replace all"),
new BMessage(MSG_REPLACE_ALL));
fCancelButton = new BButton("", B_TRANSLATE("Cancel"),
new BMessage(B_QUIT_REQUESTED));
new BMessage(MSG_HIDE_WINDOW));
fReplaceButton = new BButton("", B_TRANSLATE("Replace"),
new BMessage(MSG_REPLACE));
@@ -106,6 +106,10 @@ ReplaceWindow::MessageReceived(BMessage* msg)
_SendMessage(MSG_REPLACE_ALL);
break;
case MSG_HIDE_WINDOW:
if (!IsHidden())
Hide();
break;
default:
BWindow::MessageReceived(msg);
break;
@@ -139,12 +143,12 @@ ReplaceWindow::DispatchMessage(BMessage* message, BHandler* handler)
if (message->FindInt8("byte", 0, &key) == B_OK) {
if (key == B_ESCAPE) {
message->MakeEmpty();
message->what = B_QUIT_REQUESTED;
message->what = MSG_HIDE_WINDOW;
// This is a hack, but it actually does what is expected,
// unlike the hack above. This kind of key filtering probably
// 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);
PostMessage(B_QUIT_REQUESTED);
PostMessage(MSG_HIDE_WINDOW);
}
+3 -3
View File
@@ -6,8 +6,8 @@
* Mattias Sundblad
* Andrew Bachmann
*/
#ifndef REPLACE_WINDOW_H
#define REPLACE_WINDOW_H
#ifndef REPLACE_WINDOW_H
#define REPLACE_WINDOW_H
#include <Window.h>
@@ -32,7 +32,7 @@ class ReplaceWindow : public BWindow {
private:
void _SendMessage(uint32 what);
void _ChangeUI();
void _ChangeUI();
BTextControl *fSearchString;
BTextControl *fReplaceString;
+33 -11
View File
@@ -82,7 +82,8 @@ bs_printf(BString* string, const char* format, ...)
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);
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)
: BWindow(frame, "untitled", B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS)
: BWindow(frame, "untitled", B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS),
fFindWindow(NULL), fReplaceWindow(NULL)
{
_InitWindow(encoding);
OpenFile(ref);
@@ -236,10 +238,20 @@ StyledEditWindow::MessageReceived(BMessage* message)
break;
case MENU_FIND:
{
BRect findWindowFrame(100, 100, 400, 235);
BWindow* window = new FindWindow(findWindowFrame, this,
&fStringToFind, fCaseSensitive, fWrapAround, fBackSearch);
window->Show();
if (fFindWindow == NULL) {
BRect findWindowFrame(Frame());
findWindowFrame.InsetBy(
(findWindowFrame.Width() - 400) / 2,
(findWindowFrame.Height() - 235) / 2);
fFindWindow = new FindWindow(findWindowFrame, this,
&fStringToFind, fCaseSensitive, fWrapAround, fBackSearch);
fFindWindow->Show();
} else if (fFindWindow->IsHidden())
fFindWindow->Show();
else
fFindWindow->Activate();
break;
}
case MSG_SEARCH:
@@ -259,11 +271,21 @@ StyledEditWindow::MessageReceived(BMessage* message)
break;
case MENU_REPLACE:
{
BRect replaceWindowFrame(100, 100, 400, 284);
BWindow* window = new ReplaceWindow(replaceWindowFrame, this,
&fStringToFind, &fReplaceString, fCaseSensitive, fWrapAround,
fBackSearch);
window->Show();
if (fReplaceWindow == NULL) {
BRect replaceWindowFrame(Frame());
replaceWindowFrame.InsetBy(
(replaceWindowFrame.Width() - 400) / 2,
(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;
}
case MSG_REPLACE:
+3
View File
@@ -171,6 +171,9 @@ private:
node_ref fNodeRef;
node_ref fFolderNodeRef;
bool fNagOnNodeChange;
BWindow* fFindWindow;
BWindow* fReplaceWindow;
};