diff options
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/nautilus-toolbar.c | 20 | ||||
-rw-r--r-- | src/nautilus-view-menu.c | 173 | ||||
-rw-r--r-- | src/nautilus-view-menu.h | 60 | ||||
-rw-r--r-- | src/nautilus-view-menu.ui | 136 | ||||
-rw-r--r-- | src/nautilus.gresource.xml | 1 |
6 files changed, 392 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 2aaea2450..87b5ed422 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -211,6 +211,8 @@ nautilus_SOURCES = \ nautilus-view.h \ nautilus-view-dnd.c \ nautilus-view-dnd.h \ + nautilus-view-menu.c \ + nautilus-view-menu.h \ nautilus-window-menus.c \ nautilus-window-private.h \ nautilus-window-slot.c \ diff --git a/src/nautilus-toolbar.c b/src/nautilus-toolbar.c index 642f524bc..0401a457e 100644 --- a/src/nautilus-toolbar.c +++ b/src/nautilus-toolbar.c @@ -29,6 +29,7 @@ #include "nautilus-location-entry.h" #include "nautilus-pathbar.h" #include "nautilus-actions.h" +#include "nautilus-view-menu.h" #include <libnautilus-private/nautilus-global-preferences.h> #include <libnautilus-private/nautilus-ui-utilities.h> @@ -51,6 +52,10 @@ struct _NautilusToolbarPriv { gboolean show_location_entry; guint popup_timeout_id; + + GtkWidget *view_button; + GtkWidget *view_menu_popover; + GtkWidget *view_menu; }; enum { @@ -446,6 +451,21 @@ nautilus_toolbar_constructed (GObject *obj) button = toolbar_create_toolbutton (self, FALSE, TRUE, NAUTILUS_ACTION_VIEW_GRID, NULL); gtk_widget_set_valign (button, GTK_ALIGN_CENTER); gtk_container_add (GTK_CONTAINER (box), button); + + /* View menu popover */ + self->priv->view_button = gtk_menu_button_new (); + self->priv->view_menu_popover = gtk_popover_new (self->priv->view_button); + + gtk_menu_button_set_popover (GTK_MENU_BUTTON (self->priv->view_button), + self->priv->view_menu_popover); + + self->priv->view_menu = nautilus_view_menu_new (self->priv->window); + gtk_container_add (GTK_CONTAINER (self->priv->view_menu_popover), + GTK_WIDGET (self->priv->view_menu)); + gtk_widget_show_all (GTK_WIDGET (self->priv->view_menu)); + gtk_container_add (GTK_CONTAINER (box), self->priv->view_button); + + /* View options */ button = toolbar_create_toolbutton (self, TRUE, FALSE, "go-down-symbolic", _("View options")); gtk_widget_set_valign (button, GTK_ALIGN_CENTER); gtk_container_add (GTK_CONTAINER (box), button); diff --git a/src/nautilus-view-menu.c b/src/nautilus-view-menu.c new file mode 100644 index 000000000..75fd46a05 --- /dev/null +++ b/src/nautilus-view-menu.c @@ -0,0 +1,173 @@ +#include <glib/gi18n.h> + +#include "nautilus-view-menu.h" +#include "nautilus-actions.h" +#include "math.h" + +struct _NautilusViewMenuPrivate +{ + GtkWidget *grid_button; + GtkWidget *list_button; + GtkWidget *zoom_level_scale; + GtkWidget *sort_name; + GtkWidget *sort_size; + NautilusWindow *window; + NautilusCanvasView *canvas_view; +}; + +enum +{ + ZOOM_LEVEL_CHANGED, + LAST_SIGNAL +}; + +static guint signals [LAST_SIGNAL] = { 0 }; + +enum { + PROP_WINDOW = 1, + PROP_CANVASVIEW, + NUM_PROPERTIES +}; + +static GParamSpec *properties[NUM_PROPERTIES] = { NULL, }; + + +G_DEFINE_TYPE_WITH_PRIVATE (NautilusViewMenu, nautilus_view_menu, GTK_TYPE_BOX) + +static void +zoom_level_changed (GtkRange *range, NautilusViewMenu *self) +{ + gdouble zoom_level = gtk_range_get_value (range); + g_printf("zoom level %f\n", zoom_level); + g_signal_emit (self, signals[ZOOM_LEVEL_CHANGED], 0, + 1, zoom_level, + G_TYPE_NONE); +} + +static void +nautilus_toolbar_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + NautilusViewMenu *self = NAUTILUS_VIEW_MENU (object); + + switch (property_id) { + case PROP_WINDOW: + self->priv->window = g_value_get_object (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} +static void +nautilus_view_menu_finalize (GObject *object) +{ + NautilusViewMenu *self = NAUTILUS_VIEW_MENU (object); + + G_OBJECT_CLASS (nautilus_view_menu_parent_class)->finalize (object); +} + +static void +nautilus_view_menu_constructed (GObject *obj) +{ + NautilusViewMenu *self = NAUTILUS_VIEW_MENU (obj); + GtkActionGroup *action_group; + GtkAction *action; + + G_OBJECT_CLASS (nautilus_view_menu_parent_class)->constructed (obj); + + action_group = nautilus_window_get_main_action_group (self->priv->window); + + action = gtk_action_group_get_action (action_group, NAUTILUS_ACTION_VIEW_GRID); + gtk_activatable_set_related_action (GTK_ACTIVATABLE (self->priv->grid_button), action); + gtk_button_set_label (GTK_BUTTON (self->priv->grid_button), NULL); + + action = gtk_action_group_get_action (action_group, NAUTILUS_ACTION_VIEW_LIST); + gtk_activatable_set_related_action (GTK_ACTIVATABLE (self->priv->list_button), action); + gtk_button_set_label (GTK_BUTTON (self->priv->list_button), NULL); + + action = gtk_action_group_get_action (action_group, "Sort by Name"); + //g_assert(action); +/* g_printf ("ACTION TYPE %s\n", G_IS_OBJECT(action)); + gtk_activatable_set_related_action (GTK_ACTIVATABLE (self->priv->sort_name), action); + + action = gtk_action_group_get_action (action_group, "Sort by Size"); + gtk_activatable_set_related_action (GTK_ACTIVATABLE (self->priv->sort_size), action); + */ +} + +static void +nautilus_view_menu_class_init (NautilusViewMenuClass *klass) +{ + GObjectClass *object_class; + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + object_class = G_OBJECT_CLASS (klass); + object_class->finalize = nautilus_view_menu_finalize; + object_class->constructed = nautilus_view_menu_constructed; + object_class->set_property = nautilus_toolbar_set_property; + + gtk_widget_class_set_template_from_resource (widget_class, + "/org/gnome/nautilus/nautilus-view-menu.ui"); + gtk_widget_class_bind_template_child_private(widget_class, NautilusViewMenu, grid_button); + gtk_widget_class_bind_template_child_private(widget_class, NautilusViewMenu, list_button); + gtk_widget_class_bind_template_child_private(widget_class, NautilusViewMenu, zoom_level_scale); + gtk_widget_class_bind_template_child_private(widget_class, NautilusViewMenu, sort_name); + gtk_widget_class_bind_template_child_private(widget_class, NautilusViewMenu, sort_size); + + signals [ZOOM_LEVEL_CHANGED] = + g_signal_new ("zoom-level-changed", + G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + g_cclosure_marshal_VOID__DOUBLE, + G_TYPE_NONE, + 1, G_TYPE_DOUBLE); + + properties[PROP_WINDOW] = + g_param_spec_object ("window", + "The NautilusWindow", + "The NautilusWindow this view menu is part of", + NAUTILUS_TYPE_WINDOW, + G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS); + + properties[PROP_CANVASVIEW] = + g_param_spec_object ("canvas-view", + "The NautilusCanvasView", + "The CanvasView this view menu is part of", + NAUTILUS_TYPE_DESKTOP_CANVAS_VIEW, + G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS); + + g_object_class_install_properties (object_class, NUM_PROPERTIES, properties); +} + +static void +nautilus_view_menu_init (NautilusViewMenu *self) +{ + GtkAdjustment * adj; + self->priv = nautilus_view_menu_get_instance_private (self); + gtk_widget_init_template (GTK_WIDGET (self)); + + adj = gtk_range_get_adjustment (GTK_RANGE (self->priv->zoom_level_scale)); + g_signal_connect(self->priv->zoom_level_scale, "value-changed", + G_CALLBACK(zoom_level_changed), + self); +} + +NautilusViewMenu * +nautilus_view_menu_new (NautilusWindow *window, + NautilusCanvasView *canvas_view) +{ + g_assert (NAUTILUS_IS_WINDOW (window)); + NautilusViewMenu *self = g_object_new (NAUTILUS_TYPE_VIEW_MENU, + "window", window, + "canvas-view", canvas_view, + NULL); + + return self; +} +/* ex:set ts=8 noet: */ diff --git a/src/nautilus-view-menu.h b/src/nautilus-view-menu.h new file mode 100644 index 000000000..4b9a4204c --- /dev/null +++ b/src/nautilus-view-menu.h @@ -0,0 +1,60 @@ +/* nautilus-view-menu.h + * + * Copyright (C) 2014 Carlos Soriano <carlos.soriano89@gmail.com> + * + * This file is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This file 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef NAUTILUS_VIEW_MENU_H +#define NAUTILUS_VIEW_MENU_H + +#include <glib-object.h> +#include <gtk/gtk.h> +#include "nautilus-window.h" + +G_BEGIN_DECLS + +#define NAUTILUS_TYPE_VIEW_MENU (nautilus_view_menu_get_type()) +#define NAUTILUS_VIEW_MENU(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NAUTILUS_TYPE_VIEW_MENU, NautilusViewMenu)) +#define NAUTILUS_VIEW_MENU_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NAUTILUS_TYPE_VIEW_MENU, NautilusViewMenu const)) +#define NAUTILUS_VIEW_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_VIEW_MENU, NautilusViewMenuClass)) +#define NAUTILUS_IS_VIEW_MENU(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NAUTILUS_TYPE_VIEW_MENU)) +#define NAUTILUS_IS_VIEW_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_VIEW_MENU)) +#define NAUTILUS_VIEW_MENU_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NAUTILUS_TYPE_VIEW_MENU, NautilusViewMenuClass)) + +typedef struct _NautilusViewMenu NautilusViewMenu; +typedef struct _NautilusViewMenuClass NautilusViewMenuClass; +typedef struct _NautilusViewMenuPrivate NautilusViewMenuPrivate; + +struct _NautilusViewMenu +{ + GtkBox parent; + + /*< private >*/ + NautilusViewMenuPrivate *priv; +}; + +struct _NautilusViewMenuClass +{ + GtkBoxClass parent_class; + void (*zoom_level_changed) (NautilusViewMenu *view_menu); +}; + +GType nautilus_view_menu_get_type (void) G_GNUC_CONST; + +NautilusViewMenu * nautilus_view_menu_new (NautilusWindow *window); + +G_END_DECLS + +#endif /* NAUTILUS_VIEW_MENU_H */ diff --git a/src/nautilus-view-menu.ui b/src/nautilus-view-menu.ui new file mode 100644 index 000000000..7420e1a75 --- /dev/null +++ b/src/nautilus-view-menu.ui @@ -0,0 +1,136 @@ +<?xml version="1.0" encoding="UTF-8"?> +<interface> + <requires lib="gtk+" version="3.10"/> + <template class="NautilusViewMenu" parent="GtkBox"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="border_width">9</property> + <property name="orientation">vertical</property> + <property name="spacing">6</property> + <child> + <object class="GtkBox" id="views_box"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="orientation">horizontal</property> + <property name="homogeneous">True</property> + <property name="width_request">200</property> + <style> + <class name="linked"/> + </style> + <child> + <object class="GtkToggleButton" id="grid_button"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="image">grid_image</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkToggleButton" id="list_button"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="image">list_image</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + </object> + </child> + <child> + <object class="GtkScale" id="zoom_level_scale"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="draw_value">False</property> + <property name="adjustment">zoom_adjustment</property> + <property name="round_digits">0</property> + <property name="restrict_to_fill_level">False</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="sort_label"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="halign">start</property> + <property name="label" translatable="yes">Sort</property> + <style> + <class name="dim-label"/> + </style> + </object> + </child> + <child> + <object class="GtkRadioButton" id="sort_name"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="label" translatable="yes">name</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + </packing> + </child> + <child> + <object class="GtkRadioButton" id="sort_size"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="label" translatable="yes">size</property> + <property name="group">sort_name</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + </packing> + </child> + <child> + <object class="GtkRadioButton" id="sort_type"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="label" translatable="yes">type</property> + <property name="group">sort_name</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + </packing> + </child> + <child> + <object class="GtkRadioButton" id="sort_date"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="label" translatable="yes">date</property> + <property name="group">sort_name</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + </packing> + </child> + </template> + <object class="GtkImage" id="grid_image"> + <property name="visible">True</property> + <property name="icon_name">view-grid-symbolic</property> + </object> + <object class="GtkImage" id="list_image"> + <property name="visible">True</property> + <property name="icon_name">view-list-symbolic</property> + </object> + <object class="GtkAdjustment" id="zoom_adjustment"> + <property name="lower">1</property> + <property name="upper">3</property> + <property name="step_increment">1</property> + <property name="page_increment">1</property> + <property name="value">2</property> + </object> +</interface> diff --git a/src/nautilus.gresource.xml b/src/nautilus.gresource.xml index 37a5bbf7f..ef9a6fda9 100644 --- a/src/nautilus.gresource.xml +++ b/src/nautilus.gresource.xml @@ -9,6 +9,7 @@ <file>nautilus-list-view-ui.xml</file> <file>nautilus-shell-ui.xml</file> <file>nautilus-app-menu.ui</file> + <file>nautilus-view-menu.ui</file> <file alias="icons/thumbnail_frame.png">../icons/thumbnail_frame.png</file> <file alias="icons/filmholes.png">../icons/filmholes.png</file> <file alias="icons/knob.png">../icons/knob.png</file> |