Merge lp:~elementary-apps/pantheon-photos/export-dialog-cleanup into lp:~pantheon-photos/pantheon-photos/trunk

Proposed by Danielle Foré
Status: Merged
Approved by: David Hewitt
Approved revision: 3164
Merged at revision: 3166
Proposed branch: lp:~elementary-apps/pantheon-photos/export-dialog-cleanup
Merge into: lp:~pantheon-photos/pantheon-photos/trunk
Diff against target: 237 lines (+75/-94)
1 file modified
src/Dialogs/ExportDialog.vala (+75/-94)
To merge this branch: bzr merge lp:~elementary-apps/pantheon-photos/export-dialog-cleanup
Reviewer Review Type Date Requested Status
David Hewitt code, function Approve
Review via email: mp+317664@code.launchpad.net

Commit message

ExportDialog.vala:
* Better variable names
* GObject-style construction
* Code style
* Don't nest boxes
* Fix Dialog margins
* Spacing and alignment
* Properties, not impure functions

To post a comment you must log in.
Revision history for this message
David Hewitt (davidmhewitt) wrote :

Looks much neater, functionality still works.

review: Approve (code, function)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Dialogs/ExportDialog.vala'
2--- src/Dialogs/ExportDialog.vala 2017-02-16 19:35:47 +0000
3+++ src/Dialogs/ExportDialog.vala 2017-02-17 18:16:54 +0000
4@@ -19,8 +19,6 @@
5 */
6
7 public class ExportDialog : Gtk.Dialog {
8- public const int DEFAULT_SCALE = 1200;
9-
10 // "Unmodified" and "Current," though they appear in the "Format:" popup menu, really
11 // aren't formats so much as they are operating modes that determine specific formats.
12 // Hereafter we'll refer to these as "special formats."
13@@ -38,22 +36,40 @@
14
15 private static ScaleConstraint current_constraint = ScaleConstraint.ORIGINAL;
16 private static ExportFormatParameters current_parameters = ExportFormatParameters.current ();
17- private static int current_scale = DEFAULT_SCALE;
18+ private static int current_scale = 1200;
19
20- private Gtk.Grid table = new Gtk.Grid ();
21 private Gtk.ComboBoxText quality_combo;
22 private Gtk.ComboBoxText constraint_combo;
23 private Gtk.ComboBoxText format_combo;
24 private Gtk.CheckButton export_metadata;
25 private Gee.ArrayList<string> format_options = new Gee.ArrayList<string> ();
26 private Gtk.Entry pixels_entry;
27- private Gtk.Widget ok_button;
28+ private Gtk.Widget export_button;
29 private bool in_insert = false;
30
31 public ExportDialog (string title) {
32- this.title = title;
33- resizable = false;
34- deletable = false;
35+ Object (deletable: false,
36+ resizable: false,
37+ title: title);
38+ }
39+
40+ construct {
41+ var format_label = new Gtk.Label.with_mnemonic (_("_Format:"));
42+ format_label.halign = Gtk.Align.END;
43+ format_label.use_underline = true;
44+ format_label.mnemonic_widget = format_combo;
45+
46+ format_combo = new Gtk.ComboBoxText ();
47+ format_add_option (UNMODIFIED_FORMAT_LABEL);
48+ format_add_option (CURRENT_FORMAT_LABEL);
49+ foreach (PhotoFileFormat format in PhotoFileFormat.get_writeable ()) {
50+ format_add_option (format.get_properties ().get_user_visible_name ());
51+ }
52+
53+ var quality_label = new Gtk.Label.with_mnemonic (_("_Quality:"));
54+ quality_label.halign = Gtk.Align.END;
55+ quality_label.use_underline = true;
56+ quality_label.mnemonic_widget = quality_combo;
57
58 quality_combo = new Gtk.ComboBoxText ();
59 int ctr = 0;
60@@ -64,6 +80,11 @@
61 ctr++;
62 }
63
64+ var constraint_label = new Gtk.Label.with_mnemonic (_("_Scaling constraint:"));
65+ constraint_label.halign = Gtk.Align.END;
66+ constraint_label.use_underline = true;
67+ constraint_label.mnemonic_widget = constraint_combo;
68+
69 constraint_combo = new Gtk.ComboBoxText ();
70 ctr = 0;
71 foreach (ScaleConstraint constraint in CONSTRAINT_ARRAY) {
72@@ -73,70 +94,55 @@
73 ctr++;
74 }
75
76- format_combo = new Gtk.ComboBoxText ();
77- format_add_option (UNMODIFIED_FORMAT_LABEL);
78- format_add_option (CURRENT_FORMAT_LABEL);
79- foreach (PhotoFileFormat format in PhotoFileFormat.get_writeable ()) {
80- format_add_option (format.get_properties ().get_user_visible_name ());
81- }
82-
83 pixels_entry = new Gtk.Entry ();
84- pixels_entry.set_max_length (6);
85- pixels_entry.set_size_request (60, -1);
86- pixels_entry.set_text ("%d".printf (current_scale));
87-
88- // register after preparation to avoid signals during init
89+ pixels_entry.max_length = 6;
90+ pixels_entry.text = "%d".printf (current_scale);
91+ pixels_entry.xalign = 1;
92+
93+ Gtk.Label pixels_label = new Gtk.Label.with_mnemonic (_("_pixels"));
94+ pixels_label.mnemonic_widget = pixels_entry;
95+
96+ export_metadata = new Gtk.CheckButton.with_label (_("Export metadata"));
97+ export_metadata.active = true;
98+
99+ var grid = new Gtk.Grid ();
100+ grid.column_spacing = 12;
101+ grid.row_spacing = 6;
102+ grid.margin = 12;
103+ grid.margin_top = 0;
104+ grid.attach (format_label, 0, 0, 1, 1);
105+ grid.attach (format_combo, 1, 0, 1, 1);
106+ grid.attach (quality_label, 0, 1, 1, 1);
107+ grid.attach (quality_combo, 1, 1, 1, 1);
108+ grid.attach (constraint_label, 0, 2, 1, 1);
109+ grid.attach (constraint_combo, 1, 2, 1, 1);
110+ grid.attach (pixels_entry, 1, 3, 1, 1);
111+ grid.attach (pixels_label, 2, 3, 1, 1);
112+ grid.attach (export_metadata, 1, 4, 1, 1);
113+
114+ ((Gtk.Box) get_content_area ()).add (grid);
115+
116+ add_button (_("_Cancel"), Gtk.ResponseType.CANCEL);
117+
118+ export_button = add_button (_("_Export"), Gtk.ResponseType.OK);
119+ export_button.can_default = true;
120+ export_button.has_default = true;
121+ export_button.grab_focus ();
122+
123+ get_action_area ().margin = 5;
124+
125+ if (current_constraint == ScaleConstraint.ORIGINAL) {
126+ pixels_entry.sensitive = false;
127+ quality_combo.sensitive = false;
128+ }
129+
130 constraint_combo.changed.connect (on_constraint_changed);
131 format_combo.changed.connect (on_format_changed);
132 pixels_entry.changed.connect (on_pixels_changed);
133 pixels_entry.insert_text.connect (on_pixels_insert_text);
134- pixels_entry.activate.connect (on_activate);
135-
136- // layout controls
137- add_label (_ ("_Format:"), 0, 0, format_combo);
138- add_control (format_combo, 1, 0);
139-
140- add_label (_ ("_Quality:"), 0, 1, quality_combo);
141- add_control (quality_combo, 1, 1);
142-
143- add_label (_ ("_Scaling constraint:"), 0, 2, constraint_combo);
144- add_control (constraint_combo, 1, 2);
145-
146- Gtk.Label pixels_label = new Gtk.Label.with_mnemonic (_ (" _pixels"));
147- pixels_label.set_mnemonic_widget (pixels_entry);
148-
149- Gtk.Box pixels_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
150- pixels_box.pack_start (pixels_entry, false, false, 0);
151- pixels_box.pack_end (pixels_label, false, false, 0);
152- add_control (pixels_box, 1, 3);
153-
154- export_metadata = new Gtk.CheckButton.with_label (_ ("Export metadata"));
155- add_control (export_metadata, 1, 4);
156- export_metadata.active = true;
157-
158- table.set_row_spacing (4);
159- table.set_column_spacing (4);
160- table.set_margin_top (4);
161- table.set_margin_bottom (4);
162- table.set_margin_start (4);
163- table.set_margin_end (4);
164-
165- ((Gtk.Box) get_content_area ()).add (table);
166-
167- // add buttons to action area
168- add_button (_ ("_Cancel"), Gtk.ResponseType.CANCEL);
169- ok_button = add_button (_ ("_Export"), Gtk.ResponseType.OK);
170-
171- ok_button.set_can_default (true);
172- ok_button.has_default = true;
173- set_default (ok_button);
174-
175- if (current_constraint == ScaleConstraint.ORIGINAL) {
176- pixels_entry.sensitive = false;
177- quality_combo.sensitive = false;
178- }
179-
180- ok_button.grab_focus ();
181+ pixels_entry.activate.connect (() => {
182+ response (Gtk.ResponseType.OK);
183+ });
184 }
185
186 private void format_add_option (string format_name) {
187@@ -240,27 +246,6 @@
188 return ok;
189 }
190
191- private void add_label (string text, int x, int y, Gtk.Widget? widget = null) {
192- Gtk.Alignment left_aligned = new Gtk.Alignment (0.0f, 0.5f, 0, 0);
193-
194- Gtk.Label new_label = new Gtk.Label.with_mnemonic (text);
195- new_label.set_use_underline (true);
196-
197- if (widget != null)
198- new_label.set_mnemonic_widget (widget);
199-
200- left_aligned.add (new_label);
201-
202- table.attach (left_aligned, x, y, 1, 1);
203- }
204-
205- private void add_control (Gtk.Widget widget, int x, int y) {
206- Gtk.Alignment left_aligned = new Gtk.Alignment (0, 0.5f, 0, 0);
207- left_aligned.add (widget);
208-
209- table.attach (left_aligned, x, y, 1, 1);
210- }
211-
212 private void on_constraint_changed () {
213 bool original = CONSTRAINT_ARRAY[constraint_combo.get_active ()] == ScaleConstraint.ORIGINAL;
214 bool jpeg = format_combo.get_active_text () ==
215@@ -268,7 +253,7 @@
216 pixels_entry.sensitive = !original;
217 quality_combo.sensitive = !original && jpeg;
218 if (original)
219- ok_button.sensitive = true;
220+ export_button.sensitive = true;
221 else
222 on_pixels_changed ();
223 }
224@@ -309,12 +294,8 @@
225 }
226 }
227
228- private void on_activate () {
229- response (Gtk.ResponseType.OK);
230- }
231-
232 private void on_pixels_changed () {
233- ok_button.sensitive = (pixels_entry.get_text_length () > 0) && (int.parse (pixels_entry.get_text ()) > 0);
234+ export_button.sensitive = (pixels_entry.get_text_length () > 0) && (int.parse (pixels_entry.get_text ()) > 0);
235 }
236
237 private void on_pixels_insert_text (string text, int length, ref int position) {

Subscribers

People subscribed via source and target branches