WIP, not compiling
This commit is contained in:
parent
76efab005f
commit
8fac32e1eb
1 changed files with 44 additions and 20 deletions
|
@ -1,17 +1,24 @@
|
||||||
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,
|
MutableAppContext, RenderContext, View, ViewContext, ViewHandle, WeakViewHandle,
|
||||||
};
|
};
|
||||||
use settings::Settings;
|
use settings::Settings;
|
||||||
|
use theme::Editor;
|
||||||
use workspace::{item::ItemHandle, NewTerminal, StatusItemView};
|
use workspace::{item::ItemHandle, NewTerminal, StatusItemView};
|
||||||
|
|
||||||
|
use crate::{Copilot, Status};
|
||||||
|
|
||||||
const COPILOT_SETTINGS_URL: &str = "https://github.com/settings/copilot";
|
const COPILOT_SETTINGS_URL: &str = "https://github.com/settings/copilot";
|
||||||
|
|
||||||
#[derive(Clone, PartialEq)]
|
#[derive(Clone, PartialEq)]
|
||||||
pub struct DeployCopilotMenu;
|
pub struct DeployCopilotMenu;
|
||||||
|
|
||||||
impl_internal_actions!(copilot, [DeployCopilotMenu]);
|
// TODO: Make the other code path use `get_or_insert` logic for this modal
|
||||||
|
#[derive(Clone, PartialEq)]
|
||||||
|
pub struct DeployCopilotModal;
|
||||||
|
|
||||||
|
impl_internal_actions!(copilot, [DeployCopilotMenu, DeployCopilotModal]);
|
||||||
|
|
||||||
pub fn init(cx: &mut MutableAppContext) {
|
pub fn init(cx: &mut MutableAppContext) {
|
||||||
cx.add_action(CopilotButton::deploy_copilot_menu);
|
cx.add_action(CopilotButton::deploy_copilot_menu);
|
||||||
|
@ -19,6 +26,7 @@ pub fn init(cx: &mut MutableAppContext) {
|
||||||
|
|
||||||
pub struct CopilotButton {
|
pub struct CopilotButton {
|
||||||
popup_menu: ViewHandle<ContextMenu>,
|
popup_menu: ViewHandle<ContextMenu>,
|
||||||
|
editor: Option<WeakViewHandle<Editor>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Entity for CopilotButton {
|
impl Entity for CopilotButton {
|
||||||
|
@ -31,9 +39,16 @@ impl View for CopilotButton {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render(&mut self, cx: &mut RenderContext<'_, Self>) -> ElementBox {
|
fn render(&mut self, cx: &mut RenderContext<'_, Self>) -> ElementBox {
|
||||||
let theme = cx.global::<Settings>().theme.clone();
|
let settings = cx.global::<Settings>();
|
||||||
|
|
||||||
let visible = self.popup_menu.read(cx).visible();
|
if !settings.enable_copilot_integration {
|
||||||
|
return Empty::new().boxed();
|
||||||
|
}
|
||||||
|
|
||||||
|
let theme = settings.theme.clone();
|
||||||
|
let active = self.popup_menu.read(cx).visible() /* || modal.is_shown */;
|
||||||
|
let authorized = Copilot::global(cx).unwrap().read(cx).status() == Status::Authorized;
|
||||||
|
let enabled = true;
|
||||||
|
|
||||||
Stack::new()
|
Stack::new()
|
||||||
.with_child(
|
.with_child(
|
||||||
|
@ -45,11 +60,21 @@ impl View for CopilotButton {
|
||||||
.status_bar
|
.status_bar
|
||||||
.sidebar_buttons
|
.sidebar_buttons
|
||||||
.item
|
.item
|
||||||
.style_for(state, visible);
|
.style_for(state, active);
|
||||||
|
|
||||||
Flex::row()
|
Flex::row()
|
||||||
.with_child(
|
.with_child(
|
||||||
Svg::new("icons/maybe_copilot.svg")
|
Svg::new({
|
||||||
|
if authorized {
|
||||||
|
if enabled {
|
||||||
|
"icons/copilot_16.svg"
|
||||||
|
} else {
|
||||||
|
"icons/copilot_disabled_16.svg"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
"icons/copilot_init_16.svg"
|
||||||
|
}
|
||||||
|
})
|
||||||
.with_color(style.icon_color)
|
.with_color(style.icon_color)
|
||||||
.constrained()
|
.constrained()
|
||||||
.with_width(style.icon_size)
|
.with_width(style.icon_size)
|
||||||
|
@ -64,15 +89,12 @@ impl View for CopilotButton {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.with_cursor_style(CursorStyle::PointingHand)
|
.with_cursor_style(CursorStyle::PointingHand)
|
||||||
.on_click(MouseButton::Left, move |_, _cx| {
|
.on_click(MouseButton::Left, move |_, cx| {
|
||||||
// TODO: Behavior of this
|
if authorized {
|
||||||
// if has_terminals {
|
cx.dispatch_action(DeployCopilotMenu);
|
||||||
// cx.dispatch_action(DeployCopilotMenu);
|
} else {
|
||||||
// } else {
|
cx.dispatch_action(DeployCopilotModal);
|
||||||
// if !active {
|
}
|
||||||
// cx.dispatch_action(FocusDock);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
})
|
})
|
||||||
.with_tooltip::<Self, _>(
|
.with_tooltip::<Self, _>(
|
||||||
0,
|
0,
|
||||||
|
@ -102,6 +124,7 @@ impl CopilotButton {
|
||||||
menu.set_position_mode(OverlayPositionMode::Local);
|
menu.set_position_mode(OverlayPositionMode::Local);
|
||||||
menu
|
menu
|
||||||
}),
|
}),
|
||||||
|
editor: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,6 +144,7 @@ impl CopilotButton {
|
||||||
|
|
||||||
impl StatusItemView for CopilotButton {
|
impl StatusItemView for CopilotButton {
|
||||||
fn set_active_pane_item(&mut self, item: Option<&dyn ItemHandle>, cx: &mut ViewContext<Self>) {
|
fn set_active_pane_item(&mut self, item: Option<&dyn ItemHandle>, cx: &mut ViewContext<Self>) {
|
||||||
|
if let Some(editor) = item.map(|item| item.act_as::<editor::Editor>(cx)) {}
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue