private void ParseArgs(string[] args) { if (args == null) { return; } for (int i = 0; i < args.Length; i++) { string arg = args[i]; if (arg == "-i") { // Handle the include command. This allows us to add dlls and static resources to the editor string nextArg = (i < args.Length - 1) ? args[i + 1] : null; if (nextArg != null) { try { if (nextArg.StartsWith("pack://")) { XamlResources.Add(nextArg); } else if (System.IO.File.Exists(nextArg)) { if (nextArg.EndsWith(".xaml", StringComparison.InvariantCultureIgnoreCase)) { XamlResources.Add(nextArg); } else if (nextArg.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase)) { Assembly.LoadFile(nextArg); string dir = System.IO.Path.GetDirectoryName(nextArg); AssemblySearchDirs.Add(dir); } } } catch (Exception ex) { Console.WriteLine(ex); Debug.Fail("Could not load: " + args + " " + nextArg); } } i++; continue; } if (System.IO.File.Exists(arg)) { XamlDocument doc = XamlDocument.FromFile(arg); XamlDocuments.Add(doc); } } }
//------------------------------------------------------------------- // // Constructors // //------------------------------------------------------------------- #region Constructors 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(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); } }