Revision: 2422 http://geany.svn.sourceforge.net/geany/?rev=2422&view=rev Author: ntrel Date: 2008-03-27 06:59:51 -0700 (Thu, 27 Mar 2008)
Log Message: ----------- Split document_create_new_sci() into document_create() and create_new_sci(). Rename filename parameter utf8_filename.
Modified Paths: -------------- trunk/ChangeLog trunk/src/document.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2008-03-27 13:23:09 UTC (rev 2421) +++ trunk/ChangeLog 2008-03-27 13:59:51 UTC (rev 2422) @@ -8,6 +8,10 @@ * src/utils.c: Fix getting asked whether to reload a file twice, when a disk check is forced immediately after a disk check has been done. + * src/document.c: + Split document_create_new_sci() into document_create() and + create_new_sci(). + Rename filename parameter utf8_filename.
2008-03-26 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
Modified: trunk/src/document.c =================================================================== --- trunk/src/document.c 2008-03-27 13:23:09 UTC (rev 2421) +++ trunk/src/document.c 2008-03-27 13:59:51 UTC (rev 2422) @@ -331,7 +331,7 @@
/* Sets is_valid to FALSE and initializes some members to NULL, to mark it uninitialized. - * The flag is_valid is set to TRUE in document_create_new_sci(). */ + * The flag is_valid is set to TRUE in document_create(). */ static void init_doc_struct(document *new_doc) { new_doc->is_valid = FALSE; @@ -400,39 +400,13 @@ }
-/* creates a new tab in the notebook and does all related stuff - * finally it returns the index of the created document */ -static gint document_create_new_sci(const gchar *filename) +/* Create new editor (the scintilla widget) */ +static ScintillaObject *create_new_sci(gint new_idx) { ScintillaObject *sci; - PangoFontDescription *pfd; - gchar *fname; - gint new_idx; - document *this; - gint tabnum; - gint cur_pages = gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook));
- if (cur_pages == 1) - { - gint idx = document_get_cur_idx(); - /* remove the empty document and open a new one */ - if (doc_list[idx].file_name == NULL && ! doc_list[idx].changed) document_remove(0); - } - - new_idx = document_get_new_idx(); - if (new_idx == -1) /* expand the array, no free places */ - { - document new_doc; - init_doc_struct(&new_doc); - new_idx = doc_array->len; - g_array_append_val(doc_array, new_doc); - } - this = &doc_list[new_idx]; - - /* SCI - Code */ sci = SCINTILLA(scintilla_new()); scintilla_set_id(sci, new_idx); - this->sci = sci;
gtk_widget_show(GTK_WIDGET(sci));
@@ -443,8 +417,6 @@
setup_sci_keys(sci);
- document_apply_update_prefs(new_idx); - sci_set_tab_indents(sci, editor_prefs.use_tab_to_indent); sci_set_symbol_margin(sci, editor_prefs.show_markers_margin); sci_set_line_numbers(sci, editor_prefs.show_linenumber_margin, 0); @@ -465,6 +437,42 @@ G_CALLBACK(on_editor_button_press_event), GINT_TO_POINTER(new_idx)); g_signal_connect(G_OBJECT(sci), "motion-notify-event", G_CALLBACK(on_motion_event), NULL);
+ return sci; +} + + +/* Creates a new document and editor, adding a tab in the notebook. + * @return The index of the created document */ +static gint document_create(const gchar *utf8_filename) +{ + PangoFontDescription *pfd; + gchar *fname; + gint new_idx; + document *this; + gint tabnum; + gint cur_pages = gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)); + + if (cur_pages == 1) + { + gint idx = document_get_cur_idx(); + /* remove the empty document and open a new one */ + if (doc_list[idx].file_name == NULL && ! doc_list[idx].changed) document_remove(0); + } + + new_idx = document_get_new_idx(); + if (new_idx == -1) /* expand the array, no free places */ + { + document new_doc; + init_doc_struct(&new_doc); + new_idx = doc_array->len; + g_array_append_val(doc_array, new_doc); + } + this = &doc_list[new_idx]; + + this->sci = create_new_sci(new_idx); + + document_apply_update_prefs(new_idx); + pfd = pango_font_description_from_string(prefs.editor_font); fname = g_strdup_printf("!%s", pango_font_description_get_family(pfd)); document_set_font(new_idx, fname, pango_font_description_get_size(pfd) / PANGO_SCALE); @@ -475,7 +483,7 @@ this->tag_tree = NULL;
/* store important pointers in the tab list */ - this->file_name = (filename) ? g_strdup(filename) : NULL; + this->file_name = (utf8_filename) ? g_strdup(utf8_filename) : NULL; this->encoding = NULL; this->saved_encoding.encoding = NULL; this->saved_encoding.has_bom = FALSE; @@ -505,7 +513,6 @@ ui_document_buttons_update();
this->is_valid = TRUE; /* do this last to prevent UI updating with NULL items. */ - g_assert(doc_list[new_idx].sci == sci); return new_idx; }
@@ -586,7 +593,7 @@ **/ gint document_new_file(const gchar *filename, filetype *ft, const gchar *text) { - gint idx = document_create_new_sci(filename); + gint idx = document_create(filename);
g_assert(idx != -1);
@@ -999,7 +1006,7 @@
#ifdef G_OS_WIN32 /* if filename is a shortcut, try to resolve it */ - locale_filename = win32_get_shortcut_target(filename); + locale_filename = win32_get_shortcut_target(filename); #else locale_filename = g_strdup(filename); #endif @@ -1033,7 +1040,7 @@ return -1; }
- if (! reload) idx = document_create_new_sci(utf8_filename); + if (! reload) idx = document_create(utf8_filename); g_return_val_if_fail(idx != -1, -1); /* really should not happen */
sci_set_undo_collection(doc_list[idx].sci, FALSE); /* avoid creation of an undo action */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.