Add new plugin signal: "document-before-save".
Add get_line_end_position(), set_target_start(), set_target_end(), replace_target() to the plugin API (patch by Eugene Arshinov, thanks). Add new plugin signal: "document-filetype-set" (closes #2852286). git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@4162 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
parent
81c56818ac
commit
316f77f1f8
@ -17,6 +17,14 @@
|
||||
* src/build.c, src/project.c:
|
||||
Use NZV() macro instead of strlen() to check for empty strings.
|
||||
Remove the FOREACH_GEANYBUILDCMD_ENTRY() macro.
|
||||
* doc/plugins.dox, plugins/geanyfunctions.h, src/document.c,
|
||||
src/geanyobject.c, src/geanyobject.h, src/plugindata.h,
|
||||
src/plugins.c, THANKS:
|
||||
Add new plugin signal: "document-before-save".
|
||||
Add get_line_end_position(), set_target_start(), set_target_end(),
|
||||
replace_target() to the plugin API
|
||||
(patch by Eugene Arshinov, thanks).
|
||||
Add new plugin signal: "document-filetype-set" (closes #2852286).
|
||||
|
||||
|
||||
2009-09-04 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
|
||||
|
2
THANKS
2
THANKS
@ -65,7 +65,7 @@ Chris Macksey <cmacksey(at)users(dot)sourceforge(dot)net> - ActionScript filetyp
|
||||
Simon Treny <simon(dot)treny(at)free(dot)fr> - Documents sidebar stock icons patch
|
||||
Elias Pschernig <elias(at)users(dot)sourceforge(dot)net> - Recent Projects menu patch
|
||||
Jesse Mayes <plasmasheep(at)gmail(dot)com> - Tango'ish Save All icon
|
||||
Eugene Arshinov <earshinov(at)gmail(dot)com> - Reload color schemes, split lines KB patches
|
||||
Eugene Arshinov <earshinov(at)gmail(dot)com> - Reload color schemes, split lines KB patches, and more
|
||||
Jon Strait <jstrait(at)moonloop(dot)net> - Markdown filetype patch
|
||||
|
||||
Translators:
|
||||
|
@ -116,6 +116,20 @@ PluginCallback plugin_callbacks[] =
|
||||
* @param user_data user data.
|
||||
* @endsignaldef
|
||||
*
|
||||
* @signaldef document-before-save
|
||||
* @signalproto
|
||||
* void user_function(GObject *obj, GeanyDocument *doc, gpointer user_data);
|
||||
* @endsignalproto
|
||||
* @signaldesc
|
||||
* Sent before a document is saved.
|
||||
*
|
||||
* You need to include "document.h" for the declaration of GeanyDocument.
|
||||
*
|
||||
* @param obj a GeanyObject instance, should be ignored.
|
||||
* @param doc the document to be saved.
|
||||
* @param user_data user data.
|
||||
* @endsignaldef
|
||||
*
|
||||
* @signaldef document-save
|
||||
* @signalproto
|
||||
* void user_function(GObject *obj, GeanyDocument *doc, gpointer user_data);
|
||||
@ -130,6 +144,23 @@ PluginCallback plugin_callbacks[] =
|
||||
* @param user_data user data.
|
||||
* @endsignaldef
|
||||
*
|
||||
* @signaldef document-filetype-set
|
||||
* @signalproto
|
||||
* void user_function(GObject *obj, GeanyDocument *doc, GeanyFiletype *filetype_old, gpointer user_data);
|
||||
* @endsignalproto
|
||||
* @signaldesc
|
||||
* Sent after the filetype of a document has been changed.
|
||||
* The previous filetype object is passed but it can be NULL (e.g. at startup).
|
||||
* The new filetype can be read with: @code
|
||||
* GeanyFiletype *ft = doc->filetype;
|
||||
* @endcode
|
||||
*
|
||||
* @param obj a GeanyObject instance, should be ignored.
|
||||
* @param doc the saved document.
|
||||
* @param filetype_old the previous filetype of the document.
|
||||
* @param user_data user data.
|
||||
* @endsignaldef
|
||||
*
|
||||
* @signaldef document-activate
|
||||
* @signalproto
|
||||
* void user_function(GObject *obj, GeanyDocument *doc, gpointer user_data);
|
||||
|
@ -160,6 +160,14 @@
|
||||
geany_functions->p_sci->get_selection_contents
|
||||
#define sci_set_font \
|
||||
geany_functions->p_sci->set_font
|
||||
#define sci_get_line_end_position \
|
||||
geany_functions->p_sci->get_line_end_position
|
||||
#define sci_set_target_start \
|
||||
geany_functions->p_sci->set_target_start
|
||||
#define sci_set_target_end \
|
||||
geany_functions->p_sci->set_target_end
|
||||
#define sci_replace_target \
|
||||
geany_functions->p_sci->replace_target
|
||||
#define templates_get_template_fileheader \
|
||||
geany_functions->p_templates->get_template_fileheader
|
||||
#define utils_str_equal \
|
||||
|
@ -1720,8 +1720,10 @@ static gchar *write_data_to_disk(GeanyDocument *doc, const gchar *locale_filenam
|
||||
/**
|
||||
* Save the document. Saving includes replacing tabs by spaces,
|
||||
* stripping trailing spaces and adding a final new line at the end of the file (all only if
|
||||
* user enabled these features). The filetype is set again or auto-detected if it wasn't
|
||||
* set yet. After all, the "document-save" signal is emitted for plugins.
|
||||
* user enabled these features). Then the "document-before-save" signal is emitted,
|
||||
* allowing plugins to modify the document before it is saved, and data is
|
||||
* actually written to disk. The filetype is set again or auto-detected if it wasn't set yet.
|
||||
* After all, the "document-save" signal is emitted for plugins.
|
||||
*
|
||||
* If the file is not modified, this functions does nothing unless force is set to @c TRUE.
|
||||
*
|
||||
@ -1760,6 +1762,9 @@ gboolean document_save_file(GeanyDocument *doc, gboolean force)
|
||||
if (file_prefs.final_new_line)
|
||||
editor_ensure_final_newline(doc->editor);
|
||||
|
||||
/* notify plugins which may wish to modify the document before it's saved */
|
||||
g_signal_emit_by_name(geany_object, "document-before-save", doc);
|
||||
|
||||
len = sci_get_length(doc->editor->sci) + 1;
|
||||
if (doc->has_bom && encodings_is_unicode_charset(doc->encoding))
|
||||
{ /* always write a UTF-8 BOM because in this moment the text itself is still in UTF-8
|
||||
@ -2480,11 +2485,13 @@ static void document_load_config(GeanyDocument *doc, GeanyFiletype *type,
|
||||
void document_set_filetype(GeanyDocument *doc, GeanyFiletype *type)
|
||||
{
|
||||
gboolean ft_changed;
|
||||
GeanyFiletype *old_ft;
|
||||
|
||||
g_return_if_fail(doc);
|
||||
if (type == NULL)
|
||||
type = filetypes[GEANY_FILETYPES_NONE];
|
||||
|
||||
old_ft = doc->file_type;
|
||||
geany_debug("%s : %s (%s)",
|
||||
(doc->file_name != NULL) ? doc->file_name : "unknown",
|
||||
(type->name != NULL) ? type->name : "unknown",
|
||||
@ -2492,6 +2499,9 @@ void document_set_filetype(GeanyDocument *doc, GeanyFiletype *type)
|
||||
|
||||
ft_changed = (doc->file_type != type); /* filetype has changed */
|
||||
document_load_config(doc, type, ft_changed);
|
||||
|
||||
if (ft_changed)
|
||||
g_signal_emit_by_name(geany_object, "document-filetype-set", doc, old_ft);
|
||||
}
|
||||
|
||||
|
||||
|
@ -91,6 +91,36 @@ static void geany_cclosure_marshal_VOID__STRING_INT_POINTER(GClosure *closure, G
|
||||
}
|
||||
|
||||
|
||||
static void geany_cclosure_marshal_VOID__POINTER_POINTER(GClosure *closure, GValue *ret_val,
|
||||
guint n_param_vals, const GValue *param_values, gpointer hint, gpointer mdata)
|
||||
{
|
||||
typedef gboolean (*GeanyMarshalFunc_VOID__POINTER_POINTER)
|
||||
(gpointer data1, gconstpointer arg_1, gconstpointer arg_2, gpointer data2);
|
||||
|
||||
register GeanyMarshalFunc_VOID__POINTER_POINTER callback;
|
||||
register GCClosure* cc = (GCClosure*) closure;
|
||||
register gpointer data1, data2;
|
||||
|
||||
g_return_if_fail(n_param_vals == 3);
|
||||
|
||||
if (G_CCLOSURE_SWAP_DATA(closure))
|
||||
{
|
||||
data1 = closure->data;
|
||||
data2 = g_value_peek_pointer(param_values + 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
data1 = g_value_peek_pointer(param_values + 0);
|
||||
data2 = closure->data;
|
||||
}
|
||||
callback = (GeanyMarshalFunc_VOID__POINTER_POINTER) (mdata ? mdata : cc->callback);
|
||||
callback(data1,
|
||||
g_value_get_pointer(param_values + 1),
|
||||
g_value_get_pointer(param_values + 2),
|
||||
data2);
|
||||
}
|
||||
|
||||
|
||||
static gboolean boolean_handled_accumulator(GSignalInvocationHint *ihint, GValue *return_accu,
|
||||
const GValue *handler_return, gpointer dummy)
|
||||
{
|
||||
@ -162,6 +192,15 @@ static void create_signals(GObjectClass *g_object_class)
|
||||
g_cclosure_marshal_VOID__POINTER,
|
||||
G_TYPE_NONE, 1,
|
||||
G_TYPE_POINTER);
|
||||
geany_object_signals[GCB_DOCUMENT_BEFORE_SAVE] = g_signal_new (
|
||||
"document-before-save",
|
||||
G_OBJECT_CLASS_TYPE (g_object_class),
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET (GeanyObjectClass, document_before_save),
|
||||
NULL, NULL,
|
||||
g_cclosure_marshal_VOID__POINTER,
|
||||
G_TYPE_NONE, 1,
|
||||
G_TYPE_POINTER);
|
||||
geany_object_signals[GCB_DOCUMENT_SAVE] = g_signal_new (
|
||||
"document-save",
|
||||
G_OBJECT_CLASS_TYPE (g_object_class),
|
||||
@ -171,6 +210,15 @@ static void create_signals(GObjectClass *g_object_class)
|
||||
g_cclosure_marshal_VOID__POINTER,
|
||||
G_TYPE_NONE, 1,
|
||||
G_TYPE_POINTER);
|
||||
geany_object_signals[GCB_DOCUMENT_FILETYPE_SET] = g_signal_new (
|
||||
"document-filetype-set",
|
||||
G_OBJECT_CLASS_TYPE (g_object_class),
|
||||
G_SIGNAL_RUN_FIRST,
|
||||
G_STRUCT_OFFSET (GeanyObjectClass, document_filetype_set),
|
||||
NULL, NULL,
|
||||
geany_cclosure_marshal_VOID__POINTER_POINTER,
|
||||
G_TYPE_NONE, 2,
|
||||
G_TYPE_POINTER, G_TYPE_POINTER);
|
||||
geany_object_signals[GCB_DOCUMENT_ACTIVATE] = g_signal_new (
|
||||
"document-activate",
|
||||
G_OBJECT_CLASS_TYPE (g_object_class),
|
||||
|
@ -34,7 +34,9 @@ typedef enum
|
||||
{
|
||||
GCB_DOCUMENT_NEW,
|
||||
GCB_DOCUMENT_OPEN,
|
||||
GCB_DOCUMENT_BEFORE_SAVE,
|
||||
GCB_DOCUMENT_SAVE,
|
||||
GCB_DOCUMENT_FILETYPE_SET,
|
||||
GCB_DOCUMENT_ACTIVATE,
|
||||
GCB_DOCUMENT_CLOSE,
|
||||
GCB_PROJECT_OPEN,
|
||||
@ -76,7 +78,9 @@ struct _GeanyObjectClass
|
||||
|
||||
void (*document_new)(GeanyDocument *doc);
|
||||
void (*document_open)(GeanyDocument *doc);
|
||||
void (*document_before_save)(GeanyDocument *doc);
|
||||
void (*document_save)(GeanyDocument *doc);
|
||||
void (*document_filetype_set)(GeanyDocument *doc, GeanyFiletype *filetype_old);
|
||||
void (*document_activate)(GeanyDocument *doc);
|
||||
void (*document_close)(GeanyDocument *doc);
|
||||
void (*project_open)(GKeyFile *keyfile);
|
||||
|
@ -50,7 +50,7 @@
|
||||
enum {
|
||||
/** The Application Programming Interface (API) version, incremented
|
||||
* whenever any plugin data types are modified or appended to. */
|
||||
GEANY_API_VERSION = 153,
|
||||
GEANY_API_VERSION = 154,
|
||||
|
||||
/** The Application Binary Interface (ABI) version, incremented whenever
|
||||
* existing fields in the plugin data types have to be changed or reordered. */
|
||||
@ -337,6 +337,10 @@ typedef struct SciFuncs
|
||||
gchar* (*get_contents_range) (struct _ScintillaObject *sci, gint start, gint end);
|
||||
gchar* (*get_selection_contents) (struct _ScintillaObject *sci);
|
||||
void (*set_font) (struct _ScintillaObject *sci, gint style, const gchar *font, gint size);
|
||||
gint (*get_line_end_position) (ScintillaObject* sci, gint line);
|
||||
void (*set_target_start) (ScintillaObject *sci, gint start);
|
||||
void (*set_target_end) (ScintillaObject *sci, gint end);
|
||||
gint (*replace_target) (ScintillaObject *sci, const gchar *text, gboolean regex);
|
||||
}
|
||||
SciFuncs;
|
||||
|
||||
|
@ -167,7 +167,11 @@ static SciFuncs sci_funcs = {
|
||||
&sci_get_contents,
|
||||
&sci_get_contents_range,
|
||||
&sci_get_selection_contents,
|
||||
&sci_set_font
|
||||
&sci_set_font,
|
||||
&sci_get_line_end_position,
|
||||
&sci_set_target_start,
|
||||
&sci_set_target_end,
|
||||
&sci_replace_target
|
||||
};
|
||||
|
||||
static TemplateFuncs template_funcs = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user