Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/platform_title_bar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ doctest = false
[dependencies]
feature_flags.workspace = true
gpui.workspace = true
project.workspace = true
settings.workspace = true
smallvec.workspace = true
theme.workspace = true
Expand Down
4 changes: 3 additions & 1 deletion crates/platform_title_bar/src/platform_title_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use gpui::{
MouseButton, ParentElement, StatefulInteractiveElement, Styled, Window, WindowControlArea, div,
px,
};
use project::DisableAiSettings;
use settings::Settings;
use smallvec::SmallVec;
use std::mem;
use ui::{
Expand Down Expand Up @@ -95,7 +97,7 @@ impl PlatformTitleBar {
}

pub fn is_multi_workspace_enabled(cx: &App) -> bool {
cx.has_flag::<AgentV2FeatureFlag>()
cx.has_flag::<AgentV2FeatureFlag>() && !DisableAiSettings::get_global(cx).disable_ai
}
}

Expand Down
6 changes: 4 additions & 2 deletions crates/title_bar/src/title_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ use gpui::{
StatefulInteractiveElement, Styled, Subscription, WeakEntity, Window, actions, div,
};
use onboarding_banner::OnboardingBanner;
use project::{Project, git_store::GitStoreEvent, trusted_worktrees::TrustedWorktrees};
use project::{
DisableAiSettings, Project, git_store::GitStoreEvent, trusted_worktrees::TrustedWorktrees,
};
use remote::RemoteConnectionOptions;
use settings::Settings;
use settings::WorktreeId;
Expand Down Expand Up @@ -686,7 +688,7 @@ impl TitleBar {
_window: &mut Window,
cx: &mut Context<Self>,
) -> Option<AnyElement> {
if !cx.has_flag::<AgentV2FeatureFlag>() {
if !cx.has_flag::<AgentV2FeatureFlag>() || DisableAiSettings::get_global(cx).disable_ai {
return None;
}

Expand Down
128 changes: 115 additions & 13 deletions crates/workspace/src/multi_workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use gpui::{
ManagedView, MouseButton, Pixels, Render, Subscription, Task, Tiling, Window, WindowId,
actions, deferred, px,
};
use project::Project;
use project::{DisableAiSettings, Project};
use settings::Settings;
use std::future::Future;
use std::path::PathBuf;
use ui::prelude::*;
Expand Down Expand Up @@ -122,6 +123,12 @@ impl MultiWorkspace {
}
});
let quit_subscription = cx.on_app_quit(Self::app_will_quit);
let settings_subscription =
cx.observe_global_in::<settings::SettingsStore>(window, |this, window, cx| {
if DisableAiSettings::get_global(cx).disable_ai && this.sidebar_open {
this.close_sidebar(window, cx);
}
});
Self::subscribe_to_workspace(&workspace, cx);
Self {
window_id: window.window_handle().window_id(),
Expand All @@ -133,7 +140,11 @@ impl MultiWorkspace {
pending_removal_tasks: Vec::new(),
_serialize_task: None,
_create_task: None,
_subscriptions: vec![release_subscription, quit_subscription],
_subscriptions: vec![
release_subscription,
quit_subscription,
settings_subscription,
],
}
}

Expand Down Expand Up @@ -169,7 +180,7 @@ impl MultiWorkspace {
}

pub fn multi_workspace_enabled(&self, cx: &App) -> bool {
cx.has_flag::<AgentV2FeatureFlag>()
cx.has_flag::<AgentV2FeatureFlag>() && !DisableAiSettings::get_global(cx).disable_ai
}

pub fn toggle_sidebar(&mut self, window: &mut Window, cx: &mut Context<Self>) {
Expand Down Expand Up @@ -732,16 +743,18 @@ impl Render for MultiWorkspace {
this.activate_previous_workspace(window, cx);
},
))
.on_action(cx.listener(
|this: &mut Self, _: &ToggleWorkspaceSidebar, window, cx| {
this.toggle_sidebar(window, cx);
},
))
.on_action(
cx.listener(|this: &mut Self, _: &FocusWorkspaceSidebar, window, cx| {
this.focus_sidebar(window, cx);
}),
)
.when(self.multi_workspace_enabled(cx), |this| {
this.on_action(cx.listener(
|this: &mut Self, _: &ToggleWorkspaceSidebar, window, cx| {
this.toggle_sidebar(window, cx);
},
))
.on_action(cx.listener(
|this: &mut Self, _: &FocusWorkspaceSidebar, window, cx| {
this.focus_sidebar(window, cx);
},
))
})
.when(
self.sidebar_open() && self.multi_workspace_enabled(cx),
|this| {
Expand Down Expand Up @@ -774,3 +787,92 @@ impl Render for MultiWorkspace {
)
}
}

#[cfg(test)]
mod tests {
use super::*;
use fs::FakeFs;
use gpui::TestAppContext;
use settings::SettingsStore;

fn init_test(cx: &mut TestAppContext) {
cx.update(|cx| {
let settings_store = SettingsStore::test(cx);
cx.set_global(settings_store);
theme::init(theme::LoadThemes::JustBase, cx);
DisableAiSettings::register(cx);
cx.update_flags(false, vec!["agent-v2".into()]);
});
}

#[gpui::test]
async fn test_sidebar_disabled_when_disable_ai_is_enabled(cx: &mut TestAppContext) {
init_test(cx);
let fs = FakeFs::new(cx.executor());
let project = Project::test(fs, [], cx).await;

let (multi_workspace, cx) =
cx.add_window_view(|window, cx| MultiWorkspace::test_new(project, window, cx));

multi_workspace.read_with(cx, |mw, cx| {
assert!(mw.multi_workspace_enabled(cx));
});

multi_workspace.update_in(cx, |mw, _window, cx| {
mw.open_sidebar(cx);
assert!(mw.is_sidebar_open());
});

cx.update(|_window, cx| {
DisableAiSettings::override_global(DisableAiSettings { disable_ai: true }, cx);
});
cx.run_until_parked();

multi_workspace.read_with(cx, |mw, cx| {
assert!(
!mw.is_sidebar_open(),
"Sidebar should be closed when disable_ai is true"
);
assert!(
!mw.multi_workspace_enabled(cx),
"Multi-workspace should be disabled when disable_ai is true"
);
});

multi_workspace.update_in(cx, |mw, window, cx| {
mw.toggle_sidebar(window, cx);
});
multi_workspace.read_with(cx, |mw, _cx| {
assert!(
!mw.is_sidebar_open(),
"Sidebar should remain closed when toggled with disable_ai true"
);
});

cx.update(|_window, cx| {
DisableAiSettings::override_global(DisableAiSettings { disable_ai: false }, cx);
});
cx.run_until_parked();

multi_workspace.read_with(cx, |mw, cx| {
assert!(
mw.multi_workspace_enabled(cx),
"Multi-workspace should be enabled after re-enabling AI"
);
assert!(
!mw.is_sidebar_open(),
"Sidebar should still be closed after re-enabling AI (not auto-opened)"
);
});

multi_workspace.update_in(cx, |mw, window, cx| {
mw.toggle_sidebar(window, cx);
});
multi_workspace.read_with(cx, |mw, _cx| {
assert!(
mw.is_sidebar_open(),
"Sidebar should open when toggled after re-enabling AI"
);
});
}
}