Skip to content

Commit

Permalink
Add back RMB click menu for tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
diegogangl committed Oct 16, 2022
1 parent 4924f84 commit d4f6070
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
6 changes: 1 addition & 5 deletions GTG/gtk/browser/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def __init__(self, requester, app):
self.sidebar = Sidebar(app, app.ds)
self.sidebar_container.set_child(self.sidebar)

self.task_pane = TaskPane(app, self.sort_menu)
self.task_pane = TaskPane(self)
self.open_pane.set_child(self.task_pane)

# Treeviews handlers
Expand Down Expand Up @@ -194,16 +194,12 @@ def _init_context_menus(self):
self.closed_menu = Gtk.PopoverMenu.new_from_model_full(
closed_menu_model, Gtk.PopoverMenuFlags.NESTED
)
self.closed_menu.set_parent(self.tree_stack)
self.closed_menu.set_halign(Gtk.Align.START)
self.closed_menu.set_has_arrow(False)

open_menu_model = builder.get_object('task_menu')
self.open_menu = Gtk.PopoverMenu.new_from_model_full(
open_menu_model, Gtk.PopoverMenuFlags.NESTED
)
self.open_menu.set_parent(self.tree_stack)
self.open_menu.set_halign(Gtk.Align.START)
self.open_menu.set_has_arrow(False)

sort_menu_model = builder.get_object('sort_menu')
Expand Down
39 changes: 33 additions & 6 deletions GTG/gtk/browser/task_pane.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ def unwrap(row, expected_type):
class TaskPane(Gtk.ScrolledWindow):
"""The task pane widget"""

def __init__(self, app, sort_menu):
def __init__(self, browser):

super(TaskPane, self).__init__()
self.ds = app.ds
self.app = app
self.ds = browser.app.ds
self.app = browser.app
self.browser = browser

self.set_vexpand(True)
self.set_hexpand(True)
Expand Down Expand Up @@ -77,7 +78,7 @@ def __init__(self, app, sort_menu):

sort_btn = Gtk.MenuButton()
sort_btn.set_icon_name('view-more-symbolic')
sort_btn.set_popover(sort_menu)
sort_btn.set_popover(browser.sort_menu)
sort_btn.add_css_class('flat')

title_box.append(sort_btn)
Expand All @@ -88,8 +89,8 @@ def __init__(self, app, sort_menu):
# -------------------------------------------------------------------------------

filtered = Gtk.FilterListModel()
self.filter = TaskFilter(app.ds, Status.ACTIVE)
filtered.set_model(app.ds.tasks.tree_model)
self.filter = TaskFilter(self.app.ds, Status.ACTIVE)
filtered.set_model(self.app.ds.tasks.tree_model)
filtered.set_filter(self.filter)

self.sort_model = Gtk.TreeListRowSorter()
Expand Down Expand Up @@ -254,6 +255,10 @@ def task_setup_cb(self, factory, listitem, user_data=None):

# box.add_controller(drop)

task_RMB_controller = Gtk.GestureSingle(button=Gdk.BUTTON_SECONDARY)
task_RMB_controller.connect('end', self.on_task_RMB_click)
box.add_controller(task_RMB_controller)

box.append(expander)
box.append(check)
box.append(label)
Expand Down Expand Up @@ -389,3 +394,25 @@ def drag_end(self, source, drag, unused):

if source.get_widget():
source.get_widget().set_opacity(1)


def on_task_RMB_click(self, gesture, sequence) -> None:
"""Callback when right-clicking on an open task."""

task = gesture.get_widget().task

if task.status == Status.ACTIVE:
menu = self.browser.open_menu
else:
menu = self.browser.closed_menu

menu.set_parent(gesture.get_widget())
menu.set_halign(Gtk.Align.START)
menu.set_position(Gtk.PositionType.BOTTOM)

point = gesture.get_point(sequence)
rect = Gdk.Rectangle()
rect.x = point.x
rect.y = point.y
menu.set_pointing_to(rect)
menu.popup()

0 comments on commit d4f6070

Please sign in to comment.