Improve context menu selection in card lists
This commit is contained in:
@@ -158,4 +158,28 @@
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkMenu" id="wants_cardListPopup">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkMenuItem" id="wntCrdLst_add">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Add to Library</property>
|
||||
<property name="use_underline">True</property>
|
||||
<signal name="activate" handler="on_want_cards_add_activated" swapped="no"/>
|
||||
<accelerator key="a" signal="activate" modifiers="GDK_CONTROL_MASK"/>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkMenuItem" id="wntCrdLst_remove">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Remove Card</property>
|
||||
<property name="use_underline">True</property>
|
||||
<signal name="activate" handler="on_want_cards_remove_activated" swapped="no"/>
|
||||
<accelerator key="Delete" signal="activate"/>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
||||
|
||||
@@ -265,7 +265,15 @@ class Handlers:
|
||||
list_name = model.get_value(tree_iter, 0)
|
||||
wants_funct.reload_wants_view(self.app, list_name)
|
||||
|
||||
# Handlers for TreeViews etc. wich have been not added by Glade
|
||||
def on_want_cards_add_activated(self, menu_item):
|
||||
# TODO
|
||||
pass
|
||||
|
||||
def on_want_cards_remove_activated(self, menu_item):
|
||||
# TODO
|
||||
pass
|
||||
|
||||
# Handlers for TreeViews etc. which have been not added by Glade
|
||||
|
||||
# ---------------------------------Search Tree----------------------------------------------
|
||||
|
||||
@@ -291,10 +299,16 @@ class Handlers:
|
||||
def on_search_tree_press_event(self, treeview, event):
|
||||
if event.button == 3: # right click
|
||||
path = treeview.get_path_at_pos(int(event.x), int(event.y))
|
||||
if path:
|
||||
tree_iter = treeview.get_model().get_iter(path[0])
|
||||
self.app.ui.get_object("searchListPopup").emit('show')
|
||||
self.app.ui.get_object("searchListPopup").popup(None, None, None, None, 0, event.time)
|
||||
# Get the selection
|
||||
selection = treeview.get_selection()
|
||||
# Get the selected path(s)
|
||||
rows = selection.get_selected_rows()
|
||||
# If not clicked on selection, change selected rows
|
||||
if path[0] not in rows[1]:
|
||||
selection.unselect_all()
|
||||
selection.select_path(path[0])
|
||||
self.app.ui.get_object("searchListPopup").emit('show')
|
||||
self.app.ui.get_object("searchListPopup").popup(None, None, None, None, 0, event.time)
|
||||
return True
|
||||
|
||||
# ---------------------------------Library Tree----------------------------------------------
|
||||
@@ -311,10 +325,16 @@ class Handlers:
|
||||
def on_library_tree_press_event(self, treeview, event):
|
||||
if event.button == 3: # right click
|
||||
path = treeview.get_path_at_pos(int(event.x), int(event.y))
|
||||
if path:
|
||||
tree_iter = treeview.get_model().get_iter(path[0])
|
||||
self.app.ui.get_object("libListPopup").emit('show')
|
||||
self.app.ui.get_object("libListPopup").popup(None, None, None, None, 0, event.time)
|
||||
# Get the selection
|
||||
selection = treeview.get_selection()
|
||||
# Get the selected path(s)
|
||||
rows = selection.get_selected_rows()
|
||||
# If not clicked on selection, change selected rows
|
||||
if path[0] not in rows[1]:
|
||||
selection.unselect_all()
|
||||
selection.select_path(path[0])
|
||||
self.app.ui.get_object("libListPopup").emit('show')
|
||||
self.app.ui.get_object("libListPopup").popup(None, None, None, None, 0, event.time)
|
||||
return True
|
||||
|
||||
# ---------------------------------Wants Tree----------------------------------------------
|
||||
@@ -327,3 +347,22 @@ class Handlers:
|
||||
card_list = self.app.ui.get_object("wantsListContainer").get_child()
|
||||
card = card_list.lib[card_id]
|
||||
self.app.show_card_details(card)
|
||||
|
||||
def on_wants_cards_press_event(self, treeview, event):
|
||||
if event.button == 3: # right click
|
||||
path = treeview.get_path_at_pos(int(event.x), int(event.y))
|
||||
# Get the selection
|
||||
selection = treeview.get_selection()
|
||||
# Get the selected path(s)
|
||||
rows = selection.get_selected_rows()
|
||||
# If not clicked on selection, change selected rows
|
||||
if path[0] not in rows[1]:
|
||||
selection.unselect_all()
|
||||
selection.select_path(path[0])
|
||||
|
||||
# Show popup and emit 'show' to trigger update function of popup
|
||||
self.app.ui.get_object("wants_cardListPopup").emit('show')
|
||||
self.app.ui.get_object("wants_cardListPopup").popup(None, None, None, None, 0, event.time)
|
||||
return True
|
||||
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ def init_wants_view(app: 'application.Application'):
|
||||
card_list.set_name("wantsScroller")
|
||||
# Show details
|
||||
card_list.list.connect("row-activated", app.handlers.on_wants_card_selected)
|
||||
card_list.list.connect("button-press-event", app.handlers.on_wants_cards_press_event)
|
||||
# Add card list to container
|
||||
container.add(card_list)
|
||||
container.add_overlay(app.ui.get_object("wantsOverlay"))
|
||||
|
||||
Reference in New Issue
Block a user