Hi,
I've done some hacking on splitwindow.c and eliminated some bugs and
added some features. I checked the geany/geany-plugins feature/bug
trackers and I'll list which of the items I think can be closed.
The patches:
#0001
Enable code folding on the split window.
Closes bug #3097780[1]
#0002
Enable Scintilla's default popup editor menu on the split window editor
so that there's a way to copy/paste/undo/redo/etc.
Closes bug #2983145[2] although the keybindings and main menu items
still don't work in the split window.
#0003
Remove the widget reparenting in an attempt to make the plugin work on
Windows again. Although I can't test on Windows, I think there's a good
chance this will fix the issues and it seems to work fine on Linux as
well. I base this on an old GTK+ FAQ entry[3].
If someone can confirm, it will close bug #2725342[4] and the plugin can
be re-enabled on the Windows build.
#0004
Fix confusing terminology in Split View menu, which has annoyed me for
some time.
Closes bug #3203384[5] and feature request #2796316[6]
#0005
Stop unsplitting on document close unless there are no documents left
open. This patch just uses the first available document in the
documents array instead of unsplitting when the document in the split
window is closed. I left a TODO comment in there, I'll fix it later
unless someone else has the time.
While checking the bug/feature trackers, I noticed a few other items
that can probably be closed.
Feature request #1530436[7]
Feature request #2969886[8] - based on the comments
Bug #2983106[9] - it's not impossible, Ctrl+Scroll works, just no
keybindings and such.
Bug #2984797[10] - this one has bit me numerous times. I honestly don't
know if I fixed with my patches or if someone else fixed it in a recent
revision, but it seem to no longer be reproducible for me.
[1]
https://sourceforge.net/tracker/index.php?func=detail&aid=3097780&group_id=153444&atid=787791
[2]
https://sourceforge.net/tracker/index.php?func=detail&aid=2983145&group_id=153444&atid=787791
[3] http://www.fifi.org/doc/libgtk1.2-doc/faq-html/gtkfaq-5.html#ss5.17
[4]
https://sourceforge.net/tracker/index.php?func=detail&aid=2725342&group_id=153444&atid=787791
[5]
https://sourceforge.net/tracker/?func=detail&aid=3203384&group_id=222729&atid=1056532
[6]
https://sourceforge.net/tracker/index.php?func=detail&aid=2796316&group_id=153444&atid=787794
[7]
https://sourceforge.net/tracker/index.php?func=detail&aid=1530436&group_id=153444&atid=787794
[8]
https://sourceforge.net/tracker/index.php?func=detail&aid=2969886&group_id=153444&atid=787794
[9]
https://sourceforge.net/tracker/index.php?func=detail&aid=2983106&group_id=153444&atid=787791
[10]
https://sourceforge.net/tracker/index.php?func=detail&aid=2984797&group_id=222729&atid=1056532
Happy Coding,
Matthew Brush (codebrainz)
>From 3b3e099222f896338ba6cdd896abc376a931ec8c Mon Sep 17 00:00:00 2001
From: Matthew Brush <[email protected]>
Date: Wed, 16 Mar 2011 13:57:45 -0700
Subject: [PATCH 1/5] Enable code folding on splitview window.
---
plugins/splitwindow.c | 47 ++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 44 insertions(+), 3 deletions(-)
diff --git a/plugins/splitwindow.c b/plugins/splitwindow.c
index 3854f04..495c9ff 100644
--- a/plugins/splitwindow.c
+++ b/plugins/splitwindow.c
@@ -73,10 +73,11 @@ typedef struct EditWindow
ScintillaObject *sci; /* new editor widget */
GtkWidget *vbox;
GtkWidget *name_label;
+ gint handler_id;
}
EditWindow;
-static EditWindow edit_window = {NULL, NULL, NULL, NULL};
+static EditWindow edit_window = {NULL, NULL, NULL, NULL, 0 };
static void on_unsplit(GtkMenuItem *menuitem, gpointer user_data);
@@ -102,6 +103,26 @@ static void set_line_numbers(ScintillaObject * sci, gboolean set)
}
}
+static void on_sci_notify (GtkWidget *w, gint param, gpointer notif, gpointer data)
+{
+ gint line;
+ ScintillaObject *sci;
+ struct SCNotification *notification;
+
+ notification = (struct SCNotification *) notif;
+
+ /* doesn't work since Scintilla functions are missing from
+ * plugin API (scintilla_get_type). */
+ /*sci = SCINTILLA(w);*/
+ sci = edit_window.sci;
+
+ if (notification->nmhdr.code == SCN_MARGINCLICK && notification->margin == 2)
+ {
+ line = scintilla_send_message(sci, SCI_LINEFROMPOSITION,
+ notification->position, 0);
+ scintilla_send_message(sci, SCI_TOGGLEFOLD, line, 0);
+ }
+}
static void sync_to_current(ScintillaObject *sci, ScintillaObject *current)
{
@@ -119,14 +140,20 @@ static void sync_to_current(ScintillaObject *sci, ScintillaObject *current)
/* override some defaults */
set_line_numbers(sci, geany->editor_prefs->show_linenumber_margin);
scintilla_send_message(sci, SCI_SETMARGINWIDTHN, 1, 0 ); /* hide marker margin (no commands) */
- scintilla_send_message(sci, SCI_SETMARGINWIDTHN, 2, 0 ); /* hide fold margin (no toggle callback) */
+
}
static void set_editor(EditWindow *editwin, GeanyEditor *editor)
{
editwin->editor = editor;
-
+
+ if (editwin->handler_id > 0 && editwin->sci != NULL)
+ {
+ g_signal_handler_disconnect(editwin->sci, editwin->handler_id);
+ editwin->handler_id = 0;
+ }
+
/* first destroy any widget, otherwise its signals will have an
* invalid document as user_data */
if (editwin->sci != NULL)
@@ -138,6 +165,14 @@ static void set_editor(EditWindow *editwin, GeanyEditor *editor)
sync_to_current(editwin->sci, editor->sci);
+ if (geany->editor_prefs->folding)
+ editwin->handler_id = g_signal_connect(editwin->sci,
+ "sci-notify",
+ G_CALLBACK(on_sci_notify),
+ NULL);
+ else
+ scintilla_send_message(editwin->sci, SCI_SETMARGINWIDTHN, 2, 0);
+
gtk_label_set_text(GTK_LABEL(editwin->name_label), DOC_FILENAME(editor->document));
}
@@ -332,6 +367,12 @@ static void on_unsplit(GtkMenuItem *menuitem, gpointer user_data)
gtk_widget_reparent(notebook,
ui_lookup_widget(geany->main_widgets->window, "vbox1"));
+ if (edit_window.sci != NULL && edit_window.handler_id > 0)
+ {
+ g_signal_handler_disconnect(edit_window.sci, edit_window.handler_id);
+ edit_window.handler_id = 0;
+ }
+
gtk_widget_destroy(pane);
edit_window.editor = NULL;
edit_window.sci = NULL;
--
1.7.1
>From 0c9b92ca34ebd361422364067bdebf753424f142 Mon Sep 17 00:00:00 2001
From: Matthew Brush <[email protected]>
Date: Wed, 16 Mar 2011 13:59:11 -0700
Subject: [PATCH 2/5] Enable popup edit menu on splitview window.
---
plugins/splitwindow.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/plugins/splitwindow.c b/plugins/splitwindow.c
index 495c9ff..e357198 100644
--- a/plugins/splitwindow.c
+++ b/plugins/splitwindow.c
@@ -173,6 +173,8 @@ static void set_editor(EditWindow *editwin, GeanyEditor *editor)
else
scintilla_send_message(editwin->sci, SCI_SETMARGINWIDTHN, 2, 0);
+ scintilla_send_message(editwin->sci, SCI_USEPOPUP, 1, 0);
+
gtk_label_set_text(GTK_LABEL(editwin->name_label), DOC_FILENAME(editor->document));
}
--
1.7.1
>From 1eb6bc349514ef4446e03b61d9661e33c7cf9499 Mon Sep 17 00:00:00 2001
From: Matthew Brush <[email protected]>
Date: Wed, 16 Mar 2011 14:33:40 -0700
Subject: [PATCH 3/5] Remove widget reparenting in Split Window plugin.
Instead of reparenting the documents notebook full of
ScintillaObjects, just ref it, remove it from the old parent, add
it to the new parent, and then unref it. This might fix issues
with Split Window plugin on Windows and seems to have no issues
on in Linux.
---
plugins/splitwindow.c | 21 ++++++++++-----------
1 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/plugins/splitwindow.c b/plugins/splitwindow.c
index e357198..9117bf4 100644
--- a/plugins/splitwindow.c
+++ b/plugins/splitwindow.c
@@ -298,7 +298,6 @@ static GtkWidget *create_toolbar(void)
return toolbar;
}
-
static void split_view(gboolean horizontal)
{
GtkWidget *notebook = geany_data->main_widgets->notebook;
@@ -313,14 +312,14 @@ static void split_view(gboolean horizontal)
set_state(horizontal ? STATE_SPLIT_HORIZONTAL : STATE_SPLIT_VERTICAL);
- /* temporarily put document notebook in main vbox (scintilla widgets must stay
- * in a visible parent window, otherwise there are X selection and scrollbar issues) */
- gtk_widget_reparent(notebook,
- ui_lookup_widget(geany->main_widgets->window, "vbox1"));
+ gtk_widget_ref(notebook);
+ gtk_container_remove(GTK_CONTAINER(parent), notebook);
pane = horizontal ? gtk_hpaned_new() : gtk_vpaned_new();
gtk_container_add(GTK_CONTAINER(parent), pane);
- gtk_widget_reparent(notebook, pane);
+
+ gtk_container_add(GTK_CONTAINER(pane), notebook);
+ gtk_widget_unref(notebook);
box = gtk_vbox_new(FALSE, 0);
toolbar = create_toolbar();
@@ -364,10 +363,8 @@ static void on_unsplit(GtkMenuItem *menuitem, gpointer user_data)
g_return_if_fail(edit_window.editor);
- /* temporarily put document notebook in main vbox (scintilla widgets must stay
- * in a visible parent window, otherwise there are X selection and scrollbar issues) */
- gtk_widget_reparent(notebook,
- ui_lookup_widget(geany->main_widgets->window, "vbox1"));
+ gtk_widget_ref(notebook);
+ gtk_container_remove(GTK_CONTAINER(pane), notebook);
if (edit_window.sci != NULL && edit_window.handler_id > 0)
{
@@ -378,7 +375,9 @@ static void on_unsplit(GtkMenuItem *menuitem, gpointer user_data)
gtk_widget_destroy(pane);
edit_window.editor = NULL;
edit_window.sci = NULL;
- gtk_widget_reparent(notebook, parent);
+
+ gtk_container_add(GTK_CONTAINER(parent), notebook);
+ gtk_widget_unref(notebook);
}
--
1.7.1
>From f0067205292347e6d18495243a13e1af1df22052 Mon Sep 17 00:00:00 2001
From: Matthew Brush <[email protected]>
Date: Wed, 16 Mar 2011 14:37:47 -0700
Subject: [PATCH 4/5] Fix confusing terminology in Split Window plugin menu labels.
---
plugins/splitwindow.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/plugins/splitwindow.c b/plugins/splitwindow.c
index 9117bf4..14d7fa7 100644
--- a/plugins/splitwindow.c
+++ b/plugins/splitwindow.c
@@ -414,12 +414,12 @@ void plugin_init(GeanyData *data)
gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_items.main), menu);
menu_items.horizontal = item =
- gtk_menu_item_new_with_mnemonic(_("_Horizontally"));
+ gtk_menu_item_new_with_mnemonic(_("_Side by Side"));
g_signal_connect(item, "activate", G_CALLBACK(on_split_horizontally), NULL);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
menu_items.vertical = item =
- gtk_menu_item_new_with_mnemonic(_("_Vertically"));
+ gtk_menu_item_new_with_mnemonic(_("_Top and Bottom"));
g_signal_connect(item, "activate", G_CALLBACK(on_split_vertically), NULL);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
--
1.7.1
>From 4105d9bafb4402fe5f18aaaa2281b2f9c5a218b0 Mon Sep 17 00:00:00 2001
From: Matthew Brush <[email protected]>
Date: Wed, 16 Mar 2011 15:56:07 -0700
Subject: [PATCH 5/5] Stop unsplitting on document close, instead use first available doc (if any).
---
plugins/splitwindow.c | 24 ++++++++++++++++++++++--
1 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/plugins/splitwindow.c b/plugins/splitwindow.c
index 14d7fa7..752c529 100644
--- a/plugins/splitwindow.c
+++ b/plugins/splitwindow.c
@@ -443,11 +443,31 @@ void plugin_init(GeanyData *data)
}
+static gboolean use_first_available_doc(gint exclude_index)
+{
+ guint i;
+ GeanyDocument *tmp;
+ for (i=0; i < geany->documents_array->len; i++)
+ {
+ tmp = (documents[i]->is_valid) ? documents[i] : NULL;
+ if (tmp != NULL && tmp->index != exclude_index)
+ {
+ set_editor(&edit_window, tmp->editor);
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+
+/* TODO: handle special case of 'untitled' initial document closing */
static void on_document_close(GObject *obj, GeanyDocument *doc, gpointer user_data)
{
- /* remove the split window because the document won't exist anymore */
if (doc->editor == edit_window.editor)
- on_unsplit(NULL, NULL);
+ {
+ if (!use_first_available_doc(doc->index))
+ on_unsplit(NULL, NULL);
+ }
}
--
1.7.1
_______________________________________________
Geany-devel mailing list
[email protected]
http://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel