Prevent toggle_dock
from opening assistant panel when it is disabled via settings (#27215)
Part of #27171 Follows-up the change in https://github.com/zed-industries/zed/pull/22346 to consider the case where the assistant-panel is disabled via settings (as also noted in [this comment](https://github.com/zed-industries/zed/pull/22346#issuecomment-2558372412), Notably, only the explicit case is considered here. Can extend this change to also cover the implicit case where the button is disabled if requested.). Currently, if the user toggles the right dock, the assistant panel will be shown even if it is disabled via settings, because it has the highest priority (see https://github.com/zed-industries/zed/pull/22346#issuecomment-2564890493). With this change, the assistant panel is no longer activated when disabled and the dock with the next highest activation order is activated instead. I did not opt in to make the priority configurabe, as I agree with https://github.com/zed-industries/zed/pull/22346#issuecomment-2564890493 that this will most likely rarely be used (the active panel is only none on the first toggle of the dock, afterwards it remains set for the remainder of the session). Release Notes: - `workspace::ToggleRightDock` will no longer open the assistant panel when it is disabled via settings.
This commit is contained in:
parent
a360365410
commit
ca9fb2399e
7 changed files with 81 additions and 49 deletions
|
@ -15,7 +15,7 @@ use client::Client;
|
||||||
use command_palette_hooks::CommandPaletteFilter;
|
use command_palette_hooks::CommandPaletteFilter;
|
||||||
use feature_flags::FeatureFlagAppExt;
|
use feature_flags::FeatureFlagAppExt;
|
||||||
use fs::Fs;
|
use fs::Fs;
|
||||||
use gpui::{actions, App, Global, UpdateGlobal};
|
use gpui::{actions, App, Global, ReadGlobal, UpdateGlobal};
|
||||||
use language_model::{
|
use language_model::{
|
||||||
LanguageModelId, LanguageModelProviderId, LanguageModelRegistry, LanguageModelResponseMessage,
|
LanguageModelId, LanguageModelProviderId, LanguageModelRegistry, LanguageModelResponseMessage,
|
||||||
};
|
};
|
||||||
|
@ -86,6 +86,10 @@ impl Assistant {
|
||||||
filter.show_namespace(Self::NAMESPACE);
|
filter.show_namespace(Self::NAMESPACE);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn enabled(cx: &App) -> bool {
|
||||||
|
Self::global(cx).enabled
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init(
|
pub fn init(
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use crate::assistant_configuration::{ConfigurationView, ConfigurationViewEvent};
|
use crate::assistant_configuration::{ConfigurationView, ConfigurationViewEvent};
|
||||||
|
use crate::Assistant;
|
||||||
use crate::{
|
use crate::{
|
||||||
terminal_inline_assistant::TerminalInlineAssistant, DeployHistory, InlineAssistant, NewChat,
|
terminal_inline_assistant::TerminalInlineAssistant, DeployHistory, InlineAssistant, NewChat,
|
||||||
};
|
};
|
||||||
|
@ -58,8 +59,7 @@ pub fn init(cx: &mut App) {
|
||||||
|
|
||||||
cx.observe_new(
|
cx.observe_new(
|
||||||
|terminal_panel: &mut TerminalPanel, _, cx: &mut Context<TerminalPanel>| {
|
|terminal_panel: &mut TerminalPanel, _, cx: &mut Context<TerminalPanel>| {
|
||||||
let settings = AssistantSettings::get_global(cx);
|
terminal_panel.set_assistant_enabled(Assistant::enabled(cx), cx);
|
||||||
terminal_panel.set_assistant_enabled(settings.enabled, cx);
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.detach();
|
.detach();
|
||||||
|
@ -342,12 +342,12 @@ impl AssistantPanel {
|
||||||
window: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut Context<Workspace>,
|
cx: &mut Context<Workspace>,
|
||||||
) {
|
) {
|
||||||
let settings = AssistantSettings::get_global(cx);
|
if workspace
|
||||||
if !settings.enabled {
|
.panel::<Self>(cx)
|
||||||
return;
|
.is_some_and(|panel| panel.read(cx).enabled(cx))
|
||||||
|
{
|
||||||
|
workspace.toggle_panel_focus::<Self>(window, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
workspace.toggle_panel_focus::<Self>(window, cx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn watch_client_status(
|
fn watch_client_status(
|
||||||
|
@ -595,12 +595,10 @@ impl AssistantPanel {
|
||||||
window: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut Context<Workspace>,
|
cx: &mut Context<Workspace>,
|
||||||
) {
|
) {
|
||||||
let settings = AssistantSettings::get_global(cx);
|
let Some(assistant_panel) = workspace
|
||||||
if !settings.enabled {
|
.panel::<AssistantPanel>(cx)
|
||||||
return;
|
.filter(|panel| panel.read(cx).enabled(cx))
|
||||||
}
|
else {
|
||||||
|
|
||||||
let Some(assistant_panel) = workspace.panel::<AssistantPanel>(cx) else {
|
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1298,12 +1296,8 @@ impl Panel for AssistantPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn icon(&self, _: &Window, cx: &App) -> Option<IconName> {
|
fn icon(&self, _: &Window, cx: &App) -> Option<IconName> {
|
||||||
let settings = AssistantSettings::get_global(cx);
|
(self.enabled(cx) && AssistantSettings::get_global(cx).button)
|
||||||
if !settings.enabled || !settings.button {
|
.then_some(IconName::ZedAssistant)
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
Some(IconName::ZedAssistant)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn icon_tooltip(&self, _: &Window, _: &App) -> Option<&'static str> {
|
fn icon_tooltip(&self, _: &Window, _: &App) -> Option<&'static str> {
|
||||||
|
@ -1317,6 +1311,10 @@ impl Panel for AssistantPanel {
|
||||||
fn activation_priority(&self) -> u32 {
|
fn activation_priority(&self) -> u32 {
|
||||||
4
|
4
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn enabled(&self, cx: &App) -> bool {
|
||||||
|
Assistant::enabled(cx)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventEmitter<PanelEvent> for AssistantPanel {}
|
impl EventEmitter<PanelEvent> for AssistantPanel {}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
AssistantPanel, AssistantPanelEvent, CycleNextInlineAssist, CyclePreviousInlineAssist,
|
Assistant, AssistantPanel, AssistantPanelEvent, CycleNextInlineAssist,
|
||||||
|
CyclePreviousInlineAssist,
|
||||||
};
|
};
|
||||||
use anyhow::{anyhow, Context as _, Result};
|
use anyhow::{anyhow, Context as _, Result};
|
||||||
use assistant_context_editor::{humanize_token_count, RequestType};
|
use assistant_context_editor::{humanize_token_count, RequestType};
|
||||||
|
@ -3555,7 +3556,7 @@ impl CodeActionProvider for AssistantCodeActionProvider {
|
||||||
_: &mut Window,
|
_: &mut Window,
|
||||||
cx: &mut App,
|
cx: &mut App,
|
||||||
) -> Task<Result<Vec<CodeAction>>> {
|
) -> Task<Result<Vec<CodeAction>>> {
|
||||||
if !AssistantSettings::get_global(cx).enabled {
|
if !Assistant::enabled(cx) {
|
||||||
return Task::ready(Ok(Vec::new()));
|
return Task::ready(Ok(Vec::new()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -225,12 +225,12 @@ impl AssistantPanel {
|
||||||
window: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut Context<Workspace>,
|
cx: &mut Context<Workspace>,
|
||||||
) {
|
) {
|
||||||
let settings = AssistantSettings::get_global(cx);
|
if workspace
|
||||||
if !settings.enabled {
|
.panel::<Self>(cx)
|
||||||
return;
|
.is_some_and(|panel| panel.read(cx).enabled(cx))
|
||||||
|
{
|
||||||
|
workspace.toggle_panel_focus::<Self>(window, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
workspace.toggle_panel_focus::<Self>(window, cx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn local_timezone(&self) -> UtcOffset {
|
pub(crate) fn local_timezone(&self) -> UtcOffset {
|
||||||
|
@ -637,12 +637,8 @@ impl Panel for AssistantPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn icon(&self, _window: &Window, cx: &App) -> Option<IconName> {
|
fn icon(&self, _window: &Window, cx: &App) -> Option<IconName> {
|
||||||
let settings = AssistantSettings::get_global(cx);
|
(self.enabled(cx) && AssistantSettings::get_global(cx).button)
|
||||||
if !settings.enabled || !settings.button {
|
.then_some(IconName::ZedAssistant)
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
Some(IconName::ZedAssistant)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn icon_tooltip(&self, _window: &Window, _cx: &App) -> Option<&'static str> {
|
fn icon_tooltip(&self, _window: &Window, _cx: &App) -> Option<&'static str> {
|
||||||
|
@ -656,6 +652,10 @@ impl Panel for AssistantPanel {
|
||||||
fn activation_priority(&self) -> u32 {
|
fn activation_priority(&self) -> u32 {
|
||||||
3
|
3
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn enabled(&self, cx: &App) -> bool {
|
||||||
|
AssistantSettings::get_global(cx).enabled
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AssistantPanel {
|
impl AssistantPanel {
|
||||||
|
|
|
@ -1156,20 +1156,7 @@ impl Panel for ChatPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn icon(&self, _window: &Window, cx: &App) -> Option<ui::IconName> {
|
fn icon(&self, _window: &Window, cx: &App) -> Option<ui::IconName> {
|
||||||
let show_icon = match ChatPanelSettings::get_global(cx).button {
|
self.enabled(cx).then(|| ui::IconName::MessageBubbles)
|
||||||
ChatPanelButton::Never => false,
|
|
||||||
ChatPanelButton::Always => true,
|
|
||||||
ChatPanelButton::WhenInCall => {
|
|
||||||
let is_in_call = ActiveCall::global(cx)
|
|
||||||
.read(cx)
|
|
||||||
.room()
|
|
||||||
.map_or(false, |room| room.read(cx).contains_guests());
|
|
||||||
|
|
||||||
self.active || is_in_call
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
show_icon.then(|| ui::IconName::MessageBubbles)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn icon_tooltip(&self, _: &Window, _: &App) -> Option<&'static str> {
|
fn icon_tooltip(&self, _: &Window, _: &App) -> Option<&'static str> {
|
||||||
|
@ -1190,6 +1177,21 @@ impl Panel for ChatPanel {
|
||||||
fn activation_priority(&self) -> u32 {
|
fn activation_priority(&self) -> u32 {
|
||||||
7
|
7
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn enabled(&self, cx: &App) -> bool {
|
||||||
|
match ChatPanelSettings::get_global(cx).button {
|
||||||
|
ChatPanelButton::Never => false,
|
||||||
|
ChatPanelButton::Always => true,
|
||||||
|
ChatPanelButton::WhenInCall => {
|
||||||
|
let is_in_call = ActiveCall::global(cx)
|
||||||
|
.read(cx)
|
||||||
|
.room()
|
||||||
|
.map_or(false, |room| room.read(cx).contains_guests());
|
||||||
|
|
||||||
|
self.active || is_in_call
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventEmitter<PanelEvent> for ChatPanel {}
|
impl EventEmitter<PanelEvent> for ChatPanel {}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::persistence::model::DockData;
|
use crate::persistence::model::DockData;
|
||||||
use crate::{status_bar::StatusItemView, Workspace};
|
use crate::{status_bar::StatusItemView, Workspace};
|
||||||
use crate::{DraggedDock, Event, ModalLayer, Pane};
|
use crate::{DraggedDock, Event, ModalLayer, Pane};
|
||||||
|
use anyhow::Context as _;
|
||||||
use client::proto;
|
use client::proto;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
deferred, div, px, Action, AnyView, App, Axis, Context, Corner, Entity, EntityId, EventEmitter,
|
deferred, div, px, Action, AnyView, App, Axis, Context, Corner, Entity, EntityId, EventEmitter,
|
||||||
|
@ -53,6 +54,9 @@ pub trait Panel: Focusable + EventEmitter<PanelEvent> + Render + Sized {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
fn activation_priority(&self) -> u32;
|
fn activation_priority(&self) -> u32;
|
||||||
|
fn enabled(&self, _cx: &App) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait PanelHandle: Send + Sync {
|
pub trait PanelHandle: Send + Sync {
|
||||||
|
@ -75,6 +79,7 @@ pub trait PanelHandle: Send + Sync {
|
||||||
fn panel_focus_handle(&self, cx: &App) -> FocusHandle;
|
fn panel_focus_handle(&self, cx: &App) -> FocusHandle;
|
||||||
fn to_any(&self) -> AnyView;
|
fn to_any(&self) -> AnyView;
|
||||||
fn activation_priority(&self, cx: &App) -> u32;
|
fn activation_priority(&self, cx: &App) -> u32;
|
||||||
|
fn enabled(&self, cx: &App) -> bool;
|
||||||
fn move_to_next_position(&self, window: &mut Window, cx: &mut App) {
|
fn move_to_next_position(&self, window: &mut Window, cx: &mut App) {
|
||||||
let current_position = self.position(window, cx);
|
let current_position = self.position(window, cx);
|
||||||
let next_position = [
|
let next_position = [
|
||||||
|
@ -171,6 +176,10 @@ where
|
||||||
fn activation_priority(&self, cx: &App) -> u32 {
|
fn activation_priority(&self, cx: &App) -> u32 {
|
||||||
self.read(cx).activation_priority()
|
self.read(cx).activation_priority()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn enabled(&self, cx: &App) -> bool {
|
||||||
|
self.read(cx).enabled(cx)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&dyn PanelHandle> for AnyView {
|
impl From<&dyn PanelHandle> for AnyView {
|
||||||
|
@ -351,6 +360,18 @@ impl Dock {
|
||||||
.position(|entry| entry.panel.remote_id() == Some(panel_id))
|
.position(|entry| entry.panel.remote_id() == Some(panel_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn first_enabled_panel_idx(&mut self, cx: &mut Context<Self>) -> anyhow::Result<usize> {
|
||||||
|
self.panel_entries
|
||||||
|
.iter()
|
||||||
|
.position(|entry| entry.panel.enabled(cx))
|
||||||
|
.with_context(|| {
|
||||||
|
format!(
|
||||||
|
"Couldn't find any enabled panel for the {} dock.",
|
||||||
|
self.position.label()
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fn active_panel_entry(&self) -> Option<&PanelEntry> {
|
fn active_panel_entry(&self) -> Option<&PanelEntry> {
|
||||||
self.active_panel_index
|
self.active_panel_index
|
||||||
.and_then(|index| self.panel_entries.get(index))
|
.and_then(|index| self.panel_entries.get(index))
|
||||||
|
|
|
@ -2522,8 +2522,14 @@ impl Workspace {
|
||||||
let was_visible = dock.is_open() && !other_is_zoomed;
|
let was_visible = dock.is_open() && !other_is_zoomed;
|
||||||
dock.set_open(!was_visible, window, cx);
|
dock.set_open(!was_visible, window, cx);
|
||||||
|
|
||||||
if dock.active_panel().is_none() && dock.panels_len() > 0 {
|
if dock.active_panel().is_none() {
|
||||||
dock.activate_panel(0, window, cx);
|
let Some(panel_ix) = dock
|
||||||
|
.first_enabled_panel_idx(cx)
|
||||||
|
.log_with_level(log::Level::Info)
|
||||||
|
else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
dock.activate_panel(panel_ix, window, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(active_panel) = dock.active_panel() {
|
if let Some(active_panel) = dock.active_panel() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue