zed: Fix migration message sometimes showing up on other tabs (#29917)
<img width="1178" alt="image" src="https://github.com/user-attachments/assets/6b76fe7d-0621-4d61-936e-bfe4f72cc614" /> Release Notes: - Fixed an issue where the keymap/settings migration message sometimes showing up on tabs other than `settings.json` and `keymap.json`.
This commit is contained in:
parent
c765da1c82
commit
4a7b3aa4b8
1 changed files with 8 additions and 7 deletions
|
@ -7,7 +7,7 @@ use util::ResultExt;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use gpui::{Entity, EventEmitter, Global};
|
use gpui::{Entity, EventEmitter, Global, Task};
|
||||||
use ui::prelude::*;
|
use ui::prelude::*;
|
||||||
use workspace::item::ItemHandle;
|
use workspace::item::ItemHandle;
|
||||||
use workspace::{ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView, Workspace};
|
use workspace::{ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView, Workspace};
|
||||||
|
@ -20,6 +20,7 @@ pub enum MigrationType {
|
||||||
|
|
||||||
pub struct MigrationBanner {
|
pub struct MigrationBanner {
|
||||||
migration_type: Option<MigrationType>,
|
migration_type: Option<MigrationType>,
|
||||||
|
should_migrate_task: Option<Task<()>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum MigrationEvent {
|
pub enum MigrationEvent {
|
||||||
|
@ -61,6 +62,7 @@ impl MigrationBanner {
|
||||||
}
|
}
|
||||||
Self {
|
Self {
|
||||||
migration_type: None,
|
migration_type: None,
|
||||||
|
should_migrate_task: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,6 +112,7 @@ impl ToolbarItemView for MigrationBanner {
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) -> ToolbarItemLocation {
|
) -> ToolbarItemLocation {
|
||||||
cx.notify();
|
cx.notify();
|
||||||
|
self.should_migrate_task.take();
|
||||||
let Some(target) = active_pane_item
|
let Some(target) = active_pane_item
|
||||||
.and_then(|item| item.act_as::<Editor>(cx))
|
.and_then(|item| item.act_as::<Editor>(cx))
|
||||||
.and_then(|editor| editor.update(cx, |editor, cx| editor.target_file_abs_path(cx)))
|
.and_then(|editor| editor.update(cx, |editor, cx| editor.target_file_abs_path(cx)))
|
||||||
|
@ -121,7 +124,7 @@ impl ToolbarItemView for MigrationBanner {
|
||||||
self.migration_type = Some(MigrationType::Keymap);
|
self.migration_type = Some(MigrationType::Keymap);
|
||||||
let fs = <dyn Fs>::global(cx);
|
let fs = <dyn Fs>::global(cx);
|
||||||
let should_migrate = should_migrate_keymap(fs);
|
let should_migrate = should_migrate_keymap(fs);
|
||||||
cx.spawn_in(window, async move |this, cx| {
|
self.should_migrate_task = Some(cx.spawn_in(window, async move |this, cx| {
|
||||||
if let Ok(true) = should_migrate.await {
|
if let Ok(true) = should_migrate.await {
|
||||||
this.update(cx, |_, cx| {
|
this.update(cx, |_, cx| {
|
||||||
cx.emit(ToolbarItemEvent::ChangeLocation(
|
cx.emit(ToolbarItemEvent::ChangeLocation(
|
||||||
|
@ -131,13 +134,12 @@ impl ToolbarItemView for MigrationBanner {
|
||||||
})
|
})
|
||||||
.log_err();
|
.log_err();
|
||||||
}
|
}
|
||||||
})
|
}));
|
||||||
.detach();
|
|
||||||
} else if &target == paths::settings_file() {
|
} else if &target == paths::settings_file() {
|
||||||
self.migration_type = Some(MigrationType::Settings);
|
self.migration_type = Some(MigrationType::Settings);
|
||||||
let fs = <dyn Fs>::global(cx);
|
let fs = <dyn Fs>::global(cx);
|
||||||
let should_migrate = should_migrate_settings(fs);
|
let should_migrate = should_migrate_settings(fs);
|
||||||
cx.spawn_in(window, async move |this, cx| {
|
self.should_migrate_task = Some(cx.spawn_in(window, async move |this, cx| {
|
||||||
if let Ok(true) = should_migrate.await {
|
if let Ok(true) = should_migrate.await {
|
||||||
this.update(cx, |_, cx| {
|
this.update(cx, |_, cx| {
|
||||||
cx.emit(ToolbarItemEvent::ChangeLocation(
|
cx.emit(ToolbarItemEvent::ChangeLocation(
|
||||||
|
@ -147,8 +149,7 @@ impl ToolbarItemView for MigrationBanner {
|
||||||
})
|
})
|
||||||
.log_err();
|
.log_err();
|
||||||
}
|
}
|
||||||
})
|
}));
|
||||||
.detach();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ToolbarItemLocation::Hidden;
|
return ToolbarItemLocation::Hidden;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue