wip progress
This commit is contained in:
parent
eb4ac2c276
commit
663e8aed8a
7 changed files with 472 additions and 438 deletions
|
@ -1,6 +1,7 @@
|
|||
use crate::{status_bar::StatusItemView, Axis, Workspace};
|
||||
use gpui2::{
|
||||
Action, AnyView, EventEmitter, Render, Subscription, View, ViewContext, WeakView, WindowContext,
|
||||
Action, AnyView, Div, EventEmitter, Render, Subscription, View, ViewContext, WeakView,
|
||||
WindowContext,
|
||||
};
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -176,226 +177,226 @@ pub struct PanelButtons {
|
|||
workspace: WeakView<Workspace>,
|
||||
}
|
||||
|
||||
// impl Dock {
|
||||
// pub fn new(position: DockPosition) -> Self {
|
||||
// Self {
|
||||
// position,
|
||||
// panel_entries: Default::default(),
|
||||
// active_panel_index: 0,
|
||||
// is_open: false,
|
||||
// }
|
||||
// }
|
||||
impl Dock {
|
||||
// pub fn new(position: DockPosition) -> Self {
|
||||
// Self {
|
||||
// position,
|
||||
// panel_entries: Default::default(),
|
||||
// active_panel_index: 0,
|
||||
// is_open: false,
|
||||
// }
|
||||
// }
|
||||
|
||||
// pub fn position(&self) -> DockPosition {
|
||||
// self.position
|
||||
// }
|
||||
// pub fn position(&self) -> DockPosition {
|
||||
// self.position
|
||||
// }
|
||||
|
||||
// pub fn is_open(&self) -> bool {
|
||||
// self.is_open
|
||||
// }
|
||||
pub fn is_open(&self) -> bool {
|
||||
self.is_open
|
||||
}
|
||||
|
||||
// pub fn has_focus(&self, cx: &WindowContext) -> bool {
|
||||
// self.visible_panel()
|
||||
// .map_or(false, |panel| panel.has_focus(cx))
|
||||
// }
|
||||
// pub fn has_focus(&self, cx: &WindowContext) -> bool {
|
||||
// self.visible_panel()
|
||||
// .map_or(false, |panel| panel.has_focus(cx))
|
||||
// }
|
||||
|
||||
// pub fn panel<T: Panel>(&self) -> Option<View<T>> {
|
||||
// self.panel_entries
|
||||
// .iter()
|
||||
// .find_map(|entry| entry.panel.as_any().clone().downcast())
|
||||
// }
|
||||
// pub fn panel<T: Panel>(&self) -> Option<View<T>> {
|
||||
// self.panel_entries
|
||||
// .iter()
|
||||
// .find_map(|entry| entry.panel.as_any().clone().downcast())
|
||||
// }
|
||||
|
||||
// pub fn panel_index_for_type<T: Panel>(&self) -> Option<usize> {
|
||||
// self.panel_entries
|
||||
// .iter()
|
||||
// .position(|entry| entry.panel.as_any().is::<T>())
|
||||
// }
|
||||
// pub fn panel_index_for_type<T: Panel>(&self) -> Option<usize> {
|
||||
// self.panel_entries
|
||||
// .iter()
|
||||
// .position(|entry| entry.panel.as_any().is::<T>())
|
||||
// }
|
||||
|
||||
// pub fn panel_index_for_ui_name(&self, ui_name: &str, cx: &AppContext) -> Option<usize> {
|
||||
// todo!()
|
||||
// // self.panel_entries.iter().position(|entry| {
|
||||
// // let panel = entry.panel.as_any();
|
||||
// // cx.view_ui_name(panel.window(), panel.id()) == Some(ui_name)
|
||||
// // })
|
||||
// }
|
||||
// pub fn panel_index_for_ui_name(&self, ui_name: &str, cx: &AppContext) -> Option<usize> {
|
||||
// todo!()
|
||||
// // self.panel_entries.iter().position(|entry| {
|
||||
// // let panel = entry.panel.as_any();
|
||||
// // cx.view_ui_name(panel.window(), panel.id()) == Some(ui_name)
|
||||
// // })
|
||||
// }
|
||||
|
||||
// pub fn active_panel_index(&self) -> usize {
|
||||
// self.active_panel_index
|
||||
// }
|
||||
// pub fn active_panel_index(&self) -> usize {
|
||||
// self.active_panel_index
|
||||
// }
|
||||
|
||||
// pub(crate) fn set_open(&mut self, open: bool, cx: &mut ViewContext<Self>) {
|
||||
// if open != self.is_open {
|
||||
// self.is_open = open;
|
||||
// if let Some(active_panel) = self.panel_entries.get(self.active_panel_index) {
|
||||
// active_panel.panel.set_active(open, cx);
|
||||
// }
|
||||
// pub(crate) fn set_open(&mut self, open: bool, cx: &mut ViewContext<Self>) {
|
||||
// if open != self.is_open {
|
||||
// self.is_open = open;
|
||||
// if let Some(active_panel) = self.panel_entries.get(self.active_panel_index) {
|
||||
// active_panel.panel.set_active(open, cx);
|
||||
// }
|
||||
|
||||
// cx.notify();
|
||||
// }
|
||||
// }
|
||||
// cx.notify();
|
||||
// }
|
||||
// }
|
||||
|
||||
// pub fn set_panel_zoomed(&mut self, panel: &AnyView, zoomed: bool, cx: &mut ViewContext<Self>) {
|
||||
// for entry in &mut self.panel_entries {
|
||||
// if entry.panel.as_any() == panel {
|
||||
// if zoomed != entry.panel.is_zoomed(cx) {
|
||||
// entry.panel.set_zoomed(zoomed, cx);
|
||||
// }
|
||||
// } else if entry.panel.is_zoomed(cx) {
|
||||
// entry.panel.set_zoomed(false, cx);
|
||||
// }
|
||||
// }
|
||||
// pub fn set_panel_zoomed(&mut self, panel: &AnyView, zoomed: bool, cx: &mut ViewContext<Self>) {
|
||||
// for entry in &mut self.panel_entries {
|
||||
// if entry.panel.as_any() == panel {
|
||||
// if zoomed != entry.panel.is_zoomed(cx) {
|
||||
// entry.panel.set_zoomed(zoomed, cx);
|
||||
// }
|
||||
// } else if entry.panel.is_zoomed(cx) {
|
||||
// entry.panel.set_zoomed(false, cx);
|
||||
// }
|
||||
// }
|
||||
|
||||
// cx.notify();
|
||||
// }
|
||||
// cx.notify();
|
||||
// }
|
||||
|
||||
// pub fn zoom_out(&mut self, cx: &mut ViewContext<Self>) {
|
||||
// for entry in &mut self.panel_entries {
|
||||
// if entry.panel.is_zoomed(cx) {
|
||||
// entry.panel.set_zoomed(false, cx);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// pub fn zoom_out(&mut self, cx: &mut ViewContext<Self>) {
|
||||
// for entry in &mut self.panel_entries {
|
||||
// if entry.panel.is_zoomed(cx) {
|
||||
// entry.panel.set_zoomed(false, cx);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// pub(crate) fn add_panel<T: Panel>(&mut self, panel: View<T>, cx: &mut ViewContext<Self>) {
|
||||
// let subscriptions = [
|
||||
// cx.observe(&panel, |_, _, cx| cx.notify()),
|
||||
// cx.subscribe(&panel, |this, panel, event, cx| {
|
||||
// if T::should_activate_on_event(event) {
|
||||
// if let Some(ix) = this
|
||||
// .panel_entries
|
||||
// .iter()
|
||||
// .position(|entry| entry.panel.id() == panel.id())
|
||||
// {
|
||||
// this.set_open(true, cx);
|
||||
// this.activate_panel(ix, cx);
|
||||
// cx.focus(&panel);
|
||||
// }
|
||||
// } else if T::should_close_on_event(event)
|
||||
// && this.visible_panel().map_or(false, |p| p.id() == panel.id())
|
||||
// {
|
||||
// this.set_open(false, cx);
|
||||
// }
|
||||
// }),
|
||||
// ];
|
||||
// pub(crate) fn add_panel<T: Panel>(&mut self, panel: View<T>, cx: &mut ViewContext<Self>) {
|
||||
// let subscriptions = [
|
||||
// cx.observe(&panel, |_, _, cx| cx.notify()),
|
||||
// cx.subscribe(&panel, |this, panel, event, cx| {
|
||||
// if T::should_activate_on_event(event) {
|
||||
// if let Some(ix) = this
|
||||
// .panel_entries
|
||||
// .iter()
|
||||
// .position(|entry| entry.panel.id() == panel.id())
|
||||
// {
|
||||
// this.set_open(true, cx);
|
||||
// this.activate_panel(ix, cx);
|
||||
// cx.focus(&panel);
|
||||
// }
|
||||
// } else if T::should_close_on_event(event)
|
||||
// && this.visible_panel().map_or(false, |p| p.id() == panel.id())
|
||||
// {
|
||||
// this.set_open(false, cx);
|
||||
// }
|
||||
// }),
|
||||
// ];
|
||||
|
||||
// let dock_view_id = cx.view_id();
|
||||
// self.panel_entries.push(PanelEntry {
|
||||
// panel: Arc::new(panel),
|
||||
// // todo!()
|
||||
// // context_menu: cx.add_view(|cx| {
|
||||
// // let mut menu = ContextMenu::new(dock_view_id, cx);
|
||||
// // menu.set_position_mode(OverlayPositionMode::Local);
|
||||
// // menu
|
||||
// // }),
|
||||
// _subscriptions: subscriptions,
|
||||
// });
|
||||
// cx.notify()
|
||||
// }
|
||||
// let dock_view_id = cx.view_id();
|
||||
// self.panel_entries.push(PanelEntry {
|
||||
// panel: Arc::new(panel),
|
||||
// // todo!()
|
||||
// // context_menu: cx.add_view(|cx| {
|
||||
// // let mut menu = ContextMenu::new(dock_view_id, cx);
|
||||
// // menu.set_position_mode(OverlayPositionMode::Local);
|
||||
// // menu
|
||||
// // }),
|
||||
// _subscriptions: subscriptions,
|
||||
// });
|
||||
// cx.notify()
|
||||
// }
|
||||
|
||||
// pub fn remove_panel<T: Panel>(&mut self, panel: &View<T>, cx: &mut ViewContext<Self>) {
|
||||
// if let Some(panel_ix) = self
|
||||
// .panel_entries
|
||||
// .iter()
|
||||
// .position(|entry| entry.panel.id() == panel.id())
|
||||
// {
|
||||
// if panel_ix == self.active_panel_index {
|
||||
// self.active_panel_index = 0;
|
||||
// self.set_open(false, cx);
|
||||
// } else if panel_ix < self.active_panel_index {
|
||||
// self.active_panel_index -= 1;
|
||||
// }
|
||||
// self.panel_entries.remove(panel_ix);
|
||||
// cx.notify();
|
||||
// }
|
||||
// }
|
||||
// pub fn remove_panel<T: Panel>(&mut self, panel: &View<T>, cx: &mut ViewContext<Self>) {
|
||||
// if let Some(panel_ix) = self
|
||||
// .panel_entries
|
||||
// .iter()
|
||||
// .position(|entry| entry.panel.id() == panel.id())
|
||||
// {
|
||||
// if panel_ix == self.active_panel_index {
|
||||
// self.active_panel_index = 0;
|
||||
// self.set_open(false, cx);
|
||||
// } else if panel_ix < self.active_panel_index {
|
||||
// self.active_panel_index -= 1;
|
||||
// }
|
||||
// self.panel_entries.remove(panel_ix);
|
||||
// cx.notify();
|
||||
// }
|
||||
// }
|
||||
|
||||
// pub fn panels_len(&self) -> usize {
|
||||
// self.panel_entries.len()
|
||||
// }
|
||||
// pub fn panels_len(&self) -> usize {
|
||||
// self.panel_entries.len()
|
||||
// }
|
||||
|
||||
// pub fn activate_panel(&mut self, panel_ix: usize, cx: &mut ViewContext<Self>) {
|
||||
// if panel_ix != self.active_panel_index {
|
||||
// if let Some(active_panel) = self.panel_entries.get(self.active_panel_index) {
|
||||
// active_panel.panel.set_active(false, cx);
|
||||
// }
|
||||
// pub fn activate_panel(&mut self, panel_ix: usize, cx: &mut ViewContext<Self>) {
|
||||
// if panel_ix != self.active_panel_index {
|
||||
// if let Some(active_panel) = self.panel_entries.get(self.active_panel_index) {
|
||||
// active_panel.panel.set_active(false, cx);
|
||||
// }
|
||||
|
||||
// self.active_panel_index = panel_ix;
|
||||
// if let Some(active_panel) = self.panel_entries.get(self.active_panel_index) {
|
||||
// active_panel.panel.set_active(true, cx);
|
||||
// }
|
||||
// self.active_panel_index = panel_ix;
|
||||
// if let Some(active_panel) = self.panel_entries.get(self.active_panel_index) {
|
||||
// active_panel.panel.set_active(true, cx);
|
||||
// }
|
||||
|
||||
// cx.notify();
|
||||
// }
|
||||
// }
|
||||
// cx.notify();
|
||||
// }
|
||||
// }
|
||||
|
||||
// pub fn visible_panel(&self) -> Option<&Arc<dyn PanelHandle>> {
|
||||
// let entry = self.visible_entry()?;
|
||||
// Some(&entry.panel)
|
||||
// }
|
||||
pub fn visible_panel(&self) -> Option<&Arc<dyn PanelHandle>> {
|
||||
let entry = self.visible_entry()?;
|
||||
Some(&entry.panel)
|
||||
}
|
||||
|
||||
// pub fn active_panel(&self) -> Option<&Arc<dyn PanelHandle>> {
|
||||
// Some(&self.panel_entries.get(self.active_panel_index)?.panel)
|
||||
// }
|
||||
// pub fn active_panel(&self) -> Option<&Arc<dyn PanelHandle>> {
|
||||
// Some(&self.panel_entries.get(self.active_panel_index)?.panel)
|
||||
// }
|
||||
|
||||
// fn visible_entry(&self) -> Option<&PanelEntry> {
|
||||
// if self.is_open {
|
||||
// self.panel_entries.get(self.active_panel_index)
|
||||
// } else {
|
||||
// None
|
||||
// }
|
||||
// }
|
||||
fn visible_entry(&self) -> Option<&PanelEntry> {
|
||||
if self.is_open {
|
||||
self.panel_entries.get(self.active_panel_index)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
// pub fn zoomed_panel(&self, cx: &WindowContext) -> Option<Arc<dyn PanelHandle>> {
|
||||
// let entry = self.visible_entry()?;
|
||||
// if entry.panel.is_zoomed(cx) {
|
||||
// Some(entry.panel.clone())
|
||||
// } else {
|
||||
// None
|
||||
// }
|
||||
// }
|
||||
// pub fn zoomed_panel(&self, cx: &WindowContext) -> Option<Arc<dyn PanelHandle>> {
|
||||
// let entry = self.visible_entry()?;
|
||||
// if entry.panel.is_zoomed(cx) {
|
||||
// Some(entry.panel.clone())
|
||||
// } else {
|
||||
// None
|
||||
// }
|
||||
// }
|
||||
|
||||
// pub fn panel_size(&self, panel: &dyn PanelHandle, cx: &WindowContext) -> Option<f32> {
|
||||
// self.panel_entries
|
||||
// .iter()
|
||||
// .find(|entry| entry.panel.id() == panel.id())
|
||||
// .map(|entry| entry.panel.size(cx))
|
||||
// }
|
||||
// pub fn panel_size(&self, panel: &dyn PanelHandle, cx: &WindowContext) -> Option<f32> {
|
||||
// self.panel_entries
|
||||
// .iter()
|
||||
// .find(|entry| entry.panel.id() == panel.id())
|
||||
// .map(|entry| entry.panel.size(cx))
|
||||
// }
|
||||
|
||||
// pub fn active_panel_size(&self, cx: &WindowContext) -> Option<f32> {
|
||||
// if self.is_open {
|
||||
// self.panel_entries
|
||||
// .get(self.active_panel_index)
|
||||
// .map(|entry| entry.panel.size(cx))
|
||||
// } else {
|
||||
// None
|
||||
// }
|
||||
// }
|
||||
// pub fn active_panel_size(&self, cx: &WindowContext) -> Option<f32> {
|
||||
// if self.is_open {
|
||||
// self.panel_entries
|
||||
// .get(self.active_panel_index)
|
||||
// .map(|entry| entry.panel.size(cx))
|
||||
// } else {
|
||||
// None
|
||||
// }
|
||||
// }
|
||||
|
||||
// pub fn resize_active_panel(&mut self, size: Option<f32>, cx: &mut ViewContext<Self>) {
|
||||
// if let Some(entry) = self.panel_entries.get_mut(self.active_panel_index) {
|
||||
// entry.panel.set_size(size, cx);
|
||||
// cx.notify();
|
||||
// }
|
||||
// }
|
||||
// pub fn resize_active_panel(&mut self, size: Option<f32>, cx: &mut ViewContext<Self>) {
|
||||
// if let Some(entry) = self.panel_entries.get_mut(self.active_panel_index) {
|
||||
// entry.panel.set_size(size, cx);
|
||||
// cx.notify();
|
||||
// }
|
||||
// }
|
||||
|
||||
// pub fn render_placeholder(&self, cx: &WindowContext) -> AnyElement<Workspace> {
|
||||
// todo!()
|
||||
// if let Some(active_entry) = self.visible_entry() {
|
||||
// Empty::new()
|
||||
// .into_any()
|
||||
// .contained()
|
||||
// .with_style(self.style(cx))
|
||||
// .resizable::<WorkspaceBounds>(
|
||||
// self.position.to_resize_handle_side(),
|
||||
// active_entry.panel.size(cx),
|
||||
// |_, _, _| {},
|
||||
// )
|
||||
// .into_any()
|
||||
// } else {
|
||||
// Empty::new().into_any()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// pub fn render_placeholder(&self, cx: &WindowContext) -> AnyElement<Workspace> {
|
||||
// todo!()
|
||||
// if let Some(active_entry) = self.visible_entry() {
|
||||
// Empty::new()
|
||||
// .into_any()
|
||||
// .contained()
|
||||
// .with_style(self.style(cx))
|
||||
// .resizable::<WorkspaceBounds>(
|
||||
// self.position.to_resize_handle_side(),
|
||||
// active_entry.panel.size(cx),
|
||||
// |_, _, _| {},
|
||||
// )
|
||||
// .into_any()
|
||||
// } else {
|
||||
// Empty::new().into_any()
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
// todo!()
|
||||
// impl View for Dock {
|
||||
|
@ -596,15 +597,23 @@ impl EventEmitter for PanelButtons {
|
|||
// }
|
||||
// }
|
||||
|
||||
// impl StatusItemView for PanelButtons {
|
||||
// fn set_active_pane_item(
|
||||
// &mut self,
|
||||
// active_pane_item: Option<&dyn crate::ItemHandle>,
|
||||
// cx: &mut ViewContext<Self>,
|
||||
// ) {
|
||||
// todo!()
|
||||
// }
|
||||
// }
|
||||
impl Render for PanelButtons {
|
||||
type Element = Div<Self>;
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl StatusItemView for PanelButtons {
|
||||
fn set_active_pane_item(
|
||||
&mut self,
|
||||
active_pane_item: Option<&dyn crate::ItemHandle>,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
pub mod test {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue