[gedit/wip/redesign] Handle edit actions
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/wip/redesign] Handle edit actions
- Date: Mon, 6 May 2013 17:30:28 +0000 (UTC)
commit 10942390c108da8168f7449af57ed89bdeb63b0a
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Mon May 6 19:18:45 2013 +0200
Handle edit actions
gedit/gedit-app.c | 4 +-
gedit/gedit-commands-edit.c | 49 ++++++++++-----
gedit/gedit-commands-file.c | 7 ++-
gedit/gedit-commands.h | 45 +++++++++------
gedit/gedit-ui.h | 25 +++-----
gedit/gedit-ui.xml | 8 ---
gedit/gedit-window.c | 137 +++++++++++++++++++------------------------
7 files changed, 136 insertions(+), 139 deletions(-)
---
diff --git a/gedit/gedit-app.c b/gedit/gedit-app.c
index 5de2d8b..6eba384 100644
--- a/gedit/gedit-app.c
+++ b/gedit/gedit-app.c
@@ -377,7 +377,7 @@ quit_activated (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
- _gedit_cmd_file_quit (NULL, NULL);
+ _gedit_cmd_file_quit (NULL, NULL, NULL);
}
static GActionEntry app_entries[] = {
@@ -1141,7 +1141,7 @@ window_delete_event (GeditWindow *window,
return TRUE;
}
- _gedit_cmd_file_quit (NULL, window);
+ _gedit_cmd_file_quit (NULL, NULL, window);
/* Do not destroy the window */
return TRUE;
diff --git a/gedit/gedit-commands-edit.c b/gedit/gedit-commands-edit.c
index 489484a..976af12 100644
--- a/gedit/gedit-commands-edit.c
+++ b/gedit/gedit-commands-edit.c
@@ -43,9 +43,11 @@
#include "gedit-preferences-dialog.h"
void
-_gedit_cmd_edit_undo (GtkAction *action,
- GeditWindow *window)
+_gedit_cmd_edit_undo (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
{
+ GeditWindow *window = GEDIT_WINDOW (user_data);
GeditView *active_view;
GtkSourceBuffer *active_document;
@@ -64,9 +66,11 @@ _gedit_cmd_edit_undo (GtkAction *action,
}
void
-_gedit_cmd_edit_redo (GtkAction *action,
- GeditWindow *window)
+_gedit_cmd_edit_redo (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
{
+ GeditWindow *window = GEDIT_WINDOW (user_data);
GeditView *active_view;
GtkSourceBuffer *active_document;
@@ -85,9 +89,11 @@ _gedit_cmd_edit_redo (GtkAction *action,
}
void
-_gedit_cmd_edit_cut (GtkAction *action,
- GeditWindow *window)
+_gedit_cmd_edit_cut (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
{
+ GeditWindow *window = GEDIT_WINDOW (user_data);
GeditView *active_view;
gedit_debug (DEBUG_COMMANDS);
@@ -101,9 +107,11 @@ _gedit_cmd_edit_cut (GtkAction *action,
}
void
-_gedit_cmd_edit_copy (GtkAction *action,
- GeditWindow *window)
+_gedit_cmd_edit_copy (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
{
+ GeditWindow *window = GEDIT_WINDOW (user_data);
GeditView *active_view;
gedit_debug (DEBUG_COMMANDS);
@@ -117,9 +125,11 @@ _gedit_cmd_edit_copy (GtkAction *action,
}
void
-_gedit_cmd_edit_paste (GtkAction *action,
- GeditWindow *window)
+_gedit_cmd_edit_paste (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
{
+ GeditWindow *window = GEDIT_WINDOW (user_data);
GeditView *active_view;
gedit_debug (DEBUG_COMMANDS);
@@ -133,9 +143,11 @@ _gedit_cmd_edit_paste (GtkAction *action,
}
void
-_gedit_cmd_edit_delete (GtkAction *action,
- GeditWindow *window)
+_gedit_cmd_edit_delete (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
{
+ GeditWindow *window = GEDIT_WINDOW (user_data);
GeditView *active_view;
gedit_debug (DEBUG_COMMANDS);
@@ -149,9 +161,11 @@ _gedit_cmd_edit_delete (GtkAction *action,
}
void
-_gedit_cmd_edit_select_all (GtkAction *action,
- GeditWindow *window)
+_gedit_cmd_edit_select_all (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
{
+ GeditWindow *window = GEDIT_WINDOW (user_data);
GeditView *active_view;
gedit_debug (DEBUG_COMMANDS);
@@ -165,9 +179,12 @@ _gedit_cmd_edit_select_all (GtkAction *action,
}
void
-_gedit_cmd_edit_preferences (GtkAction *action,
- GeditWindow *window)
+_gedit_cmd_edit_preferences (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
{
+ GeditWindow *window = GEDIT_WINDOW (user_data);
+
gedit_debug (DEBUG_COMMANDS);
gedit_show_preferences_dialog (window);
diff --git a/gedit/gedit-commands-file.c b/gedit/gedit-commands-file.c
index b9c999a..fbd755b 100644
--- a/gedit/gedit-commands-file.c
+++ b/gedit/gedit-commands-file.c
@@ -1966,9 +1966,12 @@ quit_all (void)
}
void
-_gedit_cmd_file_quit (GtkAction *action,
- GeditWindow *window)
+_gedit_cmd_file_quit (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
{
+ GeditWindow *window = GEDIT_WINDOW (user_data);
+
gedit_debug (DEBUG_COMMANDS);
if (window == NULL)
diff --git a/gedit/gedit-commands.h b/gedit/gedit-commands.h
index 2f41f04..416c157 100644
--- a/gedit/gedit-commands.h
+++ b/gedit/gedit-commands.h
@@ -102,25 +102,34 @@ void _gedit_cmd_file_close (GSimpleAction *action,
void _gedit_cmd_file_close_all (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
-void _gedit_cmd_file_quit (GtkAction *action,
- GeditWindow *window);
+void _gedit_cmd_file_quit (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data);
-void _gedit_cmd_edit_undo (GtkAction *action,
- GeditWindow *window);
-void _gedit_cmd_edit_redo (GtkAction *action,
- GeditWindow *window);
-void _gedit_cmd_edit_cut (GtkAction *action,
- GeditWindow *window);
-void _gedit_cmd_edit_copy (GtkAction *action,
- GeditWindow *window);
-void _gedit_cmd_edit_paste (GtkAction *action,
- GeditWindow *window);
-void _gedit_cmd_edit_delete (GtkAction *action,
- GeditWindow *window);
-void _gedit_cmd_edit_select_all (GtkAction *action,
- GeditWindow *window);
-void _gedit_cmd_edit_preferences (GtkAction *action,
- GeditWindow *window);
+void _gedit_cmd_edit_undo (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data);
+void _gedit_cmd_edit_redo (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data);
+void _gedit_cmd_edit_cut (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data);
+void _gedit_cmd_edit_copy (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data);
+void _gedit_cmd_edit_paste (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data);
+void _gedit_cmd_edit_delete (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data);
+void _gedit_cmd_edit_select_all (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data);
+void _gedit_cmd_edit_preferences (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data);
void _gedit_cmd_view_toggle_fullscreen_mode (GSimpleAction *action,
GVariant *parameter,
diff --git a/gedit/gedit-ui.h b/gedit/gedit-ui.h
index 0bda926..2380971 100644
--- a/gedit/gedit-ui.h
+++ b/gedit/gedit-ui.h
@@ -50,22 +50,6 @@ static const GtkActionEntry gedit_always_sensitive_menu_entries[] =
static const GtkActionEntry gedit_menu_entries[] =
{
- /* Edit menu */
- { "EditUndo", GTK_STOCK_UNDO, NULL, "<control>Z",
- N_("Undo the last action"), G_CALLBACK (_gedit_cmd_edit_undo) },
- { "EditRedo", GTK_STOCK_REDO, NULL, "<shift><control>Z",
- N_("Redo the last undone action"), G_CALLBACK (_gedit_cmd_edit_redo) },
- { "EditCut", GTK_STOCK_CUT, NULL, "<control>X",
- N_("Cut the selection"), G_CALLBACK (_gedit_cmd_edit_cut) },
- { "EditCopy", GTK_STOCK_COPY, NULL, "<control>C",
- N_("Copy the selection"), G_CALLBACK (_gedit_cmd_edit_copy) },
- { "EditPaste", GTK_STOCK_PASTE, NULL, "<control>V",
- N_("Paste the clipboard"), G_CALLBACK (_gedit_cmd_edit_paste) },
- { "EditDelete", GTK_STOCK_DELETE, NULL, NULL,
- N_("Delete the selected text"), G_CALLBACK (_gedit_cmd_edit_delete) },
- { "EditSelectAll", GTK_STOCK_SELECT_ALL, N_("Select _All"), "<control>A",
- N_("Select the entire document"), G_CALLBACK (_gedit_cmd_edit_select_all) },
-
/* View menu */
{ "ViewHighlightMode", NULL, N_("_Highlight Mode") },
};
@@ -93,7 +77,14 @@ static GActionEntry win_entries[] = {
{ "next_tab_group", _gedit_cmd_documents_next_tab_group },
{ "previous_document", _gedit_cmd_documents_previous_document },
{ "next_document", _gedit_cmd_documents_next_document },
- { "move_to_new_window", _gedit_cmd_documents_move_to_new_window }
+ { "move_to_new_window", _gedit_cmd_documents_move_to_new_window },
+ { "undo", _gedit_cmd_edit_undo },
+ { "redo", _gedit_cmd_edit_redo },
+ { "cut", _gedit_cmd_edit_cut },
+ { "copy", _gedit_cmd_edit_copy },
+ { "paste", _gedit_cmd_edit_paste },
+ { "delete", _gedit_cmd_edit_delete },
+ { "select_all", _gedit_cmd_edit_select_all }
};
G_END_DECLS
diff --git a/gedit/gedit-ui.xml b/gedit/gedit-ui.xml
index 57fd3d5..6e909f3 100644
--- a/gedit/gedit-ui.xml
+++ b/gedit/gedit-ui.xml
@@ -40,17 +40,9 @@
</menu>
<menu name="EditMenu" action="Edit">
- <menuitem name="EditUndoMenu" action="EditUndo"/>
- <menuitem name="EditRedoMenu" action="EditRedo"/>
- <separator/>
- <menuitem name="EditCutMenu" action="EditCut"/>
- <menuitem name="EditCopyMenu" action="EditCopy"/>
- <menuitem name="EditPasteMenu" action="EditPaste"/>
- <menuitem name="EditDeleteMenu" action="EditDelete"/>
<placeholder name="EditOps_1" />
<separator/>
<placeholder name="EditOps_2" />
- <menuitem name="EditSelectAllMenu" action="EditSelectAll"/>
<placeholder name="EditOps_3" />
<separator/>
<placeholder name="EditOps_4" />
diff --git a/gedit/gedit-window.c b/gedit/gedit-window.c
index 4176faa..9223ef3 100644
--- a/gedit/gedit-window.c
+++ b/gedit/gedit-window.c
@@ -497,8 +497,8 @@ received_clipboard_contents (GtkClipboard *clipboard,
GeditWindow *window)
{
GeditTab *tab;
- gboolean sens;
- GtkAction *action;
+ gboolean enabled;
+ GAction *action;
/* getting clipboard contents is async, so we need to
* get the current tab and its state */
@@ -513,18 +513,16 @@ received_clipboard_contents (GtkClipboard *clipboard,
state = gedit_tab_get_state (tab);
state_normal = (state == GEDIT_TAB_STATE_NORMAL);
- sens = state_normal &&
- gtk_selection_data_targets_include_text (selection_data);
+ enabled = state_normal &&
+ gtk_selection_data_targets_include_text (selection_data);
}
else
{
- sens = FALSE;
+ enabled = FALSE;
}
- action = gtk_action_group_get_action (window->priv->action_group,
- "EditPaste");
-
- gtk_action_set_sensitive (action, sens);
+ action = g_action_map_lookup_action (G_ACTION_MAP (window), "paste");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), enabled);
g_object_unref (window);
}
@@ -546,14 +544,12 @@ set_paste_sensitivity_according_to_clipboard (GeditWindow *window,
}
else
{
- GtkAction *action;
-
- action = gtk_action_group_get_action (window->priv->action_group,
- "EditPaste");
+ GAction *action;
+ action = g_action_map_lookup_action (G_ACTION_MAP (window), "paste");
/* XFIXES extension not availbale, make
* Paste always sensitive */
- gtk_action_set_sensitive (action, TRUE);
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
}
}
@@ -639,34 +635,29 @@ set_sensitivity_according_to_tab (GeditWindow *window,
(state != GEDIT_TAB_STATE_PRINT_PREVIEWING) &&
(state != GEDIT_TAB_STATE_SAVING_ERROR));
- action = gtk_action_group_get_action (window->priv->action_group,
- "EditUndo");
- gtk_action_set_sensitive (action,
- state_normal &&
- gtk_source_buffer_can_undo (GTK_SOURCE_BUFFER (doc)));
+ gaction = g_action_map_lookup_action (G_ACTION_MAP (window), "undo");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (gaction),
+ state_normal &&
+ gtk_source_buffer_can_undo (GTK_SOURCE_BUFFER (doc)));
- action = gtk_action_group_get_action (window->priv->action_group,
- "EditRedo");
- gtk_action_set_sensitive (action,
- state_normal &&
- gtk_source_buffer_can_redo (GTK_SOURCE_BUFFER (doc)));
+ gaction = g_action_map_lookup_action (G_ACTION_MAP (window), "redo");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (gaction),
+ state_normal &&
+ gtk_source_buffer_can_redo (GTK_SOURCE_BUFFER (doc)));
- action = gtk_action_group_get_action (window->priv->action_group,
- "EditCut");
- gtk_action_set_sensitive (action,
- state_normal &&
- editable &&
- gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER (doc)));
+ gaction = g_action_map_lookup_action (G_ACTION_MAP (window), "cut");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (gaction),
+ state_normal &&
+ editable &&
+ gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER (doc)));
- action = gtk_action_group_get_action (window->priv->action_group,
- "EditCopy");
- gtk_action_set_sensitive (action,
- (state_normal ||
- state == GEDIT_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) &&
- gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER (doc)));
+ gaction = g_action_map_lookup_action (G_ACTION_MAP (window), "copy");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (gaction),
+ (state_normal ||
+ state == GEDIT_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) &&
+ gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER (doc)));
- action = gtk_action_group_get_action (window->priv->action_group,
- "EditPaste");
+ gaction = g_action_map_lookup_action (G_ACTION_MAP (window), "paste");
if (state_normal && editable)
{
set_paste_sensitivity_according_to_clipboard (window,
@@ -674,15 +665,14 @@ set_sensitivity_according_to_tab (GeditWindow *window,
}
else
{
- gtk_action_set_sensitive (action, FALSE);
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (gaction), FALSE);
}
- action = gtk_action_group_get_action (window->priv->action_group,
- "EditDelete");
- gtk_action_set_sensitive (action,
- state_normal &&
- editable &&
- gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER (doc)));
+ gaction = g_action_map_lookup_action (G_ACTION_MAP (window), "delete");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (gaction),
+ state_normal &&
+ editable &&
+ gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER (doc)));
gaction = g_action_map_lookup_action (G_ACTION_MAP (window), "find");
g_simple_action_set_enabled (G_SIMPLE_ACTION (gaction),
@@ -2700,17 +2690,16 @@ can_undo (GeditDocument *doc,
GParamSpec *pspec,
GeditWindow *window)
{
- GtkAction *action;
- gboolean sensitive;
+ GAction *action;
+ gboolean enabled;
- sensitive = gtk_source_buffer_can_undo (GTK_SOURCE_BUFFER (doc));
+ enabled = gtk_source_buffer_can_undo (GTK_SOURCE_BUFFER (doc));
if (doc != gedit_window_get_active_document (window))
return;
- action = gtk_action_group_get_action (window->priv->action_group,
- "EditUndo");
- gtk_action_set_sensitive (action, sensitive);
+ action = g_action_map_lookup_action (G_ACTION_MAP (window), "undo");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), enabled);
}
static void
@@ -2718,17 +2707,16 @@ can_redo (GeditDocument *doc,
GParamSpec *pspec,
GeditWindow *window)
{
- GtkAction *action;
- gboolean sensitive;
+ GAction *action;
+ gboolean enabled;
- sensitive = gtk_source_buffer_can_redo (GTK_SOURCE_BUFFER (doc));
+ enabled = gtk_source_buffer_can_redo (GTK_SOURCE_BUFFER (doc));
if (doc != gedit_window_get_active_document (window))
return;
- action = gtk_action_group_get_action (window->priv->action_group,
- "EditRedo");
- gtk_action_set_sensitive (action, sensitive);
+ action = g_action_map_lookup_action (G_ACTION_MAP (window), "redo");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), enabled);
}
static void
@@ -2738,7 +2726,7 @@ selection_changed (GeditDocument *doc,
{
GeditTab *tab;
GeditView *view;
- GtkAction *action;
+ GAction *action;
GeditTabState state;
gboolean state_normal;
gboolean editable;
@@ -2755,26 +2743,23 @@ selection_changed (GeditDocument *doc,
view = gedit_tab_get_view (tab);
editable = gtk_text_view_get_editable (GTK_TEXT_VIEW (view));
- action = gtk_action_group_get_action (window->priv->action_group,
- "EditCut");
- gtk_action_set_sensitive (action,
- state_normal &&
- editable &&
- gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER (doc)));
+ action = g_action_map_lookup_action (G_ACTION_MAP (window), "cut");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ state_normal &&
+ editable &&
+ gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER (doc)));
- action = gtk_action_group_get_action (window->priv->action_group,
- "EditCopy");
- gtk_action_set_sensitive (action,
- (state_normal ||
- state == GEDIT_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) &&
- gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER (doc)));
+ action = g_action_map_lookup_action (G_ACTION_MAP (window), "copy");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ (state_normal ||
+ state == GEDIT_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) &&
+ gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER (doc)));
- action = gtk_action_group_get_action (window->priv->action_group,
- "EditDelete");
- gtk_action_set_sensitive (action,
- state_normal &&
- editable &&
- gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER (doc)));
+ action = g_action_map_lookup_action (G_ACTION_MAP (window), "delete");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ state_normal &&
+ editable &&
+ gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER (doc)));
peas_extension_set_foreach (window->priv->extensions,
(PeasExtensionSetForeachFunc) extension_update_state,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]