AnkhAction CreateHandler(AnkhCommand command) { return(delegate { Commands.PostExecCommand(command); }); }
public CommandEventArgs(AnkhCommand command, AnkhContext context, object argument, bool promptUser, bool dontPromptUser) : this(command, context) { _argument = argument; _promptUser = promptUser; _dontPromptUser = dontPromptUser; }
/// <summary> /// Posts the tick command. /// </summary> /// <param name="tick">if set to <c>true</c> [tick].</param> /// <param name="command">The command.</param> /// <returns></returns> public bool PostTickCommand(ref bool tick, AnkhCommand command) { if (IsTickCommand(command)) { _ticks[command - AnkhCommand.TickFirst] = 1; } if (tick) { return(false); } tick = true; bool ok = false; try { return(ok = PostExecCommand(command)); } finally { if (!ok) { tick = false; } } }
public CommandEventArgs(AnkhCommand command, AnkhContext context, object argument, bool promptUser, bool dontPromptUser) : this(command, context) { _argument = argument; _promptUser = promptUser; _dontPromptUser = dontPromptUser; }
public void TockCommand(AnkhCommand ankhCommand) { if (IsTickCommand(ankhCommand)) { _ticks[ankhCommand - AnkhCommand.TickFirst] = 0; } }
public void PostIdleCommand(AnkhCommand command, object args) { PostIdleAction( delegate() { DirectlyExecCommand(command, args); }); }
public static bool TestExecution(AnkhCommand commandEnum, object argument) { AnkhRuntime runtime = new AnkhRuntime(ServiceProviderHelper.serviceProvider); runtime.AddModule(new AnkhModule(runtime)); runtime.Start(); return(runtime.CommandMapper.Execute(commandEnum, new CommandEventArgs(commandEnum, runtime.Context, argument, false, false))); }
public static void ExecuteCommand(IVsPackage package, AnkhCommand command) { Guid cmdId = AnkhId.CommandSetGuid; int hr = ((IOleCommandTarget)package).Exec(ref cmdId, (uint)command, (uint)OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT, IntPtr.Zero, IntPtr.Zero); if (hr == (int)OLEConstants.OLECMDERR_E_DISABLED) Assert.Inconclusive("Command is disabled"); else Assert.IsTrue(hr == VSConstants.S_OK); }
bool IsTickCommand(AnkhCommand c) { if (c < AnkhCommand.TickFirst || c >= AnkhCommand.TickLast) { return(false); } return(true); }
/// <summary> /// Installs a visual studio command handler for the specified control /// </summary> /// <param name="context">The context.</param> /// <param name="control">The control.</param> /// <param name="command">The command.</param> /// <param name="handler">The handler.</param> public static void Install(IAnkhServiceProvider context, Control control, AnkhCommand command, ICommandHandler handler) { Install(context, control, command, delegate(object sender, CommandEventArgs e) { handler.OnExecute(e); }, delegate(object sender, CommandUpdateEventArgs e) { handler.OnUpdate(e); }); }
static bool IsFolderCommand(AnkhCommand command) { switch (command) { case AnkhCommand.FolderUpdateLatest: case AnkhCommand.FolderUpdateSpecific: return(true); default: return(false); } }
static bool IsSolutionCommand(AnkhCommand command) { switch (command) { case AnkhCommand.SolutionUpdateLatest: case AnkhCommand.SolutionUpdateSpecific: case AnkhCommand.PendingChangesUpdateLatest: return(true); default: return(false); } }
public void SafePostTickCommand(ref bool tick, AnkhCommand command) { if (tick) { return; } tick = true; lock (_delayTasks) { _delayedCommands.Add((int)command); } }
static bool IsHeadCommand(AnkhCommand command) { switch (command) { case AnkhCommand.SolutionUpdateLatest: case AnkhCommand.ProjectUpdateLatest: case AnkhCommand.PendingChangesUpdateLatest: case AnkhCommand.FolderUpdateLatest: return(true); default: return(false); } }
public static void ExecuteCommand(IVsPackage package, AnkhCommand command) { Guid cmdId = AnkhId.CommandSetGuid; int hr = ((IOleCommandTarget)package).Exec(ref cmdId, (uint)command, (uint)OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT, IntPtr.Zero, IntPtr.Zero); if (hr == VSErr.OLECMDERR_E_DISABLED) { Assert.Inconclusive("Command is disabled"); } else { Assert.IsTrue(hr == VSErr.S_OK); } }
public CommandResult DirectlyExecCommand(AnkhCommand command, object args, CommandPrompt prompt) { // TODO: Assert that we are in the UI thread CommandMapper mapper = GetService <CommandMapper>(); if (mapper == null) { return(new CommandResult(false, null)); } CommandEventArgs e = new CommandEventArgs(command, AnkhContext, args, prompt == CommandPrompt.Always, prompt == CommandPrompt.Never); bool ok = mapper.Execute(command, e); return(new CommandResult(ok, e.Result)); }
internal IEnumerable <AnkhCommand> GetAllCommands() { if (LastCommand == AnkhCommand.None) { yield return(Command); } else if (LastCommand < Command || ((int)LastCommand - (int)Command) > 256) { throw new InvalidOperationException("Command range larger then 256 on range starting with" + Command.ToString()); } else { for (AnkhCommand c = Command; c <= LastCommand; c++) { yield return(c); } } }
public bool TryGetParameterList(AnkhCommand command, out string definition) { EnsureLoaded(); CommandMapItem item; if (_map.TryGetValue(command, out item)) { definition = item.ArgumentDefinition; return(!string.IsNullOrEmpty(definition)); } else { definition = null; } return(false); }
/// <summary> /// Gets the <see cref="CommandMapItem"/> for the specified command /// </summary> /// <param name="command"></param> /// <returns>The <see cref="CommandMapItem"/> or null if the command is not valid</returns> public CommandMapItem this[AnkhCommand command] { get { CommandMapItem item; if (_map.TryGetValue(command, out item)) { return(item); } else { item = new CommandMapItem(command); _map.Add(command, item); return(item); } } }
public bool Execute(AnkhCommand command, CommandEventArgs e) { EnsureLoaded(); CommandMapItem item; if (_map.TryGetValue(command, out item)) { try { e.Prepare(item); CommandUpdateEventArgs u = new CommandUpdateEventArgs(command, e.Context); item.OnUpdate(u); if (u.Enabled) { item.OnExecute(e); } else { return(false); } } catch (Exception ex) { IAnkhErrorHandler eh = GetService <IAnkhErrorHandler>(); if (eh != null && eh.IsEnabled(ex)) { eh.OnError(ex, e); return(true); // If we return false VS shows another error box! } throw; } return(item.IsHandled); } return(false); }
AnkhAction CreateHandler(AnkhCommand command) { return delegate { Commands.PostExecCommand(command); }; }
public CommandResult ExecCommand(AnkhCommand command, bool verifyEnabled) { // The commandhandler in the package always checks enabled; no need to do it here return ExecCommand(new CommandID(AnkhId.CommandSetGuid, (int)command), verifyEnabled); }
public CommandResult ExecCommand(AnkhCommand command, bool verifyEnabled, object argument) { return(ExecCommand(new CommandID(AnkhId.CommandSetGuid, (int)command), verifyEnabled, argument)); }
public CommandResult ExecCommand(AnkhCommand command) { // The commandhandler in the package always checks enabled; no need to do it here return(ExecCommand(command, false)); }
public void PostIdleCommand(AnkhCommand command) { PostIdleCommand(command, null); }
public CommandResult DirectlyExecCommand(AnkhCommand command, object args) { return DirectlyExecCommand(command, args, CommandPrompt.DoDefault); }
public bool TryGetParameterList(AnkhCommand command, out string definition) { EnsureLoaded(); CommandMapItem item; if (_map.TryGetValue(command, out item)) { definition = item.ArgumentDefinition; return !string.IsNullOrEmpty(definition); } else definition = null; return false; }
/// <summary> /// Posts the tick command. /// </summary> /// <param name="tick">if set to <c>true</c> [tick].</param> /// <param name="command">The command.</param> /// <returns></returns> public bool PostTickCommand(ref bool tick, AnkhCommand command) { if (IsTickCommand(command)) _ticks[command - AnkhCommand.TickFirst] = 1; if (tick) return false; tick = true; bool ok = false; try { return ok = PostExecCommand(command); } finally { if (!ok) tick = false; } }
public void PostIdleCommand(AnkhCommand command, object args) { PostIdleAction( delegate() { DirectlyExecCommand(command, args); }); }
public void PostIdleCommand(AnkhCommand command) { PostIdleCommand(command, null); }
public bool PostExecCommand(AnkhCommand command, object args, CommandPrompt prompt) { return PostExecCommand(new CommandID(AnkhId.CommandSetGuid, (int)command), args, prompt); }
public bool PostExecCommand(AnkhCommand command, object args) { return PostExecCommand(command, args, CommandPrompt.DoDefault); }
public bool PostExecCommand(AnkhCommand command) { return PostExecCommand(command, null, CommandPrompt.DoDefault); }
public int ScheduleAt(DateTime time, AnkhCommand command) { return ScheduleAt(time, CreateHandler(command)); }
public bool Execute(AnkhCommand command, CommandEventArgs e) { EnsureLoaded(); CommandMapItem item; if (_map.TryGetValue(command, out item)) { try { e.Prepare(item); CommandUpdateEventArgs u = new CommandUpdateEventArgs(command, e.Context); item.OnUpdate(u); if (u.Enabled) { item.OnExecute(e); } else return false; } catch (Exception ex) { IAnkhErrorHandler eh = GetService<IAnkhErrorHandler>(); if (eh != null && eh.IsEnabled(ex)) { eh.OnError(ex, e); return true; // If we return false VS shows another error box! } throw; } return item.IsHandled; } return false; }
public void SafePostTickCommand(ref bool tick, AnkhCommand command) { if (tick) return; tick = true; lock (_delayTasks) { _delayedCommands.Add((int)command); } }
public CommandResult DirectlyExecCommand(AnkhCommand command) { return DirectlyExecCommand(command, null, CommandPrompt.DoDefault); }
public void TockCommand(AnkhCommand ankhCommand) { if (IsTickCommand(ankhCommand)) _ticks[ankhCommand - AnkhCommand.TickFirst] = 0; }
static bool IsHeadCommand(AnkhCommand command) { switch (command) { case AnkhCommand.SolutionUpdateLatest: case AnkhCommand.ProjectUpdateLatest: case AnkhCommand.PendingChangesUpdateLatest: case AnkhCommand.FolderUpdateLatest: return true; default: return false; } }
bool IsTickCommand(AnkhCommand c) { if (c < AnkhCommand.TickFirst || c >= AnkhCommand.TickLast) return false; return true; }
static bool IsFolderCommand(AnkhCommand command) { switch (command) { case AnkhCommand.FolderUpdateLatest: case AnkhCommand.FolderUpdateSpecific: return true; default: return false; } }
public CommandResult DirectlyExecCommand(AnkhCommand command, object args, CommandPrompt prompt) { // TODO: Assert that we are in the UI thread CommandMapper mapper = GetService<CommandMapper>(); if (mapper == null) return new CommandResult(false, null); CommandEventArgs e = new CommandEventArgs(command, AnkhContext, args, prompt == CommandPrompt.Always, prompt == CommandPrompt.Never); bool ok = mapper.Execute(command, e); return new CommandResult(ok, e.Result); }
public CommandResult ExecCommand(AnkhCommand command, bool verifyEnabled) { // The commandhandler in the package always checks enabled; no need to do it here return(ExecCommand(new CommandID(AnkhId.CommandSetGuid, (int)command), verifyEnabled)); }
public bool PerformUpdate(AnkhCommand command, CommandUpdateEventArgs e) { EnsureLoaded(); CommandMapItem item; if (_map.TryGetValue(command, out item)) { bool skip; if ((item.Availability & CommandAvailability.AlwaysFlag) != 0) { skip = false; } else if (((item.Availability & CommandAvailability.SvnActive) != 0) && States.SccProviderActive) { skip = false; } else if (((item.Availability & CommandAvailability.GitActive) != 0) && States.GitSccProviderActive) { skip = false; } else { skip = true; } if (skip) { e.Enabled = false; } else { try { e.Prepare(item); item.OnUpdate(e); } catch (Exception ex) { IAnkhErrorHandler eh = GetService <IAnkhErrorHandler>(); if (eh != null && eh.IsEnabled(ex)) { eh.OnError(ex, e); return(false); } throw; } } if (item.HiddenWhenDisabled && !e.Enabled) { e.Visible = false; } if (item.DynamicMenuEnd) { e.DynamicMenuEnd = true; } return(item.IsHandled); } else if (_defined.Contains(command)) { e.Enabled = e.Visible = false; return(true); } return(false); }
internal void HandleEvent(AnkhCommand command) { List <SccProject> dirtyProjects; HybridCollection <string> dirtyCheck; HybridCollection <string> maybeAdd; SvnSccProvider provider = GetService <SvnSccProvider>(); lock (_lock) { _posted = false; _onIdle = false; if (provider == null) { return; } dirtyProjects = _dirtyProjects; dirtyCheck = _dirtyCheck; maybeAdd = _maybeAdd; _dirtyProjects = null; _dirtyCheck = null; _maybeAdd = null; } if (dirtyCheck != null) { foreach (string file in dirtyCheck) { DocumentTracker.CheckDirty(file); } } if (dirtyProjects != null) { foreach (SccProject project in dirtyProjects) { if (project.IsSolution) { provider.UpdateSolutionGlyph(); } else { project.NotifyGlyphChanged(); } } } if (maybeAdd != null) { using (SvnClient cl = GetService <ISvnClientPool>().GetNoUIClient()) { foreach (string file in maybeAdd) { SvnItem item = SvnCache[file]; // Only add // * files // * that are unversioned // * that are addable // * that are not ignored // * and just to be sure: that are still part of the solution if (item.IsFile && !item.IsVersioned && item.IsVersionable && !item.IsIgnored && item.InSolution && !item.IsSccExcluded) { SvnAddArgs aa = new SvnAddArgs(); aa.ThrowOnError = false; // Just ignore errors here; make the user add them themselves aa.AddParents = true; if (cl.Add(item.FullPath, aa)) { item.MarkDirty(); // Detect if we have a file that Subversion might detect as binary if (item.IsVersioned && !item.IsTextFile) { // Only check small files, avoid checking big binary files FileInfo fi = new FileInfo(item.FullPath); if (fi.Length < 10) { // We're sure it's at most 10 bytes here, so just read all byte[] fileBytes = File.ReadAllBytes(item.FullPath); // If the file starts with a UTF8 BOM, we're sure enough it's a text file, keep UTF16 & 32 binary if (StartsWith(fileBytes, new byte[] { 0xEF, 0xBB, 0xBF })) { // Delete the mime type property, so it's detected as a text file again SvnSetPropertyArgs pa = new SvnSetPropertyArgs(); pa.ThrowOnError = false; cl.DeleteProperty(item.FullPath, SvnPropertyNames.SvnMimeType, pa); } } } } } } } } }
public CommandResult ExecCommand(AnkhCommand command) { // The commandhandler in the package always checks enabled; no need to do it here return ExecCommand(command, false); }
public CommandEventArgs(AnkhCommand command, AnkhContext context) : base(command, context) { }
static bool IsSolutionCommand(AnkhCommand command) { switch (command) { case AnkhCommand.SolutionUpdateLatest: case AnkhCommand.SolutionUpdateSpecific: case AnkhCommand.PendingChangesUpdateLatest: return true; default: return false; } }
public static bool TestExecution(AnkhCommand commandEnum, object argument) { AnkhRuntime runtime = new AnkhRuntime(ServiceProviderHelper.serviceProvider); runtime.AddModule(new AnkhModule(runtime)); runtime.Start(); return runtime.CommandMapper.Execute(commandEnum, new CommandEventArgs(commandEnum, runtime.Context, argument, false, false)); }
public bool PostExecCommand(AnkhCommand command) { return(PostExecCommand(command, null, CommandPrompt.DoDefault)); }
internal void HandleEvent(AnkhCommand command) { List<SvnProject> dirtyProjects; HybridCollection<string> dirtyCheck; HybridCollection<string> maybeAdd; AnkhSccProvider provider = Context.GetService<AnkhSccProvider>(); lock (_lock) { _posted = false; _onIdle = false; if (provider == null) return; dirtyProjects = _dirtyProjects; dirtyCheck = _dirtyCheck; maybeAdd = _maybeAdd; _dirtyProjects = null; _dirtyCheck = null; _maybeAdd = null; } if (dirtyCheck != null) foreach (string file in dirtyCheck) { DocumentTracker.CheckDirty(file); } if (dirtyProjects != null) { foreach (SvnProject project in dirtyProjects) { if (project.RawHandle == null) { if (project.IsSolution) provider.UpdateSolutionGlyph(); continue; // All IVsSccProjects have a RawHandle } try { project.RawHandle.SccGlyphChanged(0, null, null, null); } catch { } } } if (maybeAdd != null) using (SvnClient cl = GetService<ISvnClientPool>().GetNoUIClient()) { foreach (string file in maybeAdd) { SvnItem item = Cache[file]; // Only add // * files // * that are unversioned // * that are addable // * that are not ignored // * and just to be sure: that are still part of the solution if (item.IsFile && !item.IsVersioned && item.IsVersionable && !item.IsIgnored && item.InSolution) { SvnAddArgs aa = new SvnAddArgs(); aa.ThrowOnError = false; // Just ignore errors here; make the user add them themselves aa.AddParents = true; cl.Add(item.FullPath, aa); } } } }
public bool PostExecCommand(AnkhCommand command, object args) { return(PostExecCommand(command, args, CommandPrompt.DoDefault)); }
public int Schedule(TimeSpan timeSpan, AnkhCommand command) { return ScheduleAt(DateTime.Now + timeSpan, CreateHandler(command)); }
public bool PostExecCommand(AnkhCommand command, object args, CommandPrompt prompt) { return(PostExecCommand(new CommandID(AnkhId.CommandSetGuid, (int)command), args, prompt)); }
/// <summary> /// Initializes a new instance of the <see cref="CommandMapItem"/> class. /// </summary> /// <param name="command">The command.</param> public CommandMapItem(AnkhCommand command) { _command = command; }
public CommandResult DirectlyExecCommand(AnkhCommand command) { return(DirectlyExecCommand(command, null, CommandPrompt.DoDefault)); }
public bool PerformUpdate(AnkhCommand command, CommandUpdateEventArgs e) { EnsureLoaded(); CommandMapItem item; if (_map.TryGetValue(command, out item)) { if (!item.AlwaysAvailable && !e.State.SccProviderActive) e.Enabled = false; else try { e.Prepare(item); item.OnUpdate(e); } catch (Exception ex) { IAnkhErrorHandler eh = GetService<IAnkhErrorHandler>(); if (eh != null && eh.IsEnabled(ex)) { eh.OnError(ex, e); return false; } throw; } if (item.HiddenWhenDisabled && !e.Enabled) e.Visible = false; if (item.DynamicMenuEnd) e.DynamicMenuEnd = true; return item.IsHandled; } else if (_defined.Contains(command)) { e.Enabled = e.Visible = false; return true; } return false; }
public CommandResult DirectlyExecCommand(AnkhCommand command, object args) { return(DirectlyExecCommand(command, args, CommandPrompt.DoDefault)); }
/// <summary> /// Gets the <see cref="CommandMapItem"/> for the specified command /// </summary> /// <param name="command"></param> /// <returns>The <see cref="CommandMapItem"/> or null if the command is not valid</returns> public CommandMapItem this[AnkhCommand command] { get { CommandMapItem item; if (_map.TryGetValue(command, out item)) return item; else { item = new CommandMapItem(command); _map.Add(command, item); return item; } } }
/// <summary> /// Installs a visual studio command handler for the specified control /// </summary> /// <param name="context">The context.</param> /// <param name="control">The control.</param> /// <param name="command">The command.</param> /// <param name="handler">The handler.</param> public static void Install(IAnkhServiceProvider context, Control control, AnkhCommand command, EventHandler <CommandEventArgs> handler) { Install(context, control, command, handler, null); }