Merge lp:~tintou/pantheon-calculator/animating-simplify into lp:~elementary-apps/pantheon-calculator/trunk

Proposed by Corentin Noël
Status: Merged
Approved by: Marvin Beckers
Approved revision: 119
Merged at revision: 126
Proposed branch: lp:~tintou/pantheon-calculator/animating-simplify
Merge into: lp:~elementary-apps/pantheon-calculator/trunk
Diff against target: 634 lines (+251/-226)
4 files modified
CMakeLists.txt (+1/-0)
src/Button.vala (+49/-0)
src/HistoryDialog.vala (+0/-4)
src/MainWindow.vala (+201/-222)
To merge this branch: bzr merge lp:~tintou/pantheon-calculator/animating-simplify
Reviewer Review Type Date Requested Status
Marvin Beckers (community) Approve
Review via email: mp+253083@code.launchpad.net

Commit message

Using a custom Button class that takes care of the size request and using Gtk.Revealer to reveal the advanced panel.

Description of the change

Using a custom Button class that takes care of the size request.
Using Gtk.Revealer to reveal the advanced panel.

To post a comment you must log in.
119. By Corentin Noël

Fixed Infobar.

Revision history for this message
Marvin Beckers (embik) wrote :

Works as a charm! Wasn't really able to review this before, sorry for that.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2015-02-09 19:41:46 +0000
3+++ CMakeLists.txt 2015-03-16 17:25:23 +0000
4@@ -39,6 +39,7 @@
5 include(ValaPrecompile)
6 vala_precompile(VALA_C ${EXEC_NAME}
7 src/PantheonCalculator.vala
8+ src/Button.vala
9 src/MainWindow.vala
10 src/HistoryDialog.vala
11 src/Core/Stack.vala
12
13=== added file 'src/Button.vala'
14--- src/Button.vala 1970-01-01 00:00:00 +0000
15+++ src/Button.vala 2015-03-16 17:25:23 +0000
16@@ -0,0 +1,49 @@
17+/*-
18+ * Copyright (c) 2012-2013 Pantheon Calculator Developers (http://launchpad.net/pantheon-calculator)
19+ *
20+ * This file is part of Pantheon Calculator
21+ *
22+ * Pantheon Calculator is free software: you can redistribute it
23+ * and/or modify it under the terms of the GNU General Public License as
24+ * published by the Free Software Foundation, either version 3 of the
25+ * License, or (at your option) any later version.
26+ *
27+ * Pantheon Calculator is distributed in the hope that it will be
28+ * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
29+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
30+ * Public License for more details.
31+ *
32+ * You should have received a copy of the GNU General Public License along
33+ * with Pantheon Calculator. If not, see http://www.gnu.org/licenses/.
34+ *
35+ * Authored by: Corentin Noël <corentin@elementaryos.io>
36+ */
37+
38+public class PantheonCalculator.Button : Gtk.Button {
39+ private const int WIDTH = 65;
40+ private const int HEIGHT = 45;
41+ public string function = null;
42+
43+ public Button (string label, string? description = null) {
44+ function = label;
45+ var lbl = new Gtk.Label (label);
46+ lbl.use_markup = true;
47+ image = lbl;
48+ tooltip_text = description;
49+ }
50+
51+ public Button.from_icon_name (string icon_name, string? description = null) {
52+ image = new Gtk.Image.from_icon_name (icon_name, Gtk.IconSize.BUTTON);
53+ tooltip_text = description;
54+ }
55+
56+ public override void get_preferred_width (out int minimum_width, out int natural_width) {
57+ minimum_width = WIDTH;
58+ natural_width = WIDTH;
59+ }
60+
61+ public override void get_preferred_height (out int minimum_height, out int natural_height) {
62+ minimum_height = HEIGHT;
63+ natural_height = HEIGHT;
64+ }
65+}
66
67=== modified file 'src/HistoryDialog.vala'
68--- src/HistoryDialog.vala 2015-01-16 17:09:51 +0000
69+++ src/HistoryDialog.vala 2015-03-16 17:25:23 +0000
70@@ -16,10 +16,6 @@
71 * with Pantheon Calculator. If not, see http://www.gnu.org/licenses/.
72 */
73
74-using Gtk;
75-using PantheonCalculator.Core;
76-using Granite.Widgets;
77-
78 namespace PantheonCalculator {
79 public class HistoryDialog : Gtk.Dialog {
80 private unowned List<MainWindow.History?> history;
81
82=== modified file 'src/MainWindow.vala'
83--- src/MainWindow.vala 2015-02-09 19:41:46 +0000
84+++ src/MainWindow.vala 2015-03-16 17:25:23 +0000
85@@ -16,15 +16,13 @@
86 * with Pantheon Calculator. If not, see http://www.gnu.org/licenses/.
87 */
88
89-using Granite.Widgets;
90-using PantheonCalculator.Core;
91-
92 namespace PantheonCalculator {
93 public class MainWindow : Gtk.Window {
94 private Settings settings;
95
96 private Gtk.HeaderBar headerbar;
97 private Gtk.Grid main_grid;
98+ private Gtk.Revealer extended_revealer;
99 private Gtk.Entry entry;
100
101 // widgets I need to access
102@@ -36,12 +34,11 @@
103 private Gtk.Button button_undo;
104 private Gtk.Button button_del;
105 private Gtk.ToggleButton button_extended;
106- private Gtk.InfoBar? infobar;
107- private Gtk.Button button_pow;
108- private Gtk.Box margin_box;
109-
110- private List<weak Gtk.Button> basic_button_list;
111- private List<weak Gtk.Button> extended_button_list;
112+
113+ private Gtk.InfoBar infobar;
114+ private Gtk.Label infobar_label;
115+
116+ private Gtk.Grid global_grid;
117
118 private List<History?> history;
119 private int position;
120@@ -51,14 +48,6 @@
121
122 public struct History { string exp; string output; }
123
124- private string[] regular_buttons = { "0", "1", "2", "3", "4", "5",
125- "6", "7", "8", "9", "0", " + ",
126- " − ", " × ", " ÷ ", "%", ".", "(",
127- ")", "^", "π", "e", Posix.nl_langinfo (Posix.NLItem.RADIXCHAR)};
128-
129- private string[] function_buttons = { "sin", "cos", "tan", "√", "sinh", "cosh",
130- "tanh" , "sqrt"};
131-
132 public MainWindow () {
133 set_resizable (false);
134 window_position = Gtk.WindowPosition.CENTER;
135@@ -72,8 +61,6 @@
136 build_titlebar ();
137 build_ui ();
138
139- button_extended.set_active (settings.get_boolean ("extended-shown"));
140-
141 this.destroy.connect (() => {
142 debug ("saving settings to gsettings");
143 settings.set_boolean ("extended-shown", button_extended.get_active ());
144@@ -83,26 +70,24 @@
145
146 private void build_titlebar () {
147 headerbar = new Gtk.HeaderBar ();
148- headerbar.get_style_context ().add_class ("primary-toolbar");
149 headerbar.show_close_button = true;
150 headerbar.set_title (_("Calculator"));
151 set_titlebar (headerbar);
152
153 extended_img_1 = new Gtk.Image.from_icon_name ("pane-hide-symbolic", Gtk.IconSize.LARGE_TOOLBAR);
154 extended_img_2 = new Gtk.Image.from_icon_name ("pane-show-symbolic", Gtk.IconSize.LARGE_TOOLBAR);
155- var history_img = new Gtk.Image.from_icon_name ("document-open-recent-symbolic", Gtk.IconSize.LARGE_TOOLBAR);
156
157 button_extended = new Gtk.ToggleButton ();
158- button_extended.set_property ("image", extended_img_1);
159- button_extended.set_tooltip_text (_("Show extended functionality"));
160- button_extended.set_relief (Gtk.ReliefStyle.NONE);
161+ button_extended.image = extended_img_1;
162+ button_extended.tooltip_text = _("Show extended functionality");
163+ button_extended.relief = Gtk.ReliefStyle.NONE;
164 button_extended.toggled.connect (toggle_grid);
165
166 button_history = new Gtk.Button ();
167- button_history.set_property ("image", history_img);
168- button_history.set_tooltip_text (_("History"));
169- button_history.set_relief (Gtk.ReliefStyle.NONE);
170- button_history.set_sensitive (false);
171+ button_history.image = new Gtk.Image.from_icon_name ("document-open-recent-symbolic", Gtk.IconSize.LARGE_TOOLBAR);
172+ button_history.tooltip_text = _("History");
173+ button_history.relief = Gtk.ReliefStyle.NONE;
174+ button_history.sensitive = false;
175 button_history.clicked.connect (show_history);
176
177 headerbar.pack_end (button_extended);
178@@ -112,212 +97,214 @@
179 private void build_ui () {
180 main_grid = new Gtk.Grid ();
181 main_grid.orientation = Gtk.Orientation.VERTICAL;
182- main_grid.set_column_spacing (2);
183- main_grid.set_row_spacing (2);
184- main_grid.margin = 5;
185+ main_grid.row_spacing = 3;
186+ main_grid.margin = 6;
187 main_grid.expand = true;
188 main_grid.halign = Gtk.Align.CENTER;
189
190 build_basic_ui ();
191 build_extended_ui ();
192-
193- add (main_grid);
194+ button_extended.active = settings.get_boolean ("extended-shown");
195+
196+ infobar = new Gtk.InfoBar ();
197+ infobar_label = new Gtk.Label ("");
198+ infobar.get_content_area ().add (infobar_label);
199+ infobar.show_close_button = false;
200+ infobar.message_type = Gtk.MessageType.ERROR;
201+ infobar.no_show_all = true;
202+
203+ global_grid = new Gtk.Grid ();
204+ global_grid.orientation = Gtk.Orientation.VERTICAL;
205+ global_grid.add (infobar);
206+ global_grid.add (main_grid);
207+
208+ add (global_grid);
209 show_all ();
210-
211- toggle_grid (button_extended);
212 }
213
214 private void build_basic_ui () {
215 entry = new Gtk.Entry ();
216 entry.set_text (settings.get_string ("entry-content"));
217-
218- button_calc = new Gtk.Button.with_label ("=");
219- button_ans = new Gtk.Button.with_label ("ANS");
220- button_undo = new Gtk.Button.from_icon_name ("go-previous-symbolic", Gtk.IconSize.SMALL_TOOLBAR);
221- button_del = new Gtk.Button.with_label ("C");
222-
223- var button_add = new Gtk.Button.with_label (" + ");
224- var button_sub = new Gtk.Button.with_label (" − ");
225- var button_mult = new Gtk.Button.with_label (" × ");
226- var button_div = new Gtk.Button.with_label (" ÷ ");
227-
228- var button_0 = new Gtk.Button.with_label ("0");
229- var button_point = new Gtk.Button.with_label (Posix.nl_langinfo (Posix.NLItem.RADIXCHAR));
230- var button_percent = new Gtk.Button.with_label ("%");
231- var button_1 = new Gtk.Button.with_label ("1");
232- var button_2 = new Gtk.Button.with_label ("2");
233- var button_3 = new Gtk.Button.with_label ("3");
234-
235- var button_4 = new Gtk.Button.with_label ("4");
236- var button_5 = new Gtk.Button.with_label ("5");
237- var button_6 = new Gtk.Button.with_label ("6");
238-
239- var button_7 = new Gtk.Button.with_label ("7");
240- var button_8 = new Gtk.Button.with_label ("8");
241- var button_9 = new Gtk.Button.with_label ("9");
242-
243- button_ans.set_sensitive (false);
244-
245- //add style context to widgets
246 entry.get_style_context ().add_class ("h2");
247+
248+ button_calc = new Button ("=", _("Calculate Result"));
249+ button_calc.get_style_context ().add_class ("h2");
250+ button_calc.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
251+ button_ans = new Button ("ANS", _("Add last result"));
252+ button_ans.sensitive = false;
253+ button_undo = new Button.from_icon_name ("go-previous-symbolic", _("Backspace"));
254+ button_del = new Button ("C", _("Clear entry"));
255 button_del.get_style_context ().add_class (Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION);
256+
257+ var button_add = new Button (" + ", _("Add"));
258+ button_add.function = "+";
259 button_add.get_style_context ().add_class ("h3");
260+ var button_sub = new Button (" − ", _("Subtract"));
261+ button_sub.function = "−";
262 button_sub.get_style_context ().add_class ("h3");
263+ var button_mult = new Button (" × ", _("Multiply"));
264+ button_mult.function = "×";
265 button_mult.get_style_context ().add_class ("h3");
266+ var button_div = new Button (" ÷ ", _("Divide"));
267+ button_div.function = "÷";
268 button_div.get_style_context ().add_class ("h3");
269- button_calc.get_style_context ().add_class ("h2");
270- button_calc.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
271-
272- //set tooltips for widgets
273- button_del.set_tooltip_text (_("Clear entry"));
274- button_undo.set_tooltip_text (_("Backspace"));
275- button_ans.set_tooltip_text (_("Add last result"));
276-
277- //set size for some widgets to get desired layout
278- entry.set_size_request (0, 45);
279- button_0.set_size_request (65, 45);
280- button_1.set_size_request (65, 45);
281- button_4.set_size_request (65, 45);
282- button_7.set_size_request (65, 45);
283-
284- button_undo.set_size_request (65, 45);
285- button_del.set_size_request (65, 45);
286- button_percent.set_size_request (65, 45);
287- button_add.set_size_request (65, 45);
288+
289+ var button_0 = new Button ("0");
290+ var button_point = new Button (Posix.nl_langinfo (Posix.NLItem.RADIXCHAR));
291+ var button_percent = new Button ("%", _("Percentage"));
292+ var button_1 = new Button ("1");
293+ var button_2 = new Button ("2");
294+ var button_3 = new Button ("3");
295+
296+ var button_4 = new Button ("4");
297+ var button_5 = new Button ("5");
298+ var button_6 = new Button ("6");
299+
300+ var button_7 = new Button ("7");
301+ var button_8 = new Button ("8");
302+ var button_9 = new Button ("9");
303+
304+ var basic_grid = new Gtk.Grid ();
305+ basic_grid.column_spacing = 3;
306+ basic_grid.row_spacing = 3;
307+ basic_grid.valign = Gtk.Align.END;
308+ basic_grid.attach (button_del, 0, 0, 1, 1);
309+ basic_grid.attach (button_undo, 1, 0, 1, 1);
310+ basic_grid.attach (button_percent, 2, 0, 1, 1);
311+ basic_grid.attach (button_div, 3, 0, 1, 1);
312+
313+ basic_grid.attach (button_7, 0, 1, 1, 1);
314+ basic_grid.attach (button_8, 1, 1, 1, 1);
315+ basic_grid.attach (button_9, 2, 1, 1, 1);
316+ basic_grid.attach (button_mult, 3, 1, 1, 1);
317+
318+ basic_grid.attach (button_4, 0, 2, 1, 1);
319+ basic_grid.attach (button_5, 1, 2, 1, 1);
320+ basic_grid.attach (button_6, 2, 2, 1, 1);
321+ basic_grid.attach (button_sub, 3, 2, 1, 1);
322+
323+ basic_grid.attach (button_1, 0, 3, 1, 1);
324+ basic_grid.attach (button_2, 1, 3, 1, 1);
325+ basic_grid.attach (button_3, 2, 3, 1, 1);
326+ basic_grid.attach (button_add, 3, 3, 1, 1);
327+
328+ basic_grid.attach (button_0, 0, 4, 1, 1);
329+ basic_grid.attach (button_point, 1, 4, 1, 1);
330+ basic_grid.attach (button_ans, 2, 4, 1, 1);
331+ basic_grid.attach (button_calc, 3, 4, 1, 1);
332
333 //attach all widgets
334- main_grid.attach (entry, 0, 0, 4, 1);
335+ main_grid.attach (entry, 0, 0, 1, 1);
336+ main_grid.attach (basic_grid, 0, 1, 1, 1);
337
338 entry.changed.connect (remove_error);
339 entry.activate.connect (button_calc_clicked);
340
341- basic_button_list.append (button_del);
342- basic_button_list.append (button_7);
343- basic_button_list.append (button_4);
344- basic_button_list.append (button_1);
345- basic_button_list.append (button_0);
346-
347- basic_button_list.append (button_undo);
348- basic_button_list.append (button_8);
349- basic_button_list.append (button_5);
350- basic_button_list.append (button_2);
351- basic_button_list.append (button_point);
352-
353- basic_button_list.append (button_percent);
354- basic_button_list.append (button_9);
355- basic_button_list.append (button_6);
356- basic_button_list.append (button_3);
357- basic_button_list.append (button_ans);
358-
359- basic_button_list.append (button_div);
360- basic_button_list.append (button_mult);
361- basic_button_list.append (button_sub);
362- basic_button_list.append (button_add);
363- basic_button_list.append (button_calc);
364-
365- int pos = 0;
366- foreach (Gtk.Button b_button in basic_button_list) {
367- main_grid.attach (b_button, (pos / 5), (pos % 5 + 1), 1, 1);
368- b_button.clicked.connect (button_clicked);
369- pos++;
370- }
371+ button_calc.clicked.connect (() => {button_calc_clicked ();});
372+ button_undo.clicked.connect (() => {button_undo_clicked ();});
373+ button_del.clicked.connect (() => {button_del_clicked ();});
374+ button_ans.clicked.connect (() => {button_ans_clicked ();});
375+ button_add.clicked.connect (() => {regular_button_clicked (button_add.function);});
376+ button_sub.clicked.connect (() => {regular_button_clicked (button_sub.function);});
377+ button_mult.clicked.connect (() => {regular_button_clicked (button_mult.function);});
378+ button_div.clicked.connect (() => {regular_button_clicked (button_div.function);});
379+ button_0.clicked.connect (() => {regular_button_clicked (button_0.function);});
380+ button_1.clicked.connect (() => {regular_button_clicked (button_1.function);});
381+ button_2.clicked.connect (() => {regular_button_clicked (button_2.function);});
382+ button_3.clicked.connect (() => {regular_button_clicked (button_3.function);});
383+ button_4.clicked.connect (() => {regular_button_clicked (button_4.function);});
384+ button_5.clicked.connect (() => {regular_button_clicked (button_5.function);});
385+ button_6.clicked.connect (() => {regular_button_clicked (button_6.function);});
386+ button_7.clicked.connect (() => {regular_button_clicked (button_7.function);});
387+ button_8.clicked.connect (() => {regular_button_clicked (button_8.function);});
388+ button_9.clicked.connect (() => {regular_button_clicked (button_9.function);});
389+ button_point.clicked.connect (() => {regular_button_clicked (button_point.function);});
390+ button_percent.clicked.connect (() => {regular_button_clicked (button_percent.function);});
391 }
392
393 private void build_extended_ui () {
394- button_pow = new Gtk.Button ();
395- var pow_label = new Gtk.Label ("x<sup>y</sup>");
396- pow_label.set_use_markup (true);
397- button_pow.add (pow_label);
398-
399- var button_sin = new Gtk.Button.with_label ("sin");
400- var button_cos = new Gtk.Button.with_label ("cos");
401- var button_tan = new Gtk.Button.with_label ("tan");
402- var button_pi = new Gtk.Button.with_label ("π");
403- var button_par_left = new Gtk.Button.with_label ("(");
404-
405- var button_sr = new Gtk.Button.with_label ("√");
406- var button_sinh = new Gtk.Button.with_label ("sinh");
407- var button_cosh = new Gtk.Button.with_label ("cosh");
408- var button_tanh = new Gtk.Button.with_label ("tanh");
409- var button_e = new Gtk.Button.with_label ("e");
410- var button_par_right = new Gtk.Button.with_label (")");
411-
412- //set size for some widgets to get desired layout
413- button_par_left.set_size_request (65, 45);
414- button_par_right.set_size_request (65, 45);
415-
416- margin_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
417- margin_box.set_size_request (0, 12);
418- main_grid.attach (margin_box, 4, 0, 1, 6);
419-
420- extended_button_list.append (button_par_left);
421- extended_button_list.append (button_pow);
422- extended_button_list.append (button_sin);
423- extended_button_list.append (button_cos);
424- extended_button_list.append (button_tan);
425- extended_button_list.append (button_pi);
426-
427- extended_button_list.append (button_par_right);
428- extended_button_list.append (button_sr);
429- extended_button_list.append (button_sinh);
430- extended_button_list.append (button_cosh);
431- extended_button_list.append (button_tanh);
432- extended_button_list.append (button_e);
433-
434- int pos = 0;
435- foreach (Gtk.Button e_button in extended_button_list) {
436- main_grid.attach (e_button, (pos / 6 + 5), (pos % 6), 1, 1);
437- e_button.clicked.connect (button_clicked);
438- pos++;
439- }
440- }
441-
442- private void button_clicked (Gtk.Button btn) {
443- if (btn == button_calc)
444- button_calc_clicked ();
445- else if (btn == button_undo)
446- button_undo_clicked ();
447- else if (btn == button_del)
448- button_del_clicked ();
449- else if (btn == button_ans)
450- button_ans_clicked ();
451- else {
452- string label = btn.get_label ();
453- if (btn == button_pow)
454- label = "^";
455-
456- bool is_function = label in function_buttons;
457- bool is_regular = label in regular_buttons;
458-
459- if (!is_function && !is_regular)
460- return;
461-
462- int selection_start = -1;
463- int selection_end = -1;
464- int new_position = entry.get_position ();
465-
466- if (is_function && entry.get_selection_bounds (out selection_start, out selection_end)) {
467- string selected_text = entry.get_chars (selection_start, selection_end);
468- string function_call = label + "(" + selected_text + ")";
469- entry.delete_text (selection_start, selection_end);
470- entry.insert_text (function_call, -1, ref selection_start);
471- new_position += function_call.length;
472- } else {
473- entry.insert_at_cursor (label);
474- new_position += label.length;
475- }
476-
477+ var button_par_left = new Button ("(", _("Start Group"));
478+ var button_par_right = new Button (")", _("End Group"));
479+ var button_pow = new Button ("x<sup>y</sup>", _("Exponent"));
480+ button_pow.function = "^";
481+ var button_sr = new Button ("√", _("Root"));
482+ var button_sin = new Button ("sin", _("Sine"));
483+ var button_sinh = new Button ("sinh", _("Hyperbolic Sine"));
484+ var button_cos = new Button ("cos", _("Cosine"));
485+ var button_cosh = new Button ("cosh", _("Hyperbolic Cosine"));
486+ var button_tan = new Button ("tan", _("Tangent"));
487+ var button_tanh = new Button ("tanh", _("Hyperbolic Tangent"));
488+ var button_pi = new Button ("π", _("Pi"));
489+ var button_e = new Button ("e", _("Euler's Number"));
490+
491+ var extended_grid = new Gtk.Grid ();
492+ extended_grid.margin_start = 3;
493+ extended_grid.column_spacing = 3;
494+ extended_grid.row_spacing = 3;
495+ extended_grid.valign = Gtk.Align.END;
496+ extended_grid.attach (button_par_left, 0, 0, 1, 1);
497+ extended_grid.attach (button_par_right, 1, 0, 1, 1);
498+ extended_grid.attach (button_pow, 0, 1, 1, 1);
499+ extended_grid.attach (button_sr, 1, 1, 1, 1);
500+ extended_grid.attach (button_sin, 0, 2, 1, 1);
501+ extended_grid.attach (button_sinh, 1, 2, 1, 1);
502+ extended_grid.attach (button_cos, 0, 3, 1, 1);
503+ extended_grid.attach (button_cosh, 1, 3, 1, 1);
504+ extended_grid.attach (button_tan, 0, 4, 1, 1);
505+ extended_grid.attach (button_tanh, 1, 4, 1, 1);
506+ extended_grid.attach (button_pi, 0, 5, 1, 1);
507+ extended_grid.attach (button_e, 1, 5, 1, 1);
508+
509+ extended_revealer = new Gtk.Revealer ();
510+ extended_revealer.set_transition_type (Gtk.RevealerTransitionType.SLIDE_LEFT);
511+ extended_revealer.show_all ();
512+ extended_revealer.add (extended_grid);
513+ main_grid.attach (extended_revealer, 1, 0, 1, 2);
514+
515+ button_pi.clicked.connect (() => {regular_button_clicked (button_pi.function);});
516+ button_e.clicked.connect (() => {regular_button_clicked (button_e.function);});
517+ button_pow.clicked.connect (() => {regular_button_clicked (button_pow.function);});
518+ button_par_left.clicked.connect (() => {regular_button_clicked (button_par_left.function);});
519+ button_par_right.clicked.connect (() => {regular_button_clicked (button_par_right.function);});
520+ button_sr.clicked.connect (() => {function_button_clicked (button_sr.function);});
521+ button_sin.clicked.connect (() => {function_button_clicked (button_sin.function);});
522+ button_sinh.clicked.connect (() => {function_button_clicked (button_sinh.function);});
523+ button_cos.clicked.connect (() => {function_button_clicked (button_cos.function);});
524+ button_cosh.clicked.connect (() => {function_button_clicked (button_cosh.function);});
525+ button_tan.clicked.connect (() => {function_button_clicked (button_tan.function);});
526+ button_tanh.clicked.connect (() => {function_button_clicked (button_tanh.function);});
527+ }
528+
529+ private void regular_button_clicked (string label) {
530+ int new_position = entry.get_position ();
531+ entry.insert_at_cursor (label);
532+ new_position += label.length;
533+ entry.grab_focus ();
534+ entry.set_position (new_position);
535+ }
536+
537+ private void function_button_clicked (string label) {
538+ int selection_start = -1;
539+ int selection_end = -1;
540+ int new_position = entry.get_position ();
541+ if (entry.get_selection_bounds (out selection_start, out selection_end)) {
542+ string selected_text = entry.get_chars (selection_start, selection_end);
543+ string function_call = label + "(" + selected_text + ")";
544+ entry.delete_text (selection_start, selection_end);
545+ entry.insert_text (function_call, -1, ref selection_start);
546+ new_position += function_call.length;
547 entry.grab_focus ();
548 entry.set_position (new_position);
549+ } else {
550+ regular_button_clicked (label);
551 }
552 }
553
554 private void button_calc_clicked () {
555 position = entry.get_position ();
556- remove_error ();
557 if (entry.get_text () != "") {
558 try {
559- var output = Evaluation.evaluate (entry.get_text (), decimal_places);
560+ var output = Core.Evaluation.evaluate (entry.get_text (), decimal_places);
561 if (entry.get_text () != output) {
562 history.append (History () { exp = entry.get_text (), output = output } );
563 entry.set_text (output);
564@@ -325,16 +312,16 @@
565 button_ans.set_sensitive (true);
566
567 position = output.length;
568+ remove_error ();
569 }
570- } catch (OUT_ERROR e) {
571- infobar = new Gtk.InfoBar ();
572- infobar.get_content_area ().add (new Gtk.Label (e.message));
573- infobar.set_show_close_button (false);
574- infobar.set_message_type (Gtk.MessageType.ERROR);
575-
576- main_grid.attach (infobar, 0, 0, 2, 1);
577+ } catch (Core.OUT_ERROR e) {
578+ infobar_label.label = e.message;
579+ infobar.no_show_all = false;
580 infobar.show_all ();
581+ infobar.no_show_all = true;
582 }
583+ } else {
584+ remove_error ();
585 }
586
587 entry.grab_focus ();
588@@ -387,20 +374,14 @@
589 position = entry.get_position ();
590 if (button.get_active ()) {
591 //show extended functionality
592- button.set_property ("image", extended_img_2);
593- button.set_tooltip_text (_("Hide extended functionality"));
594-
595- margin_box.show ();
596- foreach (Gtk.Button e_button in extended_button_list)
597- e_button.show ();
598+ button.image = extended_img_2;
599+ button.tooltip_text = _("Hide extended functionality");
600+ extended_revealer.set_reveal_child (true);
601 } else {
602 //hide extended functionality
603- button.set_property ("image", extended_img_1);
604- button.set_tooltip_text (_("Show extended functionality"));
605-
606- margin_box.hide ();
607- foreach (Gtk.Button e_button in extended_button_list)
608- e_button.hide ();
609+ button.image = extended_img_1;
610+ button.tooltip_text = _("Show extended functionality");
611+ extended_revealer.set_reveal_child (false);
612 }
613 //focusing button_calc because without a new focus it will cause weird window drawing problems.
614 entry.grab_focus ();
615@@ -409,8 +390,7 @@
616
617 private void show_history (Gtk.Button button) {
618 position = entry.get_position ();
619-
620- button_history.set_sensitive (false);
621+ button_history.sensitive = false;
622
623 var history_dialog = new HistoryDialog (history);
624 history_dialog.added.connect (history_added);
625@@ -425,8 +405,7 @@
626 }
627
628 private void remove_error () {
629- if (infobar != null)
630- infobar.hide ();
631+ infobar.hide ();
632 }
633 }
634 }

Subscribers

People subscribed via source and target branches

to all changes: