diff options
author | Carlos Soriano <csoriano@gnome.org> | 2018-04-09 17:52:09 +0200 |
---|---|---|
committer | Carlos Soriano <csoriano@gnome.org> | 2018-04-09 17:52:09 +0200 |
commit | ebaefd58d07ad00ce5dc4047f468ee1e900f58db (patch) | |
tree | f9d0300429c23078d58fd42d1e847b87887794e7 | |
parent | 540a29ba7fc9bc8acf0442863f87512dde31d454 (diff) | |
download | nautilus-ebaefd58d07ad00ce5dc4047f468ee1e900f58db.tar.gz |
action-bar: Provide 30% box designaction-info-bar-non-flat
-rw-r--r-- | src/meson.build | 2 | ||||
-rw-r--r-- | src/nautilus-action-bar-box.c | 181 | ||||
-rw-r--r-- | src/nautilus-action-bar-box.h | 32 | ||||
-rw-r--r-- | src/nautilus-action-bar.c | 9 | ||||
-rw-r--r-- | src/resources/ui/nautilus-action-bar.ui | 352 |
5 files changed, 403 insertions, 173 deletions
diff --git a/src/meson.build b/src/meson.build index f54d16140..a3892e38d 100644 --- a/src/meson.build +++ b/src/meson.build @@ -57,6 +57,8 @@ libnautilus_sources = [ 'gtk/nautilusgtkplacesviewrowprivate.h', 'nautilus-action-bar.c', 'nautilus-action-bar.h', + 'nautilus-action-bar-box.c', + 'nautilus-action-bar-box.h', 'nautilus-application.c', 'nautilus-application.h', 'nautilus-bookmark-list.c', diff --git a/src/nautilus-action-bar-box.c b/src/nautilus-action-bar-box.c new file mode 100644 index 000000000..3ef82b7eb --- /dev/null +++ b/src/nautilus-action-bar-box.c @@ -0,0 +1,181 @@ +/* nautilus-action-bar-box.c + * + * Copyright 2018 Carlos Soriano <csoriano@redhat.com> + * + * 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 3 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, see <http://www.gnu.org/licenses/>. + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include "nautilus-action-bar-box.h" + +#define INFO_SECTION_WIDTH_RATIO 0.3 +#define INFO_SECTION_CHILD_POSITION_INDEX 0 +#define ACTION_SECTION_CHILD_POSITION_INDEX 1 + +struct _NautilusActionBarBox +{ + GtkBox parent_instance; +}; + +G_DEFINE_TYPE (NautilusActionBarBox, nautilus_action_bar_box, GTK_TYPE_BOX) + +enum { + PROP_0, + N_PROPS +}; + +static GParamSpec *properties [N_PROPS]; + +NautilusActionBarBox * +nautilus_action_bar_box_new (void) +{ + return g_object_new (NAUTILUS_TYPE_ACTION_BAR_BOX, NULL); +} + +static void +nautilus_action_bar_box_finalize (GObject *object) +{ + NautilusActionBarBox *self = (NautilusActionBarBox *)object; + + G_OBJECT_CLASS (nautilus_action_bar_box_parent_class)->finalize (object); +} + +static void +nautilus_action_bar_box_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + NautilusActionBarBox *self = NAUTILUS_ACTION_BAR_BOX (object); + + switch (prop_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +nautilus_action_bar_box_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + NautilusActionBarBox *self = NAUTILUS_ACTION_BAR_BOX (object); + + switch (prop_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +nautilus_action_bar_box_size_allocate (GtkWidget *widget, + GtkAllocation *allocation) +{ + NautilusActionBarBox *self = NAUTILUS_ACTION_BAR_BOX (widget); + g_autoptr (GList) children = NULL; + GList *child; + GtkRequisition minimum_size; + GtkRequisition natural_size; + gint available_width = 0; + gint margin_sizes = 0; + GtkRequestedSize *sizes; + gint n_visible_children; + GtkAllocation child_allocation; + gint current_x = 0; + gint i; + + children = gtk_container_get_children (GTK_CONTAINER (self)); + + /* Only the info section and the action section should be added in this container */ + g_return_if_fail (g_list_length (children) == 2); + n_visible_children = 2; + + sizes = g_newa (GtkRequestedSize, g_list_length (children)); + available_width = allocation->width; + + gtk_widget_get_preferred_size (widget, &minimum_size, &natural_size); + + gtk_widget_set_allocation (widget, allocation); + + for (child = children, i = 0; child != NULL; child = child->next, i++) + { + gtk_widget_get_preferred_width_for_height (child->data, + allocation->height, + &sizes[i].minimum_size, + &sizes[i].natural_size); + sizes[i].data = child->data; + margin_sizes += gtk_widget_get_margin_end (child->data) + + gtk_widget_get_margin_start (child->data); + } + + g_print ("allocation width %d %d\n", allocation->width, margin_sizes); + available_width -= margin_sizes; + if ((sizes[INFO_SECTION_CHILD_POSITION_INDEX].natural_size + + sizes[ACTION_SECTION_CHILD_POSITION_INDEX].natural_size) + < available_width) + { + /* Info section */ + sizes[INFO_SECTION_CHILD_POSITION_INDEX].minimum_size = MAX (INFO_SECTION_WIDTH_RATIO * available_width, + sizes[INFO_SECTION_CHILD_POSITION_INDEX].minimum_size); + sizes[INFO_SECTION_CHILD_POSITION_INDEX].natural_size = sizes[INFO_SECTION_CHILD_POSITION_INDEX].minimum_size; + g_print ("info %d\n", sizes[INFO_SECTION_CHILD_POSITION_INDEX].minimum_size); + + /* Actions section */ + sizes[ACTION_SECTION_CHILD_POSITION_INDEX].minimum_size = MAX ((1.0 - INFO_SECTION_WIDTH_RATIO) * available_width, + sizes[ACTION_SECTION_CHILD_POSITION_INDEX].minimum_size); + sizes[ACTION_SECTION_CHILD_POSITION_INDEX].natural_size = sizes[ACTION_SECTION_CHILD_POSITION_INDEX].minimum_size; + g_print ("action %d\n", sizes[ACTION_SECTION_CHILD_POSITION_INDEX].minimum_size); + } + available_width -= sizes[INFO_SECTION_CHILD_POSITION_INDEX].minimum_size + + sizes[ACTION_SECTION_CHILD_POSITION_INDEX].minimum_size; + g_print ("available width %d\n", available_width); + + gtk_distribute_natural_allocation (MAX (0, available_width), + n_visible_children, sizes); + + for (child = children, i = 0; child != NULL; child = child->next, i++) + { + child_allocation.x = current_x + gtk_widget_get_margin_start (child->data); + child_allocation.y = allocation->y; + child_allocation.width = sizes[i].minimum_size; + child_allocation.height = allocation->height; + + g_print ("child alloc %d %d %d %d %d\n", current_x, child_allocation.x, sizes[i].minimum_size, gtk_widget_get_margin_end (child->data), gtk_widget_get_margin_start (child->data)); + gtk_widget_size_allocate (child->data, &child_allocation); + + current_x += sizes[i].minimum_size + gtk_widget_get_margin_end (child->data); + } +} + +static void +nautilus_action_bar_box_class_init (NautilusActionBarBoxClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + object_class->finalize = nautilus_action_bar_box_finalize; + object_class->get_property = nautilus_action_bar_box_get_property; + object_class->set_property = nautilus_action_bar_box_set_property; + + widget_class->size_allocate = nautilus_action_bar_box_size_allocate; +} + +static void +nautilus_action_bar_box_init (NautilusActionBarBox *self) +{ +} diff --git a/src/nautilus-action-bar-box.h b/src/nautilus-action-bar-box.h new file mode 100644 index 000000000..8034e2692 --- /dev/null +++ b/src/nautilus-action-bar-box.h @@ -0,0 +1,32 @@ +/* nautilus-action-bar.h + * + * Copyright (C) 2018 Carlos Soriano <csoriano@redhat.com> + * + * 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +#pragma once + +#include <glib-object.h> +#include <gtk/gtk.h> + +G_BEGIN_DECLS + +#define NAUTILUS_TYPE_ACTION_BAR_BOX (nautilus_action_bar_box_get_type()) + +G_DECLARE_FINAL_TYPE (NautilusActionBarBox, nautilus_action_bar_box, NAUTILUS, ACTION_BAR_BOX, GtkBox) + +NautilusActionBarBox *nautilus_action_bar_box_new (void); + +G_END_DECLS diff --git a/src/nautilus-action-bar.c b/src/nautilus-action-bar.c index 206132838..05140481f 100644 --- a/src/nautilus-action-bar.c +++ b/src/nautilus-action-bar.c @@ -20,6 +20,7 @@ #include "nautilus-clipboard.h" #include "nautilus-file.h" #include "nautilus-previewer.h" +#include "nautilus-action-bar-box.h" #include <gdk/gdkx.h> @@ -372,7 +373,9 @@ nautilus_action_bar_class_init (NautilusActionBarClass *klass) static void nautilus_action_bar_init (NautilusActionBar *self) { - gtk_widget_init_template (GTK_WIDGET (self)); + g_type_ensure (NAUTILUS_TYPE_ACTION_BAR_BOX); + + gtk_widget_init_template (GTK_WIDGET (self)); #if 0 update_paste_button (self); @@ -385,6 +388,6 @@ nautilus_action_bar_init (NautilusActionBar *self) NautilusActionBar* nautilus_action_bar_new (void) { - return NAUTILUS_ACTION_BAR (g_object_new (NAUTILUS_TYPE_ACTION_BAR, - NULL)); + return NAUTILUS_ACTION_BAR (g_object_new (NAUTILUS_TYPE_ACTION_BAR, + NULL)); } diff --git a/src/resources/ui/nautilus-action-bar.ui b/src/resources/ui/nautilus-action-bar.ui index 856a05bb9..8bda688bf 100644 --- a/src/resources/ui/nautilus-action-bar.ui +++ b/src/resources/ui/nautilus-action-bar.ui @@ -16,153 +16,165 @@ <property name="hexpand">True</property> <property name="transition_type">crossfade</property> <child> - <object class="GtkBox"> + <object class="NautilusActionBarBox"> <property name="visible">True</property> <property name="can_focus">False</property> <child> <object class="GtkBox"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="margin_left">4</property> - <property name="spacing">4</property> <child> - <object class="GtkButton"> + <object class="GtkBox"> <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="action_name">view.star</property> + <property name="can_focus">False</property> + <property name="margin_left">4</property> + <property name="spacing">4</property> <child> - <object class="GtkImage"> + <object class="GtkButton"> <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="icon_name">non-starred-symbolic</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="action_name">view.star</property> + <child> + <object class="GtkImage"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="icon_name">non-starred-symbolic</property> + </object> + </child> </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> </child> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkButton"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="action_name">view.move-to-trash</property> <child> - <object class="GtkImage"> + <object class="GtkButton"> <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="icon_name">user-trash-symbolic</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="action_name">view.move-to-trash</property> + <child> + <object class="GtkImage"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="icon_name">user-trash-symbolic</property> + </object> + </child> </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> </child> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">1</property> - </packing> - </child> - <child> - <object class="GtkButton"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> <child> - <object class="GtkImage"> + <object class="GtkButton"> <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="icon_name">view-more-symbolic</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <child> + <object class="GtkImage"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="icon_name">view-more-symbolic</property> + </object> + </child> + <style> + <class name="image-button"/> + </style> </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">2</property> + </packing> </child> - <style> - <class name="image-button"/> - </style> </object> <packing> <property name="expand">False</property> <property name="fill">True</property> - <property name="position">2</property> - </packing> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="pack_type">end</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkBox"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="spacing">4</property> - <property name="homogeneous">True</property> - <child> - <object class="GtkButton"> - <property name="label" translatable="yes">Open</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="action_name">view.open-with-default-application</property> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> + <property name="pack_type">end</property> <property name="position">0</property> </packing> </child> <child> - <object class="GtkButton"> - <property name="label" translatable="yes">Copy</property> + <object class="GtkBox"> <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="action_name">view.copy</property> + <property name="can_focus">False</property> + <property name="spacing">4</property> + <property name="homogeneous">True</property> + <child> + <object class="GtkButton"> + <property name="label" translatable="yes">Open</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="action_name">view.open-with-default-application</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkButton"> + <property name="label" translatable="yes">Copy</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="action_name">view.copy</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkButton"> + <property name="label" translatable="yes">Cut</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="action_name">view.cut</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">3</property> + </packing> + </child> + <child> + <object class="GtkButton"> + <property name="label" translatable="yes">Rename...</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="action_name">view.rename</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">3</property> + </packing> + </child> </object> <packing> <property name="expand">True</property> <property name="fill">True</property> + <property name="pack_type">end</property> <property name="position">1</property> </packing> </child> - <child> - <object class="GtkButton"> - <property name="label" translatable="yes">Cut</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="action_name">view.cut</property> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">3</property> - </packing> - </child> - <child> - <object class="GtkButton"> - <property name="label" translatable="yes">Rename...</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="action_name">view.rename</property> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">3</property> - </packing> - </child> </object> <packing> <property name="expand">True</property> <property name="fill">True</property> <property name="pack_type">end</property> - <property name="position">1</property> + <property name="position">0</property> </packing> </child> <child> @@ -291,14 +303,13 @@ </packing> </child> <child> - <object class="GtkBox"> + <object class="NautilusActionBarBox"> <property name="visible">True</property> <property name="can_focus">False</property> <child> <object class="GtkBox"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="margin_left">4</property> <child> <object class="GtkButton"> <property name="visible">True</property> @@ -315,76 +326,77 @@ <packing> <property name="expand">False</property> <property name="fill">True</property> - <property name="position">2</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="GtkBox"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="spacing">4</property> - <child> - <object class="GtkButton"> - <property name="label" translatable="yes">New Folder...</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="action_name">view.new-folder</property> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> + <property name="pack_type">end</property> <property name="position">0</property> </packing> </child> <child> - <object class="GtkButton" id="paste_button"> - <property name="label" translatable="yes">Paste</property> + <object class="GtkBox"> <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="action_name">view.paste</property> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">2</property> - </packing> - </child> - <child> - <object class="GtkButton"> - <property name="label" translatable="yes">Select All</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="action_name">view.select-all</property> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">4</property> - </packing> - </child> - <child> - <object class="GtkButton"> - <property name="label" translatable="yes">Properties</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="action_name">view.properties</property> + <property name="can_focus">False</property> + <property name="spacing">4</property> + <child> + <object class="GtkButton"> + <property name="label" translatable="yes">New Folder...</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="action_name">view.new-folder</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkButton" id="paste_button"> + <property name="label" translatable="yes">Paste</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="action_name">view.paste</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">2</property> + </packing> + </child> + <child> + <object class="GtkButton"> + <property name="label" translatable="yes">Select All</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="action_name">view.select-all</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">4</property> + </packing> + </child> + <child> + <object class="GtkButton"> + <property name="label" translatable="yes">Properties</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="action_name">view.properties</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">4</property> + </packing> + </child> </object> <packing> <property name="expand">True</property> <property name="fill">True</property> - <property name="position">4</property> + <property name="pack_type">end</property> + <property name="position">1</property> </packing> </child> </object> @@ -392,7 +404,7 @@ <property name="expand">True</property> <property name="fill">True</property> <property name="pack_type">end</property> - <property name="position">1</property> + <property name="position">0</property> </packing> </child> <child> |