[anjuta] build-basic-autotools: Use a GtkFileChooser dialog instead of a GtkFileChooserButton to select build



commit a72e174cac58c0a5a888abf5dc53035156570c84
Author: SÃbastien Granjoux <seb sfo free fr>
Date:   Sat Jan 26 12:48:44 2013 +0100

    build-basic-autotools: Use a GtkFileChooser dialog instead of a GtkFileChooserButton to select build directory
    
    By using a standard button, the build directory doesn't need to be created
    before displaying it. In addition, it is possible to always start the file chooser
    dialog in the project directory.

 .../anjuta-build-basic-autotools-plugin.ui         |  104 +++++++----
 plugins/build-basic-autotools/build-options.c      |  208 ++++++--------------
 plugins/build-basic-autotools/build.c              |    6 +
 3 files changed, 130 insertions(+), 188 deletions(-)
---
diff --git a/plugins/build-basic-autotools/anjuta-build-basic-autotools-plugin.ui b/plugins/build-basic-autotools/anjuta-build-basic-autotools-plugin.ui
index 5497770..fabfe10 100644
--- a/plugins/build-basic-autotools/anjuta-build-basic-autotools-plugin.ui
+++ b/plugins/build-basic-autotools/anjuta-build-basic-autotools-plugin.ui
@@ -1,7 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
-  <!-- interface-requires anjuta 0.0 -->
   <object class="GtkAdjustment" id="adjustment1">
     <property name="lower">1</property>
     <property name="upper">30</property>
@@ -32,12 +31,10 @@
             <child>
               <object class="GtkButton" id="button2">
                 <property name="label">gtk-cancel</property>
-                <property name="use_action_appearance">False</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
                 <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                <property name="use_action_appearance">False</property>
                 <property name="use_stock">True</property>
               </object>
               <packing>
@@ -49,12 +46,10 @@
             <child>
               <object class="GtkButton" id="ok_button">
                 <property name="label">gtk-execute</property>
-                <property name="use_action_appearance">False</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
                 <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                <property name="use_action_appearance">False</property>
                 <property name="use_stock">True</property>
               </object>
               <packing>
@@ -79,12 +74,10 @@
             <property name="spacing">18</property>
             <child>
               <object class="GtkCheckButton" id="force_autogen_check">
-                <property name="use_action_appearance">False</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">False</property>
                 <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                <property name="use_action_appearance">False</property>
                 <property name="xalign">0</property>
                 <property name="draw_indicator">True</property>
                 <child>
@@ -209,20 +202,6 @@
                           </packing>
                         </child>
                         <child>
-                          <object class="GtkFileChooserButton" id="build_dir_chooser">
-                            <property name="visible">True</property>
-                            <property name="can_focus">False</property>
-                            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                            <property name="action">select-folder</property>
-                            <property name="title" translatable="yes">Select a build directory</property>
-                          </object>
-                          <packing>
-                            <property name="left_attach">1</property>
-                            <property name="right_attach">2</property>
-                            <property name="y_options"></property>
-                          </packing>
-                        </child>
-                        <child>
                           <object class="GtkLabel" id="label2">
                             <property name="visible">True</property>
                             <property name="can_focus">False</property>
@@ -246,6 +225,73 @@
                             <property name="bottom_attach">4</property>
                           </packing>
                         </child>
+                        <child>
+                          <object class="GtkButton" id="build_dir_button">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">True</property>
+                            <child>
+                              <object class="GtkBox" id="box1">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <child>
+                                  <object class="GtkImage" id="image1">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="stock">gtk-directory</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">0</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkLabel" id="build_dir_label">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="xalign">0</property>
+                                    <property name="label" translatable="yes">label</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">True</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">1</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkSeparator" id="separator1">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="orientation">vertical</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">2</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkArrow" id="arrow1">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="arrow_type">down</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">True</property>
+                                    <property name="pack_type">end</property>
+                                    <property name="position">3</property>
+                                  </packing>
+                                </child>
+                              </object>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="left_attach">1</property>
+                            <property name="right_attach">2</property>
+                          </packing>
+                        </child>
                       </object>
                     </child>
                   </object>
@@ -296,12 +342,10 @@
             <child>
               <object class="GtkButton" id="cancelbutton2">
                 <property name="label">gtk-cancel</property>
-                <property name="use_action_appearance">False</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="can_default">True</property>
                 <property name="receives_default">False</property>
-                <property name="use_action_appearance">False</property>
                 <property name="use_stock">True</property>
               </object>
               <packing>
@@ -313,14 +357,12 @@
             <child>
               <object class="GtkButton" id="okbutton3">
                 <property name="label">gtk-ok</property>
-                <property name="use_action_appearance">False</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="has_focus">True</property>
                 <property name="can_default">True</property>
                 <property name="has_default">True</property>
                 <property name="receives_default">False</property>
-                <property name="use_action_appearance">False</property>
                 <property name="use_stock">True</property>
               </object>
               <packing>
@@ -411,12 +453,10 @@
                 <child>
                   <object class="GtkCheckButton" id="program_run_in_terminal">
                     <property name="label" translatable="yes">Run in terminal</property>
-                    <property name="use_action_appearance">False</property>
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="receives_default">False</property>
                     <property name="border_width">5</property>
-                    <property name="use_action_appearance">False</property>
                     <property name="use_underline">True</property>
                     <property name="xalign">0</property>
                     <property name="draw_indicator">True</property>
@@ -508,11 +548,9 @@
                         <child>
                           <object class="GtkCheckButton" id="preferences:parallel-make">
                             <property name="label" translatable="yes">Run several commands at a time:</property>
-                            <property name="use_action_appearance">False</property>
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>
                             <property name="receives_default">False</property>
-                            <property name="use_action_appearance">False</property>
                             <property name="xalign">0</property>
                             <property name="draw_indicator">True</property>
                           </object>
@@ -548,11 +586,9 @@
                     <child>
                       <object class="GtkCheckButton" id="preferences:continue-error">
                         <property name="label" translatable="yes">Continue on errors</property>
-                        <property name="use_action_appearance">False</property>
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <property name="receives_default">False</property>
-                        <property name="use_action_appearance">False</property>
                         <property name="use_underline">True</property>
                         <property name="xalign">0</property>
                         <property name="draw_indicator">True</property>
@@ -566,11 +602,9 @@
                     <child>
                       <object class="GtkCheckButton" id="preferences:translate-message">
                         <property name="label" translatable="yes">Translate messages</property>
-                        <property name="use_action_appearance">False</property>
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <property name="receives_default">False</property>
-                        <property name="use_action_appearance">False</property>
                         <property name="xalign">0</property>
                         <property name="draw_indicator">True</property>
                       </object>
@@ -583,11 +617,9 @@
                     <child>
                       <object class="GtkCheckButton" id="preferences:indicators-automatic">
                         <property name="label" translatable="yes">Highlight build warnings and errors in editor</property>
-                        <property name="use_action_appearance">False</property>
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <property name="receives_default">False</property>
-                        <property name="use_action_appearance">False</property>
                         <property name="use_underline">True</property>
                         <property name="xalign">0</property>
                         <property name="draw_indicator">True</property>
@@ -648,11 +680,9 @@
                         <child>
                           <object class="GtkCheckButton" id="preferences:install-root">
                             <property name="label" translatable="yes">Install as root:</property>
-                            <property name="use_action_appearance">False</property>
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>
                             <property name="receives_default">False</property>
-                            <property name="use_action_appearance">False</property>
                             <property name="use_underline">True</property>
                             <property name="xalign">0</property>
                             <property name="draw_indicator">True</property>
diff --git a/plugins/build-basic-autotools/build-options.c b/plugins/build-basic-autotools/build-options.c
index cee9629..7a0b000 100644
--- a/plugins/build-basic-autotools/build-options.c
+++ b/plugins/build-basic-autotools/build-options.c
@@ -36,13 +36,12 @@
 #define CONFIGURE_DIALOG "configure_dialog"
 #define RUN_AUTOGEN_CHECK "force_autogen_check"
 #define CONFIGURATION_COMBO "configuration_combo_entry"
-#define BUILD_DIR_CHOOSER "build_dir_chooser"
+#define BUILD_DIR_BUTTON "build_dir_button"
+#define BUILD_DIR_LABEL "build_dir_label"
 #define CONFIGURE_ARGS_ENTRY "configure_args_entry"
 #define ENVIRONMENT_EDITOR "environment_editor"
 #define OK_BUTTON "ok_button"
 
-#define GTK_FILE_CHOOSER_CREATE_DIRECTORY_QUARK (build_gtk_file_chooser_create_directory_get_quark ())
-
 
 /* Type defintions
  *---------------------------------------------------------------------------*/
@@ -55,170 +54,70 @@ struct _BuildConfigureDialog
 
 	GtkWidget *combo;
 	GtkWidget *autogen;
-	GtkWidget *build_dir_chooser;
+	GtkWidget *build_dir_button;
+	GtkWidget *build_dir_label;
 	GtkWidget *args;
 	GtkWidget *env_editor;
 	GtkWidget *ok;
 
+	
 	BuildConfigurationList *config_list;
 
 	const gchar *project_uri;
+	GFile *build_file;
 };
 
-typedef struct _BuildMissingDirectory BuildMissingDirectory;
-
-struct _BuildMissingDirectory
-{
-	GFile *exist;
-	GFile *created;
-};
-
-
 /* Create directory at run time for GtkFileChooserButton
  *---------------------------------------------------------------------------*/
 
-/* Create a directories, including parents if necessary, return
- * */
-
-static GFile*
-build_make_directories (GFile *file,
-							   GCancellable *cancellable,
-							   GError **error)
-{
-	GError *path_error = NULL;
-	GList *children = NULL;
-	GFile *parent;
-
-	parent = g_file_get_parent(file);
-
-	for (;;)
-	{
-		if (g_file_make_directory (file, NULL, &path_error))
-		{
-			/* Making child directory succeed */
-			if (children == NULL)
-			{
-				/* All directories have been created */
-				return parent;
-			}
-			else
-			{
-				/* Get next child directory */
-				g_object_unref (file);
-				file = (GFile *)children->data;
-				children = g_list_delete_link (children, children);
-			}
-		}
-		else if (path_error->code == G_IO_ERROR_NOT_FOUND)
-		{
-			g_clear_error (&path_error);
-			children = g_list_prepend (children, file);
-			file = parent;
-			parent = g_file_get_parent(file);
-		}
-		else
-		{
-			g_object_unref (parent);
-			g_propagate_error (error, path_error);
-
-			return NULL;
-		}
-	}
-}
-
-static GQuark
-build_gtk_file_chooser_create_directory_get_quark (void)
-{
-  static GQuark quark = 0;
-
-  if (quark == 0)
-    quark = g_quark_from_static_string ("gtk-file-chooser-create-directory");
-
-  return quark;
-}
-
-/* Remove created directory */
 static void
-on_build_missing_directory_destroyed (BuildMissingDirectory* pack)
+on_build_dir_button_clicked (GtkButton *button, gpointer user_data)
 {
-	/* Remove previously created directories */
-	GFile* created_dir;
-
-	for (created_dir = pack->created; !g_file_equal (created_dir, pack->exist);)
-	{
-		GFile *parent_dir;
-
-		if (!g_file_delete (created_dir, NULL, NULL)) break;
-		parent_dir = g_file_get_parent (created_dir);
-		g_object_unref (created_dir);
-		created_dir = parent_dir;
-	}
-	g_object_unref (created_dir);
-	g_object_unref (pack->exist);
-	g_free (pack);
-}
-
-/* If the folder is missing created it before setting it */
+	BuildConfigureDialog *dlg = (BuildConfigureDialog *)user_data;
+	GtkWidget *chooser;
+	GFile *file = NULL;
 
-static gboolean
-build_gtk_file_chooser_create_and_set_file (GtkFileChooser *chooser, GFile *dir)
-{
-	GError *error = NULL;
-	GFile *parent;
+	chooser = gtk_file_chooser_dialog_new (_("Select a build directory inside the project directory"),
+	                                       GTK_WINDOW (dlg->win),
+	                                       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+	                                       GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+	                                       GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+	                                       NULL);
 
-	parent = build_make_directories (dir, NULL, &error);
-	if (parent != NULL)
+	if (dlg->build_file != NULL)
 	{
-		BuildMissingDirectory* pack;
-
-		pack = g_new (BuildMissingDirectory, 1);
-		pack->exist = parent;
-		pack->created = g_object_ref (dir);
-
-		g_object_set_qdata_full (G_OBJECT (chooser),
-								 GTK_FILE_CHOOSER_CREATE_DIRECTORY_QUARK,
-								 pack,
-								 (GDestroyNotify)on_build_missing_directory_destroyed);
+		if (g_file_make_directory_with_parents (dlg->build_file, NULL, NULL)) file = g_object_ref (dlg->build_file);
+		gtk_file_chooser_set_file (GTK_FILE_CHOOSER (chooser), dlg->build_file, NULL);
 	}
 	else
 	{
-		g_object_set_qdata (G_OBJECT (chooser),
-							GTK_FILE_CHOOSER_CREATE_DIRECTORY_QUARK,
-							NULL);
-		g_error_free (error);
+		gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (chooser), dlg->project_uri);
 	}
 
-	return gtk_file_chooser_set_file (chooser, dir, NULL);
-}
-
-/* Do not delete the automatically created folder */
-static void
-build_gtk_file_chooser_keep_folder (GtkFileChooser *chooser, const char *uri)
-{
-	BuildMissingDirectory* pack;
-
-	pack = g_object_steal_qdata (G_OBJECT (chooser), GTK_FILE_CHOOSER_CREATE_DIRECTORY_QUARK);
-	if (pack != NULL)
+	if (gtk_dialog_run (GTK_DIALOG (chooser)) == GTK_RESPONSE_ACCEPT)
 	{
-		GFile *needed_dir;
-
-		needed_dir = g_file_new_for_uri (uri);
-		if (!g_file_equal (pack->created, needed_dir))
-		{
-			/* Need to delete created directory */
-			on_build_missing_directory_destroyed (pack);
-		}
-		else
+		gchar *basename;
+
+		if (dlg->build_file) g_object_unref (dlg->build_file);
+		dlg->build_file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (chooser));
+		
+		basename = g_file_get_basename (dlg->build_file);
+		gtk_label_set_text (GTK_LABEL (dlg->build_dir_label), basename);
+		g_free (basename);
+	}
+	if (file != NULL)
+	{
+		while ((file != NULL) && g_file_delete (file, NULL, NULL))
 		{
-			g_object_unref (pack->exist);
-			g_object_unref (pack->created);
-			g_free (pack);
+			GFile *child = file;
+			file = g_file_get_parent (child);
+			g_object_unref (child);
 		}
-		g_object_unref (needed_dir);
+		g_object_unref (file);
 	}
+	gtk_widget_destroy (chooser);
 }
 
-
 /* Helper functions
  *---------------------------------------------------------------------------*/
 
@@ -250,20 +149,22 @@ on_select_configuration (GtkComboBox *widget, gpointer user_data)
 
 		gtk_widget_set_sensitive (dlg->ok, TRUE);
 
-		cfg = build_configuration_list_select (dlg->config_list, name);
+		cfg = build_configuration_list_get (dlg->config_list, name);
 
 		if (cfg != NULL)
 		{
 			const gchar *args;
 			GList *item;
-			GFile *file;
+			gchar *basename;
 
 			args = build_configuration_get_args (cfg);
 			gtk_entry_set_text (GTK_ENTRY (dlg->args), args == NULL ? "" : args);
 
-			file = build_configuration_list_get_build_file (dlg->config_list, cfg);
-			build_gtk_file_chooser_create_and_set_file (GTK_FILE_CHOOSER (dlg->build_dir_chooser), file);
-			g_object_unref (file);
+			if (dlg->build_file != NULL) g_object_unref (dlg->build_file);
+			dlg->build_file = build_configuration_list_get_build_file (dlg->config_list, cfg);
+			basename = g_file_get_basename (dlg->build_file);
+			gtk_label_set_text (GTK_LABEL (dlg->build_dir_label), basename);
+			g_free (basename);
 
 			anjuta_environment_editor_reset (ANJUTA_ENVIRONMENT_EDITOR (dlg->env_editor));
 			for (item = build_configuration_get_variables (cfg); item != NULL; item = g_list_next (item))
@@ -314,7 +215,8 @@ build_dialog_configure (GtkWindow* parent, const gchar *project_root_uri, BuildC
 	    CONFIGURE_DIALOG, &dlg.win,
 	    CONFIGURATION_COMBO, &dlg.combo,
 	    RUN_AUTOGEN_CHECK, &dlg.autogen,
-	    BUILD_DIR_CHOOSER, &dlg.build_dir_chooser,
+	    BUILD_DIR_BUTTON, &dlg.build_dir_button,
+	    BUILD_DIR_LABEL, &dlg.build_dir_label,
 	    CONFIGURE_ARGS_ENTRY, &dlg.args,
 	    ENVIRONMENT_EDITOR, &dlg.env_editor,
 	    OK_BUTTON, &dlg.ok,
@@ -323,11 +225,13 @@ build_dialog_configure (GtkWindow* parent, const gchar *project_root_uri, BuildC
 
 	dlg.config_list = config_list;
 	dlg.project_uri = project_root_uri;
+	dlg.build_file = NULL;
 
 	/* Set run autogen option */
 	if (*run_autogen) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg.autogen), TRUE);
 
 	g_signal_connect (dlg.combo, "changed", G_CALLBACK (on_select_configuration), &dlg);
+	g_signal_connect (dlg.build_dir_button, "clicked", G_CALLBACK (on_build_dir_button_clicked), &dlg);
 
 	fill_dialog(&dlg);
 
@@ -336,7 +240,6 @@ build_dialog_configure (GtkWindow* parent, const gchar *project_root_uri, BuildC
 	if (response == GTK_RESPONSE_OK)
 	{
 		gchar *name;
-		gchar *uri;
 		const gchar *args;
 		GtkTreeIter iter;
 		gchar **mod_var;
@@ -358,10 +261,12 @@ build_dialog_configure (GtkWindow* parent, const gchar *project_root_uri, BuildC
 		args = gtk_entry_get_text (GTK_ENTRY (dlg.args));
 		build_configuration_set_args (cfg, args);
 
-		uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dlg.build_dir_chooser));
-		build_configuration_list_set_build_uri (dlg.config_list, cfg, uri);
-		build_gtk_file_chooser_keep_folder (GTK_FILE_CHOOSER (dlg.build_dir_chooser), uri);
-		g_free (uri);
+		if (dlg.build_file != NULL)
+		{
+			gchar *uri = g_file_get_uri (dlg.build_file);
+			build_configuration_list_set_build_uri (dlg.config_list, cfg, uri);
+			g_free (uri);
+		}
 
 		build_configuration_clear_variables (cfg);
 		mod_var = anjuta_environment_editor_get_modified_variables (ANJUTA_ENVIRONMENT_EDITOR (dlg.env_editor));
@@ -379,8 +284,9 @@ build_dialog_configure (GtkWindow* parent, const gchar *project_root_uri, BuildC
 		}
 		g_strfreev (mod_var);
 	}
+	if (dlg.build_file != NULL) g_object_unref (dlg.build_file);
 	gtk_widget_destroy (GTK_WIDGET(dlg.win));
-
+	
 	return cfg != NULL;
 }
 
diff --git a/plugins/build-basic-autotools/build.c b/plugins/build-basic-autotools/build.c
index cba379d..fab04a7 100644
--- a/plugins/build-basic-autotools/build.c
+++ b/plugins/build-basic-autotools/build.c
@@ -945,6 +945,9 @@ build_configure_dir (BasicAutotoolsPlugin *plugin, GFile *dir, const gchar *args
 	config = build_configuration_list_get_selected (plugin->configurations);
 	vars = build_configuration_get_variables (config);
 
+	// Make sure the build directory is here
+	g_file_make_directory_with_parents (dir, NULL, NULL);
+
 	root_path = g_file_get_path (plugin->project_root_dir);
 	quote = shell_quotef ("%s%s%s",
 		       	root_path,
@@ -1072,6 +1075,9 @@ build_generate_dir (BasicAutotoolsPlugin *plugin, GFile *dir, const gchar *args,
 	config = build_configuration_list_get_selected (plugin->configurations);
 	vars = build_configuration_get_variables (config);
 
+	// Make sure the build directory is here
+	g_file_make_directory_with_parents (dir, NULL, NULL);
+
 	if (directory_has_file (plugin->project_root_dir, "autogen.sh"))
 	{
 		gchar *quote;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]