gpui: Improve window.prompt
to support ESC with non-English cancel text on macOS (#29538)
Release Notes: - N/A ---- The before version GPUI used `Cancel` for cancel text, if we use non-English text (e.g.: "取消" in Chinese), then the press `Esc` to cancel will not work. So this PR to change it by use `PromptButton` to instead the `&str`, then we can use `PromptButton::cancel("取消")` for the `Cancel` button. Run `cargo run -p gpui --example window` to test. --- Platform Test: - [x] macOS - [x] Windows - [x] Linux (x11 and Wayland) --------- Co-authored-by: Mikayla Maki <mikayla@zed.dev> Co-authored-by: Mikayla Maki <mikayla.c.maki@gmail.com>
This commit is contained in:
parent
1d5d3de85c
commit
047e7eacec
14 changed files with 174 additions and 66 deletions
|
@ -608,7 +608,7 @@ impl PlatformWindow for WindowsWindow {
|
|||
level: PromptLevel,
|
||||
msg: &str,
|
||||
detail: Option<&str>,
|
||||
answers: &[&str],
|
||||
answers: &[PromptButton],
|
||||
) -> Option<Receiver<usize>> {
|
||||
let (done_tx, done_rx) = oneshot::channel();
|
||||
let msg = msg.to_string();
|
||||
|
@ -616,8 +616,8 @@ impl PlatformWindow for WindowsWindow {
|
|||
Some(info) => Some(info.to_string()),
|
||||
None => None,
|
||||
};
|
||||
let answers = answers.iter().map(|s| s.to_string()).collect::<Vec<_>>();
|
||||
let handle = self.0.hwnd;
|
||||
let answers = answers.to_vec();
|
||||
self.0
|
||||
.executor
|
||||
.spawn(async move {
|
||||
|
@ -653,9 +653,9 @@ impl PlatformWindow for WindowsWindow {
|
|||
let mut button_id_map = Vec::with_capacity(answers.len());
|
||||
let mut buttons = Vec::new();
|
||||
let mut btn_encoded = Vec::new();
|
||||
for (index, btn_string) in answers.iter().enumerate() {
|
||||
let encoded = HSTRING::from(btn_string);
|
||||
let button_id = if btn_string == "Cancel" {
|
||||
for (index, btn) in answers.iter().enumerate() {
|
||||
let encoded = HSTRING::from(btn.label().as_ref());
|
||||
let button_id = if btn.is_cancel() {
|
||||
IDCANCEL.0
|
||||
} else {
|
||||
index as i32 - 100
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue