forked from microsoft/terminal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Teach CommandPalette model to natively support tabs and command lines (…
…microsoft#8420) First step towards microsoft#8415: * Introduce `PaletteItem` and derive from it to provide native support for tabs and command lines (`ActionPaletteItem` / `TabPaletteItem`, `CommandLinePaltteItem`) * Remove business logic behind PaletteItem from palette (aka dispatch commands and preview tabs externally)
- Loading branch information
Showing
31 changed files
with
585 additions
and
327 deletions.
There are no files selected for viewing
147 changes: 28 additions & 119 deletions
147
src/cascadia/LocalTests_TerminalApp/FilteredCommandTests.cpp
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
#include "pch.h" | ||
#include "ActionPaletteItem.h" | ||
#include <LibraryResources.h> | ||
|
||
#include "ActionPaletteItem.g.cpp" | ||
|
||
using namespace winrt; | ||
using namespace winrt::TerminalApp; | ||
using namespace winrt::Windows::UI::Core; | ||
using namespace winrt::Windows::UI::Xaml; | ||
using namespace winrt::Windows::System; | ||
using namespace winrt::Windows::Foundation; | ||
using namespace winrt::Windows::Foundation::Collections; | ||
using namespace winrt::Microsoft::Terminal::Settings::Model; | ||
|
||
namespace winrt::TerminalApp::implementation | ||
{ | ||
ActionPaletteItem::ActionPaletteItem(Microsoft::Terminal::Settings::Model::Command const& command) : | ||
_Command(command) | ||
{ | ||
Name(command.Name()); | ||
KeyChordText(command.KeyChordText()); | ||
Icon(command.Icon()); | ||
|
||
_commandChangedRevoker = command.PropertyChanged(winrt::auto_revoke, [weakThis{ get_weak() }](auto& sender, auto& e) { | ||
auto item{ weakThis.get() }; | ||
auto senderCommand{ sender.try_as<Microsoft::Terminal::Settings::Model::Command>() }; | ||
|
||
if (item && senderCommand) | ||
{ | ||
auto changedProperty = e.PropertyName(); | ||
if (changedProperty == L"Name") | ||
{ | ||
item->Name(senderCommand.Name()); | ||
} | ||
else if (changedProperty == L"KeyChordText") | ||
{ | ||
item->KeyChordText(senderCommand.KeyChordText()); | ||
} | ||
else if (changedProperty == L"Icon") | ||
{ | ||
item->Icon(senderCommand.Icon()); | ||
} | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
#pragma once | ||
|
||
#include "PaletteItem.h" | ||
#include "ActionPaletteItem.g.h" | ||
#include "inc/cppwinrt_utils.h" | ||
|
||
namespace winrt::TerminalApp::implementation | ||
{ | ||
struct ActionPaletteItem : ActionPaletteItemT<ActionPaletteItem, PaletteItem> | ||
{ | ||
ActionPaletteItem() = default; | ||
ActionPaletteItem(Microsoft::Terminal::Settings::Model::Command const& command); | ||
|
||
GETSET_PROPERTY(Microsoft::Terminal::Settings::Model::Command, Command, nullptr); | ||
|
||
private: | ||
Windows::UI::Xaml::Data::INotifyPropertyChanged::PropertyChanged_revoker _commandChangedRevoker; | ||
}; | ||
} | ||
|
||
namespace winrt::TerminalApp::factory_implementation | ||
{ | ||
BASIC_FACTORY(ActionPaletteItem); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import "PaletteItem.idl"; | ||
|
||
namespace TerminalApp | ||
{ | ||
[default_interface] runtimeclass ActionPaletteItem : PaletteItem | ||
{ | ||
ActionPaletteItem(Microsoft.Terminal.Settings.Model.Command command); | ||
|
||
Microsoft.Terminal.Settings.Model.Command Command { get; }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
#include "pch.h" | ||
#include "CommandLinePaletteItem.h" | ||
#include <LibraryResources.h> | ||
|
||
#include "CommandLinePaletteItem.g.cpp" | ||
|
||
using namespace winrt; | ||
using namespace winrt::TerminalApp; | ||
using namespace winrt::Windows::UI::Core; | ||
using namespace winrt::Windows::UI::Xaml; | ||
using namespace winrt::Windows::System; | ||
using namespace winrt::Windows::Foundation; | ||
using namespace winrt::Windows::Foundation::Collections; | ||
using namespace winrt::Microsoft::Terminal::Settings::Model; | ||
|
||
namespace winrt::TerminalApp::implementation | ||
{ | ||
CommandLinePaletteItem::CommandLinePaletteItem(winrt::hstring const& commandLine) : | ||
_CommandLine(commandLine) | ||
{ | ||
Name(commandLine); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
#pragma once | ||
|
||
#include "PaletteItem.h" | ||
#include "CommandLinePaletteItem.g.h" | ||
#include "inc/cppwinrt_utils.h" | ||
|
||
namespace winrt::TerminalApp::implementation | ||
{ | ||
struct CommandLinePaletteItem : CommandLinePaletteItemT<CommandLinePaletteItem, PaletteItem> | ||
{ | ||
CommandLinePaletteItem() = default; | ||
CommandLinePaletteItem(winrt::hstring const& commandLine); | ||
|
||
GETSET_PROPERTY(winrt::hstring, CommandLine); | ||
}; | ||
} | ||
|
||
namespace winrt::TerminalApp::factory_implementation | ||
{ | ||
BASIC_FACTORY(CommandLinePaletteItem); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import "PaletteItem.idl"; | ||
import "TabBase.idl"; | ||
|
||
namespace TerminalApp | ||
{ | ||
[default_interface] runtimeclass CommandLinePaletteItem : PaletteItem | ||
{ | ||
CommandLinePaletteItem(String commandLine); | ||
|
||
String CommandLine { get; }; | ||
} | ||
} |
Oops, something went wrong.