[nautilus] toolbar: add NautilusToolbar
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] toolbar: add NautilusToolbar
- Date: Thu, 17 Feb 2011 16:25:51 +0000 (UTC)
commit bd36e2d04baeeeeafc2fcf2f00383fbc367de735
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Wed Feb 9 18:17:25 2011 -0500
toolbar: add NautilusToolbar
src/Makefile.am | 2 +
src/nautilus-toolbar.c | 281 ++++++++++++++++++++++++++++++++++++++++++++++++
src/nautilus-toolbar.h | 80 ++++++++++++++
3 files changed, 363 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 03d7ffc..13efcf6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -121,6 +121,8 @@ nautilus_SOURCES = \
nautilus-self-check-functions.h \
nautilus-spatial-window.c \
nautilus-spatial-window.h \
+ nautilus-toolbar.c \
+ nautilus-toolbar.h \
nautilus-tree-sidebar.c \
nautilus-tree-sidebar.h \
nautilus-tree-sidebar-model.c \
diff --git a/src/nautilus-toolbar.c b/src/nautilus-toolbar.c
new file mode 100644
index 0000000..7cf379f
--- /dev/null
+++ b/src/nautilus-toolbar.c
@@ -0,0 +1,281 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+
+/*
+ * Nautilus
+ *
+ * Copyright (C) 2011, Red Hat, Inc.
+ *
+ * Nautilus 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.
+ *
+ * Nautilus 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Author: Cosimo Cecchi <cosimoc redhat com>
+ *
+ */
+
+#include <config.h>
+
+#include "nautilus-toolbar.h"
+
+#include "nautilus-location-bar.h"
+#include "nautilus-pathbar.h"
+#include "nautilus-global-preferences.h"
+
+struct _NautilusToolbarPriv {
+ GtkWidget *toolbar;
+
+ NautilusNavigationWindowPane *pane;
+
+ GtkWidget *path_bar;
+ GtkWidget *location_bar;
+ GtkWidget *search_bar;
+
+ gboolean show_main_bar;
+ gboolean show_location_entry;
+ gboolean show_search_bar;
+};
+
+enum {
+ PROP_PANE = 1,
+ PROP_SHOW_LOCATION_ENTRY,
+ PROP_SHOW_SEARCH_BAR,
+ PROP_SHOW_MAIN_BAR,
+ NUM_PROPERTIES
+};
+
+static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
+
+G_DEFINE_TYPE (NautilusToolbar, nautilus_toolbar, GTK_TYPE_BOX);
+
+static void
+toolbar_update_appearance (NautilusToolbar *self)
+{
+ gboolean show_location_entry;
+
+ show_location_entry = self->priv->show_location_entry ||
+ g_settings_get_boolean (nautilus_preferences, NAUTILUS_PREFERENCES_ALWAYS_USE_LOCATION_ENTRY);
+
+ gtk_widget_set_visible (self->priv->toolbar,
+ self->priv->show_main_bar);
+
+ gtk_widget_set_visible (self->priv->location_bar,
+ show_location_entry);
+ gtk_widget_set_visible (self->priv->path_bar,
+ !show_location_entry);
+
+ gtk_widget_set_visible (self->priv->search_bar,
+ self->priv->show_search_bar);
+}
+
+static void
+nautilus_toolbar_constructed (GObject *obj)
+{
+ NautilusToolbar *self = NAUTILUS_TOOLBAR (obj);
+ GtkToolItem *item;
+ GtkWidget *hbox;
+
+ G_OBJECT_CLASS (nautilus_toolbar_parent_class)->constructed (obj);
+
+ self->priv->toolbar = gtk_toolbar_new ();
+ gtk_box_pack_start (GTK_BOX (self), self->priv->toolbar, TRUE, TRUE, 0);
+ gtk_widget_show (self->priv->toolbar);
+
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+ gtk_widget_show (hbox);
+
+ /* regular path bar */
+ self->priv->path_bar = g_object_new (NAUTILUS_TYPE_PATH_BAR, NULL);
+ gtk_box_pack_start (GTK_BOX (hbox), self->priv->path_bar, TRUE, TRUE, 0);
+
+ /* entry-like location bar */
+ self->priv->location_bar = nautilus_location_bar_new (self->priv->pane);
+ gtk_box_pack_start (GTK_BOX (hbox), self->priv->location_bar, TRUE, TRUE, 0);
+
+ item = gtk_tool_item_new ();
+ gtk_tool_item_set_expand (item, TRUE);
+ gtk_container_add (GTK_CONTAINER (item), hbox);
+ gtk_toolbar_insert (GTK_TOOLBAR (self->priv->toolbar), item, 0);
+ gtk_widget_show (GTK_WIDGET (item));
+
+ /* search bar */
+ self->priv->search_bar = nautilus_search_bar_new ();
+ gtk_box_pack_start (GTK_BOX (self), self->priv->search_bar, TRUE, TRUE, 0);
+
+ g_signal_connect_swapped (nautilus_preferences,
+ "changed::" NAUTILUS_PREFERENCES_ALWAYS_USE_LOCATION_ENTRY,
+ G_CALLBACK (toolbar_update_appearance), self);
+
+ toolbar_update_appearance (self);
+}
+
+static void
+nautilus_toolbar_init (NautilusToolbar *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NAUTILUS_TYPE_TOOLBAR,
+ NautilusToolbarPriv);
+ self->priv->show_main_bar = TRUE;
+}
+
+static void
+nautilus_toolbar_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ NautilusToolbar *self = NAUTILUS_TOOLBAR (object);
+
+ switch (property_id) {
+ case PROP_SHOW_LOCATION_ENTRY:
+ g_value_set_boolean (value, self->priv->show_location_entry);
+ break;
+ case PROP_SHOW_SEARCH_BAR:
+ g_value_set_boolean (value, self->priv->show_search_bar);
+ break;
+ case PROP_SHOW_MAIN_BAR:
+ g_value_set_boolean (value, self->priv->show_main_bar);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+nautilus_toolbar_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ NautilusToolbar *self = NAUTILUS_TOOLBAR (object);
+
+ switch (property_id) {
+ case PROP_PANE:
+ self->priv->pane = g_value_get_object (value);
+ break;
+ case PROP_SHOW_LOCATION_ENTRY:
+ nautilus_toolbar_set_show_location_entry (self, g_value_get_boolean (value));
+ break;
+ case PROP_SHOW_SEARCH_BAR:
+ nautilus_toolbar_set_show_search_bar (self, g_value_get_boolean (value));
+ break;
+ case PROP_SHOW_MAIN_BAR:
+ nautilus_toolbar_set_show_main_bar (self, g_value_get_boolean (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+nautilus_toolbar_class_init (NautilusToolbarClass *klass)
+{
+ GObjectClass *oclass;
+
+ oclass = G_OBJECT_CLASS (klass);
+ oclass->get_property = nautilus_toolbar_get_property;
+ oclass->set_property = nautilus_toolbar_set_property;
+ oclass->constructed = nautilus_toolbar_constructed;
+
+ properties[PROP_PANE] =
+ g_param_spec_object ("pane",
+ "The parent pane",
+ "The pane that contains this toolbar",
+ NAUTILUS_TYPE_NAVIGATION_WINDOW_PANE,
+ G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS);
+ properties[PROP_SHOW_LOCATION_ENTRY] =
+ g_param_spec_boolean ("show-location-entry",
+ "Whether to show the location entry",
+ "Whether to show the location entry instead of the pathbar",
+ FALSE,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+ properties[PROP_SHOW_SEARCH_BAR] =
+ g_param_spec_boolean ("show-search-bar",
+ "Whether to show the search bar",
+ "Whether to show the search bar beside the toolbar",
+ FALSE,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+ properties[PROP_SHOW_MAIN_BAR] =
+ g_param_spec_boolean ("show-main-bar",
+ "Whether to show the main bar",
+ "Whether to show the main toolbar",
+ TRUE,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+ g_type_class_add_private (klass, sizeof (NautilusToolbarClass));
+ g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
+}
+
+GtkWidget *
+nautilus_toolbar_new (NautilusNavigationWindowPane *parent)
+{
+ return g_object_new (NAUTILUS_TYPE_TOOLBAR,
+ "pane", parent,
+ "orientation", GTK_ORIENTATION_VERTICAL,
+ NULL);
+}
+
+GtkWidget *
+nautilus_toolbar_get_path_bar (NautilusToolbar *self)
+{
+ return self->priv->path_bar;
+}
+
+GtkWidget *
+nautilus_toolbar_get_location_bar (NautilusToolbar *self)
+{
+ return self->priv->location_bar;
+}
+
+GtkWidget *
+nautilus_toolbar_get_search_bar (NautilusToolbar *self)
+{
+ return self->priv->search_bar;
+}
+
+void
+nautilus_toolbar_set_show_main_bar (NautilusToolbar *self,
+ gboolean show_main_bar)
+{
+ if (show_main_bar != self->priv->show_main_bar) {
+ self->priv->show_main_bar = show_main_bar;
+ toolbar_update_appearance (self);
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SHOW_MAIN_BAR]);
+ }
+}
+
+void
+nautilus_toolbar_set_show_location_entry (NautilusToolbar *self,
+ gboolean show_location_entry)
+{
+ if (show_location_entry != self->priv->show_location_entry) {
+ self->priv->show_location_entry = show_location_entry;
+ toolbar_update_appearance (self);
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SHOW_LOCATION_ENTRY]);
+ }
+}
+
+void
+nautilus_toolbar_set_show_search_bar (NautilusToolbar *self,
+ gboolean show_search_bar)
+{
+ if (show_search_bar != self->priv->show_search_bar) {
+ self->priv->show_search_bar = show_search_bar;
+ toolbar_update_appearance (self);
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SHOW_SEARCH_BAR]);
+ }
+}
diff --git a/src/nautilus-toolbar.h b/src/nautilus-toolbar.h
new file mode 100644
index 0000000..adcf6ef
--- /dev/null
+++ b/src/nautilus-toolbar.h
@@ -0,0 +1,80 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+
+/*
+ * Nautilus
+ *
+ * Copyright (C) 2011, Red Hat, Inc.
+ *
+ * Nautilus 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.
+ *
+ * Nautilus 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Author: Cosimo Cecchi <cosimoc redhat com>
+ *
+ */
+
+#ifndef __NAUTILUS_TOOLBAR_H__
+#define __NAUTILUS_TOOLBAR_H__
+
+#include <gtk/gtk.h>
+
+#define NAUTILUS_TYPE_TOOLBAR nautilus_toolbar_get_type()
+#define NAUTILUS_TOOLBAR(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), NAUTILUS_TYPE_TOOLBAR, NautilusToolbar))
+#define NAUTILUS_TOOLBAR_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_TOOLBAR, NautilusToolbarClass))
+#define NAUTILUS_IS_TOOLBAR(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NAUTILUS_TYPE_TOOLBAR))
+#define NAUTILUS_IS_TOOLBAR_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_TOOLBAR))
+#define NAUTILUS_TOOLBAR_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), NAUTILUS_TYPE_TOOLBAR, NautilusToolbarClass))
+
+typedef struct _NautilusToolbar NautilusToolbar;
+typedef struct _NautilusToolbarPriv NautilusToolbarPriv;
+typedef struct _NautilusToolbarClass NautilusToolbarClass;
+
+#include "nautilus-navigation-window-pane.h"
+
+typedef enum {
+ NAUTILUS_TOOLBAR_MODE_PATH_BAR,
+ NAUTILUS_TOOLBAR_MODE_LOCATION_BAR,
+} NautilusToolbarMode;
+
+struct _NautilusToolbar {
+ GtkBox parent;
+
+ /* private */
+ NautilusToolbarPriv *priv;
+};
+
+struct _NautilusToolbarClass {
+ GtkBoxClass parent_class;
+};
+
+GType nautilus_toolbar_get_type (void);
+
+GtkWidget *nautilus_toolbar_new (NautilusNavigationWindowPane *parent);
+
+GtkWidget *nautilus_toolbar_get_path_bar (NautilusToolbar *self);
+GtkWidget *nautilus_toolbar_get_location_bar (NautilusToolbar *self);
+GtkWidget *nautilus_toolbar_get_search_bar (NautilusToolbar *self);
+
+void nautilus_toolbar_set_show_main_bar (NautilusToolbar *self,
+ gboolean show_main_bar);
+void nautilus_toolbar_set_show_location_entry (NautilusToolbar *self,
+ gboolean show_location_entry);
+void nautilus_toolbar_set_show_search_bar (NautilusToolbar *self,
+ gboolean show_search_bar);
+
+#endif /* __NAUTILUS_TOOLBAR_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]