Fix warnings, build API and execute toolbutton

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/build-system@4033 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Lex Trotman 2009-07-28 01:38:41 +00:00
parent e3b1c92aa8
commit 6108436176
6 changed files with 147 additions and 161 deletions

View File

@ -1,3 +1,12 @@
2009-07-28 Lex Trotman <elextr(at)gmail(dot)com>
* src/build.c, src/build.h, src/project.c, src/keyfile.c, src/filetypes.c
Fix some more warnings.
Fix commented out execute/stop toolbar code in build.c.
Add extra plugins documentation for GBO_TO_CMD and GBO_TO_GBG macros.
Changed build.h api so all functions prefixed with build_.
2009-07-27 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
* src/build.c, src/build.h, src/project.c:

View File

@ -113,7 +113,7 @@ static gboolean build_iofunc(GIOChannel *ioc, GIOCondition cond, gpointer data);
#endif
static gboolean build_create_shellscript(const gchar *fname, const gchar *cmd, gboolean autoclose);
static GPid build_spawn_cmd(GeanyDocument *doc, const gchar *cmd, const gchar *dir);
/* static void set_stop_button(gboolean stop); */
static void set_stop_button(gboolean stop);
static void run_exit_cb(GPid child_pid, gint status, gpointer user_data);
static void on_set_build_commands_activate(GtkWidget *w, gpointer u);
static void on_build_next_error(GtkWidget *menuitem, gpointer user_data);
@ -174,9 +174,9 @@ static const gchar* config_keys[] = {
};
/*-----------------------------------------------------
*
*
* Execute commands and handle results
*
*
*-----------------------------------------------------*/
/* the various groups of commands not in the filetype struct */
@ -333,7 +333,7 @@ static GeanyBuildCommand *get_build_cmd(GeanyDocument *doc, gint grp, gint cmdin
#define return_nonblank_regex(src, ptr) if ((ptr)!=NULL && strlen(ptr)>0){ *fr = (src); return &(ptr); }
/* like get_build_cmd, but for regexen, used by filetypes */
gchar **get_build_regex(GeanyBuildGroup grp, GeanyFiletype *ft, gint *from)
gchar **build_get_regex(GeanyBuildGroup grp, GeanyFiletype *ft, gint *from)
{
gint sink, *fr = &sink;
if (from!=NULL) fr=from;
@ -362,7 +362,7 @@ GeanyBuildCommand *get_build_group(GeanyBuildSource src, GeanyBuildGroup grp)
{
GeanyDocument *doc;
GeanyFiletype *ft;
switch(grp)
{
case GBG_FT:
@ -398,7 +398,7 @@ GeanyBuildCommand *get_build_group(GeanyBuildSource src, GeanyBuildGroup grp)
case BCS_PREF: return exec_pref;
case BCS_PROJ: return exec_proj;
default: return NULL;
}
break;
default:
@ -524,7 +524,7 @@ static gchar* build_replace_placeholder(const GeanyDocument* doc, const gchar* s
utils_string_replace_all(stack, "%e", replacement);
g_free(replacement);
}
/* replace %p with the current project's (absolute) base directory */
replacement = NULL; /* prevent double free if no replacement found */
if (app->project)
@ -656,7 +656,7 @@ static gchar *prepare_run_script(GeanyDocument *doc, gchar **vte_cmd_nonscript,
GeanyProject *project = app->project;
GeanyBuildCommand *cmd = NULL;
gchar *executable = NULL;
gchar *working_dir = NULL;
gchar *working_dir = NULL, *cmd_working_dir;
gboolean autoclose = FALSE;
gboolean result = FALSE;
gchar *tmp;
@ -672,7 +672,9 @@ static gchar *prepare_run_script(GeanyDocument *doc, gchar **vte_cmd_nonscript,
cmd_string = build_replace_placeholder(doc, buildcmd_cmd(cmd));
working_dir = build_replace_placeholder(doc, buildcmd_working_dir(cmd)); /* in utf-8 */
cmd_working_dir = buildcmd_working_dir(cmd);
if (!NZV(cmd_working_dir)) cmd_working_dir = "%d";
working_dir = build_replace_placeholder(doc, cmd_working_dir); /* in utf-8 */
/* only test whether working dir exists, don't change it or else Windows support will break
* (gspawn-win32-helper.exe is used by GLib and must be in $PATH which means current working
@ -1031,7 +1033,7 @@ static void build_exit_cb(GPid child_pid, gint status, gpointer user_data)
static void run_exit_cb(GPid child_pid, gint status, gpointer user_data)
{
RunInfo *run_info_data = (RunInfo*)user_data;
g_spawn_close_pid(child_pid);
run_info_data->pid = 0;
@ -1077,7 +1079,7 @@ static void build_command(GeanyDocument *doc, GeanyBuildGroup grp, gint cmd, gch
gchar *full_command, *subs_command;
GeanyBuildCommand *buildcmd = get_build_cmd(doc, grp, cmd, NULL);
gchar* cmdstr;
if (buildcmd==NULL)
return;
@ -1108,9 +1110,9 @@ static void build_command(GeanyDocument *doc, GeanyBuildGroup grp, gint cmd, gch
/*----------------------------------------------------------------
*
*
* Create build menu and handle callbacks (&toolbar callbacks)
*
*
*----------------------------------------------------------------*/
static void on_make_custom_input_response(const gchar *input)
@ -1190,7 +1192,7 @@ static struct build_menu_item_spec {
const gint build_grp, build_cmd;
const gchar *fix_label;
callback *cb;
} build_menu_specs[] = {
} build_menu_specs[] = {
{ GTK_STOCK_CONVERT, GEANY_KEYS_BUILD_COMPILE, GBO_TO_GBG(GBO_COMPILE),
GBO_TO_CMD(GBO_COMPILE), NULL, on_build_menu_item },
{ GEANY_STOCK_BUILD, GEANY_KEYS_BUILD_LINK, GBO_TO_GBG(GBO_BUILD),
@ -1227,7 +1229,7 @@ static struct build_menu_item_spec {
0, NULL, NULL }
};
static void create_build_menu_item(GtkWidget *menu, GeanyKeyGroup *group, GtkAccelGroup *ag,
static void create_build_menu_item(GtkWidget *menu, GeanyKeyGroup *group, GtkAccelGroup *ag,
struct build_menu_item_spec *bs, gchar *lbl, gint grp, gint cmd)
{
GtkWidget *item = gtk_image_menu_item_new_with_mnemonic(lbl);
@ -1235,7 +1237,7 @@ static void create_build_menu_item(GtkWidget *menu, GeanyKeyGroup *group, GtkAcc
{
GtkWidget *image = gtk_image_new_from_stock(bs->stock_id, GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);
}
gtk_widget_show(item);
if (bs->key_binding>0)
@ -1260,7 +1262,7 @@ static void create_build_menu(BuildMenuItems *build_menu_items)
build_menu_items->menu_item[GBG_NON_FT] = g_new0(GtkWidget*, build_groups_count[GBG_NON_FT]);
build_menu_items->menu_item[GBG_EXEC] = g_new0(GtkWidget*, build_groups_count[GBG_EXEC]);
build_menu_items->menu_item[GBG_FIXED] = g_new0(GtkWidget*, GBF_COUNT);
for (i=0; build_menu_specs[i].build_grp != MENU_DONE; ++i)
{
struct build_menu_item_spec *bs = &(build_menu_specs[i]);
@ -1314,9 +1316,9 @@ void build_menu_update(GeanyDocument *doc)
gint i, cmdcount, cmd, grp;
gboolean vis=FALSE;
gboolean have_path, build_running, exec_running, have_errors, cmd_sensitivity;
gboolean can_compile, can_make;
gboolean can_compile, can_make, run_sensitivity, run_running;
GeanyBuildCommand *bc;
if (menu_items.menu==NULL)
create_build_menu(&menu_items);
if (doc == NULL)
@ -1369,7 +1371,7 @@ void build_menu_update(GeanyDocument *doc)
if (grp < GBG_EXEC)
{
cmd_sensitivity =
cmd_sensitivity =
(grp == GBG_FT && bc!=NULL && have_path && ! build_running) ||
(grp == GBG_NON_FT && bc!=NULL && ! build_running);
gtk_widget_set_sensitive(menu_item, cmd_sensitivity);
@ -1389,6 +1391,7 @@ void build_menu_update(GeanyDocument *doc)
exec_running = run_info[cmd].pid>1;
cmd_sensitivity = bc!=NULL || exec_running;
gtk_widget_set_sensitive(menu_item, cmd_sensitivity);
if (cmd==GBO_TO_CMD(GBO_EXEC)) run_sensitivity = cmd_sensitivity;
if (!exec_running)
{
image = gtk_image_new_from_stock(bs->stock_id, GTK_ICON_SIZE_MENU);
@ -1397,6 +1400,7 @@ void build_menu_update(GeanyDocument *doc)
{
image = gtk_image_new_from_stock(GTK_STOCK_STOP, GTK_ICON_SIZE_MENU);
}
if (cmd==GBO_TO_CMD(GBO_EXEC)) run_running = exec_running;
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_item), image);
if (bc != NULL && label != NULL
&& strlen(label) > 0)
@ -1411,44 +1415,41 @@ void build_menu_update(GeanyDocument *doc)
}
}
}
can_compile = get_build_cmd(doc, GBG_FT, GBO_TO_CMD(GBO_BUILD), NULL)!=NULL
&& have_path && ! build_running;
if (widgets.toolitem_build != NULL)
gtk_widget_set_sensitive(widgets.toolitem_build, can_compile);
can_make = FALSE;
if (widgets.toolitem_make_all != NULL)
gtk_widget_set_sensitive(widgets.toolitem_make_all,
(can_make |= get_build_cmd(doc, GBG_FT, GBO_TO_CMD(GBO_MAKE_ALL), NULL)!=NULL
gtk_widget_set_sensitive(widgets.toolitem_make_all,
(can_make |= get_build_cmd(doc, GBG_FT, GBO_TO_CMD(GBO_MAKE_ALL), NULL)!=NULL
&& ! build_running));
if (widgets.toolitem_make_custom != NULL)
gtk_widget_set_sensitive(widgets.toolitem_make_custom,
(can_make |= get_build_cmd(doc, GBG_FT, GBO_TO_CMD(GBO_MAKE_CUSTOM), NULL)!=NULL
gtk_widget_set_sensitive(widgets.toolitem_make_custom,
(can_make |= get_build_cmd(doc, GBG_FT, GBO_TO_CMD(GBO_MAKE_CUSTOM), NULL)!=NULL
&& ! build_running));
if (widgets.toolitem_make_object != NULL)
gtk_widget_set_sensitive(widgets.toolitem_make_object,
(can_make |= get_build_cmd(doc, GBG_FT, GBO_TO_CMD(GBO_MAKE_OBJECT), NULL)!=NULL
(can_make |= get_build_cmd(doc, GBG_FT, GBO_TO_CMD(GBO_MAKE_OBJECT), NULL)!=NULL
&& ! build_running));
if (widgets.toolitem_set_args != NULL)
gtk_widget_set_sensitive(widgets.toolitem_set_args, TRUE);
gtk_action_set_sensitive(widgets.compile_action, can_compile);
gtk_action_set_sensitive(widgets.build_action, can_make );
/* gtk_action_set_sensitive(widgets.run_action, can_run || can_stop); */
gtk_action_set_sensitive(widgets.run_action, run_sensitivity);
/* show the stop command if a program is running, otherwise show run command
set_stop_button(can_stop); */
/* show the stop command if a program is running from execute 0 , otherwise show run command */
set_stop_button(run_running);
}
/* Call build_menu_update() instead of calling this directly. */
#if 0
static void set_stop_button(gboolean stop)
{
const gchar *button_stock_id = NULL;
GtkStockItem sitem;
GtkToolButton *run_button;
GtkWidget *menuitem = build_get_menu_items(run_info.file_type_id)->item_exec;
run_button = GTK_TOOL_BUTTON(toolbar_get_widget_by_name("Run"));
if (run_button != NULL)
@ -1459,38 +1460,18 @@ static void set_stop_button(gboolean stop)
if (! stop && utils_str_equal(button_stock_id, "gtk-execute"))
return;
/* use the run button also as stop button */
/* use the run button also as stop button */
if (stop)
{
if (run_button != NULL)
gtk_tool_button_set_stock_id(run_button, "gtk-stop");
if (menuitem != NULL)
{
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem),
gtk_image_new_from_stock("gtk-stop", GTK_ICON_SIZE_MENU));
gtk_stock_lookup("gtk-stop", &sitem);
gtk_label_set_text_with_mnemonic(GTK_LABEL(gtk_bin_get_child(GTK_BIN(menuitem))),
sitem.label);
}
}
else
{
if (run_button != NULL)
gtk_tool_button_set_stock_id(run_button, "gtk-execute");
if (menuitem != NULL)
{
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem),
gtk_image_new_from_stock("gtk-execute", GTK_ICON_SIZE_MENU));
gtk_stock_lookup("gtk-execute", &sitem);
gtk_label_set_text_with_mnemonic(GTK_LABEL(gtk_bin_get_child(GTK_BIN(menuitem))),
sitem.label);
}
}
}
#endif
static void on_set_build_commands_activate(GtkWidget *w, gpointer u)
{
@ -1596,9 +1577,9 @@ void build_toolbutton_build_clicked(GtkAction *action, gpointer unused)
}
/*------------------------------------------------------
*
*
* Create and handle the build menu configuration dialog
*
*
*-------------------------------------------------------*/
typedef struct RowWidgets {
@ -1663,11 +1644,11 @@ static RowWidgets *build_add_dialog_row(GeanyDocument *doc, GtkTable *table, gin
GtkWidget *label, *clear, *clearicon;
RowWidgets *roww;
GeanyBuildCommand *bc;
guint src;
gint src;
enum GeanyBuildCmdEntries i;
gint column = 0;
label = gtk_label_new(g_strdup_printf("%d:", cmd+1));
gtk_table_attach(table, label, column, column+1, row, row+1, GTK_FILL, GTK_FILL | GTK_EXPAND,
entry_x_padding, entry_y_padding);
@ -1722,7 +1703,7 @@ GtkWidget *build_commands_table(GeanyDocument *doc, GeanyBuildSource dst, TableD
GtkTable *table;
gchar **ch, *txt;
gint col, row, cmdindex, cmd;
guint src;
gint src;
gboolean sensitivity;
table = GTK_TABLE(gtk_table_new(build_items_count+12, 5, FALSE));
@ -1752,7 +1733,7 @@ GtkWidget *build_commands_table(GeanyDocument *doc, GeanyBuildSource dst, TableD
gtk_table_attach(table, label, 0, DC_ENTRIES+1, row, row+1, GTK_FILL, GTK_FILL | GTK_EXPAND,
entry_x_padding, entry_y_padding);
fields->fileregex = gtk_entry_new();
fields->fileregexstring = get_build_regex(GBG_FT, NULL, &src);
fields->fileregexstring = build_get_regex(GBG_FT, NULL, &src);
sensitivity = ft==NULL?FALSE:TRUE;
if (fields->fileregexstring!=NULL && *(fields->fileregexstring)!=NULL)
{
@ -1785,7 +1766,7 @@ GtkWidget *build_commands_table(GeanyDocument *doc, GeanyBuildSource dst, TableD
gtk_table_attach(table, label, 0, DC_ENTRIES+1, row, row+1, GTK_FILL, GTK_FILL | GTK_EXPAND,
entry_x_padding, entry_y_padding);
fields->nonfileregex = gtk_entry_new();
fields->nonfileregexstring = get_build_regex(GBG_NON_FT, NULL, &src);
fields->nonfileregexstring = build_get_regex(GBG_NON_FT, NULL, &src);
sensitivity = TRUE;
if (fields->nonfileregexstring!=NULL && *(fields->nonfileregexstring)!=NULL)
{
@ -1882,7 +1863,7 @@ static gboolean read_row(BuildDestination *dst, TableData table_data, gint drow,
&&
(
strlen(entries[BC_LABEL])>0 /* but now one field has some */
|| strlen(entries[BC_COMMAND])>0
|| strlen(entries[BC_COMMAND])>0
|| strlen(entries[BC_WORKING_DIR])>0
)
)
@ -1948,7 +1929,7 @@ gboolean read_build_commands(BuildDestination *dst, TableData table_data, gint r
{
gint cmdindex, cmd;
gboolean changed = FALSE;
if (response == GTK_RESPONSE_ACCEPT)
{
for (cmdindex=0, cmd=0; cmd<build_groups_count[GBG_FT]; ++cmdindex, ++cmd)
@ -1981,11 +1962,11 @@ static void show_build_commands_dialog()
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL);
table = build_commands_table(doc, BCS_PREF, &table_data, ft);
vbox = ui_dialog_vbox_new(GTK_DIALOG(dialog));
gtk_box_pack_start(GTK_BOX(vbox), table, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(vbox), table, TRUE, TRUE, 0);
gtk_widget_show_all(dialog);
/* run modally to prevent user changing idx filetype */
response = gtk_dialog_run(GTK_DIALOG(dialog));
prefdsts.dst[GBG_NON_FT] = &non_ft_pref;
prefdsts.dst[GBG_EXEC] = &exec_pref;
if (ft!=NULL)
@ -2001,7 +1982,7 @@ static void show_build_commands_dialog()
prefdsts.nonfileregexstr = &regex_pref;
read_build_commands(&prefdsts, table_data, response);
free_build_fields(table_data);
build_menu_update(doc);
gtk_widget_destroy(dialog);
}
@ -2027,9 +2008,9 @@ void set_build_non_ft_wd_to_proj(TableData table_data)
}
/*----------------------------------------------------------
*
*
* Load and store configuration
*
*
* ---------------------------------------------------------*/
static const gchar *build_grp_name = "build-menu";
@ -2045,14 +2026,14 @@ static const gchar *fixedkey="xx_xx_xx";
#define set_key_cmd(key,cmd) (key[prefixlen+3]=cmd[0], key[prefixlen+4]=cmd[1])
#define set_key_fld(key,fld) (key[prefixlen+6]=fld[0], key[prefixlen+7]=fld[1])
static void load_build_menu_grp(GKeyFile *config, GeanyBuildCommand **dst, gint grp,
static void build_load_menu_grp(GKeyFile *config, GeanyBuildCommand **dst, gint grp,
gchar *prefix, gboolean loc)
{
gint cmd, prefixlen; /* NOTE prefixlen used in macros above */
GeanyBuildCommand *dstcmd;
gchar *key;
static gchar cmdbuf[3]=" ";
if (*dst==NULL)*dst = g_new0(GeanyBuildCommand, build_groups_count[grp]);
dstcmd = *dst;
prefixlen = prefix==NULL?0:strlen(prefix);
@ -2085,9 +2066,9 @@ static void load_build_menu_grp(GKeyFile *config, GeanyBuildCommand **dst, gint
g_free(key);
}
/* for the specified source load new format build menu items or try to make some sense of
/* for the specified source load new format build menu items or try to make some sense of
* old format setings, not done perfectly but better than ignoring them */
void load_build_menu(GKeyFile *config, GeanyBuildSource src, gpointer p)
void build_load_menu(GKeyFile *config, GeanyBuildSource src, gpointer p)
{
/* gint grp;*/
GeanyFiletype *ft;
@ -2103,28 +2084,28 @@ void load_build_menu(GKeyFile *config, GeanyBuildSource src, gpointer p)
case BCS_FT:
ft = (GeanyFiletype*)p;
if (ft==NULL)return;
load_build_menu_grp(config, &(ft->filecmds), GBG_FT, NULL, TRUE);
load_build_menu_grp(config, &(ft->ftdefcmds), GBG_NON_FT, NULL, TRUE);
load_build_menu_grp(config, &(ft->execcmds), GBG_EXEC, NULL, TRUE);
build_load_menu_grp(config, &(ft->filecmds), GBG_FT, NULL, TRUE);
build_load_menu_grp(config, &(ft->ftdefcmds), GBG_NON_FT, NULL, TRUE);
build_load_menu_grp(config, &(ft->execcmds), GBG_EXEC, NULL, TRUE);
setptr(ft->error_regex_string,
g_key_file_get_string(config, build_grp_name, "error_regex", NULL));
break;
case BCS_HOME_FT:
ft = (GeanyFiletype*)p;
if (ft==NULL)return;
load_build_menu_grp(config, &(ft->homefilecmds), GBG_FT, NULL, FALSE);
load_build_menu_grp(config, &(ft->homeexeccmds), GBG_EXEC, NULL, FALSE);
build_load_menu_grp(config, &(ft->homefilecmds), GBG_FT, NULL, FALSE);
build_load_menu_grp(config, &(ft->homeexeccmds), GBG_EXEC, NULL, FALSE);
setptr(ft->homeerror_regex_string,
g_key_file_get_string(config, build_grp_name, "error_regex", NULL));
break;
case BCS_PREF:
load_build_menu_grp(config, &non_ft_pref, GBG_NON_FT, NULL, FALSE);
load_build_menu_grp(config, &exec_pref, GBG_EXEC, NULL, FALSE);
build_load_menu_grp(config, &non_ft_pref, GBG_NON_FT, NULL, FALSE);
build_load_menu_grp(config, &exec_pref, GBG_EXEC, NULL, FALSE);
setptr(regex_pref, g_key_file_get_string(config, build_grp_name, "error_regex", NULL));
break;
case BCS_PROJ:
load_build_menu_grp(config, &non_ft_proj, GBG_NON_FT, NULL, FALSE);
load_build_menu_grp(config, &exec_proj, GBG_EXEC, NULL, FALSE);
build_load_menu_grp(config, &non_ft_proj, GBG_NON_FT, NULL, FALSE);
build_load_menu_grp(config, &exec_proj, GBG_EXEC, NULL, FALSE);
setptr(regex_proj, g_key_file_get_string(config, build_grp_name, "error_regex", NULL));
pj = (GeanyProject*)p;
if (p==NULL)return;
@ -2141,7 +2122,7 @@ void load_build_menu(GKeyFile *config, GeanyBuildSource src, gpointer p)
{
gchar *regkey = g_strdup_printf("%serror_regex", *ftname);
g_ptr_array_add(pj->build_filetypes_list, ft);
load_build_menu_grp(config, &(ft->projfilecmds), GBG_FT, *ftname, FALSE);
build_load_menu_grp(config, &(ft->projfilecmds), GBG_FT, *ftname, FALSE);
setptr(ft->projerror_regex_string,
g_key_file_get_string(config, build_grp_name, regkey, NULL));
g_free(regkey);
@ -2154,9 +2135,9 @@ void load_build_menu(GKeyFile *config, GeanyBuildSource src, gpointer p)
break;
}
}
/* load old [build_settings] values if there is no value defined by [build-menu] */
/* set GeanyBuildCommand if it doesn't already exist and there is a command */
#define ASSIGNIF(type, id, string, value) \
if (value!=NULL && !type[GBO_TO_CMD(id)].exists && strlen(value)>0) { \
@ -2167,7 +2148,7 @@ void load_build_menu(GKeyFile *config, GeanyBuildSource src, gpointer p)
type[GBO_TO_CMD(id)].old = TRUE; \
} else \
g_free(value);
switch(src)
{
case BCS_FT:
@ -2214,13 +2195,13 @@ void load_build_menu(GKeyFile *config, GeanyBuildSource src, gpointer p)
}
}
static gint save_build_menu_grp(GKeyFile *config, GeanyBuildCommand *src, gint grp, gchar *prefix)
static gint build_save_menu_grp(GKeyFile *config, GeanyBuildCommand *src, gint grp, gchar *prefix)
{
gint cmd, prefixlen; /* NOTE prefixlen used in macros above */
gchar *key;
gint count=0;
enum GeanyBuildCmdEntries i;
if (src==NULL)return 0;
prefixlen = prefix==NULL?0:strlen(prefix);
key = g_strconcat(prefix==NULL?"":prefix, fixedkey, NULL);
@ -2245,7 +2226,7 @@ static gint save_build_menu_grp(GKeyFile *config, GeanyBuildCommand *src, gint g
else
{
FOREACH_GEANYBUILDCMD_ENTRY(i)
{
{
set_key_fld(key, config_keys[i]);
g_key_file_remove_key(config, build_grp_name, key, NULL);
}
@ -2268,8 +2249,8 @@ static void foreach_project_filetype(gpointer data, gpointer user_data)
ForEachData *d = (ForEachData*)user_data;
gint i=0;
gchar *regkey = g_strdup_printf("%serror_regex", ft->name);
i += save_build_menu_grp(d->config, ft->projfilecmds, GBG_FT, ft->name);
i += build_save_menu_grp(d->config, ft->projfilecmds, GBG_FT, ft->name);
if (ft->projerror_regex_string!=NULL && strlen(ft->projerror_regex_string)>0)
{
g_key_file_set_string(d->config, build_grp_name, regkey, ft->projerror_regex_string);
@ -2281,20 +2262,20 @@ static void foreach_project_filetype(gpointer data, gpointer user_data)
if (i>0)g_ptr_array_add(d->ft_names, ft->name);
}
void save_build_menu(GKeyFile *config, gpointer ptr, GeanyBuildSource src)
void build_save_menu(GKeyFile *config, gpointer ptr, GeanyBuildSource src)
{
GeanyFiletype *ft;
GeanyProject *pj;
ForEachData data;
gchar *regkey;
switch(src)
{
case BCS_HOME_FT:
ft = (GeanyFiletype*)ptr;
if (ft==NULL)return;
save_build_menu_grp(config, ft->homefilecmds, GBG_FT, NULL);
save_build_menu_grp(config, ft->homeexeccmds, GBG_EXEC, NULL);
build_save_menu_grp(config, ft->homefilecmds, GBG_FT, NULL);
build_save_menu_grp(config, ft->homeexeccmds, GBG_EXEC, NULL);
regkey = g_strdup_printf("%serror_regex", ft->name);
if (ft->homeerror_regex_string!=NULL && strlen(ft->homeerror_regex_string)>0)
g_key_file_set_string(config, build_grp_name, regkey, ft->projerror_regex_string);
@ -2303,8 +2284,8 @@ void save_build_menu(GKeyFile *config, gpointer ptr, GeanyBuildSource src)
g_free(regkey);
break;
case BCS_PREF:
save_build_menu_grp(config, non_ft_pref, GBG_NON_FT, NULL);
save_build_menu_grp(config, exec_pref, GBG_EXEC, NULL);
build_save_menu_grp(config, non_ft_pref, GBG_NON_FT, NULL);
build_save_menu_grp(config, exec_pref, GBG_EXEC, NULL);
if (regex_pref!=NULL && strlen(regex_pref)>0)
g_key_file_set_string(config, build_grp_name, "error_regex", regex_pref);
else
@ -2312,8 +2293,8 @@ void save_build_menu(GKeyFile *config, gpointer ptr, GeanyBuildSource src)
break;
case BCS_PROJ:
pj = (GeanyProject*)ptr;
save_build_menu_grp(config, non_ft_proj, GBG_NON_FT, NULL);
save_build_menu_grp(config, exec_proj, GBG_EXEC, NULL);
build_save_menu_grp(config, non_ft_proj, GBG_NON_FT, NULL);
build_save_menu_grp(config, exec_proj, GBG_EXEC, NULL);
if (regex_proj!=NULL && strlen(regex_proj)>0)
g_key_file_set_string(config, build_grp_name, "error_regex", regex_proj);
else
@ -2336,7 +2317,7 @@ void save_build_menu(GKeyFile *config, gpointer ptr, GeanyBuildSource src)
}
}
void set_build_grp_count(GeanyBuildGroup grp, gint count)
void build_set_group_count(GeanyBuildGroup grp, gint count)
{
gint i, sum;
if (count>build_groups_count[grp])
@ -2345,7 +2326,7 @@ void set_build_grp_count(GeanyBuildGroup grp, gint count)
build_items_count = sum;
}
gint get_build_group_count(GeanyBuildGroup grp)
gint build_get_group_count(GeanyBuildGroup grp)
{
return build_groups_count[grp];
}
@ -2354,9 +2335,9 @@ static struct {
gchar *entries[BC_CMDENTRIES_COUNT];
GeanyBuildCommand **ptr;
gint index;
} default_cmds[] = {
{ {N_("_Make"), "make", NULL}, &non_ft_def, GBO_TO_CMD(GBO_MAKE_ALL)},
{ {N_("Make Custom _Target"), "make ", NULL}, &non_ft_def, GBO_TO_CMD(GBO_MAKE_CUSTOM)},
} default_cmds[] = {
{ {N_("_Make"), "make", NULL}, &non_ft_def, GBO_TO_CMD(GBO_MAKE_ALL)},
{ {N_("Make Custom _Target"), "make ", NULL}, &non_ft_def, GBO_TO_CMD(GBO_MAKE_CUSTOM)},
{ {N_("Make _Object"), "make %e.o", NULL }, &non_ft_def, GBO_TO_CMD(GBO_MAKE_OBJECT)},
{ {N_("_Execute"), "./%e", NULL }, &exec_def, GBO_TO_CMD(GBO_EXEC)},
{ {NULL, NULL, NULL}, NULL, 0 }

View File

@ -28,17 +28,20 @@
#define GEANY_BUILD_ERR_HIGHLIGHT_MAX 100
/* Geany Known Build Commands, currently only these can have keybindings
* Order is important (see GBO_TO_GBG, GBO_TO_CMD below) */
/* Order is important (see GBO_TO_GBG, GBO_TO_CMD below) */
/** Geany Known Build Commands.
* These commands are named after their default use.
* Only these commands can currently have keybindings.
**/
typedef enum
{
GBO_COMPILE,
GBO_BUILD,
GBO_MAKE_ALL,
GBO_MAKE_CUSTOM,
GBO_MAKE_OBJECT,
GBO_EXEC,
GBO_COUNT /* count of how many */
GBO_COMPILE, /**< default compile file */
GBO_BUILD, /**< default build file */
GBO_MAKE_ALL, /**< default make */
GBO_MAKE_CUSTOM, /**< default make user specified target */
GBO_MAKE_OBJECT, /**< default make object, make %e.o */
GBO_EXEC, /**< default execute ./%e */
GBO_COUNT /**< count of how many */
} GeanyBuildType;
/** Groups of Build menu items. */
@ -53,10 +56,33 @@ typedef enum
/* include the fixed widgets in an array indexed by groups */
#define GBG_FIXED GBG_COUNT
/* convert GBO_xxx to GBG_xxx and command number
* Note they are macros so they can be used in static initialisers */
#define GBO_TO_GBG(gbo) ((gbo)>GBO_EXEC?GBG_COUNT:((gbo)>=GBO_EXEC?GBG_EXEC:((gbo)>=GBO_MAKE_ALL?GBG_NON_FT:GBG_FT)))
#define GBO_TO_CMD(gbo) ((gbo)>=GBO_COUNT?(gbo)-GBO_COUNT:((gbo)>=GBO_EXEC?(gbo)-GBO_EXEC:((gbo)>=GBO_MAKE_ALL?(gbo)-GBO_MAKE_ALL:(gbo))))
/** Convert @c GeanyBuildType to @c GeanyBuildGroup .
*
* This macro converts @c GeanyBiuildType enum values (the "known" commands)
* to the group they are part of.
*
* @param gbo the @c GeanyBuildType value.
*
* @return the @c GeanyBuildGroup group that @a gbo is in.
*
* Note this is a macro so that it can be used in static initialisers
**/
#define GBO_TO_GBG(gbo) ((gbo)>GBO_EXEC?GBG_COUNT:((gbo)>=GBO_EXEC?GBG_EXEC: \
((gbo)>=GBO_MAKE_ALL?GBG_NON_FT:GBG_FT)))
/** Convert @c GeanyBuildType to command index.
*
* This macro converts @c GeanyBuildType enum values (the "known" commands)
* to the index within the group.
*
* @param gbo the @c GeanyBuildType value.
*
* @return the index of the @a gbo command in its group.
*
* Note this is a macro so that it can be used in static initialisers
**/
#define GBO_TO_CMD(gbo) ((gbo)>=GBO_COUNT?(gbo)-GBO_COUNT:((gbo)>=GBO_EXEC?(gbo)-GBO_EXEC: \
((gbo)>=GBO_MAKE_ALL?(gbo)-GBO_MAKE_ALL:(gbo))))
enum GeanyBuildFixedMenuItems
{
@ -230,14 +256,14 @@ GeanyBuildCommand *build_get_current_menu_item(GeanyBuildGroup grp, gint cmd, gi
BuildMenuItems *build_get_menu_items(gint filetype_idx);
/* load and store menu configuration */
void load_build_menu( GKeyFile *config, GeanyBuildSource dst, gpointer ptr);
void build_load_menu( GKeyFile *config, GeanyBuildSource dst, gpointer ptr);
void save_build_menu( GKeyFile *config, gpointer ptr, GeanyBuildSource src);
void build_save_menu( GKeyFile *config, gpointer ptr, GeanyBuildSource src);
void set_build_grp_count(GeanyBuildGroup grp, gint count);
void build_set_group_count(GeanyBuildGroup grp, gint count);
gint get_build_group_count(GeanyBuildGroup grp);
gint build_get_group_count(GeanyBuildGroup grp);
gchar **get_build_regex(GeanyBuildGroup grp, GeanyFiletype *ft, gint *from);
gchar **build_get_regex(GeanyBuildGroup grp, GeanyFiletype *ft, gint *from);
#endif

View File

@ -1126,8 +1126,8 @@ static void load_settings(gint ft_id, GKeyFile *config, GKeyFile *configh)
}
/* read build settings */
load_build_menu( config, BCS_FT, (gpointer)ft );
load_build_menu( configh, BCS_HOME_FT, (gpointer)ft );
build_load_menu( config, BCS_FT, (gpointer)ft );
build_load_menu( configh, BCS_HOME_FT, (gpointer)ft );
}
@ -1226,7 +1226,7 @@ void filetypes_save_commands(void)
g_free(ext);
config_home = g_key_file_new();
g_key_file_load_from_file(config_home, fname, G_KEY_FILE_KEEP_COMMENTS, NULL);
save_build_menu(config_home, (gpointer)(filetypes[i]), BCS_HOME_FT);
build_save_menu(config_home, (gpointer)(filetypes[i]), BCS_HOME_FT);
data = g_key_file_to_data(config_home, NULL, NULL);
utils_write_file(fname, data);
g_free(data);
@ -1346,7 +1346,7 @@ gboolean filetypes_parse_error_message(GeanyFiletype *ft, const gchar *message,
doc = document_get_current();
if(doc!=NULL)ft = doc->file_type;
}
tmp = get_build_regex(build_info.grp, ft, NULL);
tmp = build_get_regex(build_info.grp, ft, NULL);
if (tmp==NULL) return FALSE;
regstr = *tmp;
#ifndef HAVE_REGCOMP

View File

@ -407,7 +407,7 @@ static void save_dialog_prefs(GKeyFile *config)
g_key_file_set_string(config, PACKAGE, "context_action_cmd", tool_prefs.context_action_cmd);
/* build menu */
save_build_menu( config, NULL, BCS_PREF );
build_save_menu( config, NULL, BCS_PREF );
/* printing */
g_key_file_set_string(config, "printing", "print_cmd", printing_prefs.external_print_cmd ? printing_prefs.external_print_cmd : "");
@ -773,10 +773,10 @@ static void load_dialog_prefs(GKeyFile *config)
tool_prefs.context_action_cmd = utils_get_setting_string(config, PACKAGE, "context_action_cmd", "");
/* build menu */
set_build_grp_count( GBG_FT, utils_get_setting_integer( config, "build-menu", "number_ft_menu_items", 0 ));
set_build_grp_count( GBG_NON_FT, utils_get_setting_integer( config, "build-menu", "number_non_ft_menu_items", 0 ));
set_build_grp_count( GBG_EXEC, utils_get_setting_integer( config, "build-menu", "number_exec_menu_items", 0 ));
load_build_menu( config, BCS_PREF, NULL );
build_set_group_count( GBG_FT, utils_get_setting_integer( config, "build-menu", "number_ft_menu_items", 0 ));
build_set_group_count( GBG_NON_FT, utils_get_setting_integer( config, "build-menu", "number_non_ft_menu_items", 0 ));
build_set_group_count( GBG_EXEC, utils_get_setting_integer( config, "build-menu", "number_exec_menu_items", 0 ));
build_load_menu( config, BCS_PREF, NULL );
/* printing */
tmp_string2 = g_find_program_in_path(GEANY_DEFAULT_TOOLS_PRINTCMD);

View File

@ -86,7 +86,6 @@ typedef struct _PropertyDialogElements
static gboolean update_config(const PropertyDialogElements *e);
static void on_file_save_button_clicked(GtkButton *button, PropertyDialogElements *e);
static void on_file_open_button_clicked(GtkButton *button, PropertyDialogElements *e);
static gboolean load_config(const gchar *filename);
static gboolean write_config(gboolean emit_signal);
static void on_name_entry_changed(GtkEditable *editable, PropertyDialogElements *e);
@ -868,35 +867,6 @@ static void on_file_save_button_clicked(GtkButton *button, PropertyDialogElement
}
static void on_file_open_button_clicked(GtkButton *button, PropertyDialogElements *e)
{
#ifdef G_OS_WIN32
gchar *path = win32_show_project_open_dialog(e->dialog, _("Choose Project Run Command"),
gtk_entry_get_text(GTK_ENTRY(e->run_cmd)), FALSE, FALSE);
if (path != NULL)
{
gtk_entry_set_text(GTK_ENTRY(e->run_cmd), path);
g_free(path);
}
#else
GtkWidget *dialog;
/* initialise the dialog */
dialog = gtk_file_chooser_dialog_new(_("Choose Project Run Command"), NULL,
GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
gtk_widget_set_name(dialog, "GeanyDialog");
gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE);
gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), TRUE);
gtk_window_set_type_hint(GTK_WINDOW(dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
run_dialog(dialog, e->run_cmd);
#endif
}
/* sets the project base path and the project file name according to the project name */
static void on_name_entry_changed(GtkEditable *editable, PropertyDialogElements *e)
{
@ -999,7 +969,7 @@ static gboolean load_config(const gchar *filename)
p->run_cmd = utils_get_setting_string(config, "project", "run_cmd", "");
p->file_patterns = g_key_file_get_string_list(config, "project", "file_patterns", NULL, NULL);
load_build_menu( config, BCS_PROJ, (gpointer)p );
build_load_menu( config, BCS_PROJ, (gpointer)p );
if (project_prefs.project_session)
{
/* save current (non-project) session (it could has been changed since program startup) */
@ -1056,7 +1026,7 @@ static gboolean write_config(gboolean emit_signal)
/* store the session files into the project too */
if (project_prefs.project_session)
configuration_save_session_files(config);
save_build_menu( config, (gpointer)p, BCS_PROJ );
build_save_menu( config, (gpointer)p, BCS_PROJ );
if (emit_signal)
{
g_signal_emit_by_name(geany_object, "project-save", config);