diff --git a/lib/src/ast/variable_expression.rs b/lib/src/ast/variable_expression.rs index a61a498..6cfeb24 100644 --- a/lib/src/ast/variable_expression.rs +++ b/lib/src/ast/variable_expression.rs @@ -19,14 +19,23 @@ impl VariableExpression { } } + #[inline] pub fn name(&self) -> &StString { &self.name } + /// Origin name of the variable + #[inline] + pub fn org_name(&self) -> &String { + self.name().origin_string() + } + + #[inline] pub fn ty(&self) -> Option>> { self.ty.clone() } + #[inline] pub fn set_ty(&mut self, ty: Option>>) { self.ty = ty } diff --git a/lib/src/utils/stringify.rs b/lib/src/utils/stringify.rs index f53e3d3..8a34f58 100644 --- a/lib/src/utils/stringify.rs +++ b/lib/src/utils/stringify.rs @@ -85,7 +85,7 @@ impl AstVisitor<'_> for StringifyVisitor { } fn visit_variable_expression(&mut self, variable: &'_ VariableExpression) { - self.write(format_args!("{}", variable.name().origin_string())); + self.write(format_args!("{}", variable.org_name())); } fn visit_call_expression(&mut self, call: &'_ CallExpression) { diff --git a/viewer/src/main.rs b/viewer/src/main.rs index a8c0523..c4b49f4 100644 --- a/viewer/src/main.rs +++ b/viewer/src/main.rs @@ -2,6 +2,7 @@ mod column_object; mod stc_viewer; use crate::stc_viewer::{StcViewerApp, STC_VIEWER_COLUMN_NAME}; +use glib::{ControlFlow, MainContext}; use gtk::prelude::*; use gtk::{ Adjustment, Application, ApplicationWindow, CellRendererText, Orientation, Paned, @@ -12,6 +13,11 @@ use stc::prelude::*; use std::rc::Rc; use std::sync::Mutex; +/// Send UI operations from other threads +enum UIMessages { + Refresh, +} + fn main() { pretty_env_logger::init(); @@ -138,6 +144,27 @@ fn build_ui(app: &Application, mgr: UnitsManager) { } }); + let (tx, rx) = MainContext::channel::(glib::Priority::DEFAULT); + + // refresh UI when the window is shown + window.connect_show(move |_| { + let tx = tx.clone(); + glib::idle_add(move || { + tx.send(UIMessages::Refresh).unwrap(); + ControlFlow::Break + }); + }); + + // handle UI messages from other threads + let app_copy = stc_app.clone(); + rx.attach(None, move |msg| { + match msg { + UIMessages::Refresh => app_copy.lock().unwrap().refresh(), + }; + + ControlFlow::Continue + }); + window.add(&paned); window.show_all(); }