This commit is contained in:
Tsuki 2024-11-26 16:59:54 +08:00
parent 7a6e41838f
commit c55c245792
6 changed files with 172 additions and 78 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

View File

@ -206,7 +206,7 @@ impl DataLoaderPlugin for ETWSLoader {
} }
fn supported_extensions(&self) -> RVec<RStr<'static>> where { fn supported_extensions(&self) -> RVec<RStr<'static>> where {
convert_iter_to_rvec(vec!["dat".into(), "gz".into()].into_iter()) convert_iter_to_rvec(vec!["dat".into(), "gz".into(), "zip".into()].into_iter())
} }
fn plugin_info(&self) -> radarg_plugin_interface::PluginInfo where { fn plugin_info(&self) -> radarg_plugin_interface::PluginInfo where {

View File

@ -252,7 +252,7 @@ pub fn parse_raw_data<P: AsRef<Path>>(path: P) -> Result<RadarData, ETWSError> {
if path.is_file() { if path.is_file() {
let mut file = File::open(path)?; let mut file = File::open(path)?;
let mut buf = Vec::new(); let mut buf = Vec::new();
file.read_to_end(&mut buf).unwrap(); file.read_to_end(&mut buf)?;
if &buf[0..4] == b"SSTM" || &buf[16..20] == b"STDM" || &buf[0..4] == b"RSTM" { if &buf[0..4] == b"SSTM" || &buf[16..20] == b"STDM" || &buf[0..4] == b"RSTM" {
return get_radar_data(buf); return get_radar_data(buf);
} else { } else {

View File

@ -232,16 +232,7 @@ impl MatchEvent for App {
} }
fn handle_signal(&mut self, cx: &mut Cx) { fn handle_signal(&mut self, cx: &mut Cx) {
self.file_manager.try_deal_file(cx); self.file_manager.try_deal_file(&self.ui, cx);
}
fn handle_actions(&mut self, cx: &mut Cx, actions: &Actions) {
let ui = self.ui.clone();
if ui.button(id!(open_modal)).clicked(actions) {
let modal = ui.modal(id!(selector_modal));
modal.open(cx);
}
} }
fn handle_action(&mut self, _cx: &mut Cx, e: &Action) { fn handle_action(&mut self, _cx: &mut Cx, e: &Action) {

View File

@ -1,14 +1,20 @@
use crate::{app::AppAction, errors::AppErr, GIAPP, RUNTIME}; use crate::{
use std::path::Path; app::AppAction,
errors::AppErr,
widgets::selector::{ItemKey, ItemValue, SelectorWidgetRefExt},
GIAPP, RUNTIME,
};
use ::log::info;
use makepad_widgets::*;
use std::path::{Path, PathBuf};
use log::info; use makepad_widgets::{id, Cx, ToUIReceiver, ToUISender, WidgetRef};
use makepad_widgets::{Cx, ToUIReceiver, ToUISender};
use mp_core::{datapool::Value, errors::DataError, Data}; use mp_core::{datapool::Value, errors::DataError, Data};
use crate::DATAPOOL; use crate::DATAPOOL;
#[derive(Default)] #[derive(Default)]
pub struct FileManager { pub struct FileManager {
receiver: ToUIReceiver<Vec<Result<Value<Data>, DataError>>>, receiver: ToUIReceiver<Vec<(PathBuf, Result<Value<Data>, DataError>)>>,
} }
impl FileManager { impl FileManager {
@ -22,7 +28,7 @@ impl FileManager {
let path = path.to_path_buf(); let path = path.to_path_buf();
RUNTIME.spawn(async move { RUNTIME.spawn(async move {
let data = DATAPOOL.get_or_load_async(&path).await; let data = DATAPOOL.get_or_load_async(&path).await;
sender.send(vec![data]).unwrap(); sender.send(vec![(path, data)]).unwrap();
}); });
} }
@ -38,10 +44,12 @@ impl FileManager {
} }
} }
pub fn try_deal_file(&mut self, cx: &mut Cx) { pub fn try_deal_file(&mut self, ui: &WidgetRef, cx: &mut Cx) {
let selector = ui.selector(id!(selector));
let selector_modal = ui.modal(id!(selector_modal));
while let Ok(mut data) = self.receiver.try_recv() { while let Ok(mut data) = self.receiver.try_recv() {
if data.len() == 1 { if data.len() == 1 {
let data = data.pop().unwrap(); let (path, data) = data.pop().unwrap();
if let Ok(data) = data { if let Ok(data) = data {
info!("Data: {:?}", data); info!("Data: {:?}", data);
cx.action(AppAction::Notification { cx.action(AppAction::Notification {
@ -49,25 +57,37 @@ impl FileManager {
duration: 3.0, duration: 3.0,
}); });
let mut items = vec![];
let pipelines = GIAPP.pipelines(); let pipelines = GIAPP.pipelines();
let data = data.get(0).unwrap(); for (idx, data) in data.iter() {
let supported_elements = pipelines.supported_elements(&data); let supported_elements = pipelines.supported_elements(&data);
if supported_elements.is_empty() { let key_name = ItemKey {
cx.action(AppAction::Notification { path: "".to_string(),
message: "No supported elements".to_string(), category: data.description.clone(),
duration: 3.0, description: data.description.clone(),
}); };
} else {
let names = supported_elements let item_values = supported_elements
.iter() .iter()
.map(|e| e.name().to_string()) .map(|v| ItemValue {
name: v.name().to_string(),
icon: "".to_string(),
})
.collect::<Vec<_>>(); .collect::<Vec<_>>();
cx.action(AppAction::Notification {
message: format!("Supported elements: {:?}", names), items.push((key_name, item_values));
duration: 3.0,
});
} }
let base_name = path
.file_stem()
.map(|v| v.to_string_lossy())
.unwrap_or_default();
selector.set_items(cx, items);
selector.set_base_name(&base_name);
selector_modal.open(cx);
} }
} else { } else {
} }

View File

@ -189,6 +189,24 @@ live_design! {
border_color: #9c9c9c border_color: #9c9c9c
border_width: 0.5 border_width: 0.5
} }
align: {
y: 0.5
}
padding: {
left: 20
}
file_base_name = <Label> {
text: "File Base Name"
draw_text: {
color: #9c9c9c
text_style: <THEME_FONT_BOLD>{
font_size: 8.0
}
}
}
} }
<RView> { <RView> {
@ -234,12 +252,12 @@ live_design! {
flow: Right flow: Right
spacing:10.0 spacing:10.0
<Button> { pre_button = <Button> {
width: 90 width: 90
text: "Previous" text: "Previous"
} }
<Button> { ok_button = <Button> {
width: 90 width: 90
text: "Next" text: "Next"
} }
@ -250,12 +268,16 @@ live_design! {
} }
} }
}
} }
#[derive(DefaultNone, Debug, Clone)]
pub enum SelectorAction {
None,
SelectItem(ItemKey, ItemValue, usize, usize),
Selected(ItemKey, usize),
Unselected(ItemKey, usize),
} }
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
@ -265,7 +287,7 @@ pub struct ItemKey {
pub description: String, pub description: String,
} }
#[derive(Clone, PartialEq, Eq, Hash)] #[derive(Clone, PartialEq, Eq, Hash, Default, Debug)]
pub struct ItemValue { pub struct ItemValue {
pub name: String, pub name: String,
pub icon: String, pub icon: String,
@ -281,43 +303,39 @@ pub struct SelectorList {
#[walk] #[walk]
walk: Walk, walk: Walk,
#[rust] #[rust]
// items: Vec<ItemValue>, class: Option<ItemKey>,
#[rust]
items: IndexSet<ItemValue>, items: IndexSet<ItemValue>,
#[rust] #[rust]
item_refs: Vec<WidgetRef>, item_refs: Vec<WidgetRef>,
#[live] #[live]
item_ref: Option<LivePtr>, item_ref: Option<LivePtr>,
#[rust] #[rust]
selected: Option<usize>, selected: Option<usize>,
#[rust]
entry_id: usize,
} }
impl Widget for SelectorList { impl Widget for SelectorList {
fn handle_event(&mut self, cx: &mut Cx, event: &Event, scope: &mut Scope) { fn handle_event(&mut self, cx: &mut Cx, event: &Event, scope: &mut Scope) {
let mut selected = None; let key = self.class.clone().unwrap();
self.item_refs self.item_refs.iter().enumerate().for_each(|(idx, item)| {
.iter_mut()
.enumerate()
.for_each(|(idx, item)| {
// item.handle_event(_cx, _event, _scope); // item.handle_event(_cx, _event, _scope);
let item = item.as_selector_item(); let _item = item.as_selector_item();
if item.handle_event_with_a(cx, event, scope) { if _item.handle_event_with_a(cx, event, scope) {
selected = Some(idx); cx.widget_action(
self.widget_uid(),
&scope.path,
SelectorAction::SelectItem(
key.clone(),
self.items.get_index(idx).cloned().unwrap(),
self.entry_id,
idx,
),
);
} }
}); });
self.selected = selected;
if let Some(selected) = self.selected {
let item = &self.item_refs[selected];
for item in self.item_refs.iter() {
item.as_selector_item().set_selected(false);
}
item.as_selector_item().set_selected(true);
item.redraw(cx);
}
} }
fn draw_walk(&mut self, cx: &mut Cx2d, scope: &mut Scope, walk: Walk) -> DrawStep { fn draw_walk(&mut self, cx: &mut Cx2d, scope: &mut Scope, walk: Walk) -> DrawStep {
self.draw_bg.begin(cx, Walk::fill(), self.layout); self.draw_bg.begin(cx, Walk::fill(), self.layout);
@ -332,40 +350,66 @@ impl Widget for SelectorList {
} }
impl SelectorList { impl SelectorList {
pub fn set_items(&mut self, cx: &mut Cx, items: &Vec<ItemValue>) { pub fn set_items(&mut self, cx: &mut Cx, class: ItemKey, items: &Vec<ItemValue>) {
for item in items.iter() { for item in items.iter() {
self.items.insert(item.clone()); self.items.insert(item.clone());
} }
self.class = Some(class.clone());
for item in self.items.iter() { for item in self.items.iter() {
let new_ref = WidgetRef::new_from_ptr(cx, self.item_ref); let new_ref = WidgetRef::new_from_ptr(cx, self.item_ref);
new_ref.as_selector_item().set_text(&item.name); let mut _item = new_ref.as_selector_item();
_item.set_text(&item.name);
// self.item_refs.insert(k.clone(), new_ref); // self.item_refs.insert(k.clone(), new_ref);
self.item_refs.push(new_ref); self.item_refs.push(new_ref);
} }
} }
pub fn insert_if_not_exists(&mut self, cx: &mut Cx, item: &ItemValue) { pub fn insert_if_not_exists(&mut self, cx: &mut Cx, item_id: usize, item: &ItemValue) {
self.entry_id = item_id;
if !self.items.contains(item) { if !self.items.contains(item) {
self.items.insert(item.clone()); self.items.insert(item.clone());
let new_ref = WidgetRef::new_from_ptr(cx, self.item_ref); let new_ref = WidgetRef::new_from_ptr(cx, self.item_ref);
new_ref.as_selector_item().set_text(&item.name); new_ref.as_selector_item().set_text(&item.name);
self.item_refs.push(new_ref); self.item_refs.push(new_ref);
} }
} }
pub fn set_selected(&mut self, cx: &mut Cx, idx: usize, selected: bool) {
self.item_refs
.get_mut(idx)
.unwrap()
.as_selector_item()
.set_selected(selected);
self.redraw(cx);
}
} }
impl SelectorListRef { impl SelectorListRef {
pub fn set_items(&self, cx: &mut Cx, items: &Vec<ItemValue>) { pub fn set_items(&self, cx: &mut Cx, class: ItemKey, items: &Vec<ItemValue>) {
if let Some(mut item) = self.borrow_mut() { if let Some(mut item) = self.borrow_mut() {
item.set_items(cx, items); item.set_items(cx, class, items);
} }
} }
pub fn insert_if_not_exists(&self, cx: &mut Cx, item: &ItemValue) { pub fn set_class(&self, class: ItemKey) {
if let Some(mut item) = self.borrow_mut() {
item.class = Some(class);
}
}
pub fn insert_if_not_exists(&self, cx: &mut Cx, item_id: usize, item: &ItemValue) {
if let Some(mut _item) = self.borrow_mut() { if let Some(mut _item) = self.borrow_mut() {
_item.insert_if_not_exists(cx, item); _item.insert_if_not_exists(cx, item_id, item);
}
}
pub fn set_selected(&self, cx: &mut Cx, idx: usize, selected: bool) {
if let Some(mut _item) = self.borrow_mut() {
_item.set_selected(cx, idx, selected);
} }
} }
} }
@ -502,11 +546,37 @@ pub struct Selector {
#[rust] #[rust]
class: Vec<(ItemKey, Vec<ItemValue>)>, class: Vec<(ItemKey, Vec<ItemValue>)>,
#[rust]
selected: Option<(ItemKey, ItemValue, usize, usize)>,
} }
impl Widget for Selector { impl Widget for Selector {
fn handle_event(&mut self, _cx: &mut Cx, _event: &Event, _scope: &mut Scope) { fn handle_event(&mut self, cx: &mut Cx, event: &Event, scope: &mut Scope) {
self.view.handle_event(_cx, _event, _scope); let list = self.view.widget(id!(list)).as_portal_list();
let ok_button = self.view.widget(id!(ok_button)).as_button();
for action in cx.capture_actions(|cx| self.view.handle_event(cx, event, scope)) {
match action.as_widget_action().cast() {
SelectorAction::SelectItem(key, item, list_id, item_id) => {
let raw_selected = &self.selected;
if let Some(raw_selected) = raw_selected {
list.get_item(raw_selected.2).map(|v| {
v.1.as_selector_list()
.set_selected(cx, raw_selected.3, false);
});
}
self.selected = Some((key, item, list_id, item_id));
list.get_item(list_id).map(|v| {
v.1.as_selector_list().set_selected(cx, item_id, true);
});
ok_button.set_enabled(self.selected.is_some());
}
_ => {}
}
}
} }
fn draw_walk(&mut self, cx: &mut Cx2d, scope: &mut Scope, walk: Walk) -> DrawStep { fn draw_walk(&mut self, cx: &mut Cx2d, scope: &mut Scope, walk: Walk) -> DrawStep {
@ -540,8 +610,10 @@ impl Widget for Selector {
let list = list_item.as_selector_list(); let list = list_item.as_selector_list();
for item in prepared.1.iter() { for item in prepared.1.iter() {
list.insert_if_not_exists(cx, item); list.insert_if_not_exists(cx, item_id, item);
} }
list.set_class(prepared.0.clone());
list_item list_item
}; };
@ -558,6 +630,11 @@ impl Selector {
self.class = items; self.class = items;
self.view.redraw(cx); self.view.redraw(cx);
} }
fn set_base_name(&mut self, name: &str) {
let title_bar = self.view.widget(id!(file_base_name)).as_label();
title_bar.set_text(name);
}
} }
impl SelectorRef { impl SelectorRef {
@ -566,4 +643,10 @@ impl SelectorRef {
item.set_items(cx, items); item.set_items(cx, items);
} }
} }
pub fn set_base_name(&self, name: &str) {
if let Some(mut item) = self.borrow_mut() {
item.set_base_name(name);
}
}
} }