[Xfce4-commits] <thunar:jannis/new-shortcuts-pane> Add the ThunarShortcutRow::icon-size property. Update when necessary.
Jannis Pohlmann
noreply at xfce.org
Fri Jul 15 21:10:07 CEST 2011
Updating branch refs/heads/jannis/new-shortcuts-pane
to 510aea8714e7edfcb8bd151f1081aa9a7bcec54a (commit)
from 4bc4dbf70466c80996a88bbb0cb236a6860905e2 (commit)
commit 510aea8714e7edfcb8bd151f1081aa9a7bcec54a
Author: Jannis Pohlmann <jannis at xfce.org>
Date: Mon Jun 6 18:32:40 2011 +0200
Add the ThunarShortcutRow::icon-size property. Update when necessary.
thunar/thunar-shortcut-row.c | 190 +++++++++++++++++++++++++++++++++---------
thunar/thunar-shortcut-row.h | 4 +
2 files changed, 156 insertions(+), 38 deletions(-)
diff --git a/thunar/thunar-shortcut-row.c b/thunar/thunar-shortcut-row.c
index da3d312..f0ec1bf 100644
--- a/thunar/thunar-shortcut-row.c
+++ b/thunar/thunar-shortcut-row.c
@@ -27,6 +27,8 @@
#include <exo/exo.h>
+#include <thunar/thunar-enum-types.h>
+#include <thunar/thunar-preferences.h>
#include <thunar/thunar-private.h>
#include <thunar/thunar-shortcut-row.h>
@@ -41,33 +43,37 @@ enum
PROP_EJECT_ICON,
PROP_FILE,
PROP_VOLUME,
+ PROP_ICON_SIZE,
};
-static void thunar_shortcut_row_constructed (GObject *object);
-static void thunar_shortcut_row_dispose (GObject *object);
-static void thunar_shortcut_row_finalize (GObject *object);
-static void thunar_shortcut_row_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-static void thunar_shortcut_row_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-static gboolean thunar_shortcut_row_expose_event (GtkWidget *widget,
- GdkEventExpose *event);
-static gboolean thunar_shortcut_row_focus (GtkWidget *widget,
- GtkDirectionType direction);
-static gboolean thunar_shortcut_row_focus_in_event (GtkWidget *widget,
- GdkEventFocus *event);
-static gboolean thunar_shortcut_row_focus_out_event (GtkWidget *widget,
- GdkEventFocus *event);
-static void thunar_shortcut_row_icon_changed (ThunarShortcutRow *row);
-static void thunar_shortcut_row_label_changed (ThunarShortcutRow *row);
-static void thunar_shortcut_row_file_changed (ThunarShortcutRow *row);
-static void thunar_shortcut_row_volume_changed (ThunarShortcutRow *row);
+static void thunar_shortcut_row_constructed (GObject *object);
+static void thunar_shortcut_row_dispose (GObject *object);
+static void thunar_shortcut_row_finalize (GObject *object);
+static void thunar_shortcut_row_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
+static void thunar_shortcut_row_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static gboolean thunar_shortcut_row_button_press_event (GtkWidget *widget,
+ GdkEventButton *event);
+static gboolean thunar_shortcut_row_expose_event (GtkWidget *widget,
+ GdkEventExpose *event);
+static gboolean thunar_shortcut_row_focus (GtkWidget *widget,
+ GtkDirectionType direction);
+static gboolean thunar_shortcut_row_focus_in_event (GtkWidget *widget,
+ GdkEventFocus *event);
+static gboolean thunar_shortcut_row_focus_out_event (GtkWidget *widget,
+ GdkEventFocus *event);
+static void thunar_shortcut_row_icon_changed (ThunarShortcutRow *row);
+static void thunar_shortcut_row_label_changed (ThunarShortcutRow *row);
+static void thunar_shortcut_row_file_changed (ThunarShortcutRow *row);
+static void thunar_shortcut_row_volume_changed (ThunarShortcutRow *row);
+static void thunar_shortcut_row_icon_size_changed (ThunarShortcutRow *row);
@@ -78,19 +84,24 @@ struct _ThunarShortcutRowClass
struct _ThunarShortcutRow
{
- GtkEventBox __parent__;
-
- gchar *label;
-
- GIcon *icon;
- GIcon *eject_icon;
-
- GFile *file;
- GVolume *volume;
-
- GtkWidget *label_widget;
- GtkWidget *icon_image;
- GtkWidget *action_button;
+ GtkEventBox __parent__;
+
+ ThunarPreferences *preferences;
+
+ gchar *label;
+
+ GIcon *icon;
+ GIcon *eject_icon;
+
+ GFile *file;
+ GVolume *volume;
+
+ GtkWidget *label_widget;
+ GtkWidget *icon_image;
+ GtkWidget *action_button;
+ GtkWidget *action_image;
+
+ ThunarIconSize icon_size;
};
@@ -116,6 +127,7 @@ thunar_shortcut_row_class_init (ThunarShortcutRowClass *klass)
gobject_class->set_property = thunar_shortcut_row_set_property;
gtkwidget_class = GTK_WIDGET_CLASS (klass);
+ gtkwidget_class->button_press_event = thunar_shortcut_row_button_press_event;
gtkwidget_class->expose_event = thunar_shortcut_row_expose_event;
gtkwidget_class->focus = thunar_shortcut_row_focus;
gtkwidget_class->focus_in_event = thunar_shortcut_row_focus_in_event;
@@ -155,6 +167,14 @@ thunar_shortcut_row_class_init (ThunarShortcutRowClass *klass)
"volume",
G_TYPE_VOLUME,
EXO_PARAM_READWRITE));
+
+ g_object_class_install_property (gobject_class, PROP_ICON_SIZE,
+ g_param_spec_enum ("icon-size",
+ "icon-size",
+ "icon-size",
+ THUNAR_TYPE_ICON_SIZE,
+ THUNAR_ICON_SIZE_SMALLER,
+ EXO_PARAM_READWRITE));
}
@@ -198,6 +218,16 @@ thunar_shortcut_row_init (ThunarShortcutRow *row)
gtk_button_set_relief (GTK_BUTTON (row->action_button), GTK_RELIEF_NONE);
gtk_box_pack_start (GTK_BOX (box), row->action_button, FALSE, TRUE, 0);
gtk_widget_hide (row->action_button);
+
+ /* create the action button image */
+ row->action_image = gtk_image_new ();
+ gtk_button_set_image (GTK_BUTTON (row->action_button), row->action_image);
+ gtk_widget_show (row->action_image);
+
+ /* update the icon size whenever necessary */
+ row->preferences = thunar_preferences_get ();
+ exo_binding_new (G_OBJECT (row->preferences), "shortcuts-icon-size",
+ G_OBJECT (row), "icon-size");
}
@@ -236,6 +266,9 @@ thunar_shortcut_row_finalize (GObject *object)
if (row->volume != NULL)
g_object_unref (row->volume);
+ /* release the preferences */
+ g_object_unref (row->preferences);
+
(*G_OBJECT_CLASS (thunar_shortcut_row_parent_class)->finalize) (object);
}
@@ -271,6 +304,10 @@ thunar_shortcut_row_get_property (GObject *object,
g_value_set_object (value, row->volume);
break;
+ case PROP_ICON_SIZE:
+ g_value_set_enum (value, row->icon_size);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -309,6 +346,10 @@ thunar_shortcut_row_set_property (GObject *object,
thunar_shortcut_row_set_volume (row, g_value_get_object (value));
break;
+ case PROP_ICON_SIZE:
+ thunar_shortcut_row_set_icon_size (row, g_value_get_enum (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -318,6 +359,49 @@ thunar_shortcut_row_set_property (GObject *object,
static gboolean
+thunar_shortcut_row_button_press_event (GtkWidget *widget,
+ GdkEventButton *event)
+{
+ GtkStateType state;
+
+ _thunar_return_val_if_fail (THUNAR_IS_SHORTCUT_ROW (widget), FALSE);
+
+ /* distinguish between left, right and middle-click */
+ if (event->button == 1)
+ {
+ /* determine the widget's state */
+ state = gtk_widget_get_state (widget);
+
+ if (state == GTK_STATE_SELECTED)
+ {
+ if ((event->state & GDK_CONTROL_MASK) != 0)
+ gtk_widget_set_state (widget, GTK_STATE_NORMAL);
+ }
+ else
+ {
+ gtk_widget_set_state (widget, GTK_STATE_SELECTED);
+ gtk_widget_grab_focus (widget);
+ }
+ }
+ else if (event->button == 3)
+ {
+ /* TODO emit a popup-menu signal or something similar here */
+ g_debug ("right click");
+ return FALSE;
+ }
+ else if (event->button == 2)
+ {
+ /* TODO we don't handle middle-click events yet */
+ g_debug ("middle click");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+
+
+static gboolean
thunar_shortcut_row_expose_event (GtkWidget *widget,
GdkEventExpose *event)
{
@@ -443,7 +527,7 @@ thunar_shortcut_row_icon_changed (ThunarShortcutRow *row)
_thunar_return_if_fail (THUNAR_IS_SHORTCUT_ROW (row));
/* update the icon image */
- gtk_image_set_from_gicon (GTK_IMAGE (row->icon_image), row->icon, GTK_ICON_SIZE_MENU);
+ gtk_image_set_from_gicon (GTK_IMAGE (row->icon_image), row->icon, GTK_ICON_SIZE_DIALOG);
gtk_widget_set_visible (row->icon_image, row->icon != NULL);
}
@@ -507,7 +591,7 @@ thunar_shortcut_row_volume_changed (ThunarShortcutRow *row)
/* update the icon image */
icon = g_volume_get_icon (row->volume);
- gtk_image_set_from_gicon (GTK_IMAGE (row->icon_image), icon, GTK_ICON_SIZE_MENU);
+ gtk_image_set_from_gicon (GTK_IMAGE (row->icon_image), icon, GTK_ICON_SIZE_DIALOG);
gtk_widget_set_visible (row->icon_image, icon != NULL);
g_object_unref (icon);
@@ -521,6 +605,17 @@ thunar_shortcut_row_volume_changed (ThunarShortcutRow *row)
+static void
+thunar_shortcut_row_icon_size_changed (ThunarShortcutRow *row)
+{
+ _thunar_return_if_fail (THUNAR_IS_SHORTCUT_ROW (row));
+
+ gtk_image_set_pixel_size (GTK_IMAGE (row->icon_image), row->icon_size);
+ gtk_image_set_pixel_size (GTK_IMAGE (row->action_image), row->icon_size);
+}
+
+
+
GtkWidget *
thunar_shortcut_row_new (GIcon *icon,
const gchar *label,
@@ -652,3 +747,22 @@ thunar_shortcut_row_set_volume (ThunarShortcutRow *row,
g_object_notify (G_OBJECT (row), "volume");
}
+
+
+
+void
+thunar_shortcut_row_set_icon_size (ThunarShortcutRow *row,
+ ThunarIconSize icon_size)
+{
+ _thunar_return_if_fail (THUNAR_IS_SHORTCUT_ROW (row));
+ _thunar_return_if_fail (icon_size >= THUNAR_ICON_SIZE_SMALLEST && icon_size <= THUNAR_ICON_SIZE_LARGEST);
+
+ if (row->icon_size == icon_size)
+ return;
+
+ row->icon_size = icon_size;
+
+ thunar_shortcut_row_icon_size_changed (row);
+
+ g_object_notify (G_OBJECT (row), "icon-size");
+}
diff --git a/thunar/thunar-shortcut-row.h b/thunar/thunar-shortcut-row.h
index b02110f..3acbccf 100644
--- a/thunar/thunar-shortcut-row.h
+++ b/thunar/thunar-shortcut-row.h
@@ -23,6 +23,8 @@
#include <glib-object.h>
+#include <thunar/thunar-enum-types.h>
+
G_BEGIN_DECLS
#define THUNAR_TYPE_SHORTCUT_ROW (thunar_shortcut_row_get_type ())
@@ -50,6 +52,8 @@ void thunar_shortcut_row_set_file (ThunarShortcutRow *row,
GFile *file);
void thunar_shortcut_row_set_volume (ThunarShortcutRow *row,
GVolume *volume);
+void thunar_shortcut_row_set_icon_size (ThunarShortcutRow *row,
+ ThunarIconSize icon_size);
G_END_DECLS
More information about the Xfce4-commits
mailing list