Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for 'Command' #161 #162

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion SmartCmdArgs/SharedResources/CmdArgsPackage.vsct
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,12 @@
<ButtonText>Add Working Directory</ButtonText>
</Strings>
</Button>

<Button guid="guidCmdArgsToolBarCmdSet" id="ToolbarAddLaunchAppId" priority="0x0100" type="Button">
<Parent guid="guidCmdArgsToolBarCmdSet" id="TWToolbarGroupAdd" />
<Strings>
<ButtonText>Add Launch Application</ButtonText>
</Strings>
</Button>
<Button guid="guidCmdArgsToolBarCmdSet" id="ToolbarAddGroupCommandId" priority="0x0102" type="Button">
<Parent guid="guidCmdArgsToolBarCmdSet" id="TWToolbarGroupAddRemove" />
<Icon guid="ImageCatalogGuid" id="AddFolder" />
Expand Down Expand Up @@ -256,6 +261,7 @@
<IDSymbol name="ToolbarCopyEnvVarsForPSCommandId" value="0x1109"/>
<IDSymbol name="ToolbarCopyEnvVarsForCMDCommandId" value="0x110A"/>
<IDSymbol name="ToolbarAddWorkDirId" value="0x110B"/>
<IDSymbol name="ToolbarAddLaunchAppId" value="0x110C"/>

<IDSymbol name="TWToolbar" value="0x1000" />
<IDSymbol name="TWToolbarGroupAddRemove" value="0x1050" />
Expand Down
11 changes: 11 additions & 0 deletions SmartCmdArgs/SmartCmdArgs.Shared/CmdArgsOptionPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public CmdArgsOptionPage() : base()

private bool _manageCommandLineArgs;
private bool _manageEnvironmentVars;
private bool _manageLaunchApplication;
private bool _vcsSupportEnabled;
private bool _useSolutionDir;
private bool _macroEvaluationEnabled;
Expand Down Expand Up @@ -147,6 +148,16 @@ public bool ManageWorkingDirectories
set => SetAndNotify(value, ref _manageEnvironmentVars);
}

[Category("Settings Defaults")]
[DisplayName("Manage Launch Application")]
[Description("If enabled the launch application is set automatically when a project is started/debugged.")]
[DefaultValue(false)]
public bool ManageLaunchApplication
{
get => _manageLaunchApplication;
set => SetAndNotify(value, ref _manageLaunchApplication);
}

[Category("Settings Defaults")]
[DisplayName("Enable version control support")]
[Description("If enabled the extension will store the command line arguments into an json file at the same loctation as the related project file. That way the command line arguments might be version controlled by a VCS. If disabled the extension will store everything inside the solutions .suo-file which is usally ignored by version control. The default value for this setting is True.")]
Expand Down
34 changes: 31 additions & 3 deletions SmartCmdArgs/SmartCmdArgs.Shared/CmdArgsPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public sealed class CmdArgsPackage : AsyncPackage
public bool ManageCommandLineArgs => Settings.ManageCommandLineArgs ?? Options.ManageCommandLineArgs;
public bool ManageEnvironmentVars => Settings.ManageEnvironmentVars ?? Options.ManageEnvironmentVars;
public bool ManageWorkingDirectories => Settings.ManageWorkingDirectories ?? Options.ManageWorkingDirectories;
public bool ManageLaunchApplication => Settings.ManageLaunchApplication ?? Options.ManageLaunchApplication;
public bool UseCustomJsonRoot => Settings.UseCustomJsonRoot;
public string JsonRootPath => Settings.JsonRootPath;
public bool IsVcsSupportEnabled => Settings.VcsSupportEnabled ?? Options.VcsSupportEnabled;
Expand Down Expand Up @@ -163,14 +164,15 @@ private bool TryParseEnvVar(string str, out EnvVar envVar)
#region IsActive Management for Items
private ISet<CmdArgument> GetAllActiveItemsForProject(IVsHierarchy project)
{
if (!ManageCommandLineArgs && !ManageEnvironmentVars && !ManageWorkingDirectories)
if (!ManageCommandLineArgs && !ManageEnvironmentVars && !ManageWorkingDirectories && !ManageLaunchApplication)
{
return new HashSet<CmdArgument>();
}

var Args = new HashSet<CmdArgument>();
var EnvVars = new Dictionary<string, CmdArgument>();
CmdArgument workDir = null;
CmdArgument launchApp = null;

foreach (var item in GetAllComamndLineItemsForProject(project))
{
Expand All @@ -189,6 +191,10 @@ private ISet<CmdArgument> GetAllActiveItemsForProject(IVsHierarchy project)
{
workDir = item;
}
else if (item.ArgumentType == ArgumentType.LaunchApp && ManageLaunchApplication)
{
launchApp = item;
}
}

var result = new HashSet<CmdArgument>(Args.Concat(EnvVars.Values));
Expand All @@ -198,6 +204,11 @@ private ISet<CmdArgument> GetAllActiveItemsForProject(IVsHierarchy project)
result.Add(workDir);
}

if (launchApp != null)
{
result.Add(launchApp);
}

return result;
}

Expand Down Expand Up @@ -313,6 +324,7 @@ private void CmdArgsOptionPage_PropertyChanged(object sender, System.ComponentMo
case nameof(CmdArgsOptionPage.ManageCommandLineArgs): UpdateIsActiveForArgumentsDebounced(); break;
case nameof(CmdArgsOptionPage.ManageEnvironmentVars): UpdateIsActiveForArgumentsDebounced(); break;
case nameof(CmdArgsOptionPage.ManageWorkingDirectories): UpdateIsActiveForArgumentsDebounced(); break;
case nameof(CmdArgsOptionPage.ManageLaunchApplication): UpdateIsActiveForArgumentsDebounced(); break;
}
}

Expand All @@ -331,6 +343,7 @@ private void SettingsViewModel_PropertyChanged(object sender, System.ComponentMo
case nameof(SettingsViewModel.ManageCommandLineArgs): UpdateIsActiveForArgumentsDebounced(); break;
case nameof(SettingsViewModel.ManageEnvironmentVars): UpdateIsActiveForArgumentsDebounced(); break;
case nameof(SettingsViewModel.ManageWorkingDirectories): UpdateIsActiveForArgumentsDebounced(); break;
case nameof(SettingsViewModel.ManageLaunchApplication): UpdateIsActiveForArgumentsDebounced(); break;
}
}

Expand Down Expand Up @@ -418,11 +431,12 @@ private void UpdateConfigurationForProject(IVsHierarchy project)
var commandLineArgs = ManageCommandLineArgs ? CreateCommandLineArgsForProject(project) : null;
var envVars = ManageEnvironmentVars ? GetEnvVarsForProject(project) : null;
var workDir = ManageWorkingDirectories ? GetWorkDirForProject(project) : null;
var launchApp = ManageLaunchApplication ? GetLaunchAppForProject(project) : null;

if (commandLineArgs is null && envVars is null && workDir is null)
if (commandLineArgs is null && envVars is null && workDir is null && launchApp is null)
return;

ProjectConfigHelper.SetConfig(project, commandLineArgs, envVars, workDir);
ProjectConfigHelper.SetConfig(project, commandLineArgs, envVars, workDir, launchApp);
Logger.Info($"Updated Configuration for Project: {project.GetName()}");
}

Expand Down Expand Up @@ -602,6 +616,20 @@ private string GetWorkDirForProject(IVsHierarchy project)
return result;
}

private string GetLaunchAppForProject(IVsHierarchy project)
{
var result = "";

foreach (var item in GetAllComamndLineItemsForProject(project))
{
if (item.ArgumentType != ArgumentType.LaunchApp) continue;

result = EvaluateMacros(item.Value, project);
}

return result;
}

public string CreateCommandLineArgsForProject(Guid guid)
{
return CreateCommandLineArgsForProject(vsHelper.HierarchyForProjectGuid(guid));
Expand Down
2 changes: 2 additions & 0 deletions SmartCmdArgs/SmartCmdArgs.Shared/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ internal sealed class Commands
public const int ToolbarCopyEnvVarsForPSCommandId = 0x1109;
public const int ToolbarCopyEnvVarsForCMDCommandId = 0x110A;
public const int ToolbarAddWorkDirId = 0x110B;
public const int ToolbarAddLaunchAppId = 0x110C;

public static readonly Guid KeyBindingsCmdSet = new Guid("886F463E-7F96-4BA4-BA88-F36D63044A00");

Expand Down Expand Up @@ -89,6 +90,7 @@ private Commands(CmdArgsPackage package, OleMenuCommandService commandService)
AddCommandToService(commandService, CmdArgsToolBarCmdSet, ToolbarAddCommandId, package.ToolWindowViewModel.AddEntryCommand, ViewModel.ArgumentType.CmdArg);
AddCommandToService(commandService, CmdArgsToolBarCmdSet, ToolbarAddEnvVarId, package.ToolWindowViewModel.AddEntryCommand, ViewModel.ArgumentType.EnvVar);
AddCommandToService(commandService, CmdArgsToolBarCmdSet, ToolbarAddWorkDirId, package.ToolWindowViewModel.AddEntryCommand, ViewModel.ArgumentType.WorkDir);
AddCommandToService(commandService, CmdArgsToolBarCmdSet, ToolbarAddLaunchAppId, package.ToolWindowViewModel.AddEntryCommand, ViewModel.ArgumentType.LaunchApp);
AddCommandToService(commandService, CmdArgsToolBarCmdSet, ToolbarAddGroupCommandId, package.ToolWindowViewModel.AddGroupCommand);
AddCommandToService(commandService, CmdArgsToolBarCmdSet, ToolbarRemoveCommandId, package.ToolWindowViewModel.RemoveEntriesCommand);
AddCommandToService(commandService, CmdArgsToolBarCmdSet, ToolbarMoveUpCommandId, package.ToolWindowViewModel.MoveEntriesUpCommand);
Expand Down
11 changes: 10 additions & 1 deletion SmartCmdArgs/SmartCmdArgs.Shared/Helper/CpsProjectSupport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static IDisposable ListenToLaunchProfileChanges(EnvDTE.Project project, A
return null;
}

public static void SetCpsProjectConfig(EnvDTE.Project project, string arguments, IDictionary<string, string> envVars, string workDir)
public static void SetCpsProjectConfig(EnvDTE.Project project, string arguments, IDictionary<string, string> envVars, string workDir, string launchApp)
{
IUnconfiguredProjectServices unconfiguredProjectServices;
IProjectServices projectServices;
Expand All @@ -108,6 +108,9 @@ public static void SetCpsProjectConfig(EnvDTE.Project project, string arguments,
if (workDir != null)
writableLaunchProfile.WorkingDirectory = workDir;

if (launchApp != null)
writableLaunchProfile.CommandName = launchApp;

// Does not work on VS2015, which should be okay ...
// We don't hold references for VS2015, where the interface is called IThreadHandling
IProjectThreadingService projectThreadingService = projectServices.ThreadingPolicy;
Expand Down Expand Up @@ -152,6 +155,11 @@ public static List<CmdArgumentJson> GetCpsProjectAllArguments(EnvDTE.Project pro
profileGrp.Items.Add(new CmdArgumentJson { Type = ViewModel.ArgumentType.WorkDir, Command = profile.WorkingDirectory, Enabled = true });
}

if (!string.IsNullOrEmpty(profile.CommandName))
{
profileGrp.Items.Add(new CmdArgumentJson { Type = ViewModel.ArgumentType.LaunchApp, Command = profile.CommandName, Enabled = true });
}

if (profileGrp.Items.Count > 0)
{
result.Add(profileGrp);
Expand All @@ -170,6 +178,7 @@ class WritableLaunchProfile : ILaunchProfile
public string ExecutablePath { set; get; }
public string CommandLineArgs { set; get; }
public string WorkingDirectory { set; get; }
public string LaunchApp { set; get; }
public bool LaunchBrowser { set; get; }
public string LaunchUrl { set; get; }
public ImmutableDictionary<string, string> EnvironmentVariables { set; get; }
Expand Down
Loading