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

settings.json parent folder functionality #15417

Closed
wants to merge 2 commits 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
11 changes: 11 additions & 0 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2817,6 +2817,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 @@ -2829,6 +2837,9 @@ namespace winrt::TerminalApp::implementation
openFile(CascadiaSettings::DefaultSettingsPath());
openFile(CascadiaSettings::SettingsPath());
break;
case SettingsTarget::SettingsFolder:
openFolder(CascadiaSettings::SettingsFolderPath());
break;
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/cascadia/TerminalSettingsEditor/MainPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
Automation::AutomationProperties::SetHelpText(SaveButton(), RS_(L"Settings_SaveSettingsButton/[using:Windows.UI.Xaml.Controls]ToolTipService/ToolTip"));
Automation::AutomationProperties::SetHelpText(ResetButton(), RS_(L"Settings_ResetSettingsButton/[using:Windows.UI.Xaml.Controls]ToolTipService/ToolTip"));
Automation::AutomationProperties::SetHelpText(OpenJsonNavItem(), RS_(L"Nav_OpenJSON/[using:Windows.UI.Xaml.Controls]ToolTipService/ToolTip"));
Automation::AutomationProperties::SetHelpText(OpenJsonFolderNavItem(), RS_(L"Nav_OpenJSONFolder/[using:Windows.UI.Xaml.Controls]ToolTipService/ToolTip"));

_breadcrumbs = single_threaded_observable_vector<IInspectable>();
}
Expand Down Expand Up @@ -472,6 +473,11 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
}
}

void MainPage::OpenJsonFolderClicked(const Windows::Foundation::IInspectable& /*sender*/, const Windows::UI::Xaml::RoutedEventArgs& /*args*/)
{
const auto target = SettingsTarget::SettingsFolder;
_OpenJsonHandlers(nullptr, target);
}
void MainPage::SaveButton_Click(const IInspectable& /*sender*/, const RoutedEventArgs& /*args*/)
{
_settingsClone.WriteSettingsToDisk();
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsEditor/MainPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation

void OpenJsonKeyDown(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::Input::KeyRoutedEventArgs& args);
void OpenJsonTapped(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::Input::TappedRoutedEventArgs& args);
void OpenJsonFolderClicked(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& args);
void SettingsNav_Loaded(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& args);
void SettingsNav_ItemInvoked(const Microsoft::UI::Xaml::Controls::NavigationView& sender, const Microsoft::UI::Xaml::Controls::NavigationViewItemInvokedEventArgs& args);
void SaveButton_Click(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& args);
Expand Down
7 changes: 7 additions & 0 deletions src/cascadia/TerminalSettingsEditor/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@
<muxc:NavigationViewItem.Icon>
<FontIcon Glyph="&#xE713;" />
</muxc:NavigationViewItem.Icon>
<muxc:NavigationViewItem.ContextFlyout>
<MenuFlyout>
<MenuFlyoutItem x:Name="OpenJsonFolderNavItem"
x:Uid="Nav_OpenJSONFolder"
Click="OpenJsonFolderClicked" />
</MenuFlyout>
</muxc:NavigationViewItem.ContextFlyout>
</muxc:NavigationViewItem>
</muxc:NavigationView.FooterMenuItems>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,10 @@
<data name="Nav_OpenJSON.Content" xml:space="preserve">
<value>Open JSON file</value>
<comment>Header for a menu item. This opens the JSON file that is used to log the app's settings.</comment>
</data>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, make sure you use spaces here, not tabs.

If you want, you can also edit this file in Visual Studio. It gives you a table to work with, and always formats it correctly.

<data name="Nav_OpenJSONFolder.Content" xml:space="preserve">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<data name="Nav_OpenJSONFolder.Content" xml:space="preserve">
<data name="Nav_OpenJSONFolder.Text" xml:space="preserve">

Found the bug! This'll fix the crash!

<value>Open JSON Folder</value>
<comment>Header for a menu item. This opens the JSON Folder where the JSON file that is used to log the app's settings sits.</comment>
</data>
<data name="Nav_ProfileDefaults.Content" xml:space="preserve">
<value>Defaults</value>
Expand Down Expand Up @@ -1304,6 +1308,10 @@
<data name="Nav_OpenJSON.[using:Windows.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve">
<value>Open your settings.json file. Alt+Click to open your defaults.json file.</value>
<comment>{Locked="settings.json"}, {Locked="defaults.json"}</comment>
</data>
<data name="Nav_OpenJSONFolder.[using:Windows.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve">
<value>Open your settings.json folder.</value>
<comment>Label for button to JSON Folder.</comment>
</data>
<data name="Rename.[using:Windows.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve">
<value>Rename</value>
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,
SettingsFolder
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Related to this PR, but not necessary to make this change in this PR) IMO, at this point, we should fully commit and also add this as a parameter to the openSettings action. If you're interested in doing that, I think you'd mainly have to update...

  • ActionArgs.cpp OpenSettingsArgs::GenerateName()
  • TerminalSettingsSerializationHelpers.h JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Settings::Model::SettingsTarget)
  • Resources.resw in the TerminalSettingsModel project (this is where you update the resource key for GenerateName())

Since you already updated TerminalPage::_LaunchSettings(), this should just work outright!

If you're not interested though, let me know. Happy to do it as a follow up myself :)

};

enum MoveTabDirection
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/CascadiaSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
static Model::CascadiaSettings LoadDefaults();
static Model::CascadiaSettings LoadAll();

static winrt::hstring SettingsFolderPath();
static winrt::hstring SettingsPath();
static winrt::hstring DefaultSettingsPath();
static winrt::hstring ApplicationDisplayName();
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/CascadiaSettings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Microsoft.Terminal.Settings.Model
static CascadiaSettings LoadDefaults();
static CascadiaSettings LoadAll();

static String SettingsFolderPath { get; };
static String SettingsPath { get; };
static String DefaultSettingsPath { get; };
static Boolean IsPortableMode { get; };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,17 @@ winrt::hstring CascadiaSettings::SettingsPath()
return winrt::hstring{ _settingsPath().native() };
}

// function Description:
// Returns the full path where the settings.json file is located
// Arguments:
// - <none>
// Return Value:
// full path to settings folder
winrt::hstring CascadiaSettings::SettingsFolderPath()
{
return winrt::hstring{ GetBaseSettingsPath().native() };
}

bool CascadiaSettings::IsPortableMode()
{
return Model::IsPortableMode();
Expand Down