mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-06 09:15:57 +02:00
Delete source files on move drag, clear drag_sources and allow_drags
Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/2f6384ba-c55a-4842-83a9-4cf1b0937420 Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
de6643d899
commit
6129fd66b3
@@ -228,10 +228,31 @@ func (dnd *dnd) on_drag_event(x, y, operation, Y int) (err error) {
|
||||
dnd.drag_status.dropped = true
|
||||
case 4:
|
||||
was_dropped := dnd.drag_status.dropped
|
||||
was_move := dnd.drag_status.accepted_operation == 2
|
||||
dnd.reset_drag()
|
||||
if was_dropped && dnd.has_exit_on("drag-finish") {
|
||||
dnd.lp.Quit(0)
|
||||
}
|
||||
if was_dropped && was_move {
|
||||
if ds := dnd.drag_sources["text/uri-list"]; ds != nil {
|
||||
for _, item := range ds.uri_list {
|
||||
if item.metadata.IsDir() {
|
||||
err = os.RemoveAll(item.path)
|
||||
} else {
|
||||
err = os.Remove(item.path)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
dnd.drag_sources = nil
|
||||
dnd.allow_drags = false
|
||||
dnd.lp.StopOfferingDrags()
|
||||
if !dnd.allow_drops {
|
||||
dnd.lp.Quit(0)
|
||||
}
|
||||
}
|
||||
case 5:
|
||||
if err = dnd.handle_data_request(y, Y == 1); err != nil {
|
||||
return err
|
||||
|
||||
@@ -80,6 +80,7 @@ type dnd struct {
|
||||
opts *Options
|
||||
drop_dests map[string]*drop_dest
|
||||
drag_sources map[string]*drag_source
|
||||
initial_drag_sources map[string]*drag_source
|
||||
drag_thumbnail image.Image
|
||||
allow_drops, allow_drags bool
|
||||
|
||||
@@ -163,6 +164,7 @@ func (dnd *dnd) run_loop() (err error) {
|
||||
defer dnd.remove_tdir()
|
||||
|
||||
dnd.allow_drops, dnd.allow_drags = len(dnd.drop_dests) > 0, len(dnd.drag_sources) > 0
|
||||
dnd.initial_drag_sources = dnd.drag_sources
|
||||
if dnd.lp, err = loop.New(); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -214,6 +216,8 @@ func (dnd *dnd) run_loop() (err error) {
|
||||
dnd.lp.StopOfferingDrags()
|
||||
dnd.remove_tdir()
|
||||
dnd.setup_base_dir(base_dir)
|
||||
dnd.drag_sources = dnd.initial_drag_sources
|
||||
dnd.allow_drops, dnd.allow_drags = len(dnd.drop_dests) > 0, len(dnd.drag_sources) > 0
|
||||
machine_id := ""
|
||||
if string(cmd.Payload) == "SETUP_REMOTE" {
|
||||
machine_id = "remote-client-for-test"
|
||||
|
||||
@@ -459,4 +459,9 @@ class TestDnDKitten(BaseTest):
|
||||
self.assertEqual(os.readlink(expected), os.readlink(actual))
|
||||
else:
|
||||
self.assert_files_have_same_content(expected, actual)
|
||||
src_items_before = set(os.listdir(self.src_data_dir))
|
||||
end_drag(False)
|
||||
# After a move drag finishes, all source files from text/uri-list should be deleted
|
||||
for name in src_items_before:
|
||||
item_path = os.path.join(self.src_data_dir, name)
|
||||
self.assertFalse(os.path.lexists(item_path), f'move drag: {name} should have been deleted from source')
|
||||
|
||||
Reference in New Issue
Block a user