gtkfilechooser: add compact view mode
This commit is contained in:
parent
ff8d4f899d
commit
cf8531cd0d
2 changed files with 98 additions and 31 deletions
|
|
@ -257,8 +257,15 @@ typedef enum {
|
|||
#define FALLBACK_ICON_VIEW_ICON_SIZE 48
|
||||
|
||||
#define ICON_VIEW_ITEM_WIDTH 128
|
||||
#define COMPACT_VIEW_ITEM_WIDTH 180
|
||||
#define COMPACT_VIEW_SPACING 4
|
||||
#define COMPACT_VIEW_ROW_SPACING 0
|
||||
#define COMPACT_VIEW_COLUMN_SPACING 12
|
||||
#define COMPACT_VIEW_MARGIN 2
|
||||
#define ICON_VIEW_SCALE_MAX_VISIBLE_OVERSCAN 128
|
||||
|
||||
#define VIEW_MODE_USES_ICON_VIEW(mode) ((mode) == VIEW_MODE_ICON || (mode) == VIEW_MODE_COMPACT)
|
||||
|
||||
#define PREVIEW_HBOX_SPACING 12
|
||||
#define NUM_LINES 45
|
||||
#define NUM_CHARS 60
|
||||
|
|
@ -2369,7 +2376,7 @@ new_folder_button_clicked (GtkButton *button,
|
|||
TRUE);
|
||||
gtk_tree_path_free (path);
|
||||
}
|
||||
else if (impl->view_mode == VIEW_MODE_ICON)
|
||||
else if (VIEW_MODE_USES_ICON_VIEW (impl->view_mode))
|
||||
{
|
||||
add_idle_to_edit_icon_view (impl, path);
|
||||
}
|
||||
|
|
@ -4139,7 +4146,7 @@ sort_ascending_toggled_cb (GtkCheckMenuItem *item,
|
|||
|
||||
// The sort column is explicitly set to mtime for the recent model
|
||||
// This prevents it from switching when changing sort order
|
||||
if (impl->view_mode == VIEW_MODE_ICON && impl->current_model == GTK_TREE_MODEL (impl->recent_model))
|
||||
if (VIEW_MODE_USES_ICON_VIEW (impl->view_mode) && impl->current_model == GTK_TREE_MODEL (impl->recent_model))
|
||||
gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (impl->current_model), &impl->sort_column, NULL);
|
||||
|
||||
impl->sort_order = GTK_SORT_ASCENDING;
|
||||
|
|
@ -4168,7 +4175,7 @@ sort_descending_toggled_cb (GtkCheckMenuItem *item,
|
|||
|
||||
// The sort column is explicitly set to mtime for the recent model
|
||||
// This prevents it from switching when changing sort order
|
||||
if (impl->view_mode == VIEW_MODE_ICON && impl->current_model == GTK_TREE_MODEL (impl->recent_model))
|
||||
if (VIEW_MODE_USES_ICON_VIEW (impl->view_mode) && impl->current_model == GTK_TREE_MODEL (impl->recent_model))
|
||||
gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (impl->current_model), &impl->sort_column, NULL);
|
||||
|
||||
impl->sort_order = GTK_SORT_DESCENDING;
|
||||
|
|
@ -4395,7 +4402,7 @@ file_list_build_popup_menu (GtkFileChooserDefault *impl)
|
|||
gtk_widget_show (item);
|
||||
gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item);
|
||||
}
|
||||
else if (impl->view_mode == VIEW_MODE_ICON)
|
||||
else if (VIEW_MODE_USES_ICON_VIEW (impl->view_mode))
|
||||
{
|
||||
GtkWidget *menu, *subitem;
|
||||
|
||||
|
|
@ -4490,7 +4497,7 @@ file_list_update_popup_menu (GtkFileChooserDefault *impl)
|
|||
g_signal_handlers_unblock_by_func (impl->browse_files_popup_menu_size_column_item,
|
||||
G_CALLBACK (show_size_column_toggled_cb), impl);
|
||||
}
|
||||
else if (impl->view_mode == VIEW_MODE_ICON)
|
||||
else if (VIEW_MODE_USES_ICON_VIEW (impl->view_mode))
|
||||
{
|
||||
gint column = impl->sort_column;
|
||||
GtkSortType order = impl->sort_order;
|
||||
|
|
@ -4768,7 +4775,7 @@ set_icon_cell_renderer_fixed_size (GtkFileChooserDefault *impl,
|
|||
int icon_size;
|
||||
gint xpad, ypad;
|
||||
|
||||
if (view_mode == VIEW_MODE_LIST)
|
||||
if (view_mode == VIEW_MODE_LIST || view_mode == VIEW_MODE_COMPACT)
|
||||
{
|
||||
icon_size = impl->list_view_icon_size;
|
||||
|
||||
|
|
@ -4828,8 +4835,58 @@ update_icon_view_cell_layout (GtkFileChooserDefault *impl)
|
|||
if (!impl->browse_files_icon_view)
|
||||
return;
|
||||
|
||||
if (impl->view_mode == VIEW_MODE_COMPACT)
|
||||
{
|
||||
GtkIconView *icon_view;
|
||||
gint icon_cell_width;
|
||||
gint text_width;
|
||||
|
||||
icon_view = GTK_ICON_VIEW (impl->browse_files_icon_view);
|
||||
item_width = COMPACT_VIEW_ITEM_WIDTH;
|
||||
|
||||
gtk_icon_view_set_item_orientation (icon_view, GTK_ORIENTATION_HORIZONTAL);
|
||||
gtk_icon_view_set_item_width (icon_view, item_width);
|
||||
gtk_icon_view_set_spacing (icon_view, COMPACT_VIEW_SPACING);
|
||||
gtk_icon_view_set_row_spacing (icon_view, COMPACT_VIEW_ROW_SPACING);
|
||||
gtk_icon_view_set_column_spacing (icon_view, COMPACT_VIEW_COLUMN_SPACING);
|
||||
gtk_icon_view_set_margin (icon_view, COMPACT_VIEW_MARGIN);
|
||||
|
||||
icon_size = impl->list_view_icon_size;
|
||||
if (icon_size <= 0)
|
||||
icon_size = FALLBACK_LIST_VIEW_ICON_SIZE;
|
||||
|
||||
icon_cell_width = icon_size;
|
||||
|
||||
if (impl->list_icon_renderer)
|
||||
{
|
||||
gtk_cell_renderer_get_padding (impl->list_icon_renderer, &xpad, &ypad);
|
||||
icon_cell_width = xpad * 2 + icon_size;
|
||||
gtk_cell_renderer_set_fixed_size (impl->list_icon_renderer,
|
||||
icon_cell_width,
|
||||
ypad * 2 + icon_size);
|
||||
}
|
||||
|
||||
if (impl->list_name_renderer)
|
||||
{
|
||||
text_width = MAX (1, item_width - icon_cell_width - COMPACT_VIEW_SPACING);
|
||||
|
||||
g_object_set (G_OBJECT (impl->list_name_renderer),
|
||||
"alignment", PANGO_ALIGN_LEFT,
|
||||
"ellipsize", PANGO_ELLIPSIZE_END,
|
||||
"wrap-width", -1,
|
||||
"yalign", 0.5f,
|
||||
NULL);
|
||||
gtk_cell_renderer_set_fixed_size (GTK_CELL_RENDERER (impl->list_name_renderer),
|
||||
text_width, -1);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
item_width = get_icon_view_item_width (impl);
|
||||
|
||||
gtk_icon_view_set_item_orientation (GTK_ICON_VIEW (impl->browse_files_icon_view),
|
||||
GTK_ORIENTATION_VERTICAL);
|
||||
gtk_icon_view_set_item_width (GTK_ICON_VIEW (impl->browse_files_icon_view),
|
||||
item_width);
|
||||
|
||||
|
|
@ -4855,7 +4912,11 @@ update_icon_view_cell_layout (GtkFileChooserDefault *impl)
|
|||
if (impl->list_name_renderer)
|
||||
{
|
||||
g_object_set (G_OBJECT (impl->list_name_renderer),
|
||||
"alignment", PANGO_ALIGN_CENTER,
|
||||
"ellipsize", PANGO_ELLIPSIZE_END,
|
||||
"wrap-mode", PANGO_WRAP_WORD_CHAR,
|
||||
"wrap-width", item_width,
|
||||
"yalign", 0.0f,
|
||||
NULL);
|
||||
gtk_cell_renderer_set_fixed_size (GTK_CELL_RENDERER (impl->list_name_renderer),
|
||||
item_width, -1);
|
||||
|
|
@ -5030,7 +5091,8 @@ create_browse_files_icon_view (GtkFileChooserDefault *impl)
|
|||
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (impl->browse_files_icon_view),
|
||||
impl->list_icon_renderer, TRUE);
|
||||
gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (impl->browse_files_icon_view),
|
||||
impl->list_icon_renderer, "pixbuf", MODEL_COL_ICON_PIXBUF);
|
||||
impl->list_icon_renderer, "pixbuf",
|
||||
impl->view_mode == VIEW_MODE_COMPACT ? MODEL_COL_LIST_PIXBUF : MODEL_COL_ICON_PIXBUF);
|
||||
|
||||
impl->list_name_renderer = gtk_cell_renderer_text_new ();
|
||||
g_object_set (G_OBJECT (impl->list_name_renderer),
|
||||
|
|
@ -5358,28 +5420,28 @@ location_toggle_popup_handler (GtkFileChooserDefault *impl)
|
|||
static void
|
||||
view_mode_set (GtkFileChooserDefault *impl, ViewMode view_mode)
|
||||
{
|
||||
GtkWidget *old_view = NULL;
|
||||
GtkWidget *old_view;
|
||||
ViewMode old_view_mode = impl->view_mode;
|
||||
|
||||
if (old_view_mode == view_mode)
|
||||
return;
|
||||
|
||||
old_view = impl->browse_files_current_view;
|
||||
|
||||
impl->view_mode = view_mode;
|
||||
gtk_combo_box_set_active (GTK_COMBO_BOX (impl->view_mode_combo_box),
|
||||
view_mode);
|
||||
|
||||
/* Creating the target view */
|
||||
if (view_mode == VIEW_MODE_ICON)
|
||||
if (VIEW_MODE_USES_ICON_VIEW (view_mode))
|
||||
{
|
||||
create_browse_files_icon_view (impl);
|
||||
impl->browse_files_current_view = impl->browse_files_icon_view;
|
||||
old_view = impl->browse_files_tree_view;
|
||||
}
|
||||
else if (view_mode == VIEW_MODE_LIST)
|
||||
{
|
||||
create_browse_files_tree_view (impl);
|
||||
impl->browse_files_current_view = impl->browse_files_tree_view;
|
||||
old_view = impl->browse_files_icon_view;
|
||||
}
|
||||
else
|
||||
g_assert_not_reached ();
|
||||
|
|
@ -5389,29 +5451,31 @@ view_mode_set (GtkFileChooserDefault *impl, ViewMode view_mode)
|
|||
current_view_set_select_multiple (impl, impl->select_multiple);
|
||||
copy_old_selection_to_current_view (impl, old_view_mode);
|
||||
|
||||
/* Destroy the old view */
|
||||
if (view_mode == VIEW_MODE_ICON)
|
||||
gtk_widget_show (impl->icon_view_scale_hbox);
|
||||
else
|
||||
gtk_widget_hide (impl->icon_view_scale_hbox);
|
||||
|
||||
if (old_view_mode == VIEW_MODE_LIST)
|
||||
{
|
||||
impl->browse_files_tree_view = NULL;
|
||||
impl->list_name_column = NULL;
|
||||
impl->list_mtime_column = NULL;
|
||||
impl->list_size_column = NULL;
|
||||
gtk_widget_show (impl->icon_view_scale_hbox);
|
||||
}
|
||||
else if (view_mode == VIEW_MODE_LIST)
|
||||
else if (VIEW_MODE_USES_ICON_VIEW (old_view_mode) &&
|
||||
!VIEW_MODE_USES_ICON_VIEW (view_mode))
|
||||
{
|
||||
impl->browse_files_icon_view = NULL;
|
||||
impl->list_icon_renderer = NULL;
|
||||
impl->list_name_renderer = NULL;
|
||||
gtk_widget_hide (impl->icon_view_scale_hbox);
|
||||
}
|
||||
else
|
||||
g_assert_not_reached ();
|
||||
|
||||
if (impl->browse_files_popup_menu)
|
||||
gtk_menu_detach (GTK_MENU (impl->browse_files_popup_menu));
|
||||
|
||||
gtk_widget_destroy (old_view);
|
||||
if (old_view)
|
||||
gtk_widget_destroy (old_view);
|
||||
|
||||
/* Display the new view */
|
||||
gtk_container_add (GTK_CONTAINER (impl->browse_files_scrolled_window),
|
||||
|
|
@ -5864,6 +5928,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_COMPACT */
|
||||
gtk_combo_box_set_active (GTK_COMBO_BOX(impl->view_mode_combo_box),
|
||||
VIEW_MODE_LIST);
|
||||
|
||||
|
|
@ -7609,7 +7675,7 @@ center_selected_row_foreach_cb (GtkTreeModel *model,
|
|||
|
||||
if (closure->impl->view_mode == VIEW_MODE_LIST)
|
||||
gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (closure->impl->browse_files_tree_view), path, NULL, TRUE, 0.5, 0.0);
|
||||
else if (closure->impl->view_mode == VIEW_MODE_ICON)
|
||||
else if (VIEW_MODE_USES_ICON_VIEW (closure->impl->view_mode))
|
||||
gtk_icon_view_scroll_to_path (GTK_ICON_VIEW (closure->impl->browse_files_icon_view), path, TRUE, 0.5, 0.0);
|
||||
else
|
||||
g_assert_not_reached ();
|
||||
|
|
@ -8003,7 +8069,7 @@ get_visible_range (GtkTreePath **start, GtkTreePath **end,
|
|||
{
|
||||
if (impl->view_mode == VIEW_MODE_LIST)
|
||||
return gtk_tree_view_get_visible_range (GTK_TREE_VIEW (impl->browse_files_tree_view), start, end);
|
||||
if (impl->view_mode == VIEW_MODE_ICON)
|
||||
if (VIEW_MODE_USES_ICON_VIEW (impl->view_mode))
|
||||
return gtk_icon_view_get_visible_range (GTK_ICON_VIEW (impl->browse_files_icon_view), start, end);
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
|
@ -9564,7 +9630,7 @@ get_selected_file_info_from_file_list (GtkFileChooserDefault *impl,
|
|||
}
|
||||
*had_selection = TRUE;
|
||||
}
|
||||
else if (impl->view_mode == VIEW_MODE_ICON)
|
||||
else if (VIEW_MODE_USES_ICON_VIEW (impl->view_mode))
|
||||
{
|
||||
if (!get_selected_tree_iter_from_icon_view (impl, &iter))
|
||||
{
|
||||
|
|
@ -10971,7 +11037,7 @@ check_preview_change (GtkFileChooserDefault *impl)
|
|||
|
||||
if (impl->view_mode == VIEW_MODE_LIST)
|
||||
gtk_tree_view_get_cursor (GTK_TREE_VIEW (impl->browse_files_tree_view), &cursor_path, NULL);
|
||||
else if (impl->view_mode == VIEW_MODE_ICON)
|
||||
else if (VIEW_MODE_USES_ICON_VIEW (impl->view_mode))
|
||||
cursor_path = NULL;
|
||||
else
|
||||
g_assert_not_reached ();
|
||||
|
|
@ -11822,7 +11888,7 @@ selection_selected_foreach (GtkFileChooserDefault *impl,
|
|||
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
|
||||
gtk_tree_selection_selected_foreach (selection, func, data);
|
||||
}
|
||||
else if (view == VIEW_MODE_ICON)
|
||||
else if (VIEW_MODE_USES_ICON_VIEW (view))
|
||||
icon_view_selection_selected_foreach (impl, func, data);
|
||||
else
|
||||
g_assert_not_reached ();
|
||||
|
|
@ -11845,7 +11911,7 @@ current_selection_count_selected_rows (GtkFileChooserDefault *impl)
|
|||
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
|
||||
return gtk_tree_selection_count_selected_rows (selection);
|
||||
}
|
||||
if (impl->view_mode == VIEW_MODE_ICON)
|
||||
if (VIEW_MODE_USES_ICON_VIEW (impl->view_mode))
|
||||
{
|
||||
GList *icon_selection;
|
||||
icon_selection = gtk_icon_view_get_selected_items (GTK_ICON_VIEW (impl->browse_files_icon_view));
|
||||
|
|
@ -11869,7 +11935,7 @@ selection_select_iter (GtkFileChooserDefault *impl,
|
|||
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
|
||||
gtk_tree_selection_select_iter (selection, iter);
|
||||
}
|
||||
else if (target == VIEW_MODE_ICON)
|
||||
else if (VIEW_MODE_USES_ICON_VIEW (target))
|
||||
{
|
||||
GtkTreePath *path;
|
||||
path = gtk_tree_model_get_path (impl->current_model, iter);
|
||||
|
|
@ -11925,7 +11991,7 @@ current_selection_unselect_iter (GtkFileChooserDefault *impl,
|
|||
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
|
||||
gtk_tree_selection_unselect_iter (selection, iter);
|
||||
}
|
||||
else if (impl->view_mode == VIEW_MODE_ICON)
|
||||
else if (VIEW_MODE_USES_ICON_VIEW (impl->view_mode))
|
||||
{
|
||||
GtkTreePath *path;
|
||||
path = gtk_tree_model_get_path (impl->current_model, iter);
|
||||
|
|
@ -11945,7 +12011,7 @@ current_selection_unselect_all (GtkFileChooserDefault *impl)
|
|||
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_files_tree_view));
|
||||
gtk_tree_selection_unselect_all (selection);
|
||||
}
|
||||
else if (impl->view_mode == VIEW_MODE_ICON)
|
||||
else if (VIEW_MODE_USES_ICON_VIEW (impl->view_mode))
|
||||
gtk_icon_view_unselect_all (GTK_ICON_VIEW (impl->browse_files_icon_view));
|
||||
else
|
||||
g_assert_not_reached ();
|
||||
|
|
@ -11960,7 +12026,7 @@ current_view_set_file_model (GtkFileChooserDefault *impl, GtkTreeModel *model)
|
|||
|
||||
if (impl->view_mode == VIEW_MODE_LIST)
|
||||
view = impl->browse_files_tree_view;
|
||||
else if (impl->view_mode == VIEW_MODE_ICON)
|
||||
else if (VIEW_MODE_USES_ICON_VIEW (impl->view_mode))
|
||||
view = impl->browse_files_icon_view;
|
||||
else
|
||||
g_assert_not_reached ();
|
||||
|
|
@ -11984,7 +12050,7 @@ current_view_set_cursor (GtkFileChooserDefault *impl, GtkTreePath *path)
|
|||
{
|
||||
if (impl->view_mode == VIEW_MODE_LIST)
|
||||
gtk_tree_view_set_cursor (GTK_TREE_VIEW (impl->browse_files_tree_view), path, NULL, FALSE);
|
||||
else if (impl->view_mode == VIEW_MODE_ICON)
|
||||
else if (VIEW_MODE_USES_ICON_VIEW (impl->view_mode))
|
||||
gtk_icon_view_set_cursor (GTK_ICON_VIEW (impl->browse_files_icon_view), path, NULL, FALSE);
|
||||
else
|
||||
g_assert_not_reached ();
|
||||
|
|
@ -12003,7 +12069,7 @@ current_view_set_select_multiple (GtkFileChooserDefault *impl, gboolean select_m
|
|||
gtk_tree_selection_set_mode (selection, mode);
|
||||
gtk_tree_view_set_rubber_banding (GTK_TREE_VIEW (impl->browse_files_tree_view), select_multiple);
|
||||
}
|
||||
else if (impl->view_mode == VIEW_MODE_ICON)
|
||||
else if (VIEW_MODE_USES_ICON_VIEW (impl->view_mode))
|
||||
gtk_icon_view_set_selection_mode (GTK_ICON_VIEW (impl->browse_files_icon_view), mode);
|
||||
else
|
||||
g_assert_not_reached ();
|
||||
|
|
|
|||
|
|
@ -139,7 +139,8 @@ typedef enum {
|
|||
|
||||
typedef enum {
|
||||
VIEW_MODE_LIST,
|
||||
VIEW_MODE_ICON
|
||||
VIEW_MODE_ICON,
|
||||
VIEW_MODE_COMPACT
|
||||
} ViewMode;
|
||||
|
||||
typedef enum {
|
||||
|
|
|
|||
Loading…
Reference in a new issue