Merge branch 'main' into search2

This commit is contained in:
Piotr Osiewicz
2023-11-15 12:54:26 +01:00
163 changed files with 20705 additions and 13985 deletions
+25 -3
View File
@@ -1,7 +1,8 @@
use crate::{status_bar::StatusItemView, Axis, Workspace};
use gpui::{
div, Action, AnyView, AppContext, Div, Entity, EntityId, EventEmitter, ParentElement, Render,
Subscription, View, ViewContext, WeakView, WindowContext,
div, px, Action, AnyView, AppContext, Component, Div, Entity, EntityId, EventEmitter,
FocusHandle, ParentComponent, Render, Styled, Subscription, View, ViewContext, WeakView,
WindowContext,
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
@@ -34,6 +35,7 @@ pub trait Panel: Render + EventEmitter<PanelEvent> {
fn set_zoomed(&mut self, _zoomed: bool, _cx: &mut ViewContext<Self>) {}
fn set_active(&mut self, _active: bool, _cx: &mut ViewContext<Self>) {}
fn has_focus(&self, cx: &WindowContext) -> bool;
fn focus_handle(&self, cx: &WindowContext) -> FocusHandle;
}
pub trait PanelHandle: Send + Sync {
@@ -51,6 +53,7 @@ pub trait PanelHandle: Send + Sync {
fn icon_tooltip(&self, cx: &WindowContext) -> (String, Option<Box<dyn Action>>);
fn icon_label(&self, cx: &WindowContext) -> Option<String>;
fn has_focus(&self, cx: &WindowContext) -> bool;
fn focus_handle(&self, cx: &WindowContext) -> FocusHandle;
fn to_any(&self) -> AnyView;
}
@@ -117,6 +120,10 @@ where
fn to_any(&self) -> AnyView {
self.clone().into()
}
fn focus_handle(&self, cx: &WindowContext) -> FocusHandle {
self.read(cx).focus_handle(cx).clone()
}
}
impl From<&dyn PanelHandle> for AnyView {
@@ -422,7 +429,18 @@ impl Render for Dock {
type Element = Div<Self>;
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
todo!()
if let Some(entry) = self.visible_entry() {
let size = entry.panel.size(cx);
div()
.map(|this| match self.position().axis() {
Axis::Horizontal => this.w(px(size)).h_full(),
Axis::Vertical => this.h(px(size)).w_full(),
})
.child(entry.panel.to_any())
} else {
div()
}
}
}
@@ -728,5 +746,9 @@ pub mod test {
fn has_focus(&self, _cx: &WindowContext) -> bool {
self.has_focus
}
fn focus_handle(&self, cx: &WindowContext) -> FocusHandle {
unimplemented!()
}
}
}
+25 -12
View File
@@ -1,8 +1,8 @@
use gpui::{
div, px, AnyView, Div, EventEmitter, FocusHandle, ParentElement, Render, StatelessInteractive,
Styled, Subscription, View, ViewContext, VisualContext, WindowContext,
div, prelude::*, px, AnyView, Div, EventEmitter, FocusHandle, Render, Subscription, View,
ViewContext, WindowContext,
};
use ui::v_stack;
use ui::{h_stack, v_stack};
pub struct ActiveModal {
modal: AnyView,
@@ -33,8 +33,6 @@ impl ModalLayer {
V: Modal,
B: FnOnce(&mut ViewContext<V>) -> V,
{
let previous_focus = cx.focused();
if let Some(active_modal) = &self.active_modal {
let is_close = active_modal.modal.clone().downcast::<V>().is_ok();
self.hide_modal(cx);
@@ -73,6 +71,14 @@ impl ModalLayer {
cx.notify();
}
pub fn current_modal<V>(&self) -> Option<View<V>>
where
V: 'static,
{
let active_modal = self.active_modal.as_ref()?;
active_modal.modal.clone().downcast::<V>().ok()
}
}
impl Render for ModalLayer {
@@ -85,9 +91,6 @@ impl Render for ModalLayer {
div()
.absolute()
.flex()
.flex_col()
.items_center()
.size_full()
.top_0()
.left_0()
@@ -96,11 +99,21 @@ impl Render for ModalLayer {
v_stack()
.h(px(0.0))
.top_20()
.flex()
.flex_col()
.items_center()
.track_focus(&active_modal.focus_handle)
.on_mouse_down_out(|this: &mut Self, event, cx| {
this.hide_modal(cx);
})
.child(active_modal.modal.clone()),
.child(
h_stack()
// needed to prevent mouse events leaking to the
// UI below. // todo! for gpui3.
.on_any_mouse_down(|_, _, cx| cx.stop_propagation())
.on_any_mouse_up(|_, _, cx| cx.stop_propagation())
.on_mouse_down_out(|this: &mut Self, event, cx| {
this.hide_modal(cx);
})
.child(active_modal.modal.clone()),
),
)
}
}
+42 -27
View File
@@ -1,5 +1,3 @@
// mod dragged_item_receiver;
use crate::{
item::{Item, ItemHandle, ItemSettings, WeakItemHandle},
toolbar::Toolbar,
@@ -9,7 +7,7 @@ use crate::{
use anyhow::Result;
use collections::{HashMap, HashSet, VecDeque};
use gpui::{
actions, register_action, AppContext, AsyncWindowContext, Component, Div, EntityId,
actions, prelude::*, register_action, AppContext, AsyncWindowContext, Component, Div, EntityId,
EventEmitter, FocusHandle, Model, PromptLevel, Render, Task, View, ViewContext, VisualContext,
WeakView, WindowContext,
};
@@ -27,7 +25,7 @@ use std::{
},
};
use ui::v_stack;
use ui::{prelude::*, Icon, IconButton, IconColor, IconElement, TextTooltip};
use ui::{prelude::*, Icon, IconButton, IconElement, TextColor, TextTooltip};
use util::truncate_and_remove_front;
#[derive(PartialEq, Clone, Copy, Deserialize, Debug)]
@@ -733,21 +731,21 @@ impl Pane {
// self.activate_item(index, activate_pane, activate_pane, cx);
// }
// pub fn close_active_item(
// &mut self,
// action: &CloseActiveItem,
// cx: &mut ViewContext<Self>,
// ) -> Option<Task<Result<()>>> {
// if self.items.is_empty() {
// return None;
// }
// let active_item_id = self.items[self.active_item_index].id();
// Some(self.close_item_by_id(
// active_item_id,
// action.save_intent.unwrap_or(SaveIntent::Close),
// cx,
// ))
// }
pub fn close_active_item(
&mut self,
action: &CloseActiveItem,
cx: &mut ViewContext<Self>,
) -> Option<Task<Result<()>>> {
if self.items.is_empty() {
return None;
}
let active_item_id = self.items[self.active_item_index].id();
Some(self.close_item_by_id(
active_item_id,
action.save_intent.unwrap_or(SaveIntent::Close),
cx,
))
}
pub fn close_item_by_id(
&mut self,
@@ -1401,32 +1399,44 @@ impl Pane {
// .on_drop(|_view, state: View<DraggedTab>, cx| {
// eprintln!("{:?}", state.read(cx));
// })
.px_2()
.py_0p5()
.flex()
.items_center()
.justify_center()
// todo!("Nate - I need to do some work to balance all the items in the tab once things stablize")
.map(|this| {
if close_right {
this.pl_3().pr_1()
} else {
this.pr_1().pr_3()
}
})
.py_1()
.bg(tab_bg)
.hover(|h| h.bg(tab_hover_bg))
.active(|a| a.bg(tab_active_bg))
.border_color(cx.theme().colors().border)
.map(|this| match ix.cmp(&self.active_item_index) {
cmp::Ordering::Less => this.border_l(),
cmp::Ordering::Equal => this.border_r(),
cmp::Ordering::Greater => this.border_l().border_r(),
})
// .hover(|h| h.bg(tab_hover_bg))
// .active(|a| a.bg(tab_active_bg))
.child(
div()
.px_1()
.flex()
.items_center()
.gap_1p5()
.gap_1()
.text_color(text_color)
.children(if item.has_conflict(cx) {
Some(
IconElement::new(Icon::ExclamationTriangle)
.size(ui::IconSize::Small)
.color(IconColor::Warning),
.color(TextColor::Warning),
)
} else if item.is_dirty(cx) {
Some(
IconElement::new(Icon::ExclamationTriangle)
.size(ui::IconSize::Small)
.color(IconColor::Info),
.color(TextColor::Info),
)
} else {
None
@@ -1907,7 +1917,12 @@ impl Render for Pane {
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
v_stack()
.key_context("Pane")
.size_full()
.on_action(|pane: &mut Self, action, cx| {
pane.close_active_item(action, cx)
.map(|task| task.detach_and_log_err(cx));
})
.child(self.render_tab_bar(cx))
.child(self.toolbar.clone())
.child(if let Some(item) = self.active_item() {
@@ -2,7 +2,7 @@ use super::DraggedItem;
use crate::{Pane, SplitDirection, Workspace};
use gpui::{
color::Color,
elements::{Canvas, MouseEventHandler, ParentElement, Stack},
elements::{Canvas, MouseEventHandler, ParentComponent, Stack},
geometry::{rect::RectF, vector::Vector2F},
platform::MouseButton,
scene::MouseUp,
+1 -1
View File
@@ -2,7 +2,7 @@ use std::any::TypeId;
use crate::{ItemHandle, Pane};
use gpui::{
div, AnyView, Component, Div, ParentElement, Render, Styled, Subscription, View, ViewContext,
div, AnyView, Component, Div, ParentComponent, Render, Styled, Subscription, View, ViewContext,
WindowContext,
};
use theme2::ActiveTheme;
+4 -4
View File
@@ -1,10 +1,10 @@
use crate::ItemHandle;
use gpui::{
div, AnyView, Component, Div, Entity, EntityId, EventEmitter, ParentElement, Render, Styled,
View, ViewContext, WindowContext,
AnyView, Div, Entity, EntityId, EventEmitter, ParentComponent, Render, Styled, View,
ViewContext, WindowContext,
};
use theme2::ActiveTheme;
use ui::{h_stack, v_stack, Button, Icon, IconButton, Label, LabelColor, StyledExt};
use ui::{h_stack, v_stack, Button, Icon, IconButton, Label, TextColor};
pub enum ToolbarItemEvent {
ChangeLocation(ToolbarItemLocation),
@@ -92,7 +92,7 @@ impl Render for Toolbar {
h_stack()
.p_1()
.child(Button::new("crates"))
.child(Label::new("/").color(LabelColor::Muted))
.child(Label::new("/").color(TextColor::Muted))
.child(Button::new("workspace2")),
)
// Toolbar right side
File diff suppressed because it is too large Load Diff