@@ -17,7 +17,7 @@ use std::{any::Any, cmp::Ordering, collections::VecDeque, fmt::Display};
1717use bevy:: {
1818 ecs:: {
1919 resource:: Resource ,
20- system:: { In , IntoSystem , ResMut , SystemInput } ,
20+ system:: { Commands , In , IntoSystem , ResMut , SystemInput } ,
2121 world:: World ,
2222 } ,
2323 log:: error,
@@ -29,9 +29,11 @@ use graph::{GraphAction, handle_graph_action};
2929use saving:: { SaveAction , handle_save_action} ;
3030use window:: WindowAction ;
3131
32+ use crate :: ui:: native_views:: EditorViewUiState ;
33+
3234use super :: {
3335 UiState ,
34- core:: { ViewAction , ViewState } ,
36+ core:: { EditorViewVariant , ViewAction } ,
3537 windows:: WindowId ,
3638} ;
3739
@@ -98,10 +100,20 @@ pub fn handle_editor_action(world: &mut World, action: EditorAction, ctx: &mut A
98100 }
99101}
100102
101- fn handle_view_action ( In ( view_action) : In < ViewAction > , mut ui_state : ResMut < UiState > ) {
103+ fn handle_view_action (
104+ In ( view_action) : In < ViewAction > ,
105+ mut ui_state : ResMut < UiState > ,
106+ mut commands : Commands ,
107+ ) {
102108 match view_action {
103109 ViewAction :: Close ( index) => {
104- ui_state. views . remove ( index) ;
110+ match ui_state. views . remove ( index) {
111+ EditorViewVariant :: Legacy ( _) => { }
112+ EditorViewVariant :: Native ( view_state) => {
113+ commands. entity ( view_state. entity ) . despawn ( ) ;
114+ }
115+ }
116+
105117 if let Some ( idx) = ui_state. active_view {
106118 match idx. cmp ( & index) {
107119 Ordering :: Less => { }
@@ -117,10 +129,13 @@ fn handle_view_action(In(view_action): In<ViewAction>, mut ui_state: ResMut<UiSt
117129 ViewAction :: Select ( index) => {
118130 ui_state. active_view = Some ( index) ;
119131 }
120- ViewAction :: New ( name) => ui_state. views . push ( ViewState {
121- name,
122- dock_state : DockState :: new ( vec ! [ ] ) ,
123- } ) ,
132+ ViewAction :: New ( name) => {
133+ commands. queue ( |world : & mut World | {
134+ let view_state = EditorViewUiState :: init ( world, name, DockState :: new ( vec ! [ ] ) ) ;
135+ let mut ui_state = world. resource_mut :: < UiState > ( ) ;
136+ ui_state. new_native_view ( view_state) ;
137+ } ) ;
138+ }
124139 }
125140}
126141
0 commit comments