[nautilus] Add a clue bar to special locations like Templates and scripts



commit 029219ec993a2e6bc8983939d9e8325d8112d933
Author: William Jon McCann <jmccann redhat com>
Date:   Mon Aug 13 22:11:03 2012 -0400

    Add a clue bar to special locations like Templates and scripts
    
    https://bugzilla.gnome.org/show_bug.cgi?id=84463

 src/.gitignore                      |    2 +
 src/Makefile.am                     |   47 ++++++++++
 src/nautilus-special-location-bar.c |  169 +++++++++++++++++++++++++++++++++++
 src/nautilus-special-location-bar.h |   61 +++++++++++++
 src/nautilus-view.c                 |    3 +-
 src/nautilus-window-manage-views.c  |   24 +++++
 6 files changed, 304 insertions(+), 2 deletions(-)
---
diff --git a/src/.gitignore b/src/.gitignore
index 77b0cb8..edbd22e 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -1,7 +1,9 @@
 nautilus
 nautilus-autorun-software
 nautilus-connect-server
+nautilus-enum-types.[ch]
 nautilus-file-management-properties
 nautilus-convert-metadata
 nautilus-freedesktop-generated.[ch]
 nautilus-resources.[ch]
+stamp-nautilus-enum-types.h
\ No newline at end of file
diff --git a/src/Makefile.am b/src/Makefile.am
index 2141776..8c129c0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -64,17 +64,61 @@ UI_FILES = \
 	nautilus-shell-ui.xml			\
 	$(NULL)
 
+headers =					\
+	nautilus-special-location-bar.h		\
+	$(NULL)
+
 nautilus-resources.c: nautilus.gresource.xml $(UI_FILES)
 	glib-compile-resources --target=$@ --sourcedir=$(srcdir) --generate-source --c-name nautilus $(srcdir)/nautilus.gresource.xml
 
 nautilus-resources.h: nautilus.gresource.xml
 	glib-compile-resources --target=$@ --sourcedir=$(srcdir) --generate-header --c-name nautilus $(srcdir)/nautilus.gresource.xml
 
+nautilus-enum-types.h: stamp-nautilus-enum-types.h
+	$(AM_V_GEN)true
+
+stamp-nautilus-enum-types.h: $(headers) Makefile
+	$(AM_V_GEN)(cd $(srcdir) \
+	&& glib-mkenums \
+			--fhead "#ifndef __NAUTILUS_ENUM_TYPES_H__\n" \
+			--fhead "#define __NAUTILUS_ENUM_TYPES_H__ 1\n\n" \
+			--fhead "#include <glib-object.h>\n\n" \
+			--fhead "G_BEGIN_DECLS\n\n" \
+			--ftail "G_END_DECLS\n\n" \
+			--ftail "#endif /* __NAUTILUS_ENUM_TYPES_H__ */\n" \
+			--fprod "#include \"@filename \"\n" \
+			--eprod "#define @ENUMPREFIX _TYPE_@ENUMSHORT@ @enum_name _get_type()\n" \
+			--eprod "GType @enum_name _get_type (void);\n" \
+		$(headers) ) > xgen-gth \
+	&& (cmp -s xgen-gth nautilus-enum-type.h || cp xgen-gth nautilus-enum-types.h) \
+	&& rm -f xgen-gth \
+	&& echo timestamp > $(@F)
+
+nautilus-enum-types.c: $(headers) Makefile
+	$(AM_V_GEN)(cd $(srcdir) \
+	&& glib-mkenums \
+			--fhead "#include <config.h>\n" \
+			--fhead "#include <glib-object.h>\n" \
+			--fhead "#include \"nautilus-enum-types.h\"\n\n" \
+			--fprod "\n/* enumerations from \"@filename \" */" \
+			--vhead "static const G Type@Value _ enum_name@_values[] = {" \
+			--vprod "  { @VALUENAME@, \"@VALUENAME \", \"@valuenick \" }," \
+			--vtail "  { 0, NULL, NULL }\n};\n\n" \
+			--vtail "GType\n enum_name@_get_type (void)\n{\n" \
+			--vtail "  static GType type = 0;\n\n" \
+			--vtail "  if (!type)\n" \
+			--vtail "    type = g_ type@_register_static (\"@EnumName \", _ enum_name@_values);\n\n" \
+			--vtail "  return type;\n}\n\n" \
+		$(headers) ) > xgen-gtc \
+	&& cp xgen-gtc $(@F) \
+	&& rm -f xgen-gtc
 
 BUILT_SOURCES = \
 	$(dbus_built_sources) \
 	nautilus-resources.c \
 	nautilus-resources.h \
+	nautilus-enum-types.h \
+	nautilus-enum-types.c \
 	$(NULL)
 
 nautilus_SOURCES = \
@@ -144,6 +188,8 @@ nautilus_SOURCES = \
 	nautilus-query-editor.h			\
 	nautilus-self-check-functions.c 	\
 	nautilus-self-check-functions.h 	\
+	nautilus-special-location-bar.c		\
+	nautilus-special-location-bar.h		\
 	nautilus-toolbar.c			\
 	nautilus-toolbar.h			\
 	nautilus-trash-bar.c			\
@@ -206,6 +252,7 @@ TESTS=check-nautilus
 CLEANFILES = \
 	$(BUILT_SOURCES)			\
 	$(server_DATA)				\
+	stamp-nautilus-enum-types.h		\
 	$(NULL)
 
 EXTRA_DIST =					\
diff --git a/src/nautilus-special-location-bar.c b/src/nautilus-special-location-bar.c
new file mode 100644
index 0000000..bd5a3b1
--- /dev/null
+++ b/src/nautilus-special-location-bar.c
@@ -0,0 +1,169 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2012 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+#include <string.h>
+
+#include "nautilus-special-location-bar.h"
+#include "nautilus-enum-types.h"
+
+#define NAUTILUS_SPECIAL_LOCATION_BAR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NAUTILUS_TYPE_SPECIAL_LOCATION_BAR, NautilusSpecialLocationBarPrivate))
+
+struct NautilusSpecialLocationBarPrivate
+{
+	GtkWidget *label;
+	NautilusSpecialLocation special_location;
+};
+
+enum {
+	PROP_0,
+	PROP_SPECIAL_LOCATION,
+};
+
+G_DEFINE_TYPE (NautilusSpecialLocationBar, nautilus_special_location_bar, GTK_TYPE_INFO_BAR)
+
+static char *
+get_message_for_special_location (NautilusSpecialLocation location)
+{
+	char *message;
+
+	switch (location) {
+	case NAUTILUS_SPECIAL_LOCATION_TEMPLATES:
+		message = g_strdup (_("Files in this folder will appear in the Create Document menu."));
+		break;
+	case NAUTILUS_SPECIAL_LOCATION_SCRIPTS:
+		message = g_strdup (_("Executable files in this folder will appear in the Scripts menu."));
+		break;
+	default:
+		g_assert_not_reached ();
+	}
+
+	return message;
+}
+
+static void
+set_special_location (NautilusSpecialLocationBar *bar,
+		      NautilusSpecialLocation     location)
+{
+	char *message;
+
+	message = get_message_for_special_location (location);
+
+	gtk_label_set_text (GTK_LABEL (bar->priv->label), message);
+	g_free (message);
+
+	gtk_widget_show (bar->priv->label);
+}
+
+static void
+nautilus_special_location_bar_set_property (GObject      *object,
+					    guint         prop_id,
+					    const GValue *value,
+					    GParamSpec   *pspec)
+{
+	NautilusSpecialLocationBar *bar;
+
+	bar = NAUTILUS_SPECIAL_LOCATION_BAR (object);
+
+	switch (prop_id) {
+	case PROP_SPECIAL_LOCATION:
+		set_special_location (bar, g_value_get_enum (value));
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+		break;
+	}
+}
+
+static void
+nautilus_special_location_bar_get_property (GObject    *object,
+					    guint       prop_id,
+					    GValue     *value,
+					    GParamSpec *pspec)
+{
+	NautilusSpecialLocationBar *bar;
+
+	bar = NAUTILUS_SPECIAL_LOCATION_BAR (object);
+
+	switch (prop_id) {
+	case PROP_SPECIAL_LOCATION:
+		g_value_set_enum (value, bar->priv->special_location);
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+		break;
+	}
+}
+
+static void
+nautilus_special_location_bar_class_init (NautilusSpecialLocationBarClass *klass)
+{
+	GObjectClass *object_class;
+
+	object_class = G_OBJECT_CLASS (klass);
+	object_class->get_property = nautilus_special_location_bar_get_property;
+	object_class->set_property = nautilus_special_location_bar_set_property;
+
+	g_type_class_add_private (klass, sizeof (NautilusSpecialLocationBarPrivate));
+
+	g_object_class_install_property (object_class,
+					 PROP_SPECIAL_LOCATION,
+					 g_param_spec_enum ("special-location",
+							    "special-location",
+							    "special-location",
+							    NAUTILUS_TYPE_SPECIAL_LOCATION,
+							    NAUTILUS_SPECIAL_LOCATION_TEMPLATES,
+							    G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+}
+
+static void
+nautilus_special_location_bar_init (NautilusSpecialLocationBar *bar)
+{
+	GtkWidget *location_area;
+	GtkWidget *action_area;
+	PangoAttrList *attrs;
+
+	bar->priv = NAUTILUS_SPECIAL_LOCATION_BAR_GET_PRIVATE (bar);
+	location_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (bar));
+	action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (bar));
+
+	gtk_orientable_set_orientation (GTK_ORIENTABLE (action_area), GTK_ORIENTATION_HORIZONTAL);
+
+	attrs = pango_attr_list_new ();
+	pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
+	bar->priv->label = gtk_label_new (NULL);
+	gtk_label_set_attributes (GTK_LABEL (bar->priv->label), attrs);
+	pango_attr_list_unref (attrs);
+
+	gtk_label_set_ellipsize (GTK_LABEL (bar->priv->label), PANGO_ELLIPSIZE_END);
+	gtk_container_add (GTK_CONTAINER (location_area), bar->priv->label);
+}
+
+GtkWidget *
+nautilus_special_location_bar_new (NautilusSpecialLocation location)
+{
+	return g_object_new (NAUTILUS_TYPE_SPECIAL_LOCATION_BAR,
+			     "message-type", GTK_MESSAGE_QUESTION,
+			     "special-location", location,
+			     NULL);
+}
diff --git a/src/nautilus-special-location-bar.h b/src/nautilus-special-location-bar.h
new file mode 100644
index 0000000..0e34e58
--- /dev/null
+++ b/src/nautilus-special-location-bar.h
@@ -0,0 +1,61 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2012 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef __NAUTILUS_SPECIAL_LOCATION_BAR_H
+#define __NAUTILUS_SPECIAL_LOCATION_BAR_H
+
+#include <gtk/gtk.h>
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+#define NAUTILUS_TYPE_SPECIAL_LOCATION_BAR         (nautilus_special_location_bar_get_type ())
+#define NAUTILUS_SPECIAL_LOCATION_BAR(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), NAUTILUS_TYPE_SPECIAL_LOCATION_BAR, NautilusSpecialLocationBar))
+#define NAUTILUS_SPECIAL_LOCATION_BAR_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), NAUTILUS_TYPE_SPECIAL_LOCATION_BAR, NautilusSpecialLocationBarClass))
+#define NAUTILUS_IS_SPECIAL_LOCATION_BAR(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), NAUTILUS_TYPE_SPECIAL_LOCATION_BAR))
+#define NAUTILUS_IS_SPECIAL_LOCATION_BAR_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), NAUTILUS_TYPE_SPECIAL_LOCATION_BAR))
+#define NAUTILUS_SPECIAL_LOCATION_BAR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), NAUTILUS_TYPE_SPECIAL_LOCATION_BAR, NautilusSpecialLocationBarClass))
+
+typedef struct NautilusSpecialLocationBarPrivate NautilusSpecialLocationBarPrivate;
+
+typedef struct
+{
+	GtkInfoBar parent;
+
+	NautilusSpecialLocationBarPrivate *priv;
+} NautilusSpecialLocationBar;
+
+typedef enum {
+	NAUTILUS_SPECIAL_LOCATION_TEMPLATES,
+	NAUTILUS_SPECIAL_LOCATION_SCRIPTS,
+} NautilusSpecialLocation;
+
+typedef struct
+{
+	GtkInfoBarClass parent_class;
+} NautilusSpecialLocationBarClass;
+
+GType		 nautilus_special_location_bar_get_type	(void) G_GNUC_CONST;
+
+GtkWidget	*nautilus_special_location_bar_new (NautilusSpecialLocation location);
+
+G_END_DECLS
+
+#endif /* __NAUTILUS_SPECIAL_LOCATION_BAR_H */
diff --git a/src/nautilus-view.c b/src/nautilus-view.c
index 84092c8..4389245 100644
--- a/src/nautilus-view.c
+++ b/src/nautilus-view.c
@@ -7634,8 +7634,7 @@ real_merge_menus (NautilusView *view)
 				      directory_view_entries, G_N_ELEMENTS (directory_view_entries),
 				      view);
 
-	/* Translators: %s is a directory */
-	tooltip = g_strdup_printf (_("Run or manage scripts from %s"), "~/.gnome2/nautilus-scripts");
+	tooltip = g_strdup (_("Run or manage scripts"));
 	/* Create a script action here specially because its tooltip is dynamic */
 	action = gtk_action_new ("Scripts", _("_Scripts"), tooltip, NULL);
 	gtk_action_group_add_action (action_group, action);
diff --git a/src/nautilus-window-manage-views.c b/src/nautilus-window-manage-views.c
index 43c2aff..249a600 100644
--- a/src/nautilus-window-manage-views.c
+++ b/src/nautilus-window-manage-views.c
@@ -35,6 +35,7 @@
 #include "nautilus-pathbar.h"
 #include "nautilus-window-private.h"
 #include "nautilus-window-slot.h"
+#include "nautilus-special-location-bar.h"
 #include "nautilus-trash-bar.h"
 #include "nautilus-toolbar.h"
 #include "nautilus-view-factory.h"
@@ -1304,6 +1305,18 @@ nautilus_window_slot_show_x_content_bar (NautilusWindowSlot *slot, GMount *mount
 }
 
 static void
+nautilus_window_slot_show_special_location_bar (NautilusWindowSlot     *slot,
+						NautilusSpecialLocation special_location)
+{
+	GtkWidget *bar;
+
+	bar = nautilus_special_location_bar_new (special_location);
+	gtk_widget_show (bar);
+
+	nautilus_window_slot_add_extra_location_widget (slot, bar);
+}
+
+static void
 nautilus_window_slot_show_trash_bar (NautilusWindowSlot *slot)
 {
 	GtkWidget *bar;
@@ -1439,6 +1452,17 @@ update_for_new_location (NautilusWindowSlot *slot)
 
 		if (nautilus_directory_is_in_trash (directory)) {
 			nautilus_window_slot_show_trash_bar (slot);
+		} else {
+			GFile *scripts_file;
+			char *scripts_path = nautilus_get_scripts_directory_path ();
+			scripts_file = g_file_new_for_path (scripts_path);
+			g_free (scripts_path);
+			if (nautilus_file_is_user_special_directory (file, G_USER_DIRECTORY_TEMPLATES)) {
+				nautilus_window_slot_show_special_location_bar (slot, NAUTILUS_SPECIAL_LOCATION_TEMPLATES);
+			} else if (g_file_equal (slot->location, scripts_file)) {
+				nautilus_window_slot_show_special_location_bar (slot, NAUTILUS_SPECIAL_LOCATION_SCRIPTS);
+			}
+			g_object_unref (scripts_file);
 		}
 
 		/* need the mount to determine if we should put up the x-content cluebar */



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