[gnome-builder/wip/gtk4-port] libide/sourceview: add join action
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port] libide/sourceview: add join action
- Date: Sun, 15 May 2022 00:46:25 +0000 (UTC)
commit d5d2ff7bfd5fdbf81feba2dcad6aed0e5930a175
Author: Christian Hergert <chergert redhat com>
Date: Sat May 14 17:36:49 2022 -0700
libide/sourceview: add join action
From our archive. Also include stub for sort, still to be brought over.
src/libide/sourceview/gtk/menus.ui | 5 ++--
src/libide/sourceview/ide-source-view.c | 45 +++++++++++++++++++++++++++++++++
2 files changed, 47 insertions(+), 3 deletions(-)
---
diff --git a/src/libide/sourceview/gtk/menus.ui b/src/libide/sourceview/gtk/menus.ui
index f2eae6812..3600ff4ab 100644
--- a/src/libide/sourceview/gtk/menus.ui
+++ b/src/libide/sourceview/gtk/menus.ui
@@ -89,13 +89,12 @@
<section id="ide-source-view-popup-menu-line-section">
<item>
<attribute name="label" translatable="yes">_Join Lines</attribute>
- <attribute name="action">sourceview.join-lines</attribute>
+ <attribute name="action">selection.join</attribute>
<attribute name="accel"><control>j</attribute>
</item>
<item>
<attribute name="label" translatable="yes">S_ort Lines</attribute>
- <attribute name="action">sourceview.sort</attribute>
- <attribute name="target" type="(bb)">(false,false)</attribute>
+ <attribute name="action">selection.sort</attribute>
<attribute name="accel"><shift><control>j</attribute>
</item>
</section>
diff --git a/src/libide/sourceview/ide-source-view.c b/src/libide/sourceview/ide-source-view.c
index 9c865d383..e3c57f21c 100644
--- a/src/libide/sourceview/ide-source-view.c
+++ b/src/libide/sourceview/ide-source-view.c
@@ -490,6 +490,49 @@ ide_source_view_size_allocate (GtkWidget *widget,
gtk_popover_present (self->popup_menu);
}
+static void
+ide_source_view_selection_sort (GtkWidget *widget,
+ const char *action_name,
+ GVariant *params)
+{
+ //gtk_source_buffer_sort_lines (buffer, &begin, &end, flags, column);
+}
+
+static void
+ide_source_view_selection_join (GtkWidget *widget,
+ const char *action_name,
+ GVariant *param)
+{
+ IdeSourceView *self = (IdeSourceView *)widget;
+ GtkTextBuffer *buffer;
+ GtkTextMark *mark;
+ GtkTextIter begin;
+ GtkTextIter end;
+
+ g_assert (IDE_IS_SOURCE_VIEW (self));
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self));
+
+ gtk_text_buffer_get_selection_bounds (buffer, &begin, &end);
+ gtk_text_iter_order (&begin, &end);
+
+ /*
+ * We want to leave the cursor inbetween the joined lines, so lets create an
+ * insert mark and delete it later after we reposition the cursor.
+ */
+ mark = gtk_text_buffer_create_mark (buffer, NULL, &end, TRUE);
+
+ /* join lines and restore the insert mark inbetween joined lines. */
+ gtk_text_buffer_begin_user_action (buffer);
+ gtk_source_buffer_join_lines (GTK_SOURCE_BUFFER (buffer), &begin, &end);
+ gtk_text_buffer_get_iter_at_mark (buffer, &end, mark);
+ gtk_text_buffer_select_range (buffer, &end, &end);
+ gtk_text_buffer_end_user_action (buffer);
+
+ /* Remove our temporary mark. */
+ gtk_text_buffer_delete_mark (buffer, mark);
+}
+
static void
ide_source_view_dispose (GObject *object)
{
@@ -642,6 +685,8 @@ ide_source_view_class_init (IdeSourceViewClass *klass)
g_object_class_install_properties (object_class, N_PROPS, properties);
gtk_widget_class_install_action (widget_class, "menu.popup", NULL, ide_source_view_menu_popup_action);
+ gtk_widget_class_install_action (widget_class, "selection.sort", NULL, ide_source_view_selection_sort);
+ gtk_widget_class_install_action (widget_class, "selection.join", NULL, ide_source_view_selection_join);
/**
* IdeSourceView::populate-menu:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]