[latexila] MainWindowEdit: use undo/redo Tepl GActions
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [latexila] MainWindowEdit: use undo/redo Tepl GActions
- Date: Sat, 9 Sep 2017 12:03:52 +0000 (UTC)
commit 9aaf31787e919d356b530f661ce2c647c5c0095a
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sat Aug 19 18:08:39 2017 +0200
MainWindowEdit: use undo/redo Tepl GActions
src/main_window.vala | 21 --------------
src/main_window_edit.vala | 67 ++++-----------------------------------------
2 files changed, 6 insertions(+), 82 deletions(-)
---
diff --git a/src/main_window.vala b/src/main_window.vala
index 59141a3..9d579b9 100644
--- a/src/main_window.vala
+++ b/src/main_window.vala
@@ -705,26 +705,6 @@ public class MainWindow : ApplicationWindow
Document doc = tab.document;
- /* sensitivity of undo and redo */
- doc.notify["can-undo"].connect (() =>
- {
- if (tab == active_tab)
- _main_window_edit.update_sensitivity ();
- });
-
- doc.notify["can-redo"].connect (() =>
- {
- if (tab == active_tab)
- _main_window_edit.update_sensitivity ();
- });
-
- /* sensitivity of cut/copy/delete */
- doc.notify["has-selection"].connect (() =>
- {
- if (tab == active_tab)
- _main_window_edit.update_sensitivity ();
- });
-
doc.notify["location"].connect (() =>
{
sync_name (tab);
@@ -741,7 +721,6 @@ public class MainWindow : ApplicationWindow
_main_window_build_tools.update_sensitivity ();
});
-
doc.modified_changed.connect (() => sync_name (tab));
doc.notify["readonly"].connect (() => sync_name (tab));
doc.tepl_cursor_moved.connect (update_cursor_position_statusbar);
diff --git a/src/main_window_edit.vala b/src/main_window_edit.vala
index aea856d..1aab7fd 100644
--- a/src/main_window_edit.vala
+++ b/src/main_window_edit.vala
@@ -30,10 +30,10 @@ public class MainWindowEdit
{ "Edit", null, N_("_Edit") },
{ "EditUndo", "edit-undo", N_("_Undo"), "<Control>Z",
- N_("Undo the last action"), on_undo },
+ N_("Undo the last action") },
{ "EditRedo", "edit-redo", N_("_Redo"), "<Shift><Control>Z",
- N_("Redo the last undone action"), on_redo },
+ N_("Redo the last undone action") },
{ "EditCut", "edit-cut", N_("Cu_t"), "<Control>X",
N_("Cut the selection") },
@@ -90,6 +90,10 @@ public class MainWindowEdit
LatexilaApp app = LatexilaApp.get_instance ();
+ Amtk.utils_bind_g_action_to_gtk_action (main_window, "tepl-undo",
+ _action_group, "EditUndo");
+ Amtk.utils_bind_g_action_to_gtk_action (main_window, "tepl-redo",
+ _action_group, "EditRedo");
Amtk.utils_bind_g_action_to_gtk_action (main_window, "tepl-cut",
_action_group, "EditCut");
Amtk.utils_bind_g_action_to_gtk_action (main_window, "tepl-copy",
@@ -110,21 +114,8 @@ public class MainWindowEdit
{
bool sensitive = _main_window.active_tab != null;
- set_edit_actions_sensitivity (sensitive);
-
- if (sensitive)
- {
- set_undo_sensitivity ();
- set_redo_sensitivity ();
- }
- }
-
- private void set_edit_actions_sensitivity (bool sensitive)
- {
string[] action_names =
{
- "EditUndo",
- "EditRedo",
"EditIndent",
"EditUnindent",
"EditComment",
@@ -139,54 +130,8 @@ public class MainWindowEdit
}
}
- private void set_undo_sensitivity ()
- {
- bool can_undo = false;
-
- if (_main_window.active_tab != null)
- can_undo = _main_window.active_document.can_undo;
-
- Gtk.Action action = _action_group.get_action ("EditUndo");
- action.sensitive = can_undo;
- }
-
- private void set_redo_sensitivity ()
- {
- bool can_redo = false;
-
- if (_main_window.active_tab != null)
- can_redo = _main_window.active_document.can_redo;
-
- Gtk.Action action = _action_group.get_action ("EditRedo");
- action.sensitive = can_redo;
- }
-
/* Gtk.Action callbacks */
- public void on_undo ()
- {
- return_if_fail (_main_window.active_tab != null);
-
- if (_main_window.active_document.can_undo)
- {
- _main_window.active_document.undo ();
- _main_window.active_view.scroll_to_cursor ();
- _main_window.active_view.grab_focus ();
- }
- }
-
- public void on_redo ()
- {
- return_if_fail (_main_window.active_tab != null);
-
- if (_main_window.active_document.can_redo)
- {
- _main_window.active_document.redo ();
- _main_window.active_view.scroll_to_cursor ();
- _main_window.active_view.grab_focus ();
- }
- }
-
public void on_indent ()
{
DocumentTab? tab = _main_window.active_tab;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]