List view

Most of the work for our email list was done in the preceding model code—now we need to connect it to the user interface. The following code sets up a walk.TreeView class that we use to keep track of the current item and assigns it to the declarative TreeView. After that, the model is set and then we pass a function that will be informed when the current item changes:

emailList *walk.TreeView

TreeView{
AssignTo: &g.emailList,
Model: model,
OnCurrentItemChanged: func() {
item := g.emailList.CurrentItem()

if email, ok := item.(*EmailModel); ok {
g.SetMessage(email.email)
}
},
},

With all that in place, the application will load the email details from the current email message using model.Server.CurrentMessage() via the default DataSource of the DataBinder. When the main list is clicked, the function passed to OnCurrentItemChanged checks that the item is an EmailModel and, if so, updates the detail view. Finally, we need to set up the model that will be used in the preceding code, as follows:

model := NewEmailClientModel()
model.SetServer(client.NewTestServer())

This model is used to set the list content and also to set the default content of the detail view. When built and run, the application should now look like a complete, albeit basic, email client:

Our email interface with some test data loaded
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.163.13