Skip to content

Commit

Permalink
Revert "BookmarkRow: No drop target when not mounted."
Browse files Browse the repository at this point in the history
This reverts commit 696234f.
  • Loading branch information
jeremypw committed Sep 1, 2024
1 parent fb2d7ed commit bb1b747
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 43 deletions.
56 changes: 20 additions & 36 deletions src/View/Sidebar/BookmarkRow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class Sidebar.BookmarkRow : Gtk.ListBoxRow, SidebarItemInterface {
private Gtk.EventControllerKey key_controller;
private Gtk.GestureMultiPress button_controller;

protected Files.File? target_file;
protected Files.File target_file;
protected Gtk.Grid content_grid;
protected Gtk.Grid icon_label_grid;
protected Gtk.Stack label_stack;
Expand All @@ -72,7 +72,7 @@ public class Sidebar.BookmarkRow : Gtk.ListBoxRow, SidebarItemInterface {
if (custom_name.strip () != "") {
return custom_name;
} else {
return target_file != null ? target_file.get_display_name () : "";
return target_file.get_display_name ();
}
}
}
Expand Down Expand Up @@ -108,9 +108,8 @@ public class Sidebar.BookmarkRow : Gtk.ListBoxRow, SidebarItemInterface {
}

construct {
set_up_target_file_and_drop_actions ();
set_up_drag ();
set_up_drop ();
target_file = Files.File.get_by_uri (uri);
target_file.ensure_query_info ();

/* If put margin on the row then drag and drop does not work when over the margin so we put
* the margin on the content grid */
Expand Down Expand Up @@ -189,27 +188,9 @@ public class Sidebar.BookmarkRow : Gtk.ListBoxRow, SidebarItemInterface {
notify["custom-name"].connect (() => {
label.label = display_name;
});
}

protected void set_up_target_file_and_drop_actions () {
if (uri != "") {
target_file = Files.File.get_by_uri (uri);
target_file.ensure_query_info ();
Gtk.drag_dest_set (
this,
Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
dest_targets,
Gdk.DragAction.MOVE | Gdk.DragAction.COPY | Gdk.DragAction.LINK | Gdk.DragAction.ASK
);
} else {
target_file = null;
Gtk.drag_dest_set (
this,
Gtk.DestDefaults.MOTION,
null,
Gdk.DragAction.DEFAULT
);
}
set_up_drag ();
set_up_drop ();
}

protected override void update_plugin_data (Files.SidebarPluginItem item) {
Expand Down Expand Up @@ -395,7 +376,7 @@ public class Sidebar.BookmarkRow : Gtk.ListBoxRow, SidebarItemInterface {
});
}

/* Set machinery to handle drag (only actually used if mounted). */
/* Set up as a drag destination. */
private void set_up_drop () {
var drop_revealer_child = new Gtk.Separator (Gtk.Orientation.HORIZONTAL) {
margin_top = 12,
Expand All @@ -410,6 +391,13 @@ public class Sidebar.BookmarkRow : Gtk.ListBoxRow, SidebarItemInterface {

content_grid.attach (drop_revealer, 0, 1);

Gtk.drag_dest_set (
this,
Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
dest_targets,
Gdk.DragAction.MOVE | Gdk.DragAction.COPY | Gdk.DragAction.LINK | Gdk.DragAction.ASK
);

drag_data_received.connect ((ctx, x, y, sel_data, info, time) => {
drop_text = null;
// Extract the require text from info and convert to file list if appropriate
Expand Down Expand Up @@ -495,20 +483,16 @@ public class Sidebar.BookmarkRow : Gtk.ListBoxRow, SidebarItemInterface {
y > row_height - 1;

// When dropping onto a row, determine what actions are possible
if (!reveal && drop_file_list != null && uri != "") {
var current_actions = Files.DndHandler.file_accepts_drop (
if (!reveal && drop_file_list != null) {
Files.DndHandler.file_accepts_drop (
target_file,
drop_file_list,
ctx.get_selected_action (),
ctx.get_actions (),
out current_suggested_action
);

if (current_actions == DEFAULT) {
current_suggested_action = DEFAULT;
}

if (current_suggested_action != DEFAULT) {
if (current_suggested_action != Gdk.DragAction.DEFAULT) {
highlight (true);
}
} else {
Expand All @@ -520,12 +504,12 @@ public class Sidebar.BookmarkRow : Gtk.ListBoxRow, SidebarItemInterface {
break;
}

if (current_suggested_action != DEFAULT && reveal_drop_target (reveal)) {
current_suggested_action = LINK; //A bookmark is effectively a link
if (reveal_drop_target (reveal)) {
current_suggested_action = Gdk.DragAction.LINK; //A bookmark is effectively a link
if (target.name () == "text/uri-list" && drop_text != null &&
list.has_uri (drop_text.strip ())) { //Need to remove trailing newline

current_suggested_action = DEFAULT; //Do not allowing dropping duplicate URI
current_suggested_action = Gdk.DragAction.DEFAULT; //Do not allowing dropping duplicate URI
reveal = false;
}
}
Expand Down
10 changes: 3 additions & 7 deletions src/View/Sidebar/VolumeRow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public class Sidebar.VolumeRow : Sidebar.AbstractMountableRow, SidebarItemInterf
if (drive_name != null && drive_name != "") {
custom_name = _("%s (%s)").printf (custom_name, drive_name);
}

}

construct {
Expand Down Expand Up @@ -113,19 +112,16 @@ public class Sidebar.VolumeRow : Sidebar.AbstractMountableRow, SidebarItemInterf
protected override void on_mount_added (Mount added_mount) {
if (added_mount == volume.get_mount ()) {
mount = volume.get_mount ();
uri = mount.get_root ().get_uri ();
set_up_target_file_and_drop_actions ();
// target_file = Files.File.get (mount.get_root ());
// target_file.ensure_query_info ();
target_file = Files.File.get (mount.get_root ());
target_file.ensure_query_info ();
update_visibilities ();
}
}

protected override void on_mount_removed (Mount removed_mount) {
if (volume.get_mount () == null) {
mount = null;
uri = "";
set_up_target_file_and_drop_actions ();
target_file = Files.File.get_by_uri ("");
update_visibilities ();
}
}
Expand Down

0 comments on commit bb1b747

Please sign in to comment.