sync
This commit is contained in:
parent
7a6e41838f
commit
c55c245792
@ -206,7 +206,7 @@ impl DataLoaderPlugin for ETWSLoader {
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
@ -252,7 +252,7 @@ pub fn parse_raw_data<P: AsRef<Path>>(path: P) -> Result<RadarData, ETWSError> {
|
||||
if path.is_file() {
|
||||
let mut file = File::open(path)?;
|
||||
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" {
|
||||
return get_radar_data(buf);
|
||||
} else {
|
||||
|
||||
@ -232,16 +232,7 @@ impl MatchEvent for App {
|
||||
}
|
||||
|
||||
fn handle_signal(&mut self, cx: &mut Cx) {
|
||||
self.file_manager.try_deal_file(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);
|
||||
}
|
||||
self.file_manager.try_deal_file(&self.ui, cx);
|
||||
}
|
||||
|
||||
fn handle_action(&mut self, _cx: &mut Cx, e: &Action) {
|
||||
|
||||
@ -1,14 +1,20 @@
|
||||
use crate::{app::AppAction, errors::AppErr, GIAPP, RUNTIME};
|
||||
use std::path::Path;
|
||||
use crate::{
|
||||
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::{Cx, ToUIReceiver, ToUISender};
|
||||
use makepad_widgets::{id, Cx, ToUIReceiver, ToUISender, WidgetRef};
|
||||
use mp_core::{datapool::Value, errors::DataError, Data};
|
||||
|
||||
use crate::DATAPOOL;
|
||||
#[derive(Default)]
|
||||
pub struct FileManager {
|
||||
receiver: ToUIReceiver<Vec<Result<Value<Data>, DataError>>>,
|
||||
receiver: ToUIReceiver<Vec<(PathBuf, Result<Value<Data>, DataError>)>>,
|
||||
}
|
||||
|
||||
impl FileManager {
|
||||
@ -22,7 +28,7 @@ impl FileManager {
|
||||
let path = path.to_path_buf();
|
||||
RUNTIME.spawn(async move {
|
||||
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() {
|
||||
if data.len() == 1 {
|
||||
let data = data.pop().unwrap();
|
||||
let (path, data) = data.pop().unwrap();
|
||||
if let Ok(data) = data {
|
||||
info!("Data: {:?}", data);
|
||||
cx.action(AppAction::Notification {
|
||||
@ -49,25 +57,37 @@ impl FileManager {
|
||||
duration: 3.0,
|
||||
});
|
||||
|
||||
let pipelines = GIAPP.pipelines();
|
||||
let data = data.get(0).unwrap();
|
||||
let supported_elements = pipelines.supported_elements(&data);
|
||||
let mut items = vec![];
|
||||
|
||||
if supported_elements.is_empty() {
|
||||
cx.action(AppAction::Notification {
|
||||
message: "No supported elements".to_string(),
|
||||
duration: 3.0,
|
||||
});
|
||||
} else {
|
||||
let names = supported_elements
|
||||
let pipelines = GIAPP.pipelines();
|
||||
for (idx, data) in data.iter() {
|
||||
let supported_elements = pipelines.supported_elements(&data);
|
||||
|
||||
let key_name = ItemKey {
|
||||
path: "".to_string(),
|
||||
category: data.description.clone(),
|
||||
description: data.description.clone(),
|
||||
};
|
||||
|
||||
let item_values = supported_elements
|
||||
.iter()
|
||||
.map(|e| e.name().to_string())
|
||||
.map(|v| ItemValue {
|
||||
name: v.name().to_string(),
|
||||
icon: "".to_string(),
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
cx.action(AppAction::Notification {
|
||||
message: format!("Supported elements: {:?}", names),
|
||||
duration: 3.0,
|
||||
});
|
||||
|
||||
items.push((key_name, item_values));
|
||||
}
|
||||
|
||||
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 {
|
||||
}
|
||||
|
||||
@ -189,6 +189,24 @@ live_design! {
|
||||
border_color: #9c9c9c
|
||||
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> {
|
||||
@ -234,12 +252,12 @@ live_design! {
|
||||
flow: Right
|
||||
spacing:10.0
|
||||
|
||||
<Button> {
|
||||
pre_button = <Button> {
|
||||
width: 90
|
||||
text: "Previous"
|
||||
}
|
||||
|
||||
<Button> {
|
||||
ok_button = <Button> {
|
||||
width: 90
|
||||
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)]
|
||||
@ -265,7 +287,7 @@ pub struct ItemKey {
|
||||
pub description: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, PartialEq, Eq, Hash, Default, Debug)]
|
||||
pub struct ItemValue {
|
||||
pub name: String,
|
||||
pub icon: String,
|
||||
@ -281,43 +303,39 @@ pub struct SelectorList {
|
||||
#[walk]
|
||||
walk: Walk,
|
||||
#[rust]
|
||||
// items: Vec<ItemValue>,
|
||||
class: Option<ItemKey>,
|
||||
#[rust]
|
||||
items: IndexSet<ItemValue>,
|
||||
#[rust]
|
||||
item_refs: Vec<WidgetRef>,
|
||||
#[live]
|
||||
item_ref: Option<LivePtr>,
|
||||
|
||||
#[rust]
|
||||
selected: Option<usize>,
|
||||
|
||||
#[rust]
|
||||
entry_id: usize,
|
||||
}
|
||||
|
||||
impl Widget for SelectorList {
|
||||
fn handle_event(&mut self, cx: &mut Cx, event: &Event, scope: &mut Scope) {
|
||||
let mut selected = None;
|
||||
self.item_refs
|
||||
.iter_mut()
|
||||
.enumerate()
|
||||
.for_each(|(idx, item)| {
|
||||
// item.handle_event(_cx, _event, _scope);
|
||||
let item = item.as_selector_item();
|
||||
if item.handle_event_with_a(cx, event, scope) {
|
||||
selected = Some(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);
|
||||
let key = self.class.clone().unwrap();
|
||||
self.item_refs.iter().enumerate().for_each(|(idx, item)| {
|
||||
// item.handle_event(_cx, _event, _scope);
|
||||
let _item = item.as_selector_item();
|
||||
if _item.handle_event_with_a(cx, event, scope) {
|
||||
cx.widget_action(
|
||||
self.widget_uid(),
|
||||
&scope.path,
|
||||
SelectorAction::SelectItem(
|
||||
key.clone(),
|
||||
self.items.get_index(idx).cloned().unwrap(),
|
||||
self.entry_id,
|
||||
idx,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
item.as_selector_item().set_selected(true);
|
||||
item.redraw(cx);
|
||||
}
|
||||
});
|
||||
}
|
||||
fn draw_walk(&mut self, cx: &mut Cx2d, scope: &mut Scope, walk: Walk) -> DrawStep {
|
||||
self.draw_bg.begin(cx, Walk::fill(), self.layout);
|
||||
@ -332,40 +350,66 @@ impl Widget for 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() {
|
||||
self.items.insert(item.clone());
|
||||
}
|
||||
|
||||
self.class = Some(class.clone());
|
||||
|
||||
for item in self.items.iter() {
|
||||
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.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) {
|
||||
self.items.insert(item.clone());
|
||||
let new_ref = WidgetRef::new_from_ptr(cx, self.item_ref);
|
||||
new_ref.as_selector_item().set_text(&item.name);
|
||||
|
||||
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 {
|
||||
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() {
|
||||
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() {
|
||||
_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]
|
||||
class: Vec<(ItemKey, Vec<ItemValue>)>,
|
||||
|
||||
#[rust]
|
||||
selected: Option<(ItemKey, ItemValue, usize, usize)>,
|
||||
}
|
||||
|
||||
impl Widget for Selector {
|
||||
fn handle_event(&mut self, _cx: &mut Cx, _event: &Event, _scope: &mut Scope) {
|
||||
self.view.handle_event(_cx, _event, _scope);
|
||||
fn handle_event(&mut self, cx: &mut Cx, event: &Event, scope: &mut 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 {
|
||||
@ -540,8 +610,10 @@ impl Widget for Selector {
|
||||
let list = list_item.as_selector_list();
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
@ -558,6 +630,11 @@ impl Selector {
|
||||
self.class = items;
|
||||
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 {
|
||||
@ -566,4 +643,10 @@ impl SelectorRef {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user