Detailed changes
@@ -116,6 +116,7 @@ pub fn init(cx: &mut App) {
files: false,
directories: true,
multiple: false,
+ prompt: None,
},
DirectoryLister::Local(
workspace.project().clone(),
@@ -2088,6 +2088,7 @@ impl GitPanel {
files: false,
directories: true,
multiple: false,
+ prompt: Some("Select as Repository Destination".into()),
});
let workspace = self.workspace.clone();
@@ -1278,7 +1278,7 @@ pub enum WindowBackgroundAppearance {
}
/// The options that can be configured for a file dialog prompt
-#[derive(Copy, Clone, Debug)]
+#[derive(Clone, Debug)]
pub struct PathPromptOptions {
/// Should the prompt allow files to be selected?
pub files: bool,
@@ -1286,6 +1286,8 @@ pub struct PathPromptOptions {
pub directories: bool,
/// Should the prompt allow multiple files to be selected?
pub multiple: bool,
+ /// The prompt to show to a user when selecting a path
+ pub prompt: Option<SharedString>,
}
/// What kind of prompt styling to show
@@ -294,6 +294,7 @@ impl<P: LinuxClient + 'static> Platform for P {
let request = match ashpd::desktop::file_chooser::OpenFileRequest::default()
.modal(true)
.title(title)
+ .accept_label(options.prompt.as_ref().map(crate::SharedString::as_str))
.multiple(options.multiple)
.directory(options.directories)
.send()
@@ -705,6 +705,7 @@ impl Platform for MacPlatform {
panel.setCanChooseDirectories_(options.directories.to_objc());
panel.setCanChooseFiles_(options.files.to_objc());
panel.setAllowsMultipleSelection_(options.multiple.to_objc());
+
panel.setCanCreateDirectories(true.to_objc());
panel.setResolvesAliases_(false.to_objc());
let done_tx = Cell::new(Some(done_tx));
@@ -730,6 +731,11 @@ impl Platform for MacPlatform {
}
});
let block = block.copy();
+
+ if let Some(prompt) = options.prompt {
+ let _: () = msg_send![panel, setPrompt: ns_string(&prompt)];
+ }
+
let _: () = msg_send![panel, beginWithCompletionHandler: block];
}
})
@@ -787,6 +787,12 @@ fn file_open_dialog(
unsafe {
folder_dialog.SetOptions(dialog_options)?;
+
+ if let Some(prompt) = options.prompt {
+ let prompt: &str = &prompt;
+ folder_dialog.SetOkButtonLabel(&HSTRING::from(prompt))?;
+ }
+
if folder_dialog.Show(window).is_err() {
// User cancelled
return Ok(None);
@@ -23,6 +23,11 @@ impl SharedString {
pub fn new(str: impl Into<Arc<str>>) -> Self {
SharedString(ArcCow::Owned(str.into()))
}
+
+ /// Get a &str from the underlying string.
+ pub fn as_str(&self) -> &str {
+ &self.0
+ }
}
impl JsonSchema for SharedString {
@@ -561,6 +561,7 @@ pub fn init(app_state: Arc<AppState>, cx: &mut App) {
files: true,
directories: true,
multiple: true,
+ prompt: None,
},
cx,
);
@@ -578,6 +579,7 @@ pub fn init(app_state: Arc<AppState>, cx: &mut App) {
files: true,
directories,
multiple: true,
+ prompt: None,
},
cx,
);
@@ -2655,6 +2657,7 @@ impl Workspace {
files: false,
directories: true,
multiple: true,
+ prompt: None,
},
DirectoryLister::Project(self.project.clone()),
window,
@@ -645,6 +645,7 @@ fn register_actions(
files: true,
directories: true,
multiple: true,
+ prompt: None,
},
DirectoryLister::Local(
workspace.project().clone(),
@@ -685,6 +686,7 @@ fn register_actions(
files: true,
directories: true,
multiple: true,
+ prompt: None,
},
DirectoryLister::Project(workspace.project().clone()),
window,