Skip to content

Commit 030567b

Browse files
committed
Guard modals, permit only one every time
1 parent 40156d0 commit 030567b

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

src/window.vala

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ namespace Dc {
5757
private Gtk.Box pinned_bar_content;
5858
private int[] pinned_msg_ids = {};
5959

60+
/* Modal dialog guard – only one at a time */
61+
private Adw.Dialog? active_modal = null;
62+
6063
/* Fullscreen image viewer */
6164
private Gtk.Overlay image_viewer_overlay;
6265
private Gtk.Picture image_viewer_picture;
@@ -1092,8 +1095,11 @@ namespace Dc {
10921095

10931096
private void on_new_chat () {
10941097
if (rpc.account_id <= 0) return;
1098+
if (active_modal != null) return;
10951099

10961100
var picker = new ContactPickerDialog (rpc, rpc.account_id);
1101+
active_modal = picker;
1102+
picker.closed.connect (() => { active_modal = null; });
10971103
picker.contact_picked.connect ((contact_id, email) => {
10981104
create_chat_by_email.begin (email);
10991105
});
@@ -1126,8 +1132,11 @@ namespace Dc {
11261132

11271133
private void on_new_group () {
11281134
if (rpc.account_id <= 0) return;
1135+
if (active_modal != null) return;
11291136

11301137
var dialog = new NewGroupDialog (rpc, rpc.account_id);
1138+
active_modal = dialog;
1139+
dialog.closed.connect (() => { active_modal = null; });
11311140
dialog.group_created.connect ((chat_id) => {
11321141
after_group_created.begin (chat_id);
11331142
});
@@ -1670,7 +1679,11 @@ namespace Dc {
16701679
}
16711680

16721681
private void show_settings_dialog () {
1682+
if (active_modal != null) return;
1683+
16731684
var dialog = new SettingsDialog (rpc, this);
1685+
active_modal = dialog;
1686+
dialog.closed.connect (() => { active_modal = null; });
16741687
dialog.account_changed.connect (() => {
16751688
reload_active_account.begin ();
16761689
});
@@ -1728,6 +1741,10 @@ namespace Dc {
17281741
case Gdk.Key.N:
17291742
on_new_chat ();
17301743
return true;
1744+
case Gdk.Key.g:
1745+
case Gdk.Key.G:
1746+
on_new_group ();
1747+
return true;
17311748
case Gdk.Key.comma:
17321749
show_settings_dialog ();
17331750
return true;
@@ -1792,6 +1809,7 @@ namespace Dc {
17921809
private void show_quick_switch_dialog () {
17931810
if (rpc.account_id <= 0) return;
17941811
if (chat_store.get_n_items () == 0) return;
1812+
if (active_modal != null) return;
17951813

17961814
var dialog = new Adw.Dialog ();
17971815
dialog.title = "Switch Chat";
@@ -1893,6 +1911,8 @@ namespace Dc {
18931911

18941912
box.append (inner);
18951913
dialog.child = box;
1914+
active_modal = dialog;
1915+
dialog.closed.connect (() => { active_modal = null; });
18961916
dialog.present (this);
18971917
entry.grab_focus ();
18981918
}
@@ -1912,6 +1932,8 @@ namespace Dc {
19121932
}
19131933

19141934
private void show_keyboard_shortcuts_dialog () {
1935+
if (active_modal != null) return;
1936+
19151937
var dialog = new Adw.Dialog ();
19161938
dialog.title = "Shortcuts";
19171939
dialog.content_width = 400;
@@ -1930,6 +1952,7 @@ namespace Dc {
19301952
list.margin_bottom = 12;
19311953

19321954
add_shortcut_row (list, "New chat", "<Control>n");
1955+
add_shortcut_row (list, "New group", "<Control>g");
19331956
add_shortcut_row (list, "Open settings", "<Control>comma");
19341957
add_shortcut_row (list, "Search in conversation", "<Control>f");
19351958
add_shortcut_row (list, "Quick switch chat", "<Control>k");
@@ -1940,6 +1963,8 @@ namespace Dc {
19401963

19411964
box.append (list);
19421965
dialog.child = box;
1966+
active_modal = dialog;
1967+
dialog.closed.connect (() => { active_modal = null; });
19431968
dialog.present (this);
19441969
}
19451970

0 commit comments

Comments
 (0)