Skip to content

Commit 2b386c2

Browse files
committed
Fix regression in contact context menu not working
1 parent c3d906f commit 2b386c2

2 files changed

Lines changed: 34 additions & 23 deletions

File tree

src/chat_row.vala

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -152,40 +152,48 @@ namespace Dc {
152152
var entry = find_chat_entry (chat_store, chat_id);
153153
if (entry != null) is_pinned = entry.is_pinned;
154154

155-
var menu = new GLib.Menu ();
156-
menu.append (is_pinned ? "Unpin" : "Pin", "win.chat-pin");
157-
menu.append ("Chat Info", "win.chat-info");
158-
menu.append ("Delete for Me", "win.chat-delete");
155+
var popover = new Gtk.Popover ();
156+
popover.has_arrow = false;
157+
popover.set_parent (parent);
158+
popover.set_pointing_to ({ (int) x, (int) y, 1, 1 });
159+
160+
var box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
161+
box.add_css_class ("menu");
159162

160-
var pin_action = new SimpleAction ("chat-pin", null);
161-
pin_action.activate.connect (() => {
163+
var pin_btn = make_menu_button (is_pinned ? "Unpin" : "Pin");
164+
pin_btn.clicked.connect (() => {
165+
popover.popdown ();
162166
toggle_pin.begin (chat_id, is_pinned);
163167
});
164-
var info_action = new SimpleAction ("chat-info", null);
165-
info_action.activate.connect (() => {
168+
box.append (pin_btn);
169+
170+
var info_btn = make_menu_button ("Chat Info");
171+
info_btn.clicked.connect (() => {
172+
popover.popdown ();
166173
show_info.begin (chat_id);
167174
});
168-
var delete_action = new SimpleAction ("chat-delete", null);
169-
delete_action.activate.connect (() => {
175+
box.append (info_btn);
176+
177+
var del_btn = make_menu_button ("Delete for Me");
178+
del_btn.clicked.connect (() => {
179+
popover.popdown ();
170180
confirm_delete.begin (chat_id);
171181
});
182+
box.append (del_btn);
172183

173-
window.add_action (pin_action);
174-
window.add_action (info_action);
175-
window.add_action (delete_action);
176-
177-
var popover = new Gtk.PopoverMenu.from_model (menu);
178-
popover.set_parent (parent);
179-
popover.set_pointing_to ({ (int) x, (int) y, 1, 1 });
180-
popover.closed.connect (() => {
181-
window.remove_action ("chat-pin");
182-
window.remove_action ("chat-info");
183-
window.remove_action ("chat-delete");
184-
popover.unparent ();
185-
});
184+
popover.child = box;
185+
popover.closed.connect (() => { popover.unparent (); });
186186
popover.popup ();
187187
}
188188

189+
private static Gtk.Button make_menu_button (string label) {
190+
var btn = new Gtk.Button.with_label (label);
191+
btn.add_css_class ("flat");
192+
((Gtk.Label) btn.child).xalign = 0;
193+
((Gtk.Label) btn.child).halign = Gtk.Align.START;
194+
return btn;
195+
}
196+
189197
private async void toggle_pin (int chat_id, bool currently_pinned) {
190198
try {
191199
string visibility = currently_pinned ? "Normal" : "Pinned";

src/window.vala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,21 @@ namespace Dc {
122122

123123
chat_listbox = new Gtk.ListBox ();
124124
chat_listbox.selection_mode = Gtk.SelectionMode.SINGLE;
125+
chat_listbox.can_focus = false;
125126
chat_listbox.add_css_class ("navigation-sidebar");
126127
chat_listbox.set_filter_func (filter_chats);
127128
chat_listbox.row_selected.connect (on_chat_selected);
128129

129130
/* Right-click context menu */
130131
var right_click = new Gtk.GestureClick ();
131132
right_click.button = 3; /* secondary button */
133+
right_click.propagation_phase = Gtk.PropagationPhase.CAPTURE;
132134
right_click.pressed.connect ((n, x, y) => {
133135
var row = chat_listbox.get_row_at_y ((int) y);
134136
if (row == null) return;
135137
var chat_row = row.child as ChatRow;
136138
if (chat_row == null) return;
139+
right_click.set_state (Gtk.EventSequenceState.CLAIMED);
137140
if (chat_menu != null)
138141
chat_menu.show (chat_row.chat_id, x, y, chat_listbox);
139142
});

0 commit comments

Comments
 (0)