[gnome-builder] Bug 766830 - Shortcut keys - duplicate
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] Bug 766830 - Shortcut keys - duplicate
- Date: Fri, 17 Jun 2016 19:24:46 +0000 (UTC)
commit e99fda0841ba43b5426954f91ea1aa1fc82a8cdf
Author: Raunaq Abhyankar <raunaq abhyankar gmail com>
Date: Mon May 30 18:05:52 2016 +0530
Bug 766830 - Shortcut keys - duplicate
Implemented function to duplicate entire line or selected text using keyboard binding ctrl+alt+d.
Also added the keybinding in shortcut window.
https://bugzilla.gnome.org/show_bug.cgi?id=766830
data/keybindings/default.css | 1 +
libide/keybindings/ide-shortcuts-window.ui | 7 ++++
libide/sourceview/ide-source-view.c | 55 ++++++++++++++++++++++++++++
3 files changed, 63 insertions(+), 0 deletions(-)
---
diff --git a/data/keybindings/default.css b/data/keybindings/default.css
index 1412eec..b0f9431 100644
--- a/data/keybindings/default.css
+++ b/data/keybindings/default.css
@@ -23,6 +23,7 @@
bind "<ctrl>l" { "change-case" (lower) };
bind "<ctrl>i" { "action" ("view", "goto-line", "") };
bind "<ctrl>asciitilde" { "change-case" (toggle) };
+ bind "<ctrl><alt>d" { "duplicate-entire-line" ()};
bind "<ctrl>minus" { "decrease-font-size" () };
bind "<ctrl>plus" { "increase-font-size" () };
diff --git a/libide/keybindings/ide-shortcuts-window.ui b/libide/keybindings/ide-shortcuts-window.ui
index 0bd6173..a801996 100644
--- a/libide/keybindings/ide-shortcuts-window.ui
+++ b/libide/keybindings/ide-shortcuts-window.ui
@@ -210,6 +210,13 @@
<property name="title" translatable="yes" context="shortcut window">Paste text from
clipboard</property>
</object>
</child>
+ <child>
+ <object class="GtkShortcutsShortcut">
+ <property name="visible">1</property>
+ <property name="accelerator"><ctrl><alt>d</property>
+ <property name="title" translatable="yes" context="shortcut window">Duplicate current line
or selection</property>
+ </object>
+ </child>
</object>
</child>
<child>
diff --git a/libide/sourceview/ide-source-view.c b/libide/sourceview/ide-source-view.c
index 1d9089b..c2825aa 100644
--- a/libide/sourceview/ide-source-view.c
+++ b/libide/sourceview/ide-source-view.c
@@ -247,6 +247,7 @@ enum {
CLEAR_SEARCH,
CLEAR_SELECTION,
CLEAR_SNIPPETS,
+ DUPLICATE_ENTIRE_LINE,
CYCLE_COMPLETION,
DECREASE_FONT_SIZE,
DELETE_SELECTION,
@@ -3063,6 +3064,51 @@ ide_source_view_real_insert_modifier (IdeSourceView *self,
}
static void
+ide_source_view_real_duplicate_entire_line (IdeSourceView *self)
+{
+ GtkTextView *text_view = (GtkTextView *)self;
+ GtkTextIter begin, end;
+ gboolean selected;
+ g_autofree gchar *text = NULL;
+ g_autofree gchar *duplicate_line = NULL;
+ GtkTextMark *cursor;
+ GtkTextBuffer *buffer;
+
+ g_assert (GTK_IS_TEXT_VIEW (text_view));
+ g_assert (IDE_IS_SOURCE_VIEW (self));
+
+ buffer = gtk_text_view_get_buffer (text_view);
+ cursor = gtk_text_buffer_get_insert (buffer);
+
+ gtk_text_buffer_begin_user_action (buffer);
+
+ selected = gtk_text_buffer_get_selection_bounds (buffer, &begin, &end);
+
+ if (selected)
+ {
+ duplicate_line = gtk_text_iter_get_text (&begin, &end);
+ gtk_text_buffer_insert (buffer, &begin, duplicate_line, -1);
+ }
+ else
+ {
+ gtk_text_buffer_get_iter_at_mark (buffer, &begin, cursor);
+ end = begin;
+
+ gtk_text_iter_set_line_offset (&begin, 0);
+ gtk_text_iter_forward_to_line_end (&end);
+
+ if (gtk_text_iter_get_line (&begin) == gtk_text_iter_get_line (&end))
+ {
+ text = gtk_text_iter_get_text (&begin, &end);
+ duplicate_line = g_strconcat (text, "\n", NULL);
+ gtk_text_buffer_insert (buffer, &begin, duplicate_line, -1);
+ }
+ }
+
+ gtk_text_buffer_end_user_action (buffer);
+}
+
+static void
ide_source_view_real_join_lines (IdeSourceView *self)
{
GtkTextBuffer *buffer;
@@ -6376,6 +6422,15 @@ ide_source_view_class_init (IdeSourceViewClass *klass)
G_TYPE_NONE,
0);
+ signals [DUPLICATE_ENTIRE_LINE] =
+ g_signal_new_class_handler ("duplicate-entire-line",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_CALLBACK (ide_source_view_real_duplicate_entire_line),
+ NULL, NULL, NULL,
+ G_TYPE_NONE,
+ 0);
+
signals [REINDENT] =
g_signal_new_class_handler ("reindent",
G_TYPE_FROM_CLASS (klass),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]