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 all bindings, have to fix runtime error #27

Open
wants to merge 1 commit into
base: cinnamon/settings-ui-v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
24 changes: 21 additions & 3 deletions src/TerminalSettings/TerminalSettings/Keybindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#include <winrt/Windows.UI.Xaml.Input.h>
#include <winrt/Windows.UI.Input.h>
#include <winrt/Windows.UI.Popups.h>
#include <winrt/Windows.Foundation.Collections.h>

#include <ObjectModel\CommandModel.h>

using namespace winrt;
using namespace Windows::Foundation;
Expand All @@ -23,15 +26,15 @@ namespace winrt::SettingsControl::implementation
{
Keybindings::Keybindings()
{
m_commandListModel = winrt::make<ObjectModel::implementation::CommandListModel>();

InitializeComponent();

m_optionalSettingsPanel = FindName(L"OptionalSettingsPanel").as<Controls::StackPanel>();
m_addNewButton = FindName(L"AddNewLink").as<Controls::HyperlinkButton>();

Controls::TextBox tb = FindName(L"KeyBindTextBox").as<Controls::TextBox>();
tb.KeyDown({ this, &Keybindings::KeyDown });

// tb.BeforeTextChanging({this, &Keybindings::asdf_BeforeTextChanging})
}

int32_t Keybindings::MyProperty()
Expand All @@ -44,6 +47,11 @@ namespace winrt::SettingsControl::implementation
throw hresult_not_implemented();
}

ObjectModel::CommandListModel Keybindings::CommandListModel()
{
return m_commandListModel;
}

void Keybindings::ClickHandler(IInspectable const&, RoutedEventArgs const&)
{
//Button().Content(box_value(L"Clicked"));
Expand Down Expand Up @@ -245,15 +253,25 @@ namespace winrt::SettingsControl::implementation

hstring Keybindings::CollectInputData()
{
ObjectModel::CommandModel commandModel = winrt::make<ObjectModel::implementation::CommandModel>();
ObjectModel::Command command = commandModel.Command();

hstring fullInfo = L"";

Controls::ComboBox comboBox = FindName(L"CommandComboBox").as<Controls::ComboBox>();
fullInfo = fullInfo + comboBox.Name() + L":" + GetSelectedItemTag(comboBox) + L"\n";
command.CommandString(GetSelectedItemTag(comboBox));

Controls::TextBox textBox = FindName(L"KeyBindTextBox").as<Controls::TextBox>();
fullInfo = fullInfo + textBox.Name() + L":" + textBox.Text() + L"\n";
command.KeybindString(textBox.Text());

hstring args = TraversePanel(m_lastOpenedArgsPanel);
fullInfo = fullInfo + args;
command.Args(args);

fullInfo = fullInfo + TraversePanel(m_lastOpenedArgsPanel);
Windows::Foundation::Collections::IVector<ObjectModel::CommandModel> commandList = m_commandListModel.CommandList();
commandList.Append(commandModel);

return fullInfo;
}
Expand Down
6 changes: 6 additions & 0 deletions src/TerminalSettings/TerminalSettings/Keybindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@

#include "Keybindings.g.h"
#include <set>
#include "ObjectModel/CommandListModel.h"

namespace winrt::SettingsControl::implementation
{

struct Keybindings : KeybindingsT<Keybindings>
{
Keybindings();

int32_t MyProperty();
void MyProperty(int32_t value);

ObjectModel::CommandListModel CommandListModel();

void ClickHandler(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& args);
void Button_Click(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::RoutedEventArgs const& e);
void AddNewButton_Click(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::RoutedEventArgs const& e);
Expand Down Expand Up @@ -41,6 +45,8 @@ namespace winrt::SettingsControl::implementation
winrt::Windows::UI::Xaml::Controls::HyperlinkButton m_addNewButton{};

std::set<winrt::Windows::System::VirtualKey> m_keysInBind;

ObjectModel::CommandListModel m_commandListModel{ nullptr };
};
}

Expand Down
3 changes: 3 additions & 0 deletions src/TerminalSettings/TerminalSettings/Keybindings.idl
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import "ObjectModel/CommandListModel.idl";

namespace SettingsControl
{
[default_interface]
runtimeclass Keybindings : Windows.UI.Xaml.Controls.Page
{
Keybindings();
Int32 MyProperty;
ObjectModel.CommandListModel CommandListModel { get; };
}
}
21 changes: 20 additions & 1 deletion src/TerminalSettings/TerminalSettings/Keybindings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,26 @@
Style="{StaticResource HeaderTextBlockStyle}"
Margin="0,0,0,8" />

<Button Click="Button_Click">Open Window</Button>
<!--
<ListView ItemsSource="{x:Bind CommandListModel.CommandList}">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Type}" Grid.Column="0" />
<TextBlock Text="{Binding Args}" Grid.Column="1" />
<TextBlock Text="{Binding KeybindingString}" Grid.Column="2" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
-->

<Button Click="Button_Click">Add new keybinding</Button>

<Popup VerticalOffset="10" HorizontalOffset="200" x:Name="StandardPopup">
<Border BorderBrush="{StaticResource ApplicationForegroundThemeBrush}"
Expand Down
3 changes: 3 additions & 0 deletions src/TerminalSettings/TerminalSettings/ObjectModel/Command.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "pch.h"
#include "Command.h"
#include "ObjectModel.Command.g.cpp"
51 changes: 51 additions & 0 deletions src/TerminalSettings/TerminalSettings/ObjectModel/Command.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#pragma once
#include <winrt/Windows.UI.h>
#include <winrt/Windows.UI.Xaml.Media.h>
#include "ObjectModel.Command.g.h"

// Use this macro to quick implement both the getter and setter for a property.
// This should only be used for simple types where there's no logic in the
// getter/setter beyond just accessing/updating the value.
#define GETSET_PROPERTY(type, name, ...) \
public: \
type name() const noexcept { return _##name; } \
void name(const type& value) noexcept \
{ \
if (value != _##name) \
{ \
_##name = value; \
m_propertyChanged(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs{ L"##name" }); \
} \
} \
\
private: \
type _##name{ __VA_ARGS__ };

#define DEFINE_PROPERTYCHANGED() \
public: \
event_token PropertyChanged(Windows::UI::Xaml::Data::PropertyChangedEventHandler const& handler) \
{ \
return m_propertyChanged.add(handler); \
} \
\
void PropertyChanged(event_token const& token) \
{ \
m_propertyChanged.remove(token); \
} \
\
private: \
winrt::event<Windows::UI::Xaml::Data::PropertyChangedEventHandler> m_propertyChanged;

namespace winrt::ObjectModel::implementation
{
struct Command : CommandT<Command>
{
public:
Command() = default;

GETSET_PROPERTY(hstring, CommandString, L"");
GETSET_PROPERTY(hstring, Args, L"");
GETSET_PROPERTY(hstring, KeybindString, L"");
DEFINE_PROPERTYCHANGED();
};
}
9 changes: 9 additions & 0 deletions src/TerminalSettings/TerminalSettings/ObjectModel/Command.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace ObjectModel
{
runtimeclass Command : Windows.UI.Xaml.Data.INotifyPropertyChanged
{
String CommandString;
String Args;
String KeybindString;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "pch.h"
#include "CommandModel.h"
#include "ObjectModel.CommandListModel.g.cpp"
#include "CommandListModel.h"


namespace winrt::ObjectModel::implementation
{
CommandListModel::CommandListModel()
{
m_commandList = winrt::single_threaded_vector<ObjectModel::CommandModel>();
}

winrt::Windows::Foundation::Collections::IVector<ObjectModel::CommandModel> CommandListModel::CommandList()
{
return m_commandList;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once
#include "ObjectModel.CommandListModel.g.h"
#include "CommandModel.h"

#include <winrt/Windows.Foundation.Collections.h>

namespace winrt::ObjectModel::implementation
{
struct CommandListModel : CommandListModelT<CommandListModel>
{
CommandListModel();

winrt::Windows::Foundation::Collections::IVector<ObjectModel::CommandModel> CommandList();

private:
winrt::Windows::Foundation::Collections::IVector<ObjectModel::CommandModel> m_commandList;
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import "ObjectModel/CommandModel.idl";

namespace ObjectModel
{
runtimeclass CommandListModel
{
IVector<CommandModel> CommandList { get; };
}
}
17 changes: 17 additions & 0 deletions src/TerminalSettings/TerminalSettings/ObjectModel/CommandModel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "pch.h"
#include "Command.h"
#include "ObjectModel.CommandModel.g.cpp"
#include "CommandModel.h"

namespace winrt::ObjectModel::implementation
{
CommandModel::CommandModel()
{
m_command = winrt::make<ObjectModel::implementation::Command>();
}

ObjectModel::Command CommandModel::Command()
{
return m_command;
}
}
16 changes: 16 additions & 0 deletions src/TerminalSettings/TerminalSettings/ObjectModel/CommandModel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once
#include "ObjectModel.CommandModel.g.h"
#include "Command.h"

namespace winrt::ObjectModel::implementation
{
struct CommandModel : CommandModelT<CommandModel>
{
CommandModel();

ObjectModel::Command Command();

private:
ObjectModel::Command m_command{ nullptr };
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import "ObjectModel/Command.idl";

namespace ObjectModel
{
runtimeclass CommandModel
{
Command Command { get; };
}
}
11 changes: 10 additions & 1 deletion src/TerminalSettings/TerminalSettings/SettingsControl.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@
<ClInclude Include="Launch.h">
<DependentUpon>Launch.xaml</DependentUpon>
</ClInclude>
<ClInclude Include="ObjectModel\Command.h" />
<ClInclude Include="ObjectModel\CommandListModel.h" />
<ClInclude Include="ObjectModel\CommandModel.h" />
<ClInclude Include="SplitPaneOptionPanelControl.h">
<DependentUpon>SplitPaneOptionPanelControl.xaml</DependentUpon>
</ClInclude>
Expand Down Expand Up @@ -262,6 +265,9 @@
<ClCompile Include="Launch.cpp">
<DependentUpon>Launch.xaml</DependentUpon>
</ClCompile>
<ClCompile Include="ObjectModel\Command.cpp" />
<ClCompile Include="ObjectModel\CommandListModel.cpp" />
<ClCompile Include="ObjectModel\CommandModel.cpp" />
<ClCompile Include="SplitPaneOptionPanelControl.cpp">
<DependentUpon>SplitPaneOptionPanelControl.xaml</DependentUpon>
</ClCompile>
Expand Down Expand Up @@ -328,6 +334,9 @@
<SubType>Code</SubType>
</Midl>
<Midl Include="ObjectModel\ColorSchemeModel.idl" />
<Midl Include="ObjectModel\Command.idl" />
<Midl Include="ObjectModel\CommandListModel.idl" />
<Midl Include="ObjectModel\CommandModel.idl" />
<Midl Include="ObjectModel\GlobalSettings.idl" />
<Midl Include="ObjectModel\GlobalSettingsModel.idl" />
<Midl Include="ObjectModel\Profile.idl" />
Expand Down Expand Up @@ -384,4 +393,4 @@
<Error Condition="!Exists('..\..\..\packages\Microsoft.Toolkit.Win32.UI.XamlApplication.6.1.1\build\native\Microsoft.Toolkit.Win32.UI.XamlApplication.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\Microsoft.Toolkit.Win32.UI.XamlApplication.6.1.1\build\native\Microsoft.Toolkit.Win32.UI.XamlApplication.props'))" />
<Error Condition="!Exists('..\..\..\packages\Microsoft.Toolkit.Win32.UI.XamlApplication.6.1.1\build\native\Microsoft.Toolkit.Win32.UI.XamlApplication.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\Microsoft.Toolkit.Win32.UI.XamlApplication.6.1.1\build\native\Microsoft.Toolkit.Win32.UI.XamlApplication.targets'))" />
</Target>
</Project>
</Project>
Loading