Add DivRegistrar to reduce code duplication
This commit is contained in:
parent
9cdcdbea41
commit
b6655def70
3 changed files with 59 additions and 55 deletions
|
|
@ -3,13 +3,12 @@ use std::{path::PathBuf, sync::Arc};
|
|||
use crate::TerminalView;
|
||||
use db::kvp::KEY_VALUE_STORE;
|
||||
use gpui::{
|
||||
actions, div, serde_json, AppContext, AsyncWindowContext, Div, Entity, EventEmitter,
|
||||
ExternalPaths, FocusHandle, FocusableView, InteractiveElement, IntoElement, ParentElement,
|
||||
Pixels, Render, Styled, Subscription, Task, View, ViewContext, VisualContext, WeakView,
|
||||
WindowContext,
|
||||
actions, serde_json, AppContext, AsyncWindowContext, Entity, EventEmitter, ExternalPaths,
|
||||
FocusHandle, FocusableView, IntoElement, ParentElement, Pixels, Render, Styled, Subscription,
|
||||
Task, View, ViewContext, VisualContext, WeakView, WindowContext,
|
||||
};
|
||||
use project::Fs;
|
||||
use search::{buffer_search::SearchActionsRegistrar, BufferSearchBar};
|
||||
use search::{buffer_search::DivRegistrar, BufferSearchBar};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use settings::{Settings, SettingsStore};
|
||||
use terminal::terminal_settings::{TerminalDockPosition, TerminalSettings};
|
||||
|
|
@ -330,36 +329,21 @@ impl TerminalPanel {
|
|||
|
||||
impl EventEmitter<PanelEvent> for TerminalPanel {}
|
||||
|
||||
struct ActionsRegistrar<'a, 'b>
|
||||
where
|
||||
'b: 'a,
|
||||
{
|
||||
div: Option<Div>,
|
||||
cx: &'a mut ViewContext<'b, TerminalPanel>,
|
||||
}
|
||||
impl SearchActionsRegistrar for ActionsRegistrar<'_, '_> {
|
||||
fn register_handler<A: gpui::Action>(
|
||||
&mut self,
|
||||
callback: fn(&mut BufferSearchBar, &A, &mut ViewContext<BufferSearchBar>),
|
||||
) {
|
||||
self.div = self.div.take().map(|div| {
|
||||
div.on_action(self.cx.listener(move |this, action, cx| {
|
||||
this.pane
|
||||
impl Render for TerminalPanel {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
let mut registrar = DivRegistrar::new(
|
||||
|panel, cx| {
|
||||
panel
|
||||
.pane
|
||||
.read(cx)
|
||||
.toolbar()
|
||||
.read(cx)
|
||||
.item_of_type::<BufferSearchBar>()
|
||||
.map(|search_bar| search_bar.update(cx, |this, cx| callback(this, action, cx)));
|
||||
}))
|
||||
});
|
||||
}
|
||||
}
|
||||
impl Render for TerminalPanel {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
let div = div();
|
||||
let mut registrar = ActionsRegistrar { div: Some(div), cx };
|
||||
},
|
||||
cx,
|
||||
);
|
||||
BufferSearchBar::register_inner(&mut registrar);
|
||||
registrar.div.unwrap().size_full().child(self.pane.clone())
|
||||
registrar.into_div().size_full().child(self.pane.clone())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue