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

Implement UI for choosing default terminal inside Settings page #9907

Merged
18 commits merged into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 3 additions & 0 deletions src/cascadia/CascadiaPackage/Package-Dev.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
xmlns:desktop4="http://schemas.microsoft.com/appx/manifest/desktop/windows10/4"
xmlns:desktop5="http://schemas.microsoft.com/appx/manifest/desktop/windows10/5"
xmlns:desktop6="http://schemas.microsoft.com/appx/manifest/desktop/windows10/6"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
xmlns:uap5="http://schemas.microsoft.com/appx/manifest/uap/windows10/5"
IgnorableNamespaces="uap mp rescap uap3">
Expand All @@ -23,6 +24,7 @@
<DisplayName>Windows Terminal Dev</DisplayName>
<PublisherDisplayName>A Lone Developer</PublisherDisplayName>
<Logo>Images\StoreLogo.png</Logo>
<desktop6:RegistryWriteVirtualization>disabled</desktop6:RegistryWriteVirtualization>
</Properties>

<Dependencies>
Expand Down Expand Up @@ -134,5 +136,6 @@
<Capabilities>
<Capability Name="internetClient" />
<rescap:Capability Name="runFullTrust" />
<rescap:Capability Name="unvirtualizedResources" />
</Capabilities>
</Package>
3 changes: 3 additions & 0 deletions src/cascadia/CascadiaPackage/Package-Pre.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
xmlns:desktop4="http://schemas.microsoft.com/appx/manifest/desktop/windows10/4"
xmlns:desktop5="http://schemas.microsoft.com/appx/manifest/desktop/windows10/5"
xmlns:desktop6="http://schemas.microsoft.com/appx/manifest/desktop/windows10/6"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap mp rescap uap3">

Expand All @@ -24,6 +25,7 @@
<DisplayName>Windows Terminal Preview</DisplayName>
<PublisherDisplayName>Microsoft Corporation</PublisherDisplayName>
<Logo>Images\StoreLogo.png</Logo>
<desktop6:RegistryWriteVirtualization>disabled</desktop6:RegistryWriteVirtualization>
</Properties>

<Dependencies>
Expand Down Expand Up @@ -135,6 +137,7 @@
<Capabilities>
<Capability Name="internetClient" />
<rescap:Capability Name="runFullTrust" />
<rescap:Capability Name="unvirtualizedResources" />
</Capabilities>

<Extensions>
Expand Down
3 changes: 3 additions & 0 deletions src/cascadia/CascadiaPackage/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
xmlns:desktop4="http://schemas.microsoft.com/appx/manifest/desktop/windows10/4"
xmlns:desktop5="http://schemas.microsoft.com/appx/manifest/desktop/windows10/5"
xmlns:desktop6="http://schemas.microsoft.com/appx/manifest/desktop/windows10/6"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap mp rescap uap3">

Expand All @@ -24,6 +25,7 @@
<DisplayName>Windows Terminal</DisplayName>
<PublisherDisplayName>Microsoft Corporation</PublisherDisplayName>
<Logo>Images\StoreLogo.png</Logo>
<desktop6:RegistryWriteVirtualization>disabled</desktop6:RegistryWriteVirtualization>
</Properties>

<Dependencies>
Expand Down Expand Up @@ -135,6 +137,7 @@
<Capabilities>
<Capability Name="internetClient" />
<rescap:Capability Name="runFullTrust" />
<rescap:Capability Name="unvirtualizedResources" />
</Capabilities>

<Extensions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<ItemGroup>
<ProjectReference Include="$(OpenConsoleDir)\src\cascadia\TerminalSettingsModel\Microsoft.Terminal.Settings.ModelLib.vcxproj" />
<ProjectReference Include="$(OpenConsoleDir)\src\types\lib\types.vcxproj" />
<ProjectReference Include="$(OpenConsoleDir)src\propslib\propslib.vcxproj" />
miniksa marked this conversation as resolved.
Show resolved Hide resolved

<!-- If you don't reference these projects here, the
_ConsoleGenerateAdditionalWinmdManifests step won't gather the winmd's -->
Expand Down
18 changes: 1 addition & 17 deletions src/cascadia/TerminalSettingsEditor/Launch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
void Launch::OnNavigatedTo(const NavigationEventArgs& e)
{
_State = e.Parameter().as<Editor::LaunchPageNavigationState>();
_State.Settings().RefreshDefaultTerminals();
}

IInspectable Launch::CurrentDefaultProfile()
Expand All @@ -37,21 +38,4 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
const auto profile{ winrt::unbox_value<Model::Profile>(value) };
_State.Settings().GlobalSettings().DefaultProfile(profile.Guid());
}

// TODO GH#9463 - Complete hookup of Terminal UX to choose defapp.
Windows::Foundation::Collections::IObservableVector<IInspectable> Launch::DefaultTerminals()
{
Windows::Foundation::Collections::IObservableVector<IInspectable> vec;
return vec;
}

IInspectable Launch::CurrentDefaultTerminal()
{
return nullptr;
}

void Launch::CurrentDefaultTerminal(const IInspectable& value)
{
value;
}
}
4 changes: 0 additions & 4 deletions src/cascadia/TerminalSettingsEditor/Launch.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
IInspectable CurrentDefaultProfile();
void CurrentDefaultProfile(const IInspectable& value);

Windows::Foundation::Collections::IObservableVector<IInspectable> DefaultTerminals();
IInspectable CurrentDefaultTerminal();
void CurrentDefaultTerminal(const IInspectable& value);

WINRT_PROPERTY(Editor::LaunchPageNavigationState, State, nullptr);

GETSET_BINDABLE_ENUM_SETTING(LaunchMode, Model::LaunchMode, State().Settings().GlobalSettings, LaunchMode);
Expand Down
3 changes: 0 additions & 3 deletions src/cascadia/TerminalSettingsEditor/Launch.idl
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ namespace Microsoft.Terminal.Settings.Editor

IInspectable CurrentDefaultProfile;

IInspectable CurrentDefaultTerminal;
IObservableVector<IInspectable> DefaultTerminals { get; };

IInspectable CurrentLaunchMode;
IObservableVector<Microsoft.Terminal.Settings.Editor.EnumEntry> LaunchModeList { get; };

Expand Down
60 changes: 53 additions & 7 deletions src/cascadia/TerminalSettingsEditor/Launch.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<StackPanel Style="{StaticResource SettingsStackStyle}">
<!-- Default Profile -->
<local:SettingContainer x:Uid="Globals_DefaultProfile"
MinWidth="300"
Margin="0">
<ComboBox x:Name="DefaultProfile"
ItemsSource="{x:Bind State.Settings.AllProfiles, Mode=OneWay}"
Expand Down Expand Up @@ -70,16 +71,61 @@
</local:SettingContainer>

<!-- Default Terminal -->
<!-- TODO GH#9463 - Complete hookup of Terminal UX to choose defapp. -->
<!--
<local:SettingContainer x:Uid="Globals_DefaultTerminal">
miniksa marked this conversation as resolved.
Show resolved Hide resolved
<ComboBox x:Name="DefaultTerminal"
x:Load="False"
ItemsSource="{x:Bind DefaultTerminals, Mode=OneWay}"
SelectedItem="{x:Bind CurrentDefaultTerminal, Mode=TwoWay}"
Style="{StaticResource ComboBoxSettingStyle}" />
MinWidth="300"
miniksa marked this conversation as resolved.
Show resolved Hide resolved
ItemsSource="{x:Bind State.Settings.DefaultTerminals, Mode=OneWay}"
SelectedItem="{x:Bind State.Settings.CurrentDefaultTerminal, Mode=TwoWay}"
Style="{StaticResource ComboBoxSettingStyle}">
<ComboBox.ItemTemplate>
<DataTemplate x:DataType="SettingsModel:DefaultTerminal">
<Grid HorizontalAlignment="Stretch"
ColumnSpacing="8">

<Grid.ColumnDefinitions>
<!-- icon -->
<ColumnDefinition Width="16" />
<!-- profile name and author -->
<ColumnDefinition Width="*" />
<!-- version -->
<ColumnDefinition Width="48" />
</Grid.ColumnDefinitions>

<Grid.RowDefinitions>
<!-- profile name -->
<RowDefinition Height="Auto" />
<!-- author and version -->
<RowDefinition Height="14"/>
</Grid.RowDefinitions>

<IconSourceElement Grid.Column="0"
Grid.Row="0"
Grid.RowSpan="2"
VerticalAlignment="Center"
Width="16"
Height="16"
miniksa marked this conversation as resolved.
Show resolved Hide resolved
IconSource="{x:Bind Icon, Mode=OneWay, Converter={StaticResource IconSourceConverter}}" />

<TextBlock Grid.Column="1"
Grid.Row="0"
Grid.ColumnSpan="2"
Text="{x:Bind Name}" />

<TextBlock Grid.Column ="1"
Grid.Row="1"
FontSize="12"
Text="{x:Bind Author}" />

<TextBlock Grid.Column ="2"
Grid.Row="1"
FontSize="12"
Text="{x:Bind Version}" />

</Grid>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</local:SettingContainer>
-->

<!-- Start on User Login -->
<local:SettingContainer x:Uid="Globals_StartOnUserLogin">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@
<comment>A description for what the default profile is and when it's used.</comment>
</data>
<data name="Globals_DefaultTerminal.Header" xml:space="preserve">
<value>Default terminal</value>
<value>Default terminal application</value>
<comment>Header for a drop down that permits the user to select which installed Terminal application will launch when command line tools like CMD are run from the Windows Explorer run box or start menu or anywhere else that they do not already have a graphical window assigned.</comment>
</data>
<data name="Globals_DefaultTerminal.HelpText" xml:space="preserve">
Expand Down
58 changes: 57 additions & 1 deletion src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ CascadiaSettings::CascadiaSettings(const bool addDynamicProfiles) :
_allProfiles{ winrt::single_threaded_observable_vector<Model::Profile>() },
_activeProfiles{ winrt::single_threaded_observable_vector<Model::Profile>() },
_warnings{ winrt::single_threaded_vector<SettingsLoadWarnings>() },
_deserializationErrorMessage{ L"" }
_deserializationErrorMessage{ L"" },
_defaultTerminals{ winrt::single_threaded_observable_vector<Model::DefaultTerminal>() },
_currentDefaultTerminal{ nullptr }
{
if (addDynamicProfiles)
{
Expand Down Expand Up @@ -82,6 +84,9 @@ winrt::Microsoft::Terminal::Settings::Model::CascadiaSettings CascadiaSettings::
settings->_userSettings = _userSettings;
settings->_defaultSettings = _defaultSettings;

settings->_defaultTerminals = _defaultTerminals;
settings->_currentDefaultTerminal = _currentDefaultTerminal;

_CopyProfileInheritanceTree(settings);

return *settings;
Expand Down Expand Up @@ -999,3 +1004,54 @@ winrt::hstring CascadiaSettings::ApplicationVersion()

return RS_(L"ApplicationVersionUnknown");
}

// Method Description:
// - Forces a refresh of all default terminal state
// Arguments:
// - <none>
// Return Value:
// - <none> - Updates internal state
void CascadiaSettings::RefreshDefaultTerminals()
{
_defaultTerminals.Clear();

for (const auto& term : Model::DefaultTerminal::Available())
{
_defaultTerminals.Append(term);
}

_currentDefaultTerminal = Model::DefaultTerminal::Current();
}

// Method Description:
// - Returns an iterable collection of all available terminals.
// Arguments:
// - <none>
// Return Value:
// - an iterable collection of all available terminals that could be the default.
IObservableVector<winrt::Microsoft::Terminal::Settings::Model::DefaultTerminal> CascadiaSettings::DefaultTerminals() const noexcept
miniksa marked this conversation as resolved.
Show resolved Hide resolved
{
return _defaultTerminals;
miniksa marked this conversation as resolved.
Show resolved Hide resolved
}

// Method Description:
// - Returns the currently selected default terminal application
// Arguments:
// - <none>
// Return Value:
// - the selected default terminal application
winrt::Microsoft::Terminal::Settings::Model::DefaultTerminal CascadiaSettings::CurrentDefaultTerminal() const noexcept
miniksa marked this conversation as resolved.
Show resolved Hide resolved
{
return _currentDefaultTerminal;
}

// Method Description:
// - Sets the current default terminal application
// Arguments:
// - terminal - Terminal from `DefaultTerminals` list to set as default
// Return Value:
// - <none>
void CascadiaSettings::CurrentDefaultTerminal(winrt::Microsoft::Terminal::Settings::Model::DefaultTerminal terminal)
miniksa marked this conversation as resolved.
Show resolved Hide resolved
{
_currentDefaultTerminal = terminal;
Copy link
Member

Choose a reason for hiding this comment

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

nit: maybe note that this doesn't write the defterm choice to the registry, it just sets the value internally, and that the value is persisted to the reg in CascadiaSettings::WriteSettingsToDisk

}
9 changes: 9 additions & 0 deletions src/cascadia/TerminalSettingsModel/CascadiaSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation

winrt::guid GetProfileForArgs(const Model::NewTerminalArgs& newTerminalArgs) const;

void RefreshDefaultTerminals();

Windows::Foundation::Collections::IObservableVector<Model::DefaultTerminal> DefaultTerminals() const noexcept;
Model::DefaultTerminal CurrentDefaultTerminal() const noexcept;
void CurrentDefaultTerminal(Model::DefaultTerminal terminal);
miniksa marked this conversation as resolved.
Show resolved Hide resolved

private:
com_ptr<GlobalAppSettings> _globals;
Windows::Foundation::Collections::IObservableVector<Model::Profile> _allProfiles;
Expand All @@ -106,6 +112,9 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
Windows::Foundation::IReference<SettingsLoadErrors> _loadError;
hstring _deserializationErrorMessage;

Windows::Foundation::Collections::IObservableVector<Model::DefaultTerminal> _defaultTerminals;
Model::DefaultTerminal _currentDefaultTerminal;

std::vector<std::unique_ptr<::Microsoft::Terminal::Settings::Model::IDynamicProfileGenerator>> _profileGenerators;

std::string _userSettingsString;
Expand Down
5 changes: 5 additions & 0 deletions src/cascadia/TerminalSettingsModel/CascadiaSettings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import "GlobalAppSettings.idl";
import "Profile.idl";
import "TerminalWarnings.idl";
import "DefaultTerminal.idl";

namespace Microsoft.Terminal.Settings.Model
{
Expand Down Expand Up @@ -42,5 +43,9 @@ namespace Microsoft.Terminal.Settings.Model
void UpdateColorSchemeReferences(String oldName, String newName);

Guid GetProfileForArgs(NewTerminalArgs newTerminalArgs);

void RefreshDefaultTerminals();
Windows.Foundation.Collections.IObservableVector<DefaultTerminal> DefaultTerminals { get; };
DefaultTerminal CurrentDefaultTerminal;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,8 @@ void CascadiaSettings::WriteSettingsToDisk() const

const auto styledString{ Json::writeString(wbuilder, ToJson()) };
_WriteSettings(styledString, settingsPath);

Model::DefaultTerminal::Current(_currentDefaultTerminal);
miniksa marked this conversation as resolved.
Show resolved Hide resolved
}

// Method Description:
Expand Down
Loading