created context menu for Search window;

improved context menu for Scratchpad (right click selects row now)
This commit is contained in:
fgerlits 2005-04-27 16:39:05 +00:00
parent e5120cbf0b
commit a7b1bac0a2
5 changed files with 138 additions and 15 deletions

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.8 $ Version : $Revision: 1.9 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/ScratchpadWindow.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/ScratchpadWindow.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -313,11 +313,25 @@ void
ScratchpadWindow :: onEntryClicked (GdkEventButton * event) throw () ScratchpadWindow :: onEntryClicked (GdkEventButton * event) throw ()
{ {
if (event->type == GDK_BUTTON_PRESS && event->button == 3) { if (event->type == GDK_BUTTON_PRESS && event->button == 3) {
// only show the context menu, if something is already selected
Glib::RefPtr<Gtk::TreeView::Selection> refSelection = Glib::RefPtr<Gtk::TreeView::Selection> refSelection =
treeView->get_selection(); treeView->get_selection();
if (refSelection) { if (refSelection) {
Gtk::TreeModel::iterator iter = refSelection->get_selected(); Gtk::TreeModel::iterator iter = refSelection->get_selected();
// if nothing is currently selected, select row at mouse pointer
if (!iter) {
Gtk::TreeModel::Path path;
Gtk::TreeViewColumn * column;
int cell_x,
cell_y;
if (treeView->get_path_at_pos(int(event->x), int(event->y),
path, column,
cell_x, cell_y)) {
refSelection->select(path);
iter = refSelection->get_selected();
}
}
if (iter) { if (iter) {
Ptr<Playable>::Ref playable = Ptr<Playable>::Ref playable =
(*iter)[modelColumns.playableColumn]; (*iter)[modelColumns.playableColumn];

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.8 $ Version : $Revision: 1.9 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/SearchWindow.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/SearchWindow.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -72,11 +72,13 @@ SearchWindow :: SearchWindow (Ptr<GLiveSupport>::Ref gLiveSupport,
: WhiteWindow(WidgetFactory::searchWindowTitleImage, : WhiteWindow(WidgetFactory::searchWindowTitleImage,
Colors::White, Colors::White,
WidgetFactory::getInstance()->getWhiteWindowCorners()), WidgetFactory::getInstance()->getWhiteWindowCorners()),
LocalizedObject(bundle) LocalizedObject(bundle),
gLiveSupport(gLiveSupport)
{ {
this->gLiveSupport = gLiveSupport;
treeModel = Gtk::ListStore::create(modelColumns); treeModel = Gtk::ListStore::create(modelColumns);
searchResults = constructSearchResults();
Gtk::Box * simpleSearchView = constructSimpleSearchView(); Gtk::Box * simpleSearchView = constructSimpleSearchView();
Gtk::Box * advancedSearchView = constructAdvancedSearchView(); Gtk::Box * advancedSearchView = constructAdvancedSearchView();
Gtk::Box * browseView = constructBrowseView(); Gtk::Box * browseView = constructBrowseView();
@ -96,6 +98,23 @@ SearchWindow :: SearchWindow (Ptr<GLiveSupport>::Ref gLiveSupport,
add(*views); add(*views);
// create the right-click entry context menu
contextMenu = Gtk::manage(new Gtk::Menu());
Gtk::Menu::MenuList& contextMenuList = contextMenu->items();
// register the signal handlers for the context menu
try {
contextMenuList.push_back(Gtk::Menu_Helpers::MenuElem(
*getResourceUstring("addToScratchpadMenuItem"),
sigc::mem_fun(*this,
&SearchWindow::onAddToScratchpad)));
} catch (std::invalid_argument &e) {
std::cerr << e.what() << std::endl;
std::exit(1);
}
contextMenu->accelerate(*this);
// show // show
set_name("searchWindow"); set_name("searchWindow");
set_default_size(450, 250); set_default_size(450, 250);
@ -144,9 +163,6 @@ SearchWindow :: constructSimpleSearchView(void) throw ()
entryBox->pack_start(*simpleSearchEntry, Gtk::PACK_SHRINK, 5); entryBox->pack_start(*simpleSearchEntry, Gtk::PACK_SHRINK, 5);
entryBox->pack_start(*searchButton, Gtk::PACK_SHRINK, 5); entryBox->pack_start(*searchButton, Gtk::PACK_SHRINK, 5);
// set up the search results display
ZebraTreeView * searchResults = constructSearchResults();
// make a new box and pack the main components into it // make a new box and pack the main components into it
Gtk::VBox * view = Gtk::manage(new Gtk::VBox); Gtk::VBox * view = Gtk::manage(new Gtk::VBox);
view->pack_start(*entryBox, Gtk::PACK_EXPAND_WIDGET, 5); view->pack_start(*entryBox, Gtk::PACK_EXPAND_WIDGET, 5);
@ -167,7 +183,6 @@ SearchWindow :: constructAdvancedSearchView(void) throw ()
advancedSearchEntry = Gtk::manage(new AdvancedSearchEntry(getBundle())); advancedSearchEntry = Gtk::manage(new AdvancedSearchEntry(getBundle()));
Gtk::Box * searchButtonBox = Gtk::manage(new Gtk::HButtonBox( Gtk::Box * searchButtonBox = Gtk::manage(new Gtk::HButtonBox(
Gtk::BUTTONBOX_END )); Gtk::BUTTONBOX_END ));
ZebraTreeView * searchResults = constructSearchResults();
// set up the callback function for the entry field // set up the callback function for the entry field
advancedSearchEntry->connectCallback(sigc::mem_fun( advancedSearchEntry->connectCallback(sigc::mem_fun(
@ -208,9 +223,6 @@ SearchWindow :: constructBrowseView(void) throw ()
browseEntry->signalSelectionChanged().connect(sigc::mem_fun( browseEntry->signalSelectionChanged().connect(sigc::mem_fun(
*this, &SearchWindow::onBrowse )); *this, &SearchWindow::onBrowse ));
// set up the search results display
ZebraTreeView * searchResults = constructSearchResults();
// make a new box and pack the main components into it // make a new box and pack the main components into it
Gtk::VBox * view = Gtk::manage(new Gtk::VBox); Gtk::VBox * view = Gtk::manage(new Gtk::VBox);
view->pack_start(*browseEntry, Gtk::PACK_EXPAND_WIDGET, 5); view->pack_start(*browseEntry, Gtk::PACK_EXPAND_WIDGET, 5);
@ -245,6 +257,10 @@ SearchWindow :: constructSearchResults(void) throw ()
std::exit(1); std::exit(1);
} }
// register the signal handler for treeview entries being clicked
searchResults->signal_button_press_event().connect_notify(sigc::mem_fun(
*this, &SearchWindow::onEntryClicked));
return searchResults; return searchResults;
} }
@ -332,3 +348,68 @@ SearchWindow :: onSearch(Ptr<SearchCriteria>::Ref criteria)
} }
} }
/*------------------------------------------------------------------------------
* Event handler for an entry being clicked in the list
*----------------------------------------------------------------------------*/
void
SearchWindow :: onEntryClicked (GdkEventButton * event) throw ()
{
if (event->type == GDK_BUTTON_PRESS && event->button == 3) {
Glib::RefPtr<Gtk::TreeView::Selection> refSelection =
searchResults->get_selection();
if (refSelection) {
Gtk::TreeModel::iterator iter = refSelection->get_selected();
// if nothing is currently selected, select row at mouse pointer
if (!iter) {
Gtk::TreeModel::Path path;
Gtk::TreeViewColumn * column;
int cell_x,
cell_y;
if (searchResults->get_path_at_pos(
int(event->x), int(event->y),
path, column,
cell_x, cell_y )) {
refSelection->select(path);
iter = refSelection->get_selected();
}
}
if (iter) {
Ptr<Playable>::Ref playable =
(*iter)[modelColumns.playableColumn];
switch (playable->getType()) {
case Playable::AudioClipType:
contextMenu->popup(event->button, event->time);
break;
case Playable::PlaylistType:
contextMenu->popup(event->button, event->time);
break;
default:
break;
}
}
}
}
}
/*------------------------------------------------------------------------------
* Add a playable to the scratchpad.
*----------------------------------------------------------------------------*/
void
SearchWindow :: onAddToScratchpad(void) throw ()
{
Glib::RefPtr<Gtk::TreeView::Selection> refSelection =
searchResults->get_selection();
Gtk::TreeModel::iterator iter = refSelection->get_selected();
if (iter) {
Ptr<Playable>::Ref playable = (*iter)[modelColumns.playableColumn];
gLiveSupport->addToScratchPad(playable);
}
}

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.7 $ Version : $Revision: 1.8 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/SearchWindow.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/SearchWindow.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -73,7 +73,7 @@ using namespace LiveSupport::Widgets;
* The Search/Browse window. * The Search/Browse window.
* *
* @author $Author: fgerlits $ * @author $Author: fgerlits $
* @version $Revision: 1.7 $ * @version $Revision: 1.8 $
*/ */
class SearchWindow : public WhiteWindow, public LocalizedObject class SearchWindow : public WhiteWindow, public LocalizedObject
{ {
@ -94,6 +94,16 @@ class SearchWindow : public WhiteWindow, public LocalizedObject
*/ */
BrowseEntry * browseEntry; BrowseEntry * browseEntry;
/**
* The tree view showing the search results.
*/
ZebraTreeView * searchResults;
/**
* The pop-up context menu for found items.
*/
Gtk::Menu * contextMenu;
/** /**
* Construct the simple search view. * Construct the simple search view.
* If you enter a string in the simple search view and press Enter * If you enter a string in the simple search view and press Enter
@ -155,12 +165,26 @@ class SearchWindow : public WhiteWindow, public LocalizedObject
void void
onSearch(Ptr<SearchCriteria>::Ref criteria) throw (); onSearch(Ptr<SearchCriteria>::Ref criteria) throw ();
/**
* Signal handler for the mouse clicked on one of the entries.
*
* @param event the button event received
*/
void
onEntryClicked(GdkEventButton * event) throw ();
/**
* Add a playable to the scratchpad.
*/
void
onAddToScratchpad(void) throw ();
/** /**
* The columns model needed by Gtk::TreeView. * The columns model needed by Gtk::TreeView.
* Lists one clip per row. * Lists one clip per row.
* *
* @author $Author: fgerlits $ * @author $Author: fgerlits $
* @version $Revision: 1.7 $ * @version $Revision: 1.8 $
*/ */
class ModelColumns : public ZebraTreeModelColumnRecord class ModelColumns : public ZebraTreeModelColumnRecord
{ {

View file

@ -168,6 +168,8 @@ hu:table
>=OperatorSearchKey:string { ">=" } >=OperatorSearchKey:string { ">=" }
allStringForBrowse { "--- minden ---" } allStringForBrowse { "--- minden ---" }
addToScratchpadMenuItem:string { "_Hasznos csuporba betenni" }
} }
} }

View file

@ -170,6 +170,8 @@ root:table
>=OperatorSearchKey:string { ">=" } >=OperatorSearchKey:string { ">=" }
allStringForBrowse { "--- all ---" } allStringForBrowse { "--- all ---" }
addToScratchpadMenuItem:string { "_Add To Scratchpad" }
} }
} }