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.


git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@1848 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Nick Treleaven 2007-09-03 16:09:53 +00:00
parent cb333602fd
commit 1887a20df4
10 changed files with 50 additions and 52 deletions

View File

@ -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>

View File

@ -740,7 +740,7 @@ static void cc_dlg_on_create_class(CreateClassDialog *cc_dlg)
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 @@ static void cc_dlg_on_create_class(CreateClassDialog *cc_dlg)
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);
}

View File

@ -193,7 +193,7 @@ void
on_new1_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
document_new_file(NULL, NULL);
document_new_file(NULL, NULL, NULL);
}
@ -554,7 +554,7 @@ void
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 @@ void
on_toolbutton_new_clicked (GtkToolButton *toolbutton,
gpointer user_data)
{
document_new_file(NULL, NULL);
document_new_file(NULL, NULL, NULL);
}

View File

@ -445,21 +445,23 @@ static void store_saved_encoding(gint idx)
}
/* 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 @@ gint document_new_file(const gchar *filename, filetype *ft)
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 @@ gint document_new_file(const gchar *filename, filetype *ft)
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,19 +2373,14 @@ gint document_clone(gint old_idx, const gchar *utf8_filename)
{
// create a new file and copy file content and properties
gint len, idx;
gchar *data;
// 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);
sci_set_undo_collection(doc_list[idx].sci, FALSE); // avoid creation of an undo action
sci_empty_undo_buffer(doc_list[idx].sci);
gchar *text;
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);
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, text);
g_free(text);
// copy file properties
doc_list[idx].line_wrapping = doc_list[old_idx].line_wrapping;
@ -2393,11 +2389,8 @@ gint document_clone(gint old_idx, const gchar *utf8_filename)
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;
}

View File

@ -120,20 +120,13 @@ void document_apply_update_prefs(gint idx);
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);

View File

@ -715,7 +715,7 @@ static void cb_func_file_action(guint key_id)
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);

View File

@ -553,7 +553,7 @@ static gboolean open_cl_files(gint argc, gchar **argv)
{ // 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 @@ gint main(gint argc, gchar **argv)
// 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);

View File

@ -76,7 +76,7 @@ static const gint api_version = 15;
/* 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 @@ struct filetype;
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);

View File

@ -425,7 +425,7 @@ gboolean socket_lock_input_cb(GIOChannel *source, GIOCondition condition, gpoint
{ // 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

View File

@ -307,7 +307,11 @@ static void
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 @@ static void create_new_menu_items()
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);