sync
This commit is contained in:
parent
18b7d2d3d8
commit
b0458c34a5
@ -1,6 +1,32 @@
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
use gtk::gio::SimpleAction;
|
||||
use gtk::prelude::{BoxExt, ButtonExt, GtkWindowExt, OrientableExt};
|
||||
use relm4::actions::{AccelsPlus, ActionablePlus, RelmAction, RelmActionGroup};
|
||||
use relm4::{ComponentParts, ComponentSender, RelmApp, RelmWidgetExt, SimpleComponent};
|
||||
|
||||
relm4::new_action_group!(LayerActionGroup, "layer");
|
||||
relm4::new_stateful_action!(AddLayerAction, LayerActionGroup, "add", u8, u8);
|
||||
use crate::components::app::{AppModel, AppMsg};
|
||||
use crate::widgets::Layer;
|
||||
|
||||
relm4::new_action_group!(pub LayerActionGroup, "layer");
|
||||
relm4::new_stateless_action!(pub AddLayerAction, LayerActionGroup, "add");
|
||||
relm4::new_stateless_action!(pub RemoveLayerAction, LayerActionGroup, "remove");
|
||||
relm4::new_stateless_action!(pub MoveLayerAction, LayerActionGroup, "move");
|
||||
|
||||
pub fn register_layer_actions<W: AsRef<gtk::Widget>>(widget: W, sender: ComponentSender<AppModel>) {
|
||||
let add_action: RelmAction<AddLayerAction> = {
|
||||
let sender = sender.clone();
|
||||
RelmAction::new_stateless(move |_| sender.input(AppMsg::AddLayer))
|
||||
};
|
||||
|
||||
let remove_action: RelmAction<RemoveLayerAction> = {
|
||||
let sender = sender.clone();
|
||||
RelmAction::new_stateless(move |_| sender.input(AppMsg::RemoveSelectedLayer))
|
||||
};
|
||||
|
||||
let mut group: RelmActionGroup<LayerActionGroup> = RelmActionGroup::new();
|
||||
group.add_action(add_action);
|
||||
group.add_action(remove_action);
|
||||
group.register_for_widget(widget)
|
||||
}
|
||||
|
||||
@ -5,11 +5,12 @@ use super::{
|
||||
setting::SettingModel,
|
||||
ControlPanelOutputMsg, TimelineMsg,
|
||||
};
|
||||
use crate::pipeline::element::{
|
||||
Element, InstantElement, InstantElementDrawerType, TimeSeriesElement,
|
||||
};
|
||||
use crate::pipeline::{GridElementImpl, OffscreenRenderer};
|
||||
use crate::widgets::AssoElement;
|
||||
use crate::{
|
||||
actions::register_layer_actions,
|
||||
pipeline::element::{Element, InstantElement, InstantElementDrawerType, TimeSeriesElement},
|
||||
};
|
||||
use crate::{
|
||||
coords::{
|
||||
cms::CMS,
|
||||
@ -64,6 +65,8 @@ pub enum AppMsg {
|
||||
CloseRequest,
|
||||
Close,
|
||||
OpenDialog,
|
||||
AddLayer,
|
||||
RemoveSelectedLayer,
|
||||
SwitchToTime(usize),
|
||||
NewElement(Element),
|
||||
DeleteElement(ElementKey),
|
||||
@ -263,6 +266,7 @@ impl Component for AppModel {
|
||||
let widgets = view_output!();
|
||||
let mut group = RelmActionGroup::<FileActionGroup>::new();
|
||||
relm4::main_application().set_accelerators_for_action::<OpenAction>(&["<primary>O"]);
|
||||
register_layer_actions(&widgets.main_window, sender.clone());
|
||||
let action: RelmAction<OpenAction> = {
|
||||
RelmAction::new_stateless(move |_| {
|
||||
sender.input(AppMsg::OpenDialog);
|
||||
@ -270,7 +274,6 @@ impl Component for AppModel {
|
||||
};
|
||||
group.add_action(action);
|
||||
group.register_for_widget(&widgets.main_window);
|
||||
|
||||
ComponentParts { model, widgets }
|
||||
}
|
||||
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
use crate::actions::*;
|
||||
use crate::widgets::AssoElement;
|
||||
use abi_stable::type_level::trait_marker::Hash;
|
||||
use chrono::{DateTime, Utc};
|
||||
@ -35,7 +36,7 @@ pub struct SideBarModel {
|
||||
layers: Rc<RefCell<Vec<Layer>>>,
|
||||
selected_layer_idx: usize,
|
||||
counter: u8,
|
||||
list_view_wrapper: TypedListView<LayerItem, gtk::SingleSelection>,
|
||||
list_view_wrapper: TypedListView<LayerItem, gtk::MultiSelection>,
|
||||
bottom_bar_vec: FactoryVecDeque<BottomBarModel>,
|
||||
meta_list_view: TypedColumnView<MyListItem, gtk::NoSelection>,
|
||||
}
|
||||
@ -50,6 +51,7 @@ pub enum SideBarInputMsg {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum SideBarOutputMsg {
|
||||
SelectLayer(usize),
|
||||
NewLayer(Layer),
|
||||
SwitchToTimeSeries(usize),
|
||||
}
|
||||
@ -104,7 +106,8 @@ impl SimpleComponent for SideBarModel {
|
||||
.build() -> gtk::ScrolledWindow{
|
||||
#[wrap(Some)]
|
||||
#[local_ref]
|
||||
set_child=my_view -> gtk::ListView{},
|
||||
set_child=my_view -> gtk::ListView{
|
||||
},
|
||||
set_margin_horizontal:5,
|
||||
set_margin_vertical:3
|
||||
},
|
||||
@ -132,8 +135,15 @@ impl SimpleComponent for SideBarModel {
|
||||
sender: ComponentSender<Self>,
|
||||
) -> ComponentParts<Self> {
|
||||
// Initialize the ListView wrapper
|
||||
let mut list_view_wrapper: TypedListView<LayerItem, gtk::SingleSelection> =
|
||||
let mut list_view_wrapper: TypedListView<LayerItem, gtk::MultiSelection> =
|
||||
TypedListView::with_sorting();
|
||||
|
||||
list_view_wrapper.selection_model.connect_selection_changed(
|
||||
clone!(@strong sender => move |s,_, _| {
|
||||
let selection = s.selection();
|
||||
println!("selection changed: {:?}", selection);
|
||||
}),
|
||||
);
|
||||
// let mut bottom_bar_vec = FactoryVecDeque::new(gtk::Box::default(), sender.input_sender());
|
||||
|
||||
let mut bottom_bar_vec =
|
||||
@ -282,8 +292,16 @@ impl RelmListItem for LayerItem {
|
||||
type Widgets = Widgets;
|
||||
|
||||
fn setup(_item: >k::ListItem) -> (gtk::Box, Widgets) {
|
||||
let position = _item.position() as u8;
|
||||
|
||||
relm4::menu! {
|
||||
main_menu: {
|
||||
custom: "MyWidget",
|
||||
"Remove" => RemoveLayerAction,
|
||||
section!{
|
||||
"test" => RemoveLayerAction,
|
||||
"select" => AddLayerAction
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -336,12 +354,6 @@ impl RelmListItem for LayerItem {
|
||||
menu,
|
||||
} = widgets;
|
||||
|
||||
relm4::menu! {
|
||||
main_menu: {
|
||||
}
|
||||
}
|
||||
menu.set_menu_model(Some(&main_menu));
|
||||
|
||||
status.set_label(&match self.status {
|
||||
LayerStatus::BindToTime(t) => format!("Bind To Time: {}", t),
|
||||
LayerStatus::Instance => "Instance".to_string(),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user