[anjuta] file-wizard: Use the new project node chooser



commit 8a4c387b2b190edd4d2be15caabe743dd5e84951
Author: SÃbastien Granjoux <seb sfo free fr>
Date:   Fri Jan 6 22:27:33 2012 +0100

    file-wizard: Use the new project node chooser

 plugins/file-wizard/anjuta-file-wizard.plugin.in |    1 +
 plugins/file-wizard/anjuta-file-wizard.ui        |  192 ++++++++++++---------
 plugins/file-wizard/file.c                       |  211 +++++++++++++---------
 3 files changed, 234 insertions(+), 170 deletions(-)
---
diff --git a/plugins/file-wizard/anjuta-file-wizard.plugin.in b/plugins/file-wizard/anjuta-file-wizard.plugin.in
index 0451741..40c2eb2 100644
--- a/plugins/file-wizard/anjuta-file-wizard.plugin.in
+++ b/plugins/file-wizard/anjuta-file-wizard.plugin.in
@@ -4,6 +4,7 @@ _Description=Anjuta File Assistant Plugin
 Location=anjuta-file-wizard:AnjutaFileWizardPlugin
 Icon=anjuta-file-wizard-plugin-48.png
 Interfaces=IAnjutaWizard
+Dependencies=anjuta-project-manager:ProjectManagerPlugin
 UserActivatable=no
 
 [Wizard]
diff --git a/plugins/file-wizard/anjuta-file-wizard.ui b/plugins/file-wizard/anjuta-file-wizard.ui
index 55cc825..02a8340 100644
--- a/plugins/file-wizard/anjuta-file-wizard.ui
+++ b/plugins/file-wizard/anjuta-file-wizard.ui
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
-  <requires lib="gtk+" version="2.16"/>
+  <!-- interface-requires gtk+ 3.0 -->
+  <!-- interface-requires anjuta 0.0 -->
   <object class="GtkDialog" id="dialog.new.file">
     <property name="can_focus">False</property>
     <property name="border_width">5</property>
@@ -15,6 +16,55 @@
         <property name="can_focus">False</property>
         <property name="orientation">vertical</property>
         <property name="spacing">5</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox" id="dialog-action_area1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="cancelbutton1">
+                <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>
+                <signal name="clicked" handler="on_new_file_cancelbutton_clicked" swapped="no"/>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="okbutton">
+                <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="can_default">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_action_appearance">False</property>
+                <property name="use_stock">True</property>
+                <signal name="clicked" handler="on_new_file_okbutton_clicked" swapped="no"/>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
         <child>
           <object class="GtkVBox" id="vbox1124">
             <property name="visible">True</property>
@@ -203,13 +253,14 @@ The extension will be added according to the type.</property>
                       <object class="GtkTable" id="table32">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
-                        <property name="n_rows">5</property>
+                        <property name="n_rows">7</property>
                         <property name="n_columns">2</property>
                         <property name="column_spacing">6</property>
                         <property name="row_spacing">6</property>
                         <child>
                           <object class="GtkCheckButton" id="new.file.license">
                             <property name="label" translatable="yes">Add License Information</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>
@@ -262,6 +313,7 @@ The extension will be added according to the type.</property>
                         <child>
                           <object class="GtkCheckButton" id="new.file.header">
                             <property name="label" translatable="yes">Create corresponding header file</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>
@@ -280,6 +332,7 @@ The extension will be added according to the type.</property>
                         <child>
                           <object class="GtkCheckButton" id="new.file.template">
                             <property name="label" translatable="yes">Use Template for the Header file</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>
@@ -296,50 +349,68 @@ The extension will be added according to the type.</property>
                           </packing>
                         </child>
                         <child>
-                          <object class="GtkHBox" id="hbox1129">
+                          <object class="GtkCheckButton" id="add_to_project">
+                            <property name="label" translatable="yes">Add to project</property>
+                            <property name="use_action_appearance">False</property>
                             <property name="visible">True</property>
-                            <property name="can_focus">False</property>
-                            <property name="homogeneous">True</property>
-                            <child>
-                              <object class="GtkCheckButton" id="add_to_project">
-                                <property name="label" translatable="yes">Add to project</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="active">True</property>
-                                <property name="draw_indicator">True</property>
-                              </object>
-                              <packing>
-                                <property name="expand">True</property>
-                                <property name="fill">True</property>
-                                <property name="position">0</property>
-                              </packing>
-                            </child>
-                            <child>
-                              <object class="GtkCheckButton" id="add_to_repository">
-                                <property name="label" translatable="yes">Add to repository</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="active">True</property>
-                                <property name="draw_indicator">True</property>
-                              </object>
-                              <packing>
-                                <property name="expand">True</property>
-                                <property name="fill">True</property>
-                                <property name="position">1</property>
-                              </packing>
-                            </child>
+                            <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="active">True</property>
+                            <property name="draw_indicator">True</property>
                           </object>
                           <packing>
                             <property name="right_attach">2</property>
                             <property name="top_attach">4</property>
                             <property name="bottom_attach">5</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkCheckButton" id="add_to_repository">
+                            <property name="label" translatable="yes">Add to repository</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="active">True</property>
+                            <property name="draw_indicator">True</property>
+                          </object>
+                          <packing>
+                            <property name="right_attach">2</property>
+                            <property name="top_attach">6</property>
+                            <property name="bottom_attach">7</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="add_to_project.label">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="xalign">0</property>
+                            <property name="label" translatable="yes">Parent:</property>
+                          </object>
+                          <packing>
+                            <property name="top_attach">5</property>
+                            <property name="bottom_attach">6</property>
                             <property name="x_options">GTK_FILL</property>
+                            <property name="y_options"></property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="AnjutaPmChooserButton" id="add_to_project.combo.parent">
+                            <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="use_action_appearance">False</property>
+                          </object>
+                          <packing>
+                            <property name="left_attach">1</property>
+                            <property name="right_attach">2</property>
+                            <property name="top_attach">5</property>
+                            <property name="bottom_attach">6</property>
                           </packing>
                         </child>
                       </object>
@@ -370,52 +441,11 @@ The extension will be added according to the type.</property>
             <property name="position">2</property>
           </packing>
         </child>
-        <child internal-child="action_area">
-          <object class="GtkButtonBox" id="dialog-action_area1">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="layout_style">end</property>
-            <child>
-              <object class="GtkButton" id="cancelbutton1">
-                <property name="label">gtk-cancel</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>
-                <signal name="clicked" handler="on_new_file_cancelbutton_clicked" swapped="no"/>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkButton" id="okbutton1">
-                <property name="label">gtk-ok</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>
-                <signal name="clicked" handler="on_new_file_okbutton_clicked" swapped="no"/>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">1</property>
-              </packing>
-            </child>
-          </object>
-        </child>
       </object>
     </child>
     <action-widgets>
       <action-widget response="0">cancelbutton1</action-widget>
-      <action-widget response="0">okbutton1</action-widget>
+      <action-widget response="0">okbutton</action-widget>
     </action-widgets>
   </object>
   <object class="GtkListStore" id="new.file.menu.license.store">
diff --git a/plugins/file-wizard/file.c b/plugins/file-wizard/file.c
index f184a2f..db92a38 100644
--- a/plugins/file-wizard/file.c
+++ b/plugins/file-wizard/file.c
@@ -38,6 +38,7 @@
 #include <libanjuta/interfaces/ianjuta-file.h>
 #include <libanjuta/interfaces/ianjuta-project.h>
 #include <libanjuta/interfaces/ianjuta-project-manager.h>
+#include <libanjuta/interfaces/ianjuta-project-chooser.h>
 #include <libanjuta/interfaces/ianjuta-vcs.h>
 
 #include "plugin.h"
@@ -45,6 +46,7 @@
 
 #define BUILDER_FILE_FILE PACKAGE_DATA_DIR "/glade/anjuta-file-wizard.ui"
 #define NEW_FILE_DIALOG "dialog.new.file"
+#define NEW_FILE_OK_BUTTON "okbutton"
 #define NEW_FILE_ENTRY "new.file.entry"
 #define NEW_FILE_TYPE "new.file.type"
 #define NEW_FILE_TYPE_STORE "new.file.type.store"
@@ -54,6 +56,8 @@
 #define NEW_FILE_MENU_LICENSE "new.file.menu.license"
 #define NEW_FILE_MENU_LICENSE_STORE "new.file.menu.license.store"
 #define NEW_FILE_ADD_TO_PROJECT "add_to_project"
+#define NEW_FILE_ADD_TO_PROJECT_PARENT "add_to_project.combo.parent"
+#define NEW_FILE_ADD_TO_PROJECT_LABEL "add_to_project.label"
 #define NEW_FILE_ADD_TO_REPOSITORY "add_to_repository"
 
 typedef struct _NewFileGUI
@@ -62,6 +66,9 @@ typedef struct _NewFileGUI
 	GtkWidget *dialog;
 	GtkWidget *add_to_project;
 	GtkWidget *add_to_repository;
+	GtkWidget *add_to_project_label;
+	GtkWidget *add_to_project_parent;
+	GtkWidget *ok_button;
 	gboolean showing;
 	AnjutaFileWizardPlugin *plugin;
 } NewFileGUI;
@@ -114,13 +121,32 @@ static void insert_notice(IAnjutaSnippetsManager* snippets_manager, const gchar*
 static void insert_header(IAnjutaSnippetsManager* snippets_manager, gint source_type);
 
 static void
+on_project_parent_changed (GtkWidget *project_combo, NewFileGUI *gui)
+{
+	gboolean active = TRUE;
+
+	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gui->add_to_project)))
+	{
+		GFile *file;
+
+		file = ianjuta_project_chooser_get_selected (IANJUTA_PROJECT_CHOOSER (gui->add_to_project_parent), NULL);
+		active = file != NULL;
+	}
+	gtk_widget_set_sensitive (gui->ok_button, active);
+}
+
+static void
 on_add_to_project_toggled (GtkWidget* toggle_button, NewFileGUI *gui)
 {
 	gboolean status = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(toggle_button));
 	gtk_widget_set_sensitive (gui->add_to_repository, status);
+	gtk_widget_set_sensitive (gui->add_to_project_parent, status);
 	if (!status)
+	{
 		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(gui->add_to_repository),
 		                              FALSE);
+	}
+	on_project_parent_changed (toggle_button, gui);
 }
 
 void
@@ -128,40 +154,48 @@ display_new_file(AnjutaFileWizardPlugin *plugin,
 				 IAnjutaDocumentManager *docman)
 {
 	gint caps = 0;
-	
+	gboolean has_project;
+
 	if (!nfg)
 		if (!create_new_file_dialog (docman))
 			return;
-	
+
 	nfg->plugin = plugin;
-	
+
 	/* check whether we have a loaded project or not */
 	if (plugin->top_dir) {
 		IAnjutaProjectManager *manager =
 			anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin)->shell,
 										IAnjutaProjectManager, NULL);
-       if (manager)
+		if (manager)
+		{
 			caps = ianjuta_project_manager_get_capabilities (manager, NULL);
+			/* Add combo node selection */
+			ianjuta_project_chooser_set_project_model (IANJUTA_PROJECT_CHOOSER (nfg->add_to_project_parent),
+			                                           IANJUTA_PROJECT_MANAGER (manager),
+			                                           ANJUTA_PROJECT_SOURCE,
+			                                           NULL);
+			on_project_parent_changed (nfg->add_to_project_parent, nfg);
+		}
 	}
 
-	g_signal_connect (nfg->add_to_project, "toggled", 
+	g_signal_connect (nfg->add_to_project, "toggled",
 	                  G_CALLBACK(on_add_to_project_toggled),
 	                  nfg);
-	
-	if ((caps & ANJUTA_PROJECT_CAN_ADD_SOURCE) == FALSE) {
-		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (nfg->add_to_project),
-									  FALSE);
-		gtk_widget_set_sensitive (nfg->add_to_project, FALSE);
-	}
-	else
-	{
-		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (nfg->add_to_project),
-									  TRUE);
-		gtk_widget_set_sensitive (nfg->add_to_project, TRUE);
-	}
+	g_signal_connect (nfg->add_to_project_parent, "changed",
+	                  G_CALLBACK(on_project_parent_changed),
+	                  nfg);
+
+	has_project = (caps & ANJUTA_PROJECT_CAN_ADD_SOURCE) ? TRUE : FALSE;
+	gtk_widget_set_visible (nfg->add_to_project, has_project);
+	gtk_widget_set_visible (nfg->add_to_project_parent, has_project);
+	gtk_widget_set_visible (nfg->add_to_project_label, has_project);
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (nfg->add_to_project),
+									  has_project);
+	gtk_widget_set_sensitive (nfg->add_to_project, has_project);
 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (nfg->add_to_repository),
 								  FALSE);
-	
+
 	if (nfg && !(nfg->showing))
 	{
 		gtk_window_present (GTK_WINDOW (nfg->dialog));
@@ -189,15 +223,18 @@ create_new_file_dialog(IAnjutaDocumentManager *docman)
 		return FALSE;
 	}
 	nfg->dialog = GTK_WIDGET (gtk_builder_get_object (nfg->bxml, NEW_FILE_DIALOG));
+	nfg->ok_button = GTK_WIDGET (gtk_builder_get_object (nfg->bxml, NEW_FILE_OK_BUTTON));
 	nfg->add_to_project = GTK_WIDGET (gtk_builder_get_object (nfg->bxml, NEW_FILE_ADD_TO_PROJECT));
+	nfg->add_to_project_parent = GTK_WIDGET (gtk_builder_get_object (nfg->bxml, NEW_FILE_ADD_TO_PROJECT_PARENT));
+	nfg->add_to_project_label = GTK_WIDGET (gtk_builder_get_object (nfg->bxml, NEW_FILE_ADD_TO_PROJECT_LABEL));
 	nfg->add_to_repository = GTK_WIDGET (gtk_builder_get_object (nfg->bxml, NEW_FILE_ADD_TO_REPOSITORY));
 	nfg->showing = FALSE;
-	
+
 	store = GTK_LIST_STORE (gtk_builder_get_object (nfg->bxml, NEW_FILE_TYPE_STORE));
 	for (i=0; i < (sizeof(new_file_type) / sizeof(NewfileType)); i++)
 	{
 		GtkTreeIter iter;
-		
+
 		gtk_list_store_append (store, &iter);
 		gtk_list_store_set (store, &iter, 0, new_file_type[i].name, -1);
 	}
@@ -208,17 +245,17 @@ create_new_file_dialog(IAnjutaDocumentManager *docman)
 	for (i=0; i < (sizeof(new_license_type) / sizeof(NewlicenseType)); i++)
 	{
 		GtkTreeIter iter;
-		
+
 		gtk_list_store_append (store, &iter);
 		gtk_list_store_set (store, &iter, 0, new_license_type[i].name, -1);
 	}
 	optionmenu = GTK_COMBO_BOX (gtk_builder_get_object (nfg->bxml, NEW_FILE_MENU_LICENSE));
 	gtk_combo_box_set_active (optionmenu, 0);
-	
+
 	g_object_set_data (G_OBJECT (nfg->dialog), "IAnjutaDocumentManager", docman);
 	gtk_builder_connect_signals (nfg->bxml, NULL);
 	g_signal_emit_by_name(G_OBJECT (optionmenu), "changed");
-	
+
 	return TRUE;
 }
 
@@ -253,11 +290,11 @@ on_new_file_okbutton_clicked(GtkWidget *window, GdkEvent *event,
 	IAnjutaEditor *te = NULL;
 	IAnjutaEditor *teh = NULL;
 	gboolean ok = TRUE;
-	
+
 	toplevel= gtk_widget_get_toplevel (window);
 	docman = IANJUTA_DOCUMENT_MANAGER (g_object_get_data (G_OBJECT(toplevel),
 										"IAnjutaDocumentManager"));
-	snippets_manager = anjuta_shell_get_interface (ANJUTA_PLUGIN(docman)->shell, 
+	snippets_manager = anjuta_shell_get_interface (ANJUTA_PLUGIN(docman)->shell,
 		                                           IAnjutaSnippetsManager, NULL);
 	entry = GTK_WIDGET (gtk_builder_get_object (nfg->bxml, NEW_FILE_ENTRY));
 	name = gtk_entry_get_text(GTK_ENTRY(entry));
@@ -267,14 +304,14 @@ on_new_file_okbutton_clicked(GtkWidget *window, GdkEvent *event,
 		te = ianjuta_document_manager_add_buffer (docman, name, NULL, NULL);
 	else
 		te = ianjuta_document_manager_add_buffer (docman, "", NULL, NULL);
-	
+
 	if (te == NULL)
 		return FALSE;
-	
+
 	/* Create header file */
 	optionmenu = GTK_WIDGET (gtk_builder_get_object (nfg->bxml, NEW_FILE_TYPE));
 	source_type = gtk_combo_box_get_active(GTK_COMBO_BOX(optionmenu));
-	
+
 	checkbutton = GTK_WIDGET (gtk_builder_get_object (nfg->bxml, NEW_FILE_HEADER));
 	if (gtk_widget_get_sensitive (checkbutton) &&
 			gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbutton)))
@@ -283,7 +320,7 @@ on_new_file_okbutton_clicked(GtkWidget *window, GdkEvent *event,
 		{
 			const gchar *old_ext = strrchr (name,'.');
 			const gchar *new_ext =  new_file_type[new_file_type[source_type].header].ext;
-			
+
 			if (old_ext == NULL)
 			{
 				header_name = g_strconcat (name, new_ext, NULL);
@@ -299,7 +336,7 @@ on_new_file_okbutton_clicked(GtkWidget *window, GdkEvent *event,
 		{
 			teh = ianjuta_document_manager_add_buffer (docman, "", NULL, NULL);
 		}
-		ianjuta_document_manager_set_current_document (docman, IANJUTA_DOCUMENT(te), NULL);		
+		ianjuta_document_manager_set_current_document (docman, IANJUTA_DOCUMENT(te), NULL);
 	}
 
 	checkbutton = GTK_WIDGET (gtk_builder_get_object (nfg->bxml, NEW_FILE_TEMPLATE));
@@ -309,12 +346,12 @@ on_new_file_okbutton_clicked(GtkWidget *window, GdkEvent *event,
 		insert_header(snippets_manager, source_type);
 		if (teh != NULL)
 		{
-			ianjuta_document_manager_set_current_document (docman, IANJUTA_DOCUMENT(teh), NULL);		
+			ianjuta_document_manager_set_current_document (docman, IANJUTA_DOCUMENT(teh), NULL);
 			insert_header (snippets_manager, new_file_type[source_type].header);
-			ianjuta_document_manager_set_current_document (docman, IANJUTA_DOCUMENT(te), NULL);		
+			ianjuta_document_manager_set_current_document (docman, IANJUTA_DOCUMENT(te), NULL);
 		}
 	}
-	
+
 	checkbutton = GTK_WIDGET (gtk_builder_get_object (nfg->bxml, NEW_FILE_LICENSE));
 	if (gtk_widget_get_sensitive (checkbutton) &&
 			gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbutton)))
@@ -323,79 +360,75 @@ on_new_file_okbutton_clicked(GtkWidget *window, GdkEvent *event,
 		sel = gtk_combo_box_get_active(GTK_COMBO_BOX(optionmenu));
 		license_type = new_license_type[sel].type;
 		comment_type = new_file_type[source_type].comment;
-		                                  
-		insert_notice(snippets_manager, license_type, comment_type);		
+
+		insert_notice(snippets_manager, license_type, comment_type);
 		if (teh != NULL)
 		{
 			comment_type = new_file_type[new_file_type[source_type].header].comment;
-			ianjuta_document_manager_set_current_document (docman, IANJUTA_DOCUMENT(teh), NULL);		
-			insert_notice(snippets_manager, license_type, comment_type);		
-			ianjuta_document_manager_set_current_document (docman, IANJUTA_DOCUMENT(te), NULL);		
+			ianjuta_document_manager_set_current_document (docman, IANJUTA_DOCUMENT(teh), NULL);
+			insert_notice(snippets_manager, license_type, comment_type);
+			ianjuta_document_manager_set_current_document (docman, IANJUTA_DOCUMENT(te), NULL);
 		}
 	}
-	
+
 	/* Add file to project */
 	if (nfg->plugin->top_dir &&
 		gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (nfg->add_to_project)))
 	{
 		IAnjutaProjectManager *pm;
-		GList *names = NULL;
-		GList *file_list;
-		
-		pm = anjuta_shell_get_interface (ANJUTA_PLUGIN(docman)->shell, 
+		GFile *parent;
+		GFile *source;
+		GFile *header = NULL;
+
+		pm = anjuta_shell_get_interface (ANJUTA_PLUGIN(docman)->shell,
 										 IAnjutaProjectManager, NULL);
 		g_return_val_if_fail (pm != NULL, FALSE);
 
-		if (teh) names = g_list_prepend (names, header_name);
-		names = g_list_prepend (names, (gpointer) name);
-		file_list = ianjuta_project_manager_add_sources (pm, names, NULL, NULL);
-		g_list_free (names);
-		
-		if (file_list)
-		{
-			GList* node;
+		parent = ianjuta_project_chooser_get_selected (IANJUTA_PROJECT_CHOOSER (nfg->add_to_project_parent), NULL);
 
-			/* Save main file */
-			ianjuta_file_savable_save_as (IANJUTA_FILE_SAVABLE (te), (GFile *)file_list->data, NULL);		
-			
-			if (file_list->next)
-			{
-				/* Save header file */
-				ianjuta_file_savable_save_as (IANJUTA_FILE_SAVABLE (teh), (GFile *)file_list->next->data, NULL);		
-			}		
+		/* Save main file */
+		source = ianjuta_project_manager_add_source_quiet (pm, name, parent, NULL);
+		ok = source != NULL;
+		if (ok)	ianjuta_file_savable_save_as (IANJUTA_FILE_SAVABLE (te), source, NULL);
 
+		if (ok && teh)
+		{
+			/* Save header file */
+			header = ianjuta_project_manager_add_source_quiet (pm, header_name, parent, NULL);
+			ok = header != NULL;
+			if (ok) ianjuta_file_savable_save_as (IANJUTA_FILE_SAVABLE (teh), header, NULL);
+		}
 
-			/* Add to repository */
-			if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (nfg->add_to_repository)))
-			{
-				IAnjutaVcs* ivcs = anjuta_shell_get_interface (ANJUTA_PLUGIN(docman)->shell, 
-										 IAnjutaVcs, NULL);
-				if (ivcs)
-				{					
-					AnjutaAsyncNotify* notify = anjuta_async_notify_new();
-					ianjuta_vcs_add (ivcs, file_list, notify, NULL);
-				}
-			}
 
-			/* Re emit element_added for symbol-db */
-			for (node = file_list; node != NULL; node = g_list_next (node))
+		/* Add to repository */
+		if (ok && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (nfg->add_to_repository)))
+		{
+			IAnjutaVcs* ivcs = anjuta_shell_get_interface (ANJUTA_PLUGIN(docman)->shell,
+										 IAnjutaVcs, NULL);
+			if (ivcs)
 			{
-				g_signal_emit_by_name (G_OBJECT (pm), "element_added", node->data);
-			}
+				AnjutaAsyncNotify* notify = anjuta_async_notify_new();
+				GList *file_list = NULL;
 
-			g_list_foreach (file_list, (GFunc)g_object_unref, NULL);
-			g_list_free (file_list);
-		}
-		else
-		{
-			ok = FALSE;
+				file_list = g_list_prepend (file_list, source);
+				if (header != NULL) file_list = g_list_prepend (file_list, header);
+				ianjuta_vcs_add (ivcs, file_list, notify, NULL);
+				g_list_free (file_list);
+			}
 		}
+
+		/* Re emit element_added for symbol-db */
+		if (source) g_signal_emit_by_name (G_OBJECT (pm), "element_added", source);
+		if (header) g_signal_emit_by_name (G_OBJECT (pm), "element_added", header);
+
+		if (source) g_object_unref (source);
+		if (header) g_object_unref (header);
 	}
 	g_free (header_name);
-	
+
 	gtk_widget_hide (nfg->dialog);
 	nfg->showing = FALSE;
-	
+
 	return ok;
 }
 
@@ -407,10 +440,10 @@ on_new_file_entry_changed (GtkEditable *entry, gpointer user_data)
 	static gint last_length = 0;
 	gint length;
 	GtkWidget *optionmenu;
-	
+
 	name = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
 	length = strlen(name);
-	
+
 	if (last_length != 2 && length == 1)
 	{
 		optionmenu = GTK_WIDGET (gtk_builder_get_object (nfg->bxml, NEW_FILE_TYPE));
@@ -419,7 +452,7 @@ on_new_file_entry_changed (GtkEditable *entry, gpointer user_data)
 		gtk_entry_set_text (GTK_ENTRY(entry), name);
 	}
 	last_length = length;
-	
+
 	g_free(name);
 }
 
@@ -430,9 +463,9 @@ on_new_file_type_changed (GtkComboBox   *optionmenu, gpointer user_data)
 	char *name, *tmp;
 	GtkWidget *widget;
 	GtkWidget *entry;
-	
+
 	sel = gtk_combo_box_get_active(optionmenu);
-	
+
 	widget = GTK_WIDGET (gtk_builder_get_object (nfg->bxml, NEW_FILE_HEADER));
 	gtk_widget_set_sensitive(widget, new_file_type[sel].header >= 0);
 	widget = GTK_WIDGET (gtk_builder_get_object (nfg->bxml, NEW_FILE_LICENSE));
@@ -440,7 +473,7 @@ on_new_file_type_changed (GtkComboBox   *optionmenu, gpointer user_data)
 	widget = GTK_WIDGET (gtk_builder_get_object (nfg->bxml, NEW_FILE_TEMPLATE));
 	gtk_widget_set_sensitive(widget, new_file_type[sel].template);
 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), FALSE);
-	
+
 	entry = GTK_WIDGET (gtk_builder_get_object (nfg->bxml, NEW_FILE_ENTRY));
 	name = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
 	if (strlen(name) > 0)
@@ -458,7 +491,7 @@ void
 on_new_file_license_toggled(GtkToggleButton *button, gpointer user_data)
 {
 	GtkWidget *widget;
-	
+
 	widget = GTK_WIDGET (gtk_builder_get_object (nfg->bxml, NEW_FILE_MENU_LICENSE));
 	gtk_widget_set_sensitive(widget, gtk_toggle_button_get_active(button));
 }



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