Implement new file/folder
This commit is contained in:
parent
0ed3f07ebc
commit
326fb4ba1f
4 changed files with 188 additions and 34 deletions
40
Cargo.lock
generated
40
Cargo.lock
generated
|
|
@ -110,9 +110,9 @@ checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ahash"
|
name = "ahash"
|
||||||
version = "0.8.9"
|
version = "0.8.10"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d713b3834d76b85304d4d525563c1276e2e30dc97cc67bfb4585a4a29fc2c89f"
|
checksum = "8b79b82693f705137f8fb9b37871d99e4f9a7df12b917eed79c3d3954830a60b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
"getrandom",
|
"getrandom",
|
||||||
|
|
@ -205,9 +205,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anstream"
|
name = "anstream"
|
||||||
version = "0.6.12"
|
version = "0.6.13"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "96b09b5178381e0874812a9b157f7fe84982617e48f71f4e3235482775e5b540"
|
checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anstyle",
|
"anstyle",
|
||||||
"anstyle-parse",
|
"anstyle-parse",
|
||||||
|
|
@ -1121,7 +1121,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cosmic-config"
|
name = "cosmic-config"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#a593f866efb25d149065b11714bb954c26d34cec"
|
source = "git+https://github.com/pop-os/libcosmic.git#7c3145828e780c6f6e9487f3f30486e5c44b4b2e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"atomicwrites",
|
"atomicwrites",
|
||||||
"cosmic-config-derive",
|
"cosmic-config-derive",
|
||||||
|
|
@ -1138,7 +1138,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cosmic-config-derive"
|
name = "cosmic-config-derive"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#a593f866efb25d149065b11714bb954c26d34cec"
|
source = "git+https://github.com/pop-os/libcosmic.git#7c3145828e780c6f6e9487f3f30486e5c44b4b2e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"quote",
|
"quote",
|
||||||
"syn 1.0.109",
|
"syn 1.0.109",
|
||||||
|
|
@ -1198,7 +1198,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cosmic-theme"
|
name = "cosmic-theme"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#a593f866efb25d149065b11714bb954c26d34cec"
|
source = "git+https://github.com/pop-os/libcosmic.git#7c3145828e780c6f6e9487f3f30486e5c44b4b2e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"almost",
|
"almost",
|
||||||
"cosmic-config",
|
"cosmic-config",
|
||||||
|
|
@ -2580,7 +2580,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced"
|
name = "iced"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#a593f866efb25d149065b11714bb954c26d34cec"
|
source = "git+https://github.com/pop-os/libcosmic.git#7c3145828e780c6f6e9487f3f30486e5c44b4b2e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"iced_accessibility",
|
"iced_accessibility",
|
||||||
"iced_core",
|
"iced_core",
|
||||||
|
|
@ -2595,7 +2595,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_accessibility"
|
name = "iced_accessibility"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#a593f866efb25d149065b11714bb954c26d34cec"
|
source = "git+https://github.com/pop-os/libcosmic.git#7c3145828e780c6f6e9487f3f30486e5c44b4b2e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"accesskit",
|
"accesskit",
|
||||||
"accesskit_winit",
|
"accesskit_winit",
|
||||||
|
|
@ -2604,7 +2604,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_core"
|
name = "iced_core"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#a593f866efb25d149065b11714bb954c26d34cec"
|
source = "git+https://github.com/pop-os/libcosmic.git#7c3145828e780c6f6e9487f3f30486e5c44b4b2e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.3.2",
|
||||||
"log",
|
"log",
|
||||||
|
|
@ -2621,7 +2621,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_futures"
|
name = "iced_futures"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#a593f866efb25d149065b11714bb954c26d34cec"
|
source = "git+https://github.com/pop-os/libcosmic.git#7c3145828e780c6f6e9487f3f30486e5c44b4b2e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures",
|
"futures",
|
||||||
"iced_core",
|
"iced_core",
|
||||||
|
|
@ -2634,7 +2634,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_graphics"
|
name = "iced_graphics"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#a593f866efb25d149065b11714bb954c26d34cec"
|
source = "git+https://github.com/pop-os/libcosmic.git#7c3145828e780c6f6e9487f3f30486e5c44b4b2e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.3.2",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
|
|
@ -2658,7 +2658,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_renderer"
|
name = "iced_renderer"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#a593f866efb25d149065b11714bb954c26d34cec"
|
source = "git+https://github.com/pop-os/libcosmic.git#7c3145828e780c6f6e9487f3f30486e5c44b4b2e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"iced_graphics",
|
"iced_graphics",
|
||||||
"iced_tiny_skia",
|
"iced_tiny_skia",
|
||||||
|
|
@ -2670,7 +2670,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_runtime"
|
name = "iced_runtime"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#a593f866efb25d149065b11714bb954c26d34cec"
|
source = "git+https://github.com/pop-os/libcosmic.git#7c3145828e780c6f6e9487f3f30486e5c44b4b2e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"iced_core",
|
"iced_core",
|
||||||
"iced_futures",
|
"iced_futures",
|
||||||
|
|
@ -2680,7 +2680,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_style"
|
name = "iced_style"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#a593f866efb25d149065b11714bb954c26d34cec"
|
source = "git+https://github.com/pop-os/libcosmic.git#7c3145828e780c6f6e9487f3f30486e5c44b4b2e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"iced_core",
|
"iced_core",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
|
|
@ -2690,7 +2690,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_tiny_skia"
|
name = "iced_tiny_skia"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#a593f866efb25d149065b11714bb954c26d34cec"
|
source = "git+https://github.com/pop-os/libcosmic.git#7c3145828e780c6f6e9487f3f30486e5c44b4b2e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"cosmic-text",
|
"cosmic-text",
|
||||||
|
|
@ -2707,7 +2707,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_wgpu"
|
name = "iced_wgpu"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#a593f866efb25d149065b11714bb954c26d34cec"
|
source = "git+https://github.com/pop-os/libcosmic.git#7c3145828e780c6f6e9487f3f30486e5c44b4b2e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.3.2",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
|
|
@ -2726,7 +2726,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_widget"
|
name = "iced_widget"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#a593f866efb25d149065b11714bb954c26d34cec"
|
source = "git+https://github.com/pop-os/libcosmic.git#7c3145828e780c6f6e9487f3f30486e5c44b4b2e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"iced_renderer",
|
"iced_renderer",
|
||||||
"iced_runtime",
|
"iced_runtime",
|
||||||
|
|
@ -2740,7 +2740,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_winit"
|
name = "iced_winit"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#a593f866efb25d149065b11714bb954c26d34cec"
|
source = "git+https://github.com/pop-os/libcosmic.git#7c3145828e780c6f6e9487f3f30486e5c44b4b2e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"iced_graphics",
|
"iced_graphics",
|
||||||
"iced_runtime",
|
"iced_runtime",
|
||||||
|
|
@ -3059,7 +3059,7 @@ checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libcosmic"
|
name = "libcosmic"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic.git#a593f866efb25d149065b11714bb954c26d34cec"
|
source = "git+https://github.com/pop-os/libcosmic.git#7c3145828e780c6f6e9487f3f30486e5c44b4b2e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"apply",
|
"apply",
|
||||||
"ashpd",
|
"ashpd",
|
||||||
|
|
|
||||||
|
|
@ -4,18 +4,31 @@ filesystem = Filesystem
|
||||||
home = Home
|
home = Home
|
||||||
trash = Trash
|
trash = Trash
|
||||||
|
|
||||||
# Dialog
|
# New File/Folder Dialog
|
||||||
|
create-new-file = Create new file
|
||||||
|
create-new-folder = Create new folder
|
||||||
|
file-name = File name
|
||||||
|
folder-name = Folder name
|
||||||
|
file-already-exists = A file with that name already exists.
|
||||||
|
folder-already-exists = A folder with that name already exists.
|
||||||
|
name-hidden = Names starting with "." will be hidden.
|
||||||
|
name-invalid = Name cannot be "{$filename}".
|
||||||
|
name-no-slashes = Name cannot contain slashes.
|
||||||
|
|
||||||
|
# Open/Save Dialog
|
||||||
cancel = Cancel
|
cancel = Cancel
|
||||||
open = Open
|
open = Open
|
||||||
open-file = Open file
|
open-file = Open file
|
||||||
open-folder = Open folder
|
open-folder = Open folder
|
||||||
open-multiple-files = Open multiple files
|
open-multiple-files = Open multiple files
|
||||||
open-multiple-folders = Open multiple folders
|
open-multiple-folders = Open multiple folders
|
||||||
|
save = Save
|
||||||
|
save-file = Save file
|
||||||
|
|
||||||
|
# Replace Dialog
|
||||||
replace = Replace
|
replace = Replace
|
||||||
replace-title = {$filename} already exists in this location.
|
replace-title = {$filename} already exists in this location.
|
||||||
replace-warning = Do you want to replace it with the one you are saving? Replacing it will overwrite its content.
|
replace-warning = Do you want to replace it with the one you are saving? Replacing it will overwrite its content.
|
||||||
save = Save
|
|
||||||
save-file = Save file
|
|
||||||
|
|
||||||
# List view
|
# List view
|
||||||
name = Name
|
name = Name
|
||||||
|
|
|
||||||
155
src/app.rs
155
src/app.rs
|
|
@ -75,8 +75,8 @@ impl Action {
|
||||||
Action::HistoryPrevious => Message::TabMessage(None, tab::Message::GoPrevious),
|
Action::HistoryPrevious => Message::TabMessage(None, tab::Message::GoPrevious),
|
||||||
Action::LocationUp => Message::TabMessage(None, tab::Message::LocationUp),
|
Action::LocationUp => Message::TabMessage(None, tab::Message::LocationUp),
|
||||||
Action::MoveToTrash => Message::MoveToTrash(entity_opt),
|
Action::MoveToTrash => Message::MoveToTrash(entity_opt),
|
||||||
Action::NewFile => Message::NewFile(entity_opt),
|
Action::NewFile => Message::NewItem(entity_opt, false),
|
||||||
Action::NewFolder => Message::NewFolder(entity_opt),
|
Action::NewFolder => Message::NewItem(entity_opt, true),
|
||||||
Action::Paste => Message::Paste(entity_opt),
|
Action::Paste => Message::Paste(entity_opt),
|
||||||
Action::Properties => Message::ToggleContextPage(ContextPage::Properties),
|
Action::Properties => Message::ToggleContextPage(ContextPage::Properties),
|
||||||
Action::RestoreFromTrash => Message::RestoreFromTrash(entity_opt),
|
Action::RestoreFromTrash => Message::RestoreFromTrash(entity_opt),
|
||||||
|
|
@ -106,11 +106,13 @@ pub enum Message {
|
||||||
Config(Config),
|
Config(Config),
|
||||||
Copy(Option<segmented_button::Entity>),
|
Copy(Option<segmented_button::Entity>),
|
||||||
Cut(Option<segmented_button::Entity>),
|
Cut(Option<segmented_button::Entity>),
|
||||||
|
DialogCancel,
|
||||||
|
DialogComplete,
|
||||||
|
DialogPage(DialogPage),
|
||||||
Key(Modifiers, Key),
|
Key(Modifiers, Key),
|
||||||
Modifiers(Modifiers),
|
Modifiers(Modifiers),
|
||||||
MoveToTrash(Option<segmented_button::Entity>),
|
MoveToTrash(Option<segmented_button::Entity>),
|
||||||
NewFile(Option<segmented_button::Entity>),
|
NewItem(Option<segmented_button::Entity>, bool),
|
||||||
NewFolder(Option<segmented_button::Entity>),
|
|
||||||
NotifyEvent(notify::Event),
|
NotifyEvent(notify::Event),
|
||||||
NotifyWatcher(WatcherWrapper),
|
NotifyWatcher(WatcherWrapper),
|
||||||
Paste(Option<segmented_button::Entity>),
|
Paste(Option<segmented_button::Entity>),
|
||||||
|
|
@ -150,6 +152,15 @@ impl ContextPage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
|
pub enum DialogPage {
|
||||||
|
NewItem {
|
||||||
|
parent: PathBuf,
|
||||||
|
name: String,
|
||||||
|
dir: bool,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct WatcherWrapper {
|
pub struct WatcherWrapper {
|
||||||
watcher_opt: Option<notify::RecommendedWatcher>,
|
watcher_opt: Option<notify::RecommendedWatcher>,
|
||||||
|
|
@ -176,6 +187,8 @@ pub struct App {
|
||||||
config: Config,
|
config: Config,
|
||||||
app_themes: Vec<String>,
|
app_themes: Vec<String>,
|
||||||
context_page: ContextPage,
|
context_page: ContextPage,
|
||||||
|
dialog_page: Option<DialogPage>,
|
||||||
|
dialog_text_input: widget::Id,
|
||||||
key_binds: HashMap<KeyBind, Action>,
|
key_binds: HashMap<KeyBind, Action>,
|
||||||
modifiers: Modifiers,
|
modifiers: Modifiers,
|
||||||
pending_operation_id: u64,
|
pending_operation_id: u64,
|
||||||
|
|
@ -500,6 +513,8 @@ impl Application for App {
|
||||||
config: flags.config,
|
config: flags.config,
|
||||||
app_themes,
|
app_themes,
|
||||||
context_page: ContextPage::Settings,
|
context_page: ContextPage::Settings,
|
||||||
|
dialog_page: None,
|
||||||
|
dialog_text_input: widget::Id::unique(),
|
||||||
key_binds: key_binds(),
|
key_binds: key_binds(),
|
||||||
modifiers: Modifiers::empty(),
|
modifiers: Modifiers::empty(),
|
||||||
pending_operation_id: 0,
|
pending_operation_id: 0,
|
||||||
|
|
@ -566,6 +581,11 @@ impl Application for App {
|
||||||
fn on_escape(&mut self) -> Command<Self::Message> {
|
fn on_escape(&mut self) -> Command<Self::Message> {
|
||||||
let entity = self.tab_model.active();
|
let entity = self.tab_model.active();
|
||||||
|
|
||||||
|
// Close dialog if open
|
||||||
|
if self.dialog_page.take().is_some() {
|
||||||
|
return Command::none();
|
||||||
|
}
|
||||||
|
|
||||||
// Close menus and context panes in order per message
|
// Close menus and context panes in order per message
|
||||||
// Why: It'd be weird to close everything all at once
|
// Why: It'd be weird to close everything all at once
|
||||||
// Usually, the Escape key (for example) closes menus and panes one by one instead
|
// Usually, the Escape key (for example) closes menus and panes one by one instead
|
||||||
|
|
@ -627,6 +647,32 @@ impl Application for App {
|
||||||
Message::Cut(_entity_opt) => {
|
Message::Cut(_entity_opt) => {
|
||||||
log::warn!("TODO: CUT");
|
log::warn!("TODO: CUT");
|
||||||
}
|
}
|
||||||
|
Message::DialogCancel => {
|
||||||
|
self.dialog_page = None;
|
||||||
|
}
|
||||||
|
Message::DialogComplete => {
|
||||||
|
if let Some(dialog_page) = self.dialog_page.take() {
|
||||||
|
match dialog_page {
|
||||||
|
DialogPage::NewItem { parent, name, dir } => {
|
||||||
|
let path = parent.join(name);
|
||||||
|
match if dir {
|
||||||
|
fs::create_dir(&path)
|
||||||
|
} else {
|
||||||
|
fs::File::create(&path).map(|_| ())
|
||||||
|
} {
|
||||||
|
Ok(()) => {}
|
||||||
|
Err(err) => {
|
||||||
|
//TODO: dialog
|
||||||
|
log::warn!("failed to create {:?}: {}", path, err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Message::DialogPage(dialog_page) => {
|
||||||
|
self.dialog_page = Some(dialog_page);
|
||||||
|
}
|
||||||
Message::Key(modifiers, key) => {
|
Message::Key(modifiers, key) => {
|
||||||
let entity = self.tab_model.active();
|
let entity = self.tab_model.active();
|
||||||
for (key_bind, action) in self.key_binds.iter() {
|
for (key_bind, action) in self.key_binds.iter() {
|
||||||
|
|
@ -654,11 +700,20 @@ impl Application for App {
|
||||||
self.operation(Operation::Delete { paths });
|
self.operation(Operation::Delete { paths });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::NewFile(_entity_opt) => {
|
Message::NewItem(entity_opt, dir) => {
|
||||||
log::warn!("TODO: NEW FILE");
|
if self.dialog_page.is_none() {
|
||||||
}
|
let entity = entity_opt.unwrap_or_else(|| self.tab_model.active());
|
||||||
Message::NewFolder(_entity_opt) => {
|
if let Some(tab) = self.tab_model.data_mut::<Tab>(entity) {
|
||||||
log::warn!("TODO: NEW FOLDER");
|
if let Location::Path(path) = &tab.location {
|
||||||
|
self.dialog_page = Some(DialogPage::NewItem {
|
||||||
|
parent: path.clone(),
|
||||||
|
name: String::new(),
|
||||||
|
dir,
|
||||||
|
});
|
||||||
|
return widget::text_input::focus(self.dialog_text_input.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Message::NotifyEvent(event) => {
|
Message::NotifyEvent(event) => {
|
||||||
log::debug!("{:?}", event);
|
log::debug!("{:?}", event);
|
||||||
|
|
@ -931,6 +986,88 @@ impl Application for App {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn dialog(&self) -> Option<Element<Message>> {
|
||||||
|
let dialog_page = match &self.dialog_page {
|
||||||
|
Some(some) => some,
|
||||||
|
None => return None,
|
||||||
|
};
|
||||||
|
|
||||||
|
let cosmic_theme::Spacing { space_xxs, .. } = self.core().system_theme().cosmic().spacing;
|
||||||
|
|
||||||
|
let dialog = match dialog_page {
|
||||||
|
DialogPage::NewItem { parent, name, dir } => {
|
||||||
|
let mut dialog = widget::dialog(if *dir {
|
||||||
|
fl!("create-new-folder")
|
||||||
|
} else {
|
||||||
|
fl!("create-new-file")
|
||||||
|
});
|
||||||
|
|
||||||
|
let complete_maybe = if name.is_empty() {
|
||||||
|
None
|
||||||
|
} else if name == "." || name == ".." {
|
||||||
|
dialog = dialog.tertiary_action(widget::text::body(fl!(
|
||||||
|
"name-invalid",
|
||||||
|
filename = name.as_str()
|
||||||
|
)));
|
||||||
|
None
|
||||||
|
} else if name.contains('/') {
|
||||||
|
dialog = dialog.tertiary_action(widget::text::body(fl!("name-no-slashes")));
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
let path = parent.join(name);
|
||||||
|
if path.exists() {
|
||||||
|
if path.is_dir() {
|
||||||
|
dialog = dialog
|
||||||
|
.tertiary_action(widget::text::body(fl!("folder-already-exists")));
|
||||||
|
} else {
|
||||||
|
dialog = dialog
|
||||||
|
.tertiary_action(widget::text::body(fl!("file-already-exists")));
|
||||||
|
}
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
if name.starts_with('.') {
|
||||||
|
dialog = dialog.tertiary_action(widget::text::body(fl!("name-hidden")));
|
||||||
|
}
|
||||||
|
Some(Message::DialogComplete)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
dialog
|
||||||
|
.primary_action(
|
||||||
|
widget::button::suggested(fl!("save"))
|
||||||
|
.on_press_maybe(complete_maybe.clone()),
|
||||||
|
)
|
||||||
|
.secondary_action(
|
||||||
|
widget::button::standard(fl!("cancel")).on_press(Message::DialogCancel),
|
||||||
|
)
|
||||||
|
.control(
|
||||||
|
widget::column::with_children(vec![
|
||||||
|
widget::text::body(if *dir {
|
||||||
|
fl!("folder-name")
|
||||||
|
} else {
|
||||||
|
fl!("file-name")
|
||||||
|
})
|
||||||
|
.into(),
|
||||||
|
widget::text_input("", name.as_str())
|
||||||
|
.id(self.dialog_text_input.clone())
|
||||||
|
.on_input(move |name| {
|
||||||
|
Message::DialogPage(DialogPage::NewItem {
|
||||||
|
parent: parent.clone(),
|
||||||
|
name,
|
||||||
|
dir: *dir,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.on_submit_maybe(complete_maybe)
|
||||||
|
.into(),
|
||||||
|
])
|
||||||
|
.spacing(space_xxs),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Some(dialog.into())
|
||||||
|
}
|
||||||
|
|
||||||
fn header_start(&self) -> Vec<Element<Self::Message>> {
|
fn header_start(&self) -> Vec<Element<Self::Message>> {
|
||||||
vec![menu::menu_bar(&self.key_binds).into()]
|
vec![menu::menu_bar(&self.key_binds).into()]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -372,8 +372,12 @@ impl Application for App {
|
||||||
widget::dialog(fl!("replace-title", filename = filename.as_str()))
|
widget::dialog(fl!("replace-title", filename = filename.as_str()))
|
||||||
.icon(widget::icon::from_name("dialog-question").size(64))
|
.icon(widget::icon::from_name("dialog-question").size(64))
|
||||||
.body(fl!("replace-warning"))
|
.body(fl!("replace-warning"))
|
||||||
.primary_action(fl!("replace"), Message::Save(true))
|
.primary_action(
|
||||||
.secondary_action(fl!("cancel"), Message::Cancel)
|
widget::button::suggested(fl!("replace")).on_press(Message::Save(true)),
|
||||||
|
)
|
||||||
|
.secondary_action(
|
||||||
|
widget::button::standard(fl!("cancel")).on_press(Message::Cancel),
|
||||||
|
)
|
||||||
.into(),
|
.into(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue