Skip to content

Commit

Permalink
Add action for opening settings directory in file explorer (#17690)
Browse files Browse the repository at this point in the history
Most of the logic is taken from the original PR (#15417) and adapted to work with the palette.

## References and Relevant Issues
[#12382](#12382)
  • Loading branch information
e82eric authored Dec 5, 2024
1 parent 7cdf9ee commit 3d052bf
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3175,6 +3175,14 @@ namespace winrt::TerminalApp::implementation
}
};

auto openFolder = [](const auto& filePath) {
HINSTANCE res = ShellExecute(nullptr, nullptr, filePath.c_str(), nullptr, nullptr, SW_SHOW);
if (static_cast<int>(reinterpret_cast<uintptr_t>(res)) <= 32)
{
ShellExecute(nullptr, nullptr, L"open", filePath.c_str(), nullptr, SW_SHOW);
}
};

switch (target)
{
case SettingsTarget::DefaultsFile:
Expand All @@ -3183,6 +3191,9 @@ namespace winrt::TerminalApp::implementation
case SettingsTarget::SettingsFile:
openFile(CascadiaSettings::SettingsPath());
break;
case SettingsTarget::Directory:
openFolder(CascadiaSettings::SettingsDirectory());
break;
case SettingsTarget::AllFiles:
openFile(CascadiaSettings::DefaultSettingsPath());
openFile(CascadiaSettings::SettingsPath());
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalSettingsModel/ActionArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
return RS_(L"OpenBothSettingsFilesCommandKey");
case SettingsTarget::SettingsFile:
return RS_(L"OpenSettingsCommandKey");
case SettingsTarget::Directory:
return RS_(L"SettingsFileOpenInExplorerCommandKey");
case SettingsTarget::SettingsUI:
default:
return RS_(L"OpenSettingsUICommandKey");
Expand Down
3 changes: 2 additions & 1 deletion src/cascadia/TerminalSettingsModel/ActionArgs.idl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ namespace Microsoft.Terminal.Settings.Model
SettingsFile = 0,
DefaultsFile,
AllFiles,
SettingsUI
SettingsUI,
Directory
};

enum MoveTabDirection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@
<value>Open settings file (JSON)</value>
<comment>{Locked="JSON"}. "JSON" is the extension of the file that will be opened.</comment>
</data>
<data name="SettingsFileOpenInExplorerCommandKey" xml:space="preserve">
<value>Open the settings file directory</value>
</data>
<data name="OpenTabColorPickerCommandKey" xml:space="preserve">
<value>Set tab color...</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,12 @@ JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Settings::Model::SplitType)

JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Settings::Model::SettingsTarget)
{
JSON_MAPPINGS(4) = {
JSON_MAPPINGS(5) = {
pair_type{ "settingsFile", ValueType::SettingsFile },
pair_type{ "defaultsFile", ValueType::DefaultsFile },
pair_type{ "allFiles", ValueType::AllFiles },
pair_type{ "settingsUI", ValueType::SettingsUI },
pair_type{ "directory", ValueType::Directory }
};
};

Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@
{ "command": { "action": "openSettings", "target": "settingsUI" }, "id": "Terminal.OpenSettingsUI" },
{ "command": { "action": "openSettings", "target": "settingsFile" }, "id": "Terminal.OpenSettingsFile" },
{ "command": { "action": "openSettings", "target": "defaultsFile" }, "id": "Terminal.OpenDefaultSettingsFile" },
{ "command": { "action": "openSettings", "target": "directory" }, "id": "Terminal.OpenSettingsDirectory" },
{ "command": "find", "id": "Terminal.FindText" },
{ "command": { "action": "findMatch", "direction": "next" }, "id": "Terminal.FindNextMatch" },
{ "command": { "action": "findMatch", "direction": "prev" }, "id": "Terminal.FindPrevMatch" },
Expand Down

0 comments on commit 3d052bf

Please sign in to comment.