11using Avalonia . Controls ;
22using Dock . Model . Controls ;
3+ using Dock . Model . Core ;
34using Microsoft . Extensions . Logging ;
45using MinoriEditorShell . Platforms . Avalonia . Presenters . Attributes ;
56using MinoriEditorShell . Platforms . Avalonia . ViewModels ;
@@ -199,35 +200,59 @@ protected virtual Task<bool> CloseWindow(IMvxViewModel toClose)
199200 /// Depending on what the type is, will define where the class goes.
200201 /// Either to MesDocumentManager or main view if not a IMesDocument or IMesTool
201202 /// </summary>
202- /// <param name="element "></param>
203+ /// <param name="view "></param>
203204 /// <param name="attribute"></param>
204205 /// <param name="request"></param>
205206 /// <returns></returns>
206- protected async Task < Boolean > ShowContentView (
207- IMvxView element , MesContentPresentationAttribute attribute , MvxViewModelRequest request )
207+ protected async Task < Boolean > ShowContentView ( IMvxView view , MesContentPresentationAttribute attribute , MvxViewModelRequest request )
208208 {
209209 try
210210 {
211211 // Everything that passes here should be a view
212- IMvxView view = element as IMvxView ;
213212 MesDocumentManagerViewModel manager = ( MesDocumentManagerViewModel ) Mvx . IoCProvider . Resolve < IMesDocumentManager > ( ) ;
214213
215214 // from which we can now get the view model.
216215 switch ( view . ViewModel )
217216 {
218217 case IMesDocument document :
218+ {
219+ // Try to set view, this is needed for DocumentManager
220+ IMesDocument docViewModel = ( IMesDocument ) view . ViewModel ;
221+ docViewModel . View = view ; // Needed for Binding with AvalonDock
219222
220- // Try to set view, this is needed for DocumentManager
221- IMesDocument docViewModel = ( IMesDocument ) view . ViewModel ;
222- docViewModel . View = view ; // Needed for Binding with AvalonDock
223+ MesDocumentWrapper documentWrapper = new ( docViewModel ) ;
223224
224- MesDocumentWrapper documentWrapper = new ( docViewModel ) ;
225+ // Add to manager model
226+ IDocumentDock docdock = manager . DocumentDock ;
227+ IRootDock layout = manager . Layout ;
225228
226- // Add to manager model
227- //manager.Documents.Add(docViewModel);
228- manager . AddDockable ( manager . GetDockable < IDocumentDock > ( "Files" ) , documentWrapper ) ;
229- _log . LogTrace ( $ "Add { document } to IMesDocumentManager.Documents") ;
230- return true ;
229+ if ( layout is { } && docdock is { } )
230+ {
231+ manager . DocumentDock . VisibleDockables . Add ( documentWrapper ) ;
232+ manager . AddDockable ( docdock , documentWrapper ) ;
233+ manager . SetActiveDockable ( documentWrapper ) ;
234+ manager . SetFocusedDockable ( layout , documentWrapper ) ;
235+
236+ _log . LogTrace ( $ "Add { document } to IMesDocumentManager.Documents") ;
237+ }
238+ else
239+ {
240+ _log . LogTrace ( "There was an error attaching to layout" ) ;
241+ }
242+
243+ // ---------- remove after test
244+ ContentControl contentControl = FrameworkElementsDictionary . Keys . FirstOrDefault ( w => ( w as MesWindow ) ? . Identifier == attribute . WindowIdentifier )
245+ ?? FrameworkElementsDictionary . Keys . Last ( ) ;
246+
247+ if ( ! attribute . StackNavigation && FrameworkElementsDictionary [ contentControl ] . Any ( ) )
248+ FrameworkElementsDictionary [ contentControl ] . Pop ( ) ; // Close previous view
249+
250+ FrameworkElementsDictionary [ contentControl ] . Push ( ( Control ) view ) ;
251+ contentControl . Content = documentWrapper ;
252+ _log . LogTrace ( $ "Passing to parent { view . ViewModel } ") ;
253+
254+ return true ;
255+ }
231256
232257 case IMesTool tool :
233258 // Try to set view, this is needed for DocumentManager
@@ -240,16 +265,18 @@ protected async Task<Boolean> ShowContentView(
240265 return true ;
241266
242267 default :
243- _log . LogTrace ( $ "Passing to parent { view . ViewModel } ") ;
244- ContentControl contentControl = FrameworkElementsDictionary . Keys . FirstOrDefault ( w => ( w as MesWindow ) ? . Identifier == attribute . WindowIdentifier )
245- ?? FrameworkElementsDictionary . Keys . Last ( ) ;
246-
247- if ( ! attribute . StackNavigation && FrameworkElementsDictionary [ contentControl ] . Any ( ) )
248- FrameworkElementsDictionary [ contentControl ] . Pop ( ) ; // Close previous view
249-
250- FrameworkElementsDictionary [ contentControl ] . Push ( ( Control ) element ) ;
251- contentControl . Content = element ;
252- return true ;
268+ {
269+ _log . LogTrace ( $ "Passing to parent { view . ViewModel } ") ;
270+ ContentControl contentControl = FrameworkElementsDictionary . Keys . FirstOrDefault ( w => ( w as MesWindow ) ? . Identifier == attribute . WindowIdentifier )
271+ ?? FrameworkElementsDictionary . Keys . Last ( ) ;
272+
273+ if ( ! attribute . StackNavigation && FrameworkElementsDictionary [ contentControl ] . Any ( ) )
274+ FrameworkElementsDictionary [ contentControl ] . Pop ( ) ; // Close previous view
275+
276+ FrameworkElementsDictionary [ contentControl ] . Push ( ( Control ) view ) ;
277+ contentControl . Content = view ;
278+ return true ;
279+ }
253280 }
254281 }
255282 catch ( Exception exception )
0 commit comments