From 186e36634880ada1406d71edfcd42388b5c3c5ee Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Tue, 16 Sep 2008 15:21:46 +0000 Subject: [PATCH] Add editor_create_widget() to the API; remove editor_create(), editor_destroy(). git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/split-window-plugin@2950 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 4 ++++ plugins/splitwindow.c | 9 ++++----- src/editor.c | 30 ++++++++++++++++++++++++++---- src/editor.h | 2 ++ src/plugindata.h | 7 +++---- src/plugins.c | 3 +-- 6 files changed, 40 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 70fc9ed0..a675de67 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,10 @@ Fix Doxygen 1.5.4 undocumented parameter warnings. Improve dox for sciwrappers.c. Correct sci_grap_focus() misspelling. + * src/plugindata.h, src/plugins.c, src/editor.c, src/editor.h, + plugins/splitwindow.c: + Add editor_create_widget() to the API; remove editor_create(), + editor_destroy(). 2008-09-15 Nick Treleaven diff --git a/plugins/splitwindow.c b/plugins/splitwindow.c index b16e7463..a3cf57ef 100644 --- a/plugins/splitwindow.c +++ b/plugins/splitwindow.c @@ -58,7 +58,7 @@ static struct menu_items; static enum State plugin_state; -static GeanyEditor *our_editor = NULL; +static GeanyEditor *our_editor = NULL; /* original editor for split view */ static gint sci_get_value(ScintillaObject *sci, gint message_id, gint param) @@ -193,9 +193,9 @@ static void on_split_view(GtkMenuItem *menuitem, gpointer user_data) gtk_paned_add1(GTK_PANED(pane), notebook); g_object_unref(notebook); - our_editor = p_editor->create(doc); - sci = our_editor->sci; - sync_to_current(doc->editor->sci, sci); + 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); @@ -217,7 +217,6 @@ static void on_unsplit(GtkMenuItem *menuitem, gpointer user_data) g_object_ref(notebook); gtk_container_remove(GTK_CONTAINER(pane), notebook); gtk_widget_destroy(pane); - p_editor->destroy(our_editor); our_editor = NULL; gtk_container_add(GTK_CONTAINER(parent), notebook); g_object_unref(notebook); diff --git a/src/editor.c b/src/editor.c index 3960ea8d..06be37ae 100644 --- a/src/editor.c +++ b/src/editor.c @@ -3753,6 +3753,7 @@ static void setup_sci_keys(ScintillaObject *sci) /* 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; @@ -3793,6 +3794,29 @@ static ScintillaObject *create_new_sci(GeanyDocument *doc) } +/** 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(); @@ -3800,14 +3824,12 @@ GeanyEditor *editor_create(GeanyDocument *doc) 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; } diff --git a/src/editor.h b/src/editor.h index cc4157d3..a57786aa 100644 --- a/src/editor.h +++ b/src/editor.h @@ -143,6 +143,8 @@ GeanyEditor *editor_create(GeanyDocument *doc); 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); diff --git a/src/plugindata.h b/src/plugindata.h index 195d22e8..567aa3ee 100644 --- a/src/plugindata.h +++ b/src/plugindata.h @@ -41,13 +41,13 @@ enum { /** The Application Programming Interface (API) version, incremented * whenever any plugin data types are modified or appended to. */ - GEANY_API_VERSION = 90, + GEANY_API_VERSION = 91, /** The Application Binary Interface (ABI) version, incremented whenever * existing fields in the plugin data types have to be changed or reordered. */ /* This should usually stay the same if fields are only appended, assuming only pointers to * structs and not structs themselves are declared by plugins. */ - GEANY_ABI_VERSION = 44 + GEANY_ABI_VERSION = 45 }; /** Check the plugin can be loaded by Geany. @@ -455,8 +455,7 @@ typedef struct EditorFuncs void (*clear_indicators) (struct GeanyEditor *editor); const struct GeanyIndentPrefs* (*get_indent_prefs)(struct GeanyEditor *editor); - struct GeanyEditor* (*create)(struct GeanyDocument *doc); - void (*destroy)(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. */ } diff --git a/src/plugins.c b/src/plugins.c index 06163451..bddf34dc 100644 --- a/src/plugins.c +++ b/src/plugins.c @@ -116,8 +116,7 @@ static EditorFuncs editor_funcs = { &editor_set_indicator_on_line, &editor_clear_indicators, &editor_get_indent_prefs, - &editor_create, - &editor_destroy + &editor_create_widget }; static ScintillaFuncs sci_funcs = {