//------------------------------------------------------------------------------ void ListModelWrapper::handle_popup(const int x, const int y, const int time, GdkEventButton* evb) { Gtk::TreeModel::Path path; Gtk::TreeView::Column *column(0); int cell_x(-1); int cell_y(-1); ListModelWrapper::NodeIdArray list = get_selection(); bool there_is_path_at_pos = false; if (_treeview) there_is_path_at_pos = _treeview->get_path_at_pos(x, y, path, column, cell_x, cell_y); else if (_iconview) { path = _iconview->get_path_at_pos(x, y); there_is_path_at_pos = path.gobj() && !path.empty(); } if ( there_is_path_at_pos ) { // Check that @path is on selection, otherwise add @path to selection bec::NodeId node = get_node_for_path(path); // list stores current selection bool path_at_pos_is_in_selection = false; for (int i = list.size() - 1; i >= 0; --i) { if (node == list[i]) { path_at_pos_is_in_selection = true; break; } } if (!path_at_pos_is_in_selection) { // Add it, if user holds Ctrl while clicking right mouse btn // Otherwise clear selection, and select only @path const bool clear_selection = evb ? (!(evb->state & GDK_CONTROL_MASK)) : false; if (clear_selection) { if (_treeview) _treeview->get_selection()->unselect_all(); if (_iconview) _iconview->unselect_all(); } if (_treeview) _treeview->get_selection()->select(path); if (_iconview) _iconview->select_path(path); list = get_selection(); } } if (!_context_menu) _context_menu = new Gtk::Menu(); run_menu_and_forward_action((*_tm)->get_popup_items_for_nodes(list), x, y, time, *_tm, list, _fe_menu_handler, _context_menu); }
//------------------------------------------------------------------------------ ListModelWrapper::NodeIdArray ListModelWrapper::get_selection() const { NodeIdArray nodes; std::vector<Gtk::TreePath> paths; if (_treeview) paths = _treeview->get_selection()->get_selected_rows(); else if (_iconview) paths = _iconview->get_selected_items(); const int size = paths.size(); nodes.reserve(size); for (int i = 0; i < size; ++i) nodes.push_back(get_node_for_path(paths[i])); return nodes; }