[Xfce4-commits] [xfce/thunar] 01/01: Extra padding for Eject button when scrollbar is visible (Bug #15312)
noreply at xfce.org
noreply at xfce.org
Mon Dec 16 16:36:04 CET 2019
This is an automated email from the git hooks/post-receive script.
a n d r e p u s h e d a c o m m i t t o b r a n c h m a s t e r
in repository xfce/thunar.
commit 78c15641e0aa6f780c6766056a848428ab1d8e60
Author: Andre Miranda <andreldm at xfce.org>
Date: Mon Dec 16 12:34:05 2019 -0300
Extra padding for Eject button when scrollbar is visible (Bug #15312)
It also gets rid of the extra column just for the button and spinner,
so no more wasted space!
---
thunar/thunar-shortcuts-model.c | 8 +++++++
thunar/thunar-shortcuts-model.h | 1 +
thunar/thunar-shortcuts-pane.c | 28 ++++++++++++++++++++++
thunar/thunar-shortcuts-view.c | 51 ++++++++++++++++++++++++++++++-----------
thunar/thunar-shortcuts-view.h | 3 +++
5 files changed, 77 insertions(+), 14 deletions(-)
diff --git a/thunar/thunar-shortcuts-model.c b/thunar/thunar-shortcuts-model.c
index aa38b70..d5e92df 100644
--- a/thunar/thunar-shortcuts-model.c
+++ b/thunar/thunar-shortcuts-model.c
@@ -495,6 +495,9 @@ thunar_shortcuts_model_get_column_type (GtkTreeModel *tree_model,
case THUNAR_SHORTCUTS_MODEL_COLUMN_BUSY_PULSE:
return G_TYPE_UINT;
+
+ case THUNAR_SHORTCUTS_MODEL_COLUMN_HIDDEN:
+ return G_TYPE_BOOLEAN;
}
_thunar_assert_not_reached ();
@@ -711,6 +714,11 @@ thunar_shortcuts_model_get_value (GtkTreeModel *tree_model,
g_value_set_uint (value, shortcut->busy_pulse);
break;
+ case THUNAR_SHORTCUTS_MODEL_COLUMN_HIDDEN:
+ g_value_init (value, G_TYPE_BOOLEAN);
+ g_value_set_boolean (value, FALSE);
+ break;
+
default:
_thunar_assert_not_reached ();
}
diff --git a/thunar/thunar-shortcuts-model.h b/thunar/thunar-shortcuts-model.h
index cb87a1f..677e9b4 100644
--- a/thunar/thunar-shortcuts-model.h
+++ b/thunar/thunar-shortcuts-model.h
@@ -52,6 +52,7 @@ typedef enum
THUNAR_SHORTCUTS_MODEL_COLUMN_GROUP,
THUNAR_SHORTCUTS_MODEL_COLUMN_BUSY,
THUNAR_SHORTCUTS_MODEL_COLUMN_BUSY_PULSE,
+ THUNAR_SHORTCUTS_MODEL_COLUMN_HIDDEN,
THUNAR_SHORTCUTS_MODEL_N_COLUMNS,
} ThunarShortcutsModelColumn;
diff --git a/thunar/thunar-shortcuts-pane.c b/thunar/thunar-shortcuts-pane.c
index f72ec39..2cc26a2 100644
--- a/thunar/thunar-shortcuts-pane.c
+++ b/thunar/thunar-shortcuts-pane.c
@@ -66,6 +66,8 @@ static void thunar_shortcuts_pane_set_ui_manager (ThunarComponen
GtkUIManager *ui_manager);
static void thunar_shortcuts_pane_action_shortcuts_add (GtkAction *action,
ThunarShortcutsPane *shortcuts_pane);
+static void thunar_shortcuts_pane_show_shortcuts_view_padding (GtkWidget *widget);
+static void thunar_shortcuts_pane_hide_shortcuts_view_padding (GtkWidget *widget);
@@ -162,6 +164,8 @@ thunar_shortcuts_pane_side_pane_init (ThunarSidePaneIface *iface)
static void
thunar_shortcuts_pane_init (ThunarShortcutsPane *shortcuts_pane)
{
+ GtkWidget *vscrollbar;
+
/* setup the action group for the shortcuts actions */
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
shortcuts_pane->action_group = gtk_action_group_new ("ThunarShortcutsPane");
@@ -180,6 +184,14 @@ G_GNUC_END_IGNORE_DEPRECATIONS
gtk_container_add (GTK_CONTAINER (shortcuts_pane), shortcuts_pane->view);
gtk_widget_show (shortcuts_pane->view);
+ vscrollbar = gtk_scrolled_window_get_vscrollbar (GTK_SCROLLED_WINDOW (shortcuts_pane));
+ g_signal_connect_swapped (G_OBJECT (vscrollbar), "map",
+ G_CALLBACK (thunar_shortcuts_pane_show_shortcuts_view_padding),
+ shortcuts_pane->view);
+ g_signal_connect_swapped (G_OBJECT (vscrollbar), "unmap",
+ G_CALLBACK (thunar_shortcuts_pane_hide_shortcuts_view_padding),
+ shortcuts_pane->view);
+
/* add widget to css class */
gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (shortcuts_pane)), "shortcuts-pane");
@@ -508,3 +520,19 @@ G_GNUC_END_IGNORE_DEPRECATIONS
thunar_g_file_list_free (lp);
}
}
+
+
+
+static void
+thunar_shortcuts_pane_show_shortcuts_view_padding (GtkWidget *widget)
+{
+ thunar_shortcuts_view_toggle_padding (THUNAR_SHORTCUTS_VIEW (widget), TRUE);
+}
+
+
+
+static void
+thunar_shortcuts_pane_hide_shortcuts_view_padding (GtkWidget *widget)
+{
+ thunar_shortcuts_view_toggle_padding (THUNAR_SHORTCUTS_VIEW (widget), FALSE);
+}
diff --git a/thunar/thunar-shortcuts-view.c b/thunar/thunar-shortcuts-view.c
index d5597b3..5e1695b 100644
--- a/thunar/thunar-shortcuts-view.c
+++ b/thunar/thunar-shortcuts-view.c
@@ -168,6 +168,9 @@ struct _ThunarShortcutsView
ThunarPreferences *preferences;
GtkCellRenderer *icon_renderer;
+ GtkCellRenderer *padding_renderer;
+ GtkTreeViewColumn *column;
+ gboolean padding_enabled;
ThunarxProviderFactory *provider_factory;
@@ -269,7 +272,7 @@ thunar_shortcuts_view_class_init (ThunarShortcutsViewClass *klass)
static void
thunar_shortcuts_view_init (ThunarShortcutsView *view)
{
- GtkTreeViewColumn *column, *column_eject;
+ GtkTreeViewColumn *column;
GtkCellRenderer *renderer;
GtkTreeSelection *selection;
@@ -288,18 +291,14 @@ thunar_shortcuts_view_init (ThunarShortcutsView *view)
g_signal_connect_swapped (G_OBJECT (view->preferences), "notify::shortcuts-icon-emblems", G_CALLBACK (gtk_widget_queue_draw), view);
/* allocate a single column for our renderers */
- column = g_object_new (GTK_TYPE_TREE_VIEW_COLUMN,
+ column = view->column = g_object_new (GTK_TYPE_TREE_VIEW_COLUMN,
"reorderable", FALSE,
"resizable", FALSE,
"expand", TRUE,
- "sizing", GTK_TREE_VIEW_COLUMN_AUTOSIZE,
"spacing", 2,
NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (view), column);
- column_eject = gtk_tree_view_column_new ();
- gtk_tree_view_append_column (GTK_TREE_VIEW (view), column_eject);
-
/* queue a resize on the column whenever the icon size is changed */
view->queue_resize_signal_id = g_signal_connect_swapped (G_OBJECT (view->preferences), "notify::shortcuts-icon-size",
G_CALLBACK (gtk_tree_view_column_queue_resize), column);
@@ -311,7 +310,7 @@ thunar_shortcuts_view_init (ThunarShortcutsView *view)
"ypad", 4,
"ellipsize", PANGO_ELLIPSIZE_END,
NULL);
- gtk_tree_view_column_pack_start (column, renderer, FALSE);
+ gtk_tree_view_column_pack_end (column, renderer, FALSE);
gtk_tree_view_column_set_attributes (column, renderer,
"text", THUNAR_SHORTCUTS_MODEL_COLUMN_NAME,
"visible", THUNAR_SHORTCUTS_MODEL_COLUMN_IS_HEADER,
@@ -354,8 +353,8 @@ thunar_shortcuts_view_init (ThunarShortcutsView *view)
/* spinner to indicate (un)mount/eject delay */
renderer = gtk_cell_renderer_spinner_new ();
- gtk_tree_view_column_pack_start (column_eject, renderer, FALSE);
- gtk_tree_view_column_set_attributes (column_eject, renderer,
+ gtk_tree_view_column_pack_start (column, renderer, FALSE);
+ gtk_tree_view_column_set_attributes (column, renderer,
"visible", THUNAR_SHORTCUTS_MODEL_COLUMN_BUSY,
"active", THUNAR_SHORTCUTS_MODEL_COLUMN_BUSY,
"pulse", THUNAR_SHORTCUTS_MODEL_COLUMN_BUSY_PULSE,
@@ -364,8 +363,17 @@ thunar_shortcuts_view_init (ThunarShortcutsView *view)
/* allocate icon renderer for the eject symbol */
renderer = gtk_cell_renderer_pixbuf_new ();
g_object_set (renderer, "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE, "icon-name", "media-eject", NULL);
- gtk_tree_view_column_pack_start (column_eject, renderer, FALSE);
- gtk_tree_view_column_set_attributes (column_eject, renderer,
+ gtk_tree_view_column_pack_start (column, renderer, FALSE);
+ gtk_tree_view_column_set_attributes (column, renderer,
+ "visible", THUNAR_SHORTCUTS_MODEL_COLUMN_CAN_EJECT,
+ NULL);
+
+ /* padding for the eject symbol so it's not covered by scroll bar */
+ view->padding_enabled = FALSE;
+ view->padding_renderer = gtk_cell_renderer_text_new ();
+ g_object_set (G_OBJECT (view->padding_renderer), "xpad", 6, NULL);
+ gtk_tree_view_column_pack_start (column, view->padding_renderer, FALSE);
+ gtk_tree_view_column_set_attributes (column, view->padding_renderer,
"visible", THUNAR_SHORTCUTS_MODEL_COLUMN_CAN_EJECT,
NULL);
@@ -418,7 +426,7 @@ thunar_shortcuts_view_button_press_event (GtkWidget *widget,
GtkTreeIter iter;
gboolean result;
gboolean can_eject;
- gint icon_width, icon_height, column_width;
+ gint icon_width, column_width;
/* reset the pressed button state */
view->pressed_button = -1;
@@ -453,8 +461,8 @@ thunar_shortcuts_view_button_press_event (GtkWidget *widget,
{
/* check if we clicked the eject button area */
column_width = gtk_tree_view_column_get_width (gtk_tree_view_get_column (GTK_TREE_VIEW (view), 0));
- gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &icon_width, &icon_height);
- if (event->button == 1 && event->x > column_width)
+ gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &icon_width, NULL);
+ if (event->button == 1 && event->x >= column_width - icon_width - (view->padding_enabled ? 16 : 3))
{
/* check if that shortcut actually has an eject button */
model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
@@ -2197,3 +2205,18 @@ thunar_shortcuts_view_select_by_file (ThunarShortcutsView *view,
else
gtk_tree_selection_unselect_all (selection);
}
+
+
+
+void
+thunar_shortcuts_view_toggle_padding (ThunarShortcutsView *view,
+ gboolean enable)
+{
+ gtk_tree_view_column_set_attributes (view->column, view->padding_renderer,
+ "visible", enable ?
+ THUNAR_SHORTCUTS_MODEL_COLUMN_CAN_EJECT :
+ THUNAR_SHORTCUTS_MODEL_COLUMN_HIDDEN,
+ NULL);
+
+ view->padding_enabled = enable;
+}
diff --git a/thunar/thunar-shortcuts-view.h b/thunar/thunar-shortcuts-view.h
index 5f81f0b..3a0a308 100644
--- a/thunar/thunar-shortcuts-view.h
+++ b/thunar/thunar-shortcuts-view.h
@@ -41,6 +41,9 @@ GtkWidget *thunar_shortcuts_view_new (void) G_GNUC_MALLOC;
void thunar_shortcuts_view_select_by_file (ThunarShortcutsView *view,
ThunarFile *file);
+void thunar_shortcuts_view_toggle_padding (ThunarShortcutsView *view,
+ gboolean enable);
+
G_END_DECLS;
#endif /* !__THUNAR_SHORTCUTS_VIEW_H__ */
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list