Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion crates/settings_ui/src/settings_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,9 @@ pub fn open_settings_editor(

if let Some(existing_window) = existing_window {
existing_window
.update(cx, |settings_window, window, _| {
.update(cx, |settings_window, window, cx| {
settings_window.original_window = Some(workspace_handle);
settings_window.observe_workspace_release(window, cx);
window.activate_window();
})
.ok();
Expand Down Expand Up @@ -518,6 +519,7 @@ fn sub_page_stack_mut() -> std::sync::RwLockWriteGuard<'static, Vec<SubPage>> {

pub struct SettingsWindow {
original_window: Option<WindowHandle<Workspace>>,
workspace_release_subscription: Option<Subscription>,
files: Vec<(SettingsUiFile, FocusHandle)>,
worktree_root_dirs: HashMap<WorktreeId, String>,
current_file: SettingsUiFile,
Expand Down Expand Up @@ -884,6 +886,7 @@ impl SettingsWindow {

let mut this = Self {
original_window,
workspace_release_subscription: None,
worktree_root_dirs: HashMap::default(),
files: vec![],
current_file: current_file,
Expand Down Expand Up @@ -915,6 +918,8 @@ impl SettingsWindow {
.tab_stop(false),
};

this.observe_workspace_release(window, cx);

this.fetch_files(window, cx);
this.build_ui(window, cx);

Expand All @@ -925,6 +930,26 @@ impl SettingsWindow {
this
}

fn observe_workspace_release(&mut self, window: &mut Window, cx: &mut Context<Self>) {
// Drop the old subscription if any
self.workspace_release_subscription = None;

if let Some(workspace_handle) = self.original_window {
let workspace_entity_result =
workspace_handle.update(cx, |_workspace, _window, cx| cx.entity());

if let Ok(workspace_entity) = workspace_entity_result {
self.workspace_release_subscription = Some(cx.observe_release_in(
&workspace_entity,
window,
|_this, _workspace, window, _cx| {
window.remove_window();
},
));
}
}
}

fn toggle_navbar_entry(&mut self, ix: usize) {
// We can only toggle root entries
if !self.navbar_entries[ix].is_root {
Expand Down Expand Up @@ -2338,6 +2363,7 @@ mod test {

let mut settings_window = SettingsWindow {
original_window: None,
workspace_release_subscription: None,
worktree_root_dirs: HashMap::default(),
files: Vec::default(),
current_file: crate::SettingsUiFile::User,
Expand Down