Refactor workspace notifications to use explicit NotificationId
type (#10342)
This PR reworks the way workspace notifications are identified to use a new `NotificationId` type. A `NotificationId` is bound to a given type that is used as a unique identifier. Generally this will be a unit struct that can be used to uniquely identify this notification. A `NotificationId` can also accept an optional `ElementId` in order to distinguish between different notifications of the same type. This system avoids the issue we had previously of selecting `usize` IDs somewhat arbitrarily and running the risk of having two independent notifications collide (and thus interfere with each other). This also fixes a bug where multiple suggestion notifications for the same extension could be live at once Fixes https://github.com/zed-industries/zed/issues/10320. Release Notes: - Fixed a bug where multiple extension suggestions for the same extension could be shown at once ([#10320](https://github.com/zed-industries/zed/issues/10320)). --------- Co-authored-by: Max <max@zed.dev>
This commit is contained in:
parent
322f68f3d6
commit
8cbdd9e0fa
12 changed files with 212 additions and 98 deletions
|
@ -34,6 +34,7 @@ use task::{
|
|||
static_source::{StaticSource, TrackedFile},
|
||||
};
|
||||
use theme::ActiveTheme;
|
||||
use workspace::notifications::NotificationId;
|
||||
|
||||
use terminal_view::terminal_panel::{self, TerminalPanel};
|
||||
use util::{
|
||||
|
@ -253,9 +254,11 @@ pub fn initialize_workspace(app_state: Arc<AppState>, cx: &mut AppContext) {
|
|||
.await
|
||||
.context("error creating CLI symlink")?;
|
||||
workspace.update(&mut cx, |workspace, cx| {
|
||||
struct InstalledZedCli;
|
||||
|
||||
workspace.show_toast(
|
||||
Toast::new(
|
||||
0,
|
||||
NotificationId::unique::<InstalledZedCli>(),
|
||||
format!(
|
||||
"Installed `zed` to {}. You can launch {} from your terminal.",
|
||||
path.to_string_lossy(),
|
||||
|
@ -274,9 +277,11 @@ pub fn initialize_workspace(app_state: Arc<AppState>, cx: &mut AppContext) {
|
|||
cx.spawn(|workspace, mut cx| async move {
|
||||
register_zed_scheme(&cx).await?;
|
||||
workspace.update(&mut cx, |workspace, cx| {
|
||||
struct RegisterZedScheme;
|
||||
|
||||
workspace.show_toast(
|
||||
Toast::new(
|
||||
0,
|
||||
NotificationId::unique::<RegisterZedScheme>(),
|
||||
format!(
|
||||
"zed:// links will now open in {}.",
|
||||
ReleaseChannel::global(cx).display_name()
|
||||
|
@ -555,14 +560,20 @@ fn open_log_file(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
|
|||
workspace
|
||||
.update(&mut cx, |workspace, cx| {
|
||||
let Some(log) = log else {
|
||||
workspace.show_notification(29, cx, |cx| {
|
||||
cx.new_view(|_| {
|
||||
MessageNotification::new(format!(
|
||||
"Unable to access/open log file at path {:?}",
|
||||
paths::LOG.as_path()
|
||||
))
|
||||
})
|
||||
});
|
||||
struct OpenLogError;
|
||||
|
||||
workspace.show_notification(
|
||||
NotificationId::unique::<OpenLogError>(),
|
||||
cx,
|
||||
|cx| {
|
||||
cx.new_view(|_| {
|
||||
MessageNotification::new(format!(
|
||||
"Unable to access/open log file at path {:?}",
|
||||
paths::LOG.as_path()
|
||||
))
|
||||
})
|
||||
},
|
||||
);
|
||||
return;
|
||||
};
|
||||
let project = workspace.project().clone();
|
||||
|
@ -749,7 +760,9 @@ fn open_local_file(
|
|||
})
|
||||
.detach();
|
||||
} else {
|
||||
workspace.show_notification(0, cx, |cx| {
|
||||
struct NoOpenFolders;
|
||||
|
||||
workspace.show_notification(NotificationId::unique::<NoOpenFolders>(), cx, |cx| {
|
||||
cx.new_view(|_| MessageNotification::new("This project has no folders open."))
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue