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

Add copyFormatting keybinding arg and array support #6004

Merged
merged 27 commits into from
Aug 15, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
0395d46
allow copyFormatting to be an array
carlos-zamora May 15, 2020
8a52b23
add copyFormatting as a copy arg
carlos-zamora May 15, 2020
0bb55eb
add keybinding arg to copy
carlos-zamora May 15, 2020
d86c1ea
update docs and fix a few comments
carlos-zamora May 19, 2020
322da3b
code format
carlos-zamora May 19, 2020
f2bfeda
change sentinel value to 0
carlos-zamora Jun 24, 2020
bb27289
attempt to use JsonUtilsNew (and fail :( )
carlos-zamora Jun 26, 2020
0532d0d
Merge branch 'master' into dev/cazamor/copy-formatting-arg
carlos-zamora Jul 2, 2020
0dc5b2a
PR comments (2 errors from JsonUtilsNew and WI_...)
carlos-zamora Jul 6, 2020
f1c93eb
Merge branch 'master' into dev/cazamor/copy-formatting-arg
carlos-zamora Jul 10, 2020
f95bdac
IT WORKS!!!!!!
carlos-zamora Jul 10, 2020
f72a443
I like default params too much...
carlos-zamora Jul 10, 2020
82e25a5
Merge branch 'master' into dev/cazamor/copy-formatting-arg
carlos-zamora Jul 13, 2020
708f586
merge master
carlos-zamora Jul 17, 2020
e7d0f2a
JsonUtilsNew is no more
carlos-zamora Jul 17, 2020
bf85092
a leap of faith (should work, but my machine is dumb)
carlos-zamora Jul 17, 2020
21856aa
better documentation surrounding format override
carlos-zamora Jul 20, 2020
bbe7d82
remove debugging vars
carlos-zamora Jul 20, 2020
b785989
dustin's PR comments
carlos-zamora Jul 21, 2020
260a98f
Merge branch 'master' into dev/cazamor/copy-formatting-arg
carlos-zamora Aug 7, 2020
1230b77
fix plain value, add generated name
carlos-zamora Aug 7, 2020
15e019f
remove plain and unnecessary resw changes
carlos-zamora Aug 10, 2020
2806285
befriend localization
carlos-zamora Aug 11, 2020
3661dc9
Merge branch 'master' into dev/cazamor/copy-formatting-arg
carlos-zamora Aug 11, 2020
bcb750f
clean up GenerateName
carlos-zamora Aug 11, 2020
06d2e6c
FlagMapper should use BaseEnumMapper's TypeDescription()
carlos-zamora Aug 11, 2020
339f65c
actually test it this time...
carlos-zamora Aug 14, 2020
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
39 changes: 37 additions & 2 deletions src/cascadia/TerminalApp/ActionArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include <LibraryResources.h>

using namespace winrt::Microsoft::Terminal::TerminalControl;

namespace winrt::TerminalApp::implementation
{
winrt::hstring NewTerminalArgs::GenerateName() const
Expand Down Expand Up @@ -62,11 +64,44 @@ namespace winrt::TerminalApp::implementation

winrt::hstring CopyTextArgs::GenerateName() const
{
winrt::hstring singleLineStr;
if (_SingleLine)
{
return RS_(L"CopyTextAsSingleLineCommandKey");
// as a single line
singleLineStr = RS_(L"CopyTextAsSingleLineCommandKey");
}

winrt::hstring copyFormatStr;
if (_CopyFormatting != nullptr)
{
if (_CopyFormatting.Value() == CopyFormat::All ||
(WI_IsFlagSet(_CopyFormatting.Value(), CopyFormat::HTML) && WI_IsFlagSet(_CopyFormatting.Value(), CopyFormat::RTF)))
{
// with formatting
copyFormatStr = RS_(L"CopyTextFormatAllCommandKey");
}
else if (_CopyFormatting.Value() == static_cast<CopyFormat>(0))
{
// without formatting
copyFormatStr = RS_(L"CopyTextFormatNoneCommandKey");
}
else
{
if (WI_IsFlagSet(_CopyFormatting.Value(), CopyFormat::HTML))
{
// html
copyFormatStr = RS_(L"CopyTextFormatHTMLCommandKey");
}
else if (WI_IsFlagSet(_CopyFormatting.Value(), CopyFormat::RTF))
{
// rtf
copyFormatStr = RS_(L"CopyTextFormatRTFCommandKey");
}
}
}
return RS_(L"CopyTextCommandKey");
return winrt::hstring{
fmt::format(std::wstring_view(RS_(L"CopyTextCommandKey")), singleLineStr, copyFormatStr)
};
}

winrt::hstring NewTabArgs::GenerateName() const
Expand Down
3 changes: 2 additions & 1 deletion src/cascadia/TerminalApp/ActionArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ namespace winrt::TerminalApp::implementation
{
CopyTextArgs() = default;
GETSET_PROPERTY(bool, SingleLine, false);
GETSET_PROPERTY(Windows::Foundation::IReference<Microsoft::Terminal::Settings::CopyFormat>, CopyFormatting, nullptr);
GETSET_PROPERTY(Windows::Foundation::IReference<Microsoft::Terminal::TerminalControl::CopyFormat>, CopyFormatting, nullptr);

static constexpr std::string_view SingleLineKey{ "singleLine" };
static constexpr std::string_view CopyFormattingKey{ "copyFormatting" };
Expand All @@ -115,6 +115,7 @@ namespace winrt::TerminalApp::implementation
// LOAD BEARING: Not using make_self here _will_ break you in the future!
auto args = winrt::make_self<CopyTextArgs>();
JsonUtils::GetValueForKey(json, SingleLineKey, args->_SingleLine);
JsonUtils::GetValueForKey(json, CopyFormattingKey, args->_CopyFormatting);
return { *args, {} };
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalApp/ActionArgs.idl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace TerminalApp
[default_interface] runtimeclass CopyTextArgs : IActionArgs
{
Boolean SingleLine { get; };
Windows.Foundation.IReference<Microsoft.Terminal.Settings.CopyFormat> CopyFormatting { get; };
Windows.Foundation.IReference<Microsoft.Terminal.TerminalControl.CopyFormat> CopyFormatting { get; };
};

[default_interface] runtimeclass NewTabArgs : IActionArgs
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalApp/GlobalAppSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class TerminalApp::GlobalAppSettings final
GETSET_PROPERTY(bool, ShowTabsInTitlebar, true);
GETSET_PROPERTY(std::wstring, WordDelimiters); // default value set in constructor
GETSET_PROPERTY(bool, CopyOnSelect, false);
GETSET_PROPERTY(winrt::Microsoft::Terminal::Settings::CopyFormat, CopyFormatting, winrt::Microsoft::Terminal::Settings::CopyFormat::Plain);
GETSET_PROPERTY(winrt::Microsoft::Terminal::TerminalControl::CopyFormat, CopyFormatting, 0);
GETSET_PROPERTY(bool, WarnAboutLargePaste, true);
GETSET_PROPERTY(bool, WarnAboutMultiLinePaste, true);
GETSET_PROPERTY(LaunchPosition, InitialPosition);
Expand Down
81 changes: 47 additions & 34 deletions src/cascadia/TerminalApp/Resources/en-US/Resources.resw
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema

<!--
Microsoft ResX Schema
Version 2.0

The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.

Example:

... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
Expand All @@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>

There are any number of "resheader" rows that contain simple
There are any number of "resheader" rows that contain simple
name/value pairs.

Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.

The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:

Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.

mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
Expand Down Expand Up @@ -204,12 +204,12 @@
<value>Warnings were found while parsing your keybindings:</value>
</data>
<data name="TooManyKeysForChord" xml:space="preserve">
<value>&#x2022; Found a keybinding with too many strings for the "keys" array. There should only be one string value in the "keys" array.</value>
<comment>{Locked="\"keys\"","&#x2022;"} This glyph is a bullet, used in a bulleted list.</comment>
<value> Found a keybinding with too many strings for the "keys" array. There should only be one string value in the "keys" array.</value>
<comment>{Locked="\"keys\"",""} This glyph is a bullet, used in a bulleted list.</comment>
</data>
<data name="MissingRequiredParameter" xml:space="preserve">
<value>&#x2022; Found a keybinding that was missing a required parameter value. This keybinding will be ignored.</value>
<comment>{Locked="&#x2022;"} This glyph is a bullet, used in a bulleted list.</comment>
<value> Found a keybinding that was missing a required parameter value. This keybinding will be ignored.</value>
<comment>{Locked=""} This glyph is a bullet, used in a bulleted list.</comment>
carlos-zamora marked this conversation as resolved.
Show resolved Hide resolved
</data>
<data name="LegacyGlobalsProperty" xml:space="preserve">
<value>The "globals" property is deprecated - your settings might need updating. </value>
Expand Down Expand Up @@ -480,10 +480,11 @@
<value>Split pane vertically</value>
</data>
<data name="CopyTextCommandKey" xml:space="preserve">
<value>Copy text</value>
<value>Copy text {0} {1}</value>
<comment>{0} will be replaced with SingleLine value. {1} will be replaced with formats</comment>
carlos-zamora marked this conversation as resolved.
Show resolved Hide resolved
</data>
<data name="CopyTextAsSingleLineCommandKey" xml:space="preserve">
<value>Copy text as a single line</value>
<value>as a single line</value>
</data>
<data name="PasteTextCommandKey" xml:space="preserve">
<value>Paste</value>
Expand Down Expand Up @@ -603,4 +604,16 @@
<data name="DarkGrayColorButton.[using:Windows.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve">
<value>Dark Gray</value>
</data>
</root>
<data name="CopyTextFormatAllCommandKey" xml:space="preserve">
<value>with formatting</value>
</data>
<data name="CopyTextFormatHTMLCommandKey" xml:space="preserve">
<value>with HTML data</value>
</data>
<data name="CopyTextFormatNoneCommandKey" xml:space="preserve">
<value>without formatting</value>
</data>
<data name="CopyTextFormatRTFCommandKey" xml:space="preserve">
<value>with RTF data</value>
</data>
</root>
9 changes: 3 additions & 6 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1604,11 +1604,8 @@ namespace winrt::TerminalApp::implementation
_settings->GlobalSettings().CopyFormatting() :
copiedData.Formats().Value();

if (WI_IsFlagSet(copyFormats, CopyFormat::Plain))
{
// copy text to dataPack
dataPack.SetText(copiedData.Text());
}
// copy text to dataPack
dataPack.SetText(copiedData.Text());

if (WI_IsFlagSet(copyFormats, CopyFormat::HTML))
{
Expand Down Expand Up @@ -1717,7 +1714,7 @@ namespace winrt::TerminalApp::implementation
// - formats: dictate which formats need to be copied
// Return Value:
// - true iff we we able to copy text (if a selection was active)
bool TerminalPage::_CopyText(const bool singleLine, const Windows::Foundation::IReference<Settings::CopyFormat>& formats)
bool TerminalPage::_CopyText(const bool singleLine, const Windows::Foundation::IReference<CopyFormat>& formats)
{
const auto control = _GetActiveControl();
return control.CopySelectionToClipboard(singleLine, formats);
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ namespace winrt::TerminalApp::implementation
winrt::fire_and_forget _CopyToClipboardHandler(const IInspectable sender, const winrt::Microsoft::Terminal::TerminalControl::CopyToClipboardEventArgs copiedData);
winrt::fire_and_forget _PasteFromClipboardHandler(const IInspectable sender,
const Microsoft::Terminal::TerminalControl::PasteFromClipboardEventArgs eventArgs);
bool _CopyText(const bool singleLine, const Windows::Foundation::IReference<Microsoft::Terminal::Settings::CopyFormat>& formats);
bool _CopyText(const bool singleLine, const Windows::Foundation::IReference<Microsoft::Terminal::TerminalControl::CopyFormat>& formats);
void _PasteText();

fire_and_forget _LaunchSettings(const winrt::TerminalApp::SettingsTarget target);
Expand Down
9 changes: 0 additions & 9 deletions src/cascadia/TerminalApp/TerminalSettings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@

namespace TerminalApp
{
// Each CopyFormat value should be a flag in a bitfield
enum CopyFormat
{
Plain = 0x1,
HTML = 0x2,
RTF = 0x4,
All = 0xffffffff
};

// Class Description:
// TerminalSettings encapsulates all settings that control the
// TermControl's behavior. In these settings there is both the entirety
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,11 @@ JSON_ENUM_MAPPER(::winrt::Microsoft::UI::Xaml::Controls::TabViewWidthMode)
};
};

DEFINE_ENUM_FLAG_OPERATORS(::winrt::Microsoft::Terminal::Settings::CopyFormat);

JSON_FLAG_MAPPER(::winrt::Microsoft::Terminal::Settings::CopyFormat)
JSON_FLAG_MAPPER(::winrt::Microsoft::Terminal::TerminalControl::CopyFormat)
{
JSON_MAPPINGS(5) = {
pair_type{ "none", AllClear },
pair_type{ "plain", ValueType::Plain },
pair_type{ "plain", AllClear },
carlos-zamora marked this conversation as resolved.
Show resolved Hide resolved
pair_type{ "html", ValueType::HTML },
pair_type{ "rtf", ValueType::RTF },
pair_type{ "all", AllSet },
Expand All @@ -196,7 +194,7 @@ JSON_FLAG_MAPPER(::winrt::Microsoft::Terminal::Settings::CopyFormat)
{
if (json.isBool())
{
return json.asBool() ? AllSet : ValueType::Plain;
return json.asBool() ? AllSet : AllClear;
}
return BaseFlagMapper::FromJson(json);
}
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ constexpr const auto ScrollBarUpdateInterval = std::chrono::milliseconds(8);
// The minimum delay between updating the TSF input control.
constexpr const auto TsfRedrawInterval = std::chrono::milliseconds(100);

DEFINE_ENUM_FLAG_OPERATORS(CopyFormat);
DEFINE_ENUM_FLAG_OPERATORS(winrt::Microsoft::Terminal::TerminalControl::CopyFormat);

namespace winrt::Microsoft::Terminal::TerminalControl::implementation
{
Expand Down
10 changes: 5 additions & 5 deletions src/cascadia/TerminalControl/TermControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
_text(text),
_html(),
_rtf(),
_formats(Settings::CopyFormat::Plain) {}
_formats(static_cast<CopyFormat>(0)) {}

CopyToClipboardEventArgs(hstring text, hstring html, hstring rtf, Windows::Foundation::IReference<Settings::CopyFormat> formats) :
CopyToClipboardEventArgs(hstring text, hstring html, hstring rtf, Windows::Foundation::IReference<CopyFormat> formats) :
_text(text),
_html(html),
_rtf(rtf),
Expand All @@ -37,13 +37,13 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
hstring Text() { return _text; };
hstring Html() { return _html; };
hstring Rtf() { return _rtf; };
Windows::Foundation::IReference<Settings::CopyFormat> Formats() { return _formats; };
Windows::Foundation::IReference<CopyFormat> Formats() { return _formats; };

private:
hstring _text;
hstring _html;
hstring _rtf;
Windows::Foundation::IReference<Settings::CopyFormat> _formats;
Windows::Foundation::IReference<CopyFormat> _formats;
};

struct PasteFromClipboardEventArgs :
Expand Down Expand Up @@ -71,7 +71,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
hstring Title();
hstring GetProfileName() const;

bool CopySelectionToClipboard(bool singleLine, const Windows::Foundation::IReference<Settings::CopyFormat>& formats);
bool CopySelectionToClipboard(bool singleLine, const Windows::Foundation::IReference<CopyFormat>& formats);
void PasteTextFromClipboard();
void Close();
Windows::Foundation::Size CharacterDimensions() const;
Expand Down
12 changes: 10 additions & 2 deletions src/cascadia/TerminalControl/TermControl.idl
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,20 @@ namespace Microsoft.Terminal.TerminalControl
Boolean OnDirectKeyEvent(UInt32 vkey, Boolean down);
}

[flags]
enum CopyFormat
{
HTML = 0x1,
RTF = 0x2,
All = 0xffffffff
};

runtimeclass CopyToClipboardEventArgs
{
String Text { get; };
String Html { get; };
String Rtf { get; };
Windows.Foundation.IReference<Microsoft.Terminal.Settings.CopyFormat> Formats { get; };
Windows.Foundation.IReference<CopyFormat> Formats { get; };
}

runtimeclass PasteFromClipboardEventArgs
Expand Down Expand Up @@ -53,7 +61,7 @@ namespace Microsoft.Terminal.TerminalControl

String Title { get; };

Boolean CopySelectionToClipboard(Boolean singleLine, Windows.Foundation.IReference<Microsoft.Terminal.Settings.CopyFormat> formats);
Boolean CopySelectionToClipboard(Boolean singleLine, Windows.Foundation.IReference<CopyFormat> formats);
void PasteTextFromClipboard();
void Close();
Windows.Foundation.Size CharacterDimensions { get; };
Expand Down