filechooser: add a compact view
This commit is contained in:
parent
a73f195c16
commit
c43ae2f944
3 changed files with 144 additions and 19 deletions
|
|
@ -257,6 +257,7 @@ typedef enum {
|
|||
#define FALLBACK_ICON_VIEW_ICON_SIZE 48
|
||||
|
||||
#define ICON_VIEW_ITEM_WIDTH 128
|
||||
#define COMPACT_VIEW_ITEM_WIDTH 200
|
||||
#define ICON_VIEW_SCALE_MAX_VISIBLE_OVERSCAN 128
|
||||
|
||||
#define PREVIEW_HBOX_SPACING 12
|
||||
|
|
@ -5236,9 +5237,15 @@ file_icon_view_query_tooltip_cb (GtkWidget *widget,
|
|||
|
||||
if (file && name)
|
||||
{
|
||||
gint width = get_icon_view_item_width (impl);
|
||||
|
||||
/* in the compact view the name has what the icon leaves */
|
||||
if (impl->compact_view)
|
||||
gtk_cell_renderer_get_fixed_size (GTK_CELL_RENDERER (impl->list_name_renderer), &width, NULL);
|
||||
|
||||
if (impl->operation_mode != OPERATION_MODE_BROWSE)
|
||||
text = g_file_get_parse_name (file);
|
||||
else if (file_name_ellipsized (impl, widget, file, name, get_icon_view_item_width (impl)))
|
||||
else if (file_name_ellipsized (impl, widget, file, name, width))
|
||||
text = g_strdup (name);
|
||||
}
|
||||
|
||||
|
|
@ -5359,6 +5366,9 @@ get_icon_view_item_width (GtkFileChooserDefault *impl)
|
|||
gint xpad = 0;
|
||||
gint item_width;
|
||||
|
||||
if (impl->compact_view)
|
||||
return COMPACT_VIEW_ITEM_WIDTH;
|
||||
|
||||
icon_size = impl->icon_view_icon_size;
|
||||
if (icon_size <= 0)
|
||||
icon_size = FALLBACK_ICON_VIEW_ICON_SIZE;
|
||||
|
|
@ -5379,6 +5389,9 @@ get_icon_view_item_width (GtkFileChooserDefault *impl)
|
|||
return MAX (ICON_VIEW_ITEM_WIDTH, item_width);
|
||||
}
|
||||
|
||||
static void name_renderer_set_compact (GtkCellRenderer *cell,
|
||||
gboolean compact);
|
||||
|
||||
static void
|
||||
update_icon_view_cell_layout (GtkFileChooserDefault *impl)
|
||||
{
|
||||
|
|
@ -5394,6 +5407,39 @@ update_icon_view_cell_layout (GtkFileChooserDefault *impl)
|
|||
gtk_icon_view_set_item_width (GTK_ICON_VIEW (impl->browse_files_icon_view),
|
||||
item_width);
|
||||
|
||||
/* The compact view: the small icon of the list beside one line of name */
|
||||
gtk_icon_view_set_orientation (GTK_ICON_VIEW (impl->browse_files_icon_view),
|
||||
impl->compact_view ? GTK_ORIENTATION_HORIZONTAL
|
||||
: GTK_ORIENTATION_VERTICAL);
|
||||
if (impl->list_name_renderer)
|
||||
name_renderer_set_compact (GTK_CELL_RENDERER (impl->list_name_renderer), impl->compact_view);
|
||||
if (impl->list_icon_renderer)
|
||||
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (impl->browse_files_icon_view),
|
||||
impl->list_icon_renderer,
|
||||
"pixbuf", impl->compact_view ? MODEL_COL_LIST_PIXBUF
|
||||
: MODEL_COL_ICON_PIXBUF,
|
||||
NULL);
|
||||
if (impl->compact_view)
|
||||
{
|
||||
gint small = impl->list_view_icon_size > 0 ? impl->list_view_icon_size : FALLBACK_LIST_VIEW_ICON_SIZE;
|
||||
|
||||
gtk_icon_view_set_spacing (GTK_ICON_VIEW (impl->browse_files_icon_view), 4);
|
||||
gtk_icon_view_set_row_spacing (GTK_ICON_VIEW (impl->browse_files_icon_view), 0);
|
||||
if (impl->list_icon_renderer)
|
||||
{
|
||||
gtk_cell_renderer_get_padding (impl->list_icon_renderer, &xpad, &ypad);
|
||||
gtk_cell_renderer_set_fixed_size (impl->list_icon_renderer,
|
||||
small + 2 * xpad, small + 2 * ypad);
|
||||
if (impl->list_name_renderer)
|
||||
gtk_cell_renderer_set_fixed_size (GTK_CELL_RENDERER (impl->list_name_renderer),
|
||||
item_width - small - 2 * xpad - 4, -1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
gtk_icon_view_set_spacing (GTK_ICON_VIEW (impl->browse_files_icon_view), 0);
|
||||
gtk_icon_view_set_row_spacing (GTK_ICON_VIEW (impl->browse_files_icon_view), 6);
|
||||
|
||||
icon_size = impl->icon_view_icon_size;
|
||||
if (icon_size <= 0)
|
||||
icon_size = FALLBACK_ICON_VIEW_ICON_SIZE;
|
||||
|
|
@ -5681,6 +5727,7 @@ typedef struct
|
|||
GtkCellRendererText parent;
|
||||
GtkStyle *metrics_style; /* style line_height was computed for, not a reference */
|
||||
gint line_height;
|
||||
gint lines; /* NAME_RENDERER_LINES, or 1 in the compact view */
|
||||
} NameRenderer;
|
||||
|
||||
typedef GtkCellRendererTextClass NameRendererClass;
|
||||
|
|
@ -5695,12 +5742,14 @@ name_renderer_create_layout (GtkCellRenderer *cell,
|
|||
{
|
||||
PangoLayout *layout;
|
||||
|
||||
gint lines = ((NameRenderer *) cell)->lines;
|
||||
|
||||
layout = gtk_widget_create_pango_layout (widget, GTK_CELL_RENDERER_TEXT (cell)->text);
|
||||
pango_layout_set_width (layout, MAX (width, 1) * PANGO_SCALE);
|
||||
pango_layout_set_wrap (layout, PANGO_WRAP_WORD_CHAR);
|
||||
pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
|
||||
pango_layout_set_alignment (layout, lines > 1 ? PANGO_ALIGN_CENTER : PANGO_ALIGN_LEFT);
|
||||
pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END);
|
||||
pango_layout_set_height (layout, -NAME_RENDERER_LINES);
|
||||
pango_layout_set_height (layout, -lines);
|
||||
|
||||
return layout;
|
||||
}
|
||||
|
|
@ -5739,7 +5788,7 @@ name_renderer_get_size (GtkCellRenderer *cell,
|
|||
}
|
||||
|
||||
if (height)
|
||||
*height = 2 * cell->ypad + NAME_RENDERER_LINES * renderer->line_height;
|
||||
*height = 2 * cell->ypad + renderer->lines * renderer->line_height;
|
||||
if (x_offset)
|
||||
*x_offset = 0;
|
||||
if (y_offset)
|
||||
|
|
@ -5770,12 +5819,24 @@ name_renderer_render (GtkCellRenderer *cell,
|
|||
else
|
||||
state = gtk_widget_get_state (widget) == GTK_STATE_INSENSITIVE ? GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL;
|
||||
|
||||
/* As wide as the item, like the wrap width a text renderer gets here. */
|
||||
/* As wide as the item, like the wrap width a text renderer gets here;
|
||||
* a single line stands in the middle of its height */
|
||||
layout = name_renderer_create_layout (cell, widget, cell_area->width);
|
||||
gtk_paint_layout (widget->style, window, state, TRUE, expose_area, widget,
|
||||
"cellrenderertext",
|
||||
cell_area->x, cell_area->y + cell->ypad,
|
||||
layout);
|
||||
{
|
||||
gint y = cell_area->y + cell->ypad;
|
||||
|
||||
if (((NameRenderer *) cell)->lines == 1)
|
||||
{
|
||||
PangoRectangle logical;
|
||||
|
||||
pango_layout_get_pixel_extents (layout, NULL, &logical);
|
||||
y = cell_area->y + MAX (0, (cell_area->height - logical.height) / 2);
|
||||
}
|
||||
gtk_paint_layout (widget->style, window, state, TRUE, expose_area, widget,
|
||||
"cellrenderertext",
|
||||
cell_area->x, y,
|
||||
layout);
|
||||
}
|
||||
g_object_unref (layout);
|
||||
}
|
||||
|
||||
|
|
@ -5791,6 +5852,14 @@ name_renderer_class_init (NameRendererClass *class)
|
|||
static void
|
||||
name_renderer_init (NameRenderer *renderer)
|
||||
{
|
||||
renderer->lines = NAME_RENDERER_LINES;
|
||||
}
|
||||
|
||||
static void
|
||||
name_renderer_set_compact (GtkCellRenderer *cell,
|
||||
gboolean compact)
|
||||
{
|
||||
((NameRenderer *) cell)->lines = compact ? 1 : NAME_RENDERER_LINES;
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
|
|
@ -6182,7 +6251,7 @@ view_mode_set (GtkFileChooserDefault *impl, ViewMode view_mode)
|
|||
|
||||
impl->view_mode = view_mode;
|
||||
gtk_combo_box_set_active (GTK_COMBO_BOX (impl->view_mode_combo_box),
|
||||
view_mode);
|
||||
view_mode == VIEW_MODE_ICON && impl->compact_view ? 2 : view_mode);
|
||||
|
||||
/* Creating the target view */
|
||||
if (view_mode == VIEW_MODE_ICON)
|
||||
|
|
@ -6225,7 +6294,7 @@ view_mode_set (GtkFileChooserDefault *impl, ViewMode view_mode)
|
|||
impl->list_name_column = NULL;
|
||||
impl->list_mtime_column = NULL;
|
||||
impl->list_size_column = NULL;
|
||||
gtk_widget_show (impl->icon_view_scale_hbox);
|
||||
gtk_widget_set_visible (impl->icon_view_scale_hbox, !impl->compact_view);
|
||||
}
|
||||
else if (view_mode == VIEW_MODE_LIST)
|
||||
{
|
||||
|
|
@ -6251,14 +6320,56 @@ view_mode_set (GtkFileChooserDefault *impl, ViewMode view_mode)
|
|||
browse_files_center_selected_row (impl);
|
||||
}
|
||||
|
||||
/* Callback used when view mode combo box active item is changed */
|
||||
static void thumbnail_requests_cancel_all (GtkFileChooserDefault *impl);
|
||||
static void browse_files_center_selected_row (GtkFileChooserDefault *impl);
|
||||
|
||||
/* The icon view, compact or not: the same view, other sizes */
|
||||
static void
|
||||
compact_view_set (GtkFileChooserDefault *impl,
|
||||
gboolean compact)
|
||||
{
|
||||
if (impl->compact_view == (compact != FALSE))
|
||||
return;
|
||||
|
||||
impl->compact_view = compact != FALSE;
|
||||
if (impl->view_mode != VIEW_MODE_ICON || impl->browse_files_icon_view == NULL)
|
||||
return;
|
||||
|
||||
/* the setting may say so, on the next showing of the dialog */
|
||||
g_signal_handlers_block_by_func (impl->view_mode_combo_box,
|
||||
view_mode_combo_box_changed_cb, impl);
|
||||
gtk_combo_box_set_active (GTK_COMBO_BOX (impl->view_mode_combo_box), compact ? 2 : 1);
|
||||
g_signal_handlers_unblock_by_func (impl->view_mode_combo_box,
|
||||
view_mode_combo_box_changed_cb, impl);
|
||||
|
||||
thumbnail_requests_cancel_all (impl);
|
||||
update_icon_view_cell_layout (impl);
|
||||
gtk_widget_set_visible (impl->icon_view_scale_hbox, !compact);
|
||||
gtk_widget_queue_resize (impl->browse_files_icon_view);
|
||||
browse_files_center_selected_row (impl);
|
||||
}
|
||||
|
||||
/* Callback used when view mode combo box active item is changed: list,
|
||||
* icons, compact */
|
||||
static void
|
||||
view_mode_combo_box_changed_cb (GtkComboBox *combo,
|
||||
GtkFileChooserDefault *impl)
|
||||
{
|
||||
ViewMode target = gtk_combo_box_get_active (combo);
|
||||
gint target = gtk_combo_box_get_active (combo);
|
||||
|
||||
view_mode_set (impl, target);
|
||||
if (target < 0)
|
||||
return;
|
||||
|
||||
if (target == 2)
|
||||
{
|
||||
compact_view_set (impl, TRUE);
|
||||
view_mode_set (impl, VIEW_MODE_ICON);
|
||||
}
|
||||
else
|
||||
{
|
||||
compact_view_set (impl, FALSE);
|
||||
view_mode_set (impl, target);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -6604,7 +6715,7 @@ browse_files_icon_view_scroll_event_cb (GtkWidget *widget,
|
|||
GdkEventScroll *event,
|
||||
GtkFileChooserDefault *impl)
|
||||
{
|
||||
if (impl->view_mode != VIEW_MODE_ICON)
|
||||
if (impl->view_mode != VIEW_MODE_ICON || impl->compact_view)
|
||||
return FALSE;
|
||||
|
||||
if ((event->state & GDK_CONTROL_MASK) == 0)
|
||||
|
|
@ -6694,6 +6805,8 @@ view_mode_combo_box_create (GtkFileChooserDefault *impl)
|
|||
_("List View")); /* VIEW_MODE_LIST */
|
||||
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(impl->view_mode_combo_box),
|
||||
_("Icon View")); /* VIEW_MODE_ICON */
|
||||
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(impl->view_mode_combo_box),
|
||||
_("Compact View")); /* VIEW_MODE_ICON, compact */
|
||||
gtk_combo_box_set_active (GTK_COMBO_BOX(impl->view_mode_combo_box),
|
||||
VIEW_MODE_LIST);
|
||||
|
||||
|
|
@ -8064,7 +8177,9 @@ settings_load (GtkFileChooserDefault *impl)
|
|||
impl);
|
||||
}
|
||||
|
||||
view_mode_set (impl, view_mode);
|
||||
/* compact is the icon view, smaller */
|
||||
compact_view_set (impl, view_mode == VIEW_MODE_COMPACT);
|
||||
view_mode_set (impl, view_mode == VIEW_MODE_COMPACT ? VIEW_MODE_ICON : view_mode);
|
||||
|
||||
gtk_file_chooser_set_show_hidden (GTK_FILE_CHOOSER (impl), show_hidden);
|
||||
|
||||
|
|
@ -8114,7 +8229,9 @@ settings_save (GtkFileChooserDefault *impl)
|
|||
/* All the other state */
|
||||
|
||||
_gtk_file_chooser_settings_set_location_mode (settings, impl->location_mode);
|
||||
_gtk_file_chooser_settings_set_view_mode (settings, impl->view_mode);
|
||||
_gtk_file_chooser_settings_set_view_mode (settings,
|
||||
impl->view_mode == VIEW_MODE_ICON && impl->compact_view
|
||||
? VIEW_MODE_COMPACT : impl->view_mode);
|
||||
_gtk_file_chooser_settings_set_icon_view_scale (settings, impl->icon_view_icon_size);
|
||||
_gtk_file_chooser_settings_set_show_hidden (settings, gtk_file_chooser_get_show_hidden (GTK_FILE_CHOOSER (impl)));
|
||||
_gtk_file_chooser_settings_set_show_size_column (settings, impl->show_size_column);
|
||||
|
|
@ -8910,7 +9027,7 @@ thumbnail_maybe_request (GtkFileChooserDefault *impl,
|
|||
ThumbnailRequest *request;
|
||||
GFile *file;
|
||||
|
||||
if (!impl->show_thumbnails || impl->view_mode != VIEW_MODE_ICON ||
|
||||
if (!impl->show_thumbnails || impl->view_mode != VIEW_MODE_ICON || impl->compact_view ||
|
||||
!g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_ICON) ||
|
||||
g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH) ||
|
||||
g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_THUMBNAILING_FAILED) ||
|
||||
|
|
|
|||
|
|
@ -138,7 +138,9 @@ typedef enum {
|
|||
|
||||
typedef enum {
|
||||
VIEW_MODE_LIST,
|
||||
VIEW_MODE_ICON
|
||||
VIEW_MODE_ICON,
|
||||
/* only in the settings: the icon view, compact */
|
||||
VIEW_MODE_COMPACT
|
||||
} ViewMode;
|
||||
|
||||
typedef enum {
|
||||
|
|
@ -352,6 +354,7 @@ struct _GtkFileChooserDefault
|
|||
guint has_search : 1;
|
||||
guint show_size_column : 1;
|
||||
guint show_thumbnails : 1;
|
||||
guint compact_view : 1; /* the icon view with small icons beside the names */
|
||||
guint create_folders : 1;
|
||||
|
||||
#if 0
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@
|
|||
|
||||
#define MODE_LIST_VIEW "list-view"
|
||||
#define MODE_ICON_VIEW "icon-view"
|
||||
#define MODE_COMPACT_VIEW "compact-view"
|
||||
|
||||
#define EQ(a, b) (g_ascii_strcasecmp ((a), (b)) == 0)
|
||||
|
||||
|
|
@ -175,6 +176,8 @@ ensure_settings_read (GtkFileChooserSettings *settings)
|
|||
settings->view_mode = VIEW_MODE_LIST;
|
||||
else if (EQ (view_mode_str, MODE_ICON_VIEW))
|
||||
settings->view_mode = VIEW_MODE_ICON;
|
||||
else if (EQ (view_mode_str, MODE_COMPACT_VIEW))
|
||||
settings->view_mode = VIEW_MODE_COMPACT;
|
||||
else
|
||||
g_warning ("Unknown view mode '%s' encountered in filechooser settings",
|
||||
view_mode_str);
|
||||
|
|
@ -502,6 +505,8 @@ _gtk_file_chooser_settings_save (GtkFileChooserSettings *settings,
|
|||
view_mode_str = MODE_LIST_VIEW;
|
||||
else if (settings->view_mode == VIEW_MODE_ICON)
|
||||
view_mode_str = MODE_ICON_VIEW;
|
||||
else if (settings->view_mode == VIEW_MODE_COMPACT)
|
||||
view_mode_str = MODE_COMPACT_VIEW;
|
||||
else
|
||||
{
|
||||
g_assert_not_reached ();
|
||||
|
|
|
|||
Loading…
Reference in a new issue