Exemple #1
0
        public static XamlDocument FromFile(string fullPath)
        {
            if (File.Exists(fullPath))
            {
                string sourceText = File.ReadAllText(fullPath);

                XamlDocument document = null;

                if (sourceText.Contains("http://schemas.microsoft.com/winfx/2006/xaml/presentation"))
                {
                    document = new WpfDocument(Path.GetDirectoryName(fullPath), sourceText);
                }
                else
                {
                    document = new AgDocument(Path.GetDirectoryName(fullPath), sourceText);
                }


                document.FullPath = fullPath;
                return(document);
            }

            return(null);
        }
Exemple #2
0
        public MainWindow()
        {
            InitializeComponent();

            KaxamlInfo.MainWindow = this;

            // initialize commands

            CommandBinding binding = new CommandBinding(ParseCommand);
            binding.Executed += new ExecutedRoutedEventHandler(this.Parse_Executed);
            binding.CanExecute += new CanExecuteRoutedEventHandler(this.Parse_CanExecute);
            this.InputBindings.Add(new InputBinding(binding.Command, new KeyGesture(Key.F5)));
            this.CommandBindings.Add(binding);

            binding = new CommandBinding(NewWPFTabCommand);
            binding.Executed += new ExecutedRoutedEventHandler(this.NewWPFTab_Executed);
            binding.CanExecute += new CanExecuteRoutedEventHandler(this.NewWPFTab_CanExecute);
            this.InputBindings.Add(new InputBinding(binding.Command, new KeyGesture(Key.T, ModifierKeys.Control, "Ctrl+T")));
            this.CommandBindings.Add(binding);

            binding = new CommandBinding(NewAgTabCommand);
            binding.Executed += new ExecutedRoutedEventHandler(this.NewAgTab_Executed);
            binding.CanExecute += new CanExecuteRoutedEventHandler(this.NewAgTab_CanExecute);
            this.InputBindings.Add(new InputBinding(binding.Command, new KeyGesture(Key.L, ModifierKeys.Control, "Ctrl+L")));
            this.CommandBindings.Add(binding);

            binding = new CommandBinding(CloseTabCommand);
            binding.Executed += new ExecutedRoutedEventHandler(this.CloseTab_Executed);
            binding.CanExecute += new CanExecuteRoutedEventHandler(this.CloseTab_CanExecute);
            this.InputBindings.Add(new InputBinding(binding.Command, new KeyGesture(Key.W, ModifierKeys.Control, "Ctrl+W")));
            this.CommandBindings.Add(binding);

            binding = new CommandBinding(SaveCommand);
            binding.Executed += new ExecutedRoutedEventHandler(this.Save_Executed);
            binding.CanExecute += new CanExecuteRoutedEventHandler(this.Save_CanExecute);
            this.InputBindings.Add(new InputBinding(binding.Command, new KeyGesture(Key.S, ModifierKeys.Control, "Ctrl+S")));
            this.CommandBindings.Add(binding);

            binding = new CommandBinding(SaveAsCommand);
            binding.Executed += new ExecutedRoutedEventHandler(this.SaveAs_Executed);
            binding.CanExecute += new CanExecuteRoutedEventHandler(this.SaveAs_CanExecute);
            this.InputBindings.Add(new InputBinding(binding.Command, new KeyGesture(Key.S, ModifierKeys.Control | ModifierKeys.Alt, "Ctrl+Alt+S")));
            this.CommandBindings.Add(binding);

            binding = new CommandBinding(OpenCommand);
            binding.Executed += new ExecutedRoutedEventHandler(this.Open_Executed);
            binding.CanExecute += new CanExecuteRoutedEventHandler(this.Open_CanExecute);
            this.InputBindings.Add(new InputBinding(binding.Command, new KeyGesture(Key.O, ModifierKeys.Control, "Ctrl+O")));
            this.CommandBindings.Add(binding);

            binding = new CommandBinding(SaveAsImageCommand);
            binding.Executed += new ExecutedRoutedEventHandler(this.SaveAsImage_Executed);
            binding.CanExecute += new CanExecuteRoutedEventHandler(this.SaveAsImage_CanExecute);
            this.InputBindings.Add(new InputBinding(binding.Command, new KeyGesture(Key.I, ModifierKeys.Control, "Ctrl+I")));
            this.CommandBindings.Add(binding);

            binding = new CommandBinding(ExitCommand);
            binding.Executed += new ExecutedRoutedEventHandler(this.Exit_Executed);
            binding.CanExecute += new CanExecuteRoutedEventHandler(this.Exit_CanExecute);
            //this.InputBindings.Add(new InputBinding(binding.Command, new KeyGesture(Key.O, ModifierKeys.Control, "Ctrl+O")));
            this.CommandBindings.Add(binding);

            // Zoom Commands

            binding = new CommandBinding(ZoomInCommand);
            binding.Executed += new ExecutedRoutedEventHandler(this.ZoomIn_Executed);
            binding.CanExecute += new CanExecuteRoutedEventHandler(this.ZoomIn_CanExecute);
            this.InputBindings.Add(new InputBinding(binding.Command, new KeyGesture(Key.OemPlus, ModifierKeys.Control, "Ctrl++")));
            this.CommandBindings.Add(binding);

            binding = new CommandBinding(ZoomOutCommand);
            binding.Executed += new ExecutedRoutedEventHandler(this.ZoomOut_Executed);
            binding.CanExecute += new CanExecuteRoutedEventHandler(this.ZoomOut_CanExecute);
            this.InputBindings.Add(new InputBinding(binding.Command, new KeyGesture(Key.OemMinus, ModifierKeys.Control, "Ctrl+-")));
            this.CommandBindings.Add(binding);

            binding = new CommandBinding(ActualSizeCommand);
            binding.Executed += new ExecutedRoutedEventHandler(this.ActualSize_Executed);
            binding.CanExecute += new CanExecuteRoutedEventHandler(this.ActualSize_CanExecute);
            this.InputBindings.Add(new InputBinding(binding.Command, new KeyGesture(Key.D1, ModifierKeys.Control, "Ctrl+1")));
            this.CommandBindings.Add(binding);

            // Edit Commands
            // We have an unusual situation here where we need to handle Copy/Paste/etc. from the menu
            // separately from the built in keyboard commands that you have in control itself.  This
            // is because of some difficulty in getting commands to go accross the WPF/WinForms barrier.
            // One artifact of this is the fact that we want to create the commands without InputGestures
            // because the WinForms controls will handle the keyboards stuff--so this is for Menu only.

            binding = new CommandBinding(CopyCommand);
            binding.Executed += new ExecutedRoutedEventHandler(this.Copy_Executed);
            binding.CanExecute += new CanExecuteRoutedEventHandler(this.Copy_CanExecute);
            this.CommandBindings.Add(binding);

            binding = new CommandBinding(CutCommand);
            binding.Executed += new ExecutedRoutedEventHandler(this.Cut_Executed);
            binding.CanExecute += new CanExecuteRoutedEventHandler(this.Cut_CanExecute);
            this.CommandBindings.Add(binding);

            binding = new CommandBinding(PasteCommand);
            binding.Executed += new ExecutedRoutedEventHandler(this.Paste_Executed);
            binding.CanExecute += new CanExecuteRoutedEventHandler(this.Paste_CanExecute);
            this.CommandBindings.Add(binding);

            binding = new CommandBinding(PasteImageCommand);
            binding.Executed += new ExecutedRoutedEventHandler(this.PasteImage_Executed);
            binding.CanExecute += new CanExecuteRoutedEventHandler(this.PasteImage_CanExecute);
            this.InputBindings.Add(new InputBinding(binding.Command, new KeyGesture(Key.V, ModifierKeys.Control | ModifierKeys.Shift, "Ctrl+Shift+V")));
            this.CommandBindings.Add(binding);

            binding = new CommandBinding(DeleteCommand);
            binding.Executed += new ExecutedRoutedEventHandler(this.Delete_Executed);
            binding.CanExecute += new CanExecuteRoutedEventHandler(this.Delete_CanExecute);
            this.CommandBindings.Add(binding);

            binding = new CommandBinding(UndoCommand);
            binding.Executed += new ExecutedRoutedEventHandler(this.Undo_Executed);
            binding.CanExecute += new CanExecuteRoutedEventHandler(this.Undo_CanExecute);
            this.CommandBindings.Add(binding);

            binding = new CommandBinding(RedoCommand);
            binding.Executed += new ExecutedRoutedEventHandler(this.Redo_Executed);
            binding.CanExecute += new CanExecuteRoutedEventHandler(this.Redo_CanExecute);
            this.CommandBindings.Add(binding);

            binding = new CommandBinding(FindCommand);
            binding.Executed += new ExecutedRoutedEventHandler(this.Find_Executed);
            binding.CanExecute += new CanExecuteRoutedEventHandler(this.Find_CanExecute);
            this.CommandBindings.Add(binding);

            binding = new CommandBinding(FindNextCommand);
            binding.Executed += new ExecutedRoutedEventHandler(this.FindNext_Executed);
            binding.CanExecute += new CanExecuteRoutedEventHandler(this.FindNext_CanExecute);
            this.InputBindings.Add(new InputBinding(binding.Command, new KeyGesture(Key.F3, ModifierKeys.None, "F3")));
            this.CommandBindings.Add(binding);

            binding = new CommandBinding(ReplaceCommand);
            binding.Executed += new ExecutedRoutedEventHandler(this.Replace_Executed);
            binding.CanExecute += new CanExecuteRoutedEventHandler(this.Replace_CanExecute);
            this.InputBindings.Add(new InputBinding(binding.Command, new KeyGesture(Key.H, ModifierKeys.Control, "F3")));
            this.CommandBindings.Add(binding);

            this.PreviewKeyDown += new KeyEventHandler(MainWindow_PreviewKeyDown);

            // load or create startup documents

            if (App.StartupArgs.Length > 0)
            {
                foreach (string s in App.StartupArgs)
                {
                    if (System.IO.File.Exists(s))
                    {
                        XamlDocument doc = XamlDocument.FromFile(s);
                        XamlDocuments.Add(doc);
                    }
                }
            }

            if (XamlDocuments.Count == 0)
            {
                WpfDocument doc = new WpfDocument(System.IO.Directory.GetCurrentDirectory());
                XamlDocuments.Add(doc);
            }
        }
Exemple #3
0
        void NewWPFTab_Executed(object sender, ExecutedRoutedEventArgs args)
        {
            if (sender == this)
            {
                WpfDocument doc = new WpfDocument(System.IO.Directory.GetCurrentDirectory());
                XamlDocuments.Add(doc);

                this.DocumentsView.SelectedDocument = doc;

            }
        }
Exemple #4
0
        public static XamlDocument FromFile(string fullPath)
        {
            if (File.Exists(fullPath))
            {
                string sourceText = File.ReadAllText(fullPath);

                XamlDocument document = null;

                if (sourceText.Contains("http://schemas.microsoft.com/winfx/2006/xaml/presentation"))
                {
                    document = new WpfDocument(Path.GetDirectoryName(fullPath), sourceText);
                }
                else
                {
                    document = new AgDocument(Path.GetDirectoryName(fullPath), sourceText);
                }

                document.FullPath = fullPath;
                return document;
            }

            return null;
        }