[gnome-calculator] Added shortcut to clear history (bgo#792814)
- From: Robert Roth <robertroth src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calculator] Added shortcut to clear history (bgo#792814)
- Date: Fri, 26 Jan 2018 01:34:17 +0000 (UTC)
commit a95e2e5896fbfceaa5d5dc9110e798bc86d64231
Author: Robert Roth <robert roth off gmail com>
Date: Fri Jan 26 03:33:57 2018 +0200
Added shortcut to clear history (bgo#792814)
src/gnome-calculator.vala | 1 +
src/math-display.vala | 7 ++++++-
src/math-history.vala | 8 +++++---
src/math-shortcuts.ui | 7 +++++++
src/math-window.vala | 6 ++++++
5 files changed, 25 insertions(+), 4 deletions(-)
---
diff --git a/src/gnome-calculator.vala b/src/gnome-calculator.vala
index 079ec6e..d261d3a 100644
--- a/src/gnome-calculator.vala
+++ b/src/gnome-calculator.vala
@@ -75,6 +75,7 @@ public class Calculator : Gtk.Application
Number.precision = precision;
add_action_entries (app_entries, this);
+ add_accelerator ("<Primary>Escape", "win.clear", null);
var current_window = new MathWindow (this, equation);
current_window.set_title (_("Calculator"));
diff --git a/src/math-display.vala b/src/math-display.vala
index e88a89d..fbbe113 100644
--- a/src/math-display.vala
+++ b/src/math-display.vala
@@ -103,11 +103,16 @@ public class MathDisplay : Gtk.Viewport
_equation.display_selected (prev_eq);
}
- public void update_history (string answer, Number number, int number_base, uint representation_base)
+ public void update_history (string answer, Number number, int number_base, uint representation_base)
{
history.insert_entry (answer, number, number_base, representation_base); /* Sends current equation
and answer for updating History-View */
}
+ public void clear_history ()
+ {
+ history.clear ();
+ }
+
public void insert_text (string answer)
{
_equation.insert_selected (answer);
diff --git a/src/math-history.vala b/src/math-history.vala
index b35d3d6..53ab5ee 100644
--- a/src/math-history.vala
+++ b/src/math-history.vala
@@ -11,8 +11,6 @@
[GtkTemplate (ui = "/org/gnome/calculator/history-view.ui")]
public class HistoryView : Gtk.ScrolledWindow
{
- int no_ofitems = 0; /* No of entries in history-view listbox */
-
string? last_answer = null;
string? last_equation = null;
@@ -57,7 +55,6 @@ public class HistoryView : Gtk.ScrolledWindow
listbox.insert (entry, -1);
entry.show ();
- no_ofitems++;
entry.answer_clicked.connect ((ans) => { this.answer_clicked (ans); });
entry.equation_clicked.connect ((eq) => { this.equation_clicked (eq); });
@@ -66,6 +63,11 @@ public class HistoryView : Gtk.ScrolledWindow
last_equation = equation;
row_added ();
}
+
+ public void clear ()
+ {
+ listbox.foreach ((child) => { listbox.remove(child); });
+ }
}
[GtkTemplate (ui = "/org/gnome/calculator/history-entry.ui")]
diff --git a/src/math-shortcuts.ui b/src/math-shortcuts.ui
index 89a5d04..729d5d6 100644
--- a/src/math-shortcuts.ui
+++ b/src/math-shortcuts.ui
@@ -37,6 +37,13 @@
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">1</property>
+ <property name="accelerator"><primary>Escape</property>
+ <property name="title" translatable="yes" context="shortcut window">Clear history</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkShortcutsShortcut">
+ <property name="visible">1</property>
<property name="accelerator"><ctrl>q</property>
<property name="title" translatable="yes" context="shortcut window">Quit the
application</property>
</object>
diff --git a/src/math-window.vala b/src/math-window.vala
index e8b4ac1..dc244cc 100644
--- a/src/math-window.vala
+++ b/src/math-window.vala
@@ -38,6 +38,7 @@ public class MathWindow : Gtk.ApplicationWindow
{ "undo", undo_cb, null, null, null },
{ "redo", redo_cb, null, null, null },
{ "mode", mode_cb, "s", "\"basic\"", null },
+ { "clear", clear_cb, null, null, null },
{ "close",close, null, null, null },
};
@@ -71,6 +72,11 @@ public class MathWindow : Gtk.ApplicationWindow
Gtk.StyleContext.add_provider_for_screen (get_screen (), provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
}
+ private void clear_cb ()
+ {
+ _display.clear_history ();
+ }
+
private void mode_changed_cb ()
{
var action = (SimpleAction) lookup_action ("mode");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]