Revision: 1848
http://geany.svn.sourceforge.net/geany/?rev=1848&view=rev
Author: ntrel
Date: 2007-09-03 09:09:53 -0700 (Mon, 03 Sep 2007)
Log Message:
-----------
Add text argument for document_new_file(), so that it's independent
from filetype templates.
Make File->New create a blank document, rather than using the None
filetype template.
Add None option for the 'New with Template' menu commands.
Modified Paths:
--------------
trunk/ChangeLog
trunk/plugins/classbuilder.c
trunk/src/callbacks.c
trunk/src/document.c
trunk/src/document.h
trunk/src/keybindings.c
trunk/src/main.c
trunk/src/plugindata.h
trunk/src/socket.c
trunk/src/templates.c
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2007-09-03 12:17:58 UTC (rev 1847)
+++ trunk/ChangeLog 2007-09-03 16:09:53 UTC (rev 1848)
@@ -3,6 +3,14 @@
* src/keybindings.c:
Set copy lines default KB to Ctrl-Shift-C.
Set cut lines default KB to Ctrl-Shift-X.
+ * plugins/classbuilder.c, src/templates.c, src/keybindings.c,
+ src/plugindata.h, src/callbacks.c, src/document.c, src/document.h,
+ src/main.c, src/socket.c:
+ Add text argument for document_new_file(), so that it's independent
+ from filetype templates.
+ Make File->New create a blank document, rather than using the None
+ filetype template.
+ Add None option for the 'New with Template' menu commands.
2007-08-31 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
Modified: trunk/plugins/classbuilder.c
===================================================================
--- trunk/plugins/classbuilder.c 2007-09-03 12:17:58 UTC (rev 1847)
+++ trunk/plugins/classbuilder.c 2007-09-03 16:09:53 UTC (rev 1848)
@@ -740,7 +740,7 @@
if (! utils->str_equal(class_info->source, ""))
{
text = get_template_class_source(class_info);
- idx = documents->new_file(class_info->source, NULL);
+ idx = documents->new_file(class_info->source, NULL, NULL);
scintilla->set_text(doc_list[idx].sci, text);
g_free(text);
}
@@ -748,7 +748,7 @@
if (! utils->str_equal(class_info->header, ""))
{
text = get_template_class_header(class_info);
- idx = documents->new_file(class_info->header, NULL);
+ idx = documents->new_file(class_info->header, NULL, NULL);
scintilla->set_text(doc_list[idx].sci, text);
g_free(text);
}
Modified: trunk/src/callbacks.c
===================================================================
--- trunk/src/callbacks.c 2007-09-03 12:17:58 UTC (rev 1847)
+++ trunk/src/callbacks.c 2007-09-03 16:09:53 UTC (rev 1848)
@@ -193,7 +193,7 @@
on_new1_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
- document_new_file(NULL, NULL);
+ document_new_file(NULL, NULL, NULL);
}
@@ -554,7 +554,7 @@
on_toolbutton8_clicked (GtkToolButton *toolbutton,
gpointer user_data)
{
- document_new_file(NULL, NULL);
+ document_new_file(NULL, NULL, NULL);
}
// open file
@@ -1185,7 +1185,7 @@
on_toolbutton_new_clicked (GtkToolButton *toolbutton,
gpointer user_data)
{
- document_new_file(NULL, NULL);
+ document_new_file(NULL, NULL, NULL);
}
Modified: trunk/src/document.c
===================================================================
--- trunk/src/document.c 2007-09-03 12:17:58 UTC (rev 1847)
+++ trunk/src/document.c 2007-09-03 16:09:53 UTC (rev 1848)
@@ -445,21 +445,23 @@
}
-/* This creates a new document, by clearing the text widget and setting the
- current filename to filename or NULL. If ft is NULL and filename is not NULL, then the filetype
- will be guessed from the given filename.
- filename is expected in UTF-8 encoding. */
-gint document_new_file(const gchar *filename, filetype *ft)
+/* Create a new document.
+ * filename is either the UTF-8 file name, or NULL.
+ * If ft is NULL and filename is not NULL, then the filetype will be guessed
+ * from the given filename.
+ * text is the contents of the new file, or NULL.
+ * Returns: idx of new file in doc_list. */
+gint document_new_file(const gchar *filename, filetype *ft, const gchar *text)
{
gint idx = document_create_new_sci(filename);
- gchar *template = templates_get_template_new_file(ft);
g_assert(idx != -1);
sci_set_undo_collection(doc_list[idx].sci, FALSE); // avoid creation of an undo action
- sci_clear_all(doc_list[idx].sci);
- sci_set_text(doc_list[idx].sci, template);
- g_free(template);
+ if (text)
+ sci_set_text(doc_list[idx].sci, text);
+ else
+ sci_clear_all(doc_list[idx].sci);
#ifdef G_OS_WIN32
sci_set_eol_mode(doc_list[idx].sci, SC_EOL_CRLF);
@@ -469,6 +471,9 @@
sci_set_undo_collection(doc_list[idx].sci, TRUE);
sci_empty_undo_buffer(doc_list[idx].sci);
+ doc_list[idx].mtime = time(NULL);
+ doc_list[idx].changed = FALSE;
+
doc_list[idx].encoding = g_strdup(encodings[prefs.default_new_encoding].charset);
// store the opened encoding for undo/redo
store_saved_encoding(idx);
@@ -482,10 +487,6 @@
filetypes[GEANY_FILETYPES_ALL]->style_func_ptr(doc_list[idx].sci);
ui_set_window_title(idx);
build_menu_update(idx);
-
- doc_list[idx].mtime = time(NULL);
- doc_list[idx].changed = FALSE;
-
document_update_tag_list(idx, FALSE);
document_set_text_changed(idx);
ui_document_show_hide(idx); // update the document menu
@@ -2372,20 +2373,15 @@
{
// create a new file and copy file content and properties
gint len, idx;
- gchar *data;
+ gchar *text;
+ len = sci_get_length(doc_list[old_idx].sci) + 1;
+ text = (gchar*) g_malloc(len);
+ sci_get_text(doc_list[old_idx].sci, len, text);
// use old file type (or maybe NULL for auto detect would be better?)
- idx = document_new_file(utf8_filename, doc_list[old_idx].file_type);
+ idx = document_new_file(utf8_filename, doc_list[old_idx].file_type, text);
+ g_free(text);
- sci_set_undo_collection(doc_list[idx].sci, FALSE); // avoid creation of an undo action
- sci_empty_undo_buffer(doc_list[idx].sci);
-
- len = sci_get_length(doc_list[old_idx].sci) + 1;
- data = (gchar*) g_malloc(len);
- sci_get_text(doc_list[old_idx].sci, len, data);
-
- sci_set_text(doc_list[idx].sci, data);
-
// copy file properties
doc_list[idx].line_wrapping = doc_list[old_idx].line_wrapping;
doc_list[idx].readonly = doc_list[old_idx].readonly;
@@ -2393,11 +2389,8 @@
document_set_encoding(idx, doc_list[old_idx].encoding);
sci_set_lines_wrapped(doc_list[idx].sci, doc_list[idx].line_wrapping);
sci_set_readonly(doc_list[idx].sci, doc_list[idx].readonly);
- sci_set_undo_collection(doc_list[idx].sci, TRUE);
ui_document_show_hide(idx);
-
- g_free(data);
return idx;
}
Modified: trunk/src/document.h
===================================================================
--- trunk/src/document.h 2007-09-03 12:17:58 UTC (rev 1847)
+++ trunk/src/document.h 2007-09-03 16:09:53 UTC (rev 1848)
@@ -120,20 +120,13 @@
gboolean document_remove(guint page_num);
-/* This creates a new document, by clearing the text widget and setting the
- current filename to filename or NULL. If ft is NULL and filename is not NULL, then the filetype
- will be guessed from the given filename.
- filename is expected in UTF-8 encoding. */
-gint document_new_file(const gchar *filename, filetype *ft);
+/* See document.c. */
+gint document_new_file(const gchar *filename, filetype *ft, const gchar *text);
gint document_clone(gint old_idx, const gchar *utf8_filename);
-/* To open a new file, set idx to -1; filename should be locale encoded.
- * To reload a file, set the idx for the document to be reloaded; filename should be NULL.
- * Returns: idx of the opened file or -1 if an error occurred.
- * Note: If opening more than one file, document_delay_colourise() should be used before
- * and document_colourise_new() after opening to avoid unnecessary recolourising. */
+/* See document.c. */
gint document_open_file(gint idx, const gchar *filename, gint pos, gboolean readonly,
filetype *ft, const gchar *forced_enc);
Modified: trunk/src/keybindings.c
===================================================================
--- trunk/src/keybindings.c 2007-09-03 12:17:58 UTC (rev 1847)
+++ trunk/src/keybindings.c 2007-09-03 16:09:53 UTC (rev 1848)
@@ -715,7 +715,7 @@
switch (key_id)
{
case GEANY_KEYS_MENU_NEW:
- document_new_file(NULL, NULL);
+ document_new_file(NULL, NULL, NULL);
break;
case GEANY_KEYS_MENU_OPEN:
on_open1_activate(NULL, NULL);
Modified: trunk/src/main.c
===================================================================
--- trunk/src/main.c 2007-09-03 12:17:58 UTC (rev 1847)
+++ trunk/src/main.c 2007-09-03 16:09:53 UTC (rev 1848)
@@ -553,7 +553,7 @@
{ // create new file if it doesn't exist
gint idx;
- idx = document_new_file(filename, NULL);
+ idx = document_new_file(filename, NULL, NULL);
if (DOC_IDX_VALID(idx))
ui_add_recent_file(doc_list[idx].file_name);
}
@@ -740,7 +740,7 @@
// open a new file if no other file was opened
if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)) == 0)
- document_new_file(NULL, NULL);
+ document_new_file(NULL, NULL, NULL);
ui_document_buttons_update();
ui_save_buttons_toggle(FALSE);
Modified: trunk/src/plugindata.h
===================================================================
--- trunk/src/plugindata.h 2007-09-03 12:17:58 UTC (rev 1847)
+++ trunk/src/plugindata.h 2007-09-03 16:09:53 UTC (rev 1848)
@@ -76,7 +76,7 @@
/* The ABI version should be incremented whenever existing fields in the plugin
* data types below have to be changed or reordered. It should stay the same if fields
* are only appended, as this doesn't affect existing fields. */
-static const gint abi_version = 6;
+static const gint abi_version = 7;
/* This performs runtime checks that try to ensure:
* 1. Geany ABI data types are compatible with this plugin.
@@ -170,7 +170,7 @@
typedef struct DocumentFuncs
{
- gint (*new_file) (const gchar *filename, struct filetype *ft);
+ gint (*new_file) (const gchar *filename, struct filetype *ft, const gchar *text);
gint (*get_cur_idx) ();
struct document* (*get_current) ();
gboolean (*save_file)(gint idx, gboolean force);
Modified: trunk/src/socket.c
===================================================================
--- trunk/src/socket.c 2007-09-03 12:17:58 UTC (rev 1847)
+++ trunk/src/socket.c 2007-09-03 16:09:53 UTC (rev 1848)
@@ -425,7 +425,7 @@
{ // create new file if it doesn't exist
gint idx;
- idx = document_new_file(buf, NULL);
+ idx = document_new_file(buf, NULL, NULL);
if (DOC_IDX_VALID(idx))
ui_add_recent_file(doc_list[idx].file_name);
else
Modified: trunk/src/templates.c
===================================================================
--- trunk/src/templates.c 2007-09-03 12:17:58 UTC (rev 1847)
+++ trunk/src/templates.c 2007-09-03 16:09:53 UTC (rev 1848)
@@ -307,7 +307,11 @@
on_new_with_template (GtkMenuItem *menuitem,
gpointer user_data)
{
- document_new_file(NULL, (filetype*) user_data);
+ filetype *ft = user_data;
+ gchar *template = templates_get_template_new_file(ft);
+
+ document_new_file(NULL, ft, template);
+ g_free(template);
}
@@ -317,16 +321,16 @@
GtkWidget *template_menu = lookup_widget(app->window, "menu_new_with_template1_menu");
filetype_id ft_id;
- for (ft_id = 0; ft_id < GEANY_FILETYPES_ALL; ft_id++)
+ for (ft_id = 0; ft_id < GEANY_MAX_FILE_TYPES; ft_id++)
{
GtkWidget *tmp_menu, *tmp_button;
filetype *ft = filetypes[ft_id];
const gchar *label = ft->title;
if (ft_templates[ft_id] == NULL)
- {
continue;
- }
+ if (ft_id == GEANY_FILETYPES_ALL)
+ label = _("None");
tmp_menu = gtk_menu_item_new_with_label(label);
tmp_button = gtk_menu_item_new_with_label(label);
gtk_widget_show(tmp_menu);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.