Forward selected path to caller
This commit is contained in:
parent
c6eecbddd8
commit
2832e6066e
3 changed files with 39 additions and 9 deletions
|
|
@ -1,3 +1,11 @@
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
cosmic_files::dialog()
|
match cosmic_files::dialog()? {
|
||||||
|
Some(paths) => {
|
||||||
|
for path in paths {
|
||||||
|
println!("{}", path.display());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => {}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,13 @@ use cosmic::{
|
||||||
Application, ApplicationExt, Element,
|
Application, ApplicationExt, Element,
|
||||||
};
|
};
|
||||||
use notify::Watcher;
|
use notify::Watcher;
|
||||||
use std::{any::TypeId, collections::HashSet, path::PathBuf, time};
|
use std::{
|
||||||
|
any::TypeId,
|
||||||
|
collections::HashSet,
|
||||||
|
path::PathBuf,
|
||||||
|
sync::{Arc, Mutex},
|
||||||
|
time,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
fl, home_dir,
|
fl, home_dir,
|
||||||
|
|
@ -24,7 +30,9 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Flags {}
|
pub struct Flags {
|
||||||
|
pub result_lock: Arc<Mutex<Option<Vec<PathBuf>>>>,
|
||||||
|
}
|
||||||
|
|
||||||
/// Messages that are used specifically by our [`App`].
|
/// Messages that are used specifically by our [`App`].
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
|
@ -61,6 +69,7 @@ impl PartialEq for WatcherWrapper {
|
||||||
/// The [`App`] stores application-specific state.
|
/// The [`App`] stores application-specific state.
|
||||||
pub struct App {
|
pub struct App {
|
||||||
core: Core,
|
core: Core,
|
||||||
|
flags: Flags,
|
||||||
nav_model: segmented_button::SingleSelectModel,
|
nav_model: segmented_button::SingleSelectModel,
|
||||||
tab_model: segmented_button::Model<segmented_button::SingleSelect>,
|
tab_model: segmented_button::Model<segmented_button::SingleSelect>,
|
||||||
modifiers: Modifiers,
|
modifiers: Modifiers,
|
||||||
|
|
@ -221,6 +230,7 @@ impl Application for App {
|
||||||
|
|
||||||
let mut app = App {
|
let mut app = App {
|
||||||
core,
|
core,
|
||||||
|
flags,
|
||||||
nav_model: nav_model.build(),
|
nav_model: nav_model.build(),
|
||||||
tab_model: segmented_button::ModelBuilder::default().build(),
|
tab_model: segmented_button::ModelBuilder::default().build(),
|
||||||
modifiers: Modifiers::empty(),
|
modifiers: Modifiers::empty(),
|
||||||
|
|
@ -274,7 +284,8 @@ impl Application for App {
|
||||||
fn update(&mut self, message: Self::Message) -> Command<Self::Message> {
|
fn update(&mut self, message: Self::Message) -> Command<Self::Message> {
|
||||||
match message {
|
match message {
|
||||||
Message::Cancel => {
|
Message::Cancel => {
|
||||||
println!("CANCEL");
|
*self.flags.result_lock.lock().unwrap() = None;
|
||||||
|
return window::close(window::Id::MAIN);
|
||||||
}
|
}
|
||||||
Message::Modifiers(modifiers) => {
|
Message::Modifiers(modifiers) => {
|
||||||
self.modifiers = modifiers;
|
self.modifiers = modifiers;
|
||||||
|
|
@ -329,7 +340,8 @@ impl Application for App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println!("OPEN {:?}", paths);
|
*self.flags.result_lock.lock().unwrap() = Some(paths);
|
||||||
|
return window::close(window::Id::MAIN);
|
||||||
}
|
}
|
||||||
Message::SelectAll(entity_opt) => {
|
Message::SelectAll(entity_opt) => {
|
||||||
let entity = entity_opt.unwrap_or_else(|| self.tab_model.active());
|
let entity = entity_opt.unwrap_or_else(|| self.tab_model.active());
|
||||||
|
|
|
||||||
18
src/lib.rs
18
src/lib.rs
|
|
@ -5,7 +5,11 @@ use cosmic::{
|
||||||
app::{Application, Settings},
|
app::{Application, Settings},
|
||||||
cosmic_config::{self, CosmicConfigEntry},
|
cosmic_config::{self, CosmicConfigEntry},
|
||||||
};
|
};
|
||||||
use std::{path::PathBuf, process};
|
use std::{
|
||||||
|
path::PathBuf,
|
||||||
|
process,
|
||||||
|
sync::{Arc, Mutex},
|
||||||
|
};
|
||||||
|
|
||||||
use app::{App, Flags};
|
use app::{App, Flags};
|
||||||
mod app;
|
mod app;
|
||||||
|
|
@ -31,7 +35,7 @@ pub fn home_dir() -> PathBuf {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Runs application with these settings
|
/// Runs application with these settings
|
||||||
pub fn dialog() -> Result<(), Box<dyn std::error::Error>> {
|
pub fn dialog() -> Result<Option<Vec<PathBuf>>, Box<dyn std::error::Error>> {
|
||||||
localize::localize();
|
localize::localize();
|
||||||
|
|
||||||
let mut settings = Settings::default();
|
let mut settings = Settings::default();
|
||||||
|
|
@ -42,10 +46,16 @@ pub fn dialog() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
settings = settings.client_decorations(false);
|
settings = settings.client_decorations(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
let flags = dialog::Flags {};
|
let mut result_lock = Arc::new(Mutex::new(None));
|
||||||
|
|
||||||
|
let flags = dialog::Flags {
|
||||||
|
result_lock: result_lock.clone(),
|
||||||
|
};
|
||||||
cosmic::app::run::<dialog::App>(settings, flags)?;
|
cosmic::app::run::<dialog::App>(settings, flags)?;
|
||||||
|
|
||||||
Ok(())
|
let mut result_guard = result_lock.lock().unwrap();
|
||||||
|
let result = result_guard.take();
|
||||||
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Runs application with these settings
|
/// Runs application with these settings
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue