Add plugin signal "document-close", sent just before a document is

closed.
(Merged from split-window-plugin branch).

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@2953 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Nick Treleaven 2008-09-16 15:47:26 +00:00
parent 86a7cb2ec9
commit 03f0700c23
5 changed files with 79 additions and 44 deletions

View File

@ -9,6 +9,11 @@
* doc/plugins.dox:
Fix wrong parameter for "project-close" signal.
(Merged from split-window-plugin branch).
* src/geanyobject.c, src/geanyobject.h, src/document.c,
doc/plugins.dox:
Add plugin signal "document-close", sent just before a document is
closed.
(Merged from split-window-plugin branch).
2008-09-15 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>

View File

@ -121,6 +121,17 @@ PluginCallback plugin_callbacks[] =
* @param user_data user data.
* @endsignaldef
*
* @signaldef document-close
* @signalproto
* void user_function(GObject *obj, GeanyDocument *doc, gpointer user_data);
* @endsignalproto
* @signaldesc
* Sent before closing a document.
* @param obj a GeanyObject instance, should be ignored.
* @param doc the document about to be closed.
* @param user_data user data.
* @endsignaldef
*
* @signaldef project-open
* @signalproto
* void user_function(GObject *obj, GKeyFile *config, gpointer user_data);

View File

@ -475,53 +475,60 @@ gboolean document_close(GeanyDocument *doc)
gboolean document_remove_page(guint page_num)
{
GeanyDocument *doc = document_get_from_page(page_num);
Document *fdoc = DOCUMENT(doc);
if (doc != NULL)
if (doc == NULL)
{
Document *fdoc = DOCUMENT(doc);
if (doc->changed && ! dialogs_show_unsaved_file(doc))
{
return FALSE;
}
/* Checking real_path makes it likely the file exists on disk */
if (! main_status.closing_all && doc->real_path != NULL)
ui_add_recent_file(doc->file_name);
notebook_remove_page(page_num);
treeviews_remove_document(doc);
navqueue_remove_file(doc->file_name);
msgwin_status_add(_("File %s closed."), DOC_FILENAME(doc));
g_free(doc->encoding);
g_free(fdoc->saved_encoding.encoding);
g_free(doc->file_name);
g_free(doc->real_path);
tm_workspace_remove_object(doc->tm_file, TRUE, TRUE);
editor_destroy(doc->editor);
doc->editor = NULL;
doc->is_valid = FALSE;
doc->file_name = NULL;
doc->real_path = NULL;
doc->file_type = NULL;
doc->encoding = NULL;
doc->has_bom = FALSE;
doc->tm_file = NULL;
document_undo_clear(doc);
if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)) == 0)
{
treeviews_update_tag_list(NULL, FALSE);
/*on_notebook1_switch_page(GTK_NOTEBOOK(main_widgets.notebook), NULL, 0, NULL);*/
ui_set_window_title(NULL);
ui_save_buttons_toggle(FALSE);
ui_document_buttons_update();
build_menu_update(NULL);
}
return TRUE;
geany_debug("Error: page_num: %d", page_num);
return FALSE;
}
geany_debug("Error: page_num: %d", page_num);
return FALSE;
if (doc->changed && ! dialogs_show_unsaved_file(doc))
{
return FALSE;
}
/* tell any plugins that the document is about to be closed */
if (geany_object)
{
g_signal_emit_by_name(geany_object, "document-close", doc);
}
/* Checking real_path makes it likely the file exists on disk */
if (! main_status.closing_all && doc->real_path != NULL)
ui_add_recent_file(doc->file_name);
notebook_remove_page(page_num);
treeviews_remove_document(doc);
navqueue_remove_file(doc->file_name);
msgwin_status_add(_("File %s closed."), DOC_FILENAME(doc));
g_free(doc->encoding);
g_free(fdoc->saved_encoding.encoding);
g_free(doc->file_name);
g_free(doc->real_path);
tm_workspace_remove_object(doc->tm_file, TRUE, TRUE);
editor_destroy(doc->editor);
doc->editor = NULL;
doc->is_valid = FALSE;
doc->file_name = NULL;
doc->real_path = NULL;
doc->file_type = NULL;
doc->encoding = NULL;
doc->has_bom = FALSE;
doc->tm_file = NULL;
document_undo_clear(doc);
if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)) == 0)
{
treeviews_update_tag_list(NULL, FALSE);
/*on_notebook1_switch_page(GTK_NOTEBOOK(main_widgets.notebook), NULL, 0, NULL);*/
ui_set_window_title(NULL);
ui_save_buttons_toggle(FALSE);
ui_document_buttons_update();
build_menu_update(NULL);
}
return TRUE;
}

View File

@ -116,6 +116,15 @@ static void create_signals(GObjectClass *g_object_class)
gtk_marshal_NONE__POINTER,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
geany_object_signals[GCB_DOCUMENT_CLOSE] = g_signal_new (
"document-close",
G_OBJECT_CLASS_TYPE (g_object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GeanyObjectClass, document_close),
NULL, NULL,
gtk_marshal_NONE__POINTER,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
geany_object_signals[GCB_PROJECT_OPEN] = g_signal_new (
"project-open",
@ -143,6 +152,7 @@ static void create_signals(GObjectClass *g_object_class)
NULL, NULL,
gtk_marshal_NONE__NONE,
G_TYPE_NONE, 0);
geany_object_signals[GCB_UPDATE_EDITOR_MENU] = g_signal_new (
"update-editor-menu",
G_OBJECT_CLASS_TYPE (g_object_class),

View File

@ -38,6 +38,7 @@ typedef enum
GCB_DOCUMENT_OPEN,
GCB_DOCUMENT_SAVE,
GCB_DOCUMENT_ACTIVATE,
GCB_DOCUMENT_CLOSE,
GCB_PROJECT_OPEN,
GCB_PROJECT_SAVE,
GCB_PROJECT_CLOSE,
@ -75,6 +76,7 @@ struct _GeanyObjectClass
void (*document_open)(GeanyDocument *doc);
void (*document_save)(GeanyDocument *doc);
void (*document_activate)(GeanyDocument *doc);
void (*document_close)(GeanyDocument *doc);
void (*project_open)(GKeyFile *keyfile);
void (*project_save)(GKeyFile *keyfile);
void (*project_close)(void);