Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion locales/en.catkeys
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
1 English x-vnd.KapiX-Koder 2172933300
1 English x-vnd.KapiX-Koder 3825495319
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%.
Access denied EditorWindow Access denied
Line endings EditorWindow Line endings
Expand Down Expand Up @@ -69,6 +69,7 @@ The file contains unsaved changes, but is read-only. What to do? EditorWindow T
Old Mac format EditorWindow Old Mac format
Open Terminal EditorWindow Open Terminal
loaded Preferences settings will not be _ loaded
Bookmark all FindWindow Bookmark all
Unsaved files QuitAlert Unsaved files
Bookmarks AppPreferencesWindow Bookmarks
load Preferences to _ the configuration load
Expand Down
6 changes: 6 additions & 0 deletions src/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,12 @@ App::MessageReceived(BMessage* message)
}
fPreferences->fFindWindowState = *message;
} break;
case FINDWINDOW_BOOKMARKALL: {
if(fLastActiveWindow != nullptr) {
BMessenger messenger((BWindow*) fLastActiveWindow);
messenger.SendMessage(message);
}
} break;
case FINDWINDOW_QUITTING: {
fFindWindow = nullptr;
} break;
Expand Down
49 changes: 49 additions & 0 deletions src/editor/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,55 @@ Editor::SetBookmarks(const BMessage &lines)
}


void
Editor::SetBookmarksFromSearch(const BMessage &searchMessage)
{
std::string search = searchMessage.GetString("findText", "");
if(search.empty() == true) {
return;
}

bool inSelection = searchMessage.GetBool("inSelection", false);
bool wrapAround = searchMessage.GetBool("wrapAround", false);
bool backwards = searchMessage.GetBool("backwards", false);
bool regex = searchMessage.GetBool("regex", false);
bool wholeWord = searchMessage.GetBool("wholeWord", false);
bool matchCase = searchMessage.GetBool("matchCase", false);
Sci_Position start = 0, finish;

if(inSelection == true) {
start = SendMessage(SCI_GETSELECTIONSTART);
} else if(wrapAround == false && backwards == false) {
start = SendMessage(SCI_GETCURRENTPOS);
}

if(inSelection == true) {
finish = SendMessage(SCI_GETSELECTIONEND);
} else if(backwards == false) {
finish = SendMessage(SCI_GETLENGTH, 0, 0);
} else {
finish = SendMessage(SCI_GETCURRENTPOS);
}

Set<SearchTarget>({start, finish});

Set<SearchFlags>((wholeWord == true ? SCFIND_WHOLEWORD : 0)
| (matchCase == true ? SCFIND_MATCHCASE : 0)
| (regex == true ? (SCFIND_REGEXP | SCFIND_CXX11REGEX) : 0));

int result;
do {
result = SendMessage(SCI_SEARCHINTARGET, search.length(), (sptr_t) search.c_str());
if(result == -1)
continue;

int64 line = SendMessage(SCI_LINEFROMPOSITION, result);
SendMessage(SCI_MARKERADD, line, Marker::BOOKMARK);
Set<SearchTarget>({Get<SearchTargetEnd>(), finish});
} while(result != -1);
}


BMessage
Editor::Bookmarks()
{
Expand Down
1 change: 1 addition & 0 deletions src/editor/Editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class Editor : public BScintillaView {
void GoToLine(int64 line);

void SetBookmarks(const BMessage &lines);
void SetBookmarksFromSearch(const BMessage &searchMessage);
BMessage Bookmarks();
BMessage BookmarksWithText();

Expand Down
3 changes: 3 additions & 0 deletions src/editor/EditorWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,9 @@ EditorWindow::MessageReceived(BMessage* message)
message->what = FindReplaceHandler::REPLACEFIND;
PostMessage(message, fFindReplaceHandler, this);
} break;
case FINDWINDOW_BOOKMARKALL: {
fEditor->SetBookmarksFromSearch(*message);
} break;
case OPEN_TERMINAL: {
if(fOpenedFilePath != nullptr) {
BPath directory;
Expand Down
67 changes: 40 additions & 27 deletions src/find/FindWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,33 +68,9 @@ FindWindow::MessageReceived(BMessage* message)
std::string replaceText(fReplaceTC->TextLength(), '\0');
fFindTC->GetText(0, findText.size() + 1, &findText[0]);
fReplaceTC->GetText(0, replaceText.size() + 1, &replaceText[0]);
{
const int32 mruMax = 10;
int32 count = 0;
std::string lastFind;
if(fFindHistory.GetInfo("mru", nullptr, &count) == B_OK) {
lastFind = fFindHistory.GetString("mru", count - 1, "");
}
if(lastFind != findText)
fFindHistory.AddString("mru", findText.c_str());
while(count >= mruMax) {
fFindHistory.RemoveData("mru", 0);
count--;
}

if (message->what != FINDWINDOW_FIND) {
count = 0;
std::string lastReplace;
if(fReplaceHistory.GetInfo("mru", nullptr, &count) == B_OK) {
lastReplace = fReplaceHistory.GetString("mru", count - 1, "");
}
if(lastReplace != replaceText)
fReplaceHistory.AddString("mru", replaceText.c_str());
while(count >= mruMax) {
fReplaceHistory.RemoveData("mru", 0);
count--;
}
}
_AppendHistoryString(fFindHistory, findText);
if (message->what != FINDWINDOW_FIND) {
_AppendHistoryString(fReplaceHistory, replaceText);
}
bool newSearch = (fFlagsChanged
|| fOldFindText != findText
Expand All @@ -118,6 +94,22 @@ FindWindow::MessageReceived(BMessage* message)
fFlagsChanged = false;
}
} break;
case FINDWINDOW_BOOKMARKALL: {
std::string findText(fFindTC->TextLength(), '\0');
fFindTC->GetText(0, findText.size() + 1, &findText[0]);
if(findText.empty() == true) {
return;
}
_AppendHistoryString(fFindHistory, findText);
message->AddString("findText", findText.c_str());
message->AddBool("matchCase", IsChecked(fMatchCaseCB));
message->AddBool("matchWord", IsChecked(fMatchWordCB));
message->AddBool("wrapAround", IsChecked(fWrapAroundCB));
message->AddBool("regex", IsChecked(fRegexCB));
message->AddBool("backwards", IsChecked(fBackwardsCB));
message->AddBool("inSelection", IsChecked(fInSelectionCB));
be_app->PostMessage(message);
} break;
case FINDWINDOW_QUITTING: {
if(LockLooper())
Quit();
Expand Down Expand Up @@ -226,6 +218,8 @@ FindWindow::_InitInterface()
fReplaceFindButton->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
fReplaceAllButton = new BButton(B_TRANSLATE("Replace all"), new BMessage((uint32) FINDWINDOW_REPLACEALL));
fReplaceAllButton->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
fBookmarkAllButton = new BButton(B_TRANSLATE("Bookmark all"), new BMessage((uint32) FINDWINDOW_BOOKMARKALL));
fBookmarkAllButton->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));

fMatchCaseCB = new BCheckBox("matchCase", B_TRANSLATE("Match case"), new BMessage((uint32) Actions::MATCH_CASE));
fMatchWordCB = new BCheckBox("matchWord", B_TRANSLATE("Match entire words"), new BMessage((uint32) Actions::MATCH_WORD));
Expand All @@ -249,6 +243,7 @@ FindWindow::_InitInterface()
.Add(fReplaceButton)
.Add(fReplaceFindButton)
.Add(fReplaceAllButton)
.Add(fBookmarkAllButton)
.AddGlue()
.End()
.End()
Expand Down Expand Up @@ -300,3 +295,21 @@ FindWindow::_SaveHistory()
backupFileGuard.SaveSuccessful();
}
}


void
FindWindow::_AppendHistoryString(BMessage& historyMessage, std::string& itemString)
{
const int32 mruMax = 10;
int32 count = 0;
std::string lastItemString;
if(historyMessage.GetInfo("mru", nullptr, &count) == B_OK) {
lastItemString = historyMessage.GetString("mru", count - 1, "");
}
if(lastItemString != itemString)
historyMessage.AddString("mru", itemString.c_str());
while(count >= mruMax) {
historyMessage.RemoveData("mru", 0);
count--;
}
}
3 changes: 3 additions & 0 deletions src/find/FindWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ enum {
FINDWINDOW_REPLACE = 'fwrp',
FINDWINDOW_REPLACEFIND = 'fwrf',
FINDWINDOW_REPLACEALL = 'fwra',
FINDWINDOW_BOOKMARKALL = 'fwba',
FINDWINDOW_QUITTING = 'FWQU'
};

Expand Down Expand Up @@ -65,6 +66,7 @@ class FindWindow : public BWindow {
void _InitInterface();
void _LoadHistory();
void _SaveHistory();
void _AppendHistoryString(BMessage& historyMessage, std::string& itemString);

BStringView* fFindString;
find::ScintillaView* fFindTC;
Expand All @@ -75,6 +77,7 @@ class FindWindow : public BWindow {
BButton* fReplaceButton;
BButton* fReplaceFindButton;
BButton* fReplaceAllButton;
BButton* fBookmarkAllButton;

BCheckBox* fMatchCaseCB;
BCheckBox* fMatchWordCB;
Expand Down