private bool ExecuteEditorCommandInvokedFromPlugIn(IAMLEditorPlugin source, AMLEditorCommandEnum command, EditorCommandArguments args) { bool success = false; args.Cancelled = false; Dispatcher.Invoke(new Action(() => { try { switch (command) { case AMLEditorCommandEnum.CloseFileCommand: MessageBoxResult result = MessageBox.Show("Close File", "AMLEditor Command Execution", MessageBoxButton.YesNoCancel, MessageBoxImage.Question); success = result == MessageBoxResult.Yes; args.Cancelled = result == MessageBoxResult.Cancel; if (success) { _mainModel.CloseCommand.Execute(null); } break; case AMLEditorCommandEnum.GetCAEXFileCommand: if (_mainModel.ActiveDocument.Document != null && args is GetCAEXFileCommandArguments cfarg) { cfarg.CaexFile = _mainModel.ActiveDocument.Document.CAEXFile; success = true; } else { success = false; } break; case AMLEditorCommandEnum.NewFileCommand: result = MessageBox.Show("New File", "AMLEditor Command Execution", MessageBoxButton.YesNoCancel, MessageBoxImage.Question); success = result == MessageBoxResult.Yes; args.Cancelled = result == MessageBoxResult.Cancel; if (success) { _mainModel.CloseCommand.Execute(null); _mainModel.NewCommand.Execute(null); } break; case AMLEditorCommandEnum.OpenFileCommand: result = MessageBox.Show("Open File", "AMLEditor Command Execution", MessageBoxButton.YesNoCancel, MessageBoxImage.Question); success = result == MessageBoxResult.Yes; args.Cancelled = result == MessageBoxResult.Cancel; if (success && args is OpenFileCommandArguments ofarg) { _mainModel.CloseCommand.Execute(null); _mainModel.OpenDocument(ofarg.FilePath); } break; case AMLEditorCommandEnum.SaveFileCommand: result = MessageBox.Show("Save File", "AMLEditor Command Execution", MessageBoxButton.YesNoCancel, MessageBoxImage.Question); success = result == MessageBoxResult.Yes; args.Cancelled = result == MessageBoxResult.Cancel; if (success && args is SaveCAEXFileCommandArguments sfarg) { if (_mainModel.SaveCommand.CanExecute(null)) { _mainModel.SaveCommand.Execute(null); } else { success = false; } } break; case AMLEditorCommandEnum.ImportLibrariesCommand: result = MessageBox.Show("Import from File not implemented in SandBox", "AMLEditor Command Execution", MessageBoxButton.OK, MessageBoxImage.Information); success = false; args.Cancelled = true; break; case AMLEditorCommandEnum.CaptureCommand: result = MessageBox.Show("Capture not implemented in SandBox", "AMLEditor Command Execution", MessageBoxButton.OK, MessageBoxImage.Information); success = false; args.Cancelled = true; break; } } catch (Exception exp) { args.Error = exp; } })); return(success); }
private bool ExecuteEditorCommandInvokedFromPlugIn(IAMLEditorPlugin source, AMLEditorCommandEnum command, EditorCommandArguments args) { bool success = false; args.Cancelled = false; Dispatcher.Invoke(new Action(() => { try { switch (command) { case AMLEditorCommandEnum.CloseFileCommand: MessageBoxResult result = MessageBox.Show("Close File", "AMLEditor Command Execution", MessageBoxButton.YesNoCancel, MessageBoxImage.Question); success = result == MessageBoxResult.Yes; args.Cancelled = result == MessageBoxResult.Cancel; if (success) { MainViewModel.Instance.Close(); } break; case AMLEditorCommandEnum.GetCAEXFileCommand: if (MainViewModel.Instance.Document != null && args is GetCAEXFileCommandArguments cfarg) { cfarg.CaexFile = MainViewModel.Instance.Document.CAEXFile; } break; case AMLEditorCommandEnum.NewFileCommand: result = MessageBox.Show("New File", "AMLEditor Command Execution", MessageBoxButton.YesNoCancel, MessageBoxImage.Question); success = result == MessageBoxResult.Yes; args.Cancelled = result == MessageBoxResult.Cancel; if (success) { MainViewModel.Instance.Close(); MainViewModel.Instance.New(); } break; case AMLEditorCommandEnum.OpenFileCommand: result = MessageBox.Show("Open File", "AMLEditor Command Execution", MessageBoxButton.YesNoCancel, MessageBoxImage.Question); success = result == MessageBoxResult.Yes; args.Cancelled = result == MessageBoxResult.Cancel; if (success && args is OpenFileCommandArguments ofarg) { MainViewModel.Instance.Close(); MainViewModel.Instance.Open(ofarg.FilePath); } break; case AMLEditorCommandEnum.ImportLibrariesCommand: result = MessageBox.Show("Import from File not implemented in SandBox", "AMLEditor Command Execution", MessageBoxButton.YesNoCancel, MessageBoxImage.Question); success = result == MessageBoxResult.Yes; args.Cancelled = result == MessageBoxResult.Cancel; break; } } catch (Exception exp) { args.Error = exp; } })); return(success); }