예제 #1
0
파일: Program.cs 프로젝트: danwalmsley/Dock
        static void Main(string[] args)
        {
#if !NET461
            Thread.CurrentThread.TrySetApartmentState(ApartmentState.STA);
#endif
            try
            {
                var   vm      = new MainWindowViewModel();
                var   factory = new MainWindowDockFactory();
                IDock layout  = null;

                string path = DockSerializer.GetBasePath("Layout.json");
                if (DockSerializer.Exists(path))
                {
                    layout = DockSerializer.Load <DockRoot>(path);
                }

                BuildAvaloniaApp().Start <MainWindow>(() =>
                {
                    // NOTE: Initialize layout after main window was created so child windows can be created.
                    vm.Factory = factory;
                    vm.Layout  = layout ?? vm.Factory.CreateLayout();
                    vm.Factory.InitLayout(vm.Layout, vm);
                    return(vm);
                });

                vm.Layout.CurrentView.HideWindows();
                DockSerializer.Save(path, vm.Layout);
            }
            catch (Exception ex)
            {
                Print(ex);
            }
        }
예제 #2
0
        /// <summary>
        /// Loads the docking layout.
        /// </summary>
        /// <param name="storedLayout">The stored layout.</param>
        /// <inheritdoc cref="DockSerializer.Load"/>
        public void LoadLayout(XElement storedLayout)
        {
            try
            {
                DockStrategy.Begin();

                var oldItems = Items.ToList();
                DockSerializer.Load(this, storedLayout);
                var newItems = Items.ToList();

                // Screen conduction for items closed in Load().
                foreach (var dockTabItem in oldItems.Except(newItems))
                {
                    // IActivatable
                    (dockTabItem as IActivatable)?.OnDeactivate(true);

                    // IScreen
                    var screen = dockTabItem as IScreen;
                    if (screen != null)
                    {
                        screen.Conductor = null;
                    }
                }
            }
            finally
            {
                DockStrategy.End();
            }
        }
예제 #3
0
        public void Serialization0()
        {
            DockControlViewModel dockControl = CreateDockLayout();

            // Serialize layout.
            var xElement1 = DockSerializer.Save(dockControl);

            // Make some changes.
            dockControl.DockStrategy.Close(dockControl.FloatWindows[0]);

            // Deserialize and serialize again.
            DockSerializer.Load(dockControl, xElement1);
            var xElement2 = DockSerializer.Save(dockControl);

            // We want to compare the two created XMLs. But first we must remove the
            // LastActivation="..." entries, because they will not match.
            var string1 = xElement1.ToString();
            var string2 = xElement2.ToString();
            var r       = new Regex(@"LastActivation="".*""");

            string1 = r.Replace(string1, string.Empty);
            string2 = r.Replace(string2, string.Empty);

            Assert.AreEqual(string1, string2);
        }
예제 #4
0
    override public void Load(StructureSerializer ss, SurfaceBlock sblock)
    {
        LoadStructureData(ss, sblock);
        DockSerializer ds = new DockSerializer();

        GameMaster.DeserializeByteArray <DockSerializer>(ss.specificData, ref ds);
        LoadDockData(ds);
    }
예제 #5
0
        private void OnDeserialize(object sender, RoutedEventArgs e)
        {
            var xElement = XElement.Parse(TextBox0.Text);

            DockSerializer.Load(DockControlViewModel, xElement);
            xElement = DockSerializer.Save(DockControlViewModel);

            TextBox1.Text = xElement.ToString();
        }
        public override void OnFrameworkInitializationCompleted()
        {
            var factory = new DockFactory(new LogViewerSpikeData());

            IDock layout = null;

            var filename = @"D:\layout.json";

            if (File.Exists(filename))
            {
                try
                {
                    layout = new DockSerializer(typeof(AvaloniaList <>))
                             .Load <RootDock>(filename);
                }
                catch { }
            }
            layout = layout ?? factory.CreateLayout();

            factory.InitLayout(layout);

            var mainWindowViewModel = new MainWindowViewModel
            {
                Factory = factory,
                Layout  = layout
            };

            if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopLifetime)
            {
                var mainWindow = new MainWindow
                {
                    DataContext = mainWindowViewModel
                };

                mainWindow.Closing += (sender, e) =>
                {
                    if (layout is IDock dock)
                    {
                        dock.Close();
                    }
                };

                desktopLifetime.MainWindow = mainWindow;

                desktopLifetime.Exit += (sender, e) =>
                {
                    if (layout is IDock dock)
                    {
                        new DockSerializer(typeof(AvaloniaList <>)).Save(filename, layout);
                        dock.Close();
                    }
                };
            }
            base.OnFrameworkInitializationCompleted();
        }
예제 #7
0
 /// <summary>
 /// Saves the docking layout.
 /// </summary>
 /// <param name="excludeNonPersistentItems">
 /// <see langword="true"/> to exclude non-persistent <see cref="IDockTabItem"/>s.
 /// <see langword="false"/> to store the layout of all (persistent and non-persistent)
 /// <see cref="IDockTabItem"/>s.
 /// </param>
 /// <returns>The <see cref="XElement"/> with the serialized layout.</returns>
 /// <inheritdoc cref="DockSerializer.Save(IDockControl,bool)"/>
 public XElement SaveLayout(bool excludeNonPersistentItems = false)
 {
     try
     {
         DockStrategy.Begin();
         return(DockSerializer.Save(this, excludeNonPersistentItems));
     }
     finally
     {
         DockStrategy.End();
     }
 }
예제 #8
0
    DockSerializer GetDockSerializer()
    {
        DockSerializer ds = new DockSerializer();

        ds.workBuildingSerializer = GetWorkBuildingSerializer();
        ds.correctLocation        = correctLocation;
        ds.maintainingShip        = maintainingShip;
        if (maintainingShip && loadingShip != null)
        {
            ds.loadingShip = loadingShip.GetShipSerializer();
        }
        ds.loadingTimer      = loadingTimer;
        ds.shipArrivingTimer = shipArrivingTimer;
        return(ds);
    }
예제 #9
0
 void LoadDockData(DockSerializer ds)
 {
     LoadWorkBuildingData(ds.workBuildingSerializer);
     correctLocation = ds.correctLocation;
     maintainingShip = ds.maintainingShip;
     if (maintainingShip)
     {
         ShipSerializer ss = ds.loadingShip;
         Ship           s  = PoolMaster.current.GetShip(ss.level, ss.type);
         s.Load(ss, this);
         loadingShip = s;
     }
     loadingTimer      = ds.loadingTimer;
     shipArrivingTimer = ds.shipArrivingTimer;
 }
예제 #10
0
        private void OnSerialize(object sender, RoutedEventArgs e)
        {
            var xElement = DockSerializer.Save(DockControlViewModel);

            TextBox0.Text = xElement.ToString();
        }
예제 #11
0
 private void OnSaveLayout(object sender, RoutedEventArgs eventArgs)
 {
     new XDocument(DockSerializer.Save(DockControlViewModel)).Save("DockControlTest.Layout");
 }
예제 #12
0
 private void OnLoadLayout(object sender, RoutedEventArgs eventArgs)
 {
     DockSerializer.Load(DockControlViewModel, XDocument.Load("DockControlTest.Layout").Root);
 }