TextSearch: add context menu
A right-click opens a popup menu with useful items of the "Actions" menu of the main window menu. Change-Id: Ie2eb832fee48d642cec66f0a3c7212570eedb6c0 Reviewed-on: https://review.haiku-os.org/c/haiku/+/9657 Tested-by: Commit checker robot <[email protected]> Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
committed by
Adrien Destugues
parent
913c5a4298
commit
c928bd3270
@@ -5,7 +5,12 @@
|
||||
|
||||
#include "GrepListView.h"
|
||||
|
||||
#include <Catalog.h>
|
||||
#include <MenuItem.h>
|
||||
#include <Path.h>
|
||||
#include <Window.h>
|
||||
|
||||
#include "Model.h"
|
||||
|
||||
ResultItem::ResultItem(const entry_ref& ref)
|
||||
: BStringItem("", 0, false),
|
||||
@@ -22,6 +27,36 @@ GrepListView::GrepListView()
|
||||
B_MULTIPLE_SELECTION_LIST,
|
||||
B_WILL_DRAW | B_NAVIGABLE)
|
||||
{
|
||||
_CreatePopUpMenu();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GrepListView::AttachedToWindow()
|
||||
{
|
||||
fContextMenu->SetTargetForItems(Window());
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GrepListView::MouseDown(BPoint where)
|
||||
{
|
||||
int32 index = IndexOf(where);
|
||||
if (index >= 0) {
|
||||
if (Window() != NULL && Window()->CurrentMessage() != NULL) {
|
||||
uint32 buttons = Window()->CurrentMessage()->FindInt32("buttons");
|
||||
if ((buttons & B_SECONDARY_MOUSE_BUTTON) != 0) {
|
||||
BListItem* item = ItemAt(index);
|
||||
bool clickOnSelection = item != NULL && item->IsSelected();
|
||||
if (CurrentSelection() < 0 || !clickOnSelection)
|
||||
Select(index);
|
||||
if (CurrentSelection() >= 0)
|
||||
fContextMenu->Go(ConvertToScreen(where), true, true, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
BOutlineListView::MouseDown(where);
|
||||
}
|
||||
|
||||
|
||||
@@ -69,3 +104,28 @@ GrepListView::RemoveResults(const entry_ref& ref, bool completeItem)
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GrepListView::_CreatePopUpMenu()
|
||||
{
|
||||
fContextMenu = new BPopUpMenu("ContextMenu", false, false);
|
||||
|
||||
#undef B_TRANSLATION_CONTEXT
|
||||
#define B_TRANSLATION_CONTEXT "GrepWindow"
|
||||
fContextMenu->AddItem(new BMenuItem(B_TRANSLATE("Select all"),
|
||||
new BMessage(MSG_SELECT_ALL), 'A', B_SHIFT_KEY));
|
||||
|
||||
fContextMenu->AddItem(new BMenuItem(B_TRANSLATE("Trim to selection"),
|
||||
new BMessage(MSG_TRIM_SELECTION), 'T'));
|
||||
|
||||
fContextMenu->AddSeparatorItem();
|
||||
|
||||
fContextMenu->AddItem(new BMenuItem(B_TRANSLATE("Open selection"),
|
||||
new BMessage(MSG_OPEN_SELECTION), 'O'));
|
||||
|
||||
fContextMenu->AddItem(new BMenuItem(B_TRANSLATE("Show files in Tracker"),
|
||||
new BMessage(MSG_SELECT_IN_TRACKER), 'K'));
|
||||
|
||||
fContextMenu->AddItem(new BMenuItem(B_TRANSLATE("Copy text to clipboard"),
|
||||
new BMessage(MSG_COPY_TEXT), 'B'));
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <Entry.h>
|
||||
#include <ListItem.h>
|
||||
#include <OutlineListView.h>
|
||||
#include <PopUpMenu.h>
|
||||
|
||||
|
||||
class ResultItem : public BStringItem {
|
||||
@@ -22,11 +23,19 @@ class GrepListView : public BOutlineListView {
|
||||
public:
|
||||
GrepListView();
|
||||
|
||||
virtual void AttachedToWindow();
|
||||
virtual void MouseDown(BPoint where);
|
||||
|
||||
ResultItem* FindItem(const entry_ref& ref,
|
||||
int32* _index) const;
|
||||
|
||||
ResultItem* RemoveResults(const entry_ref& ref,
|
||||
bool completeItem);
|
||||
|
||||
private:
|
||||
void _CreatePopUpMenu();
|
||||
BPopUpMenu* fContextMenu;
|
||||
};
|
||||
|
||||
|
||||
#endif // GREP_LIST_VIEW_H
|
||||
|
||||
Reference in New Issue
Block a user