Skip to content

Commit

Permalink
Register Views before creating them (#3181)
Browse files Browse the repository at this point in the history
  • Loading branch information
akavel committed Dec 8, 2021
1 parent 04ac2a2 commit 5e5abac
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 25 deletions.
3 changes: 3 additions & 0 deletions app/gui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

- [Fixed histograms coloring and added a color legend.][3153]
- [Fixed broken node whose expression contains non-ASCII characters.][3166]
- [Fixed developer console warnings about views being created but not
registered.][3181]

[3153]: https://github.com/enso-org/enso/pull/3153
[3166]: https://github.com/enso-org/enso/pull/3166
[3181]: https://github.com/enso-org/enso/pull/3181

# Enso 2.0.0-alpha.18 (2021-10-12)

Expand Down
24 changes: 24 additions & 0 deletions app/gui/src/ide/initializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ impl Initializer {
info!(self.logger, "Starting IDE with the following config: {self.config:?}");

let application = Application::new(&web::get_html_element_by_id("root").unwrap());
Initializer::register_views(&application);
let view = application.new_view::<ide_view::root::View>();

// If `rust_welcome_screen` feature-flag is not used, switch to project view
Expand Down Expand Up @@ -104,6 +105,29 @@ impl Initializer {
std::mem::forget(executor);
}

fn register_views(app: &Application) {
app.views.register::<ide_view::root::View>();
app.views.register::<ide_view::graph_editor::GraphEditor>();
app.views.register::<ide_view::graph_editor::component::breadcrumbs::ProjectName>();
app.views.register::<ide_view::code_editor::View>();
app.views.register::<ide_view::project::View>();
app.views.register::<ide_view::searcher::View>();
app.views.register::<ide_view::welcome_screen::View>();
app.views.register::<ensogl_component::text::Area>();
app.views.register::<ensogl_component::selector::NumberPicker>();
app.views.register::<ensogl_component::selector::NumberRangePicker>();

// As long as .label() of a View is the same, shortcuts and commands are currently also
// expected to be the same, so it should not be important which concrete type parameter of
// ListView we use below.
type PlaceholderEntryType = ensogl_component::list_view::entry::Label;
app.views.register::<ensogl_component::list_view::ListView<PlaceholderEntryType>>();

if enso_config::ARGS.is_in_cloud.unwrap_or(false) {
app.views.register::<ide_view::window_control_buttons::View>();
}
}

/// Initialize and return a new Ide Controller.
///
/// This will setup all required connections to backend properly, according to the
Expand Down
12 changes: 0 additions & 12 deletions app/gui/view/src/window_control_buttons/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,3 @@ impl<Shape> application::command::FrpNetworkProvider for View<Shape> {
&self.frp.network
}
}

impl<Shape: ButtonShape> application::View for View<Shape> {
fn label() -> &'static str {
"CloseButton"
}
fn new(app: &Application) -> Self {
View::new(app)
}
fn app(&self) -> &Application {
&self.model.app
}
}
12 changes: 0 additions & 12 deletions lib/rust/ensogl/component/selector/src/decimal_aligned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,3 @@ impl application::command::FrpNetworkProvider for FloatLabel {
self.frp.network()
}
}

impl application::View for FloatLabel {
fn label() -> &'static str {
"FloatLabel"
}
fn new(app: &Application) -> Self {
FloatLabel::new(app)
}
fn app(&self) -> &Application {
&self.app
}
}
2 changes: 1 addition & 1 deletion lib/rust/ensogl/component/selector/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl Model {
pub fn new(app: &Application) -> Self {
let logger = Logger::new("selector::common::Model");
let root = display::object::Instance::new(&logger);
let label = app.new_view::<FloatLabel>();
let label = FloatLabel::new(app);
let label_left = app.new_view::<text::Area>();
let label_right = app.new_view::<text::Area>();
let caption_center = app.new_view::<text::Area>();
Expand Down
5 changes: 5 additions & 0 deletions lib/rust/ensogl/core/src/application/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ impl Registry {
}

/// View registration.
///
/// Registers any keyboard shortcuts provided by the [View], and registers the View for use
/// with commands. Should be called for every View that might potentially be instantiated at
/// any point in the future, so that the keyboard shortcuts overview has full information from
/// the outset.
pub fn register<V: View>(&self) {
let label = V::label().into();
for shortcut in V::default_shortcuts() {
Expand Down

0 comments on commit 5e5abac

Please sign in to comment.