~jeremywootten/pantheon-files/fix-backspace-in-columnv-view

« back to all changes in this revision

Viewing changes to src/View/Sidebar.vala

  • Committer: jeremy at elementaryos
  • Date: 2016-04-30 11:11:40 UTC
  • mfrom: (2023.1.107 pantheon-files)
  • Revision ID: jeremy@elementaryos.org-20160430111140-ez2siepsfxwj9asi
Merge trunk to r2130

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
        GLib.Icon eject_icon;
55
55
 
56
56
        int eject_button_size = 20;
57
 
        uint n_builtins_before;
 
57
        uint n_builtins_before; /* Number of builtin (immovable) bookmarks before the personal bookmarks */
58
58
        string last_selected_uri;
59
59
        string slot_location;
60
60
 
97
97
        Gtk.MenuItem popupmenu_mount_item;
98
98
        Gtk.MenuItem popupmenu_unmount_item;
99
99
        Gtk.MenuItem popupmenu_eject_item;
100
 
        Gtk.MenuItem popupmenu_rescan_item;
101
 
        Gtk.MenuItem popupmenu_format_item;
102
100
        Gtk.MenuItem popupmenu_empty_trash_item;
103
101
        Gtk.MenuItem popupmenu_drive_property_item;
104
 
        Gtk.MenuItem popupmenu_start_item;
105
 
        Gtk.MenuItem popupmenu_stop_item;
106
102
 
107
103
        /* volume mounting - delayed open process */
108
104
        bool mounting = false;
397
393
                            Column.VOLUME, volume,
398
394
                            Column.MOUNT, mount,
399
395
                            Column.NAME, converted_name,
400
 
                            Column.ICON, (GLib.Icon)pixbuf,
 
396
                            Column.ICON, icon,
401
397
                            Column.INDEX, index,
402
398
                            Column.CAN_EJECT, show_eject_button,
403
399
                            Column.NO_EJECT, !show_eject_button,
897
893
                this.drag_row_ref = null;
898
894
                if (selection_data.get_target () != Gdk.Atom.NONE
899
895
                    && info == TargetType.TEXT_URI_LIST) {
 
896
 
900
897
                    string s = (string)(selection_data.get_data ());
901
898
                    drag_list = EelGFile.list_new_from_string (s);
902
899
                } else {
947
944
                                           Gtk.TreeViewDropPosition drop_pos,
948
945
                                           uint info) {
949
946
            Marlin.PlaceType type;
950
 
            uint position;
 
947
            uint target_position;
951
948
            store.@get (iter,
952
949
                        Column.ROW_TYPE, out type,
953
 
                        Column.INDEX, out position);
 
950
                        Column.INDEX, out target_position);
954
951
 
955
952
            if (type == Marlin.PlaceType.BOOKMARK || type == Marlin.PlaceType.BUILT_IN) {
956
 
                if (type == Marlin.PlaceType.BOOKMARK && drop_pos == Gtk.TreeViewDropPosition.BEFORE)
957
 
                    position--;
958
 
 
959
953
                switch (info) {
960
954
                    case TargetType.TEXT_URI_LIST:
961
 
                        drop_drag_list (position);
 
955
                        drop_drag_list (target_position, drop_pos);
962
956
                        return true;
963
957
                    case TargetType.GTK_TREE_MODEL_ROW:
964
 
                        reorder_bookmarks (position);
 
958
                        reorder_bookmarks (target_position, drop_pos);
965
959
                        return true;
966
960
                    default:
967
961
                        assert_not_reached ();
1033
1027
            return count > 0 && count <= MAX_BOOKMARKS_DROPPED;
1034
1028
        }
1035
1029
 
1036
 
        private void drop_drag_list (uint position) {
 
1030
        private void drop_drag_list (uint target_position, Gtk.TreeViewDropPosition drop_pos) {
1037
1031
            if (drag_list == null) {
1038
1032
                warning ("dropped a null drag list");
1039
1033
                return;
1045
1039
                    uris.prepend (file.get_uri ());
1046
1040
            });
1047
1041
 
1048
 
            if (uris != null)
 
1042
            if (uris != null) {
 
1043
                if (target_position > n_builtins_before) {
 
1044
                    target_position-= n_builtins_before;
 
1045
                } else {
 
1046
                    /* The target is a builtin. Always drop at start of bookmarks */
 
1047
                    target_position = 0;
 
1048
                    drop_pos = Gtk.TreeViewDropPosition.BEFORE; /* We have effectively moved target down */
 
1049
                }
 
1050
                uint position = (drop_pos == Gtk.TreeViewDropPosition.AFTER) ? ++target_position : target_position;
1049
1051
                bookmarks.insert_uris (uris, position);
 
1052
            }
1050
1053
        }
1051
1054
 
1052
1055
        public void add_uri (string uri, string? label = null) {
1115
1118
                                            out Gtk.TreeViewDropPosition drop_position
1116
1119
                                            ) {
1117
1120
            path = null;
1118
 
            int num_rows = store.iter_n_children (null);
 
1121
            drop_position = 0;
1119
1122
            if (!tree_view.get_dest_row_at_pos (x, y, out path, out drop_position)) {
1120
 
                warning ("tree_view.get_dest_row_at_pos failed in sidebar");
 
1123
                return false;
 
1124
            }
 
1125
 
 
1126
            if (path.get_depth () == 1) { /* On category name */
1121
1127
                return false;
1122
1128
            }
1123
1129
 
1124
1130
            int row = (path.get_indices ()) [0];
1125
 
            if (row == 1 || row == 2) {
1126
 
                /* Hardcoded shortcuts can only be dragged into */
 
1131
            Gtk.TreeIter? row_iter = null;
 
1132
            store.get_iter_from_string (out row_iter, row.to_string ());
 
1133
            int last_row = store.iter_n_children (row_iter) - 1;
 
1134
 
 
1135
            if (row > 0) {
 
1136
                /* On a Device or Network bookmark - these can only be dropped into */
1127
1137
                drop_position = Gtk.TreeViewDropPosition.INTO_OR_BEFORE;
1128
 
            } else if (row >= num_rows) {
1129
 
                row = num_rows - 1; /* row not used after this?? */
1130
 
                drop_position = Gtk.TreeViewDropPosition.AFTER;
1131
 
            } else if (drop_position != Gtk.TreeViewDropPosition.BEFORE
1132
 
                    && received_drag_data
1133
 
                    && drag_data_info == TargetType.GTK_TREE_MODEL_ROW)
 
1138
            } else if (row == last_row && drop_position == Gtk.TreeViewDropPosition.AFTER) {
 
1139
                /* Cannot drop after "Trash" */
 
1140
                return false;
 
1141
            } else if (received_drag_data && drag_data_info == TargetType.GTK_TREE_MODEL_ROW) {
1134
1142
                /* bookmark rows are never dragged into other bookmark rows */
1135
 
                drop_position = Gtk.TreeViewDropPosition.AFTER;
1136
 
 
1137
 
            if (path.get_depth () == 1)
1138
 
                return false;
 
1143
                if (drop_position == Gtk.TreeViewDropPosition.INTO_OR_BEFORE) {
 
1144
                    drop_position = Gtk.TreeViewDropPosition.BEFORE;
 
1145
                } else if (drop_position == Gtk.TreeViewDropPosition.INTO_OR_AFTER) {
 
1146
                    drop_position = Gtk.TreeViewDropPosition.AFTER;
 
1147
                }
 
1148
            }
1139
1149
 
1140
1150
            return true;
1141
1151
        }
1200
1210
                        var location = mount.get_default_location ();
1201
1211
                        if (flags == Marlin.OpenFlag.NEW_WINDOW) {
1202
1212
                            var app = Marlin.Application.get ();
1203
 
                            app.create_window (location, window.get_screen ());
 
1213
                            app.create_window (location);
1204
1214
                        } else if (flags == Marlin.OpenFlag.NEW_TAB) {
1205
1215
                            window.add_tab (location, Marlin.ViewMode.CURRENT);
1206
1216
                        } else {
1271
1281
        }
1272
1282
 
1273
1283
        /* Reorder the selected bookmark to the specified position */
1274
 
        private void reorder_bookmarks (uint new_position) {
 
1284
        private void reorder_bookmarks (uint target_position, Gtk.TreeViewDropPosition drop_pos) {
1275
1285
            if (drag_row_ref != null) {
1276
1286
                Gtk.TreeIter iter;
1277
1287
                store.get_iter (out iter, drag_row_ref.get_path ());
1283
1293
                uint old_position;
1284
1294
                store.@get (iter, Column.INDEX, out old_position);
1285
1295
 
1286
 
                if (old_position <= n_builtins_before)
 
1296
                /* Positions are currently indices into the Sidebar TreeView.  We need to take account
 
1297
                 * of builtin entries like "Home" to convert these positions into indices into the personal
 
1298
                 * bookmarklist.
 
1299
                 * As we are using uints, take care not to assign negative numbers */
 
1300
                if (old_position > n_builtins_before) {
 
1301
                    old_position-= n_builtins_before;
 
1302
                } else {
1287
1303
                    old_position = 0;
1288
 
                else
1289
 
                    old_position-= n_builtins_before;
 
1304
                }
1290
1305
 
1291
 
                if (old_position >= bookmarks.length ())
 
1306
                if (target_position > n_builtins_before) {
 
1307
                    target_position-= n_builtins_before;
 
1308
                } else {
 
1309
                    /* The target is a builtin. Always drop at start of bookmarks */
 
1310
                    drop_pos = Gtk.TreeViewDropPosition.BEFORE;
 
1311
                    target_position = 0;
 
1312
                }
 
1313
                /* If the row is dropped on the opposite side of the target than it starts from,
 
1314
                 * then it replaces the target position. Otherwise it takes one more or less
 
1315
                 * than the target position. */
 
1316
                uint new_position = 0;
 
1317
                if (old_position < target_position) {
 
1318
                    new_position = (drop_pos == Gtk.TreeViewDropPosition.BEFORE) ? --target_position : target_position;
 
1319
                } else if (old_position > target_position) {
 
1320
                    new_position = (drop_pos == Gtk.TreeViewDropPosition.AFTER) ? ++target_position : target_position;
 
1321
                } else {
 
1322
                    warning ("Dropping before or after self - ignore");
1292
1323
                    return;
 
1324
                }
1293
1325
 
1294
 
                bookmarks.move_item (old_position, new_position);
 
1326
                bookmarks.move_item (old_position, new_position); /* Bookmarklist will validate the positions. */
1295
1327
            }
1296
1328
        }
1297
1329
 
1302
1334
                return;
1303
1335
 
1304
1336
            popupmenu = new Gtk.Menu ();
1305
 
            popupmenu.attach_to_widget ((Gtk.Widget)this, (Gtk.MenuDetachFunc)popup_menu_detach_cb);
1306
1337
 
1307
1338
            var item = new Gtk.ImageMenuItem.with_mnemonic (_("Open"));
1308
1339
            var image = new Gtk.Image.from_icon_name ("document-open", Gtk.IconSize.MENU);
1390
1421
                                     event);
1391
1422
        }
1392
1423
 
1393
 
        /* Callback used when the file list's popup menu is detached */
1394
 
        public void popup_menu_detach_cb (Gtk.Widget attach_widget, Gtk.Menu menu) {
1395
 
            popupmenu = null;
1396
 
            popupmenu_remove_item = null;
1397
 
            popupmenu_rename_item = null;
1398
 
            popupmenu_separator_item1 = null;
1399
 
            popupmenu_separator_item2 = null;
1400
 
            popupmenu_mount_item = null;
1401
 
            popupmenu_unmount_item = null;
1402
 
            popupmenu_eject_item = null;
1403
 
            popupmenu_rescan_item = null;
1404
 
            popupmenu_format_item = null;
1405
 
            popupmenu_start_item = null;
1406
 
            popupmenu_stop_item = null;
1407
 
            popupmenu_empty_trash_item = null;
1408
 
            popupmenu_drive_property_item = null;
1409
 
        }
1410
 
 
1411
1424
        /* Callback used for the GtkWidget::popup-menu signal of the shortcuts list */
1412
1425
        private bool popup_menu_cb (Gtk.Widget widget) {
1413
1426
            popup_menu (null);