Skip to content

Commit 02973e1

Browse files
authored
SourceDialog: make a dialog (#840)
1 parent a7d8e87 commit 02973e1

2 files changed

Lines changed: 30 additions & 60 deletions

File tree

src/SourceDialog/SourceDialog.vala

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* Corentin Noël <corentin@elementaryos.org>
2020
*/
2121

22-
public class Maya.View.SourceDialog : Gtk.Grid {
22+
public class Maya.View.SourceDialog : Granite.Dialog {
2323
public EventType event_type { get; private set; default=EventType.EDIT;}
2424

2525
private Gtk.Entry name_entry;
@@ -51,18 +51,13 @@ public class Maya.View.SourceDialog : Gtk.Grid {
5151
construct {
5252
widgets_checked = new Gee.HashMap<string, bool> (null, null);
5353

54-
var cancel_button = new Gtk.Button.with_label (_("Cancel"));
55-
create_button = new Gtk.Button.with_label (_("Create"));
54+
var cancel_button = (Gtk.Button) add_button (_("Cancel"), Gtk.ResponseType.CANCEL);
55+
56+
create_button = (Gtk.Button) add_button (_("Create") , Gtk.ResponseType.ACCEPT);
5657

5758
create_button.clicked.connect (save);
5859
cancel_button.clicked.connect (() => go_back ());
5960

60-
var buttonbox = new Gtk.ButtonBox (Gtk.Orientation.HORIZONTAL);
61-
buttonbox.layout_style = Gtk.ButtonBoxStyle.END;
62-
buttonbox.spacing = 6;
63-
buttonbox.pack_end (cancel_button);
64-
buttonbox.pack_end (create_button);
65-
6661
var name_label = new Gtk.Label (_("Name:"));
6762
name_label.xalign = 1;
6863

@@ -229,24 +224,25 @@ public class Maya.View.SourceDialog : Gtk.Grid {
229224
hex_color = "#667885";
230225
});
231226

232-
main_grid = new Gtk.Grid ();
233-
main_grid.row_spacing = 6;
234-
main_grid.column_spacing = 12;
227+
main_grid = new Gtk.Grid () {
228+
margin_top = 12,
229+
margin_end = 12,
230+
margin_start = 12,
231+
margin_bottom = 24,
232+
column_spacing = 12,
233+
row_spacing = 6,
234+
vexpand = true
235+
};
235236
main_grid.attach (type_label, 0, 0);
236237
main_grid.attach (type_combobox, 1, 0);
237238
main_grid.attach (name_label, 0, 1);
238239
main_grid.attach (name_entry, 1, 1);
239240
main_grid.attach (color_label, 0, 2);
240241
main_grid.attach (color_grid, 1, 2);
241242
main_grid.attach (is_default_check, 1, 3);
243+
main_grid.show_all ();
242244

243-
margin = 12;
244-
margin_bottom = 8;
245-
row_spacing = 24;
246-
attach (main_grid, 0, 0);
247-
attach (buttonbox, 0, 1);
248-
249-
show_all ();
245+
get_content_area ().add (main_grid);
250246
}
251247

252248
public void set_source (E.Source? source = null) {

src/Widgets/SourcePopover.vala

Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
public class Calendar.Widgets.SourcePopover : Gtk.Popover {
2121
private GLib.HashTable<string, SourceRow?> src_map;
2222

23-
private Gtk.Stack stack;
2423
private Maya.View.SourceDialog src_dialog = null;
2524

2625
private Gtk.Grid main_grid;
@@ -68,6 +67,7 @@ public class Calendar.Widgets.SourcePopover : Gtk.Popover {
6867
};
6968

7069
main_grid = new Gtk.Grid () {
70+
margin_bottom = 3,
7171
orientation = Gtk.Orientation.VERTICAL
7272
};
7373

@@ -76,18 +76,13 @@ public class Calendar.Widgets.SourcePopover : Gtk.Popover {
7676
main_grid.add (add_calendar_button);
7777
main_grid.add (import_calendar_button);
7878
main_grid.add (accounts_button);
79+
main_grid.show_all ();
7980

80-
stack = new Gtk.Stack () {
81-
margin_bottom = 3
82-
};
83-
stack.add_named (main_grid, "main");
84-
85-
add (stack);
81+
add (main_grid);
8682
populate.begin ();
87-
stack.show_all ();
8883

8984
add_calendar_button.button_release_event.connect (() => {
90-
create_source ();
85+
edit_source ();
9186
return Gdk.EVENT_STOP;
9287
});
9388

@@ -181,17 +176,6 @@ public class Calendar.Widgets.SourcePopover : Gtk.Popover {
181176
source_item.source_has_changed ();
182177
}
183178

184-
private void create_source () {
185-
if (src_dialog == null) {
186-
src_dialog = new Maya.View.SourceDialog ();
187-
src_dialog.go_back.connect (() => {switch_to_main ();});
188-
stack.add_named (src_dialog, "source");
189-
}
190-
191-
src_dialog.set_source (null);
192-
switch_to_source ();
193-
}
194-
195179
private void add_source_to_view (E.Source source) {
196180
if (source.enabled == false)
197181
return;
@@ -234,30 +218,20 @@ public class Calendar.Widgets.SourcePopover : Gtk.Popover {
234218
source_item.show_calendar_removed ();
235219
}
236220

237-
private void edit_source (E.Source source) {
221+
private void edit_source (E.Source? source = null) {
238222
if (src_dialog == null) {
239-
src_dialog = new Maya.View.SourceDialog ();
240-
src_dialog.go_back.connect (() => {switch_to_main ();});
241-
stack.add_named (src_dialog, "source");
223+
src_dialog = new Maya.View.SourceDialog () {
224+
modal = true,
225+
transient_for = ((Gtk.Application) GLib.Application.get_default ()).active_window
226+
};
227+
228+
src_dialog.go_back.connect (() => {
229+
src_dialog.hide ();
230+
});
242231
}
243232

233+
popdown ();
244234
src_dialog.set_source (source);
245-
switch_to_source ();
246-
}
247-
248-
private void switch_to_main () {
249-
main_grid.no_show_all = false;
250-
main_grid.show ();
251-
stack.set_visible_child_full ("main", Gtk.StackTransitionType.SLIDE_RIGHT);
252-
src_dialog.hide ();
253-
src_dialog.no_show_all = true;
254-
}
255-
256-
private void switch_to_source () {
257-
src_dialog.no_show_all = false;
258-
src_dialog.show ();
259-
stack.set_visible_child_full ("source", Gtk.StackTransitionType.SLIDE_LEFT);
260-
main_grid.hide ();
261-
main_grid.no_show_all = true;
235+
src_dialog.present ();
262236
}
263237
}

0 commit comments

Comments
 (0)