Merge lp:~markodolar/pantheon-calculator/pantheon-calculator-fixes into lp:~elementary-apps/pantheon-calculator/trunk

Proposed by MarkoD
Status: Merged
Approved by: Danielle Foré
Approved revision: 297
Merged at revision: 295
Proposed branch: lp:~markodolar/pantheon-calculator/pantheon-calculator-fixes
Merge into: lp:~elementary-apps/pantheon-calculator/trunk
Diff against target: 169 lines (+52/-12)
3 files modified
data/org.pantheon.calculator.gschema.xml (+10/-0)
src/MainWindow.vala (+28/-10)
src/PantheonCalculator.vala (+14/-2)
To merge this branch: bzr merge lp:~markodolar/pantheon-calculator/pantheon-calculator-fixes
Reviewer Review Type Date Requested Status
Danielle Foré ux Approve
Review via email: mp+311885@code.launchpad.net

Commit message

Ctrl+Q for quitting, remember window position.

Description of the change

Fixes 2 bugs:
- Ctrl+Q shortcut to quit calculator
- Remember main window position (size not needed)

Also renamed 2 confusing variable names.

To post a comment you must log in.
Revision history for this message
Danielle Foré (danrabbit) wrote :

Hey Marko, thanks for your branch! In the future, please split up separate, unrelated fixes into separate branches. This makes the branches much easier to review and helps prevent regressions. It also ensures that one fix doesn't get held up by a "needs fixing" status with another fix.

I can confirm that all of the proposed changes work as expected. Would like a double check on the session code :)

Approving, UX

review: Approve (ux)
Revision history for this message
MarkoD (markodolar) wrote :

> Hey Marko, thanks for your branch! In the future, please split up separate,
> unrelated fixes into separate branches. This makes the branches much easier to
> review and helps prevent regressions. It also ensures that one fix doesn't get
> held up by a "needs fixing" status with another fix.
>
> I can confirm that all of the proposed changes work as expected. Would like a
> double check on the session code :)
>
> Approving, UX

Yea, makes sense, will do next time.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/org.pantheon.calculator.gschema.xml'
2--- data/org.pantheon.calculator.gschema.xml 2015-01-24 15:37:13 +0000
3+++ data/org.pantheon.calculator.gschema.xml 2016-11-26 23:10:11 +0000
4@@ -16,5 +16,15 @@
5 <summary>Saves the decimal places for displayed values.</summary>
6 <description>Saves the decimal places for displayed values.</description>
7 </key>
8+ <key name="window-x" type="i">
9+ <default>-100</default>
10+ <summary>Window x position.</summary>
11+ <description>Saved x position of main calculator window.</description>
12+ </key>
13+ <key name="window-y" type="i">
14+ <default>-100</default>
15+ <summary>Window y position.</summary>
16+ <description>Saved y position of main calculator window.</description>
17+ </key>
18 </schema>
19 </schemalist>
20
21=== modified file 'src/MainWindow.vala'
22--- src/MainWindow.vala 2016-11-01 20:58:04 +0000
23+++ src/MainWindow.vala 2016-11-26 23:10:11 +0000
24@@ -31,8 +31,8 @@
25 private Gtk.Button button_calc;
26 private Gtk.Button button_history;
27 private Gtk.Button button_ans;
28- private Gtk.Button button_undo;
29 private Gtk.Button button_del;
30+ private Gtk.Button button_clr;
31 private Gtk.ToggleButton button_extended;
32
33 private Gtk.InfoBar infobar;
34@@ -59,6 +59,12 @@
35 history = new List<History?> ();
36 position = 0;
37
38+ int x = settings.get_int ("window-x");
39+ int y = settings.get_int ("window-y");
40+ if (x != -100 && y != -100) {
41+ move (x, y);
42+ }
43+
44 build_titlebar ();
45 build_ui ();
46
47@@ -66,6 +72,11 @@
48 settings.bind ("entry-content", entry, "text", SettingsBindFlags.DEFAULT);
49
50 this.key_press_event.connect (key_pressed);
51+
52+ delete_event.connect((event) => {
53+ save_state ();
54+ return false;
55+ });
56 }
57
58 private void build_titlebar () {
59@@ -129,9 +140,9 @@
60 button_calc.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
61 button_ans = new Button ("ANS", _("Add last result"));
62 button_ans.sensitive = false;
63- button_undo = new Button ("Del", _("Backspace"));
64- button_del = new Button ("C", _("Clear entry"));
65- button_del.get_style_context ().add_class (Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION);
66+ button_del = new Button ("Del", _("Backspace"));
67+ button_clr = new Button ("C", _("Clear entry"));
68+ button_clr.get_style_context ().add_class (Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION);
69
70 var button_add = new Button (" + ", _("Add"));
71 button_add.function = "+";
72@@ -167,8 +178,8 @@
73 basic_grid.valign = Gtk.Align.FILL;
74
75 basic_grid.attach (entry, 0, 0, 4, 1);
76- basic_grid.attach (button_del, 0, 1, 1, 1);
77- basic_grid.attach (button_undo, 1, 1, 1, 1);
78+ basic_grid.attach (button_clr, 0, 1, 1, 1);
79+ basic_grid.attach (button_del, 1, 1, 1, 1);
80 basic_grid.attach (button_percent, 2, 1, 1, 1);
81 basic_grid.attach (button_div, 3, 1, 1, 1);
82
83@@ -199,8 +210,8 @@
84 entry.activate.connect (button_calc_clicked);
85
86 button_calc.clicked.connect (() => {button_calc_clicked ();});
87- button_undo.clicked.connect (() => {button_undo_clicked ();});
88 button_del.clicked.connect (() => {button_del_clicked ();});
89+ button_clr.clicked.connect (() => {button_clr_clicked ();});
90 button_ans.clicked.connect (() => {button_ans_clicked ();});
91 button_add.clicked.connect (() => {regular_button_clicked (button_add.function);});
92 button_sub.clicked.connect (() => {regular_button_clicked (button_sub.function);});
93@@ -326,7 +337,7 @@
94 entry.set_position (position);
95 }
96
97- private void button_undo_clicked () {
98+ private void button_del_clicked () {
99 position = entry.get_position ();
100 if (entry.get_text ().length > 0) {
101 string new_text = "";
102@@ -350,7 +361,7 @@
103 entry.set_position (position - 1);
104 }
105
106- private void button_del_clicked () {
107+ private void button_clr_clicked () {
108 position = 0;
109 entry.set_text ("");
110 set_focus (entry);
111@@ -410,7 +421,7 @@
112 bool retval = false;
113 switch (key.keyval) {
114 case Gdk.Key.Escape:
115- button_del_clicked ();
116+ button_clr_clicked ();
117 break;
118 case Gdk.Key.KP_Divide:
119 case Gdk.Key.slash:
120@@ -428,5 +439,12 @@
121 }
122 return retval;
123 }
124+
125+ public void save_state () {
126+ int x_pos, y_pos;
127+ get_position (out x_pos, out y_pos);
128+ settings.set_int ("window-x", x_pos);
129+ settings.set_int ("window-y", y_pos);
130+ }
131 }
132 }
133
134=== modified file 'src/PantheonCalculator.vala'
135--- src/PantheonCalculator.vala 2016-09-01 06:57:26 +0000
136+++ src/PantheonCalculator.vala 2016-11-26 23:10:11 +0000
137@@ -16,7 +16,9 @@
138 * with Pantheon Calculator. If not, see http://www.gnu.org/licenses/.
139 */
140
141-namespace PantheonCalculator {
142+namespace PantheonCalculator {
143+ PantheonCalculator.MainWindow window = null;
144+
145 public class PantheonCalculatorApp : Granite.Application {
146 construct {
147 application_id = "org.pantheon.calculator";
148@@ -43,10 +45,20 @@
149 about_comments = "";
150 about_translators = _("translator-credits");
151 about_license_type = Gtk.License.GPL_3_0;
152+
153+ SimpleAction quit_action = new SimpleAction ("quit", null);
154+ quit_action.activate.connect (() => {
155+ if (window != null) {
156+ window.save_state ();
157+ window.destroy ();
158+ }
159+ });
160+ add_action (quit_action);
161+ add_accelerator ("<Control>q", "app.quit", null);
162 }
163
164 public override void activate () {
165- var window = new PantheonCalculator.MainWindow ();
166+ window = new PantheonCalculator.MainWindow ();
167 this.add_window (window);
168 }
169 }

Subscribers

People subscribed via source and target branches

to all changes: