Wire up buffer search toggle for EditorPane
This commit is contained in:
parent
e477fa7a93
commit
c70f220db3
4 changed files with 94 additions and 64 deletions
|
@ -12,8 +12,8 @@ use std::sync::Arc;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use gpui3::{
|
use gpui3::{
|
||||||
div, px, size, view, AnyView, Bounds, Context, Element, ViewContext, WindowBounds,
|
div, px, size, view, AnyView, BorrowAppContext, Bounds, Context, Element, ViewContext,
|
||||||
WindowOptions,
|
WindowBounds, WindowOptions,
|
||||||
};
|
};
|
||||||
use log::LevelFilter;
|
use log::LevelFilter;
|
||||||
use simplelog::SimpleLogger;
|
use simplelog::SimpleLogger;
|
||||||
|
@ -68,7 +68,11 @@ fn main() {
|
||||||
},
|
},
|
||||||
move |cx| {
|
move |cx| {
|
||||||
view(
|
view(
|
||||||
cx.entity(|cx| StoryWrapper::new(selector.story(cx), theme)),
|
cx.entity(|cx| {
|
||||||
|
cx.with_global(theme.clone(), |cx| {
|
||||||
|
StoryWrapper::new(selector.story(cx), theme)
|
||||||
|
})
|
||||||
|
}),
|
||||||
StoryWrapper::render,
|
StoryWrapper::render,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,43 +1,74 @@
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use gpui3::{view, Context, View};
|
||||||
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::{v_stack, Breadcrumb, Buffer, Icon, IconButton, Symbol, Tab, TabBar, Toolbar};
|
use crate::{
|
||||||
|
hello_world_rust_editor_with_status_example, v_stack, Breadcrumb, Buffer, Icon, IconButton,
|
||||||
|
IconColor, Symbol, Tab, TabBar, Toolbar,
|
||||||
|
};
|
||||||
|
|
||||||
pub struct Editor<S: 'static + Send + Sync + Clone> {
|
#[derive(Clone)]
|
||||||
pub tabs: Vec<Tab<S>>,
|
pub struct EditorPane {
|
||||||
pub path: PathBuf,
|
tabs: Vec<Tab<Self>>,
|
||||||
pub symbols: Vec<Symbol>,
|
path: PathBuf,
|
||||||
pub buffer: Buffer<S>,
|
symbols: Vec<Symbol>,
|
||||||
|
buffer: Buffer<Self>,
|
||||||
|
is_buffer_search_open: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Element)]
|
impl EditorPane {
|
||||||
pub struct EditorPane<S: 'static + Send + Sync + Clone> {
|
pub fn new(
|
||||||
editor: Editor<S>,
|
tabs: Vec<Tab<Self>>,
|
||||||
|
path: PathBuf,
|
||||||
|
symbols: Vec<Symbol>,
|
||||||
|
buffer: Buffer<Self>,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
tabs,
|
||||||
|
path,
|
||||||
|
symbols,
|
||||||
|
buffer,
|
||||||
|
is_buffer_search_open: false,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: 'static + Send + Sync + Clone> EditorPane<S> {
|
pub fn toggle_buffer_search(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
pub fn new(editor: Editor<S>) -> Self {
|
self.is_buffer_search_open = !self.is_buffer_search_open;
|
||||||
Self { editor }
|
|
||||||
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
|
pub fn view(cx: &mut WindowContext) -> View<Self> {
|
||||||
|
let theme = theme(cx);
|
||||||
|
|
||||||
|
view(
|
||||||
|
cx.entity(|cx| hello_world_rust_editor_with_status_example(&theme)),
|
||||||
|
Self::render,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element<ViewState = Self> {
|
||||||
v_stack()
|
v_stack()
|
||||||
.w_full()
|
.w_full()
|
||||||
.h_full()
|
.h_full()
|
||||||
.flex_1()
|
.flex_1()
|
||||||
.child(TabBar::new(self.editor.tabs.clone()))
|
.child(TabBar::new(self.tabs.clone()))
|
||||||
.child(
|
.child(
|
||||||
Toolbar::new()
|
Toolbar::new()
|
||||||
.left_item(Breadcrumb::new(
|
.left_item(Breadcrumb::new(self.path.clone(), self.symbols.clone()))
|
||||||
self.editor.path.clone(),
|
|
||||||
self.editor.symbols.clone(),
|
|
||||||
))
|
|
||||||
.right_items(vec![
|
.right_items(vec![
|
||||||
IconButton::new(Icon::InlayHint).into_any(),
|
IconButton::new(Icon::InlayHint),
|
||||||
IconButton::new(Icon::MagnifyingGlass).into_any(),
|
IconButton::<Self>::new(Icon::MagnifyingGlass)
|
||||||
IconButton::new(Icon::MagicWand).into_any(),
|
.when(self.is_buffer_search_open, |this| {
|
||||||
|
this.color(IconColor::Accent)
|
||||||
|
})
|
||||||
|
.on_click(|editor, cx| {
|
||||||
|
editor.toggle_buffer_search(cx);
|
||||||
|
}),
|
||||||
|
IconButton::new(Icon::MagicWand),
|
||||||
]),
|
]),
|
||||||
)
|
)
|
||||||
.child(self.editor.buffer.clone())
|
.child(self.buffer.clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,18 @@
|
||||||
use chrono::DateTime;
|
use chrono::DateTime;
|
||||||
use gpui3::{px, relative, rems, view, Context, Size, View};
|
use gpui3::{px, relative, rems, view, Context, Size, View};
|
||||||
|
|
||||||
|
use crate::prelude::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
hello_world_rust_editor_with_status_example, theme, v_stack, AssistantPanel, Button,
|
theme, v_stack, AssistantPanel, Button, ChatMessage, ChatPanel, CollabPanel, EditorPane, Label,
|
||||||
ChatMessage, ChatPanel, CollabPanel, EditorPane, Label, LanguageSelector, Pane, PaneGroup,
|
LanguageSelector, NotificationToast, Pane, PaneGroup, Panel, PanelAllowedSides, PanelSide,
|
||||||
Panel, PanelAllowedSides, PanelSide, ProjectPanel, SplitDirection, StatusBar, Terminal,
|
ProjectPanel, SplitDirection, StatusBar, Terminal, TitleBar, Toast, ToastOrigin,
|
||||||
TitleBar, Toast, ToastOrigin,
|
|
||||||
};
|
};
|
||||||
use crate::{prelude::*, NotificationToast};
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Workspace {
|
pub struct Workspace {
|
||||||
title_bar: View<TitleBar>,
|
title_bar: View<TitleBar>,
|
||||||
|
editor_1: View<EditorPane>,
|
||||||
|
editor_2: View<EditorPane>,
|
||||||
show_project_panel: bool,
|
show_project_panel: bool,
|
||||||
show_collab_panel: bool,
|
show_collab_panel: bool,
|
||||||
show_chat_panel: bool,
|
show_chat_panel: bool,
|
||||||
|
@ -28,6 +29,8 @@ impl Workspace {
|
||||||
pub fn new(cx: &mut ViewContext<Self>) -> Self {
|
pub fn new(cx: &mut ViewContext<Self>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
title_bar: TitleBar::view(cx),
|
title_bar: TitleBar::view(cx),
|
||||||
|
editor_1: EditorPane::view(cx),
|
||||||
|
editor_2: EditorPane::view(cx),
|
||||||
show_project_panel: true,
|
show_project_panel: true,
|
||||||
show_collab_panel: false,
|
show_collab_panel: false,
|
||||||
show_chat_panel: true,
|
show_chat_panel: true,
|
||||||
|
@ -127,9 +130,7 @@ impl Workspace {
|
||||||
height: temp_size,
|
height: temp_size,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.child(EditorPane::new(
|
.child(self.editor_1.clone()),
|
||||||
hello_world_rust_editor_with_status_example(&theme),
|
|
||||||
)),
|
|
||||||
Pane::new(
|
Pane::new(
|
||||||
ScrollState::default(),
|
ScrollState::default(),
|
||||||
Size {
|
Size {
|
||||||
|
@ -149,9 +150,7 @@ impl Workspace {
|
||||||
height: relative(1.).into(),
|
height: relative(1.).into(),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.child(EditorPane::new(
|
.child(self.editor_2.clone())],
|
||||||
hello_world_rust_editor_with_status_example(&theme),
|
|
||||||
))],
|
|
||||||
SplitDirection::Vertical,
|
SplitDirection::Vertical,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
|
@ -4,7 +4,7 @@ use std::str::FromStr;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Buffer, BufferRow, BufferRows, Editor, FileSystemStatus, GitStatus, HighlightColor,
|
Buffer, BufferRow, BufferRows, EditorPane, FileSystemStatus, GitStatus, HighlightColor,
|
||||||
HighlightedLine, HighlightedText, Icon, Keybinding, Label, LabelColor, ListEntry,
|
HighlightedLine, HighlightedText, Icon, Keybinding, Label, LabelColor, ListEntry,
|
||||||
ListEntrySize, ListItem, Livestream, MicStatus, ModifierKeys, PaletteItem, Player,
|
ListEntrySize, ListItem, Livestream, MicStatus, ModifierKeys, PaletteItem, Player,
|
||||||
PlayerCallStatus, PlayerWithCallStatus, ScreenShareStatus, Symbol, Tab, Theme, ToggleState,
|
PlayerCallStatus, PlayerWithCallStatus, ScreenShareStatus, Symbol, Tab, Theme, ToggleState,
|
||||||
|
@ -597,26 +597,24 @@ pub fn example_editor_actions<S: 'static + Send + Sync + Clone>() -> Vec<Palette
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn empty_editor_example<S: 'static + Send + Sync + Clone>() -> Editor<S> {
|
pub fn empty_editor_example() -> EditorPane {
|
||||||
Editor {
|
EditorPane::new(
|
||||||
tabs: static_tabs_example(),
|
static_tabs_example(),
|
||||||
path: PathBuf::from_str("crates/ui/src/static_data.rs").unwrap(),
|
PathBuf::from_str("crates/ui/src/static_data.rs").unwrap(),
|
||||||
symbols: vec![],
|
vec![],
|
||||||
buffer: empty_buffer_example(),
|
empty_buffer_example(),
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn empty_buffer_example<S: 'static + Send + Sync + Clone>() -> Buffer<S> {
|
pub fn empty_buffer_example<S: 'static + Send + Sync + Clone>() -> Buffer<S> {
|
||||||
Buffer::new().set_rows(Some(BufferRows::default()))
|
Buffer::new().set_rows(Some(BufferRows::default()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hello_world_rust_editor_example<S: 'static + Send + Sync + Clone>(
|
pub fn hello_world_rust_editor_example(theme: &Theme) -> EditorPane {
|
||||||
theme: &Theme,
|
EditorPane::new(
|
||||||
) -> Editor<S> {
|
static_tabs_example(),
|
||||||
Editor {
|
PathBuf::from_str("crates/ui/src/static_data.rs").unwrap(),
|
||||||
tabs: static_tabs_example(),
|
vec![Symbol(vec![
|
||||||
path: PathBuf::from_str("crates/ui/src/static_data.rs").unwrap(),
|
|
||||||
symbols: vec![Symbol(vec![
|
|
||||||
HighlightedText {
|
HighlightedText {
|
||||||
text: "fn ".to_string(),
|
text: "fn ".to_string(),
|
||||||
color: HighlightColor::Keyword.hsla(&theme),
|
color: HighlightColor::Keyword.hsla(&theme),
|
||||||
|
@ -626,8 +624,8 @@ pub fn hello_world_rust_editor_example<S: 'static + Send + Sync + Clone>(
|
||||||
color: HighlightColor::Function.hsla(&theme),
|
color: HighlightColor::Function.hsla(&theme),
|
||||||
},
|
},
|
||||||
])],
|
])],
|
||||||
buffer: hello_world_rust_buffer_example(theme),
|
hello_world_rust_buffer_example(theme),
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hello_world_rust_buffer_example<S: 'static + Send + Sync + Clone>(
|
pub fn hello_world_rust_buffer_example<S: 'static + Send + Sync + Clone>(
|
||||||
|
@ -750,13 +748,11 @@ pub fn hello_world_rust_buffer_rows(theme: &Theme) -> Vec<BufferRow> {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hello_world_rust_editor_with_status_example<S: 'static + Send + Sync + Clone>(
|
pub fn hello_world_rust_editor_with_status_example(theme: &Theme) -> EditorPane {
|
||||||
theme: &Theme,
|
EditorPane::new(
|
||||||
) -> Editor<S> {
|
static_tabs_example(),
|
||||||
Editor {
|
PathBuf::from_str("crates/ui/src/static_data.rs").unwrap(),
|
||||||
tabs: static_tabs_example(),
|
vec![Symbol(vec![
|
||||||
path: PathBuf::from_str("crates/ui/src/static_data.rs").unwrap(),
|
|
||||||
symbols: vec![Symbol(vec![
|
|
||||||
HighlightedText {
|
HighlightedText {
|
||||||
text: "fn ".to_string(),
|
text: "fn ".to_string(),
|
||||||
color: HighlightColor::Keyword.hsla(&theme),
|
color: HighlightColor::Keyword.hsla(&theme),
|
||||||
|
@ -766,8 +762,8 @@ pub fn hello_world_rust_editor_with_status_example<S: 'static + Send + Sync + Cl
|
||||||
color: HighlightColor::Function.hsla(&theme),
|
color: HighlightColor::Function.hsla(&theme),
|
||||||
},
|
},
|
||||||
])],
|
])],
|
||||||
buffer: hello_world_rust_buffer_with_status_example(theme),
|
hello_world_rust_buffer_with_status_example(theme),
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hello_world_rust_buffer_with_status_example<S: 'static + Send + Sync + Clone>(
|
pub fn hello_world_rust_buffer_with_status_example<S: 'static + Send + Sync + Clone>(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue