[anjuta] starter: New starter UI



commit 5cc66db73fb51a14b4c2194c0ec5605eb964f48d
Author: Johannes Schmid <jhs gnome org>
Date:   Mon Feb 21 22:53:11 2011 +0100

    starter: New starter UI
    
    The UI is build with glade now and repects theming. It is shown in fullscreen ifno file/project is open and disappears otherwise. It only contains the useful actions when no project is open.

 plugins/starter/Makefile.am |   11 +-
 plugins/starter/plugin.c    |  218 ++++++++++++++++-
 plugins/starter/starter.c   |  555 -------------------------------------------
 plugins/starter/starter.h   |   51 ----
 plugins/starter/starter.ui  |  280 ++++++++++++++++++++++
 5 files changed, 499 insertions(+), 616 deletions(-)
---
diff --git a/plugins/starter/Makefile.am b/plugins/starter/Makefile.am
index 6e83cd0..37eede3 100644
--- a/plugins/starter/Makefile.am
+++ b/plugins/starter/Makefile.am
@@ -11,6 +11,9 @@ starter_pixmaps_DATA = starter_logo.png
 plugindir = $(anjuta_plugin_dir)
 plugin_LTLIBRARIES = libanjuta-starter.la
 
+uidir = $(anjuta_glade_dir)
+ui_DATA = starter.ui
+
 AM_CPPFLAGS = \
 	$(WARN_CFLAGS) \
 	$(DEPRECATED_FLAGS) \
@@ -26,13 +29,13 @@ libanjuta_starter_la_LIBADD = \
 
 libanjuta_starter_la_SOURCES= \
 	plugin.c \
-	plugin.h \
-	starter.h \
-	starter.c
+	plugin.h
 
 EXTRA_DIST = \
 	$(plugin_in_files) \
 	$(starter_plugin_DATA) \
-	$(starter_pixmaps_DATA) 
+	$(starter_pixmaps_DATA) \
+	$(ui_DATA)
 
 -include $(top_srcdir)/git.mk
+
diff --git a/plugins/starter/plugin.c b/plugins/starter/plugin.c
index 100048b..fca8936 100644
--- a/plugins/starter/plugin.c
+++ b/plugins/starter/plugin.c
@@ -23,13 +23,190 @@
 #include <libanjuta/anjuta-debug.h>
 #include <libanjuta/anjuta-encodings.h>
 #include <libanjuta/interfaces/ianjuta-document-manager.h>
+#include <libanjuta/interfaces/ianjuta-project-manager.h>
+#include <libanjuta/interfaces/ianjuta-file-loader.h>
+#include <libanjuta/interfaces/ianjuta-wizard.h>
 
-#include "plugin.h"
-#include "starter.h"
+#include <gtk/gtk.h>
 
+#include "plugin.h"
 
 static gpointer parent_class;
 
+#define UI_FILE PACKAGE_DATA_DIR"/glade/starter.ui"
+#define STARTER_VBOX "starter_vbox"
+#define RECENT_VBOX "recent_vbox"
+#define IMPORT_IMAGE "import_image"
+#define NEW_IMAGE "new_image"
+
+#define NEW_PROJECT_PIXMAP "anjuta-project-wizard-plugin-48.png"
+#define IMPORT_PROJECT_PIXMAP "anjuta-project-import-plugin-48.png"
+
+#define PROJECT_WIZARD_ID "anjuta-project-wizard:NPWPlugin"
+#define PROJECT_IMPORT_ID "anjuta-project-import:AnjutaProjectImportPlugin"
+
+void
+on_new_project_clicked (GtkButton *button, gpointer user_data);
+void
+on_import_project_clicked (GtkButton *button, gpointer user_data);
+
+static void
+on_recent_project_clicked (GtkButton *button, StarterPlugin *plugin)
+{
+	GFile *file;
+	IAnjutaFileLoader *loader = 
+		anjuta_shell_get_interface (anjuta_plugin_get_shell (ANJUTA_PLUGIN (plugin)),
+		                            IAnjutaFileLoader,
+		                            NULL);
+	
+	file = g_object_get_data (G_OBJECT (button), "file");
+
+	ianjuta_file_loader_load (IANJUTA_FILE_LOADER (loader),
+							  file, FALSE, NULL);
+}
+
+void
+on_new_project_clicked (GtkButton *button, gpointer user_data)
+{
+	AnjutaPlugin* plugin = ANJUTA_PLUGIN (user_data);
+	AnjutaPluginManager* plugin_manager = 
+		anjuta_shell_get_plugin_manager (anjuta_plugin_get_shell (plugin),
+		                                 NULL);
+	
+	GObject* wizard = 
+		anjuta_plugin_manager_get_plugin_by_id (plugin_manager, PROJECT_WIZARD_ID);
+
+	if (wizard)
+		ianjuta_wizard_activate (IANJUTA_WIZARD (wizard), NULL);
+}
+
+void
+on_import_project_clicked (GtkButton *button, gpointer user_data)
+{
+	AnjutaPlugin* plugin = ANJUTA_PLUGIN (user_data);
+	AnjutaPluginManager* plugin_manager = 
+		anjuta_shell_get_plugin_manager (anjuta_plugin_get_shell (plugin),
+		                                 NULL);
+	GObject* wizard = 
+		anjuta_plugin_manager_get_plugin_by_id (plugin_manager, PROJECT_IMPORT_ID);
+
+	if (wizard)
+		ianjuta_wizard_activate (IANJUTA_WIZARD (wizard), NULL);
+}
+
+static void
+build_recent_projects (GtkWidget *box, StarterPlugin* plugin)
+{
+	GtkRecentManager *manager;
+	GList *list;
+	gint limit = 1000;
+	gint i = 0;
+	
+	manager = gtk_recent_manager_get_default ();
+
+	list = gtk_recent_manager_get_items (manager);
+
+	while (i < limit && list != NULL)
+	{
+		if (strcmp (gtk_recent_info_get_mime_type (list->data), "application/x-anjuta") == 0)
+		{
+			GtkWidget *button;
+			GtkWidget *label;
+			GtkWidget *button_box;
+			GFile *file;
+			GFileInfo* info;
+			gchar *uri;
+			GIcon* icon;
+
+			button_box = gtk_hbox_new (FALSE, 5);
+			button = gtk_button_new ();
+			gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
+			gtk_widget_set_halign (button, GTK_ALIGN_START);
+
+			label = gtk_label_new (gtk_recent_info_get_display_name (list->data));
+			gtk_box_pack_end (GTK_BOX (button_box), label, FALSE, FALSE, 0);
+			
+			file = g_file_new_for_uri (gtk_recent_info_get_uri (list->data));
+			info = g_file_query_info (file,
+			                          G_FILE_ATTRIBUTE_STANDARD_ICON,
+			                          G_FILE_QUERY_INFO_NONE,
+			                          NULL, NULL);
+			icon = g_file_info_get_icon (info);
+			if (icon)
+			{
+				GtkWidget* image = gtk_image_new_from_gicon (icon,
+				                                             GTK_ICON_SIZE_BUTTON);
+				gtk_box_pack_start (GTK_BOX (button_box), image, FALSE, FALSE, 0);
+			}
+			g_object_unref (info);
+
+			gtk_container_add (GTK_CONTAINER (button), button_box);
+			gtk_widget_show_all (button);
+			
+			gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
+
+			g_object_set_data_full (G_OBJECT (button), "file", file,
+			                        (GDestroyNotify)g_object_unref);
+			uri = gtk_recent_info_get_uri_display (list->data);
+			if (uri)
+			{
+				gchar *tip;
+
+				tip = g_strdup_printf (_("Open '%s'"), uri);
+				gtk_widget_set_tooltip_text (button, tip);
+
+				g_free (tip);
+				g_free (uri);
+			}
+
+			g_signal_connect (button, "clicked",
+							  G_CALLBACK (on_recent_project_clicked),
+							  plugin);
+		}
+		i++;
+		list = g_list_next (list);
+	}
+
+	g_list_foreach (list, (GFunc)gtk_recent_info_unref, NULL);
+	g_list_free (list);
+}
+
+static GtkWidget*
+create_starter_widget (StarterPlugin* plugin)
+{
+	GError* error = NULL;
+	GtkWidget* starter_vbox;
+	GtkWidget* recent_vbox;
+	GtkBuilder* builder = gtk_builder_new ();
+	GtkWidget* image;
+	
+	if (!gtk_builder_add_from_file(builder, UI_FILE, &error))
+	{
+		DEBUG_PRINT ("Could load starter ui!", error->message);
+		g_error_free (error);
+		return NULL;
+	}
+	starter_vbox = GTK_WIDGET (gtk_builder_get_object (builder, STARTER_VBOX));
+	recent_vbox = GTK_WIDGET (gtk_builder_get_object (builder, RECENT_VBOX));
+
+	build_recent_projects (recent_vbox, plugin);
+
+	g_object_ref (starter_vbox);
+	gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (starter_vbox)),
+	                      starter_vbox);
+
+	image = GTK_WIDGET (gtk_builder_get_object (builder, NEW_IMAGE));
+	gtk_image_set_from_file (GTK_IMAGE (image),
+	                         PACKAGE_PIXMAPS_DIR"/"NEW_PROJECT_PIXMAP);
+	image = GTK_WIDGET (gtk_builder_get_object (builder, IMPORT_IMAGE));
+	gtk_image_set_from_file (GTK_IMAGE (image),
+	                         PACKAGE_PIXMAPS_DIR"/"IMPORT_PROJECT_PIXMAP);	
+	
+	gtk_builder_connect_signals (builder, plugin);
+
+	return starter_vbox;
+}
+
 /* Remove the starter plugin once a document was opened */
 static void
 on_value_added_current_editor (AnjutaPlugin *plugin, const gchar *name,
@@ -54,24 +231,47 @@ static void
 on_value_removed_current_editor (AnjutaPlugin *plugin, const gchar *name,
 								 gpointer data)
 {
-	AnjutaShell* shell = ANJUTA_PLUGIN(plugin)->shell;
+	AnjutaShell* shell = anjuta_plugin_get_shell (plugin);
 	StarterPlugin* splugin = ANJUTA_PLUGIN_STARTER (plugin);
 	IAnjutaDocumentManager* docman = anjuta_shell_get_interface (shell,
 	                                                             IAnjutaDocumentManager,
 	                                                             NULL);
+	IAnjutaProjectManager* pm = anjuta_shell_get_interface (shell,
+	                                                        IAnjutaProjectManager,
+	                                                        NULL);
 	
 	if (!ianjuta_document_manager_get_doc_widgets (docman,
-	                                               NULL))
+	                                               NULL) &&
+	    !ianjuta_project_manager_get_current_project (pm, 
+	                                                  NULL))
 	{
 		DEBUG_PRINT ("Showing starter");
-		splugin->starter = GTK_WIDGET (starter_new (shell));
+		splugin->starter = create_starter_widget (splugin);
 		anjuta_shell_add_widget (shell, splugin->starter,
 		                         "AnjutaStarter",
-		                         _("Starter"),
+		                         _("Start"),
 		                         GTK_STOCK_ABOUT,
 		                         ANJUTA_SHELL_PLACEMENT_CENTER,
 		                         NULL);
 		anjuta_shell_present_widget (shell, splugin->starter, NULL);
+		g_object_unref (splugin->starter);
+	}
+}
+
+static void
+on_session_load (AnjutaShell* shell,
+                 AnjutaSessionPhase phase,
+                 AnjutaSession* session,
+                 StarterPlugin* plugin)
+{
+	if (phase == ANJUTA_SESSION_PHASE_END)
+	{
+		if (plugin->starter)
+		{
+			anjuta_shell_maximize_widget (shell,
+			                              "AnjutaStarter",
+			                              NULL);
+		}
 	}
 }
 
@@ -89,6 +289,12 @@ activate_plugin (AnjutaPlugin *plugin)
 								 on_value_removed_current_editor,
 								 NULL);
 	on_value_removed_current_editor (plugin, NULL, splugin);
+
+	g_signal_connect (anjuta_plugin_get_shell (plugin),
+	                  "load-session",
+	                  G_CALLBACK (on_session_load),
+	                  plugin);
+	
 	return TRUE;
 }
 
diff --git a/plugins/starter/starter.ui b/plugins/starter/starter.ui
new file mode 100644
index 0000000..1990265
--- /dev/null
+++ b/plugins/starter/starter.ui
@@ -0,0 +1,280 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <object class="GtkWindow" id="unused">
+    <property name="can_focus">False</property>
+    <child>
+      <object class="GtkVBox" id="starter_vbox">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="spacing">10</property>
+        <child>
+          <object class="GtkFrame" id="frame3">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="hexpand">True</property>
+            <property name="label_xalign">0</property>
+            <child>
+              <object class="GtkAlignment" id="alignment3">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="left_padding">12</property>
+                <child>
+                  <object class="GtkHBox" id="hbox1">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="halign">start</property>
+                    <property name="valign">start</property>
+                    <property name="spacing">5</property>
+                    <child>
+                      <object class="GtkButton" id="new_button">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <property name="halign">start</property>
+                        <property name="use_action_appearance">False</property>
+                        <property name="relief">none</property>
+                        <signal name="clicked" handler="on_new_project_clicked" swapped="no"/>
+                        <child>
+                          <object class="GtkBox" id="box1">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <child>
+                              <object class="GtkImage" id="new_image">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="icon-size">6</property>
+                              </object>
+                              <packing>
+                                <property name="expand">True</property>
+                                <property name="fill">True</property>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkLabel" id="label1">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="label" translatable="yes">Create a new project</property>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">True</property>
+                                <property name="position">1</property>
+                              </packing>
+                            </child>
+                          </object>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkButton" id="import_button">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <property name="halign">start</property>
+                        <property name="use_action_appearance">False</property>
+                        <property name="relief">none</property>
+                        <signal name="clicked" handler="on_import_project_clicked" swapped="no"/>
+                        <child>
+                          <object class="GtkBox" id="box2">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <child>
+                              <object class="GtkImage" id="import_image">
+                                <property name="can_focus">False</property>
+                                <property name="icon-size">6</property>
+                              </object>
+                              <packing>
+                                <property name="expand">True</property>
+                                <property name="fill">True</property>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkLabel" id="label2">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="label" translatable="yes">Import an existing project</property>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">True</property>
+                                <property name="position">1</property>
+                              </packing>
+                            </child>
+                          </object>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+            <child type="label_item">
+              <placeholder/>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="padding">10</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkFrame" id="frame1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="hexpand">True</property>
+            <property name="label_xalign">0</property>
+            <child>
+              <object class="GtkAlignment" id="alignment1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="left_padding">12</property>
+                <child>
+                  <object class="GtkVBox" id="recent_vbox">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="halign">start</property>
+                    <property name="spacing">5</property>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+            <child type="label">
+              <object class="GtkLabel" id="label3">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">Recent projects:</property>
+                <property name="use_markup">True</property>
+                <attributes>
+                  <attribute name="weight" value="bold"/>
+                </attributes>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="padding">10</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkFrame" id="frame2">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="hexpand">True</property>
+            <property name="label_xalign">0</property>
+            <child>
+              <object class="GtkAlignment" id="alignment2">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="left_padding">12</property>
+                <child>
+                  <object class="GtkVBox" id="vbox4">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="spacing">5</property>
+                    <child>
+                      <object class="GtkLinkButton" id="tutorials_link">
+                        <property name="label" translatable="yes">Tutorials</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <property name="has_tooltip">True</property>
+                        <property name="halign">start</property>
+                        <property name="use_action_appearance">False</property>
+                        <property name="relief">none</property>
+                        <property name="uri">http://developer.gnome.org</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLinkButton" id="manual_link">
+                        <property name="label" translatable="yes">Anjuta Manual</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <property name="has_tooltip">True</property>
+                        <property name="halign">start</property>
+                        <property name="use_action_appearance">False</property>
+                        <property name="relief">none</property>
+                        <property name="uri">ghelp:anjuta-manual</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLinkButton" id="faq_link">
+                        <property name="label" translatable="yes">FAQ</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <property name="has_tooltip">True</property>
+                        <property name="halign">start</property>
+                        <property name="use_action_appearance">False</property>
+                        <property name="relief">none</property>
+                        <property name="uri">ghelp:anjuta-faq</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">2</property>
+                      </packing>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+            <child type="label">
+              <object class="GtkLabel" id="label4">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">Getting started:</property>
+                <property name="use_markup">True</property>
+                <attributes>
+                  <attribute name="weight" value="bold"/>
+                </attributes>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="padding">10</property>
+            <property name="position">2</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>



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