Skip to content

Commit 474ecee

Browse files
augiedoggieKapiX
authored andcommitted
FindWindow: add "Bookmark all" button
1 parent e8a27a4 commit 474ecee

7 files changed

Lines changed: 104 additions & 28 deletions

File tree

locales/en.catkeys

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1 English x-vnd.KapiX-Koder 2172933300
1+
1 English x-vnd.KapiX-Koder 3825495319
22
Something wrong has happened while opening the configuration file. Your personal settings will not be %s%. Preferences Something wrong has happened while opening the configuration file. Your personal settings will not be %s%.
33
Access denied EditorWindow Access denied
44
Line endings EditorWindow Line endings
@@ -69,6 +69,7 @@ The file contains unsaved changes, but is read-only. What to do? EditorWindow T
6969
Old Mac format EditorWindow Old Mac format
7070
Open Terminal EditorWindow Open Terminal
7171
loaded Preferences settings will not be _ loaded
72+
Bookmark all FindWindow Bookmark all
7273
Unsaved files QuitAlert Unsaved files
7374
Bookmarks AppPreferencesWindow Bookmarks
7475
load Preferences to _ the configuration load

src/App.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,12 @@ App::MessageReceived(BMessage* message)
293293
}
294294
fPreferences->fFindWindowState = *message;
295295
} break;
296+
case FINDWINDOW_BOOKMARKALL: {
297+
if(fLastActiveWindow != nullptr) {
298+
BMessenger messenger((BWindow*) fLastActiveWindow);
299+
messenger.SendMessage(message);
300+
}
301+
} break;
296302
case FINDWINDOW_QUITTING: {
297303
fFindWindow = nullptr;
298304
} break;

src/editor/Editor.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,55 @@ Editor::SetBookmarks(const BMessage &lines)
408408
}
409409

410410

411+
void
412+
Editor::SetBookmarksFromSearch(const BMessage &searchMessage)
413+
{
414+
std::string search = searchMessage.GetString("findText", "");
415+
if(search.empty() == true) {
416+
return;
417+
}
418+
419+
bool inSelection = searchMessage.GetBool("inSelection", false);
420+
bool wrapAround = searchMessage.GetBool("wrapAround", false);
421+
bool backwards = searchMessage.GetBool("backwards", false);
422+
bool regex = searchMessage.GetBool("regex", false);
423+
bool wholeWord = searchMessage.GetBool("wholeWord", false);
424+
bool matchCase = searchMessage.GetBool("matchCase", false);
425+
Sci_Position start = 0, finish;
426+
427+
if(inSelection == true) {
428+
start = SendMessage(SCI_GETSELECTIONSTART);
429+
} else if(wrapAround == false && backwards == false) {
430+
start = SendMessage(SCI_GETCURRENTPOS);
431+
}
432+
433+
if(inSelection == true) {
434+
finish = SendMessage(SCI_GETSELECTIONEND);
435+
} else if(backwards == false) {
436+
finish = SendMessage(SCI_GETLENGTH, 0, 0);
437+
} else {
438+
finish = SendMessage(SCI_GETCURRENTPOS);
439+
}
440+
441+
Set<SearchTarget>({start, finish});
442+
443+
Set<SearchFlags>((wholeWord == true ? SCFIND_WHOLEWORD : 0)
444+
| (matchCase == true ? SCFIND_MATCHCASE : 0)
445+
| (regex == true ? (SCFIND_REGEXP | SCFIND_CXX11REGEX) : 0));
446+
447+
int result;
448+
do {
449+
result = SendMessage(SCI_SEARCHINTARGET, search.length(), (sptr_t) search.c_str());
450+
if(result == -1)
451+
continue;
452+
453+
int64 line = SendMessage(SCI_LINEFROMPOSITION, result);
454+
SendMessage(SCI_MARKERADD, line, Marker::BOOKMARK);
455+
Set<SearchTarget>({Get<SearchTargetEnd>(), finish});
456+
} while(result != -1);
457+
}
458+
459+
411460
BMessage
412461
Editor::Bookmarks()
413462
{

src/editor/Editor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class Editor : public BScintillaView {
8080
void GoToLine(int64 line);
8181

8282
void SetBookmarks(const BMessage &lines);
83+
void SetBookmarksFromSearch(const BMessage &searchMessage);
8384
BMessage Bookmarks();
8485
BMessage BookmarksWithText();
8586

src/editor/EditorWindow.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,9 @@ EditorWindow::MessageReceived(BMessage* message)
941941
message->what = FindReplaceHandler::REPLACEFIND;
942942
PostMessage(message, fFindReplaceHandler, this);
943943
} break;
944+
case FINDWINDOW_BOOKMARKALL: {
945+
fEditor->SetBookmarksFromSearch(*message);
946+
} break;
944947
case OPEN_TERMINAL: {
945948
if(fOpenedFilePath != nullptr) {
946949
BPath directory;

src/find/FindWindow.cpp

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -68,33 +68,9 @@ FindWindow::MessageReceived(BMessage* message)
6868
std::string replaceText(fReplaceTC->TextLength(), '\0');
6969
fFindTC->GetText(0, findText.size() + 1, &findText[0]);
7070
fReplaceTC->GetText(0, replaceText.size() + 1, &replaceText[0]);
71-
{
72-
const int32 mruMax = 10;
73-
int32 count = 0;
74-
std::string lastFind;
75-
if(fFindHistory.GetInfo("mru", nullptr, &count) == B_OK) {
76-
lastFind = fFindHistory.GetString("mru", count - 1, "");
77-
}
78-
if(lastFind != findText)
79-
fFindHistory.AddString("mru", findText.c_str());
80-
while(count >= mruMax) {
81-
fFindHistory.RemoveData("mru", 0);
82-
count--;
83-
}
84-
85-
if (message->what != FINDWINDOW_FIND) {
86-
count = 0;
87-
std::string lastReplace;
88-
if(fReplaceHistory.GetInfo("mru", nullptr, &count) == B_OK) {
89-
lastReplace = fReplaceHistory.GetString("mru", count - 1, "");
90-
}
91-
if(lastReplace != replaceText)
92-
fReplaceHistory.AddString("mru", replaceText.c_str());
93-
while(count >= mruMax) {
94-
fReplaceHistory.RemoveData("mru", 0);
95-
count--;
96-
}
97-
}
71+
_AppendHistoryString(fFindHistory, findText);
72+
if (message->what != FINDWINDOW_FIND) {
73+
_AppendHistoryString(fReplaceHistory, replaceText);
9874
}
9975
bool newSearch = (fFlagsChanged
10076
|| fOldFindText != findText
@@ -118,6 +94,22 @@ FindWindow::MessageReceived(BMessage* message)
11894
fFlagsChanged = false;
11995
}
12096
} break;
97+
case FINDWINDOW_BOOKMARKALL: {
98+
std::string findText(fFindTC->TextLength(), '\0');
99+
fFindTC->GetText(0, findText.size() + 1, &findText[0]);
100+
if(findText.empty() == true) {
101+
return;
102+
}
103+
_AppendHistoryString(fFindHistory, findText);
104+
message->AddString("findText", findText.c_str());
105+
message->AddBool("matchCase", IsChecked(fMatchCaseCB));
106+
message->AddBool("matchWord", IsChecked(fMatchWordCB));
107+
message->AddBool("wrapAround", IsChecked(fWrapAroundCB));
108+
message->AddBool("regex", IsChecked(fRegexCB));
109+
message->AddBool("backwards", IsChecked(fBackwardsCB));
110+
message->AddBool("inSelection", IsChecked(fInSelectionCB));
111+
be_app->PostMessage(message);
112+
} break;
121113
case FINDWINDOW_QUITTING: {
122114
if(LockLooper())
123115
Quit();
@@ -226,6 +218,8 @@ FindWindow::_InitInterface()
226218
fReplaceFindButton->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
227219
fReplaceAllButton = new BButton(B_TRANSLATE("Replace all"), new BMessage((uint32) FINDWINDOW_REPLACEALL));
228220
fReplaceAllButton->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
221+
fBookmarkAllButton = new BButton(B_TRANSLATE("Bookmark all"), new BMessage((uint32) FINDWINDOW_BOOKMARKALL));
222+
fBookmarkAllButton->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
229223

230224
fMatchCaseCB = new BCheckBox("matchCase", B_TRANSLATE("Match case"), new BMessage((uint32) Actions::MATCH_CASE));
231225
fMatchWordCB = new BCheckBox("matchWord", B_TRANSLATE("Match entire words"), new BMessage((uint32) Actions::MATCH_WORD));
@@ -249,6 +243,7 @@ FindWindow::_InitInterface()
249243
.Add(fReplaceButton)
250244
.Add(fReplaceFindButton)
251245
.Add(fReplaceAllButton)
246+
.Add(fBookmarkAllButton)
252247
.AddGlue()
253248
.End()
254249
.End()
@@ -300,3 +295,21 @@ FindWindow::_SaveHistory()
300295
backupFileGuard.SaveSuccessful();
301296
}
302297
}
298+
299+
300+
void
301+
FindWindow::_AppendHistoryString(BMessage& historyMessage, std::string& itemString)
302+
{
303+
const int32 mruMax = 10;
304+
int32 count = 0;
305+
std::string lastItemString;
306+
if(historyMessage.GetInfo("mru", nullptr, &count) == B_OK) {
307+
lastItemString = historyMessage.GetString("mru", count - 1, "");
308+
}
309+
if(lastItemString != itemString)
310+
historyMessage.AddString("mru", itemString.c_str());
311+
while(count >= mruMax) {
312+
historyMessage.RemoveData("mru", 0);
313+
count--;
314+
}
315+
}

src/find/FindWindow.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ enum {
3030
FINDWINDOW_REPLACE = 'fwrp',
3131
FINDWINDOW_REPLACEFIND = 'fwrf',
3232
FINDWINDOW_REPLACEALL = 'fwra',
33+
FINDWINDOW_BOOKMARKALL = 'fwba',
3334
FINDWINDOW_QUITTING = 'FWQU'
3435
};
3536

@@ -65,6 +66,7 @@ class FindWindow : public BWindow {
6566
void _InitInterface();
6667
void _LoadHistory();
6768
void _SaveHistory();
69+
void _AppendHistoryString(BMessage& historyMessage, std::string& itemString);
6870

6971
BStringView* fFindString;
7072
find::ScintillaView* fFindTC;
@@ -75,6 +77,7 @@ class FindWindow : public BWindow {
7577
BButton* fReplaceButton;
7678
BButton* fReplaceFindButton;
7779
BButton* fReplaceAllButton;
80+
BButton* fBookmarkAllButton;
7881

7982
BCheckBox* fMatchCaseCB;
8083
BCheckBox* fMatchWordCB;

0 commit comments

Comments
 (0)