diff --git a/src/apps/text_search/GrepWindow.cpp b/src/apps/text_search/GrepWindow.cpp index 61e4821781..ee35aa3585 100644 --- a/src/apps/text_search/GrepWindow.cpp +++ b/src/apps/text_search/GrepWindow.cpp @@ -208,6 +208,13 @@ void GrepWindow::FrameMoved(BPoint origin) void GrepWindow::MenusBeginning() { fModel->FillHistoryMenu(fHistoryMenu); + + if (fHistoryMenu->CountItems() > 0) { + fHistoryMenu->AddSeparatorItem(); + BMessage* message = new BMessage(MSG_CLEAR_HISTORY); + fHistoryMenu->AddItem(new BMenuItem(B_TRANSLATE("Clear history"), message)); + } + BWindow::MenusBeginning(); } @@ -329,6 +336,11 @@ void GrepWindow::MessageReceived(BMessage* message) _OnSearchText(); break; } + + case MSG_CLEAR_HISTORY: + fModel->ClearHistory(); + break; + case MSG_START_CANCEL: _OnStartCancel(); break; diff --git a/src/apps/text_search/Model.cpp b/src/apps/text_search/Model.cpp index 8eb9e037e7..a3544f48fb 100644 --- a/src/apps/text_search/Model.cpp +++ b/src/apps/text_search/Model.cpp @@ -207,6 +207,20 @@ Model::AddToHistory(const char* text) } +void +Model::ClearHistory() +{ + BList items; + if (!_LoadHistory(items)) + return; + + items.RemoveItems(0, items.CountItems()); + + _SaveHistory(items); + _FreeHistory(items); +} + + void Model::FillHistoryMenu(BMenu* menu) const { diff --git a/src/apps/text_search/Model.h b/src/apps/text_search/Model.h index b6d9ee3ac8..23899d562c 100644 --- a/src/apps/text_search/Model.h +++ b/src/apps/text_search/Model.h @@ -33,6 +33,7 @@ enum { MSG_SELECT_HISTORY, MSG_PREV_HISTORY, MSG_NEXT_HISTORY, + MSG_CLEAR_HISTORY, MSG_NODE_MONITOR_PULSE, MSG_START_NODE_MONITORING, @@ -70,6 +71,7 @@ public: status_t SavePrefs(); void AddToHistory(const char* text); + void ClearHistory(); void FillHistoryMenu(BMenu* menu) const; BString GetHistoryItem(int32 index);