Skip to content

Commit

Permalink
Update Terminal Handling code to explicitly change path to the target…
Browse files Browse the repository at this point in the history
… folder before launching the Terminal or Shell. This allows the new Windows Terminal to be used, but only if customizing the profile. More info: https://weblog.west-wind.com/posts/2019/Sep/03/Programmatically-Opening-Windows-Terminal-in-a-Specific-Folder
  • Loading branch information
RickStrahl committed Sep 4, 2019
1 parent 26ef4fd commit a92c389
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 16 deletions.
8 changes: 7 additions & 1 deletion MarkdownMonster/_Classes/Commands/AppCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2181,7 +2181,13 @@ void ViewInExternalBrowser()
// EXTERNAL BROWSER VIEW
ViewInExternalBrowserCommand = new CommandBase((p, e) =>
{
if (Model.ActiveDocument == null) return;
if (Model.ActiveEditor?.MarkdownDocument == null)
{
if(!string.IsNullOrEmpty(Model.ActiveTabFilename))
mmFileUtils.ShowExternalBrowser(Model.ActiveTabFilename);

return;
}

Model.ActiveDocument.RenderHtmlToFile();
mmFileUtils.ShowExternalBrowser(Model.ActiveDocument.HtmlRenderFilename);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,14 @@ public bool AlwaysUsePreviewRefresh
/// </summary>
public string OpenFolderCommand { get; set; }

/// <summary>
/// Command Processing Executable to bring up a terminal window
/// Command or Powershell, but could also be Console or ConEmu
/// cmd.exe /k \"cd {0}\"
/// powershell.exe -NoExit -Command "&amp; cd 'c:\program files'"
/// </summary>
public string TerminalCommand { get; set; }
/// <summary>
/// Command Processing Executable to bring up a terminal window
/// Command or Powershell, but could also be Console or ConEmu
/// cmd.exe /k \"cd {0}\"
/// powershell.exe -NoExit -Command "&amp; cd 'c:\program files'"
/// wt.exe (leave blank) &amp; set Profile "startingDirectory" : "%__CD__%",
/// </summary>
public string TerminalCommand { get; set; }

/// <summary>
/// Terminal executable arguments to pass to bring up terminal
Expand Down
29 changes: 21 additions & 8 deletions MarkdownMonster/_Classes/Utilities/mmFileUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,14 @@ public static bool OpenTerminal(string folder)
{
try
{
Process.Start(mmApp.Configuration.TerminalCommand,
string.Format(mmApp.Configuration.TerminalCommandArgs, folder));
var pi = new ProcessStartInfo
{
FileName = mmApp.Configuration.TerminalCommand,
Arguments = string.Format(mmApp.Configuration.TerminalCommandArgs, folder),
WorkingDirectory = folder,
UseShellExecute = false
};
Process.Start(pi);
}
catch
{
Expand All @@ -475,15 +481,22 @@ public static bool OpenTerminal(string folder)
/// <param name="url"></param>
public static void ShowExternalBrowser(string url)
{
if (string.IsNullOrEmpty(mmApp.Configuration.WebBrowserPreviewExecutable) ||
!File.Exists(mmApp.Configuration.WebBrowserPreviewExecutable))
try
{
mmApp.Configuration.WebBrowserPreviewExecutable = null;
ShellUtils.GoUrl(url);
if (string.IsNullOrEmpty(mmApp.Configuration.WebBrowserPreviewExecutable) ||
!File.Exists(mmApp.Configuration.WebBrowserPreviewExecutable))
{
mmApp.Configuration.WebBrowserPreviewExecutable = null;
ShellUtils.GoUrl(url);
}
else
{
ShellUtils.ExecuteProcess(mmApp.Configuration.WebBrowserPreviewExecutable, $"\"{url}\"");
}
}
else
catch (Exception ex)
{
ShellUtils.ExecuteProcess(mmApp.Configuration.WebBrowserPreviewExecutable, $"\"{url}\"");
mmApp.Log($"External Preview failed: {url}", ex, logLevel: LogLevels.Warning);
}
}

Expand Down
Binary file modified SupportAssemblies/Westwind.TypeImporter.dll
Binary file not shown.

0 comments on commit a92c389

Please sign in to comment.