From c214056ea1d000c6e53b158f616b680d1e02eb53 Mon Sep 17 00:00:00 2001 From: pik Date: Sun, 19 Apr 2015 12:20:55 -0400 Subject: [PATCH] Fix callbacks to scintilla functions to work with splitwindow * Use Scintilla focus object instead of notebook document to fix splitwindow behaviour for cut, copy, paste and delete callbacks. * move else-if to same line (style) --- src/callbacks.c | 44 +++++++++++++++----------------------------- src/keybindings.c | 11 +++++------ 2 files changed, 20 insertions(+), 35 deletions(-) diff --git a/src/callbacks.c b/src/callbacks.c index 1e7f546f..aef4493b 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -228,16 +228,13 @@ void on_redo1_activate(GtkMenuItem *menuitem, gpointer user_data) void on_cut1_activate(GtkMenuItem *menuitem, gpointer user_data) { - GeanyDocument *doc = document_get_current(); GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window)); if (GTK_IS_EDITABLE(focusw)) gtk_editable_cut_clipboard(GTK_EDITABLE(focusw)); - else - if (IS_SCINTILLA(focusw) && doc != NULL) - sci_cut(doc->editor->sci); - else - if (GTK_IS_TEXT_VIEW(focusw)) + else if (IS_SCINTILLA(focusw)) + sci_cut(SCINTILLA(focusw)); + else if (GTK_IS_TEXT_VIEW(focusw)) { GtkTextBuffer *buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(focusw)); @@ -248,16 +245,13 @@ void on_cut1_activate(GtkMenuItem *menuitem, gpointer user_data) void on_copy1_activate(GtkMenuItem *menuitem, gpointer user_data) { - GeanyDocument *doc = document_get_current(); GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window)); if (GTK_IS_EDITABLE(focusw)) gtk_editable_copy_clipboard(GTK_EDITABLE(focusw)); - else - if (IS_SCINTILLA(focusw) && doc != NULL) - sci_copy(doc->editor->sci); - else - if (GTK_IS_TEXT_VIEW(focusw)) + else if (IS_SCINTILLA(focusw)) + sci_copy(SCINTILLA(focusw)); + else if (GTK_IS_TEXT_VIEW(focusw)) { GtkTextBuffer *buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(focusw)); @@ -268,18 +262,13 @@ void on_copy1_activate(GtkMenuItem *menuitem, gpointer user_data) void on_paste1_activate(GtkMenuItem *menuitem, gpointer user_data) { - GeanyDocument *doc = document_get_current(); GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window)); if (GTK_IS_EDITABLE(focusw)) gtk_editable_paste_clipboard(GTK_EDITABLE(focusw)); - else - if (IS_SCINTILLA(focusw) && doc != NULL) - { - sci_paste(doc->editor->sci); - } - else - if (GTK_IS_TEXT_VIEW(focusw)) + else if (IS_SCINTILLA(focusw)) + sci_paste(SCINTILLA(focusw)); + else if (GTK_IS_TEXT_VIEW(focusw)) { GtkTextBuffer *buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(focusw)); @@ -291,16 +280,13 @@ void on_paste1_activate(GtkMenuItem *menuitem, gpointer user_data) void on_delete1_activate(GtkMenuItem *menuitem, gpointer user_data) { - GeanyDocument *doc = document_get_current(); GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window)); if (GTK_IS_EDITABLE(focusw)) gtk_editable_delete_selection(GTK_EDITABLE(focusw)); - else - if (IS_SCINTILLA(focusw) && doc != NULL && sci_has_selection(doc->editor->sci)) - sci_clear(doc->editor->sci); - else - if (GTK_IS_TEXT_VIEW(focusw)) + else if (IS_SCINTILLA(focusw) && sci_has_selection(SCINTILLA(focusw))) + sci_clear(SCINTILLA(focusw)); + else if (GTK_IS_TEXT_VIEW(focusw)) { GtkTextBuffer *buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(focusw)); @@ -1200,10 +1186,10 @@ void on_print1_activate(GtkMenuItem *menuitem, gpointer user_data) void on_menu_select_all1_activate(GtkMenuItem *menuitem, gpointer user_data) { - GeanyDocument *doc = document_get_current(); - g_return_if_fail(doc != NULL); + GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window)); + g_return_if_fail(IS_SCINTILLA(focusw)); - sci_select_all(doc->editor->sci); + sci_select_all(SCINTILLA(focusw)); } diff --git a/src/keybindings.c b/src/keybindings.c index 271fad29..a8f723b2 100644 --- a/src/keybindings.c +++ b/src/keybindings.c @@ -1831,10 +1831,7 @@ static void goto_matching_brace(GeanyDocument *doc) static gboolean cb_func_clipboard_action(guint key_id) { - GeanyDocument *doc = document_get_current(); - - if (doc == NULL) - return TRUE; + GtkWidget *focusw = gtk_window_get_focus(GTK_WINDOW(main_widgets.window)); switch (key_id) { @@ -1848,10 +1845,12 @@ static gboolean cb_func_clipboard_action(guint key_id) on_paste1_activate(NULL, NULL); break; case GEANY_KEYS_CLIPBOARD_COPYLINE: - sci_send_command(doc->editor->sci, SCI_LINECOPY); + if (IS_SCINTILLA(focusw)) + sci_send_command(SCINTILLA(focusw), SCI_LINECOPY); break; case GEANY_KEYS_CLIPBOARD_CUTLINE: - sci_send_command(doc->editor->sci, SCI_LINECUT); + if (IS_SCINTILLA(focusw)) + sci_send_command(SCINTILLA(focusw), SCI_LINECUT); break; } return TRUE;