[gnome-builder/wip/gtk4-port: 1290/1774] plugins/editorui: allow toggling line-ending types
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port: 1290/1774] plugins/editorui: allow toggling line-ending types
- Date: Mon, 11 Jul 2022 22:31:41 +0000 (UTC)
commit b540df56fb18da32da1e10c33095bbad8f7b357b
Author: Christian Hergert <chergert redhat com>
Date: Wed Jun 1 15:14:26 2022 -0700
plugins/editorui: allow toggling line-ending types
.../editorui/gbp-editorui-application-addin.c | 2 +-
.../editorui/gbp-editorui-workspace-addin.c | 45 +++++++++++++++++++---
src/plugins/editorui/gtk/menus.ui | 9 +++--
3 files changed, 46 insertions(+), 10 deletions(-)
---
diff --git a/src/plugins/editorui/gbp-editorui-application-addin.c
b/src/plugins/editorui/gbp-editorui-application-addin.c
index 27986a49e..b687baab7 100644
--- a/src/plugins/editorui/gbp-editorui-application-addin.c
+++ b/src/plugins/editorui/gbp-editorui-application-addin.c
@@ -367,7 +367,7 @@ update_menus (IdeApplication *app)
menu = ide_application_get_menu_by_id (app, "editorui-line-ends-section");
lf = g_menu_item_new (lf_name, NULL);
- g_menu_item_set_action_and_target (lf, "editor.newline", "s", "lf");
+ g_menu_item_set_action_and_target (lf, "editorui.newline-type", "s", "lf");
g_menu_prepend_item (menu, lf);
}
diff --git a/src/plugins/editorui/gbp-editorui-workspace-addin.c
b/src/plugins/editorui/gbp-editorui-workspace-addin.c
index e2603e1d3..5d3cd1812 100644
--- a/src/plugins/editorui/gbp-editorui-workspace-addin.c
+++ b/src/plugins/editorui/gbp-editorui-workspace-addin.c
@@ -77,6 +77,31 @@ static void
}
}
+static gboolean
+newline_type_to_label (GBinding *binding,
+ const GValue *from_value,
+ GValue *to_value,
+ gpointer user_data)
+{
+ GtkSourceNewlineType newline_type = g_value_get_enum (from_value);
+
+ switch (newline_type)
+ {
+ default:
+ case GTK_SOURCE_NEWLINE_TYPE_LF:
+ g_value_set_static_string (to_value, "LF");
+ return TRUE;
+
+ case GTK_SOURCE_NEWLINE_TYPE_CR:
+ g_value_set_static_string (to_value, "CR");
+ return TRUE;
+
+ case GTK_SOURCE_NEWLINE_TYPE_CR_LF:
+ g_value_set_static_string (to_value, "CR/LF");
+ return TRUE;
+ }
+}
+
static void
notify_overwrite_cb (GbpEditoruiWorkspaceAddin *self)
{
@@ -324,9 +349,8 @@ gbp_editorui_workspace_addin_load (IdeWorkspaceAddin *addin,
self->workspace = workspace;
self->statusbar = ide_workspace_get_statusbar (workspace);
- self->encoding_label = g_object_new (GTK_TYPE_LABEL,
- "label", "UTF-8",
- NULL);
+ self->encoding_label = g_object_new (GTK_TYPE_LABEL, NULL);
+ self->line_ends_label = g_object_new (GTK_TYPE_LABEL, NULL);
self->actions = g_simple_action_group_new ();
g_action_map_add_action_entries (G_ACTION_MAP (self->actions),
@@ -348,6 +372,11 @@ gbp_editorui_workspace_addin_load (IdeWorkspaceAddin *addin,
ide_binding_group_bind (self->buffer_bindings, "charset",
self->encoding_label, "label",
G_BINDING_SYNC_CREATE);
+ ide_binding_group_bind_full (self->buffer_bindings, "newline-type",
+ self->line_ends_label, "label",
+ G_BINDING_SYNC_CREATE,
+ newline_type_to_label,
+ NULL, NULL, NULL);
self->view_signals = ide_signal_group_new (IDE_TYPE_SOURCE_VIEW);
ide_signal_group_connect_object (self->view_signals,
@@ -383,9 +412,6 @@ gbp_editorui_workspace_addin_load (IdeWorkspaceAddin *addin,
/* Line ending */
menu = ide_application_get_menu_by_id (IDE_APPLICATION_DEFAULT, "editorui-line-ends-menu");
- self->line_ends_label = g_object_new (GTK_TYPE_LABEL,
- "label", "LF",
- NULL);
self->line_ends = g_object_new (GTK_TYPE_MENU_BUTTON,
"menu-model", menu,
"direction", GTK_ARROW_UP,
@@ -477,7 +503,9 @@ gbp_editorui_workspace_addin_page_changed (IdeWorkspaceAddin *addin,
g_clear_handle_id (&self->queued_cursor_moved, g_source_remove);
+ /* Remove now invalid actions */
g_action_map_remove_action (G_ACTION_MAP (self->actions), "encoding");
+ g_action_map_remove_action (G_ACTION_MAP (self->actions), "newline-type");
if (!IDE_IS_EDITOR_PAGE (page))
page = NULL;
@@ -485,6 +513,7 @@ gbp_editorui_workspace_addin_page_changed (IdeWorkspaceAddin *addin,
if (page != NULL)
{
g_autoptr(GPropertyAction) encoding_action = NULL;
+ g_autoptr(GPropertyAction) newline_action = NULL;
view = ide_editor_page_get_view (IDE_EDITOR_PAGE (page));
buffer = ide_editor_page_get_buffer (IDE_EDITOR_PAGE (page));
@@ -492,6 +521,10 @@ gbp_editorui_workspace_addin_page_changed (IdeWorkspaceAddin *addin,
/* Export charset control via action */
encoding_action = g_property_action_new ("encoding", buffer, "charset");
g_action_map_add_action (G_ACTION_MAP (self->actions), G_ACTION (encoding_action));
+
+ /* Export newline-type via action */
+ newline_action = g_property_action_new ("newline-type", buffer, "newline-type");
+ g_action_map_add_action (G_ACTION_MAP (self->actions), G_ACTION (newline_action));
}
ide_binding_group_set_source (self->buffer_bindings, buffer);
diff --git a/src/plugins/editorui/gtk/menus.ui b/src/plugins/editorui/gtk/menus.ui
index 2f6c2b5ef..489217bf6 100644
--- a/src/plugins/editorui/gtk/menus.ui
+++ b/src/plugins/editorui/gtk/menus.ui
@@ -60,15 +60,18 @@
This item is inserted automatically when the application starts
so that we can alter what label is shown.
<attribute name="label">Linux (LF)</attribute>
- <attribute name="action">editorui.newline('lf')</attribute>
+ <attribute name="action">editorui.newline-type</attribute>
+ <attribute name="target" type="s">'lf'</attribute>
</item-->
<item>
<attribute name="label">Windows (CR/LF)</attribute>
- <attribute name="action">editorui.newline('crlf')</attribute>
+ <attribute name="action">editorui.newline-type</attribute>
+ <attribute name="target" type="s">'cr-lf'</attribute>
</item>
<item>
<attribute name="label">Mac Classic (CR)</attribute>
- <attribute name="action">editorui.newline('cr')</attribute>
+ <attribute name="action">editorui.newline-type</attribute>
+ <attribute name="target" type="s">'cr'</attribute>
</item>
</section>
</menu>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]