fix clippy issues

This commit is contained in:
2024-12-11 09:11:30 +07:00
parent 516eb0e8bc
commit 10f042acab
49 changed files with 661 additions and 319 deletions

View File

@@ -1,3 +1,4 @@
#[allow(clippy::module_inception)]
mod dock;
mod invalid_panel;
mod panel;
@@ -6,7 +7,7 @@ mod state;
mod tab_panel;
use anyhow::Result;
pub use dock::*;
use gpui::{
actions, canvas, div, prelude::FluentBuilder, AnyElement, AnyView, AppContext, Axis, Bounds,
Edges, Entity as _, EntityId, EventEmitter, InteractiveElement as _, IntoElement,
@@ -15,11 +16,14 @@ use gpui::{
};
use std::sync::Arc;
pub use dock::*;
pub use panel::*;
pub use stack_panel::*;
pub use state::*;
pub use tab_panel::*;
use crate::theme::ActiveTheme;
pub fn init(cx: &mut AppContext) {
cx.set_global(PanelRegistry::new());
}
@@ -232,7 +236,7 @@ impl DockItem {
}
Self::Split { view, items, .. } => {
// Iter items to add panel to the first tabs
for item in items.into_iter() {
for item in items.iter_mut() {
if let DockItem::Tabs { view, .. } = item {
view.update(cx, |tab_panel, cx| {
tab_panel.add_panel(panel.clone(), cx);
@@ -636,12 +640,12 @@ impl DockArea {
}
self._subscriptions
.push(cx.subscribe(view, move |_, _, event, cx| match event {
PanelEvent::LayoutChanged => {
.push(cx.subscribe(view, move |_, _, event, cx| {
if let PanelEvent::LayoutChanged = event {
let dock_area = cx.view().clone();
cx.spawn(|_, mut cx| async move {
let _ = cx.update(|cx| {
let _ = dock_area.update(cx, |view, cx| {
dock_area.update(cx, |view, cx| {
view.update_toggle_button_tab_panels(cx)
});
});
@@ -649,7 +653,6 @@ impl DockArea {
.detach();
cx.emit(DockEvent::LayoutChanged);
}
_ => {}
}));
}
DockItem::Tabs { .. } => {
@@ -673,7 +676,7 @@ impl DockArea {
let panel = panel.clone();
cx.spawn(|_, mut cx| async move {
let _ = cx.update(|cx| {
let _ = dock_area.update(cx, |dock, cx| {
dock_area.update(cx, |dock, cx| {
dock.set_zoomed_in(panel, cx);
cx.notify();
});
@@ -685,7 +688,7 @@ impl DockArea {
let dock_area = cx.view().clone();
cx.spawn(|_, mut cx| async move {
let _ = cx.update(|cx| {
let _ = dock_area.update(cx, |view, cx| view.set_zoomed_out(cx));
dock_area.update(cx, |view, cx| view.set_zoomed_out(cx));
});
})
.detach()
@@ -694,8 +697,7 @@ impl DockArea {
let dock_area = cx.view().clone();
cx.spawn(|_, mut cx| async move {
let _ = cx.update(|cx| {
let _ = dock_area
.update(cx, |view, cx| view.update_toggle_button_tab_panels(cx));
dock_area.update(cx, |view, cx| view.update_toggle_button_tab_panels(cx));
});
})
.detach();
@@ -780,6 +782,8 @@ impl Render for DockArea {
// Left dock
.when_some(self.left_dock.clone(), |this, dock| {
this.child(div().flex().flex_none().child(dock))
.bg(cx.theme().sidebar)
.text_color(cx.theme().sidebar_foreground)
})
// Center
.child(

View File

@@ -143,19 +143,22 @@ impl PartialEq for dyn PanelView {
}
}
pub struct PanelRegistry {
pub(super) items: HashMap<
String,
Arc<
dyn Fn(
WeakView<DockArea>,
&DockItemState,
&DockItemInfo,
&mut WindowContext,
) -> Box<dyn PanelView>,
>,
type PanelRegistryItem = HashMap<
String,
Arc<
dyn Fn(
WeakView<DockArea>,
&DockItemState,
&DockItemInfo,
&mut WindowContext,
) -> Box<dyn PanelView>,
>,
>;
pub struct PanelRegistry {
pub(super) items: PanelRegistryItem,
}
impl PanelRegistry {
pub fn new() -> Self {
Self {
@@ -163,6 +166,13 @@ impl PanelRegistry {
}
}
}
impl Default for PanelRegistry {
fn default() -> Self {
Self::new()
}
}
impl Global for PanelRegistry {}
/// Register the Panel init by panel_name to global registry.
@@ -176,7 +186,7 @@ where
) -> Box<dyn PanelView>
+ 'static,
{
if let None = cx.try_global::<PanelRegistry>() {
if cx.try_global::<PanelRegistry>().is_none() {
cx.set_global(PanelRegistry::new());
}

View File

@@ -184,7 +184,7 @@ impl StackPanel {
cx: &mut ViewContext<Self>,
) {
// If the panel is already in the stack, return.
if let Some(_) = self.index_of_panel(panel.clone()) {
if self.index_of_panel(panel.clone()).is_some() {
return;
}

View File

@@ -456,7 +456,7 @@ impl TabPanel {
let right_dock_button = self.render_dock_toggle_button(DockPlacement::Right, cx);
if self.panels.len() == 1 && panel_style == PanelStyle::Default {
let panel = self.panels.get(0).unwrap();
let panel = self.panels.first().unwrap();
let title_style = panel.title_style(cx);
return h_flex()
@@ -694,6 +694,7 @@ impl TabPanel {
// If target is same tab, and it is only one panel, do nothing.
if is_same_tab && ix.is_none() {
#[allow(clippy::if_same_then_else)]
if self.will_split_placement.is_none() {
return;
} else if self.panels.len() == 1 {
@@ -708,7 +709,7 @@ impl TabPanel {
if is_same_tab {
self.detach_panel(panel.clone(), cx);
} else {
let _ = drag.tab_panel.update(cx, |view, cx| {
drag.tab_panel.update(cx, |view, cx| {
view.detach_panel(panel.clone(), cx);
view.remove_self_if_empty(cx);
});