Skip to main content

blockworx_tools/
file.rs

1//! What the File flow asks for, and what comes back.
2//!
3//! Pure data: opening the dialog is the shell's, since a picker is a platform
4//! affordance, and what a *path* means is [`blockworx_store::file`]'s. What is
5//! here is the vocabulary [`crate::tool::Action`] carries between the two.
6//!
7//! What a *pick* is depends on the picker, so a [`crate::file::FilePick`]
8//! is a path: a shell whose documents are not files never opens one of
9//! these dialogs, and says so by never raising
10//! [`crate::file::FileRequest`].
11
12use std::path::PathBuf;
13use std::sync::mpsc::Receiver;
14
15use blockworx_doc::rev::Rev;
16use blockworx_store::doc::Viewing;
17
18/// What a Save-as writes: the document whole, or the history through the rev on
19/// the canvas.
20///
21/// Settled when the user asks rather than read again when the dialog
22/// returns: a native picker can sit open for minutes, and what lands must be
23/// what the menu promised — not whichever rev the stepper has walked to
24/// since.
25#[derive(Clone, Copy, PartialEq, Eq, Debug, serde::Serialize, serde::Deserialize)]
26pub enum SaveScope {
27    Whole,
28    Through(Rev),
29}
30
31impl From<Viewing> for SaveScope {
32    fn from(viewing: Viewing) -> Self {
33        match viewing {
34            Viewing::Head => SaveScope::Whole,
35            Viewing::Past(at) => SaveScope::Through(at),
36        }
37    }
38}
39
40/// What the File menu asked a dialog for.
41#[derive(Clone, Copy, PartialEq, Eq, Debug, serde::Serialize, serde::Deserialize)]
42pub enum FileRequest {
43    OpenContainer,
44    SaveAsContainer(SaveScope),
45}
46
47/// What a dialog picked, named for what the app does with it — so the
48/// dispatcher cannot mistake a container to open for a place to make one.
49#[derive(Clone, Debug, PartialEq, Eq)]
50pub enum FilePick {
51    Container(PathBuf),
52    NewContainer(PathBuf, SaveScope),
53}
54
55/// The channel a pending dialog delivers on: the pick, or `None` if the user
56/// cancelled.
57pub type PickReceiver = Receiver<Option<FilePick>>;