예제 #1
0
 public TargetPropertyControl(TargetPropertyDataModel model, TargetManagerDataModel host, string originalName = null)
 {
     InitializeComponent();
     DataContext     = model;
     __host          = host;
     __original_name = originalName;
 }
예제 #2
0
        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()));
        }
예제 #3
0
        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;
            }
        }
예제 #4
0
        private void NewProject_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;
                }
            }
            __target_manager_data_model         = new TargetManagerDataModel();
            _ConnectionTargetsContainer.Content = new TargetManagerControl(__target_manager_data_model);
            __cabinets_navigation_data_model.ClearToolbox((doc) => doc.Close());
            _ToolboxContainer.Children.Clear();

            __main_wnd_data_model.IsDirty     = true;
            __main_wnd_data_model.ProjectPath = null;
        }
예제 #5
0
        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 TargetManagerControl(TargetManagerDataModel model)
 {
     InitializeComponent();
     DataContext = model;
 }