S014: in-app drag and drop with drop targets, drop menu and bookmark drops
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
parent
56574edb7f
commit
f503a7c987
21 changed files with 866 additions and 200 deletions
|
|
@ -90,6 +90,7 @@ Never modify: `PROMPT.md` (the user's brief), the user's other projects under `~
|
|||
| `cargo run -p tunal -- --gallery --screenshot <png> [--dark] --size 1200x1000` (`--gallery` alone opens it in a window) | every control in rest/hover/pressed/focused/disabled; press squeeze not drawn by the software renderer | S004 |
|
||||
| `cargo run -p tunal -- --gallery --page menu\|dialog --screenshot <png> [--dark] --size 960x640` | open menu + submenu + two toasts, or dialog + indeterminate toast, over a stand-in folder | S005 |
|
||||
| `TUNAL_SETTINGS=<0-4> cargo run -p tunal -- <dir> --screenshot <png> --size 1000x700` (`XDG_CONFIG_HOME=<scratch>`) | settings dialog page over a folder | S013 |
|
||||
| `TUNAL_DRAG=x1,y1,x2,y2[,hold] TUNAL_REDUCED_MOTION=1 cargo run -p tunal -- <dir> --screenshot <png> --size 1200x760` (`XDG_CONFIG_HOME=<scratch>`) | drags between window points and drops (drop menu) or holds (glow + drag image) before the frame | S014 |
|
||||
|
||||
Don't assume a tool exists: check first. When your plan creates a tool, add its row here.
|
||||
|
||||
|
|
|
|||
|
|
@ -10,11 +10,11 @@ Drag files inside Tunal between panes, tabs, folders, breadcrumbs and places; a
|
|||
docs/DECISIONS.md D-014; Slint 1.19 `DragArea`/`DropArea` docs and `~/.cargo/registry/src/*/slint-1.19.0/tests/native_drag.rs`; crates/tunal/src/actions.rs.
|
||||
|
||||
## Steps
|
||||
- [ ] Drag source from the selection in both views (drag image with count badge); payload as a `text/uri-list` string so S030/S031 can hand it to other apps.
|
||||
- [ ] Drop targets: folder rows/cells, pane background, tabs (hover switches after a delay), breadcrumb segments, places entries; animated drop highlight.
|
||||
- [ ] Drop menu Move / Copy / Link / Cancel at the pointer; Shift = move, Ctrl = copy, Ctrl+Shift = link skip the menu; refuse drops into self or descendants.
|
||||
- [ ] Sidebar: drop a folder on the bookmarks section to add it; drag bookmarks to reorder.
|
||||
- [ ] PROGRESS entry, INDEX line, commit `S014: …`
|
||||
- [x] Drag source from the selection in both views (drag image with count badge); payload as a `text/uri-list` string so S030/S031 can hand it to other apps.
|
||||
- [x] Drop targets: folder rows/cells, pane background, tabs (hover switches after a delay), breadcrumb segments, places entries; animated drop highlight.
|
||||
- [x] Drop menu Move / Copy / Link / Cancel at the pointer; Shift = move, Ctrl = copy, Ctrl+Shift = link skip the menu; refuse drops into self or descendants.
|
||||
- [x] Sidebar: drop a folder on the bookmarks section to add it; drag bookmarks to reorder.
|
||||
- [x] PROGRESS entry, INDEX line, commit `S014: …`
|
||||
|
||||
## End criteria
|
||||
- `cargo build --workspace`, `cargo clippy --workspace --all-targets -- -D warnings` and `cargo fmt --check` pass.
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ Tracker: https://claude.ai/artifact/4X8YCk3cQjUGyuyCqGuU7v
|
|||
- [x] [S011 — File operation actions](03%20File%20browsing/S011-file-op-actions.md) · Sonnet high
|
||||
- [x] [S012 — Properties, Open and Open with](03%20File%20browsing/S012-properties-open-with.md) · Sonnet medium
|
||||
- [x] [S013 — Settings dialog and editable context menus](03%20File%20browsing/S013-settings-context-menus.md) · Sonnet high
|
||||
- [ ] [S014 — In-app drag and drop](03%20File%20browsing/S014-in-app-dnd.md) · Opus medium
|
||||
- [x] [S014 — In-app drag and drop](03%20File%20browsing/S014-in-app-dnd.md) · Opus medium
|
||||
|
||||
## 04 Directory metadata
|
||||
|
||||
|
|
|
|||
|
|
@ -248,6 +248,11 @@ impl Actions {
|
|||
actions
|
||||
}
|
||||
|
||||
/// Runs a file job (drag and drop).
|
||||
pub fn submit(&self, kind: JobKind) {
|
||||
self.bridge.submit(kind);
|
||||
}
|
||||
|
||||
/// The items on the clipboard to be moved.
|
||||
pub fn cut_uris(&self) -> Vec<Uri> {
|
||||
let clipboard = self.clipboard.borrow();
|
||||
|
|
|
|||
323
crates/tunal/src/dnd.rs
Normal file
323
crates/tunal/src/dnd.rs
Normal file
|
|
@ -0,0 +1,323 @@
|
|||
//! In-app drag and drop: files from the views onto folders, panes, tabs, breadcrumb
|
||||
//! segments and places; bookmarks onto bookmarks (reorder) or the bookmarks section (add).
|
||||
//!
|
||||
//! The payload is a `text/uri-list` string (one URI per line, CRLF), plus the file paths
|
||||
//! when every item is local, so other applications can take it (native DnD hands the same
|
||||
//! text to `drop_uris`). A drop without modifiers opens the drop menu; Shift moves, Ctrl
|
||||
//! copies and Ctrl+Shift links at once.
|
||||
|
||||
use std::any::Any;
|
||||
use std::cell::{OnceCell, RefCell};
|
||||
use std::rc::{Rc, Weak};
|
||||
|
||||
use slint::{ComponentHandle, DataTransfer, Image, SharedString};
|
||||
use tunal_core::ops::JobKind;
|
||||
use tunal_core::{Locations, Uri};
|
||||
|
||||
use crate::actions::Actions;
|
||||
use crate::shell::Shell;
|
||||
use crate::shell::places::Section;
|
||||
use crate::{Dnd, DropAction, DropTarget, MainWindow};
|
||||
|
||||
/// A bookmark being dragged (in-process only, carried as user data).
|
||||
struct BookmarkDrag(usize);
|
||||
|
||||
/// The last payload read back, since `accepts` runs on every pointer move.
|
||||
#[derive(Default)]
|
||||
struct Parsed {
|
||||
text: SharedString,
|
||||
uris: Rc<Vec<Uri>>,
|
||||
/// Every item is a local folder (bookmarks section), checked once when first asked.
|
||||
dirs: OnceCell<bool>,
|
||||
}
|
||||
|
||||
pub struct DragDrop {
|
||||
ui: slint::Weak<MainWindow>,
|
||||
shell: Weak<Shell>,
|
||||
actions: Weak<Actions>,
|
||||
locations: Locations,
|
||||
parsed: RefCell<Parsed>,
|
||||
/// Sources and folder of a drop waiting for the drop menu.
|
||||
pending: RefCell<Option<(Vec<Uri>, Uri)>>,
|
||||
}
|
||||
|
||||
/// One URI per line, as `text/uri-list` has them.
|
||||
pub fn uri_list(uris: &[Uri]) -> String {
|
||||
uris.iter().map(|u| format!("{u}\r\n")).collect()
|
||||
}
|
||||
|
||||
/// The URIs of a `text/uri-list` (comments and blank lines skipped).
|
||||
pub fn parse_uri_list(text: &str) -> Vec<Uri> {
|
||||
text.lines()
|
||||
.map(str::trim)
|
||||
.filter(|l| !l.is_empty() && !l.starts_with('#'))
|
||||
.filter_map(Uri::parse)
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// `dir` is `src` or lies inside it.
|
||||
fn within(dir: &Uri, src: &Uri) -> bool {
|
||||
if dir.scheme() != src.scheme() || dir.authority() != src.authority() {
|
||||
return false;
|
||||
}
|
||||
let src = src.path().strip_suffix(b"/").unwrap_or(src.path());
|
||||
let dir = dir.path().strip_suffix(b"/").unwrap_or(dir.path());
|
||||
dir.starts_with(src) && (dir.len() == src.len() || dir[src.len()] == b'/' || src.is_empty())
|
||||
}
|
||||
|
||||
impl DragDrop {
|
||||
pub fn attach(
|
||||
ui: &MainWindow,
|
||||
shell: &Rc<Shell>,
|
||||
actions: &Rc<Actions>,
|
||||
locations: Locations,
|
||||
) -> Rc<Self> {
|
||||
let dnd = Rc::new(Self {
|
||||
ui: ui.as_weak(),
|
||||
shell: Rc::downgrade(shell),
|
||||
actions: Rc::downgrade(actions),
|
||||
locations,
|
||||
parsed: RefCell::new(Parsed::default()),
|
||||
pending: RefCell::new(None),
|
||||
});
|
||||
dnd.bind(ui);
|
||||
dnd
|
||||
}
|
||||
|
||||
fn bind(self: &Rc<Self>, ui: &MainWindow) {
|
||||
let global = ui.global::<Dnd>();
|
||||
let me = Rc::downgrade(self);
|
||||
global.on_payload(move |pane, row, _| {
|
||||
me.upgrade()
|
||||
.map(|d| d.payload(&d.drag_uris(pane, row)))
|
||||
.unwrap_or_default()
|
||||
});
|
||||
let me = Rc::downgrade(self);
|
||||
global.on_image(move |pane, row, _, fill, ink, badge, badge_ink| {
|
||||
me.upgrade()
|
||||
.map(|d| drag_image(&d.drag_uris(pane, row), [fill, ink, badge, badge_ink]))
|
||||
.unwrap_or_default()
|
||||
});
|
||||
global.on_bookmark_payload(|index| {
|
||||
let mut data = DataTransfer::default();
|
||||
data.set_user_data(Rc::new(BookmarkDrag(index.max(0) as usize)));
|
||||
data
|
||||
});
|
||||
let me = Rc::downgrade(self);
|
||||
global.on_accepts(move |data, target, a, b| {
|
||||
me.upgrade().is_some_and(|d| d.accepts(&data, target, a, b))
|
||||
});
|
||||
let me = Rc::downgrade(self);
|
||||
global.on_dropped(move |data, action, target, a, b, x, y| {
|
||||
if let Some(d) = me.upgrade() {
|
||||
d.dropped(&data, action, target, a, b, x, y);
|
||||
}
|
||||
});
|
||||
let me = Rc::downgrade(self);
|
||||
ui.on_drop_chosen(move |choice| {
|
||||
let Some(d) = me.upgrade() else { return };
|
||||
let Some((sources, dir)) = d.pending.take() else {
|
||||
return;
|
||||
};
|
||||
let action = match choice {
|
||||
0 => DropAction::Move,
|
||||
1 => DropAction::Copy,
|
||||
2 => DropAction::Link,
|
||||
_ => return,
|
||||
};
|
||||
d.drop_uris(sources, dir, action);
|
||||
});
|
||||
}
|
||||
|
||||
fn drag_uris(&self, pane: i32, row: i32) -> Vec<Uri> {
|
||||
let (Ok(pane), Ok(row)) = (usize::try_from(pane), usize::try_from(row)) else {
|
||||
return Vec::new();
|
||||
};
|
||||
self.shell
|
||||
.upgrade()
|
||||
.and_then(|s| s.pane_at(pane))
|
||||
.map(|p| p.model.drag_uris(row))
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn payload(&self, uris: &[Uri]) -> DataTransfer {
|
||||
let mut data = DataTransfer::default();
|
||||
if uris.is_empty() {
|
||||
return data;
|
||||
}
|
||||
data.set_plain_text(uri_list(uris).into());
|
||||
let paths: Option<Vec<_>> = uris.iter().map(Uri::to_path).collect();
|
||||
if let Some(paths) = paths {
|
||||
data.set_file_paths(paths);
|
||||
}
|
||||
data
|
||||
}
|
||||
|
||||
/// The payload's URIs, parsed once per drag.
|
||||
fn uris(&self, data: &DataTransfer) -> Rc<Vec<Uri>> {
|
||||
let text = data.plain_text().unwrap_or_default();
|
||||
let mut parsed = self.parsed.borrow_mut();
|
||||
if parsed.text != text {
|
||||
*parsed = Parsed {
|
||||
uris: Rc::new(parse_uri_list(&text)),
|
||||
text,
|
||||
dirs: OnceCell::new(),
|
||||
};
|
||||
}
|
||||
parsed.uris.clone()
|
||||
}
|
||||
|
||||
fn bookmark(data: &DataTransfer) -> Option<usize> {
|
||||
let any: Rc<dyn Any> = data.user_data()?;
|
||||
any.downcast_ref::<BookmarkDrag>().map(|b| b.0)
|
||||
}
|
||||
|
||||
fn target_dir(&self, target: DropTarget, a: i32, b: i32) -> Option<Uri> {
|
||||
let shell = self.shell.upgrade()?;
|
||||
let index = |i: i32| usize::try_from(i).ok();
|
||||
match target {
|
||||
DropTarget::Row => shell.pane_at(index(a)?)?.model.folder_at(index(b)?),
|
||||
DropTarget::Pane => shell.pane_at(index(a)?)?.dir(),
|
||||
DropTarget::Tab => shell.tab_dir(a),
|
||||
DropTarget::Crumb => shell.crumb_uri(index(a)?),
|
||||
DropTarget::Place => shell.place_uri(*Section::ALL.get(index(a)?)?, index(b)?),
|
||||
DropTarget::Bookmarks => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn accepts(&self, data: &DataTransfer, target: DropTarget, a: i32, b: i32) -> bool {
|
||||
let bookmarks = Section::ALL.iter().position(|&s| s == Section::Bookmarks);
|
||||
if let Some(from) = Self::bookmark(data) {
|
||||
return target == DropTarget::Place
|
||||
&& usize::try_from(a).ok() == bookmarks
|
||||
&& usize::try_from(b).is_ok_and(|to| to != from);
|
||||
}
|
||||
let uris = self.uris(data);
|
||||
if uris.is_empty() {
|
||||
return false;
|
||||
}
|
||||
if target == DropTarget::Bookmarks {
|
||||
return usize::try_from(a).ok() == bookmarks && self.all_dirs();
|
||||
}
|
||||
let Some(dir) = self.target_dir(target, a, b) else {
|
||||
return false;
|
||||
};
|
||||
self.can_drop(&uris, &dir)
|
||||
}
|
||||
|
||||
/// Every dragged item is a local folder.
|
||||
fn all_dirs(&self) -> bool {
|
||||
let parsed = self.parsed.borrow();
|
||||
*parsed.dirs.get_or_init(|| {
|
||||
parsed
|
||||
.uris
|
||||
.iter()
|
||||
.all(|u| u.to_path().is_some_and(|p| p.is_dir()))
|
||||
})
|
||||
}
|
||||
|
||||
/// `dir` can take `uris`: it is writable, not one of them or inside one, and not the
|
||||
/// folder they are all in already.
|
||||
fn can_drop(&self, uris: &[Uri], dir: &Uri) -> bool {
|
||||
let writable = self
|
||||
.locations
|
||||
.resolve(dir)
|
||||
.is_ok_and(|l| l.capabilities().write);
|
||||
writable
|
||||
&& !uris.iter().any(|u| within(dir, u))
|
||||
&& !uris.iter().all(|u| u.parent().as_ref() == Some(dir))
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn dropped(
|
||||
&self,
|
||||
data: &DataTransfer,
|
||||
action: DropAction,
|
||||
target: DropTarget,
|
||||
a: i32,
|
||||
b: i32,
|
||||
x: f32,
|
||||
y: f32,
|
||||
) {
|
||||
let Some(shell) = self.shell.upgrade() else {
|
||||
return;
|
||||
};
|
||||
if let Some(from) = Self::bookmark(data) {
|
||||
if let Ok(to) = usize::try_from(b) {
|
||||
shell.move_bookmark(from, to);
|
||||
}
|
||||
return;
|
||||
}
|
||||
let uris = self.uris(data).to_vec();
|
||||
if target == DropTarget::Bookmarks {
|
||||
shell.add_bookmarks(&uris);
|
||||
return;
|
||||
}
|
||||
let Some(dir) = self.target_dir(target, a, b) else {
|
||||
return;
|
||||
};
|
||||
if action == DropAction::Ask {
|
||||
*self.pending.borrow_mut() = Some((uris, dir));
|
||||
// After the drop has finished dispatching, so the menu takes the focus.
|
||||
let ui = self.ui.clone();
|
||||
slint::Timer::single_shot(std::time::Duration::ZERO, move || {
|
||||
if let Some(ui) = ui.upgrade() {
|
||||
ui.invoke_open_drop_menu(x, y);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
self.drop_uris(uris, dir, action);
|
||||
}
|
||||
}
|
||||
|
||||
/// Moves, copies or links `sources` into `dir`; also the entry point for native drops.
|
||||
pub fn drop_uris(&self, sources: Vec<Uri>, dir: Uri, action: DropAction) {
|
||||
if sources.is_empty() || !self.can_drop(&sources, &dir) {
|
||||
return;
|
||||
}
|
||||
let Some(actions) = self.actions.upgrade() else {
|
||||
return;
|
||||
};
|
||||
actions.submit(match action {
|
||||
DropAction::Copy => JobKind::Copy { sources, dest: dir },
|
||||
DropAction::Link => JobKind::Link { sources, dest: dir },
|
||||
_ => JobKind::Move { sources, dest: dir },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// The picture under the pointer: a tonal pill with the first item's name and, for several
|
||||
/// items, a count badge. Drawn as SVG in the theme's colours (fill, ink, badge, badge ink).
|
||||
fn drag_image(uris: &[Uri], colors: [slint::Color; 4]) -> Image {
|
||||
let Some(first) = uris.first() else {
|
||||
return Image::default();
|
||||
};
|
||||
let hex = |c: slint::Color| format!("#{:02x}{:02x}{:02x}", c.red(), c.green(), c.blue());
|
||||
let [fill, ink, badge, badge_ink] = colors.map(hex);
|
||||
let name = first
|
||||
.file_name()
|
||||
.map(|n| String::from_utf8_lossy(n).into_owned())
|
||||
.unwrap_or_else(|| first.to_string());
|
||||
let mut name: String = name.chars().take(28).collect();
|
||||
if name.chars().count() == 28 {
|
||||
name.push('…');
|
||||
}
|
||||
let escape = |s: &str| {
|
||||
s.replace('&', "&")
|
||||
.replace('<', "<")
|
||||
.replace('>', ">")
|
||||
};
|
||||
let count = if uris.len() > 1 {
|
||||
format!(
|
||||
r#"<circle cx="228" cy="14" r="12" fill="{badge}"/><text x="228" y="18.5" font-family="sans-serif" font-size="12" font-weight="600" text-anchor="middle" fill="{badge_ink}">{}</text>"#,
|
||||
uris.len().min(999)
|
||||
)
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
let svg = format!(
|
||||
r#"<svg xmlns="http://www.w3.org/2000/svg" width="244" height="52" viewBox="0 0 244 52"><rect x="4" y="12" width="224" height="36" rx="18" fill="{fill}" fill-opacity="0.94"/><text x="22" y="35" font-family="sans-serif" font-size="14" fill="{ink}">{}</text>{count}</svg>"#,
|
||||
escape(&name)
|
||||
);
|
||||
Image::load_from_svg_data(svg.as_bytes()).unwrap_or_default()
|
||||
}
|
||||
|
|
@ -809,6 +809,29 @@ impl FolderModel {
|
|||
names.into_iter().map(|n| dir.join(n)).collect()
|
||||
}
|
||||
|
||||
/// What a drag from `row` carries: the selection when the row is in it, else the row.
|
||||
pub fn drag_uris(&self, row: usize) -> Vec<Uri> {
|
||||
let Some(name) = self.name_at(row) else {
|
||||
return Vec::new();
|
||||
};
|
||||
if self.state.borrow().selected.contains(&name) {
|
||||
return self.selected_uris();
|
||||
}
|
||||
let s = self.state.borrow();
|
||||
s.dir.iter().map(|d| d.join(&name)).collect()
|
||||
}
|
||||
|
||||
/// The folder `row` shows, if it is one.
|
||||
pub fn folder_at(&self, row: usize) -> Option<Uri> {
|
||||
let s = self.state.borrow();
|
||||
match s.rows.get(row)? {
|
||||
Row::Item(i) if s.items[*i].is_dir => {
|
||||
Some(s.dir.as_ref()?.join(&s.items[*i].entry.name))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// The items to draw dimmed: those on the clipboard to be moved.
|
||||
pub fn set_cut(&self, uris: &[Uri]) {
|
||||
let mut s = self.state.borrow_mut();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
mod actions;
|
||||
mod config;
|
||||
mod desktop_apps;
|
||||
mod dnd;
|
||||
mod folder;
|
||||
mod icons;
|
||||
mod jobs_bridge;
|
||||
|
|
|
|||
|
|
@ -55,6 +55,13 @@ pub fn run<C: Themed>(
|
|||
window.set_size(PhysicalSize::new(width, height));
|
||||
ui.show().map_err(|e| e.to_string())?;
|
||||
let mut pixels = vec![PremultipliedRgbaColor::default(); (width * height) as usize];
|
||||
if let Ok(spec) = std::env::var("TUNAL_DRAG") {
|
||||
// Lay the window out before pointing at it.
|
||||
window.draw_if_needed(|renderer| {
|
||||
renderer.render(&mut pixels, width as usize);
|
||||
});
|
||||
drag(&window, &spec);
|
||||
}
|
||||
window.request_redraw();
|
||||
window.draw_if_needed(|renderer| {
|
||||
renderer.render(&mut pixels, width as usize);
|
||||
|
|
@ -70,6 +77,34 @@ pub fn run<C: Themed>(
|
|||
.map_err(|e| format!("couldn't write {}: {e}", options.path))
|
||||
}
|
||||
|
||||
/// `TUNAL_DRAG=x1,y1,x2,y2[,hold]`: drags from one window point to another and drops there,
|
||||
/// or keeps holding with `hold` (to see the drop highlight and the drag image).
|
||||
fn drag(window: &MinimalSoftwareWindow, spec: &str) {
|
||||
use slint::LogicalPosition;
|
||||
use slint::platform::{PointerEventButton, WindowEvent};
|
||||
let parts: Vec<&str> = spec.split(',').collect();
|
||||
let n: Vec<f32> = parts.iter().filter_map(|p| p.trim().parse().ok()).collect();
|
||||
let [x1, y1, x2, y2] = n[..] else {
|
||||
eprintln!("tunal: TUNAL_DRAG wants x1,y1,x2,y2[,hold]");
|
||||
return;
|
||||
};
|
||||
let button = PointerEventButton::Left;
|
||||
window.dispatch_event(WindowEvent::PointerPressed {
|
||||
position: LogicalPosition::new(x1, y1),
|
||||
button,
|
||||
});
|
||||
for step in 1..=10 {
|
||||
let t = step as f32 / 10.0;
|
||||
let position = LogicalPosition::new(x1 + (x2 - x1) * t, y1 + (y2 - y1) * t);
|
||||
window.dispatch_event(WindowEvent::PointerMoved { position });
|
||||
}
|
||||
if parts.get(4) != Some(&"hold") {
|
||||
let position = LogicalPosition::new(x2, y2);
|
||||
window.dispatch_event(WindowEvent::PointerReleased { position, button });
|
||||
}
|
||||
slint::platform::update_timers_and_animations();
|
||||
}
|
||||
|
||||
fn write_png(path: &Path, width: u32, height: u32, rgba: &[u8]) -> Result<(), png::EncodingError> {
|
||||
let mut encoder = png::Encoder::new(BufWriter::new(File::create(path)?), width, height);
|
||||
encoder.set_color(png::ColorType::Rgba);
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ use tunal_core::{Locations, Uri};
|
|||
|
||||
use crate::actions::Actions;
|
||||
use crate::config::{self, Session, TabSession};
|
||||
use crate::dnd::DragDrop;
|
||||
use crate::folder::format;
|
||||
use crate::settings::SettingsUi;
|
||||
use crate::{
|
||||
|
|
@ -57,6 +58,8 @@ pub struct Shell {
|
|||
actions: OnceCell<Rc<Actions>>,
|
||||
/// The settings dialog; kept alive here.
|
||||
settings: OnceCell<Rc<SettingsUi>>,
|
||||
/// Drag and drop; kept alive here.
|
||||
dnd: OnceCell<Rc<DragDrop>>,
|
||||
}
|
||||
|
||||
impl Shell {
|
||||
|
|
@ -84,9 +87,16 @@ impl Shell {
|
|||
completion: Arc::new(AtomicU64::new(0)),
|
||||
actions: OnceCell::new(),
|
||||
settings: OnceCell::new(),
|
||||
dnd: OnceCell::new(),
|
||||
});
|
||||
let actions = Actions::attach(ui, &shell, shell.locations.clone());
|
||||
let _ = shell.settings.set(SettingsUi::attach(ui, &shell, &actions));
|
||||
let _ = shell.dnd.set(DragDrop::attach(
|
||||
ui,
|
||||
&shell,
|
||||
&actions,
|
||||
shell.locations.clone(),
|
||||
));
|
||||
let _ = shell.actions.set(actions);
|
||||
ui.set_tabs(ModelRc::from(shell.tab_rows.clone()));
|
||||
ui.set_panes(ModelRc::from(shell.pane_rows.clone()));
|
||||
|
|
@ -652,16 +662,48 @@ impl Shell {
|
|||
}
|
||||
|
||||
fn go_crumb(&self, index: usize) {
|
||||
let target = self
|
||||
.active()
|
||||
.and_then(|p| p.dir())
|
||||
.and_then(|d| path::segments(&d).into_iter().nth(index))
|
||||
.map(|s| s.uri);
|
||||
if let Some(uri) = target {
|
||||
if let Some(uri) = self.crumb_uri(index) {
|
||||
self.go(uri);
|
||||
}
|
||||
}
|
||||
|
||||
// ---- drop targets (dnd.rs) --------------------------------------------------------------
|
||||
|
||||
/// The folder breadcrumb segment `index` names.
|
||||
pub(crate) fn crumb_uri(&self, index: usize) -> Option<Uri> {
|
||||
let dir = self.active()?.dir()?;
|
||||
path::segments(&dir).into_iter().nth(index).map(|s| s.uri)
|
||||
}
|
||||
|
||||
/// The folder of the active pane of the tab with `id`.
|
||||
pub(crate) fn tab_dir(&self, id: i32) -> Option<Uri> {
|
||||
let tabs = self.tabs.borrow();
|
||||
let tab = tabs.iter().find(|t| t.id == id)?;
|
||||
tab.panes.get(tab.active)?.dir()
|
||||
}
|
||||
|
||||
pub(crate) fn place_uri(&self, section: Section, index: usize) -> Option<Uri> {
|
||||
self.places
|
||||
.borrow()
|
||||
.get(section, index)
|
||||
.map(|p| p.uri.clone())
|
||||
}
|
||||
|
||||
pub(crate) fn add_bookmarks(&self, dirs: &[Uri]) {
|
||||
for dir in dirs {
|
||||
let (name, _) = path::title(dir);
|
||||
self.places.borrow_mut().add_bookmark(name, dir.clone());
|
||||
}
|
||||
self.show_chrome();
|
||||
}
|
||||
|
||||
/// Puts bookmark `from` at slot `to`.
|
||||
pub(crate) fn move_bookmark(&self, from: usize, to: usize) {
|
||||
let by = to as isize - from as isize;
|
||||
self.places.borrow_mut().move_bookmark(from, by);
|
||||
self.show_chrome();
|
||||
}
|
||||
|
||||
// ---- wiring -------------------------------------------------------------------------
|
||||
|
||||
fn bind(&self, ui: &MainWindow) {
|
||||
|
|
|
|||
|
|
@ -23,10 +23,11 @@ import { ErrorsDialog } from "dialogs/errors.slint";
|
|||
import { PropertiesDialog, PropertiesInfo, PropRow } from "dialogs/properties.slint";
|
||||
import { OpenWithDialog, AppRow } from "dialogs/open-with.slint";
|
||||
import { SettingsDialog, SettingsData, EditRow } from "dialogs/settings.slint";
|
||||
import { Dnd, DropAction, DropMenu, DropTarget } from "components/drop-menu.slint";
|
||||
|
||||
export { Theme, Shapes, ShapeKind, MotionPrefs, MenuItem, MenuEntry, DetailRow, FolderState, FolderStatus, Grouping, NavKey, SortColumn, Travel, ViewMode, GridRow }
|
||||
export { ButtonKind, TabData, PaneData, Crumb, Completion, SidebarSection, PlaceItem, ToastData, ToastProgress, DialogAction, ConflictInfo, SettingsData, EditRow }
|
||||
export { PropertiesInfo, PropRow, AppRow }
|
||||
export { PropertiesInfo, PropRow, AppRow, Dnd, DropAction, DropTarget }
|
||||
export { Gallery, GalleryPage } from "gallery.slint";
|
||||
|
||||
// The window: sidebar, tab bar, toolbar with the breadcrumb, the panes of the current tab
|
||||
|
|
@ -175,6 +176,12 @@ export component MainWindow inherits Window {
|
|||
context-popup.open-at(x, y);
|
||||
}
|
||||
|
||||
// After a drop without modifiers (dnd.rs): 0 move, 1 copy, 2 link, else cancel.
|
||||
callback drop-chosen(int);
|
||||
public function open-drop-menu(x: length, y: length) {
|
||||
drop-popup.open-at(x, y);
|
||||
}
|
||||
|
||||
public function show-settings(page: int) {
|
||||
root.settings-opening();
|
||||
settings-dialog.page = page;
|
||||
|
|
@ -241,7 +248,17 @@ export component MainWindow inherits Window {
|
|||
}
|
||||
|
||||
shortcuts := FocusScope {
|
||||
// Shift during a drag picks move without the drop menu (see Dnd.shift).
|
||||
capture-key-released(event) => {
|
||||
if event.text == Key.Shift || event.text == Key.ShiftR {
|
||||
Dnd.shift = false;
|
||||
}
|
||||
reject
|
||||
}
|
||||
capture-key-pressed(event) => {
|
||||
if event.text == Key.Shift || event.text == Key.ShiftR {
|
||||
Dnd.shift = true;
|
||||
}
|
||||
// Text fields (breadcrumb, rename) keep their own editing keys; Rust checks the rest.
|
||||
if !toolbar.editing
|
||||
&& (event.modifiers.control || event.text == Key.F2 || event.text == Key.Delete)
|
||||
|
|
@ -410,6 +427,7 @@ export component MainWindow inherits Window {
|
|||
for pane[i] in root.panes: Pane {
|
||||
property <int> request: root.focus-request + root.refocus;
|
||||
data: pane;
|
||||
index: i;
|
||||
active: i == root.active-pane;
|
||||
split: root.panes.length > 1;
|
||||
init => {
|
||||
|
|
@ -534,6 +552,17 @@ export component MainWindow inherits Window {
|
|||
}
|
||||
}
|
||||
|
||||
drop-popup := DropMenu {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
activated(index, sub) => {
|
||||
root.drop-chosen(index);
|
||||
}
|
||||
closed => {
|
||||
root.focus-pane();
|
||||
}
|
||||
}
|
||||
|
||||
place-popup := Menu {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
|
|
|||
76
crates/tunal/ui/components/drop-menu.slint
Normal file
76
crates/tunal/ui/components/drop-menu.slint
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
import { Theme } from "../theme.slint";
|
||||
import { Motion } from "../motion.slint";
|
||||
import { Icons } from "icon.slint";
|
||||
import { Menu } from "menu.slint";
|
||||
|
||||
// What a drop landed on; `a` and `b` of the Dnd callbacks name it:
|
||||
// row (pane, row), pane (pane, -), tab (tab, -), crumb (crumb, -), place (section, index),
|
||||
// bookmarks (the bookmarks section: adds folders).
|
||||
export enum DropTarget { row, pane, tab, crumb, place, bookmarks }
|
||||
|
||||
// What the drop does: `ask` opens the drop menu (no modifier held).
|
||||
export enum DropAction { ask, move, copy, link }
|
||||
|
||||
// Drag and drop, served by Rust (dnd.rs).
|
||||
export global Dnd {
|
||||
// Shift is held. Tracked from the window's keys: Slint's drop event can't tell Shift
|
||||
// from no modifier (both propose a move).
|
||||
in-out property <bool> shift;
|
||||
// The payload of a drag from row `row` of pane `pane`. `fresh` only makes the binding
|
||||
// read the selection again (pass the row's pressed state).
|
||||
pure callback payload(pane: int, row: int, fresh: bool) -> data-transfer;
|
||||
// The picture under the pointer: the first name and, for several items, their count.
|
||||
pure callback image(pane: int, row: int, fresh: bool, fill: color, ink: color, badge: color, badge-ink: color) -> image;
|
||||
// A bookmark's payload (reordering).
|
||||
pure callback bookmark-payload(index: int) -> data-transfer;
|
||||
pure callback accepts(data: data-transfer, target: DropTarget, a: int, b: int) -> bool;
|
||||
// At window coordinates, for the drop menu.
|
||||
callback dropped(data: data-transfer, action: DropAction, target: DropTarget, a: int, b: int, x: length, y: length);
|
||||
}
|
||||
|
||||
// A drop target over its parent: glows while a drag it accepts hovers it.
|
||||
export component DropZone inherits DropArea {
|
||||
in property <DropTarget> target;
|
||||
in property <int> a;
|
||||
in property <int> b: -1;
|
||||
in property <length> radius;
|
||||
|
||||
can-drop(event) => {
|
||||
Dnd.accepts(event.data, root.target, root.a, root.b) ? event.proposed-action : DragAction.none
|
||||
}
|
||||
dropped(event) => {
|
||||
Dnd.dropped(
|
||||
event.data,
|
||||
event.proposed-action == DragAction.copy ? DropAction.copy
|
||||
: event.proposed-action == DragAction.link ? DropAction.link
|
||||
: Dnd.shift ? DropAction.move : DropAction.ask,
|
||||
root.target, root.a, root.b,
|
||||
self.absolute-position.x + event.position.x,
|
||||
self.absolute-position.y + event.position.y);
|
||||
event.proposed-action
|
||||
}
|
||||
|
||||
@children
|
||||
|
||||
// Above the content: a primary outline and a faint drag tint.
|
||||
Rectangle {
|
||||
border-radius: root.radius;
|
||||
border-width: Theme.focus-ring-width;
|
||||
border-color: Theme.primary;
|
||||
background: Theme.primary.with-alpha(Theme.state-drag);
|
||||
opacity: root.has-drag ? 1 : 0;
|
||||
animate opacity { duration: Motion.time(Motion.short3); easing: Motion.standard; }
|
||||
}
|
||||
}
|
||||
|
||||
// Move / Copy / Link / Cancel, opened at the pointer after a drop without modifiers.
|
||||
export component DropMenu inherits Menu {
|
||||
leading-icons: true;
|
||||
items: [
|
||||
{ text: "Move here", icon: Icons.drive-file-move, shortcut: "Shift" },
|
||||
{ text: "Copy here", icon: Icons.content-copy, shortcut: "Ctrl" },
|
||||
{ text: "Link here", icon: Icons.link, shortcut: "Ctrl+Shift" },
|
||||
{ separator: true },
|
||||
{ text: "Cancel", icon: Icons.cancel, shortcut: "Esc" },
|
||||
];
|
||||
}
|
||||
|
|
@ -35,6 +35,8 @@ export global Icons {
|
|||
out property <string> description: "\u{e873}";
|
||||
out property <string> chevron-right: "\u{e5cc}";
|
||||
out property <string> content-copy: "\u{e14d}";
|
||||
out property <string> drive-file-move: "\u{e9a1}";
|
||||
out property <string> link: "\u{e157}";
|
||||
out property <string> content-cut: "\u{e14e}";
|
||||
out property <string> content-paste: "\u{e14f}";
|
||||
out property <string> edit: "\u{e3c9}";
|
||||
|
|
|
|||
|
|
@ -56,6 +56,8 @@ export global Motion {
|
|||
|
||||
// Hover time before a tooltip shows. A delay, not motion: reduced motion keeps it.
|
||||
out property <duration> tooltip-delay: 500ms;
|
||||
// How long a drag hovers over a tab before the tab opens (not shortened by reduced motion).
|
||||
out property <duration> drag-switch-delay: 700ms;
|
||||
|
||||
// How far content slides when a folder opens in a direction of travel.
|
||||
out property <length> travel-shift: 32px;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { Theme } from "../theme.slint";
|
|||
import { Motion } from "../motion.slint";
|
||||
import { Icon, Icons } from "../components/icon.slint";
|
||||
import { StateLayer } from "../components/state-layer.slint";
|
||||
import { DropTarget, DropZone } from "../components/drop-menu.slint";
|
||||
|
||||
// One segment of the path: the root (glyph and name) or a folder.
|
||||
export struct Crumb {
|
||||
|
|
@ -149,6 +150,12 @@ export component Breadcrumb inherits Rectangle {
|
|||
clicked => {
|
||||
root.go(i);
|
||||
}
|
||||
|
||||
DropZone {
|
||||
target: DropTarget.crumb;
|
||||
a: i;
|
||||
radius: parent.border-radius;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { Icon } from "../components/icon.slint";
|
|||
import { DetailRow, FolderState, NavKey, SortColumn } from "../views/details-view.slint";
|
||||
import { GridRow } from "../views/grid-view.slint";
|
||||
import { FolderView } from "../views/view-switch.slint";
|
||||
import { DropTarget, DropZone } from "../components/drop-menu.slint";
|
||||
|
||||
// One pane of a tab, set from Rust (shell/pane.rs).
|
||||
export struct PaneData {
|
||||
|
|
@ -22,6 +23,8 @@ export component Pane inherits Rectangle {
|
|||
in property <PaneData> data;
|
||||
in property <bool> active;
|
||||
in property <bool> split;
|
||||
// Index in the tab, for drag and drop.
|
||||
in property <int> index;
|
||||
out property <bool> hovered: touch.has-hover;
|
||||
|
||||
// The pointer or keyboard went here: make this the active pane.
|
||||
|
|
@ -57,111 +60,119 @@ export component Pane inherits Rectangle {
|
|||
|
||||
// Clicks the view leaves alone (empty space, the header) still activate the pane; the
|
||||
// hover is for the mouse back and forward buttons, which go to the pane under the pointer.
|
||||
touch := TouchArea {
|
||||
clicked => {
|
||||
root.activated();
|
||||
root.focus-view();
|
||||
}
|
||||
pointer-event(event) => {
|
||||
if event.button == PointerEventButton.right && event.kind == PointerEventKind.down {
|
||||
// Dropping on the background (or on a file) goes into the pane's folder.
|
||||
DropZone {
|
||||
target: DropTarget.pane;
|
||||
a: root.index;
|
||||
radius: root.border-radius;
|
||||
|
||||
touch := TouchArea {
|
||||
clicked => {
|
||||
root.activated();
|
||||
root.context-menu(-1, self.absolute-position.x + self.mouse-x, self.absolute-position.y + self.mouse-y);
|
||||
root.focus-view();
|
||||
}
|
||||
pointer-event(event) => {
|
||||
if event.button == PointerEventButton.right && event.kind == PointerEventKind.down {
|
||||
root.activated();
|
||||
root.context-menu(-1, self.absolute-position.x + self.mouse-x, self.absolute-position.y + self.mouse-y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VerticalLayout {
|
||||
if root.split: Rectangle {
|
||||
height: root.header-height;
|
||||
background: root.active ? Theme.secondary-container : Theme.surface-container;
|
||||
animate background { duration: Motion.time(Motion.short4); easing: Motion.standard; }
|
||||
VerticalLayout {
|
||||
if root.split: Rectangle {
|
||||
height: root.header-height;
|
||||
background: root.active ? Theme.secondary-container : Theme.surface-container;
|
||||
animate background { duration: Motion.time(Motion.short4); easing: Motion.standard; }
|
||||
|
||||
HorizontalLayout {
|
||||
padding-left: Theme.space-3;
|
||||
padding-right: Theme.space-3;
|
||||
spacing: Theme.space-2;
|
||||
HorizontalLayout {
|
||||
padding-left: Theme.space-3;
|
||||
padding-right: Theme.space-3;
|
||||
spacing: Theme.space-2;
|
||||
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
Icon {
|
||||
glyph: root.data.glyph;
|
||||
size: 18px;
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
Icon {
|
||||
glyph: root.data.glyph;
|
||||
size: 18px;
|
||||
color: root.active ? Theme.on-secondary-container : Theme.on-surface-variant;
|
||||
animate color { duration: Motion.time(Motion.short4); easing: Motion.standard; }
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
horizontal-stretch: 1;
|
||||
text: root.data.title;
|
||||
color: root.active ? Theme.on-secondary-container : Theme.on-surface-variant;
|
||||
font-size: Theme.label-large.size;
|
||||
font-weight: Theme.label-large.weight;
|
||||
vertical-alignment: center;
|
||||
overflow: elide;
|
||||
animate color { duration: Motion.time(Motion.short4); easing: Motion.standard; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
horizontal-stretch: 1;
|
||||
text: root.data.title;
|
||||
color: root.active ? Theme.on-secondary-container : Theme.on-surface-variant;
|
||||
font-size: Theme.label-large.size;
|
||||
font-weight: Theme.label-large.weight;
|
||||
vertical-alignment: center;
|
||||
overflow: elide;
|
||||
animate color { duration: Motion.time(Motion.short4); easing: Motion.standard; }
|
||||
details := FolderView {
|
||||
pane: root.index;
|
||||
rows: root.data.rows;
|
||||
lines: root.data.lines;
|
||||
state: root.data.folder;
|
||||
columns-changed(n) => {
|
||||
root.columns-changed(n);
|
||||
}
|
||||
motion-settled => {
|
||||
root.motion-settled();
|
||||
}
|
||||
row-renamed(row, text) => {
|
||||
root.row-renamed(row, text);
|
||||
}
|
||||
rename-cancelled => {
|
||||
root.rename-cancelled();
|
||||
}
|
||||
context-menu(row, x, y) => {
|
||||
root.activated();
|
||||
root.context-menu(row, x, y);
|
||||
}
|
||||
sort-by(column) => {
|
||||
root.activated();
|
||||
root.sort-by(column);
|
||||
}
|
||||
open-sort-menu(x, y) => {
|
||||
root.activated();
|
||||
root.open-sort-menu(x, y);
|
||||
}
|
||||
filter-typed(text) => {
|
||||
root.activated();
|
||||
root.filter-typed(text);
|
||||
}
|
||||
filter-edited(text) => {
|
||||
root.activated();
|
||||
root.filter-edited(text);
|
||||
}
|
||||
toggle-hidden => {
|
||||
root.activated();
|
||||
root.toggle-hidden();
|
||||
}
|
||||
row-clicked(row, ctrl, shift) => {
|
||||
root.activated();
|
||||
root.row-clicked(row, ctrl, shift);
|
||||
}
|
||||
row-activated(row) => {
|
||||
root.activated();
|
||||
root.row-activated(row);
|
||||
}
|
||||
select-all => {
|
||||
root.activated();
|
||||
root.select-all();
|
||||
}
|
||||
clear-selection => {
|
||||
root.activated();
|
||||
root.clear-selection();
|
||||
}
|
||||
navigate(key, shift, page) => {
|
||||
root.activated();
|
||||
root.navigate(key, shift, page)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
details := FolderView {
|
||||
rows: root.data.rows;
|
||||
lines: root.data.lines;
|
||||
state: root.data.folder;
|
||||
columns-changed(n) => {
|
||||
root.columns-changed(n);
|
||||
}
|
||||
motion-settled => {
|
||||
root.motion-settled();
|
||||
}
|
||||
row-renamed(row, text) => {
|
||||
root.row-renamed(row, text);
|
||||
}
|
||||
rename-cancelled => {
|
||||
root.rename-cancelled();
|
||||
}
|
||||
context-menu(row, x, y) => {
|
||||
root.activated();
|
||||
root.context-menu(row, x, y);
|
||||
}
|
||||
sort-by(column) => {
|
||||
root.activated();
|
||||
root.sort-by(column);
|
||||
}
|
||||
open-sort-menu(x, y) => {
|
||||
root.activated();
|
||||
root.open-sort-menu(x, y);
|
||||
}
|
||||
filter-typed(text) => {
|
||||
root.activated();
|
||||
root.filter-typed(text);
|
||||
}
|
||||
filter-edited(text) => {
|
||||
root.activated();
|
||||
root.filter-edited(text);
|
||||
}
|
||||
toggle-hidden => {
|
||||
root.activated();
|
||||
root.toggle-hidden();
|
||||
}
|
||||
row-clicked(row, ctrl, shift) => {
|
||||
root.activated();
|
||||
root.row-clicked(row, ctrl, shift);
|
||||
}
|
||||
row-activated(row) => {
|
||||
root.activated();
|
||||
root.row-activated(row);
|
||||
}
|
||||
select-all => {
|
||||
root.activated();
|
||||
root.select-all();
|
||||
}
|
||||
clear-selection => {
|
||||
root.activated();
|
||||
root.clear-selection();
|
||||
}
|
||||
navigate(key, shift, page) => {
|
||||
root.activated();
|
||||
root.navigate(key, shift, page)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import { IconButton } from "../components/icon-button.slint";
|
|||
import { ListRow } from "../components/list-row.slint";
|
||||
import { StateLayer } from "../components/state-layer.slint";
|
||||
import { ShapeKind } from "../components/shape.slint";
|
||||
import { Dnd, DropTarget, DropZone } from "../components/drop-menu.slint";
|
||||
|
||||
export struct PlaceItem {
|
||||
name: string,
|
||||
|
|
@ -104,6 +105,8 @@ export component Sidebar inherits Rectangle {
|
|||
// On the window's surface-container: the sidebar has no fill of its own.
|
||||
|
||||
Flickable {
|
||||
// Mouse drags start drags of bookmarks; the wheel scrolls.
|
||||
mouse-drag-pan-enabled: false;
|
||||
content-height: max(self.height, column.preferred-height);
|
||||
|
||||
column := VerticalLayout {
|
||||
|
|
@ -122,6 +125,13 @@ export component Sidebar inherits Rectangle {
|
|||
add => {
|
||||
root.add-bookmark();
|
||||
}
|
||||
|
||||
// Folders dropped on the header become bookmarks (Rust accepts only there).
|
||||
DropZone {
|
||||
target: DropTarget.bookmarks;
|
||||
a: s;
|
||||
radius: parent.border-radius;
|
||||
}
|
||||
}
|
||||
|
||||
// Folds to nothing: clipped while its height animates.
|
||||
|
|
@ -144,26 +154,52 @@ export component Sidebar inherits Rectangle {
|
|||
overflow: elide;
|
||||
}
|
||||
|
||||
for item[i] in section.items: ListRow {
|
||||
// Files dropped on the empty bookmarks text become bookmarks too.
|
||||
if section.items.length == 0: DropZone {
|
||||
target: DropTarget.bookmarks;
|
||||
a: s;
|
||||
radius: Theme.corner-full(root.row-height);
|
||||
}
|
||||
|
||||
// A place takes drops into its folder; a bookmark dragged onto another
|
||||
// takes its slot.
|
||||
for item[i] in section.items: Rectangle {
|
||||
x: 0;
|
||||
y: i * root.row-height;
|
||||
width: parent.width;
|
||||
height: root.row-height;
|
||||
icon: item.glyph;
|
||||
title: item.name;
|
||||
selected: item.current;
|
||||
shaped: true;
|
||||
shape: root.shapes[mod(i, root.shapes.length)];
|
||||
focusable: false;
|
||||
clicked => {
|
||||
root.open(s, i, false);
|
||||
}
|
||||
pointer(event) => {
|
||||
if event.kind == PointerEventKind.up && event.button == PointerEventButton.middle {
|
||||
root.open(s, i, true);
|
||||
}
|
||||
if event.kind == PointerEventKind.down && event.button == PointerEventButton.right {
|
||||
root.item-menu(s, i, self.absolute-position.x + self.mouse-x, self.absolute-position.y + root.row-height);
|
||||
|
||||
DropZone {
|
||||
target: DropTarget.place;
|
||||
a: s;
|
||||
b: i;
|
||||
radius: place.border-radius;
|
||||
|
||||
DragArea {
|
||||
enabled: section.can-add;
|
||||
allow-move: true;
|
||||
data: Dnd.bookmark-payload(i);
|
||||
|
||||
place := ListRow {
|
||||
height: root.row-height;
|
||||
icon: item.glyph;
|
||||
title: item.name;
|
||||
selected: item.current;
|
||||
shaped: true;
|
||||
shape: root.shapes[mod(i, root.shapes.length)];
|
||||
focusable: false;
|
||||
clicked => {
|
||||
root.open(s, i, false);
|
||||
}
|
||||
pointer(event) => {
|
||||
if event.kind == PointerEventKind.up && event.button == PointerEventButton.middle {
|
||||
root.open(s, i, true);
|
||||
}
|
||||
if event.kind == PointerEventKind.down && event.button == PointerEventButton.right {
|
||||
root.item-menu(s, i, self.absolute-position.x + self.mouse-x, self.absolute-position.y + root.row-height);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { Motion } from "../motion.slint";
|
|||
import { Icon, Icons } from "../components/icon.slint";
|
||||
import { IconButton } from "../components/icon-button.slint";
|
||||
import { StateLayer } from "../components/state-layer.slint";
|
||||
import { DropTarget, DropZone } from "../components/drop-menu.slint";
|
||||
|
||||
// One tab as Rust keeps it. Rows stay in the order the tabs were opened, so closing or moving
|
||||
// one never rebuilds the others; `slot` is the place it is shown at.
|
||||
|
|
@ -202,6 +203,21 @@ export component TabBar {
|
|||
root.moved(tab.id, root.drag-to);
|
||||
root.drag-id = -1;
|
||||
}
|
||||
|
||||
// A file drag that rests here opens the tab; a drop goes into its folder.
|
||||
tab-zone := DropZone {
|
||||
target: DropTarget.tab;
|
||||
a: tab.id;
|
||||
radius: parent.border-radius;
|
||||
|
||||
Timer {
|
||||
interval: Motion.drag-switch-delay;
|
||||
running: tab-zone.has-drag && tab.id != root.current;
|
||||
triggered => {
|
||||
root.selected(tab.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import { ListRow } from "../components/list-row.slint";
|
|||
import { FileShapes } from "../components/shape.slint";
|
||||
import { IconButton } from "../components/icon-button.slint";
|
||||
import { Chip, ChipKind } from "../components/chip.slint";
|
||||
import { Dnd, DropTarget, DropZone } from "../components/drop-menu.slint";
|
||||
|
||||
export enum SortColumn { name, size, type, modified, playlist }
|
||||
export enum Grouping { none, type, modified, size }
|
||||
|
|
@ -393,6 +394,8 @@ export component DetailsView inherits Rectangle {
|
|||
callback rename-cancelled();
|
||||
// A right click on a row (-1 for none) at window coordinates.
|
||||
callback context-menu(int, length, length);
|
||||
// This pane's index in the tab, for drag and drop.
|
||||
in property <int> pane;
|
||||
|
||||
// Narrow views drop the Type column so names keep their room.
|
||||
property <bool> compact: root.width < 640px;
|
||||
|
|
@ -583,65 +586,84 @@ export component DetailsView inherits Rectangle {
|
|||
accessible-role: text;
|
||||
}
|
||||
|
||||
if !row.header: ListRow {
|
||||
if !row.header: Rectangle {
|
||||
x: Columns.inset;
|
||||
width: parent.width - 2 * Columns.inset;
|
||||
focusable: false;
|
||||
icon: row.glyph;
|
||||
badge: row.badge;
|
||||
shaped: true;
|
||||
shape-size: 32px;
|
||||
shape: FileShapes.shape(row.glyph);
|
||||
active-shape: FileShapes.active-shape(row.glyph);
|
||||
shape-fill: FileShapes.fill(row.glyph);
|
||||
shape-ink: FileShapes.ink(row.glyph);
|
||||
title: row.name;
|
||||
selected: row.selected;
|
||||
editing: row.editing;
|
||||
edit-select: root.state.edit-select;
|
||||
opacity: row.dimmed ? Theme.disabled-content : 1;
|
||||
force-state: row.cursor && keys.has-focus ? ForceState.focused : ForceState.none;
|
||||
renamed(text) => {
|
||||
root.row-renamed(i, text);
|
||||
}
|
||||
rename-cancelled => {
|
||||
root.rename-cancelled();
|
||||
}
|
||||
pointer(event) => {
|
||||
if event.button == PointerEventButton.right && event.kind == PointerEventKind.down {
|
||||
root.context-menu(i, self.absolute-position.x + self.mouse-x, self.absolute-position.y + self.mouse-y);
|
||||
|
||||
DropZone {
|
||||
target: DropTarget.row;
|
||||
a: root.pane;
|
||||
b: i;
|
||||
radius: item.border-radius;
|
||||
|
||||
DragArea {
|
||||
enabled: !row.editing;
|
||||
allow-move: true;
|
||||
allow-copy: true;
|
||||
allow-link: true;
|
||||
data: Dnd.payload(root.pane, i, item.pressed);
|
||||
drag-image: Dnd.image(root.pane, i, item.pressed, Theme.secondary-container, Theme.on-secondary-container, Theme.primary, Theme.on-primary);
|
||||
|
||||
item := ListRow {
|
||||
focusable: false;
|
||||
icon: row.glyph;
|
||||
badge: row.badge;
|
||||
shaped: true;
|
||||
shape-size: 32px;
|
||||
shape: FileShapes.shape(row.glyph);
|
||||
active-shape: FileShapes.active-shape(row.glyph);
|
||||
shape-fill: FileShapes.fill(row.glyph);
|
||||
shape-ink: FileShapes.ink(row.glyph);
|
||||
title: row.name;
|
||||
selected: row.selected;
|
||||
editing: row.editing;
|
||||
edit-select: root.state.edit-select;
|
||||
opacity: row.dimmed ? Theme.disabled-content : 1;
|
||||
force-state: row.cursor && keys.has-focus ? ForceState.focused : ForceState.none;
|
||||
renamed(text) => {
|
||||
root.row-renamed(i, text);
|
||||
}
|
||||
rename-cancelled => {
|
||||
root.rename-cancelled();
|
||||
}
|
||||
pointer(event) => {
|
||||
if event.button == PointerEventButton.right && event.kind == PointerEventKind.down {
|
||||
root.context-menu(i, self.absolute-position.x + self.mouse-x, self.absolute-position.y + self.mouse-y);
|
||||
}
|
||||
}
|
||||
clicked => {
|
||||
keys.focus();
|
||||
root.row-clicked(i, self.modifiers.control, self.modifiers.shift);
|
||||
}
|
||||
double-clicked => {
|
||||
root.row-activated(i);
|
||||
}
|
||||
|
||||
Cell {
|
||||
width: Columns.size;
|
||||
text: row.size;
|
||||
end-aligned: true;
|
||||
color: row.selected ? Theme.on-secondary-container : Theme.on-surface-variant;
|
||||
}
|
||||
|
||||
if !root.compact: Cell {
|
||||
width: Columns.kind;
|
||||
text: row.kind;
|
||||
color: row.selected ? Theme.on-secondary-container : Theme.on-surface-variant;
|
||||
}
|
||||
|
||||
Cell {
|
||||
width: Columns.modified;
|
||||
text: row.modified;
|
||||
color: row.selected ? Theme.on-secondary-container : Theme.on-surface-variant;
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
width: Columns.tools;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
clicked => {
|
||||
keys.focus();
|
||||
root.row-clicked(i, self.modifiers.control, self.modifiers.shift);
|
||||
}
|
||||
double-clicked => {
|
||||
root.row-activated(i);
|
||||
}
|
||||
|
||||
Cell {
|
||||
width: Columns.size;
|
||||
text: row.size;
|
||||
end-aligned: true;
|
||||
color: row.selected ? Theme.on-secondary-container : Theme.on-surface-variant;
|
||||
}
|
||||
|
||||
if !root.compact: Cell {
|
||||
width: Columns.kind;
|
||||
text: row.kind;
|
||||
color: row.selected ? Theme.on-secondary-container : Theme.on-surface-variant;
|
||||
}
|
||||
|
||||
Cell {
|
||||
width: Columns.modified;
|
||||
text: row.modified;
|
||||
color: row.selected ? Theme.on-secondary-container : Theme.on-surface-variant;
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
width: Columns.tools;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import {
|
|||
Columns, DetailRow, FilterChip, FolderKeys, FolderMessages, FolderState, HeaderCell, NavKey,
|
||||
SortColumn,
|
||||
} from "details-view.slint";
|
||||
import { Dnd, DropTarget, DropZone } from "../components/drop-menu.slint";
|
||||
|
||||
// One line of the grid: a group header (`rows[start]` is the header row) or up to `columns`
|
||||
// cells for `rows[start .. start + count]`. Laid out by the folder model for the column count
|
||||
|
|
@ -132,6 +133,8 @@ export component GridView inherits Rectangle {
|
|||
in property <[GridRow]> lines;
|
||||
in property <FolderState> state;
|
||||
in property <float> motion: 1;
|
||||
// This pane's index in the tab, for drag and drop.
|
||||
in property <int> pane;
|
||||
in property <length> travel-x;
|
||||
in property <float> travel-opacity: 1;
|
||||
in property <length> travel-y;
|
||||
|
|
@ -321,7 +324,7 @@ export component GridView inherits Rectangle {
|
|||
}
|
||||
|
||||
if !line.header: Rectangle {
|
||||
for c in line.count: Rectangle {
|
||||
for c in line.count: cell := Rectangle {
|
||||
property <int> index: line.start + c;
|
||||
property <DetailRow> entry: root.rows[self.index];
|
||||
// Entering cells fade and grow in, leaving ones fade and
|
||||
|
|
@ -335,33 +338,52 @@ export component GridView inherits Rectangle {
|
|||
opacity: self.size;
|
||||
transform-scale: Motion.enter-scale + (1 - Motion.enter-scale) * self.size;
|
||||
|
||||
GridCell {
|
||||
Rectangle {
|
||||
x: Grid.gap;
|
||||
y: Grid.gap;
|
||||
width: parent.width - 2 * Grid.gap;
|
||||
height: parent.height - 2 * Grid.gap;
|
||||
entry: parent.entry;
|
||||
cursor-ring: parent.entry.cursor && keys.has-focus;
|
||||
edit-select: root.state.edit-select;
|
||||
opacity: parent.entry.dimmed ? Theme.disabled-content : 1;
|
||||
renamed(text) => {
|
||||
root.row-renamed(parent.index, text);
|
||||
}
|
||||
rename-cancelled => {
|
||||
root.rename-cancelled();
|
||||
}
|
||||
pointer(event) => {
|
||||
if event.button == PointerEventButton.right && event.kind == PointerEventKind.down {
|
||||
root.context-menu(parent.index, self.absolute-position.x + self.mouse-x, self.absolute-position.y + self.mouse-y);
|
||||
|
||||
DropZone {
|
||||
target: DropTarget.row;
|
||||
a: root.pane;
|
||||
b: cell.index;
|
||||
radius: tile.border-radius;
|
||||
|
||||
DragArea {
|
||||
enabled: !cell.entry.editing;
|
||||
allow-move: true;
|
||||
allow-copy: true;
|
||||
allow-link: true;
|
||||
data: Dnd.payload(root.pane, cell.index, tile.pressed);
|
||||
drag-image: Dnd.image(root.pane, cell.index, tile.pressed, Theme.secondary-container, Theme.on-secondary-container, Theme.primary, Theme.on-primary);
|
||||
|
||||
tile := GridCell {
|
||||
entry: cell.entry;
|
||||
cursor-ring: cell.entry.cursor && keys.has-focus;
|
||||
edit-select: root.state.edit-select;
|
||||
opacity: cell.entry.dimmed ? Theme.disabled-content : 1;
|
||||
renamed(text) => {
|
||||
root.row-renamed(cell.index, text);
|
||||
}
|
||||
rename-cancelled => {
|
||||
root.rename-cancelled();
|
||||
}
|
||||
pointer(event) => {
|
||||
if event.button == PointerEventButton.right && event.kind == PointerEventKind.down {
|
||||
root.context-menu(cell.index, self.absolute-position.x + self.mouse-x, self.absolute-position.y + self.mouse-y);
|
||||
}
|
||||
}
|
||||
clicked => {
|
||||
keys.focus();
|
||||
root.row-clicked(cell.index, self.modifiers.control, self.modifiers.shift);
|
||||
}
|
||||
double-clicked => {
|
||||
root.row-activated(cell.index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
clicked => {
|
||||
keys.focus();
|
||||
root.row-clicked(parent.index, self.modifiers.control, self.modifiers.shift);
|
||||
}
|
||||
double-clicked => {
|
||||
root.row-activated(parent.index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,6 +91,8 @@ export component FolderView inherits Rectangle {
|
|||
in property <[DetailRow]> rows;
|
||||
in property <[GridRow]> lines;
|
||||
in property <FolderState> state;
|
||||
// This pane's index in the tab, for drag and drop.
|
||||
in property <int> pane;
|
||||
|
||||
callback sort-by(SortColumn);
|
||||
callback open-sort-menu(length, length);
|
||||
|
|
@ -148,6 +150,7 @@ export component FolderView inherits Rectangle {
|
|||
|
||||
details := DetailsView {
|
||||
rows: root.rows;
|
||||
pane: root.pane;
|
||||
state: root.state;
|
||||
motion: list-clock.progress;
|
||||
travel-x: root.travel-x;
|
||||
|
|
@ -199,6 +202,7 @@ export component FolderView inherits Rectangle {
|
|||
|
||||
grid := GridView {
|
||||
rows: root.rows;
|
||||
pane: root.pane;
|
||||
lines: root.lines;
|
||||
state: root.state;
|
||||
motion: list-clock.progress;
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue