Triple Click Settings

This commit is contained in:
Carlos Zamora 2019-06-17 10:30:44 -07:00
parent d2e1be1bf0
commit 9db18ab1e0
7 changed files with 80 additions and 2 deletions

View file

@ -40,6 +40,7 @@ static constexpr std::string_view IconKey{ "icon" };
static constexpr std::string_view BackgroundImageKey{ "backgroundImage" };
static constexpr std::string_view BackgroundImageOpacityKey{ "backgroundImageOpacity" };
static constexpr std::string_view BackgroundimageStretchModeKey{ "backgroundImageStretchMode" };
static constexpr std::string_view TripleClickSelectionModeKey{ "tripleClickSelectionMode" };
// Possible values for Scrollbar state
static constexpr std::wstring_view AlwaysVisible{ L"visible" };
@ -58,6 +59,11 @@ static constexpr std::string_view ImageStretchModeFill{ "fill" };
static constexpr std::string_view ImageStretchModeUniform{ "uniform" };
static constexpr std::string_view ImageStretchModeUniformTofill{ "uniformToFill" };
// Possible values for Triple Click Selection Mode
static constexpr std::wstring_view SelectionModeDisabled{ L"disabled" };
static constexpr std::wstring_view SelectionModeLine{ L"line" };
static constexpr std::wstring_view SelectionModeViewport{ L"viewport" };
Profile::Profile() :
Profile(Utils::CreateGuid())
{
@ -76,6 +82,7 @@ Profile::Profile(const winrt::guid& guid) :
_cursorColor{ DEFAULT_CURSOR_COLOR },
_cursorShape{ CursorStyle::Bar },
_cursorHeight{ DEFAULT_CURSOR_HEIGHT },
_tripleClickSelectionMode{ SelectionMode::Line },
_commandline{ L"cmd.exe" },
_startingDirectory{},
@ -144,6 +151,7 @@ TerminalSettings Profile::CreateTerminalSettings(const std::vector<ColorScheme>&
terminalSettings.CursorColor(_cursorColor);
terminalSettings.CursorHeight(_cursorHeight);
terminalSettings.CursorShape(_cursorShape);
terminalSettings.TripleClickSelectionMode(_tripleClickSelectionMode);
// Fill in the remaining properties from the profile
terminalSettings.UseAcrylic(_useAcrylic);
@ -249,6 +257,7 @@ Json::Value Profile::ToJson() const
root[JsonKey(CursorHeightKey)] = _cursorHeight;
}
root[JsonKey(CursorShapeKey)] = winrt::to_string(_SerializeCursorStyle(_cursorShape));
root[JsonKey(TripleClickSelectionModeKey)] = winrt::to_string(_SerializeSelectionMode(_tripleClickSelectionMode));
///// Control Settings /////
root[JsonKey(CommandlineKey)] = winrt::to_string(_commandline);
@ -369,6 +378,10 @@ Profile Profile::FromJson(const Json::Value& json)
{
result._cursorShape = _ParseCursorShape(GetWstringFromJson(cursorShape));
}
if (auto tripleClickSelectionMode{ json[JsonKey(TripleClickSelectionModeKey)] })
{
result._tripleClickSelectionMode = _ParseSelectionMode(GetWstringFromJson(tripleClickSelectionMode));
}
// Control Settings
if (auto commandline{ json[JsonKey(CommandlineKey)] })
@ -673,3 +686,30 @@ std::wstring_view Profile::_SerializeCursorStyle(const CursorStyle cursorShape)
return CursorShapeBar;
}
}
winrt::Microsoft::Terminal::Settings::SelectionMode Profile::_ParseSelectionMode(const std::wstring& selectionModeString)
{
if (selectionModeString == SelectionModeDisabled)
{
return SelectionMode::Disabled;
}
else if (selectionModeString == SelectionModeViewport)
{
return SelectionMode::VisibleViewport;
}
return SelectionMode::Line;
}
std::wstring_view Profile::_SerializeSelectionMode(const winrt::Microsoft::Terminal::Settings::SelectionMode selectionMode)
{
switch (selectionMode)
{
case SelectionMode::Disabled:
return SelectionModeDisabled;
case SelectionMode::VisibleViewport:
return SelectionModeViewport;
case SelectionMode::Line:
default:
return SelectionModeLine;
}
}

View file

@ -61,6 +61,8 @@ private:
static std::string_view SerializeImageStretchMode(const winrt::Windows::UI::Xaml::Media::Stretch imageStretchMode);
static winrt::Microsoft::Terminal::Settings::CursorStyle _ParseCursorShape(const std::wstring& cursorShapeString);
static std::wstring_view _SerializeCursorStyle(const winrt::Microsoft::Terminal::Settings::CursorStyle cursorShape);
static winrt::Microsoft::Terminal::Settings::SelectionMode _ParseSelectionMode(const std::wstring& selectionModeString);
static std::wstring_view _SerializeSelectionMode(const winrt::Microsoft::Terminal::Settings::SelectionMode selectionMode);
GUID _guid;
std::wstring _name;
@ -76,6 +78,7 @@ private:
uint32_t _cursorColor;
uint32_t _cursorHeight;
winrt::Microsoft::Terminal::Settings::CursorStyle _cursorShape;
winrt::Microsoft::Terminal::Settings::SelectionMode _tripleClickSelectionMode;
std::wstring _commandline;
std::wstring _fontFace;

View file

@ -133,8 +133,19 @@ void Terminal::UpdateSettings(winrt::Microsoft::Terminal::Settings::ICoreSetting
_snapOnInput = settings.SnapOnInput();
// TODO: import tripleClickSelection setting from Settings
_tripleClickMode = TripleClickSelectionMode::Line;
switch (settings.TripleClickSelectionMode())
{
case winrt::Microsoft::Terminal::Settings::SelectionMode::Disabled:
_tripleClickMode = TripleClickSelectionMode::Disabled;
break;
case winrt::Microsoft::Terminal::Settings::SelectionMode::VisibleViewport:
_tripleClickMode = TripleClickSelectionMode::VisibleViewport;
break;
case winrt::Microsoft::Terminal::Settings::SelectionMode::Line:
default:
_tripleClickMode = TripleClickSelectionMode::Line;
break;
}
// TODO:MSFT:21327402 - if HistorySize has changed, resize the buffer so we
// have a smaller scrollback. We should do this carefully - if the new buffer

View file

@ -12,6 +12,13 @@ namespace Microsoft.Terminal.Settings
EmptyBox
};
enum SelectionMode
{
Disabled,
Line,
VisibleViewport
};
interface ICoreSettings
{
UInt32 DefaultForeground;
@ -27,6 +34,7 @@ namespace Microsoft.Terminal.Settings
UInt32 CursorColor;
CursorStyle CursorShape;
UInt32 CursorHeight;
SelectionMode TripleClickSelectionMode;
};
}

View file

@ -20,6 +20,7 @@ namespace winrt::Microsoft::Terminal::Settings::implementation
_cursorColor{ DEFAULT_CURSOR_COLOR },
_cursorShape{ CursorStyle::Vintage },
_cursorHeight{ DEFAULT_CURSOR_HEIGHT },
_tripleClickSelectionMode{ Settings::SelectionMode::Line },
_useAcrylic{ false },
_closeOnExit{ true },
_tintOpacity{ 0.5 },
@ -135,6 +136,16 @@ namespace winrt::Microsoft::Terminal::Settings::implementation
_cursorHeight = value;
}
Settings::SelectionMode TerminalSettings::TripleClickSelectionMode() const noexcept
{
return _tripleClickSelectionMode;
}
void TerminalSettings::TripleClickSelectionMode(winrt::Microsoft::Terminal::Settings::SelectionMode const& value) noexcept
{
_tripleClickSelectionMode = value;
}
bool TerminalSettings::UseAcrylic()
{
return _useAcrylic;

View file

@ -45,6 +45,8 @@ namespace winrt::Microsoft::Terminal::Settings::implementation
void CursorShape(winrt::Microsoft::Terminal::Settings::CursorStyle const& value) noexcept;
uint32_t CursorHeight();
void CursorHeight(uint32_t value);
Settings::SelectionMode TripleClickSelectionMode() const noexcept;
void TripleClickSelectionMode(winrt::Microsoft::Terminal::Settings::SelectionMode const& value) noexcept;
// ------------------------ End of Core Settings -----------------------
bool UseAcrylic();
@ -94,6 +96,7 @@ namespace winrt::Microsoft::Terminal::Settings::implementation
uint32_t _cursorColor;
Settings::CursorStyle _cursorShape;
uint32_t _cursorHeight;
Settings::SelectionMode _tripleClickSelectionMode;
bool _useAcrylic;
bool _closeOnExit;

View file

@ -36,6 +36,7 @@ namespace TerminalCoreUnitTests
uint32_t CursorColor() { return COLOR_WHITE; }
CursorStyle CursorShape() const noexcept { return CursorStyle::Vintage; }
uint32_t CursorHeight() { return 42UL; }
SelectionMode TripleClickSelectionMode() { return SelectionMode::Line; }
// other implemented methods
uint32_t GetColorTableEntry(int32_t) const { return 123; }
@ -50,6 +51,7 @@ namespace TerminalCoreUnitTests
void CursorColor(uint32_t) {}
void CursorShape(CursorStyle const&) noexcept {}
void CursorHeight(uint32_t) {}
void TripleClickSelectionMode(SelectionMode) {}
// other unimplemented methods
void SetColorTableEntry(int32_t /* index */, uint32_t /* value */) {}