WIP
This commit is contained in:
parent
e3822a5b5c
commit
76efab005f
3 changed files with 114 additions and 161 deletions
|
@ -1,172 +1,126 @@
|
||||||
// use context_menu::{ContextMenu, ContextMenuItem};
|
use context_menu::{ContextMenu, ContextMenuItem};
|
||||||
// use gpui::{
|
use gpui::{
|
||||||
// elements::*, impl_internal_actions, CursorStyle, Element, ElementBox, Entity, MouseButton,
|
elements::*, impl_internal_actions, CursorStyle, Element, ElementBox, Entity, MouseButton,
|
||||||
// MutableAppContext, RenderContext, View, ViewContext, ViewHandle, WeakModelHandle,
|
MutableAppContext, RenderContext, View, ViewContext, ViewHandle,
|
||||||
// WeakViewHandle,
|
};
|
||||||
// };
|
use settings::Settings;
|
||||||
// use settings::Settings;
|
use workspace::{item::ItemHandle, NewTerminal, StatusItemView};
|
||||||
// use std::any::TypeId;
|
|
||||||
// use workspace::{dock::FocusDock, item::ItemHandle, NewTerminal, StatusItemView, Workspace};
|
|
||||||
|
|
||||||
// #[derive(Clone, PartialEq)]
|
const COPILOT_SETTINGS_URL: &str = "https://github.com/settings/copilot";
|
||||||
// pub struct DeployTerminalMenu;
|
|
||||||
|
|
||||||
// impl_internal_actions!(terminal, [DeployTerminalMenu]);
|
#[derive(Clone, PartialEq)]
|
||||||
|
pub struct DeployCopilotMenu;
|
||||||
|
|
||||||
// pub fn init(cx: &mut MutableAppContext) {
|
impl_internal_actions!(copilot, [DeployCopilotMenu]);
|
||||||
// cx.add_action(CopilotButton::deploy_terminal_menu);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub struct CopilotButton {
|
pub fn init(cx: &mut MutableAppContext) {
|
||||||
// workspace: WeakViewHandle<Workspace>,
|
cx.add_action(CopilotButton::deploy_copilot_menu);
|
||||||
// popup_menu: ViewHandle<ContextMenu>,
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// impl Entity for CopilotButton {
|
pub struct CopilotButton {
|
||||||
// type Event = ();
|
popup_menu: ViewHandle<ContextMenu>,
|
||||||
// }
|
}
|
||||||
|
|
||||||
// impl View for CopilotButton {
|
impl Entity for CopilotButton {
|
||||||
// fn ui_name() -> &'static str {
|
type Event = ();
|
||||||
// "TerminalButton"
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// fn render(&mut self, cx: &mut RenderContext<'_, Self>) -> ElementBox {
|
impl View for CopilotButton {
|
||||||
// let workspace = self.workspace.upgrade(cx);
|
fn ui_name() -> &'static str {
|
||||||
// let project = match workspace {
|
"CopilotButton"
|
||||||
// Some(workspace) => workspace.read(cx).project().read(cx),
|
}
|
||||||
// None => return Empty::new().boxed(),
|
|
||||||
// };
|
|
||||||
|
|
||||||
// let focused_view = cx.focused_view_id(cx.window_id());
|
fn render(&mut self, cx: &mut RenderContext<'_, Self>) -> ElementBox {
|
||||||
// let active = focused_view
|
let theme = cx.global::<Settings>().theme.clone();
|
||||||
// .map(|view_id| {
|
|
||||||
// cx.view_type_id(cx.window_id(), view_id) == Some(TypeId::of::<TerminalView>())
|
|
||||||
// })
|
|
||||||
// .unwrap_or(false);
|
|
||||||
|
|
||||||
// let has_terminals = !project.local_terminal_handles().is_empty();
|
let visible = self.popup_menu.read(cx).visible();
|
||||||
// let terminal_count = project.local_terminal_handles().len() as i32;
|
|
||||||
// let theme = cx.global::<Settings>().theme.clone();
|
|
||||||
|
|
||||||
// Stack::new()
|
Stack::new()
|
||||||
// .with_child(
|
.with_child(
|
||||||
// MouseEventHandler::<Self>::new(0, cx, {
|
MouseEventHandler::<Self>::new(0, cx, {
|
||||||
// let theme = theme.clone();
|
let theme = theme.clone();
|
||||||
// move |state, _cx| {
|
move |state, _cx| {
|
||||||
// let style = theme
|
let style = theme
|
||||||
// .workspace
|
.workspace
|
||||||
// .status_bar
|
.status_bar
|
||||||
// .sidebar_buttons
|
.sidebar_buttons
|
||||||
// .item
|
.item
|
||||||
// .style_for(state, active);
|
.style_for(state, visible);
|
||||||
|
|
||||||
// Flex::row()
|
Flex::row()
|
||||||
// .with_child(
|
.with_child(
|
||||||
// Svg::new("icons/terminal_12.svg")
|
Svg::new("icons/maybe_copilot.svg")
|
||||||
// .with_color(style.icon_color)
|
.with_color(style.icon_color)
|
||||||
// .constrained()
|
.constrained()
|
||||||
// .with_width(style.icon_size)
|
.with_width(style.icon_size)
|
||||||
// .aligned()
|
.aligned()
|
||||||
// .named("terminals-icon"),
|
.named("copilot-icon"),
|
||||||
// )
|
)
|
||||||
// .with_children(has_terminals.then(|| {
|
.constrained()
|
||||||
// Label::new(terminal_count.to_string(), style.label.text.clone())
|
.with_height(style.icon_size)
|
||||||
// .contained()
|
.contained()
|
||||||
// .with_style(style.label.container)
|
.with_style(style.container)
|
||||||
// .aligned()
|
.boxed()
|
||||||
// .boxed()
|
}
|
||||||
// }))
|
})
|
||||||
// .constrained()
|
.with_cursor_style(CursorStyle::PointingHand)
|
||||||
// .with_height(style.icon_size)
|
.on_click(MouseButton::Left, move |_, _cx| {
|
||||||
// .contained()
|
// TODO: Behavior of this
|
||||||
// .with_style(style.container)
|
|
||||||
// .boxed()
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
// .with_cursor_style(CursorStyle::PointingHand)
|
|
||||||
// .on_click(MouseButton::Left, move |_, cx| {
|
|
||||||
// if has_terminals {
|
// if has_terminals {
|
||||||
// cx.dispatch_action(DeployTerminalMenu);
|
// cx.dispatch_action(DeployCopilotMenu);
|
||||||
// } else {
|
// } else {
|
||||||
// if !active {
|
// if !active {
|
||||||
// cx.dispatch_action(FocusDock);
|
// cx.dispatch_action(FocusDock);
|
||||||
// }
|
// }
|
||||||
// };
|
// };
|
||||||
// })
|
})
|
||||||
// .with_tooltip::<Self, _>(
|
.with_tooltip::<Self, _>(
|
||||||
// 0,
|
0,
|
||||||
// "Show Terminal".into(),
|
"GitHub Copilot".into(),
|
||||||
// Some(Box::new(FocusDock)),
|
None,
|
||||||
// theme.tooltip.clone(),
|
theme.tooltip.clone(),
|
||||||
// cx,
|
cx,
|
||||||
// )
|
)
|
||||||
// .boxed(),
|
.boxed(),
|
||||||
// )
|
)
|
||||||
// .with_child(
|
.with_child(
|
||||||
// ChildView::new(&self.popup_menu, cx)
|
ChildView::new(&self.popup_menu, cx)
|
||||||
// .aligned()
|
.aligned()
|
||||||
// .top()
|
.top()
|
||||||
// .right()
|
.right()
|
||||||
// .boxed(),
|
.boxed(),
|
||||||
// )
|
)
|
||||||
// .boxed()
|
.boxed()
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// impl CopilotButton {
|
impl CopilotButton {
|
||||||
// pub fn new(workspace: ViewHandle<Workspace>, cx: &mut ViewContext<Self>) -> Self {
|
pub fn new(cx: &mut ViewContext<Self>) -> Self {
|
||||||
// cx.observe(&workspace, |_, _, cx| cx.notify()).detach();
|
Self {
|
||||||
// Self {
|
popup_menu: cx.add_view(|cx| {
|
||||||
// workspace: workspace.downgrade(),
|
let mut menu = ContextMenu::new(cx);
|
||||||
// popup_menu: cx.add_view(|cx| {
|
menu.set_position_mode(OverlayPositionMode::Local);
|
||||||
// let mut menu = ContextMenu::new(cx);
|
menu
|
||||||
// menu.set_position_mode(OverlayPositionMode::Local);
|
}),
|
||||||
// menu
|
}
|
||||||
// }),
|
}
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub fn deploy_terminal_menu(
|
pub fn deploy_copilot_menu(&mut self, _: &DeployCopilotMenu, cx: &mut ViewContext<Self>) {
|
||||||
// &mut self,
|
let mut menu_options = vec![ContextMenuItem::item("New Terminal", NewTerminal)];
|
||||||
// _action: &DeployTerminalMenu,
|
|
||||||
// cx: &mut ViewContext<Self>,
|
|
||||||
// ) {
|
|
||||||
// let mut menu_options = vec![ContextMenuItem::item("New Terminal", NewTerminal)];
|
|
||||||
|
|
||||||
// if let Some(workspace) = self.workspace.upgrade(cx) {
|
self.popup_menu.update(cx, |menu, cx| {
|
||||||
// let project = workspace.read(cx).project().read(cx);
|
menu.show(
|
||||||
// let local_terminal_handles = project.local_terminal_handles();
|
Default::default(),
|
||||||
|
AnchorCorner::BottomRight,
|
||||||
|
menu_options,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// if !local_terminal_handles.is_empty() {
|
impl StatusItemView for CopilotButton {
|
||||||
// menu_options.push(ContextMenuItem::Separator)
|
fn set_active_pane_item(&mut self, item: Option<&dyn ItemHandle>, cx: &mut ViewContext<Self>) {
|
||||||
// }
|
cx.notify();
|
||||||
|
}
|
||||||
// for local_terminal_handle in local_terminal_handles {
|
}
|
||||||
// if let Some(terminal) = local_terminal_handle.upgrade(cx) {
|
|
||||||
// menu_options.push(ContextMenuItem::item(
|
|
||||||
// terminal.read(cx).title(),
|
|
||||||
// // FocusTerminal {
|
|
||||||
// // terminal_handle: local_terminal_handle.clone(),
|
|
||||||
// // },
|
|
||||||
// ))
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// self.popup_menu.update(cx, |menu, cx| {
|
|
||||||
// menu.show(
|
|
||||||
// Default::default(),
|
|
||||||
// AnchorCorner::BottomRight,
|
|
||||||
// menu_options,
|
|
||||||
// cx,
|
|
||||||
// );
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// impl StatusItemView for CopilotButton {
|
|
||||||
// fn set_active_pane_item(&mut self, _: Option<&dyn ItemHandle>, cx: &mut ViewContext<Self>) {
|
|
||||||
// cx.notify();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
|
@ -2756,8 +2756,6 @@ impl Editor {
|
||||||
|
|
||||||
let settings = cx.global::<Settings>();
|
let settings = cx.global::<Settings>();
|
||||||
|
|
||||||
dbg!(self.copilot_state.user_enabled);
|
|
||||||
|
|
||||||
if !self
|
if !self
|
||||||
.copilot_state
|
.copilot_state
|
||||||
.user_enabled
|
.user_enabled
|
||||||
|
@ -2776,8 +2774,6 @@ impl Editor {
|
||||||
|
|
||||||
let copilot_enabled = settings.copilot_on(language_name.as_deref());
|
let copilot_enabled = settings.copilot_on(language_name.as_deref());
|
||||||
|
|
||||||
dbg!(language_name, copilot_enabled);
|
|
||||||
|
|
||||||
if !copilot_enabled {
|
if !copilot_enabled {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ use breadcrumbs::Breadcrumbs;
|
||||||
pub use client;
|
pub use client;
|
||||||
use collab_ui::{CollabTitlebarItem, ToggleContactsMenu};
|
use collab_ui::{CollabTitlebarItem, ToggleContactsMenu};
|
||||||
use collections::VecDeque;
|
use collections::VecDeque;
|
||||||
|
use copilot::copilot_button::CopilotButton;
|
||||||
pub use editor;
|
pub use editor;
|
||||||
use editor::{Editor, MultiBuffer};
|
use editor::{Editor, MultiBuffer};
|
||||||
|
|
||||||
|
@ -311,6 +312,7 @@ pub fn initialize_workspace(
|
||||||
});
|
});
|
||||||
|
|
||||||
let toggle_terminal = cx.add_view(|cx| TerminalButton::new(workspace_handle.clone(), cx));
|
let toggle_terminal = cx.add_view(|cx| TerminalButton::new(workspace_handle.clone(), cx));
|
||||||
|
let copilot = cx.add_view(|cx| CopilotButton::new(cx));
|
||||||
let diagnostic_summary =
|
let diagnostic_summary =
|
||||||
cx.add_view(|cx| diagnostics::items::DiagnosticIndicator::new(workspace.project(), cx));
|
cx.add_view(|cx| diagnostics::items::DiagnosticIndicator::new(workspace.project(), cx));
|
||||||
let activity_indicator =
|
let activity_indicator =
|
||||||
|
@ -324,6 +326,7 @@ pub fn initialize_workspace(
|
||||||
status_bar.add_left_item(activity_indicator, cx);
|
status_bar.add_left_item(activity_indicator, cx);
|
||||||
status_bar.add_right_item(toggle_terminal, cx);
|
status_bar.add_right_item(toggle_terminal, cx);
|
||||||
status_bar.add_right_item(feedback_button, cx);
|
status_bar.add_right_item(feedback_button, cx);
|
||||||
|
status_bar.add_right_item(copilot, cx);
|
||||||
status_bar.add_right_item(active_buffer_language, cx);
|
status_bar.add_right_item(active_buffer_language, cx);
|
||||||
status_bar.add_right_item(cursor_position, cx);
|
status_bar.add_right_item(cursor_position, cx);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue