improv: feature gate for xdg_portal

This commit is contained in:
Ashley Wulber 2026-07-15 15:24:46 -04:00 • committed by Ashley Wulber
parent 8e6aea650a
commit 63568a8d9c
12 changed files with 53 additions and 53 deletions

View file

@ -90,7 +90,7 @@ pub mod open;
/// Save file dialog.
pub mod save;
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
pub use ashpd::desktop::file_chooser::{Choice, FileFilter};
use thiserror::Error;
@ -139,7 +139,7 @@ pub enum Error {
UrlAbsolute,
}
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
pub type DialogError = ashpd::Error;
#[cfg(feature = "rfd")]

View file

@ -6,7 +6,7 @@
//! Check out the [open-dialog](https://github.com/pop-os/libcosmic/tree/master/examples/open-dialog)
//! example in our repository.
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
pub use portal::{FileResponse, MultiFileResponse, file, files, folder, folders};
#[cfg(feature = "rfd")]
@ -24,7 +24,7 @@ pub struct Dialog {
title: String,
/// The label for the accept button. Mnemonic underlines are allowed.
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
#[setters(skip)]
accept_label: Option<String>,
@ -39,17 +39,17 @@ pub struct Dialog {
file_name: Option<String>,
/// Modal dialogs require user input before continuing the program.
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
#[setters(skip)]
modal: bool,
/// Adds a list of choices.
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
#[setters(skip)]
choices: Vec<super::Choice>,
/// Specifies the default file filter.
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
#[setters(skip)]
current_filter: Option<super::FileFilter>,
@ -62,36 +62,36 @@ impl Dialog {
pub const fn new() -> Self {
Self {
title: String::new(),
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
accept_label: None,
directory: None,
file_name: None,
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
modal: true,
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
current_filter: None,
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
choices: Vec::new(),
filters: Vec::new(),
}
}
/// The label for the accept button. Mnemonic underlines are allowed.
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
pub fn accept_label(mut self, label: impl Into<String>) -> Self {
self.accept_label = Some(label.into());
self
}
/// Adds a choice.
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
pub fn choice(mut self, choice: impl Into<super::Choice>) -> Self {
self.choices.push(choice.into());
self
}
/// Specifies the default file filter.
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
pub fn current_filter(mut self, filter: impl Into<super::FileFilter>) -> Self {
self.current_filter = Some(filter.into());
self
@ -104,7 +104,7 @@ impl Dialog {
}
/// Modal dialogs require user input before continuing the program.
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
pub fn modal(mut self, modal: bool) -> Self {
self.modal = modal;
self
@ -131,7 +131,7 @@ impl Dialog {
}
}
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
mod portal {
use super::Dialog;
use crate::dialog::file_chooser::Error;
@ -147,7 +147,7 @@ mod portal {
}
/// Creates a new file dialog, and begins to await its responses.
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
pub async fn create(
dialog: super::Dialog,
folders: bool,

View file

@ -6,7 +6,7 @@
//! Check out the [open-dialog](https://github.com/pop-os/libcosmic/tree/master/examples/open-dialog)
//! example in our repository.
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
pub use portal::{Response, file};
#[cfg(feature = "rfd")]
@ -23,12 +23,12 @@ pub struct Dialog {
title: String,
/// The label for the accept button. Mnemonic underlines are allowed.
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
#[setters(skip)]
accept_label: Option<String>,
/// Modal dialogs require user input before continuing the program.
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
#[setters(skip)]
modal: bool,
@ -41,17 +41,17 @@ pub struct Dialog {
directory: Option<PathBuf>,
/// Sets the absolute path of the file
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
#[setters(skip)]
current_file: Option<PathBuf>,
/// Adds a list of choices.
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
#[setters(skip)]
choices: Vec<super::Choice>,
/// Specifies the default file filter.
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
#[setters(skip)]
current_filter: Option<super::FileFilter>,
@ -64,38 +64,38 @@ impl Dialog {
pub const fn new() -> Self {
Self {
title: String::new(),
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
accept_label: None,
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
modal: true,
file_name: None,
directory: None,
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
current_file: None,
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
current_filter: None,
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
choices: Vec::new(),
filters: Vec::new(),
}
}
/// The label for the accept button. Mnemonic underlines are allowed.
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
pub fn accept_label(mut self, label: impl Into<String>) -> Self {
self.accept_label = Some(label.into());
self
}
/// Adds a choice.
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
pub fn choice(mut self, choice: impl Into<super::Choice>) -> Self {
self.choices.push(choice.into());
self
}
/// Set the current file filter.
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
pub fn current_filter(mut self, filter: impl Into<super::FileFilter>) -> Self {
self.current_filter = Some(filter.into());
self
@ -108,7 +108,7 @@ impl Dialog {
}
/// Modal dialogs require user input before continuing the program.
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
pub fn modal(mut self, modal: bool) -> Self {
self.modal = modal;
self
@ -126,7 +126,7 @@ impl Default for Dialog {
}
}
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
mod portal {
use super::Dialog;
use crate::dialog::file_chooser::Error;

View file

@ -3,7 +3,7 @@
//! Create dialogs for retrieving user input.
#[cfg(feature = "xdg-portal")]
#[cfg(xdg_portal)]
pub use ashpd;
pub mod file_chooser;