Exemplo n.º 1
0
        private void EditLayout_Click(object sender, RoutedEventArgs e)
        {
            EditorOverlay mainEditor = EditorOverlay.Current;
            LayoutModel   model      = mainEditor.DataContext as LayoutModel;

            if (model == null)
            {
                return;
            }
            model.IsSelected = false;
            _editing         = true;
            this.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(c_defaultNamePrefix))
                    {
                        int i;
                        if (Int32.TryParse(name.Substring(c_defaultNamePrefix.Length), out i))
                        {
                            if (maxCustomIndex < i)
                            {
                                maxCustomIndex = i;
                            }
                        }
                    }
                }
                model.Name = c_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();
        }