Skip to content

Commit

Permalink
BookmarkRow: No drop target when not mounted.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremypw committed Jul 29, 2024
1 parent 58ec381 commit 696234f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 23 deletions.
56 changes: 36 additions & 20 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.get_display_name ();
return target_file != null ? target_file.get_display_name () : "";
}
}
}
Expand Down Expand Up @@ -108,8 +108,9 @@ public class Sidebar.BookmarkRow : Gtk.ListBoxRow, SidebarItemInterface {
}

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

/* 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 @@ -188,9 +189,27 @@ public class Sidebar.BookmarkRow : Gtk.ListBoxRow, SidebarItemInterface {
notify["custom-name"].connect (() => {
label.label = display_name;
});
}

set_up_drag ();
set_up_drop ();
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
);
}
}

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

/* Set up as a drag destination. */
/* Set machinery to handle drag (only actually used if mounted). */
private void set_up_drop () {
var drop_revealer_child = new Gtk.Separator (Gtk.Orientation.HORIZONTAL) {
margin_top = 12,
Expand All @@ -391,13 +410,6 @@ 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 @@ -483,16 +495,20 @@ 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) {
Files.DndHandler.file_accepts_drop (
if (!reveal && drop_file_list != null && uri != "") {
var current_actions = Files.DndHandler.file_accepts_drop (
target_file,
drop_file_list,
ctx.get_selected_action (),
ctx.get_actions (),
out current_suggested_action
);

if (current_suggested_action != Gdk.DragAction.DEFAULT) {
if (current_actions == DEFAULT) {
current_suggested_action = DEFAULT;
}

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

if (reveal_drop_target (reveal)) {
current_suggested_action = Gdk.DragAction.LINK; //A bookmark is effectively a link
if (current_suggested_action != DEFAULT && reveal_drop_target (reveal)) {
current_suggested_action = 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 = Gdk.DragAction.DEFAULT; //Do not allowing dropping duplicate URI
current_suggested_action = DEFAULT; //Do not allowing dropping duplicate URI
reveal = false;
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/View/Sidebar/VolumeRow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ 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 @@ -112,16 +113,19 @@ 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 ();
target_file = Files.File.get (mount.get_root ());
target_file.ensure_query_info ();
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 ();
update_visibilities ();
}
}

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

0 comments on commit 696234f

Please sign in to comment.