SF.net SVN: geany:[2954] trunk
ntrel at users.sourceforge.net
ntrel at xxxxx
Tue Sep 16 16:06:48 UTC 2008
Revision: 2954
http://geany.svn.sourceforge.net/geany/?rev=2954&view=rev
Author: ntrel
Date: 2008-09-16 16:06:47 +0000 (Tue, 16 Sep 2008)
Log Message:
-----------
Merge split-window-plugin branch.
Add Split Window plugin (should work OK for viewing and basic text
editing; most other features are not implemented yet).
Add editor_create_widget() to the API.
Modified Paths:
--------------
trunk/ChangeLog
trunk/plugins/Makefile.am
trunk/plugins/makefile.win32
trunk/po/POTFILES.in
trunk/src/editor.c
trunk/src/editor.h
trunk/src/plugindata.h
trunk/src/plugins.c
Added Paths:
-----------
trunk/plugins/splitwindow.c
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2008-09-16 15:47:26 UTC (rev 2953)
+++ trunk/ChangeLog 2008-09-16 16:06:47 UTC (rev 2954)
@@ -14,6 +14,13 @@
Add plugin signal "document-close", sent just before a document is
closed.
(Merged from split-window-plugin branch).
+ * src/plugindata.h, src/plugins.c, src/editor.c, src/editor.h,
+ po/POTFILES.in, plugins/splitwindow.c, plugins/Makefile.am,
+ plugins/makefile.win32:
+ Merge split-window-plugin branch.
+ Add Split Window plugin (should work OK for viewing and basic text
+ editing; most other features are not implemented yet).
+ Add editor_create_widget() to the API.
2008-09-15 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
Modified: trunk/plugins/Makefile.am
===================================================================
--- trunk/plugins/Makefile.am 2008-09-16 15:47:26 UTC (rev 2953)
+++ trunk/plugins/Makefile.am 2008-09-16 16:06:47 UTC (rev 2954)
@@ -16,6 +16,7 @@
vcdiff_la_LDFLAGS = -module -avoid-version
autosave_la_LDFLAGS = -module -avoid-version
filebrowser_la_LDFLAGS = -module -avoid-version
+splitwindow_la_LDFLAGS = -module -avoid-version
if PLUGINS
@@ -26,7 +27,8 @@
export.la \
vcdiff.la \
autosave.la \
- filebrowser.la
+ filebrowser.la \
+ splitwindow.la
# Plugins not to be installed
noinst_LTLIBRARIES = \
@@ -39,6 +41,7 @@
vcdiff_la_SOURCES = vcdiff.c
autosave_la_SOURCES = autosave.c
filebrowser_la_SOURCES = filebrowser.c
+splitwindow_la_SOURCES = splitwindow.c
# instead of linking against all in $(GTK_LIBS), we link only against needed libs
demoplugin_la_LIBADD = $(GTK_LIBS)
@@ -48,6 +51,7 @@
vcdiff_la_LIBADD = $(GTK_LIBS)
autosave_la_LIBADD = $(GTK_LIBS)
filebrowser_la_LIBADD = $(GTK_LIBS)
+splitwindow_la_LIBADD = $(GTK_LIBS)
endif # PLUGINS
Modified: trunk/plugins/makefile.win32
===================================================================
--- trunk/plugins/makefile.win32 2008-09-16 15:47:26 UTC (rev 2953)
+++ trunk/plugins/makefile.win32 2008-09-16 16:06:47 UTC (rev 2954)
@@ -54,6 +54,7 @@
demoplugin.dll \
classbuilder.dll \
export.dll \
+ splitwindow.dll \
vcdiff.dll \
autosave.dll \
filebrowser.dll
Copied: trunk/plugins/splitwindow.c (from rev 2950, branches/split-window-plugin/plugins/splitwindow.c)
===================================================================
--- trunk/plugins/splitwindow.c (rev 0)
+++ trunk/plugins/splitwindow.c 2008-09-16 16:06:47 UTC (rev 2954)
@@ -0,0 +1,274 @@
+/*
+ * splitview.c
+ *
+ * Copyright 2008 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+#include "geany.h"
+#include <glib/gi18n.h>
+#include "Scintilla.h"
+#include "ScintillaWidget.h"
+#include "SciLexer.h"
+
+#include "ui_utils.h"
+#include "document.h"
+#include "editor.h"
+#include "plugindata.h"
+#include "pluginmacros.h"
+
+
+PLUGIN_VERSION_CHECK(76)
+PLUGIN_SET_INFO(_("Split Window"), _("Splits the editor view into two windows."),
+ "0.1", _("The Geany developer team"))
+
+
+GeanyData *geany_data;
+GeanyFunctions *geany_functions;
+PluginFields *plugin_fields;
+
+enum State
+{
+ STATE_SPLIT_HORIZONTAL,
+ /* STATE_SPLIT_VERTICAL, */
+ STATE_UNSPLIT,
+ STATE_COUNT
+};
+
+static struct
+{
+ GtkWidget *main;
+ GtkWidget *horizontal;
+ GtkWidget *unsplit;
+}
+menu_items;
+
+static enum State plugin_state;
+static GeanyEditor *our_editor = NULL; /* original editor for split view */
+
+
+static gint sci_get_value(ScintillaObject *sci, gint message_id, gint param)
+{
+ return p_sci->send_message(sci, message_id, param, 0);
+}
+
+
+static void set_styles(ScintillaObject *oldsci, ScintillaObject *newsci)
+{
+ gint style_id;
+
+ for (style_id = 0; style_id <= 127; style_id++)
+ {
+ gint val;
+
+ val = sci_get_value(oldsci, SCI_STYLEGETFORE, style_id);
+ p_sci->send_message(newsci, SCI_STYLESETFORE, style_id, val);
+ val = sci_get_value(oldsci, SCI_STYLEGETBACK, style_id);
+ p_sci->send_message(newsci, SCI_STYLESETBACK, style_id, val);
+ val = sci_get_value(oldsci, SCI_STYLEGETBOLD, style_id);
+ p_sci->send_message(newsci, SCI_STYLESETBOLD, style_id, val);
+ val = sci_get_value(oldsci, SCI_STYLEGETITALIC, style_id);
+ p_sci->send_message(newsci, SCI_STYLESETITALIC, style_id, val);
+ }
+}
+
+
+static void sci_set_font(ScintillaObject *sci, gint style, const gchar *font,
+ gint size)
+{
+ p_sci->send_message(sci, SCI_STYLESETFONT, style, (sptr_t) font);
+ p_sci->send_message(sci, SCI_STYLESETSIZE, style, size);
+}
+
+
+static void update_font(ScintillaObject *current, ScintillaObject *sci)
+{
+ gint style_id;
+ gint size;
+ gchar font_name[1024]; /* should be big enough */
+
+ p_sci->send_message(current, SCI_STYLEGETFONT, 0, (sptr_t)font_name);
+ size = sci_get_value(current, SCI_STYLEGETSIZE, 0);
+
+ for (style_id = 0; style_id <= 127; style_id++)
+ {
+ sci_set_font(sci, style_id, font_name, size);
+ }
+
+ /* line number and braces */
+ sci_set_font(sci, STYLE_LINENUMBER, font_name, size);
+ sci_set_font(sci, STYLE_BRACELIGHT, font_name, size);
+ sci_set_font(sci, STYLE_BRACEBAD, font_name, size);
+}
+
+
+/* line numbers visibility */
+static void set_line_numbers(ScintillaObject * sci, gboolean set, gint extra_width)
+{
+ if (set)
+ {
+ gchar tmp_str[15];
+ gint len = p_sci->send_message(sci, SCI_GETLINECOUNT, 0, 0);
+ gint width;
+ g_snprintf(tmp_str, 15, "_%d%d", len, extra_width);
+ width = p_sci->send_message(sci, SCI_TEXTWIDTH, STYLE_LINENUMBER, (sptr_t) tmp_str);
+ p_sci->send_message(sci, SCI_SETMARGINWIDTHN, 0, width);
+ p_sci->send_message(sci, SCI_SETMARGINSENSITIVEN, 0, FALSE); /* use default behaviour */
+ }
+ else
+ {
+ p_sci->send_message(sci, SCI_SETMARGINWIDTHN, 0, 0 );
+ }
+}
+
+
+static void sync_to_current(ScintillaObject *current, ScintillaObject *sci)
+{
+ gpointer sdoc;
+ gint lexer;
+ gint pos;
+
+ /* set the new sci widget to view the existing Scintilla document */
+ sdoc = (gpointer) p_sci->send_message(current, SCI_GETDOCPOINTER, 0, 0);
+ p_sci->send_message(sci, SCI_SETDOCPOINTER, 0, GPOINTER_TO_INT(sdoc));
+
+ update_font(current, sci);
+ lexer = p_sci->send_message(current, SCI_GETLEXER, 0, 0);
+ p_sci->send_message(sci, SCI_SETLEXER, lexer, 0);
+ set_styles(current, sci);
+
+ pos = p_sci->get_current_position(current);
+ p_sci->set_current_position(sci, pos, TRUE);
+
+ /* override some defaults */
+ set_line_numbers(sci, TRUE, 0);
+ p_sci->send_message(sci, SCI_SETMARGINWIDTHN, 1, 0 ); /* hide marker margin */
+}
+
+
+static void set_state(enum State id)
+{
+ gtk_widget_set_sensitive(menu_items.horizontal,
+ id != STATE_SPLIT_HORIZONTAL);
+ gtk_widget_set_sensitive(menu_items.unsplit,
+ id != STATE_UNSPLIT);
+
+ plugin_state = id;
+}
+
+
+static void on_split_view(GtkMenuItem *menuitem, gpointer user_data)
+{
+ GtkWidget *notebook = geany_data->main_widgets->notebook;
+ GtkWidget *parent = gtk_widget_get_parent(notebook);
+ GtkWidget *pane;
+ GeanyDocument *doc = p_document->get_current();
+ ScintillaObject *sci;
+ gint width = notebook->allocation.width / 2;
+
+ set_state(STATE_SPLIT_HORIZONTAL);
+
+ g_return_if_fail(doc);
+ g_return_if_fail(our_editor == NULL);
+
+ /* reparent document notebook */
+ g_object_ref(notebook);
+ gtk_container_remove(GTK_CONTAINER(parent), notebook);
+ pane = gtk_hpaned_new();
+ gtk_container_add(GTK_CONTAINER(parent), pane);
+ gtk_paned_add1(GTK_PANED(pane), notebook);
+ g_object_unref(notebook);
+
+ our_editor = doc->editor;
+ sci = p_editor->create_widget(our_editor);
+ sync_to_current(our_editor->sci, sci);
+ gtk_paned_add2(GTK_PANED(pane), GTK_WIDGET(sci));
+
+ gtk_paned_set_position(GTK_PANED(pane), width);
+ gtk_widget_show_all(pane);
+}
+
+
+static void on_unsplit(GtkMenuItem *menuitem, gpointer user_data)
+{
+ GtkWidget *notebook = geany_data->main_widgets->notebook;
+ GtkWidget *pane = gtk_widget_get_parent(notebook);
+ GtkWidget *parent = gtk_widget_get_parent(pane);
+
+ set_state(STATE_UNSPLIT);
+
+ g_return_if_fail(our_editor);
+
+ /* reparent document notebook */
+ g_object_ref(notebook);
+ gtk_container_remove(GTK_CONTAINER(pane), notebook);
+ gtk_widget_destroy(pane);
+ our_editor = NULL;
+ gtk_container_add(GTK_CONTAINER(parent), notebook);
+ g_object_unref(notebook);
+}
+
+
+void plugin_init(GeanyData *data)
+{
+ GtkWidget *item, *menu;
+
+ menu_items.main = item = gtk_menu_item_new_with_mnemonic(_("_Split Window"));
+ gtk_menu_append(geany_data->main_widgets->tools_menu, menu_items.main);
+ plugin_fields->menu_item = item;
+ plugin_fields->flags = PLUGIN_IS_DOCUMENT_SENSITIVE;
+
+ menu = gtk_menu_new();
+ gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_items.main), menu);
+
+ menu_items.horizontal = item =
+ gtk_menu_item_new_with_mnemonic(_("_Horizontally"));
+ g_signal_connect(item, "activate", G_CALLBACK(on_split_view), NULL);
+ gtk_menu_append(menu, item);
+
+ menu_items.unsplit = item =
+ gtk_menu_item_new_with_mnemonic(_("_Unsplit"));
+ g_signal_connect(item, "activate", G_CALLBACK(on_unsplit), NULL);
+ gtk_menu_append(menu, item);
+
+ gtk_widget_show_all(menu_items.main);
+
+ set_state(STATE_UNSPLIT);
+}
+
+
+static void on_document_close(GObject *obj, GeanyDocument *doc, gpointer user_data)
+{
+ /* remove the split window because the document won't exist anymore */
+ if (our_editor && doc == our_editor->document)
+ on_unsplit(NULL, NULL);
+}
+
+PluginCallback plugin_callbacks[] =
+{
+ { "document-close", (GCallback) &on_document_close, FALSE, NULL },
+ { NULL, NULL, FALSE, NULL }
+};
+
+
+void plugin_cleanup()
+{
+ if (plugin_state != STATE_UNSPLIT)
+ on_unsplit(NULL, NULL);
+
+ gtk_widget_destroy(menu_items.main);
+}
Modified: trunk/po/POTFILES.in
===================================================================
--- trunk/po/POTFILES.in 2008-09-16 15:47:26 UTC (rev 2953)
+++ trunk/po/POTFILES.in 2008-09-16 16:06:47 UTC (rev 2954)
@@ -42,3 +42,4 @@
plugins/vcdiff.c
plugins/filebrowser.c
plugins/autosave.c
+plugins/splitwindow.c
Modified: trunk/src/editor.c
===================================================================
--- trunk/src/editor.c 2008-09-16 15:47:26 UTC (rev 2953)
+++ trunk/src/editor.c 2008-09-16 16:06:47 UTC (rev 2954)
@@ -3766,6 +3766,7 @@
/* Create new editor widget (scintilla).
* @note The @c "sci-notify" signal is connected separately. */
+/* TODO: change to use GeanyEditor */
static ScintillaObject *create_new_sci(GeanyDocument *doc)
{
ScintillaObject *sci;
@@ -3804,6 +3805,29 @@
}
+/** Create a new Scintilla @c GtkWidget based on the settings for @a editor.
+ * @param editor Editor settings.
+ * @return The new widget. */
+ScintillaObject *editor_create_widget(GeanyEditor *editor)
+{
+ const GeanyIndentPrefs *iprefs = get_default_indent_prefs();
+ ScintillaObject *old, *sci;
+
+ /* temporarily change editor to use the new sci widget */
+ old = editor->sci;
+ sci = create_new_sci(editor->document);
+ editor->sci = sci;
+
+ editor_set_indent_type(editor, iprefs->type);
+ editor_set_font(editor, interface_prefs.editor_font);
+
+ /* if editor already had a widget, restore it */
+ if (old)
+ editor->sci = old;
+ return sci;
+}
+
+
GeanyEditor *editor_create(GeanyDocument *doc)
{
const GeanyIndentPrefs *iprefs = get_default_indent_prefs();
@@ -3811,14 +3835,12 @@
editor->document = doc;
- editor->sci = create_new_sci(doc);
- editor_set_indent_type(editor, iprefs->type);
- editor_set_font(editor, interface_prefs.editor_font);
-
editor->auto_indent = (iprefs->auto_indent_mode != GEANY_AUTOINDENT_NONE);
editor->line_wrapping = editor_prefs.line_wrapping;
editor->scroll_percent = -1.0F;
editor->line_breaking = FALSE;
+
+ editor->sci = editor_create_widget(editor);
return editor;
}
Modified: trunk/src/editor.h
===================================================================
--- trunk/src/editor.h 2008-09-16 15:47:26 UTC (rev 2953)
+++ trunk/src/editor.h 2008-09-16 16:06:47 UTC (rev 2954)
@@ -142,6 +142,8 @@
void editor_destroy(GeanyEditor *editor);
+ScintillaObject *editor_create_widget(GeanyEditor *editor);
+
void on_editor_notification(GtkWidget* editor, gint scn, gpointer lscn, gpointer user_data);
gboolean editor_start_auto_complete(GeanyDocument *doc, gint pos, gboolean force);
Modified: trunk/src/plugindata.h
===================================================================
--- trunk/src/plugindata.h 2008-09-16 15:47:26 UTC (rev 2953)
+++ trunk/src/plugindata.h 2008-09-16 16:06:47 UTC (rev 2954)
@@ -41,7 +41,7 @@
enum {
/** The Application Programming Interface (API) version, incremented
* whenever any plugin data types are modified or appended to. */
- GEANY_API_VERSION = 91,
+ GEANY_API_VERSION = 92,
/** The Application Binary Interface (ABI) version, incremented whenever
* existing fields in the plugin data types have to be changed or reordered. */
@@ -456,6 +456,7 @@
void (*clear_indicators) (struct GeanyEditor *editor);
const struct GeanyIndentPrefs* (*get_indent_prefs)(struct GeanyEditor *editor);
+ struct _ScintillaObject* (*create_widget)(struct GeanyEditor *editor);
/* Remember to convert any GeanyDocument or ScintillaObject pointers in any
* appended functions to GeanyEditor pointers. */
}
Modified: trunk/src/plugins.c
===================================================================
--- trunk/src/plugins.c 2008-09-16 15:47:26 UTC (rev 2953)
+++ trunk/src/plugins.c 2008-09-16 16:06:47 UTC (rev 2954)
@@ -115,7 +115,8 @@
&editor_set_indicator,
&editor_set_indicator_on_line,
&editor_clear_indicators,
- &editor_get_indent_prefs
+ &editor_get_indent_prefs,
+ &editor_create_widget
};
static ScintillaFuncs sci_funcs = {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Commits
mailing list