Skip to content

Commit

Permalink
Triple Click Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-zamora committed Jun 17, 2019
1 parent 494658f commit 3bce793
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 2 deletions.
40 changes: 40 additions & 0 deletions src/cascadia/TerminalApp/Profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" };
Expand All @@ -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())
{
Expand All @@ -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{},
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)] })
Expand Down Expand Up @@ -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;
}
}
3 changes: 3 additions & 0 deletions src/cascadia/TerminalApp/Profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class TerminalApp::Profile final
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;
Expand All @@ -76,6 +78,7 @@ class TerminalApp::Profile final
uint32_t _cursorColor;
uint32_t _cursorHeight;
winrt::Microsoft::Terminal::Settings::CursorStyle _cursorShape;
winrt::Microsoft::Terminal::Settings::SelectionMode _tripleClickSelectionMode;

std::wstring _commandline;
std::wstring _fontFace;
Expand Down
15 changes: 13 additions & 2 deletions src/cascadia/TerminalCore/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/cascadia/TerminalSettings/ICoreSettings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ namespace Microsoft.Terminal.Settings
EmptyBox
};

enum SelectionMode
{
Disabled,
Line,
VisibleViewport
};

interface ICoreSettings
{
UInt32 DefaultForeground;
Expand All @@ -27,6 +34,7 @@ namespace Microsoft.Terminal.Settings
UInt32 CursorColor;
CursorStyle CursorShape;
UInt32 CursorHeight;
SelectionMode TripleClickSelectionMode;
};

}
11 changes: 11 additions & 0 deletions src/cascadia/TerminalSettings/TerminalSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/cascadia/TerminalSettings/terminalsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/UnitTests_TerminalCore/ScreenSizeLimitsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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 */) {}
Expand Down

0 comments on commit 3bce793

Please sign in to comment.