1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//! Common commands.
//!

use zng_ext_clipboard::{COPY_CMD, CUT_CMD, PASTE_CMD};
use zng_wgt::{prelude::*, ICONS};

command! {
    /// Represents the **new** action.
    ///
    /// The command parameter can identify the new item type, otherwise the default (or single) type
    /// must be used.
    pub static NEW_CMD = {
        l10n!: true,
        name: "New",
        shortcut: [shortcut!(CTRL+'N'), shortcut!(New)],
    };

    /// Represents the **open** action.
    ///
    /// The command parameter can be an item path to open (like a `PathBuf`), otherwise the
    /// command implementer must identify the item, either by context or by prompting the user.
    pub static OPEN_CMD = {
        l10n!: true,
        name: "Open…",
        shortcut: [shortcut!(CTRL+'O'), shortcut!(Open)],
        icon: wgt_fn!(|_| ICONS.get("file-open")),
    };

    /// Represents the **save** action.
    ///
    /// Usually this saves to the already defined item path (open or previous save path),
    /// otherwise the user is prompted like [`SAVE_AS_CMD`].
    pub static SAVE_CMD = {
        l10n!: true,
        name: "Save",
        shortcut: [shortcut!(CTRL+'S'), shortcut!(Save)],
        icon: wgt_fn!(|_| ICONS.get("save")),
    };

    /// Represents the **save-as** action.
    ///
    /// Usually this prompts the user for a save path, even if a previous path is already known.
    pub static SAVE_AS_CMD = {
        l10n!: true,
        name: "Save As…",
        shortcut: [shortcut!(CTRL|SHIFT+'S')],
    };

    /// Represents the **context menu open** action.
    pub static CONTEXT_MENU_CMD = {
        shortcut: [shortcut!(SHIFT+F10), shortcut!(ContextMenu)],
        icon: wgt_fn!(|_| ICONS.get(["context-menu", "menu-open"])),
    };

    /// Represents the **open settings** action.
    ///
    /// Settings is an editor for a selection of app configs.
    ///
    /// # Parameter
    ///
    /// The parameter can be a `Txt` that can match a `ConfigKey` or config metadata
    /// such as the display name or description.
    pub static SETTINGS_CMD = {
        l10n!: true,
        name: "Settings",
        shortcut: [shortcut!(CTRL+',')],
        icon: wgt_fn!(|_| ICONS.get("settings")),
    };
}

command_property! {
    /// On new command.
    ///
    /// Receives [`NEW_CMD`] command events scoped on the widget. The command parameter can be
    /// the new item type identifier.
    pub fn new {
        cmd: NEW_CMD.scoped(WIDGET.id()),
    }

    /// On open command.
    ///
    /// Receives [`OPEN_CMD`] command events scoped on the widget. The command parameter can be
    /// a path to open, otherwise the path must be derived from context or the user prompted.
    ///
    /// You can use [`WINDOWS.native_file_dialog`] to prompt the user for a file or folder path.
    ///
    /// [`WINDOWS.native_file_dialog`]: zng_ext_window::WINDOWS::native_file_dialog
    pub fn open {
        cmd: OPEN_CMD.scoped(WIDGET.id()),
    }

    /// On save command.
    ///
    /// Receives [`SAVE_CMD`] command events scoped on the widget. Usually saves to the last
    /// open or save path, otherwise prompt the user like [`on_save_as`].
    ///
    /// You can use [`WINDOWS.native_file_dialog`] to prompt the user for a file or folder path.
    ///
    /// [`WINDOWS.native_file_dialog`]: zng_ext_window::WINDOWS::native_file_dialog
    /// [`on_save_as`]: fn@on_save_as
    pub fn save {
        cmd: SAVE_CMD.scoped(WIDGET.id()),
    }

    /// On save-as command.
    ///
    /// Receives [`SAVE_AS_CMD`] command events scoped on the widget. Usually prompts the user for
    /// a new save path.
    ///
    /// You can use [`WINDOWS.native_file_dialog`] to prompt the user for a file or folder path.
    ///
    /// [`WINDOWS.native_file_dialog`]: zng_ext_window::WINDOWS::native_file_dialog
    pub fn save_as {
        cmd: SAVE_AS_CMD.scoped(WIDGET.id()),
    }

    /// On cut command.
    ///
    /// Receives [`CUT_CMD`] command events scoped on the widget. You can use the `CLIPBOARD` service
    /// to send data to the clipboard.
    ///
    /// [`CUT_CMD`]: zng_ext_clipboard::CUT_CMD
    pub fn cut {
        cmd: CUT_CMD.scoped(WIDGET.id()),
    }

    /// On copy command.
    ///
    /// Receives [`COPY_CMD`] command events scoped on the widget. You can use the `CLIPBOARD` service
    /// to send data to the clipboard.
    ///
    /// [`COPY_CMD`]: zng_ext_clipboard::COPY_CMD
    pub fn copy {
        cmd: COPY_CMD.scoped(WIDGET.id()),
    }

    /// On paste command.
    ///
    /// Receives [`PASTE_CMD`] command events scoped on the widget. You can use the `CLIPBOARD` service
    /// to receive data from the clipboard.
    ///
    /// [`PASTE_CMD`]: zng_ext_clipboard::PASTE_CMD
    pub fn paste {
        cmd: PASTE_CMD.scoped(WIDGET.id()),
    }

    /// On settings command.
    ///
    /// Receives [`SETTINGS_CMD`] command events scoped on the widget.
    pub fn settings {
        cmd: SETTINGS_CMD.scoped(WIDGET.id()),
    }
}