private void LoadTemplate() { try { string xml = File.ReadAllText(Filename); var layout = LayoutSerializer.DeserializeLite(xml); if (layout != null) { PaperFormat = layout.Paper.PaperName; Orientation = layout.Paper.Landscape ? Orientation.Horizontal : Orientation.Vertical; Pages = string.Format("{0} × {1}", layout.Paper.PageCountX, layout.Paper.PageCountY); } else { Orientation = Orientation.Vertical; PaperFormat = "n/d"; Pages = "n/d"; } } catch (Exception ex) { Logger.Current.Warn("Failed to read layout template: " + Filename, ex); } }
private void OpenDialogFromXml(object sender, EventArgs eventArgs) { // ----- Load a dialog from an XML file. // Load the XML file that contains a layout that the LayoutSerializer can read. var xDocument = XDocument.Load("Content/Layout.xml"); // Deserialize the objects in the XML document. var serializer = new LayoutSerializer(); var objects = serializer.Load(xDocument); // Get the first window of the deserialized objects. var window = objects.OfType <Window>().First(); // Get the button named "OkButton" and handle click event. var button = (Button)window.GetControl("OkButton"); button.Click += (s, e) => window.Close(); // ----- Show the window in the center of the screen. // First, we need to open the window. window.Show(this); // The window is now part of the visual tree of controls and can be measured. (The // window does not have a fixed size. Window.Width and Window.Height are NaN. The // size is calculated automatically depending on its content.) window.Measure(new Vector2F(float.PositiveInfinity)); // Measure computes DesiredWidth and DesiredHeight. With this info we can center the // window on the screen. window.X = Screen.ActualWidth / 2 - window.DesiredWidth / 2; window.Y = Screen.ActualHeight / 2 - window.DesiredHeight / 2; }
private void Save() { try { CultureInfo.InvariantCulture.DoInCulture(() => { var root = new SettingsStorage(); root.SetValue("DriveCache", DriveCache.Instance.Save()); root.SetValue("DatabaseConnectionCache", DatabaseConnectionCache.Instance.Save()); var mainWindow = new SettingsStorage(); mainWindow.SetValue("Width", MainWindow.Width); mainWindow.SetValue("Height", MainWindow.Height); mainWindow.SetValue("Location", MainWindow.GetLocation()); mainWindow.SetValue("WindowState", MainWindow.WindowState); root.SetValue("mainWindow", mainWindow); var navBar = new SettingsStorage(); navBar.SetValue("IsMinimized", MainWindow.NavigationBar.IsMinimized); navBar.SetValue("Width", MainWindow.NavigationBar.ContentWidth); navBar.SetValue("SelectedPane", MainWindow.NavigationBar.SelectedIndex); navBar.SetValue("SelectedSource", MainWindow.CurrentSources.SelectedIndex); navBar.SetValue("SelectedTool", MainWindow.CurrentTools.SelectedIndex); root.SetValue("navBar", navBar); var panes = new List <SettingsStorage>(); foreach (var paneWnd in MainWindow.DockSite.DocumentWindows.OfType <PaneWindow>()) { var settings = paneWnd.Pane.SaveEntire(false); settings.SetValue("isActive", MainWindow.DockSite.ActiveWindow == paneWnd); panes.Add(settings); } root.SetValue("panes", panes); new XmlSerializer <SettingsStorage>().Serialize(root, _configFile); if (MainWindow.DockSite != null) { var stream = new MemoryStream(); LayoutSerializer.SaveToStream(stream, MainWindow.DockSite); stream.Position = 0; stream.Save(_layoutFile); } }); } catch (Exception ex) { this.AddErrorLog(ex); } }
private void LayoutViewFormClosing(object sender, FormClosingEventArgs e) { var ls = new LayoutSerializer(); if (!ls.PromptToSaveChanges(layoutControl1, this)) { e.Cancel = true; return; } dockingManager1.SaveLayout(SerializationKey, false); mainFrameBarManager1.SaveLayout(SerializationKey, false); }
protected override void Initialize() { View.LayoutControl.Lock(); if (Model.HasTemplate) { var serializer = new LayoutSerializer(); serializer.LoadLayout(_context, View.LayoutControl, Model.TemplateName, Model.Extents, Model.PrinterSettings); } View.LayoutControl.PrinterSettings = Model.PrinterSettings; View.LayoutControl.Initialize(_context.Map, _loadingService); if (!Model.HasTemplate) { AddMapElement(Model.Scale, Model.Extents); } View.LayoutControl.Unlock(); View.UpdateView(); }
public void LoadLayout() { try { if (File.Exists(_layoutFile)) { CultureInfo.InvariantCulture.DoInCulture(() => LayoutSerializer.LoadFromFile(_layoutFile, MainWindow.DockSite)); } if (_settings == null) { return; } var navBar = _settings.GetValue <SettingsStorage>("navBar"); MainWindow.CurrentSources.SelectedIndex = navBar.GetValue <int>("SelectedSource"); MainWindow.CurrentConverters.SelectedIndex = navBar.GetValue <int>("SelectedConverter"); var panes = _settings.GetValue <IEnumerable <SettingsStorage> >("panes").ToArray(); var wnds = MainWindow.DockSite.DocumentWindows.OfType <PaneWindow>().ToArray(); // почему-то после загрузки разметки устанавливается в MainWindow wnds.ForEach(w => w.DataContext = null); var len = wnds.Length.Min(panes.Length); PaneWindow activeWnd = null; for (var i = 0; i < len; i++) { try { var wnd = wnds[i]; wnd.Pane = panes[i].LoadEntire <IPane>(); if (wnd.Pane.IsValid) { if (panes[i].GetValue <bool>("isActive")) { activeWnd = wnd; } } else { wnd.Pane = null; } } catch (Exception ex) { ex.LogError(); } } wnds.Where(w => w.Pane == null).ForEach(w => w.Close()); if (activeWnd != null) { activeWnd.Activate(); } DriveCache.Instance.NewDriveCreated += s => { lock (_timerSync) _needToSave = true; }; DatabaseConnectionCache.Instance.NewConnectionCreated += c => { lock (_timerSync) _needToSave = true; }; } catch (Exception ex) { ex.LogError(); } }
protected override void OnClosed(EventArgs e) { LayoutSerializer.SaveToFile(LayoutManager.LayoutFile, DockSite1); base.OnClosed(e); }
public void OnItemClicked(object sender, MenuItemEventArgs e) { _layoutControl.PanMode = false; switch (e.ItemKey) { case LayoutMenuKeys.RestoreToolbars: _view.RestoreToolbars(); break; case LayoutMenuKeys.RestorePanels: _view.RestorePanels(); break; case LayoutMenuKeys.ShowRulers: _layoutControl.ShowRulers = !_layoutControl.ShowRulers; break; case LayoutMenuKeys.AdjustPages: _layoutControl.UpdateLayout(); break; case LayoutMenuKeys.SelectAll: _layoutControl.SelectAll(); break; case LayoutMenuKeys.SelectNone: _layoutControl.ClearSelection(); break; case LayoutMenuKeys.InvertSelection: _layoutControl.InvertSelection(); break; case LayoutMenuKeys.ConvertToBitmap: ConvertElementToBitmap(); break; case LayoutMenuKeys.MoveUp: _layoutControl.MoveSelectionUp(); break; case LayoutMenuKeys.MoveDown: _layoutControl.MoveSelectionDown(); break; case LayoutMenuKeys.DeleteElement: _layoutControl.DeleteSelected(); break; case LayoutMenuKeys.ShowMargins: _layoutControl.ShowMargins = !_layoutControl.ShowMargins; break; case LayoutMenuKeys.ShowPageNumbers: _layoutControl.ShowPageNumbers = !_layoutControl.ShowPageNumbers; break; case LayoutMenuKeys.NewLayout: if (PromptSaveExistingLayout()) { _layoutControl.Filename = string.Empty; _layoutControl.ClearLayout(); } break; case LayoutMenuKeys.SaveLayout: SaveLayout(false); break; case LayoutMenuKeys.SaveLayoutAs: SaveLayout(true); break; case LayoutMenuKeys.LoadLayout: var ls = new LayoutSerializer(); ls.LoadNewLayout(_layoutControl, _context, _view.Model.Extents, _view as IWin32Window); break; case LayoutMenuKeys.Print: { var service = new PrintingService(); service.Print(_layoutControl.Pages, _layoutControl.PrinterSettings, _layoutControl.LayoutElements); } break; case LayoutMenuKeys.PrinterSetup: RunPrinterSetup(); break; case LayoutMenuKeys.PageSetup: RunPageSetup(); break; case LayoutMenuKeys.ExportToPdf: _pdfService.ExportToPdf(_layoutControl, ParentView); break; case LayoutMenuKeys.ExportToBitmap: ExportToBitmap(); break; case LayoutMenuKeys.ZoomIn: _layoutControl.ZoomIn(); break; case LayoutMenuKeys.ZoomOut: _layoutControl.ZoomOut(); break; case LayoutMenuKeys.ZoomFitScreen: _layoutControl.ZoomFitToScreen(); break; case LayoutMenuKeys.ZoomOriginal: _layoutControl.Zoom = 1; break; case LayoutMenuKeys.AddMap: AddMap(); break; case LayoutMenuKeys.AddLegend: AddLegend(); break; case LayoutMenuKeys.AddScaleBar: AddScaleBar(); break; case LayoutMenuKeys.AddNorthArrow: _layoutControl.AddElementWithMouse(new LayoutNorthArrow()); break; case LayoutMenuKeys.AddTable: AddTable(); break; case LayoutMenuKeys.AddLabel: _layoutControl.AddElementWithMouse(new LayoutText()); break; case LayoutMenuKeys.AddRectangle: _layoutControl.AddElementWithMouse(new LayoutRectangle()); break; case LayoutMenuKeys.AddBitmap: AddBitmap(); break; case LayoutMenuKeys.ZoomToMaximum: { var map = SelectedMapElement; if (map != null) { map.ZoomToMaxExtents(); } } break; case LayoutMenuKeys.ZoomToOriginalExtents: { var map = SelectedMapElement; if (map != null) { map.ZooomToOriginalExtents(); } } break; case LayoutMenuKeys.MapZoomIn: { var map = SelectedMapElement; if (map != null) { _layoutControl.ZoomInMap(map); } } break; case LayoutMenuKeys.MapZoomOut: { var map = SelectedMapElement; if (map != null) { _layoutControl.ZoomOutMap(map); } } break; case LayoutMenuKeys.MapPan: { _layoutControl.PanMode = true; } break; } _view.UpdateView(); }
private bool PromptSaveExistingLayout() { var ls = new LayoutSerializer(); return(ls.PromptToSaveChanges(_layoutControl, _view as IWin32Window)); }
private void SaveLayout(bool saveAs) { var ls = new LayoutSerializer(); ls.SaveLayout(_layoutControl, saveAs, _view as IWin32Window); }