Commit 679688892cb9ea63606c41998ba4ed22642f36a2

Authored by Monsta
1 parent 85433f2e
Exists in upstream-1.8

places-sidebar: enable both creating bookmarks and dropping files

- drag a folder to the top or bottom of the bookmark list to add
a new bookmark. a horizontal line will be shown and the mouse
pointer will have a '+' at its right side.
- if there are no bookmarks (and that section isn't shown), drag
a folder over the computer section's heading. this will add a new
bookmark and make the bookmarks list visible.
- drag a file or a folder over some existing bookmark to move it
into the bookmarked folder. the mouse pointer will have an arrow
at its right side.
- if you want to copy a file or a folder there instead, perform
the same operation but hold ctrl during that. the mouse pointer
will have a '+' at its right side. no horizontal line will be
shown, so you will be able to distinguish this operation from
adding a new bookmark. :)

adapted from https://github.com/mate-desktop/caja/commit/3fdb9a14077b14263e8acfc93addc8fbcf568ca1
with adjustments for 1.8 (different order of sidebar sections)
Showing 1 changed file with 24 additions and 14 deletions   Show diff stats
src/caja-places-sidebar.c
... ... @@ -1130,11 +1130,13 @@ compute_drop_position (GtkTreeView *tree_view,
1130 1130 PLACES_SIDEBAR_COLUMN_SECTION_TYPE, &section_type,
1131 1131 -1);
1132 1132  
1133   - if (place_type == PLACES_HEADING && section_type != SECTION_BOOKMARKS) {
1134   - /* never drop on headings, but special case the bookmarks heading,
1135   - * so we can drop bookmarks in between it and the first item.
  1133 + if (place_type == PLACES_HEADING &&
  1134 + section_type != SECTION_BOOKMARKS &&
  1135 + section_type != SECTION_COMPUTER) {
  1136 + /* never drop on headings, but the bookmarks or computer heading
  1137 + * is a special case, so we can create new bookmarks by dragging
  1138 + * at the beginning or end of the bookmark list.
1136 1139 */
1137   -
1138 1140 gtk_tree_path_free (*path);
1139 1141 *path = NULL;
1140 1142  
... ... @@ -1145,17 +1147,19 @@ compute_drop_position (GtkTreeView *tree_view,
1145 1147 sidebar->drag_data_received &&
1146 1148 sidebar->drag_data_info == GTK_TREE_MODEL_ROW) {
1147 1149 /* don't allow dropping bookmarks into non-bookmark areas */
1148   -
1149   - gtk_tree_path_free (*path);
1150   - *path = NULL;
  1150 + gtk_tree_path_free (*path);
  1151 + *path = NULL;
1151 1152  
1152 1153 return FALSE;
1153 1154 }
1154 1155  
1155   - if (section_type == SECTION_BOOKMARKS) {
  1156 + /* drag to top or bottom of bookmark list to add a bookmark */
  1157 + if (place_type == PLACES_HEADING && section_type == SECTION_BOOKMARKS) {
1156 1158 *pos = GTK_TREE_VIEW_DROP_AFTER;
  1159 + } else if (place_type == PLACES_HEADING && section_type == SECTION_COMPUTER) {
  1160 + *pos = GTK_TREE_VIEW_DROP_BEFORE;
1157 1161 } else {
1158   - /* non-bookmark shortcuts can only be dragged into */
  1162 + /* or else you want to drag items INTO the existing bookmarks */
1159 1163 *pos = GTK_TREE_VIEW_DROP_INTO_OR_BEFORE;
1160 1164 }
1161 1165  
... ... @@ -1266,10 +1270,10 @@ drag_motion_callback (GtkTreeView *tree_view,
1266 1270 }
1267 1271  
1268 1272 if (pos == GTK_TREE_VIEW_DROP_BEFORE ||
1269   - pos == GTK_TREE_VIEW_DROP_AFTER )
  1273 + pos == GTK_TREE_VIEW_DROP_AFTER )
1270 1274 {
1271 1275 if (sidebar->drag_data_received &&
1272   - sidebar->drag_data_info == GTK_TREE_MODEL_ROW)
  1276 + sidebar->drag_data_info == GTK_TREE_MODEL_ROW)
1273 1277 {
1274 1278 action = GDK_ACTION_MOVE;
1275 1279 }
... ... @@ -1527,7 +1531,7 @@ drag_data_received_callback (GtkWidget *widget,
1527 1531 success = FALSE;
1528 1532  
1529 1533 if (tree_pos == GTK_TREE_VIEW_DROP_BEFORE ||
1530   - tree_pos == GTK_TREE_VIEW_DROP_AFTER)
  1534 + tree_pos == GTK_TREE_VIEW_DROP_AFTER)
1531 1535 {
1532 1536 model = gtk_tree_view_get_model (tree_view);
1533 1537  
... ... @@ -1538,14 +1542,20 @@ drag_data_received_callback (GtkWidget *widget,
1538 1542  
1539 1543 gtk_tree_model_get (model, &iter,
1540 1544 PLACES_SIDEBAR_COLUMN_SECTION_TYPE, &section_type,
1541   - PLACES_SIDEBAR_COLUMN_ROW_TYPE, &place_type,
  1545 + PLACES_SIDEBAR_COLUMN_ROW_TYPE, &place_type,
1542 1546 PLACES_SIDEBAR_COLUMN_INDEX, &position,
1543 1547 -1);
1544 1548  
1545   - if (section_type != SECTION_BOOKMARKS) {
  1549 + if (section_type != SECTION_BOOKMARKS &&
  1550 + !(section_type == SECTION_COMPUTER && place_type == PLACES_HEADING)) {
1546 1551 goto out;
1547 1552 }
1548 1553  
  1554 + if (section_type == SECTION_COMPUTER && place_type == PLACES_HEADING &&
  1555 + tree_pos == GTK_TREE_VIEW_DROP_BEFORE) {
  1556 + position = caja_bookmark_list_length (sidebar->bookmarks);
  1557 + }
  1558 +
1549 1559 if (tree_pos == GTK_TREE_VIEW_DROP_AFTER && place_type != PLACES_HEADING) {
1550 1560 /* heading already has position 0 */
1551 1561 position++;
... ...