Revision: 5077 http://geany.svn.sourceforge.net/geany/?rev=5077&view=rev Author: elextr Date: 2010-07-01 12:08:38 +0000 (Thu, 01 Jul 2010)
Log Message: ----------- Add build config edit subdialog with extra fields. Change arrays to named struct fields.
Modified Paths: -------------- branches/bs2/ChangeLog branches/bs2/src/build.c branches/bs2/src/build.h
Modified: branches/bs2/ChangeLog =================================================================== --- branches/bs2/ChangeLog 2010-07-01 11:49:30 UTC (rev 5076) +++ branches/bs2/ChangeLog 2010-07-01 12:08:38 UTC (rev 5077) @@ -1,3 +1,10 @@ +2010-07-01 Lex Trotman lex@linux-c6rk + + * src/build.c, src/build.h + Add build config edit subdialog with extra fields. + Change arrays to named struct fields. + + 2010-06-29 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
* src/ui_utils.c, THANKS, doc/geany.txt, doc/geany.html:
Modified: branches/bs2/src/build.c =================================================================== --- branches/bs2/src/build.c 2010-07-01 11:49:30 UTC (rev 5076) +++ branches/bs2/src/build.c 2010-07-01 12:08:38 UTC (rev 5077) @@ -145,7 +145,7 @@ kb->key, kb->mods, GTK_ACCEL_VISIBLE); }
- +#if 0 /* convenience routines to access parts of GeanyBuildCommand */ static gchar *id_to_str(GeanyBuildCommand *bc, gint id) { @@ -176,7 +176,7 @@ [GEANY_BC_COMMAND] = "CM", [GEANY_BC_WORKING_DIR] = "WD" }; - +#endif /*----------------------------------------------------- * * Execute commands and handle results @@ -196,102 +196,11 @@ /* project non-fileregex string */ static gchar *regex_proj = NULL;
-/* control if build commands are printed by get_build_cmd, for debug purposes only*/ -#ifndef PRINTBUILDCMDS -#define PRINTBUILDCMDS FALSE -#endif -static gboolean printbuildcmds = PRINTBUILDCMDS; - - -/* for debug only, print the commands structures in priority order */ -static void printfcmds(void) -{ - GeanyBuildCommand **cl[GEANY_GBG_COUNT][GEANY_BCS_COUNT] = { - /* GEANY_BCS_DEF, GEANY_BCS_FT, GEANY_BCS_HOME_FT, GEANY_BCS_PREF, - * GEANY_BCS_FT_PROJ, GEANY_BCS_PROJ */ - { &ft_def, NULL, NULL, NULL, NULL, NULL }, - { &non_ft_def, NULL, NULL, &non_ft_pref, NULL, &non_ft_proj }, - { &exec_def, NULL, NULL, &exec_pref, NULL, &exec_proj } - }; - GeanyFiletype *ft = NULL; - GeanyDocument *doc; - gint i, j, k, l, m; - enum GeanyBuildCmdEntries n; - gint cc[GEANY_BCS_COUNT]; - gchar c; - - doc = document_get_current(); - if (doc != NULL) - ft = doc->file_type; - if (ft != NULL) - { - printf("filetype %s\n",ft->name); - cl[GEANY_GBG_FT][GEANY_BCS_FT] = &(ft->filecmds); - cl[GEANY_GBG_FT][GEANY_BCS_HOME_FT] = &(ft->homefilecmds); - cl[GEANY_GBG_FT][GEANY_BCS_PROJ] = &(ft->projfilecmds); - cl[GEANY_GBG_NON_FT][GEANY_BCS_FT] = &(ft->ftdefcmds); - cl[GEANY_GBG_EXEC][GEANY_BCS_FT] = &(ft->execcmds); - cl[GEANY_GBG_EXEC][GEANY_BCS_HOME_FT] = &(ft->homeexeccmds); - cl[GEANY_GBG_EXEC][GEANY_BCS_PROJ_FT] = &(ft->projexeccmds); - } - for (i = 0; i < GEANY_BCS_COUNT; ++i) - { - m = 1; - for (j = 0; j < GEANY_GBG_COUNT; ++j) - { - for (k = 0; k < build_groups_count[j]; ++k) - if (cl[j][i] != NULL && *(cl[j][i]) != NULL && (*(cl[j][i]))[k].exists) - { - for (n = 0; n < GEANY_BC_CMDENTRIES_COUNT; n++) - { - if ((*(cl[j][i]))[k].entries[n] != NULL && - (l = strlen((*(cl[j][i]))[k].entries[n])) > m) - { - m = l; - } - } - } - } - cc[i] = m; - } - for (i = 0; i < GEANY_GBG_COUNT; ++i) - { - for (k = 0; k < build_groups_count[i]; ++k) - { - for (l = 0; l < 2; ++l) - { - c = ' '; - for (j = 0; j < GEANY_BCS_COUNT; ++j) - { - if (cl[i][j] != NULL && *(cl[i][j]) != NULL && (*(cl[i][j]))[k].exists) - { - for (n = 0; n < GEANY_BC_CMDENTRIES_COUNT; n++) - { - if ((*(cl[i][j]))[k].entries[i] != NULL) - printf("%c %*.*s",c,cc[j],cc[j],(*(cl[i][j]))[k].entries[i]); - else - printf("%c %*.*s",c,cc[j],cc[j]," "); - } - } - else - printf("%c %*.*s",c,cc[j],cc[j]," "); - c = ','; - } - printf("\n"); - } - } - printf("\n"); - } -} - - /* macros to save typing and make the logic visible */ #define return_cmd_if(src, cmds)\ if (cmds != NULL && cmds[cmdindex].exists && below>src)\ { \ *fr=src; \ - if (printbuildcmds) \ - printf("cmd[%d,%d]=%d\n",cmdgrp,cmdindex,src); \ return &(cmds[cmdindex]); \ }
@@ -300,8 +209,6 @@ && ft->cmds[cmdindex].exists && below>src)\ { \ *fr=src; \ - if (printbuildcmds) \ - printf("cmd[%d,%d]=%d\n",cmdgrp,cmdindex,src); \ return &(ft->cmds[cmdindex]); \ }
@@ -314,8 +221,6 @@ GeanyFiletype *ft = NULL; gint sink, *fr = &sink;
- if (printbuildcmds) - printfcmds(); if (cmdgrp >= GEANY_GBG_COUNT) return NULL; if (from != NULL) @@ -775,8 +680,8 @@ have_project = project != NULL; cmd = get_build_cmd(doc, GEANY_GBG_EXEC, cmdindex, NULL);
- cmd_string = build_replace_placeholder(doc, buildcmd_cmd(cmd)); - cmd_working_dir = buildcmd_working_dir(cmd); + cmd_string = build_replace_placeholder(doc, cmd->command); + cmd_working_dir = cmd->wd; if (! NZV(cmd_working_dir)) cmd_working_dir = "%d"; working_dir = build_replace_placeholder(doc, cmd_working_dir); /* in utf-8 */ @@ -1195,7 +1100,7 @@ if (buildcmd == NULL) return;
- cmdstr = buildcmd_cmd(buildcmd); + cmdstr = buildcmd->command;
if (cmd_cat != NULL) { @@ -1207,7 +1112,7 @@ else full_command = cmdstr;
- dir = build_replace_placeholder(doc, buildcmd_working_dir(buildcmd)); + dir = build_replace_placeholder(doc, buildcmd->wd); subs_command = build_replace_placeholder(doc, full_command); build_info.grp = grp; build_info.cmd = cmd; @@ -1271,7 +1176,7 @@ return; } bc = get_build_cmd(doc, grp, cmd, NULL); - if (bc != NULL && strcmp(buildcmd_cmd(bc), "builtin") == 0) + if (bc != NULL && strcmp(bc->command, "builtin") == 0) { gchar *uri; if (doc == NULL) @@ -1406,14 +1311,14 @@ for (j = bs->build_cmd; j < build_groups_count[grp]; ++j) { GeanyBuildCommand *bc = get_build_cmd(NULL, grp, j, NULL); - const gchar *lbl = (bc == NULL) ? "" : buildcmd_label(bc); + const gchar *lbl = (bc == NULL) ? "" : bc->label; create_build_menu_item(menu, keygroup, accel_group, bs, lbl, grp, j); } } else { GeanyBuildCommand *bc = get_build_cmd(NULL, bs->build_grp, bs->build_cmd, NULL); - const gchar *lbl = (bc == NULL) ? "" : buildcmd_label(bc); + const gchar *lbl = (bc == NULL) ? "" : bc->label; create_build_menu_item(menu, keygroup, accel_group, bs, lbl, bs->build_grp, bs->build_cmd); } } @@ -1502,7 +1407,7 @@ const gchar *label; bc = get_build_cmd(doc, grp, cmd, NULL); if (bc) - label = buildcmd_label(bc); + label = bc->label; else label = NULL;
@@ -1722,7 +1627,9 @@ *-------------------------------------------------------*/ typedef struct RowWidgets { - GtkWidget *entries[GEANY_BC_CMDENTRIES_COUNT]; + GtkWidget *label; + GtkWidget *command; + GtkWidget *wd; GeanyBuildSource src; GeanyBuildSource dst; GeanyBuildCommand *cmdsrc; @@ -1730,52 +1637,46 @@ gint cmd; gboolean cleared; gboolean used_dst; + gboolean use_terminal; + gboolean save_all; } RowWidgets;
static GdkColor *insensitive_color; +static const guint entry_x_padding = 3; +static const guint entry_y_padding = 0;
static void set_row_color(RowWidgets *r, GdkColor *color ) { - enum GeanyBuildCmdEntries i; - - for (i = 0; i < GEANY_BC_CMDENTRIES_COUNT; i++) - gtk_widget_modify_text(r->entries[i], GTK_STATE_NORMAL, color); + gtk_widget_modify_text(r->label, GTK_STATE_NORMAL, color); + gtk_widget_modify_text(r->command, GTK_STATE_NORMAL, color); + gtk_widget_modify_text(r->wd, GTK_STATE_NORMAL, color); };
-static void set_build_command_entry_text(GtkWidget *wid, const gchar *text) -{ - if (GTK_IS_BUTTON(wid)) - gtk_button_set_label(GTK_BUTTON(wid), text); - else - gtk_entry_set_text(GTK_ENTRY(wid), text); -} - - static void on_clear_dialog_row(GtkWidget *unused, gpointer user_data) { RowWidgets *r = (RowWidgets*)user_data; gint src; - enum GeanyBuildCmdEntries i; GeanyBuildCommand *bc = get_next_build_cmd(NULL, r->grp, r->cmd, r->dst, &src);
if (bc != NULL) { r->cmdsrc = bc; r->src = src; - for (i = 0; i < GEANY_BC_CMDENTRIES_COUNT; i++) - { - set_build_command_entry_text(r->entries[i], - id_to_str(bc,i) != NULL ? id_to_str(bc,i) : ""); - } + gtk_label_set_text(GTK_LABEL(r->label), bc->label != NULL ? bc->label : ""); + gtk_entry_set_text(GTK_ENTRY(r->command), bc->command != NULL ? bc->command : ""); + gtk_entry_set_text(GTK_ENTRY(r->wd), bc->wd != NULL ? bc->wd : "" ); + r->use_terminal = bc->use_terminal; + r->save_all = bc->save_all; } else { r->cmdsrc = NULL; - for (i = 0; i < GEANY_BC_CMDENTRIES_COUNT; i++) - { - set_build_command_entry_text(r->entries[i], ""); - } + gtk_label_set_text(GTK_LABEL(r->label), ""); + gtk_entry_set_text(GTK_ENTRY(r->command), ""); + gtk_entry_set_text(GTK_ENTRY(r->wd), ""); + r->use_terminal = TRUE; + r->save_all = FALSE; } r->used_dst = FALSE; set_row_color(r, insensitive_color); @@ -1788,7 +1689,7 @@ gtk_entry_set_text(regex,""); }
- +#if 0 static void on_label_button_clicked(GtkWidget *wid, gpointer user_data) { RowWidgets *r = (RowWidgets*)user_data; @@ -1800,8 +1701,68 @@ r->used_dst = TRUE; set_row_color(r, NULL); } +#endif
+ +static void on_edit_row_clicked(GtkWidget *unused, gpointer user_data) +{ + /* Structure to save edit dialog widgets so it doesn't get re-made each use */ + static struct EditDialogWidgets{ + GtkWidget *dialog, *table, *label, *command, *wd, *use_term, *save_all; + } *dw = NULL; + GtkWidget *contents, *lb; + RowWidgets *r = (RowWidgets *)user_data; + gint response; + if (dw == NULL) + { + dw = g_new0(struct EditDialogWidgets, 1); + dw->dialog = gtk_dialog_new_with_buttons(_("Edit Build Command"), NULL, + GTK_DIALOG_MODAL, + GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, + GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, + NULL); + dw->table = gtk_table_new(5, 2, FALSE); + lb = gtk_label_new(_("Menu Item Label:")); + gtk_table_attach(GTK_TABLE(dw->table), lb, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL , GTK_FILL, 0, 0); + dw->label = gtk_entry_new(); + gtk_table_attach(GTK_TABLE(dw->table), dw->label, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL , GTK_FILL, 0, 0); + lb = gtk_label_new(_("Command:")); + gtk_table_attach(GTK_TABLE(dw->table), lb, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL , GTK_FILL, 0, 0); + dw->command = gtk_entry_new(); + gtk_table_attach(GTK_TABLE(dw->table), dw->command, 1, 2, 1, 2, GTK_EXPAND | GTK_FILL , GTK_FILL, 0, 0); + lb = gtk_label_new(_("Working Directory:")); + gtk_table_attach(GTK_TABLE(dw->table), lb, 0, 1, 2, 3, GTK_EXPAND | GTK_FILL , GTK_FILL, 0, 0); + dw->wd = gtk_entry_new(); + gtk_table_attach(GTK_TABLE(dw->table), dw->wd, 1, 2, 2, 3, GTK_EXPAND | GTK_FILL , GTK_FILL, 0, 0); + dw->use_term = gtk_check_button_new_with_label(_("Run in Terminal")); + gtk_table_attach(GTK_TABLE(dw->table), dw->use_term, 0, 2, 3, 4, GTK_EXPAND | GTK_FILL , GTK_FILL, 0, 0); + dw->save_all = gtk_check_button_new_with_label(_("Save all changed documents")); + gtk_table_attach(GTK_TABLE(dw->table), dw->save_all, 0, 2, 4, 5, GTK_EXPAND | GTK_FILL , GTK_FILL, 0, 0); + contents = ui_dialog_vbox_new(GTK_DIALOG(dw->dialog)); + gtk_box_pack_start(GTK_BOX(contents), dw->table, TRUE, TRUE, 0); + gtk_widget_show_all(dw->dialog); + } + gtk_entry_set_text(GTK_ENTRY(dw->label), gtk_label_get_text(GTK_LABEL(r->label))); + gtk_entry_set_text(GTK_ENTRY(dw->command), gtk_entry_get_text(GTK_ENTRY(r->command))); + gtk_entry_set_text(GTK_ENTRY(dw->wd), gtk_entry_get_text(GTK_ENTRY(r->wd))); + if (r->grp != GEANY_GBG_EXEC) gtk_widget_hide(dw->use_term); + else gtk_widget_show(dw->use_term); + response = gtk_dialog_run(GTK_DIALOG(dw->dialog)); + if (response == GTK_RESPONSE_ACCEPT) + { + gtk_label_set_text(GTK_LABEL(r->label), gtk_entry_get_text(GTK_ENTRY(dw->label))); + gtk_entry_set_text(GTK_ENTRY(r->command), gtk_entry_get_text(GTK_ENTRY(dw->command))); + gtk_entry_set_text(GTK_ENTRY(r->wd), gtk_entry_get_text(GTK_ENTRY(dw->wd))); + r->use_terminal = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dw->use_term)); + r->save_all = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dw->save_all)); + r->used_dst = TRUE; + set_row_color(r, NULL); + } + gtk_widget_hide(dw->dialog); +}; + + static void on_entry_focus(GtkWidget *wid, GdkEventFocus *unused, gpointer user_data) { RowWidgets *r = (RowWidgets*)user_data; @@ -1818,26 +1779,25 @@ N_("Label"), N_("Command"), N_("Working directory"), + N_("Edit"), N_("Clear"), NULL }; /* column names */ -#define DC_ITEM 0 -#define DC_ENTRIES 1 -#define DC_CLEAR 4 -#define DC_N_COL 5 +#define DC_ITEM 0 +#define DC_LABEL 1 +#define DC_CMD 2 +#define DC_WD 3 +#define DC_EDIT 4 +#define DC_CLEAR 5 +#define DC_N_COL 6
-static const guint entry_x_padding = 3; -static const guint entry_y_padding = 0; - - static RowWidgets *build_add_dialog_row(GeanyDocument *doc, GtkTable *table, guint row, GeanyBuildSource dst, gint grp, gint cmd, gboolean dir) { - GtkWidget *label, *clear, *clearicon; + GtkWidget *label, *edit, *editicon, *clear, *clearicon; RowWidgets *roww; GeanyBuildCommand *bc; gint src; - enum GeanyBuildCmdEntries i; guint column = 0;
label = gtk_label_new(g_strdup_printf("%d:", cmd + 1)); @@ -1849,56 +1809,52 @@ roww->grp = grp; roww->cmd = cmd; roww->dst = dst; - for (i = 0; i < GEANY_BC_CMDENTRIES_COUNT; i++) + roww->cmdsrc = bc = get_build_cmd(doc, grp, cmd, &src); + if (bc != NULL) { - gint xflags = (i == GEANY_BC_COMMAND) ? GTK_FILL | GTK_EXPAND : GTK_FILL; - - column += 1; - if (i == GEANY_BC_LABEL) - { - GtkWidget *wid = roww->entries[i] = gtk_button_new(); - gtk_button_set_use_underline(GTK_BUTTON(wid), TRUE); - ui_widget_set_tooltip_text(wid, _("Click to set menu item label")); - g_signal_connect(wid, "clicked", G_CALLBACK(on_label_button_clicked), roww); - } - else - { - roww->entries[i] = gtk_entry_new(); - g_signal_connect(roww->entries[i], "focus-in-event", G_CALLBACK(on_entry_focus), roww); - } - gtk_table_attach(table, roww->entries[i], column, column + 1, row, row + 1, xflags, - GTK_FILL | GTK_EXPAND, entry_x_padding, entry_y_padding); + roww->src = src; + if ((gint)dst == src) + roww->used_dst = TRUE; } - column++; + roww->label = gtk_label_new(bc != NULL && bc->label != NULL ? bc->label : ""); + gtk_misc_set_alignment(GTK_MISC(roww->label), 0.0, 0.5); + gtk_table_attach(table, roww->label, DC_LABEL, DC_LABEL + 1, row, row + 1, + GTK_FILL, GTK_FILL | GTK_EXPAND, entry_x_padding, entry_y_padding); + + roww->command = gtk_entry_new(); + gtk_entry_set_text(GTK_ENTRY(roww->command), bc != NULL && bc->command != NULL ? bc->command : ""); + gtk_table_attach(table, roww->command, DC_CMD, DC_CMD + 1, row, row + 1, + GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, entry_x_padding, entry_y_padding); + g_signal_connect(roww->command, "focus-in-event", G_CALLBACK(on_entry_focus), roww); + + roww->wd = gtk_entry_new(); + gtk_entry_set_text(GTK_ENTRY(roww->wd), bc != NULL && bc->wd != NULL ? bc->wd : ""); + gtk_table_attach(table, roww->wd, DC_WD, DC_WD+ 1, row, row + 1, + GTK_FILL, GTK_FILL | GTK_EXPAND, entry_x_padding, entry_y_padding); + g_signal_connect(roww->wd, "focus-in-event", G_CALLBACK(on_entry_focus), roww); + + editicon = gtk_image_new_from_stock(GTK_STOCK_EDIT, GTK_ICON_SIZE_MENU); + edit = gtk_button_new(); + gtk_button_set_image(GTK_BUTTON(edit), editicon); + g_signal_connect(edit, "clicked", G_CALLBACK(on_edit_row_clicked), roww); + gtk_table_attach(table, edit, DC_EDIT, DC_EDIT + 1, row, row + 1, GTK_FILL, + GTK_FILL | GTK_EXPAND, entry_x_padding, entry_y_padding); + clearicon = gtk_image_new_from_stock(GTK_STOCK_CLEAR, GTK_ICON_SIZE_MENU); clear = gtk_button_new(); gtk_button_set_image(GTK_BUTTON(clear), clearicon); g_signal_connect(clear, "clicked", G_CALLBACK(on_clear_dialog_row), roww); - gtk_table_attach(table, clear, column, column + 1, row, row + 1, GTK_FILL, + gtk_table_attach(table, clear, DC_CLEAR, DC_CLEAR + 1, row, row + 1, GTK_FILL, GTK_FILL | GTK_EXPAND, entry_x_padding, entry_y_padding); - roww->cmdsrc = bc = get_build_cmd(doc, grp, cmd, &src); - if (bc != NULL) - roww->src = src;
- for (i = 0; i < GEANY_BC_CMDENTRIES_COUNT; i++) - { - const gchar *str = ""; - - if (bc != NULL ) - { - if ((str = bc->entries[i]) == NULL) - str = ""; - else if ((gint)dst == src) - roww->used_dst = TRUE; - } - set_build_command_entry_text(roww->entries[i], str); - } if (bc != NULL && ((gint)dst > src)) set_row_color(roww, insensitive_color); if (bc != NULL && (src > (gint)dst || (grp == GEANY_GBG_FT && (doc == NULL || doc->file_type == NULL)))) { - for (i = 0; i < GEANY_BC_CMDENTRIES_COUNT; i++) - gtk_widget_set_sensitive(roww->entries[i], FALSE); + gtk_widget_set_sensitive(roww->label, FALSE); + gtk_widget_set_sensitive(roww->command, FALSE); + gtk_widget_set_sensitive(roww->wd, FALSE); + gtk_widget_set_sensitive(edit, FALSE); gtk_widget_set_sensitive(clear, FALSE); } return roww; @@ -1953,7 +1909,7 @@ for (row = 3, cmdindex = 0, cmd = 0; cmd < build_groups_count[GEANY_GBG_FT]; ++row, ++cmdindex, ++cmd) fields->rows[cmdindex] = build_add_dialog_row(doc, table, row, dst, GEANY_GBG_FT, cmd, FALSE); label = gtk_label_new(_("Error Regular Expression:")); - gtk_table_attach(table, label, 0, DC_ENTRIES + 1, row, row + 1, GTK_FILL, GTK_FILL | GTK_EXPAND, + gtk_table_attach(table, label, 0, DC_CMD, row, row + 1, GTK_FILL, GTK_FILL | GTK_EXPAND, entry_x_padding, entry_y_padding); fields->fileregex = gtk_entry_new(); fields->fileregexstring = build_get_regex(GEANY_GBG_FT, NULL, &src); @@ -1964,7 +1920,7 @@ if (src > (gint)dst) sensitivity = FALSE; } - gtk_table_attach(table, fields->fileregex, DC_ENTRIES + 1, DC_CLEAR, row, row + 1, GTK_FILL, + gtk_table_attach(table, fields->fileregex, DC_CMD, DC_EDIT, row, row + 1, GTK_FILL, GTK_FILL | GTK_EXPAND, entry_x_padding, entry_y_padding); clearicon = gtk_image_new_from_stock(GTK_STOCK_CLEAR, GTK_ICON_SIZE_MENU); clear = gtk_button_new(); @@ -1988,7 +1944,7 @@ fields->rows[cmdindex] = build_add_dialog_row( doc, table, row, dst, GEANY_GBG_NON_FT, cmd, TRUE); label = gtk_label_new(_("Error Regular Expression:")); - gtk_table_attach(table, label, 0, DC_ENTRIES + 1, row, row + 1, GTK_FILL, + gtk_table_attach(table, label, 0, DC_CMD, row, row + 1, GTK_FILL, GTK_FILL | GTK_EXPAND, entry_x_padding, entry_y_padding); fields->nonfileregex = gtk_entry_new(); fields->nonfileregexstring = build_get_regex(GEANY_GBG_NON_FT, NULL, &src); @@ -1998,7 +1954,7 @@ gtk_entry_set_text(GTK_ENTRY(fields->nonfileregex), *(fields->nonfileregexstring)); sensitivity = src > (gint)dst ? FALSE : TRUE; } - gtk_table_attach(table, fields->nonfileregex, DC_ENTRIES + 1, DC_CLEAR, row, row + 1, GTK_FILL, + gtk_table_attach(table, fields->nonfileregex, DC_CMD, DC_EDIT, row, row + 1, GTK_FILL, GTK_FILL | GTK_EXPAND, entry_x_padding, entry_y_padding); clearicon = gtk_image_new_from_stock(GTK_STOCK_CLEAR, GTK_ICON_SIZE_MENU); clear = gtk_button_new(); @@ -2064,9 +2020,9 @@ return strlen(a); return strcmp(a, b); } -#endif
+ static const gchar *get_build_command_entry_text(GtkWidget *wid) { if (GTK_IS_BUTTON(wid)) @@ -2075,20 +2031,19 @@ return gtk_entry_get_text(GTK_ENTRY(wid)); }
- +#endif static gboolean read_row(BuildDestination *dst, BuildTableData table_data, gint drow, gint grp, gint cmd) { - gchar *entries[GEANY_BC_CMDENTRIES_COUNT]; + gchar *label, *command, *wd; gboolean changed = FALSE; GeanyBuildSource src; - enum GeanyBuildCmdEntries i;
src = table_data->rows[drow]->src;
- for (i = 0; i < GEANY_BC_CMDENTRIES_COUNT; i++) - { - entries[i] = g_strdup(get_build_command_entry_text(table_data->rows[drow]->entries[i])); - } + label = g_strdup(gtk_label_get_text(GTK_LABEL(table_data->rows[drow]->label))); + command = g_strdup(gtk_entry_get_text(GTK_ENTRY(table_data->rows[drow]->command))); + wd = g_strdup(gtk_entry_get_text(GTK_ENTRY(table_data->rows[drow]->wd))); + if (table_data->rows[drow]->cleared) { if (dst->dst[grp] != NULL) @@ -2106,8 +2061,9 @@ { if (*(dst->dst[grp]) == NULL) *(dst->dst[grp]) = g_new0(GeanyBuildCommand, build_groups_count[grp]); - for (i = 0; i < GEANY_BC_CMDENTRIES_COUNT; i++) - setptr((*(dst->dst[grp]))[cmd].entries[i], entries[i]); + setptr((*(dst->dst[grp]))[cmd].label, label); + setptr((*(dst->dst[grp]))[cmd].command, command); + setptr((*(dst->dst[grp]))[cmd].wd, wd); (*(dst->dst[grp]))[cmd].exists = TRUE; (*(dst->dst[grp]))[cmd].changed = TRUE; changed = TRUE; @@ -2115,8 +2071,9 @@ } else { - for (i = 0; i < GEANY_BC_CMDENTRIES_COUNT; i++) - g_free(entries[i]); + g_free(label); + g_free(command); + g_free(wd); } return changed; } @@ -2257,7 +2214,7 @@ start = build_groups_count[GEANY_GBG_FT]; end = start + build_groups_count[GEANY_GBG_NON_FT]; for (i = start; i < end; ++i) - gtk_entry_set_text(GTK_ENTRY(table_data->rows[i]->entries[GEANY_BC_WORKING_DIR]), "%p"); + gtk_entry_set_text(GTK_ENTRY(table_data->rows[i]->wd), "%p"); }
@@ -2271,7 +2228,7 @@ /* config format for build-menu group is prefix_gg_nn_xx=value * where gg = FT, NF, EX for the command group * nn = 2 digit command number - * xx = LB for label, CM for command and WD for working dir */ + * xx = LB for label, CM for command, WD for working dir, IT in terminal and SA save all */ static const gchar *groups[GEANY_GBG_COUNT] = { "FT", "NF", "EX" }; static const gchar *fixedkey="xx_xx_xx";
@@ -2308,13 +2265,15 @@ if (label != NULL) { dstcmd[cmd].exists = TRUE; - setptr(dstcmd[cmd].entries[GEANY_BC_LABEL], label); - set_key_fld(key,"CM"); - setptr(dstcmd[cmd].entries[GEANY_BC_COMMAND], - g_key_file_get_string(config, build_grp_name, key, NULL)); - set_key_fld(key,"WD"); - setptr(dstcmd[cmd].entries[GEANY_BC_WORKING_DIR], - g_key_file_get_string(config, build_grp_name, key, NULL)); + setptr(dstcmd[cmd].label, label); + set_key_fld(key, "CM"); + setptr(dstcmd[cmd].command, g_key_file_get_string(config, build_grp_name, key, NULL)); + set_key_fld(key, "WD"); + setptr(dstcmd[cmd].wd, g_key_file_get_string(config, build_grp_name, key, NULL)); + set_key_fld(key, "IT"); + dstcmd[cmd].use_terminal = g_key_file_get_boolean(config, build_grp_name, key, NULL); + set_key_fld(key, "SA"); + dstcmd[cmd].save_all = g_key_file_get_boolean(config, build_grp_name, key, NULL); } else dstcmd[cmd].exists = FALSE; } @@ -2402,9 +2361,11 @@ #define ASSIGNIF(type, id, string, value) \ if (NZV(value) && ! type[GBO_TO_CMD(id)].exists) { \ type[GBO_TO_CMD(id)].exists = TRUE; \ - setptr(type[GBO_TO_CMD(id)].entries[GEANY_BC_LABEL], g_strdup(string)); \ - setptr(type[GBO_TO_CMD(id)].entries[GEANY_BC_COMMAND], (value)); \ - setptr(type[GBO_TO_CMD(id)].entries[GEANY_BC_WORKING_DIR], NULL); \ + setptr(type[GBO_TO_CMD(id)].label, g_strdup(string)); \ + setptr(type[GBO_TO_CMD(id)].command, (value)); \ + setptr(type[GBO_TO_CMD(id)].wd, NULL); \ + type[GBO_TO_CMD(id)].use_terminal = TRUE; \ + type[GBO_TO_CMD(id)].save_all = FALSE; \ type[GBO_TO_CMD(id)].old = TRUE; \ } else \ g_free(value); @@ -2449,11 +2410,11 @@ else makebasedir = g_strdup("%d"); if (non_ft_pref[GBO_TO_CMD(GEANY_GBO_MAKE_ALL)].old) - setptr(non_ft_pref[GBO_TO_CMD(GEANY_GBO_MAKE_ALL)].entries[GEANY_BC_WORKING_DIR], g_strdup(makebasedir)); + setptr(non_ft_pref[GBO_TO_CMD(GEANY_GBO_MAKE_ALL)].wd, g_strdup(makebasedir)); if (non_ft_pref[GBO_TO_CMD(GEANY_GBO_CUSTOM)].old) - setptr(non_ft_pref[GBO_TO_CMD(GEANY_GBO_CUSTOM)].entries[GEANY_BC_WORKING_DIR], g_strdup(makebasedir)); + setptr(non_ft_pref[GBO_TO_CMD(GEANY_GBO_CUSTOM)].wd, g_strdup(makebasedir)); if (non_ft_pref[GBO_TO_CMD(GEANY_GBO_MAKE_OBJECT)].old) - setptr(non_ft_pref[GBO_TO_CMD(GEANY_GBO_MAKE_OBJECT)].entries[GEANY_BC_WORKING_DIR], g_strdup("%d")); + setptr(non_ft_pref[GBO_TO_CMD(GEANY_GBO_MAKE_OBJECT)].wd, g_strdup("%d")); value = g_key_file_get_string(config, "project", "run_cmd", NULL); if (NZV(value)) { @@ -2462,9 +2423,9 @@ if (! exec_proj[GBO_TO_CMD(GEANY_GBO_EXEC)].exists) { exec_proj[GBO_TO_CMD(GEANY_GBO_EXEC)].exists = TRUE; - setptr(exec_proj[GBO_TO_CMD(GEANY_GBO_EXEC)].entries[GEANY_BC_LABEL], g_strdup(_("_Execute"))); - setptr(exec_proj[GBO_TO_CMD(GEANY_GBO_EXEC)].entries[GEANY_BC_COMMAND], value); - setptr(exec_proj[GBO_TO_CMD(GEANY_GBO_EXEC)].entries[GEANY_BC_WORKING_DIR], g_strdup(basedir)); + setptr(exec_proj[GBO_TO_CMD(GEANY_GBO_EXEC)].label, g_strdup(_("_Execute"))); + setptr(exec_proj[GBO_TO_CMD(GEANY_GBO_EXEC)].command, value); + setptr(exec_proj[GBO_TO_CMD(GEANY_GBO_EXEC)].wd, g_strdup(basedir)); exec_proj[GBO_TO_CMD(GEANY_GBO_EXEC)].old = TRUE; } } @@ -2495,7 +2456,6 @@ gint cmd, prefixlen; /* NOTE prefixlen used in macros above */ gchar *key; gint count = 0; - enum GeanyBuildCmdEntries i;
if (src == NULL) return 0; @@ -2514,19 +2474,29 @@ set_key_cmd(key, cmdbuf); if (src[cmd].exists) { - for (i = 0; i < GEANY_BC_CMDENTRIES_COUNT; i++) - { - set_key_fld(key, config_keys[i]); - g_key_file_set_string(config, build_grp_name, key, src[cmd].entries[i]); - } + set_key_fld(key, "LB"); + g_key_file_set_string(config, build_grp_name, key, src[cmd].label); + set_key_fld(key, "CM"); + g_key_file_set_string(config, build_grp_name, key, src[cmd].command); + set_key_fld(key, "WD"); + g_key_file_set_string(config, build_grp_name, key, src[cmd].wd); + set_key_fld(key, "IT"); + g_key_file_set_boolean(config, build_grp_name, key, src[cmd].use_terminal); + set_key_fld(key, "SA"); + g_key_file_set_boolean(config, build_grp_name, key, src[cmd].save_all); } else { - for (i = 0; i < GEANY_BC_CMDENTRIES_COUNT; i++) - { - set_key_fld(key, config_keys[i]); - g_key_file_remove_key(config, build_grp_name, key, NULL); - } + set_key_fld(key, "LB"); + g_key_file_remove_key(config, build_grp_name, key, NULL); + set_key_fld(key, "CM"); + g_key_file_remove_key(config, build_grp_name, key, NULL); + set_key_fld(key, "WD"); + g_key_file_remove_key(config, build_grp_name, key, NULL); + set_key_fld(key, "IT"); + g_key_file_remove_key(config, build_grp_name, key, NULL); + set_key_fld(key, "SA"); + g_key_file_remove_key(config, build_grp_name, key, NULL); } } } @@ -2648,15 +2618,17 @@
static struct { - const gchar *entries[GEANY_BC_CMDENTRIES_COUNT]; + const gchar *label; + const gchar *command; + const gchar *wd; GeanyBuildCommand **ptr; gint index; } default_cmds[] = { - { {N_("_Make"), "make", NULL}, &non_ft_def, GBO_TO_CMD(GEANY_GBO_MAKE_ALL)}, - { {N_("Make Custom _Target"), "make ", NULL}, &non_ft_def, GBO_TO_CMD(GEANY_GBO_CUSTOM)}, - { {N_("Make _Object"), "make %e.o", NULL }, &non_ft_def, GBO_TO_CMD(GEANY_GBO_MAKE_OBJECT)}, - { {N_("_Execute"), "./%e", NULL }, &exec_def, GBO_TO_CMD(GEANY_GBO_EXEC)}, - { {NULL, NULL, NULL}, NULL, 0 } + { N_("_Make"), "make", NULL, &non_ft_def, GBO_TO_CMD(GEANY_GBO_MAKE_ALL)}, + { N_("Make Custom _Target"), "make ", NULL, &non_ft_def, GBO_TO_CMD(GEANY_GBO_CUSTOM)}, + { N_("Make _Object"), "make %e.o", NULL, &non_ft_def, GBO_TO_CMD(GEANY_GBO_MAKE_OBJECT)}, + { N_("_Execute"), "./%e", NULL, &exec_def, GBO_TO_CMD(GEANY_GBO_EXEC)}, + { NULL, NULL, NULL, NULL, 0 } };
@@ -2672,15 +2644,15 @@ non_ft_def = g_new0(GeanyBuildCommand, build_groups_count[GEANY_GBG_NON_FT]); exec_def = g_new0(GeanyBuildCommand, build_groups_count[GEANY_GBG_EXEC]); run_info = g_new0(RunInfo, build_groups_count[GEANY_GBG_EXEC]); - for (cmdindex = 0; default_cmds[cmdindex].entries[GEANY_BC_COMMAND] != NULL; ++cmdindex) + for (cmdindex = 0; default_cmds[cmdindex].command != NULL; ++cmdindex) { - enum GeanyBuildCmdEntries k; GeanyBuildCommand *cmd = &((*(default_cmds[cmdindex].ptr))[ default_cmds[cmdindex].index ]); cmd->exists = TRUE; - for (k = 0; k < GEANY_BC_CMDENTRIES_COUNT; k++) - { - cmd->entries[k] = g_strdup(default_cmds[cmdindex].entries[k]); - } + cmd->label = g_strdup(default_cmds[cmdindex].label); + cmd->command = g_strdup(default_cmds[cmdindex].command); + cmd->wd = g_strdup(default_cmds[cmdindex].wd); + cmd->use_terminal = TRUE; + cmd->save_all = FALSE; }
/* create the toolbar Build item sub menu */
Modified: branches/bs2/src/build.h =================================================================== --- branches/bs2/src/build.h 2010-07-01 11:49:30 UTC (rev 5076) +++ branches/bs2/src/build.h 2010-07-01 12:08:38 UTC (rev 5077) @@ -121,6 +121,7 @@
extern GeanyBuildInfo build_info;
+#if 0 /** The entries of a command for a menu item */ typedef enum GeanyBuildCmdEntries { @@ -129,13 +130,18 @@ GEANY_BC_WORKING_DIR, /**< The directory to run in */ GEANY_BC_CMDENTRIES_COUNT /**< Count of entries */ } GeanyBuildCmdEntries; +#endif
/** The command for a menu item. */ typedef struct GeanyBuildCommand { /** Pointers to g_string values of the command entries. * Must be freed if the pointer is changed. */ - gchar *entries[GEANY_BC_CMDENTRIES_COUNT]; + gchar *label; /**< Menu item label */ + gchar *command; /**< Command to run */ + gchar *wd; /**< working directory */ + gboolean use_terminal; /**< execute commands run in a terminal */ + gboolean save_all; /**< save all files before running command */ gboolean exists; /**< If the entries have valid values. */ gboolean changed; /**< Save on exit if @c changed, remove if not @c exist. */ gboolean old; /**< Converted from old format. */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.