mirror of
https://github.com/vczh-libraries/Release.git
synced 2026-05-19 02:25:04 +08:00
AddressBook ViewModel
This commit is contained in:
@@ -13,6 +13,34 @@
|
||||
</Folder>
|
||||
</Folder>
|
||||
|
||||
<Script>
|
||||
<Workflow-ViewModel>
|
||||
module viewmodel;
|
||||
|
||||
using system::*;
|
||||
|
||||
namespace demo
|
||||
{
|
||||
interface ICategory
|
||||
{
|
||||
func GetName() : string;
|
||||
prop Name : string {GetName}
|
||||
|
||||
func GetFolders() : ObservableList^;
|
||||
prop Folders : ObservableList^ {GetFolders}
|
||||
|
||||
func GetContacts() : ObservableList^;
|
||||
prop Contacts : ObservableList^ {GetContacts}
|
||||
}
|
||||
|
||||
interface IViewModel
|
||||
{
|
||||
func GetRootCategory() : ICategory^;
|
||||
}
|
||||
}
|
||||
</Workflow-ViewModel>
|
||||
</Script>
|
||||
|
||||
<Folder name="Images">
|
||||
<Image content="File" name="NewContact">NewContact.png</Image>
|
||||
<Image content="File" name="NewFolder">NewFolder.png</Image>
|
||||
@@ -32,6 +60,7 @@
|
||||
<Folder name="MainWindow">
|
||||
<Instance name="MainWindowResource">
|
||||
<Instance ref.Class="demo::MainWindow">
|
||||
<ref.Parameter Name="ViewModel" Class="demo::IViewModel"/>
|
||||
<Window Text="AddressBook" ClientSize="x:480 y:320">
|
||||
<att.BoundsComposition-set PreferredMinSize="x:480 y:320"/>
|
||||
|
||||
@@ -101,9 +130,9 @@
|
||||
</Cell>
|
||||
|
||||
<Cell Site="row:1 column:0">
|
||||
<TreeView ref.Name="treeViewFolders" HorizontalAlwaysVisible="false" VerticalAlwaysVisible="false">
|
||||
<BindableTreeView ref.Name="treeViewFolders" ItemSource-eval="ViewModel.GetRootCategory()" HorizontalAlwaysVisible="false" VerticalAlwaysVisible="false">
|
||||
<att.BoundsComposition-set AlignmentToParent="left:0 top:0 right:0 bottom:0"/>
|
||||
</TreeView>
|
||||
</BindableTreeView>
|
||||
</Cell>
|
||||
</Table>
|
||||
</GroupBox>
|
||||
@@ -139,9 +168,9 @@
|
||||
</Cell>
|
||||
|
||||
<Cell Site="row:1 column:0">
|
||||
<ListView ref.Name="listViewContacts" HorizontalAlwaysVisible="false" VerticalAlwaysVisible="false">
|
||||
<BindableListView ref.Name="listViewContacts" HorizontalAlwaysVisible="false" VerticalAlwaysVisible="false">
|
||||
<att.BoundsComposition-set AlignmentToParent="left:0 top:0 right:0 bottom:0"/>
|
||||
</ListView>
|
||||
</BindableListView>
|
||||
</Cell>
|
||||
</Table>
|
||||
</GroupBox>
|
||||
|
||||
@@ -17,11 +17,28 @@ namespace vl
|
||||
namespace description
|
||||
{
|
||||
#define _ ,
|
||||
IMPL_CPP_TYPE_INFO(demo::ICategory)
|
||||
IMPL_CPP_TYPE_INFO(demo::IViewModel)
|
||||
IMPL_CPP_TYPE_INFO(demo::MainWindow)
|
||||
|
||||
BEGIN_CLASS_MEMBER(demo::ICategory)
|
||||
CLASS_MEMBER_BASE(vl::reflection::IDescriptable)
|
||||
CLASS_MEMBER_METHOD(GetName, NO_PARAMETER);
|
||||
CLASS_MEMBER_METHOD(GetFolders, NO_PARAMETER);
|
||||
CLASS_MEMBER_METHOD(GetContacts, NO_PARAMETER);
|
||||
CLASS_MEMBER_PROPERTY_READONLY(Name, GetName)
|
||||
CLASS_MEMBER_PROPERTY_READONLY(Folders, GetFolders)
|
||||
CLASS_MEMBER_PROPERTY_READONLY(Contacts, GetContacts)
|
||||
END_CLASS_MEMBER(demo::ICategory)
|
||||
|
||||
BEGIN_CLASS_MEMBER(demo::IViewModel)
|
||||
CLASS_MEMBER_BASE(vl::reflection::IDescriptable)
|
||||
CLASS_MEMBER_METHOD(GetRootCategory, NO_PARAMETER);
|
||||
END_CLASS_MEMBER(demo::IViewModel)
|
||||
|
||||
BEGIN_CLASS_MEMBER(demo::MainWindow)
|
||||
CLASS_MEMBER_BASE(vl::presentation::controls::GuiWindow)
|
||||
CLASS_MEMBER_CONSTRUCTOR(demo::MainWindow*(), NO_PARAMETER)
|
||||
CLASS_MEMBER_CONSTRUCTOR(demo::MainWindow*(Ptr<demo::IViewModel>), { L"ViewModel" })
|
||||
|
||||
CLASS_MEMBER_GUIEVENT_HANDLER(commandBigIcon_Executed, vl::presentation::compositions::GuiEventArgs)
|
||||
CLASS_MEMBER_GUIEVENT_HANDLER(commandDeleteContact_Executed, vl::presentation::compositions::GuiEventArgs)
|
||||
@@ -33,6 +50,8 @@ namespace vl
|
||||
CLASS_MEMBER_GUIEVENT_HANDLER(commandNewFolder_Executed, vl::presentation::compositions::GuiEventArgs)
|
||||
CLASS_MEMBER_GUIEVENT_HANDLER(commandSmallIcon_Executed, vl::presentation::compositions::GuiEventArgs)
|
||||
CLASS_MEMBER_GUIEVENT_HANDLER(commandTile_Executed, vl::presentation::compositions::GuiEventArgs)
|
||||
|
||||
CLASS_MEMBER_PROPERTY_READONLY_FAST(ViewModel)
|
||||
END_CLASS_MEMBER(demo::MainWindow)
|
||||
|
||||
#undef _
|
||||
@@ -42,6 +61,8 @@ namespace vl
|
||||
public:
|
||||
void Load(ITypeManager* manager)
|
||||
{
|
||||
ADD_TYPE_INFO(demo::ICategory)
|
||||
ADD_TYPE_INFO(demo::IViewModel)
|
||||
ADD_TYPE_INFO(demo::MainWindow)
|
||||
}
|
||||
|
||||
|
||||
@@ -15,13 +15,30 @@ DO NOT MODIFY
|
||||
|
||||
namespace demo
|
||||
{
|
||||
class ICategory;
|
||||
class IViewModel;
|
||||
class MainWindow;
|
||||
|
||||
class ICategory : public virtual vl::reflection::IDescriptable, public vl::reflection::Description<ICategory>
|
||||
{
|
||||
public:
|
||||
virtual vl::WString GetName() = 0;
|
||||
virtual vl::Ptr<vl::reflection::description::IValueObservableList> GetFolders() = 0;
|
||||
virtual vl::Ptr<vl::reflection::description::IValueObservableList> GetContacts() = 0;
|
||||
};
|
||||
|
||||
class IViewModel : public virtual vl::reflection::IDescriptable, public vl::reflection::Description<IViewModel>
|
||||
{
|
||||
public:
|
||||
virtual vl::Ptr<demo::ICategory> GetRootCategory() = 0;
|
||||
};
|
||||
|
||||
template<typename TImpl>
|
||||
class MainWindow_ : public vl::presentation::controls::GuiWindow, public vl::presentation::GuiInstancePartialClass<vl::presentation::controls::GuiWindow>, public vl::reflection::Description<TImpl>
|
||||
{
|
||||
friend struct vl::reflection::description::CustomTypeDescriptorSelector<TImpl>;
|
||||
private:
|
||||
Ptr<demo::IViewModel> ViewModel_;
|
||||
protected:
|
||||
vl::presentation::controls::GuiToolstripCommand* commandBigIcon;
|
||||
vl::presentation::controls::GuiToolstripCommand* commandDeleteContact;
|
||||
@@ -33,11 +50,12 @@ namespace demo
|
||||
vl::presentation::controls::GuiToolstripCommand* commandNewFolder;
|
||||
vl::presentation::controls::GuiToolstripCommand* commandSmallIcon;
|
||||
vl::presentation::controls::GuiToolstripCommand* commandTile;
|
||||
vl::presentation::controls::GuiListView* listViewContacts;
|
||||
vl::presentation::controls::GuiTreeView* treeViewFolders;
|
||||
vl::presentation::controls::GuiBindableListView* listViewContacts;
|
||||
vl::presentation::controls::GuiBindableTreeView* treeViewFolders;
|
||||
|
||||
void InitializeComponents()
|
||||
void InitializeComponents(Ptr<demo::IViewModel> ViewModel)
|
||||
{
|
||||
ViewModel_ = ViewModel;
|
||||
if (InitializeFromResource())
|
||||
{
|
||||
GUI_INSTANCE_REFERENCE(commandBigIcon);
|
||||
@@ -55,6 +73,7 @@ namespace demo
|
||||
}
|
||||
else
|
||||
{
|
||||
ViewModel_ = 0;
|
||||
}
|
||||
}
|
||||
public:
|
||||
@@ -75,6 +94,11 @@ namespace demo
|
||||
,treeViewFolders(0)
|
||||
{
|
||||
}
|
||||
|
||||
Ptr<demo::IViewModel> GetViewModel()
|
||||
{
|
||||
return ViewModel_;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -84,6 +108,8 @@ namespace vl
|
||||
{
|
||||
namespace description
|
||||
{
|
||||
DECL_TYPE_INFO(demo::ICategory)
|
||||
DECL_TYPE_INFO(demo::IViewModel)
|
||||
DECL_TYPE_INFO(demo::MainWindow)
|
||||
|
||||
}
|
||||
|
||||
@@ -62,9 +62,9 @@ namespace demo
|
||||
|
||||
// #endregion CLASS_MEMBER_GUIEVENT_HANDLER
|
||||
|
||||
MainWindow::MainWindow()
|
||||
MainWindow::MainWindow(Ptr<demo::IViewModel> ViewModel)
|
||||
{
|
||||
InitializeComponents();
|
||||
InitializeComponents(ViewModel);
|
||||
OnCreate();
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace demo
|
||||
void OnDestroy();
|
||||
// #endregion CLASS_MEMBER_GUIEVENT_HANDLER
|
||||
public:
|
||||
MainWindow();
|
||||
MainWindow(Ptr<demo::IViewModel> ViewModel);
|
||||
~MainWindow();
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user