From b670d2387d47a33cf8b447f9565080e4dcb9ff5b Mon Sep 17 00:00:00 2001 From: Benjamin Klum Date: Mon, 4 Nov 2024 21:34:24 +0100 Subject: [PATCH] Medium-level API: get_user_file_name_for_read --- main/medium/src/reaper.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/main/medium/src/reaper.rs b/main/medium/src/reaper.rs index 9f8b19b1..007d4696 100644 --- a/main/medium/src/reaper.rs +++ b/main/medium/src/reaper.rs @@ -3391,6 +3391,33 @@ impl Reaper { NonNull::new(ptr) } + /// Opens a file picker. + /// + /// Returns `None` if the user canceled the dialog. + pub fn get_user_file_name_for_read<'a>( + &self, + path: &Utf8Path, + title: impl Into>, + defext: impl Into>, + ) -> Option + where + UsageScope: MainThreadOnly, + { + self.require_main_thread(); + let (file, successful) = + with_string_buffer_prefilled(path.to_string(), 4096, |buffer, _| unsafe { + self.low.GetUserFileNameForRead( + buffer, + title.into().as_ptr(), + defext.into().as_ptr(), + ) + }); + if !successful { + return None; + } + Some(Utf8PathBuf::from(file.into_string())) + } + /// Grants temporary access to the "reaper.ini" full filename. pub fn get_ini_file(&self, use_ini_file: impl FnOnce(&Utf8Path) -> R) -> R where