mirror of
https://github.com/project-gauntlet/gauntlet.git
synced 2025-12-23 10:35:53 +00:00
Add entrypoint name to the bottom panel of view
This commit is contained in:
parent
903079f7e4
commit
35d419bcac
4 changed files with 68 additions and 27 deletions
|
|
@ -56,7 +56,9 @@ pub struct AppModel {
|
|||
struct PluginViewData {
|
||||
top_level_view: bool,
|
||||
plugin_id: PluginId,
|
||||
plugin_name: String,
|
||||
entrypoint_id: EntrypointId,
|
||||
entrypoint_name: String,
|
||||
}
|
||||
|
||||
struct PreferenceRequiredViewData {
|
||||
|
|
@ -70,7 +72,9 @@ struct PreferenceRequiredViewData {
|
|||
pub enum AppMsg {
|
||||
OpenView {
|
||||
plugin_id: PluginId,
|
||||
plugin_name: String,
|
||||
entrypoint_id: EntrypointId,
|
||||
entrypoint_name: String,
|
||||
},
|
||||
RunCommand {
|
||||
plugin_id: PluginId,
|
||||
|
|
@ -186,11 +190,13 @@ impl Application for AppModel {
|
|||
|
||||
fn update(&mut self, message: Self::Message) -> Command<Self::Message> {
|
||||
match message {
|
||||
AppMsg::OpenView { plugin_id, entrypoint_id } => {
|
||||
AppMsg::OpenView { plugin_id, plugin_name, entrypoint_id, entrypoint_name } => {
|
||||
self.plugin_view_data.replace(PluginViewData {
|
||||
top_level_view: true,
|
||||
plugin_id: plugin_id.clone(),
|
||||
plugin_name,
|
||||
entrypoint_id: entrypoint_id.clone(),
|
||||
entrypoint_name
|
||||
});
|
||||
|
||||
self.open_view(plugin_id, entrypoint_id)
|
||||
|
|
@ -492,7 +498,9 @@ impl Application for AppModel {
|
|||
search_results,
|
||||
|event| AppMsg::OpenView {
|
||||
plugin_id: event.plugin_id,
|
||||
plugin_name: event.plugin_name,
|
||||
entrypoint_id: event.entrypoint_id,
|
||||
entrypoint_name: event.entrypoint_name,
|
||||
},
|
||||
|event| AppMsg::RunCommand {
|
||||
plugin_id: event.plugin_id,
|
||||
|
|
@ -552,14 +560,19 @@ impl Application for AppModel {
|
|||
// element.explain(iced::color!(0xFF0000))
|
||||
element
|
||||
}
|
||||
Some(PluginViewData { plugin_id, entrypoint_id: _, top_level_view: _ }) => {
|
||||
let container_element: Element<_> = view_container(self.client_context.clone(), plugin_id.to_owned())
|
||||
.into();
|
||||
Some(PluginViewData { top_level_view: _, plugin_id, plugin_name, entrypoint_id, entrypoint_name }) => {
|
||||
let container_element: Element<_> = view_container(
|
||||
self.client_context.clone(),
|
||||
plugin_id.to_owned(),
|
||||
plugin_name.to_owned(),
|
||||
entrypoint_id.to_owned(),
|
||||
entrypoint_name.to_owned()
|
||||
).into();
|
||||
|
||||
let element: Element<_> = container(container_element)
|
||||
.style(ContainerStyle::Background)
|
||||
.height(Length::Fixed(SUB_VIEW_WINDOW_HEIGHT as f32))
|
||||
.width(Length::Fixed(SUB_VIEW_WINDOW_WIDTH as f32))
|
||||
.height(Length::Fixed(SUB_VIEW_WINDOW_HEIGHT))
|
||||
.width(Length::Fixed(SUB_VIEW_WINDOW_WIDTH))
|
||||
.into();
|
||||
|
||||
// element.explain(iced::color!(0xFF0000))
|
||||
|
|
@ -652,7 +665,7 @@ impl AppModel {
|
|||
window::resize(window::Id::MAIN, Size::new(WINDOW_WIDTH, WINDOW_HEIGHT))
|
||||
])
|
||||
}
|
||||
Some(PluginViewData { top_level_view: false, plugin_id, entrypoint_id }) => {
|
||||
Some(PluginViewData { top_level_view: false, plugin_id, entrypoint_id, .. }) => {
|
||||
self.open_view(plugin_id.clone(), entrypoint_id.clone())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,9 @@ pub fn search_list<Message>(
|
|||
|
||||
pub struct OpenViewEvent {
|
||||
pub plugin_id: PluginId,
|
||||
pub plugin_name: String,
|
||||
pub entrypoint_id: EntrypointId,
|
||||
pub entrypoint_name: String,
|
||||
}
|
||||
|
||||
pub struct RunCommandEvent {
|
||||
|
|
@ -50,7 +52,9 @@ pub enum Event {
|
|||
},
|
||||
OpenView {
|
||||
plugin_id: PluginId,
|
||||
plugin_name: String,
|
||||
entrypoint_id: EntrypointId,
|
||||
entrypoint_name: String,
|
||||
},
|
||||
RunGeneratedCommand {
|
||||
plugin_id: PluginId,
|
||||
|
|
@ -84,8 +88,8 @@ impl<Message> Component<Message, GauntletTheme> for SearchList<Message> {
|
|||
event: Event,
|
||||
) -> Option<Message> {
|
||||
match event {
|
||||
Event::OpenView { plugin_id, entrypoint_id } => {
|
||||
let event = OpenViewEvent { plugin_id, entrypoint_id, };
|
||||
Event::OpenView { plugin_id, plugin_name, entrypoint_id, entrypoint_name } => {
|
||||
let event = OpenViewEvent { plugin_id, plugin_name, entrypoint_id, entrypoint_name };
|
||||
Some((self.on_open_view)(event))
|
||||
}
|
||||
Event::RunCommand { plugin_id, entrypoint_id } => {
|
||||
|
|
@ -127,8 +131,10 @@ impl<Message> Component<Message, GauntletTheme> for SearchList<Message> {
|
|||
plugin_id: search_result.plugin_id.clone()
|
||||
},
|
||||
SearchResultEntrypointType::View => Event::OpenView {
|
||||
plugin_id: search_result.plugin_id.clone(),
|
||||
plugin_name: search_result.plugin_name.clone(),
|
||||
entrypoint_id: search_result.entrypoint_id.clone(),
|
||||
plugin_id: search_result.plugin_id.clone()
|
||||
entrypoint_name: search_result.entrypoint_name.clone(),
|
||||
},
|
||||
SearchResultEntrypointType::GeneratedCommand => Event::RunGeneratedCommand {
|
||||
entrypoint_id: search_result.entrypoint_id.clone(),
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use std::sync::{Arc, RwLock};
|
|||
use iced::widget::Component;
|
||||
use iced::widget::component;
|
||||
|
||||
use common::model::{PluginId, RenderLocation};
|
||||
use common::model::{EntrypointId, PluginId, RenderLocation};
|
||||
|
||||
use crate::ui::AppMsg;
|
||||
use crate::ui::client_context::ClientContext;
|
||||
|
|
@ -13,12 +13,18 @@ use crate::ui::widget::{ComponentRenderContext, ComponentWidgetEvent};
|
|||
pub struct ViewContainer {
|
||||
client_context: Arc<RwLock<ClientContext>>,
|
||||
plugin_id: PluginId,
|
||||
plugin_name: String,
|
||||
entrypoint_id: EntrypointId,
|
||||
entrypoint_name: String,
|
||||
}
|
||||
|
||||
pub fn view_container(client_context: Arc<RwLock<ClientContext>>, plugin_id: PluginId) -> ViewContainer {
|
||||
pub fn view_container(client_context: Arc<RwLock<ClientContext>>, plugin_id: PluginId, plugin_name: String, entrypoint_id: EntrypointId, entrypoint_name: String) -> ViewContainer {
|
||||
ViewContainer {
|
||||
client_context,
|
||||
plugin_id
|
||||
plugin_id,
|
||||
plugin_name,
|
||||
entrypoint_id,
|
||||
entrypoint_name,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -41,7 +47,7 @@ impl Component<AppMsg, GauntletTheme> for ViewContainer {
|
|||
fn view(&self, _state: &Self::State) -> Element<Self::Event> {
|
||||
let client_context = self.client_context.read().expect("lock is poisoned");
|
||||
let view_container = client_context.get_view_container();
|
||||
view_container.render_widget(ComponentRenderContext::None)
|
||||
view_container.render_widget(ComponentRenderContext::Root { entrypoint_name: self.entrypoint_name.clone() })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ impl ComponentWidgetState {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ComponentRenderContext {
|
||||
None,
|
||||
H1,
|
||||
|
|
@ -121,6 +121,9 @@ pub enum ComponentRenderContext {
|
|||
Grid {
|
||||
widget_id: NativeUiWidgetId
|
||||
},
|
||||
Root {
|
||||
entrypoint_name: String,
|
||||
}
|
||||
}
|
||||
|
||||
impl ComponentWidgetWrapper {
|
||||
|
|
@ -450,10 +453,10 @@ impl ComponentWidgetWrapper {
|
|||
}
|
||||
};
|
||||
|
||||
render_root(show_action_panel, widget_id, children, content)
|
||||
render_root(show_action_panel, widget_id, children, content, context)
|
||||
}
|
||||
ComponentWidget::Root { children } => {
|
||||
row(render_children(children, ComponentRenderContext::None))
|
||||
row(render_children(children, context))
|
||||
.into()
|
||||
}
|
||||
ComponentWidget::TextField { .. } => {
|
||||
|
|
@ -567,7 +570,7 @@ impl ComponentWidgetWrapper {
|
|||
let (widget, _) = &*child.get();
|
||||
|
||||
match widget {
|
||||
ComponentWidget::Separator => Some(child.render_widget(context)),
|
||||
ComponentWidget::Separator => Some(child.render_widget(ComponentRenderContext::None)),
|
||||
ComponentWidget::ActionPanel { .. } => None,
|
||||
_ => {
|
||||
let label = match widget {
|
||||
|
|
@ -597,7 +600,7 @@ impl ComponentWidgetWrapper {
|
|||
}
|
||||
};
|
||||
|
||||
let form_input = container(child.render_widget(context))
|
||||
let form_input = container(child.render_widget(ComponentRenderContext::None))
|
||||
.width(Length::FillPortion(3))
|
||||
.into();
|
||||
|
||||
|
|
@ -627,7 +630,7 @@ impl ComponentWidgetWrapper {
|
|||
.width(Length::Fill)
|
||||
.into();
|
||||
|
||||
render_root(show_action_panel, widget_id, children, content)
|
||||
render_root(show_action_panel, widget_id, children, content, context)
|
||||
}
|
||||
ComponentWidget::InlineSeparator => {
|
||||
vertical_rule(1)
|
||||
|
|
@ -786,7 +789,7 @@ impl ComponentWidgetWrapper {
|
|||
.width(Length::Fill)
|
||||
.into();
|
||||
|
||||
render_root(show_action_panel, widget_id, children, content)
|
||||
render_root(show_action_panel, widget_id, children, content, context)
|
||||
}
|
||||
ComponentWidget::GridItem { children, id, title, subtitle } => {
|
||||
let ComponentRenderContext::Grid { widget_id: grid_widget_id } = context else {
|
||||
|
|
@ -861,7 +864,7 @@ impl ComponentWidgetWrapper {
|
|||
.width(Length::Fill)
|
||||
.into();
|
||||
|
||||
render_root(show_action_panel, widget_id, children, content)
|
||||
render_root(show_action_panel, widget_id, children, content, context)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1002,7 +1005,19 @@ fn render_section<'a>(content: Element<'a, ComponentWidgetEvent>, title: Option<
|
|||
.into()
|
||||
}
|
||||
|
||||
fn render_root<'a>(show_action_panel: bool, widget_id: NativeUiWidgetId, children: &[ComponentWidgetWrapper], content: Element<'a, ComponentWidgetEvent>) -> Element<'a, ComponentWidgetEvent> {
|
||||
fn render_root<'a>(
|
||||
show_action_panel: bool,
|
||||
widget_id: NativeUiWidgetId,
|
||||
children: &[ComponentWidgetWrapper],
|
||||
content: Element<'a, ComponentWidgetEvent>,
|
||||
context: ComponentRenderContext
|
||||
) -> Element<'a, ComponentWidgetEvent> {
|
||||
let ComponentRenderContext::Root { entrypoint_name } = context else {
|
||||
panic!("not supposed to be passed to root item: {:?}", context)
|
||||
};
|
||||
|
||||
let entrypoint_name: Element<_> = text(entrypoint_name)
|
||||
.into();
|
||||
|
||||
let space = Space::with_width(Length::FillPortion(3))
|
||||
.into();
|
||||
|
|
@ -1017,12 +1032,12 @@ fn render_root<'a>(show_action_panel: bool, widget_id: NativeUiWidgetId, childre
|
|||
.on_press(ComponentWidgetEvent::ToggleActionPanel { widget_id })
|
||||
.into();
|
||||
|
||||
let bottom_panel: Element<_> = row(vec![space, action_panel_toggle])
|
||||
let bottom_panel: Element<_> = row(vec![entrypoint_name, space, action_panel_toggle])
|
||||
.into();
|
||||
|
||||
(!show_action_panel, action_panel_element, bottom_panel)
|
||||
} else {
|
||||
let bottom_panel: Element<_> = row(vec![space])
|
||||
let bottom_panel: Element<_> = row(vec![entrypoint_name, space])
|
||||
.into();
|
||||
|
||||
(true, Space::with_height(1).into(), bottom_panel)
|
||||
|
|
@ -1067,6 +1082,7 @@ fn render_text_part<'a>(value: &str, context: ComponentRenderContext) -> Element
|
|||
ComponentRenderContext::H6 => Some(16),
|
||||
ComponentRenderContext::List { .. } => panic!("not supposed to be passed to text part"),
|
||||
ComponentRenderContext::Grid { .. } => panic!("not supposed to be passed to text part"),
|
||||
ComponentRenderContext::Root { .. } => panic!("not supposed to be passed to text part")
|
||||
};
|
||||
|
||||
let mut text = text(value);
|
||||
|
|
@ -1110,7 +1126,7 @@ fn render_children<'a>(
|
|||
) -> Vec<Element<'a, ComponentWidgetEvent>> {
|
||||
return content
|
||||
.into_iter()
|
||||
.map(|child| child.render_widget(context))
|
||||
.map(|child| child.render_widget(context.clone()))
|
||||
.collect();
|
||||
}
|
||||
|
||||
|
|
@ -1144,7 +1160,7 @@ fn render_children_by_type<'a>(
|
|||
let (widget, _) = &*child.get();
|
||||
predicate(widget)
|
||||
})
|
||||
.map(|child| child.render_widget(context))
|
||||
.map(|child| child.render_widget(context.clone()))
|
||||
.collect();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue