virtual public IQueryStatusResult CommandBeforeQueryStatus(ICommandQueryStatusParams e) { var result = new QueryStatusResult(); var prgcmds = (OLECMD[])e.PrgCmds; uint wtfisthis = prgcmds[0].cmdf; int commandID = Convert.ToInt32(prgcmds[0].cmdID); if (CommandMap.ContainsKey(commandID)) { var mappedCommand = CommandMap[commandID]; bool isVisible = mappedCommand.BaseCommand.BeforeQueryStatus(mappedCommand.MenuCommand, new EventArgs()); wtfisthis |= (uint)OLECMDF.OLECMDF_SUPPORTED | (uint)OLECMDF.OLECMDF_ENABLED; if (!isVisible) { wtfisthis = (uint)OLECMDF.OLECMDF_DEFHIDEONCTXTMENU | (uint)OLECMDF.OLECMDF_SUPPORTED | (uint)OLECMDF.OLECMDF_INVISIBLE; } result.IsVersionControlled = isVisible; } else { } result.PrgCmdsValue = wtfisthis; result.ReturnValue = 0; return(result); }
/// <summary> /// Remove a previously registered <c>ICommand</c> to <c>INotification</c> mapping. /// </summary> /// <param name="notificationName">the name of the <c>INotification</c> to remove the <c>ICommand</c> mapping for</param> public virtual void RemoveCommand(string notificationName) { if (!CommandMap.ContainsKey(notificationName)) { return; } MyView.RemoveObserver(notificationName, this); }
/// <summary> /// Register a particular <c>ICommand</c> class as the handler /// for a particular <c>INotification</c>. /// </summary> /// <remarks> /// <para> /// If a <c>ICommand</c> has already been registered to /// handle <c>INotification</c>s with this name, it is no longer /// used, the new <c>Func</c> is used instead. /// </para> /// <para> /// The Observer for the new ICommand is only created if this the /// first time an ICommand has been regisered for this Notification name. /// </para> /// </remarks> /// <param name="notificationName">the name of the <c>INotification</c></param> /// <param name="commandType">the <c>ICommand</c> type</param> public virtual void RegisterCommand(string notificationName, Type commandType) { if (!CommandMap.ContainsKey(notificationName)) { MyView.RegisterObserver(notificationName, new Observer(ExecuteCommand, this)); } CommandMap[notificationName] = commandType; }
public virtual bool KeyPress(KeyDescriptor descriptor) { // build repeat buffer if (_command == null && (_count > 0 || descriptor.KeyChar > '0') && descriptor.KeyChar >= '0' && descriptor.KeyChar <= '9') { _count = (_count * 10) + (descriptor.KeyChar - 48); return(false); } _buf += Char.ToString(descriptor.KeyChar); if (_command == null) { if (descriptor.ModifierKeys == ModifierKeys.Control) { _buf = "^" + _buf; } if (!SpecialKeyCommandMap.TryGetValue(descriptor.SpecialKey, out _command)) { if (!CommandMap.ContainsKey(_buf)) { foreach (var k in CommandMap.Keys) { if (k.StartsWith(_buf, StringComparison.Ordinal)) { return(false); } } Reset(); return(false); } _command = CommandMap[_buf]; } _buf = ""; if (_command.TakeArgument) { return(false); } } CaretOffEol(); RequestedMode = _command.RunCommand(_count, (char)(_buf.Length > 0 ? _buf[0] : 0)); _command = null; Reset(); CaretOffEol(); return(false); }
virtual public int CommandExecute(ICommandExecParams e) { int commandID = Convert.ToInt32(e.CommandID); if (CommandMap.ContainsKey(commandID)) { var mappedCommand = CommandMap[commandID]; //var x = Microsoft.VisualStudio.Shell.Interop.Constants.OLECMDERR_E_UNKNOWNGROUP; mappedCommand.BaseCommand.Execute(mappedCommand.MenuCommand, new EventArgs()); } return(0); }
/// <summary> /// Проверяет, существует ли команда в списке доступных. /// Если существует - возвращает команду. /// Если не существует - возвращает команду <see cref="NotFoundCommand" /> /// Работает с командами, реализующими интерфейс <see cref="ICommand" /> /// </summary> /// <param name="command">Название команды</param> /// <returns>Команда реализующая интерфейс <see cref="ICommand" /></returns> private ICommand CheckCommand(string command) { if (CommandMap.ContainsKey(command)) { return(CommandMap[command]); } var notFound = new NotFoundCommand(this) { Name = command }; return(notFound); }
/// <summary> /// If an <c>ICommand</c> has previously been registered /// to handle a the given <c>INotification</c>, then it is executed. /// </summary> /// <param name="notification">note an <c>INotification</c></param> public virtual void ExecuteCommand(INotification notification) { if (!CommandMap.ContainsKey(notification.Name)) { return; } var instance = Activator.CreateInstance(CommandMap[notification.Name]); var command = instance as ICommand; if (command != null) { command.Execute(notification); } }
private static int ParseCommandLine(TextWriter outwriter, Action <Library.Main.Controller> setup, ref bool verboseErrors, string[] args) { List <string> cargs = new List <string>(args); var tmpparsed = Library.Utility.FilterCollector.ExtractOptions(cargs); var options = tmpparsed.Item1; var filter = tmpparsed.Item2; verboseErrors = Library.Utility.Utility.ParseBoolOption(options, "debug-output"); if (cargs.Count == 1 && string.Equals(cargs[0], "changelog", StringComparison.OrdinalIgnoreCase)) { return(ShowChangeLog(outwriter)); } foreach (string internaloption in Library.Main.Options.InternalOptions) { if (options.ContainsKey(internaloption)) { outwriter.WriteLine(Strings.Program.InternalOptionUsedError(internaloption)); return(200); } } // Probe for "help" to avoid extra processing if (cargs.Count == 0 || (string.Equals(cargs[0], "help", StringComparison.OrdinalIgnoreCase))) { return(Commands.Help(outwriter, setup, cargs, options, filter)); } // try and parse all parameter file aliases foreach (string parameterOption in new [] { "parameters-file", "parameters-file", "parameterfile" }) { if (options.ContainsKey(parameterOption) && !string.IsNullOrEmpty(options[parameterOption])) { string filename = options[parameterOption]; options.Remove(parameterOption); if (!ReadOptionsFromFile(outwriter, filename, ref filter, cargs, options)) { return(100); } break; } } if (!options.ContainsKey("passphrase")) { if (!string.IsNullOrEmpty(System.Environment.GetEnvironmentVariable("PASSPHRASE"))) { options["passphrase"] = System.Environment.GetEnvironmentVariable("PASSPHRASE"); } } if (!options.ContainsKey("auth-password")) { if (!string.IsNullOrEmpty(System.Environment.GetEnvironmentVariable("AUTH_PASSWORD"))) { options["auth-password"] = System.Environment.GetEnvironmentVariable("AUTH_PASSWORD"); } } if (!options.ContainsKey("auth-username")) { if (!string.IsNullOrEmpty(System.Environment.GetEnvironmentVariable("AUTH_USERNAME"))) { options["auth-username"] = System.Environment.GetEnvironmentVariable("AUTH_USERNAME"); } } var showDeletionErrors = verboseErrors; Duplicati.Library.Utility.TempFile.RemoveOldApplicationTempFiles((path, ex) => { if (showDeletionErrors) { outwriter.WriteLine(string.Format("Failed to delete temp file: {0}", path)); } }); string command = cargs[0]; cargs.RemoveAt(0); if (CommandMap.ContainsKey(command)) { var autoupdate = Library.Utility.Utility.ParseBoolOption(options, "auto-update"); options.Remove("auto-update"); var res = CommandMap[command](outwriter, setup, cargs, options, filter); if (autoupdate && FROM_COMMANDLINE) { CheckForUpdates(outwriter); } return(res); } else { Commands.PrintInvalidCommand(outwriter, command, cargs); return(200); } }
/// <summary> /// Check if a Command is registered for a given Notification /// </summary> /// <param name="notificationName"></param> /// <returns>whether a Command is currently registered for the given <c>notificationName</c>.</returns> public virtual bool HasCommand(string notificationName) { return(CommandMap.ContainsKey(notificationName)); }