142
141
gpointer callback_data);
143
static void apply_columns_settings (NautilusListView *list_view,
145
char **visible_columns);
146
static char **get_visible_columns (NautilusListView *list_view);
147
static char **get_default_visible_columns (NautilusListView *list_view);
148
static char **get_column_order (NautilusListView *list_view);
149
static char **get_default_column_order (NautilusListView *list_view);
145
152
G_DEFINE_TYPE (NautilusListView, nautilus_list_view, NAUTILUS_TYPE_VIEW);
154
static const char * default_search_visible_columns[] = {
155
"name", "size", "type", "where", NULL
158
static const char * default_search_columns_order[] = {
159
"name", "size", "type", "where", NULL
147
162
static const char * default_trash_visible_columns[] = {
148
163
"name", "size", "type", "trashed_on", "trash_orig_path", NULL
1452
column_header_menu_toggled (GtkCheckMenuItem *menu_item,
1453
NautilusListView *list_view)
1456
char **visible_columns;
1457
char **column_order;
1463
file = nautilus_view_get_directory_as_file (NAUTILUS_VIEW (list_view));
1464
visible_columns = get_visible_columns (list_view);
1465
column_order = get_column_order (list_view);
1466
column = g_object_get_data (G_OBJECT (menu_item), "column-name");
1468
for (i = 0; visible_columns[i] != NULL; ++i) {
1469
list = g_list_prepend (list, visible_columns[i]);
1472
if (gtk_check_menu_item_get_active (menu_item)) {
1473
list = g_list_prepend (list, g_strdup (column));
1475
l = g_list_find_custom (list, column, (GCompareFunc) g_strcmp0);
1476
list = g_list_delete_link (list, l);
1479
list = g_list_reverse (list);
1480
nautilus_file_set_metadata_list (file,
1481
NAUTILUS_METADATA_KEY_LIST_VIEW_VISIBLE_COLUMNS,
1484
g_free (visible_columns);
1486
visible_columns = g_new0 (char *, g_list_length (list) + 1);
1487
for (i = 0, l = list; l != NULL; ++i, l = l->next) {
1488
visible_columns[i] = l->data;
1491
/* set view values ourselves, as new metadata could not have been
1494
apply_columns_settings (list_view, column_order, visible_columns);
1497
g_strfreev (column_order);
1498
g_strfreev (visible_columns);
1502
column_header_menu_use_default (GtkMenuItem *menu_item,
1503
NautilusListView *list_view)
1506
char **default_columns;
1507
char **default_order;
1509
file = nautilus_view_get_directory_as_file (NAUTILUS_VIEW (list_view));
1511
nautilus_file_set_metadata_list (file, NAUTILUS_METADATA_KEY_LIST_VIEW_COLUMN_ORDER, NULL);
1512
nautilus_file_set_metadata_list (file, NAUTILUS_METADATA_KEY_LIST_VIEW_VISIBLE_COLUMNS, NULL);
1514
default_columns = get_default_visible_columns (list_view);
1515
default_order = get_default_column_order (list_view);
1517
/* set view values ourselves, as new metadata could not have been
1520
apply_columns_settings (list_view, default_order, default_columns);
1522
g_strfreev (default_columns);
1523
g_strfreev (default_order);
1527
column_header_clicked (GtkWidget *column_button,
1528
GdkEventButton *event,
1529
NautilusListView *list_view)
1532
char **visible_columns;
1533
char **column_order;
1535
GHashTable *visible_columns_hash;
1539
GtkWidget *menu_item;
1541
if (event->button != GDK_BUTTON_SECONDARY) {
1545
file = nautilus_view_get_directory_as_file (NAUTILUS_VIEW (list_view));
1547
visible_columns = get_visible_columns (list_view);
1548
column_order = get_column_order (list_view);
1550
all_columns = nautilus_get_columns_for_file (file);
1551
all_columns = nautilus_sort_columns (all_columns, column_order);
1553
/* hash table to lookup if a given column should be visible */
1554
visible_columns_hash = g_hash_table_new_full (g_str_hash,
1556
(GDestroyNotify) g_free,
1557
(GDestroyNotify) g_free);
1558
/* always show name column */
1559
g_hash_table_insert (visible_columns_hash, g_strdup ("name"), g_strdup ("name"));
1560
if (visible_columns != NULL) {
1561
for (i = 0; visible_columns[i] != NULL; ++i) {
1562
g_hash_table_insert (visible_columns_hash,
1563
g_ascii_strdown (visible_columns[i], -1),
1564
g_ascii_strdown (visible_columns[i], -1));
1568
menu = gtk_menu_new ();
1570
for (l = all_columns; l != NULL; l = l->next) {
1575
g_object_get (G_OBJECT (l->data),
1579
lowercase = g_ascii_strdown (name, -1);
1581
menu_item = gtk_check_menu_item_new_with_label (label);
1582
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
1584
g_object_set_data_full (G_OBJECT (menu_item),
1585
"column-name", name, g_free);
1587
/* name is always visible */
1588
if (strcmp (lowercase, "name") == 0) {
1589
gtk_widget_set_sensitive (menu_item, FALSE);
1592
if (g_hash_table_lookup (visible_columns_hash, lowercase) != NULL) {
1593
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item),
1597
g_signal_connect (menu_item,
1599
G_CALLBACK (column_header_menu_toggled),
1606
menu_item = gtk_separator_menu_item_new ();
1607
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
1609
menu_item = gtk_menu_item_new_with_label (_("Use Default"));
1610
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
1612
g_signal_connect (menu_item,
1614
G_CALLBACK (column_header_menu_use_default),
1617
gtk_widget_show_all (menu);
1618
gtk_menu_popup_for_device (GTK_MENU (menu),
1619
gdk_event_get_device ((GdkEvent *) event),
1620
NULL, NULL, NULL, NULL, NULL,
1621
event->button, event->time);
1623
g_hash_table_destroy (visible_columns_hash);
1624
nautilus_column_list_free (all_columns);
1625
g_strfreev (column_order);
1626
g_strfreev (visible_columns);
1439
1632
apply_columns_settings (NautilusListView *list_view,
1440
1633
char **column_order,
1441
1634
char **visible_columns)
1497
1690
view_columns = g_list_reverse (view_columns);
1499
/* remove columns that are not present in the configuration */
1692
/* hide columns that are not present in the configuration */
1500
1693
old_view_columns = gtk_tree_view_get_columns (list_view->details->tree_view);
1501
1694
for (l = old_view_columns; l != NULL; l = l->next) {
1502
1695
if (g_list_find (view_columns, l->data) == NULL) {
1503
gtk_tree_view_remove_column (list_view->details->tree_view, l->data);
1696
gtk_tree_view_column_set_visible (l->data, FALSE);
1506
1699
g_list_free (old_view_columns);
1508
/* append new columns from the configuration */
1509
old_view_columns = gtk_tree_view_get_columns (list_view->details->tree_view);
1701
/* show new columns from the configuration */
1510
1702
for (l = view_columns; l != NULL; l = l->next) {
1511
if (g_list_find (old_view_columns, l->data) == NULL) {
1512
gtk_tree_view_append_column (list_view->details->tree_view, l->data);
1703
gtk_tree_view_column_set_visible (l->data, TRUE);
1515
g_list_free (old_view_columns);
1517
1706
/* place columns in the correct order */
1518
1707
prev_view_column = NULL;
1753
location_cell_data_func (GtkTreeViewColumn *column,
1754
GtkCellRenderer *renderer,
1755
GtkTreeModel *model,
1757
NautilusListView *view,
1758
gboolean show_trash_orig)
1760
NautilusDirectory *directory;
1761
GFile *home_location;
1763
GFile *dir_location;
1764
GFile *base_location;
1765
gchar *where = NULL;
1767
directory = nautilus_view_get_model (NAUTILUS_VIEW (view));
1769
home_location = g_file_new_for_path (g_get_home_dir ());
1771
gtk_tree_model_get (model, iter,
1772
NAUTILUS_LIST_MODEL_FILE_COLUMN, &file,
1775
/* The file might be NULL if we just toggled an expander
1776
* and we're still loading the subdirectory.
1782
if (show_trash_orig && nautilus_file_is_in_trash (file)) {
1783
NautilusFile *orig_file;
1785
orig_file = nautilus_file_get_trash_original_file (file);
1787
if (orig_file != NULL) {
1788
nautilus_file_unref (file);
1793
if (!nautilus_file_is_in_recent (file)) {
1794
dir_location = nautilus_file_get_parent_location (file);
1796
GFile *activation_location;
1798
activation_location = nautilus_file_get_activation_location (file);
1799
dir_location = g_file_get_parent (activation_location);
1801
g_object_unref (activation_location);
1804
if (!NAUTILUS_IS_SEARCH_DIRECTORY (directory)) {
1805
base_location = g_object_ref (home_location);
1807
NautilusQuery *query;
1811
query = nautilus_search_directory_get_query (NAUTILUS_SEARCH_DIRECTORY (directory));
1812
base_uri = nautilus_query_get_location (query);
1813
base = nautilus_file_get_by_uri (base_uri);
1815
if (!nautilus_file_is_in_recent (base)) {
1816
base_location = nautilus_file_get_location (base);
1818
base_location = g_object_ref (home_location);
1821
nautilus_file_unref (base);
1823
g_object_unref (query);
1826
if (g_file_equal (home_location, dir_location)) {
1827
where = g_strdup (_("Home"));
1828
} else if (g_file_equal (base_location, dir_location)) {
1829
/* Only occurs when search result is
1830
* a direct child of the base location
1832
where = g_strdup ("");
1833
} else if (g_file_has_prefix (dir_location, base_location)) {
1834
gchar *relative_path;
1836
relative_path = g_file_get_relative_path (base_location,
1838
where = g_filename_display_name (relative_path);
1840
g_free (relative_path);
1843
if (where != NULL) {
1844
g_object_set (G_OBJECT (renderer),
1851
g_object_unref (base_location);
1852
g_object_unref (dir_location);
1853
nautilus_file_unref (file);
1854
g_object_unref (home_location);
1859
where_cell_data_func (GtkTreeViewColumn *column,
1860
GtkCellRenderer *renderer,
1861
GtkTreeModel *model,
1863
NautilusListView *view)
1865
location_cell_data_func (column, renderer, model, iter, view, FALSE);
1869
trash_orig_path_cell_data_func (GtkTreeViewColumn *column,
1870
GtkCellRenderer *renderer,
1871
GtkTreeModel *model,
1873
NautilusListView *view)
1875
location_cell_data_func (column, renderer, model, iter, view, TRUE);
1564
1880
set_up_pixbuf_size (NautilusListView *view)
1757
2089
"text", column_num,
1759
g_object_ref_sink (column);
2091
gtk_tree_view_append_column (view->details->tree_view, column);
1760
2092
gtk_tree_view_column_set_sort_column_id (column, column_num);
1761
2093
g_hash_table_insert (view->details->columns,
1762
2094
g_strdup (name),
2097
g_signal_connect (gtk_tree_view_column_get_button (column),
2098
"button-press-event",
2099
G_CALLBACK (column_header_clicked),
1765
2102
gtk_tree_view_column_set_resizable (column, TRUE);
1766
gtk_tree_view_column_set_visible (column, TRUE);
1767
2103
gtk_tree_view_column_set_sort_order (column, sort_order);
2105
if (!strcmp (name, "where")) {
2106
gtk_tree_view_column_set_cell_data_func (column, cell,
2107
(GtkTreeCellDataFunc) where_cell_data_func,
2109
} else if (!strcmp (name, "trash_orig_path")) {
2110
gtk_tree_view_column_set_cell_data_func (column, cell,
2111
(GtkTreeCellDataFunc) trash_orig_path_cell_data_func,
1770
2116
g_free (label);
1828
2192
g_ptr_array_add (res, NULL);
1830
ret = (char **) g_ptr_array_free (res, FALSE);
1831
2194
g_list_free (visible_columns);
1838
return nautilus_file_is_in_trash (file) ?
1839
g_strdupv ((gchar **) default_trash_visible_columns) :
1840
g_settings_get_strv (nautilus_list_view_preferences,
1841
NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_VISIBLE_COLUMNS);
2196
return (char **) g_ptr_array_free (res, FALSE);
2199
return get_default_visible_columns (list_view);
2203
get_default_column_order (NautilusListView *list_view)
2206
NautilusDirectory *directory;
2208
file = nautilus_view_get_directory_as_file (NAUTILUS_VIEW (list_view));
2210
if (nautilus_file_is_in_trash (file)) {
2211
return g_strdupv ((gchar **) default_trash_columns_order);
2214
directory = nautilus_view_get_model (NAUTILUS_VIEW (list_view));
2215
if (NAUTILUS_IS_SEARCH_DIRECTORY (directory)) {
2216
return g_strdupv ((gchar **) default_search_columns_order);
2219
return g_settings_get_strv (nautilus_list_view_preferences,
2220
NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_COLUMN_ORDER);
3286
3658
G_CALLBACK (list_view_notify_clipboard_info), list_view);
3289
static NautilusView *
3290
nautilus_list_view_create (NautilusWindowSlot *slot)
3662
nautilus_list_view_new (NautilusWindowSlot *slot)
3292
NautilusListView *view;
3294
view = g_object_new (NAUTILUS_TYPE_LIST_VIEW,
3664
return g_object_new (NAUTILUS_TYPE_LIST_VIEW,
3295
3665
"window-slot", slot,
3297
return NAUTILUS_VIEW (view);
3301
nautilus_list_view_supports_uri (const char *uri,
3302
GFileType file_type,
3303
const char *mime_type)
3305
if (file_type == G_FILE_TYPE_DIRECTORY) {
3308
if (strcmp (mime_type, NAUTILUS_SAVED_SEARCH_MIMETYPE) == 0){
3311
if (g_str_has_prefix (uri, "trash:")) {
3314
if (g_str_has_prefix (uri, EEL_SEARCH_URI)) {
3321
static NautilusViewInfo nautilus_list_view = {
3322
NAUTILUS_LIST_VIEW_ID,
3323
/* translators: this is used in the view selection dropdown
3324
* of navigation windows and in the preferences dialog */
3326
/* translators: this is used in the view menu */
3328
N_("The list view encountered an error."),
3329
N_("The list view encountered an error while starting up."),
3330
N_("Display this location with the list view."),
3331
nautilus_list_view_create,
3332
nautilus_list_view_supports_uri
3336
nautilus_list_view_register (void)
3338
nautilus_list_view.view_combo_label = _(nautilus_list_view.view_combo_label);
3339
nautilus_list_view.view_menu_label_with_mnemonic = _(nautilus_list_view.view_menu_label_with_mnemonic);
3340
nautilus_list_view.error_label = _(nautilus_list_view.error_label);
3341
nautilus_list_view.startup_error_label = _(nautilus_list_view.startup_error_label);
3342
nautilus_list_view.display_location_label = _(nautilus_list_view.display_location_label);
3344
nautilus_view_factory_register (&nautilus_list_view);