private void EditLayout_Click(object sender, RoutedEventArgs e)
        {
            EditorOverlay mainEditor = EditorOverlay.Current;

            if (!(mainEditor.DataContext is LayoutModel model))
            {
                return;
            }

            model.IsSelected = false;
            _editing         = true;
            Close();

            bool isPredefinedLayout = Settings.IsPredefinedLayout(model);

            if (!_settings.CustomModels.Contains(model) || isPredefinedLayout)
            {
                if (isPredefinedLayout)
                {
                    // make a copy
                    model = model.Clone();
                    mainEditor.DataContext = model;
                }

                int maxCustomIndex = 0;
                foreach (LayoutModel customModel in _settings.CustomModels)
                {
                    string name = customModel.Name;
                    if (name.StartsWith(_defaultNamePrefix))
                    {
                        if (int.TryParse(name.Substring(_defaultNamePrefix.Length), out int i))
                        {
                            if (maxCustomIndex < i)
                            {
                                maxCustomIndex = i;
                            }
                        }
                    }
                }

                model.Name = _defaultNamePrefix + (++maxCustomIndex);
            }

            mainEditor.Edit();

            EditorWindow window;

            if (model is GridLayoutModel)
            {
                window = new GridEditorWindow();
            }
            else
            {
                window = new CanvasEditorWindow();
            }

            window.Owner       = EditorOverlay.Current;
            window.DataContext = model;
            window.Show();
        }
Exemple #2
0
        public void OpenEditor(LayoutModel model)
        {
            _layoutPreview = null;
            if (CurrentDataContext is GridLayoutModel)
            {
                _editor = new GridEditor();
            }
            else if (CurrentDataContext is CanvasLayoutModel)
            {
                _editor = new CanvasEditor();
            }

            CurrentLayoutWindow.Content = _editor;

            EditorWindow window;
            bool         isGrid = false;

            if (model is GridLayoutModel)
            {
                window = new GridEditorWindow();
                isGrid = true;
            }
            else
            {
                window = new CanvasEditorWindow();
            }

            window.Owner       = Monitors[App.Overlay.CurrentDesktop].Window;
            window.DataContext = model;
            window.Show();

            if (isGrid)
            {
                (window as GridEditorWindow).NameTextBox().Focus();
            }

            window.LeftWindowCommands  = null;
            window.RightWindowCommands = null;
        }