Esempio n. 1
0
        public EditorTabUIWPF(EditorTabUIWPFParameters parameters)
        {
            InitializeComponent();

            DataContext = new EditorTabViewModel(parameters);

            Name = parameters.Name;

            Title = "Editor Tab";
        }
        protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs args)
        {
            base.OnPropertyChanged(args);

            if (args.Property != DataContextProperty)
            {
                return;
            }

            if (args.OldValue is EditorTabViewModel previousModel)
            {
                // The way the DataTemplate works means the same control can be re-used for the different tabs, just with a different
                // DataContext. It is important to ensure the previous part is saved first
                previousModel.Part.Contents = this.Editor.Text;

                previousModel.ReadEditorInfo -= this.OnReadEditorInfo;
                previousModel.UpdateEditor   -= this.OnUpdateEditor;
                previousModel.ShowResults    -= this.OnShowResults;

                previousModel.Cut       -= this.OnCut;
                previousModel.Copy      -= this.OnCopy;
                previousModel.Paste     -= this.OnPaste;
                previousModel.Undo      -= this.OnUndo;
                previousModel.Redo      -= this.OnRedo;
                previousModel.SelectAll -= this.OnSelectAll;
            }

            if (!(args.NewValue is EditorTabViewModel model))
            {
                this.viewModel = null;
                return;
            }

            this.viewModel       = model;
            this.viewModel.Lexer = new XmlLexer
            {
                Editor = this.Editor,
            };

            this.Editor.Text = this.viewModel.Part.Contents;
            this.Editor.EmptyUndoBuffer();

            this.viewModel.ReadEditorInfo += this.OnReadEditorInfo;
            this.viewModel.UpdateEditor   += this.OnUpdateEditor;
            this.viewModel.ShowResults    += this.OnShowResults;

            this.viewModel.Cut       += this.OnCut;
            this.viewModel.Copy      += this.OnCopy;
            this.viewModel.Paste     += this.OnPaste;
            this.viewModel.Undo      += this.OnUndo;
            this.viewModel.Redo      += this.OnRedo;
            this.viewModel.SelectAll += this.OnSelectAll;
        }
Esempio n. 3
0
 public static void WriteEditorTabToFile(string path, EditorTabViewModel tab)
 => File.WriteAllText(path, tab.Content);