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
|
@ -1,7 +1,7 @@
|
|||
use crate::{
|
||||
AnyView, AnyWindowHandle, App, AppCell, AppContext, BackgroundExecutor, BorrowAppContext,
|
||||
Entity, EventEmitter, Focusable, ForegroundExecutor, Global, PromptLevel, Render, Reservation,
|
||||
Result, Subscription, Task, VisualContext, Window, WindowHandle,
|
||||
Entity, EventEmitter, Focusable, ForegroundExecutor, Global, PromptButton, PromptLevel, Render,
|
||||
Reservation, Result, Subscription, Task, VisualContext, Window, WindowHandle,
|
||||
};
|
||||
use anyhow::Context as _;
|
||||
use derive_more::{Deref, DerefMut};
|
||||
|
@ -314,13 +314,16 @@ impl AsyncWindowContext {
|
|||
/// Present a platform dialog.
|
||||
/// The provided message will be presented, along with buttons for each answer.
|
||||
/// When a button is clicked, the returned Receiver will receive the index of the clicked button.
|
||||
pub fn prompt(
|
||||
pub fn prompt<T>(
|
||||
&mut self,
|
||||
level: PromptLevel,
|
||||
message: &str,
|
||||
detail: Option<&str>,
|
||||
answers: &[&str],
|
||||
) -> oneshot::Receiver<usize> {
|
||||
answers: &[T],
|
||||
) -> oneshot::Receiver<usize>
|
||||
where
|
||||
T: Clone + Into<PromptButton>,
|
||||
{
|
||||
self.window
|
||||
.update(self, |_, window, cx| {
|
||||
window.prompt(level, message, detail, answers, cx)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue