private void SaveProjectAs_Executed(object sender, ExecutedRoutedEventArgs e) { var m = __any_binding_error(); if (m != null) { HandyControl.Controls.MessageBox.Show(this, $"At least one data binding error was found in <{m.FriendlyName}>.", "Error Message", MessageBoxButton.OK, MessageBoxImage.Error); return; } try { System.Windows.Forms.SaveFileDialog save = new System.Windows.Forms.SaveFileDialog(); save.Filter = "JavaScript Object Notation(*.json)|*.json"; save.AddExtension = true; save.DefaultExt = "json"; if (save.ShowDialog() == System.Windows.Forms.DialogResult.OK) { __docking_documents_layout = __save_documents_docking_layout(_ToolboxContainer); var floatingLayout = __save_documents_floating_layout(); MainDataModel.SAVE_TO_JSON(__target_manager_data_model, __cabinets_navigation_data_model, __docking_documents_layout, floatingLayout, save.FileName); __main_wnd_data_model.ProjectPath = save.FileName; __main_wnd_data_model.IsDirty = false; } } catch (Exception ex) { HandyControl.Controls.MessageBox.Show(this, $"At least one unexpected error occured while saving the project.\n{ex.Message}", "Error Message", MessageBoxButton.OK, MessageBoxImage.Error); } }
private bool __docking_layout_comparison(ToolLayout layout0, ToolLayout layout1) { if (layout0.Type == layout1.Type) { switch (layout0.Type) { case TOOL_LAYOUT_TYPE_T.PANEL: var layoutpanel0 = layout0 as LayoutPanel <LayoutDocument>; var layoutpanel1 = layout1 as LayoutPanel <LayoutDocument>; if (layoutpanel0.Height == layoutpanel1.Height && layoutpanel0.Width == layoutpanel1.Width && layoutpanel0.Documents.Count == layoutpanel1.Documents.Count) { for (int i = 0; i < layoutpanel0.Documents.Count; ++i) { if (layoutpanel0.Documents[i] != layoutpanel1.Documents[i]) { return(false); } } return(true); } else { return(false); } case TOOL_LAYOUT_TYPE_T.GROUP: var layoutgroup0 = layout0 as LayoutGroup; var layoutgroup1 = layout0 as LayoutGroup; if (layoutgroup0.Orientation == layoutgroup1.Orientation && layoutgroup0.SubLayout.Count == layoutgroup1.SubLayout.Count && layoutgroup0.Height == layoutgroup1.Height && layoutgroup0.Width == layoutgroup1.Width) { for (int i = 0; i < layoutgroup0.SubLayout.Count; ++i) { if (__docking_layout_comparison(layoutgroup0.SubLayout[i], layoutgroup1.SubLayout[i]) == false) { return(false); } } return(true); } else { return(false); } default: return(false); } } else { return(false); } }
private void OpenProject_Executed(object sender, ExecutedRoutedEventArgs e) { if (__main_wnd_data_model.IsDirty == true || __docking_layout_comparison(_ToolboxContainer, __docking_documents_layout) == false) { if (HandyControl.Controls.MessageBox.Show(this, $"Discard the changes you have made ?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No) { return; } } System.Windows.Forms.OpenFileDialog open = new System.Windows.Forms.OpenFileDialog(); open.Multiselect = false; open.Filter = "JavaScript Object Notation(*.json)|*.json"; open.AddExtension = true; open.DefaultExt = "json"; if (open.ShowDialog() == System.Windows.Forms.DialogResult.OK) { List <LayoutDocument> floatingLayout = null; try { __cabinets_navigation_data_model.ClearToolbox((doc) => doc.Close()); MainDataModel.RESTORE_FROM_JSON(open.FileName, out __target_manager_data_model, __cabinets_navigation_data_model, out __docking_documents_layout, out floatingLayout); } catch (Exception ex) { HandyControl.Controls.MessageBox.Show(this, $"At least one unexpected error occured while opening the project.\n{ex.Message}", "Error Message", MessageBoxButton.OK, MessageBoxImage.Error); } if (__target_manager_data_model == null) { __target_manager_data_model = new TargetManagerDataModel(); } _ConnectionTargetsContainer.Content = new TargetManagerControl(__target_manager_data_model); if (__docking_documents_layout == null) { __docking_documents_layout = __docking_documents_layout_null; } if (floatingLayout != null) { __restore_documents_floating_layout(floatingLayout); } _ToolboxContainer.Children.Clear(); if (__docking_documents_layout != null) { _ToolboxContainer.Orientation = (__docking_documents_layout as LayoutGroup).Orientation == TOOL_LAYOUT_ORIENTATION_T.HORIZONTAL ? Orientation.Horizontal : Orientation.Vertical; __restore_documents_docking_layout((__docking_documents_layout as LayoutGroup).SubLayout, _ToolboxContainer); } __main_wnd_data_model.ProjectPath = open.FileName; __main_wnd_data_model.IsDirty = false; } }
public MainWindow() { InitializeComponent(); __main_wnd_data_model = new MainDataModel(); DataContext = __main_wnd_data_model; try { __cabinets_navigation_data_model = new ToolsNavigationDataModel <LayoutDocument>(null, null, Plugin_PropertyChanged); _CabinetContainer.Content = new ToolsNavigationControl(__cabinets_navigation_data_model); __docking_documents_layout = __save_documents_docking_layout(_ToolboxContainer); __docking_documents_layout_null = __docking_documents_layout; __data_synchronizer = new DataSynchronizer(__cabinets_navigation_data_model.ToolDataCollection); __user_interface_synchronizer = new UserInterfaceSynchronizer(this, __ui_data_refresh_handler); } catch (Exception ex) { HandyControl.Controls.MessageBox.Show(this, $"At least one unexpected error occured during the boot process.\n{ex.Message}", "Error Message", MessageBoxButton.OK, MessageBoxImage.Error); Close(); } }
private void SaveProject_Executed(object sender, ExecutedRoutedEventArgs e) { var m = __any_binding_error(); if (m != null) { HandyControl.Controls.MessageBox.Show(this, $"At least one data binding error was found in <{m.FriendlyName}>.", "Error Message", MessageBoxButton.OK, MessageBoxImage.Error); return; } try { __docking_documents_layout = __save_documents_docking_layout(_ToolboxContainer); var floatingLayout = __save_documents_floating_layout(); MainDataModel.SAVE_TO_JSON(__target_manager_data_model, __cabinets_navigation_data_model, __docking_documents_layout, floatingLayout, __main_wnd_data_model.ProjectPath); __main_wnd_data_model.IsDirty = false; } catch (Exception ex) { HandyControl.Controls.MessageBox.Show(this, $"At least one unexpected error occured while saving the project.\n{ex.Message}", "Error Message", MessageBoxButton.OK, MessageBoxImage.Error); } }
private bool __docking_layout_comparison(LayoutDocumentPaneGroup root, ToolLayout layout) { if (layout.Type == TOOL_LAYOUT_TYPE_T.GROUP) { var layoutgroup = layout as LayoutGroup; var orientation = layoutgroup.Orientation == TOOL_LAYOUT_ORIENTATION_T.HORIZONTAL ? Orientation.Horizontal : Orientation.Vertical; if (orientation == root.Orientation && root.Children.Count == layoutgroup.SubLayout.Count && root.DockHeight.Value == layoutgroup.Height && root.DockWidth.Value == layoutgroup.Width) { for (int i = 0; i < layoutgroup.SubLayout.Count; ++i) { if (root.Children[i] is LayoutDocumentPaneGroup && layoutgroup.SubLayout[i].Type == TOOL_LAYOUT_TYPE_T.GROUP) { if (__docking_layout_comparison(root.Children[i] as LayoutDocumentPaneGroup, layoutgroup.SubLayout[i]) == false) { return(false); } } if (root.Children[i] is LayoutDocumentPane && layoutgroup.SubLayout[i].Type == TOOL_LAYOUT_TYPE_T.PANEL) { if (__docking_layout_comparison(root.Children[i] as LayoutDocumentPane, layoutgroup.SubLayout[i] as LayoutPanel <LayoutDocument>) == false) { return(false); } } } return(true); } else { return(false); } } else { return(false); } }
public void ExportDockingToolboxToJSON(Utf8JsonWriter writer, ToolLayout layout) { writer.WriteStartObject(); //if(layout.Panel != null) //{ // writer.WritePropertyName("Panel"); //__export_docking_toolbox_to_json_panel(writer, layout.Panel); //} //else if(layout.Group != null) if (layout.Type == TOOL_LAYOUT_TYPE_T.GROUP) { var layoutgroup = layout as LayoutGroup; switch (layoutgroup.Orientation) { case TOOL_LAYOUT_ORIENTATION_T.HORIZONTAL: writer.WritePropertyName("HGroup*" + layoutgroup.Height.ToString("F4", CultureInfo.InvariantCulture) + "*" + layoutgroup.Width.ToString("F4", CultureInfo.InvariantCulture)); break; case TOOL_LAYOUT_ORIENTATION_T.VERTICAL: writer.WritePropertyName("VGroup*" + layoutgroup.Height.ToString("F4", CultureInfo.InvariantCulture) + "*" + layoutgroup.Width.ToString("F4", CultureInfo.InvariantCulture)); break; default: throw new ArgumentException("The given value of <ToolLayout.Orientation> property is invalid."); } __export_docking_toolbox_to_json_group(writer, layoutgroup.SubLayout); } else { throw new ArgumentException("<ToolLayout> object is invalid."); } writer.WriteEndObject(); }
public static void RESTORE_FROM_JSON(string file, out TargetManagerDataModel targets, ToolsNavigationDataModel <LayoutDocument> navigation, out ToolLayout dockingLayout, out List <LayoutDocument> floatingLayout) { targets = null; dockingLayout = null; floatingLayout = null; ReadOnlySpan <byte> fs = File.ReadAllBytes(file); if (fs.StartsWith(__utf8_bom)) { fs = fs.Slice(__utf8_bom.Length); } var reader = new Utf8JsonReader(fs, new JsonReaderOptions() { CommentHandling = JsonCommentHandling.Skip }); try { while (reader.Read()) { switch (reader.TokenType, reader.CurrentDepth) { case (JsonTokenType.PropertyName, 1): switch (reader.GetString()) { case "Targets": TargetManagerDataModel.RESTORE_FROM_JSON(ref reader, out targets); break; case "Docking": dockingLayout = navigation.ImportDockingToolboxFromJSON(ref reader, fs); break; case "Floating": floatingLayout = navigation.ImportFloatingToolboxFromJSON(ref reader, fs); break; } break;
public static string SAVE_TO_JSON(TargetManagerDataModel targets, ToolsNavigationDataModel <LayoutDocument> navigation, ToolLayout dockingLayout, IReadOnlyList <LayoutDocument> floatingLayout, string file) { using var ms = new MemoryStream(); using var writer = new Utf8JsonWriter(ms, new JsonWriterOptions() { Indented = true }); writer.WriteStartObject(); writer.WritePropertyName("Targets"); TargetManagerDataModel.SAVE_TO_JSON(writer, targets); writer.WritePropertyName("Docking"); navigation.ExportDockingToolboxToJSON(writer, dockingLayout); writer.WritePropertyName("Floating"); navigation.ExportFloatingToolboxToJSON(writer, floatingLayout); writer.WriteEndObject(); writer.Flush(); using var fs = new FileStream(file, FileMode.Create, FileAccess.Write); ms.Seek(0, SeekOrigin.Begin); ms.CopyTo(fs); fs.Flush(); return(Encoding.UTF8.GetString(ms.ToArray())); }