Branch: refs/heads/master Author: Lex Trotman elextr@gmail.com Committer: Lex Trotman elextr@gmail.com Date: Wed, 15 Feb 2012 03:18:34 Commit: fa118fb12a0a2a98c6d80939d489cc57c5dcf23b https://github.com/geany/geany/commit/fa118fb12a0a2a98c6d80939d489cc57c5dcf2...
Log Message: ----------- Add build command access to plugin interface
Add ability for plugins to read and edit the fields of the build commands.
Modified Paths: -------------- plugins/geanyfunctions.h src/build.c src/build.h src/plugindata.h src/plugins.c
Modified: plugins/geanyfunctions.h 10 files changed, 10 insertions(+), 0 deletions(-) =================================================================== @@ -420,5 +420,15 @@ geany_functions->p_stash->stash_group_update #define symbols_get_context_separator \ geany_functions->p_symbols->symbols_get_context_separator +#define build_activate_menu_item \ + geany_functions->p_build->build_activate_menu_item +#define build_get_current_menu_item \ + geany_functions->p_build->build_get_current_menu_item +#define build_remove_menu_item \ + geany_functions->p_build->build_remove_menu_item +#define build_set_menu_item \ + geany_functions->p_build->build_set_menu_item +#define build_get_group_count \ + geany_functions->p_build->build_get_group_count
#endif
Modified: src/build.c 162 files changed, 130 insertions(+), 32 deletions(-) =================================================================== @@ -132,7 +132,7 @@ static void show_build_result_message(gboolean failure); static void process_build_output_line(const gchar *line, gint color); static void show_build_commands_dialog(void); - +static void on_build_menu_item(GtkWidget *w, gpointer user_data);
void build_finalize(void) { @@ -422,8 +422,7 @@ static void printfcmds(void) }
-/* get pointer to the command group array */ -static GeanyBuildCommand *get_build_group(GeanyBuildSource src, GeanyBuildGroup grp) +static GeanyBuildCommand **get_build_group_pointer(const GeanyBuildSource src, const GeanyBuildGroup grp) { GeanyDocument *doc; GeanyFiletype *ft = NULL; @@ -435,23 +434,22 @@ static void printfcmds(void) return NULL; if ((ft = doc->file_type) == NULL) return NULL; - switch (src) { - case GEANY_BCS_DEF: return ft->ftdefcmds; - case GEANY_BCS_FT: return ft->filecmds; - case GEANY_BCS_HOME_FT: return ft->homefilecmds; - case GEANY_BCS_PREF: return ft->homefilecmds; - case GEANY_BCS_PROJ: return ft->projfilecmds; + case GEANY_BCS_DEF: return &(ft->ftdefcmds); + case GEANY_BCS_FT: return &(ft->filecmds); + case GEANY_BCS_HOME_FT: return &(ft->homefilecmds); + case GEANY_BCS_PREF: return &(ft->homefilecmds); + case GEANY_BCS_PROJ: return &(ft->projfilecmds); default: return NULL; } break; case GEANY_GBG_NON_FT: switch (src) { - case GEANY_BCS_DEF: return non_ft_def; - case GEANY_BCS_PREF: return non_ft_pref; - case GEANY_BCS_PROJ: return non_ft_proj; + case GEANY_BCS_DEF: return &(non_ft_def); + case GEANY_BCS_PREF: return &(non_ft_pref); + case GEANY_BCS_PROJ: return &(non_ft_proj); default: return NULL; } break; @@ -460,12 +458,12 @@ static void printfcmds(void) ft = doc->file_type; switch (src) { - case GEANY_BCS_DEF: return exec_def; - case GEANY_BCS_FT: return ft ? ft->execcmds: NULL; - case GEANY_BCS_HOME_FT: return ft ? ft->homeexeccmds: NULL; - case GEANY_BCS_PROJ_FT: return ft ? ft->projexeccmds: NULL; - case GEANY_BCS_PREF: return exec_pref; - case GEANY_BCS_PROJ: return exec_proj; + case GEANY_BCS_DEF: return &(exec_def); + case GEANY_BCS_FT: return ft ? &(ft->execcmds): NULL; + case GEANY_BCS_HOME_FT: return ft ? &(ft->homeexeccmds): NULL; + case GEANY_BCS_PROJ_FT: return ft ? &(ft->projexeccmds): NULL; + case GEANY_BCS_PREF: return &(exec_pref); + case GEANY_BCS_PROJ: return &(exec_proj); default: return NULL; } break; @@ -475,7 +473,16 @@ static void printfcmds(void) }
-/* * Remove the specified Build menu item. +/* get pointer to the command group array */ +static GeanyBuildCommand *get_build_group(const GeanyBuildSource src, const GeanyBuildGroup grp) +{ + GeanyBuildCommand **g = get_build_group_pointer(src, grp); + if (g == NULL) return NULL; + return *g; +}; + + +/** Remove the specified Build menu item. * * Makes the specified menu item configuration no longer exist. This * is different to setting fields to blank because the menu item @@ -490,9 +497,10 @@ static void printfcmds(void) * * If any parameter is out of range does nothing. * - * @see build_menu_update + * Updates the menu. + * **/ -void build_remove_menu_item(GeanyBuildSource src, GeanyBuildGroup grp, gint cmd) +void build_remove_menu_item(const GeanyBuildSource src, const GeanyBuildGroup grp, const gint cmd) { GeanyBuildCommand *bc; guint i; @@ -539,30 +547,109 @@ void build_remove_menu_item(GeanyBuildSource src, GeanyBuildGroup grp, gint cmd) }
-/* * Get the @a GeanyBuildCommand structure for the menu item. +/** Get the string for the menu item field. * * Get the current highest priority command specified by @a grp and @a cmd. This is the one * that the menu item will use if activated. * * @param grp the group of the specified menu item. * @param cmd the index of the command within the group. - * @param src pointer to @a gint to return which source provided the command. Ignored if @a NULL. - * Values are one of @a GeanyBuildSource but returns a signed type not the enum. + * @param fld the field to return * - * @return a pointer to the @a GeanyBuildCommand structure or @a NULL if it doesn't exist. + * @return a pointer to the constant string or @a NULL if it doesn't exist. * This is a pointer to an internal structure and must not be freed. * - * @see build_menu_update **/ -/* parameter checked version of get_build_cmd for external interface */ -GeanyBuildCommand *build_get_current_menu_item(GeanyBuildGroup grp, guint cmd, guint *src) +const gchar *build_get_current_menu_item(const GeanyBuildGroup grp, const guint cmd, + const GeanyBuildCmdEntries fld) { - g_return_val_if_fail(*src < GEANY_BCS_COUNT, NULL); + GeanyBuildCommand *c; + gchar *str = NULL; + g_return_val_if_fail(grp < GEANY_GBG_COUNT, NULL); + g_return_val_if_fail(fld < GEANY_BC_CMDENTRIES_COUNT, NULL); g_return_val_if_fail(cmd < build_groups_count[grp], NULL);
- return get_build_cmd(NULL, grp, cmd, src); -} + c = get_build_cmd(NULL, grp, cmd, NULL); + if (c == NULL) return NULL; + switch (fld) + { + case GEANY_BC_COMMAND: + str = c->command; + break; + case GEANY_BC_LABEL: + str = c->label; + break; + case GEANY_BC_WORKING_DIR: + str = c->working_dir; + break; + default: + break; + } + return str; +}; + +/** Set the string for the menu item field. + * + * Set the specified field of the command specified by @a src, @a grp and @a cmd. + * + * @param src the source of the menu item + * @param grp the group of the specified menu item. + * @param cmd the index of the menu item within the group. + * @param fld the field in the menu item command to set + * @param val the value to set the field to, is copied + * + **/ + +void build_set_menu_item(const GeanyBuildSource src, const GeanyBuildGroup grp, + const guint cmd, const GeanyBuildCmdEntries fld, const gchar *val) +{ + GeanyBuildCommand **g; + + g_return_if_fail(src < GEANY_BCS_COUNT); + g_return_if_fail(grp < GEANY_GBG_COUNT); + g_return_if_fail(fld < GEANY_BC_CMDENTRIES_COUNT); + g_return_if_fail(cmd < build_groups_count[grp]); + + g = get_build_group_pointer(src, grp); + if (g == NULL) return; + if (*g == NULL ) + { + *g = g_new0(GeanyBuildCommand, build_groups_count[grp]); + } + switch (fld) + { + case GEANY_BC_COMMAND: + SETPTR((*g)[cmd].command, g_strdup(val)); + (*g)[cmd].exists = TRUE; + break; + case GEANY_BC_LABEL: + SETPTR((*g)[cmd].label, g_strdup(val)); + (*g)[cmd].exists = TRUE; + break; + case GEANY_BC_WORKING_DIR: + SETPTR((*g)[cmd].working_dir, g_strdup(val)); + (*g)[cmd].exists = TRUE; + break; + default: + break; + } + build_menu_update(NULL); +}; + +/** Set the string for the menu item field. + * + * Set the specified field of the command specified by @a src, @a grp and @a cmd. + * + * @param grp the group of the specified menu item. + * @param cmd the index of the command within the group. + * + **/ + +void build_activate_menu_item(const GeanyBuildGroup grp, const guint cmd) +{ + on_build_menu_item(NULL, GRP_CMD_TO_POINTER(grp, cmd)); +};
/* Clear all error indicators in all documents. */ @@ -2688,8 +2775,19 @@ void build_set_group_count(GeanyBuildGroup grp, gint count) }
-guint build_get_group_count(GeanyBuildGroup grp) +/** Get the count of commands for the group + * + * Get the number of commands in the group specified by @a grp. + * + * @param grp the group of the specified menu item. + * + * @return a count of the number of commands in the group + * + **/ + +guint build_get_group_count(const GeanyBuildGroup grp) { + g_return_val_if_fail(grp < GEANY_GBG_COUNT, 0); return build_groups_count[grp]; }
Modified: src/build.h 22 files changed, 14 insertions(+), 8 deletions(-) =================================================================== @@ -19,7 +19,7 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-/* * @file build.h Interface to the Build menu functionality. */ +/** @file build.h Interface to the Build menu functionality. */
#ifndef GEANY_BUILD_H #define GEANY_BUILD_H 1 @@ -40,7 +40,7 @@ GEANY_GBO_COUNT /* *< count of how many */ } GeanyBuildType;
-/* * Groups of Build menu items. */ +/** Groups of Build menu items. */ typedef enum { GEANY_GBG_FT, /* *< filetype items */ @@ -92,7 +92,7 @@ enum GeanyBuildFixedMenuItems GBF_COUNT };
-/* * Build menu item sources in increasing priority */ +/** Build menu item sources in increasing priority */ typedef enum { GEANY_BCS_DEF, /* *< Default values. */ @@ -117,7 +117,7 @@ enum GeanyBuildFixedMenuItems
extern GeanyBuildInfo build_info;
-/* * The entries of a command for a menu item */ +/** The entries of a command for a menu item */ typedef enum GeanyBuildCmdEntries { GEANY_BC_LABEL, /* *< The menu item label, _ marks mnemonic */ @@ -177,11 +177,17 @@ enum GeanyBuildFixedMenuItems
void build_toolbutton_build_clicked(GtkAction *action, gpointer user_data);
-void build_remove_menu_item(GeanyBuildSource src, GeanyBuildGroup grp, gint cmd); +void build_remove_menu_item(const GeanyBuildSource src, const GeanyBuildGroup grp, const gint cmd);
-GeanyBuildCommand *build_get_menu_item(GeanyBuildSource src, GeanyBuildGroup grp, guint cmd); +GeanyBuildCommand *build_get_menu_item(const GeanyBuildSource src, const GeanyBuildGroup grp, const guint cmd);
-GeanyBuildCommand *build_get_current_menu_item(GeanyBuildGroup grp, guint cmd, guint *src); +const gchar *build_get_current_menu_item(const GeanyBuildGroup grp, const guint cmd, + const GeanyBuildCmdEntries field); + +void build_set_menu_item(const GeanyBuildSource src, const GeanyBuildGroup grp, + const guint cmd, const GeanyBuildCmdEntries field, const gchar *value); + +void build_activate_menu_item(const GeanyBuildGroup grp, const guint cmd);
BuildMenuItems *build_get_menu_items(gint filetype_idx);
@@ -192,7 +198,7 @@ enum GeanyBuildFixedMenuItems
void build_set_group_count(GeanyBuildGroup grp, gint count);
-guint build_get_group_count(GeanyBuildGroup grp); +guint build_get_group_count(const GeanyBuildGroup grp);
gchar **build_get_regex(GeanyBuildGroup grp, GeanyFiletype *ft, guint *from);
Modified: src/plugindata.h 25 files changed, 20 insertions(+), 5 deletions(-) =================================================================== @@ -39,6 +39,7 @@ #define GEANY(symbol_name) geany->symbol_name
#include "editor.h" /* GeanyIndentType */ +#include "build.h" /* GeanyBuildGroup, GeanyBuildSource, GeanyBuildCmdEntries enums */
/** The Application Programming Interface (API) version, incremented @@ -52,7 +53,7 @@ * @warning You should not test for values below 200 as previously * @c GEANY_API_VERSION was defined as an enum value, not a macro. */ -#define GEANY_API_VERSION 212 +#define GEANY_API_VERSION 213
/** The Application Binary Interface (ABI) version, incremented whenever * existing fields in the plugin data types have to be changed or reordered. @@ -266,14 +267,15 @@ struct SearchFuncs *p_search; /**< See search.h */ struct HighlightingFuncs *p_highlighting; /**< See highlighting.h */ struct FiletypeFuncs *p_filetypes; /**< See filetypes.h */ - struct NavQueueFuncs *p_navqueue; /**< See navqueue.h */ - struct EditorFuncs *p_editor; /**< See editor.h */ - struct MainFuncs *p_main; /**< See main.h */ - struct PluginFuncs *p_plugin; /**< See pluginutils.c */ + struct NavQueueFuncs *p_navqueue; /**< See navqueue.h */ + struct EditorFuncs *p_editor; /**< See editor.h */ + struct MainFuncs *p_main; /**< See main.h */ + struct PluginFuncs *p_plugin; /**< See pluginutils.c */ struct ScintillaFuncs *p_scintilla; /**< See ScintillaFuncs */ struct MsgWinFuncs *p_msgwin; /**< See msgwindow.h */ struct StashFuncs *p_stash; /**< See stash.h */ struct SymbolsFuncs *p_symbols; /**< See symbols.h */ + struct BuildFuncs *p_build; /**< See build.h */ } GeanyFunctions;
@@ -708,6 +710,19 @@ } SymbolsFuncs;
+/* See build.h */ +typedef struct BuildFuncs +{ + void (*build_activate_menu_item)(const GeanyBuildGroup grp, const guint cmd); + const gchar *(*build_get_current_menu_item)(const GeanyBuildGroup grp, const guint cmd, + const GeanyBuildCmdEntries field); + void (*build_remove_menu_item)(const GeanyBuildSource src, const GeanyBuildGroup grp, + const gint cmd); + void (*build_set_menu_item)(const GeanyBuildSource src, const GeanyBuildGroup grp, + const guint cmd, const GeanyBuildCmdEntries field, const gchar *value); + guint (*build_get_group_count)(const GeanyBuildGroup grp); +} +BuildFuncs;
/* Deprecated aliases */ #ifndef GEANY_DISABLE_DEPRECATED
Modified: src/plugins.c 13 files changed, 11 insertions(+), 2 deletions(-) =================================================================== @@ -46,7 +46,7 @@ #include "msgwindow.h" #include "prefs.h" #include "geanywraplabel.h" -#include "build.h" +/* #include "build.h" included in plugindata.h so it can use enums */ #include "encodings.h" #include "search.h" #include "highlighting.h" @@ -353,6 +353,14 @@ &symbols_get_context_separator };
+static BuildFuncs build_funcs = { + &build_activate_menu_item, + &build_get_current_menu_item, + &build_remove_menu_item, + &build_set_menu_item, + &build_get_group_count +}; + static GeanyFunctions geany_functions = { &doc_funcs, &sci_funcs, @@ -375,7 +383,8 @@ &scintilla_funcs, &msgwin_funcs, &stash_funcs, - &symbols_funcs + &symbols_funcs, + &build_funcs };
static GeanyData geany_data;
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: TBD).