1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 Copyright (C) 2008 Sébastien Granjoux
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "build-options.h"
23 #include <glib/gi18n.h>
25 #include <libanjuta/anjuta-debug.h>
26 #include <libanjuta/anjuta-shell.h>
27 #include <libanjuta/anjuta-utils.h>
28 #include <libanjuta/anjuta-environment-editor.h>
32 *---------------------------------------------------------------------------*/
34 #define BUILDER_FILE PACKAGE_DATA_DIR "/glade/anjuta-build-basic-autotools-plugin.ui"
36 #define CONFIGURE_DIALOG "configure_dialog"
37 #define RUN_AUTOGEN_CHECK "force_autogen_check"
38 #define CONFIGURATION_COMBO "configuration_combo_entry"
39 #define BUILD_DIR_BUTTON "build_dir_button"
40 #define BUILD_DIR_LABEL "build_dir_label"
41 #define CONFIGURE_ARGS_ENTRY "configure_args_entry"
42 #define ENVIRONMENT_EDITOR "environment_editor"
43 #define OK_BUTTON "ok_button"
47 *---------------------------------------------------------------------------*/
49 typedef struct _BuildConfigureDialog BuildConfigureDialog
;
51 struct _BuildConfigureDialog
57 GtkWidget
*build_dir_button
;
58 GtkWidget
*build_dir_label
;
60 GtkWidget
*env_editor
;
64 BuildConfigurationList
*config_list
;
66 const gchar
*project_uri
;
70 /* Create directory at run time for GtkFileChooserButton
71 *---------------------------------------------------------------------------*/
74 on_build_dir_button_clicked (GtkButton
*button
, gpointer user_data
)
76 BuildConfigureDialog
*dlg
= (BuildConfigureDialog
*)user_data
;
80 chooser
= gtk_file_chooser_dialog_new (_("Select a build directory inside the project directory"),
81 GTK_WINDOW (dlg
->win
),
82 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER
,
83 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
84 GTK_STOCK_OPEN
, GTK_RESPONSE_ACCEPT
,
87 if (dlg
->build_file
!= NULL
)
89 if (g_file_make_directory_with_parents (dlg
->build_file
, NULL
, NULL
)) file
= g_object_ref (dlg
->build_file
);
90 gtk_file_chooser_set_file (GTK_FILE_CHOOSER (chooser
), dlg
->build_file
, NULL
);
94 gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (chooser
), dlg
->project_uri
);
97 if (gtk_dialog_run (GTK_DIALOG (chooser
)) == GTK_RESPONSE_ACCEPT
)
101 if (dlg
->build_file
) g_object_unref (dlg
->build_file
);
102 dlg
->build_file
= gtk_file_chooser_get_file (GTK_FILE_CHOOSER (chooser
));
104 basename
= g_file_get_basename (dlg
->build_file
);
105 gtk_label_set_text (GTK_LABEL (dlg
->build_dir_label
), basename
);
110 while ((file
!= NULL
) && g_file_delete (file
, NULL
, NULL
))
113 file
= g_file_get_parent (child
);
114 g_object_unref (child
);
116 g_object_unref (file
);
118 gtk_widget_destroy (chooser
);
122 *---------------------------------------------------------------------------*/
125 on_select_configuration (GtkComboBox
*widget
, gpointer user_data
)
127 BuildConfigureDialog
*dlg
= (BuildConfigureDialog
*)user_data
;
131 if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (dlg
->combo
), &iter
))
133 gtk_tree_model_get (gtk_combo_box_get_model (GTK_COMBO_BOX (dlg
->combo
)), &iter
, 1, &name
, -1);
137 GtkWidget
* entry
= gtk_bin_get_child (GTK_BIN (dlg
->combo
));
138 name
= g_strdup(gtk_entry_get_text (GTK_ENTRY (entry
)));
143 /* Configuration name is mandatory disable Ok button */
144 gtk_widget_set_sensitive (dlg
->ok
, FALSE
);
148 BuildConfiguration
*cfg
;
150 gtk_widget_set_sensitive (dlg
->ok
, TRUE
);
152 cfg
= build_configuration_list_get (dlg
->config_list
, name
);
160 args
= build_configuration_get_args (cfg
);
161 gtk_entry_set_text (GTK_ENTRY (dlg
->args
), args
== NULL
? "" : args
);
163 if (dlg
->build_file
!= NULL
) g_object_unref (dlg
->build_file
);
164 dlg
->build_file
= build_configuration_list_get_build_file (dlg
->config_list
, cfg
);
165 basename
= g_file_get_basename (dlg
->build_file
);
166 gtk_label_set_text (GTK_LABEL (dlg
->build_dir_label
), basename
);
169 anjuta_environment_editor_reset (ANJUTA_ENVIRONMENT_EDITOR (dlg
->env_editor
));
170 for (item
= build_configuration_get_variables (cfg
); item
!= NULL
; item
= g_list_next (item
))
172 anjuta_environment_editor_set_variable (ANJUTA_ENVIRONMENT_EDITOR (dlg
->env_editor
), (gchar
*)item
->data
);
180 fill_dialog (BuildConfigureDialog
*dlg
)
182 GtkListStore
* store
= gtk_list_store_new(2, G_TYPE_STRING
, G_TYPE_STRING
);
183 BuildConfiguration
*cfg
;
185 gtk_combo_box_set_model (GTK_COMBO_BOX(dlg
->combo
), GTK_TREE_MODEL(store
));
186 gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX (dlg
->combo
), 0);
188 for (cfg
= build_configuration_list_get_first (dlg
->config_list
); cfg
!= NULL
; cfg
= build_configuration_next (cfg
))
192 gtk_list_store_append (store
, &iter
);
193 gtk_list_store_set (store
, &iter
, 0, build_configuration_get_translated_name (cfg
), 1, build_configuration_get_name (cfg
), -1);
195 gtk_combo_box_set_active (GTK_COMBO_BOX (dlg
->combo
),
196 build_configuration_list_get_position (dlg
->config_list
,
197 build_configuration_list_get_selected (dlg
->config_list
)));
201 *---------------------------------------------------------------------------*/
204 build_dialog_configure (GtkWindow
* parent
, const gchar
*project_root_uri
, BuildConfigurationList
*config_list
, gboolean
*run_autogen
)
207 BuildConfigureDialog dlg
;
208 BuildConfiguration
*cfg
= NULL
;
211 /* Get all dialog widgets */
212 bxml
= anjuta_util_builder_new (BUILDER_FILE
, NULL
);
213 if (bxml
== NULL
) return FALSE
;
214 anjuta_util_builder_get_objects (bxml
,
215 CONFIGURE_DIALOG
, &dlg
.win
,
216 CONFIGURATION_COMBO
, &dlg
.combo
,
217 RUN_AUTOGEN_CHECK
, &dlg
.autogen
,
218 BUILD_DIR_BUTTON
, &dlg
.build_dir_button
,
219 BUILD_DIR_LABEL
, &dlg
.build_dir_label
,
220 CONFIGURE_ARGS_ENTRY
, &dlg
.args
,
221 ENVIRONMENT_EDITOR
, &dlg
.env_editor
,
224 g_object_unref (bxml
);
226 dlg
.config_list
= config_list
;
227 dlg
.project_uri
= project_root_uri
;
228 dlg
.build_file
= NULL
;
230 /* Set run autogen option */
231 if (*run_autogen
) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg
.autogen
), TRUE
);
233 g_signal_connect (dlg
.combo
, "changed", G_CALLBACK (on_select_configuration
), &dlg
);
234 g_signal_connect (dlg
.build_dir_button
, "clicked", G_CALLBACK (on_build_dir_button_clicked
), &dlg
);
238 response
= gtk_dialog_run (GTK_DIALOG (dlg
.win
));
240 if (response
== GTK_RESPONSE_OK
)
247 *run_autogen
= gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dlg
.autogen
));
249 if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (dlg
.combo
), &iter
))
251 gtk_tree_model_get (gtk_combo_box_get_model (GTK_COMBO_BOX (dlg
.combo
)), &iter
, 1, &name
, -1);
255 GtkWidget
* entry
= gtk_bin_get_child (GTK_BIN (dlg
.combo
));
256 name
= g_strdup (gtk_entry_get_text (GTK_ENTRY (entry
)));
258 cfg
= build_configuration_list_create (config_list
, name
);
261 args
= gtk_entry_get_text (GTK_ENTRY (dlg
.args
));
262 build_configuration_set_args (cfg
, args
);
264 if (dlg
.build_file
!= NULL
)
266 gchar
*uri
= g_file_get_uri (dlg
.build_file
);
267 build_configuration_list_set_build_uri (dlg
.config_list
, cfg
, uri
);
271 build_configuration_clear_variables (cfg
);
272 mod_var
= anjuta_environment_editor_get_modified_variables (ANJUTA_ENVIRONMENT_EDITOR (dlg
.env_editor
));
273 if ((mod_var
!= NULL
) && (*mod_var
!= NULL
))
277 for (var
= mod_var
; *var
!= NULL
; var
++);
281 build_configuration_set_variable (cfg
, *var
);
283 while (var
!= mod_var
);
285 g_strfreev (mod_var
);
287 if (dlg
.build_file
!= NULL
) g_object_unref (dlg
.build_file
);
288 gtk_widget_destroy (GTK_WIDGET(dlg
.win
));