Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions libcore/DndHandler.vala
Original file line number Diff line number Diff line change
Expand Up @@ -355,36 +355,44 @@ namespace Files {
Gdk.DragAction possible_actions,
out Gdk.DragAction suggested_action_return) {

warning ("checking file accepts drop");
var actions = possible_actions;
var suggested_action = selected_action;
var target_location = dest.get_target_location ();
suggested_action_return = Gdk.DragAction.PRIVATE;

if (drop_file_list == null || drop_file_list.data == null) {
warning ("drop file list empty - return DEFAULT");
return Gdk.DragAction.DEFAULT;
}

if (dest.is_folder ()) {
if (!dest.is_writable ()) {
warning ("Folder not writable - return DEFAULT");
actions = Gdk.DragAction.DEFAULT;
} else {
warning ("target is writable folder - check valid actions");
/* Modify actions and suggested_action according to source files */
actions &= valid_actions_for_file_list (target_location,
drop_file_list,
ref suggested_action);
}
} else if (dest.is_executable ()) {
warning ("target is executable file - actions |= COPY|MOVE|LINK|PRIVATE");
actions |= (Gdk.DragAction.COPY |
Gdk.DragAction.MOVE |
Gdk.DragAction.LINK |
Gdk.DragAction.PRIVATE);
} else {
warning ("target is not a valid DnD target - not folder and not executable");
actions = Gdk.DragAction.DEFAULT;
}

if (actions == Gdk.DragAction.DEFAULT) { // No point asking if no other valid actions
warning ("Cannot accept drop - return now");
return Gdk.DragAction.DEFAULT;
} else if (FileUtils.location_is_in_trash (target_location)) { // cannot copy or link to trash
warning ("target is trash - cannot copy or link");
actions &= ~(Gdk.DragAction.COPY | Gdk.DragAction.LINK);
}

Expand All @@ -400,6 +408,7 @@ namespace Files {
suggested_action_return = Gdk.DragAction.MOVE;
}

warning ("actions - %s, suggested - %s", actions.to_string (), suggested_action_return.to_string ());
return actions;
}

Expand All @@ -408,6 +417,7 @@ namespace Files {
GLib.List<GLib.File> drop_file_list,
ref Gdk.DragAction suggested_action) {

warning ("checking valid actions for file list");
var valid_actions = Gdk.DragAction.DEFAULT |
Gdk.DragAction.COPY |
Gdk.DragAction.MOVE |
Expand All @@ -427,24 +437,28 @@ namespace Files {
from_trash = true;

if (FileUtils.location_is_in_trash (target_location)) {
warning ("file in trash - cannot DnD");
valid_actions = Gdk.DragAction.DEFAULT; // No DnD within trash
}
}

var parent = drop_file.get_parent ();

if (parent != null && parent.equal (target_location)) {
warning ("file in destination - only LINK");
valid_actions &= Gdk.DragAction.LINK; // Only LINK is valid
}

var scheme = drop_file.get_uri_scheme ();
if (scheme == null || !scheme.has_prefix ("file")) {
warning ("file not local - cannot LINK");
valid_actions &= ~(Gdk.DragAction.LINK); // Can only LINK local files
}

if (++count > MAX_FILES_CHECKED ||
valid_actions == Gdk.DragAction.DEFAULT) {

warning ("No valid action for file - stop checking files");
break;
}
}
Expand All @@ -457,13 +471,15 @@ namespace Files {
suggested_action == Gdk.DragAction.COPY &&
(from_trash || FileUtils.same_file_system (drop_file_list.first ().data, target_location))) {

warning ("Same filesystem - suggesting MOVE");
suggested_action = Gdk.DragAction.MOVE;
}

if (valid_actions != Gdk.DragAction.DEFAULT) {
valid_actions |= Gdk.DragAction.ASK; // Allow ASK if there is a possible action
}

warning ("valid actions - %s", valid_actions.to_string ());
return valid_actions;
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/View/AbstractDirectoryView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,7 @@ namespace Files {
Idle.add (() => {
empty_label.visible = slot.directory.is_empty ();
thaw_tree ();
warning ("tree thawed");
schedule_thumbnail_color_tag_timeout ();
return Source.REMOVE;
});
Expand Down Expand Up @@ -1784,16 +1785,18 @@ namespace Files {
string uri = drop_target_file != null ? drop_target_file.uri : "";

if (uri != current_uri) {
warning ("drop target has changed");
cancel_timeout (ref drag_enter_timer_id);
current_actions = Gdk.DragAction.DEFAULT;
current_suggested_action = Gdk.DragAction.DEFAULT;

if (drop_target_file != null) {
warning ("have a target file - %s", drop_target_file.uri);
if (current_target_type == Gdk.Atom.intern_static_string ("XdndDirectSave0")) {
warning ("XdndDirectSave0 - copy");
current_suggested_action = Gdk.DragAction.COPY;
current_actions = current_suggested_action;
} else {

current_actions = DndHandler.file_accepts_drop (
drop_target_file,
destination_drop_file_list,
Expand All @@ -1807,21 +1810,26 @@ namespace Files {

if (drop_target_file.is_folder () && is_valid_drop_folder (drop_target_file)) {
/* open the target folder after a short delay */
warning ("starting folder enter timer");
drag_enter_timer_id = GLib.Timeout.add_full (GLib.Priority.LOW,
1000,
() => {

warning ("loading location during DnD");
load_location (drop_target_file.get_target_location ());
drag_enter_timer_id = 0;
return GLib.Source.REMOVE;
});
} else {
warning ("not a valid drop folder - cannot drop onto a file's parent or itself");
}
}
}
}

private bool is_valid_drop_folder (Files.File file) {
/* Cannot drop onto a file onto its parent or onto itself */
/* We no longer implement link creation by dropping onto parent */
if (file.uri != slot.uri &&
source_drag_file_list != null &&
source_drag_file_list.index (file) < 0) {
Expand Down
1 change: 1 addition & 0 deletions src/View/Widgets/BreadcrumbsEntry.vala
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ namespace Files.View.Chrome {
Gdk.Atom target = Gtk.drag_dest_find_target (this, context, list);
if (target != Gdk.Atom.NONE) {
Gtk.drag_get_data (this, context, target, time); /* emits "drag_data_received" */
return false;
}
}

Expand Down
Loading