add ability to pass appid through to file dialogs (#1042)
* dialog: add new Dialog::create() method with new DialogSettings struct to allow passing app_id from portal; deprecating Dialog::new() * dialog: remove deprecation, move to builder pattern, add path_opt and kind options to DialogSettings * dialog: instances of -> DialogSettings to -> Self
This commit is contained in:
parent
d74576e446
commit
aba90279e6
2 changed files with 48 additions and 10 deletions
|
|
@ -66,6 +66,7 @@ use trash::TrashItem;
|
||||||
#[cfg(all(feature = "wayland", feature = "desktop-applet"))]
|
#[cfg(all(feature = "wayland", feature = "desktop-applet"))]
|
||||||
use wayland_client::{protocol::wl_output::WlOutput, Proxy};
|
use wayland_client::{protocol::wl_output::WlOutput, Proxy};
|
||||||
|
|
||||||
|
use crate::dialog::DialogSettings;
|
||||||
use crate::{
|
use crate::{
|
||||||
clipboard::{ClipboardCopy, ClipboardKind, ClipboardPaste},
|
clipboard::{ClipboardCopy, ClipboardKind, ClipboardPaste},
|
||||||
config::{
|
config::{
|
||||||
|
|
@ -2562,8 +2563,9 @@ impl Application for App {
|
||||||
.map(|parent| parent.to_path_buf())
|
.map(|parent| parent.to_path_buf())
|
||||||
{
|
{
|
||||||
let (mut dialog, dialog_task) = Dialog::new(
|
let (mut dialog, dialog_task) = Dialog::new(
|
||||||
DialogKind::OpenFolder,
|
DialogSettings::new()
|
||||||
Some(destination),
|
.kind(DialogKind::OpenFolder)
|
||||||
|
.path(destination),
|
||||||
Message::FileDialogMessage,
|
Message::FileDialogMessage,
|
||||||
Message::ExtractToResult,
|
Message::ExtractToResult,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -204,6 +204,43 @@ impl<'a, M: Clone + 'static> From<&'a DialogLabel> for Element<'a, M> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct DialogSettings {
|
||||||
|
app_id: String,
|
||||||
|
kind: DialogKind,
|
||||||
|
path_opt: Option<PathBuf>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DialogSettings {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Default::default()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn app_id(mut self, app_id: String) -> Self {
|
||||||
|
self.app_id = app_id;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn kind(mut self, kind: DialogKind) -> Self {
|
||||||
|
self.kind = kind;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn path(mut self, path: PathBuf) -> Self {
|
||||||
|
self.path_opt = Some(path);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for DialogSettings {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
app_id: App::APP_ID.to_string(),
|
||||||
|
kind: DialogKind::OpenFile,
|
||||||
|
path_opt: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Dialog<M> {
|
pub struct Dialog<M> {
|
||||||
cosmic: Cosmic<App>,
|
cosmic: Cosmic<App>,
|
||||||
mapper: fn(DialogMessage) -> M,
|
mapper: fn(DialogMessage) -> M,
|
||||||
|
|
@ -212,8 +249,7 @@ pub struct Dialog<M> {
|
||||||
|
|
||||||
impl<M: Send + 'static> Dialog<M> {
|
impl<M: Send + 'static> Dialog<M> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
kind: DialogKind,
|
dialog_settings: DialogSettings,
|
||||||
path_opt: Option<PathBuf>,
|
|
||||||
mapper: fn(DialogMessage) -> M,
|
mapper: fn(DialogMessage) -> M,
|
||||||
on_result: impl Fn(DialogResult) -> M + 'static,
|
on_result: impl Fn(DialogResult) -> M + 'static,
|
||||||
) -> (Self, Task<M>) {
|
) -> (Self, Task<M>) {
|
||||||
|
|
@ -234,7 +270,7 @@ impl<M: Send + 'static> Dialog<M> {
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
{
|
{
|
||||||
settings.platform_specific.application_id = App::APP_ID.to_string();
|
settings.platform_specific.application_id = dialog_settings.app_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
let (window_id, window_command) = window::open(settings.clone());
|
let (window_id, window_command) = window::open(settings.clone());
|
||||||
|
|
@ -242,16 +278,16 @@ impl<M: Send + 'static> Dialog<M> {
|
||||||
let mut core = Core::default();
|
let mut core = Core::default();
|
||||||
core.set_main_window_id(Some(window_id));
|
core.set_main_window_id(Some(window_id));
|
||||||
let flags = Flags {
|
let flags = Flags {
|
||||||
kind,
|
kind: dialog_settings.kind,
|
||||||
path_opt: path_opt
|
path_opt: dialog_settings.path_opt.as_ref().and_then(|path| {
|
||||||
.as_ref()
|
match fs::canonicalize(path) {
|
||||||
.and_then(|path| match fs::canonicalize(path) {
|
|
||||||
Ok(ok) => Some(ok),
|
Ok(ok) => Some(ok),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
log::warn!("failed to canonicalize {:?}: {}", path, err);
|
log::warn!("failed to canonicalize {:?}: {}", path, err);
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}),
|
}
|
||||||
|
}),
|
||||||
window_id,
|
window_id,
|
||||||
config_handler,
|
config_handler,
|
||||||
config,
|
config,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue