Changed naming from controller to viewmodel
This commit is contained in:
parent
c848c2332f
commit
17bec4ede5
24
baseview.go
24
baseview.go
@ -19,7 +19,7 @@ type BaseView struct {
|
||||
id string
|
||||
|
||||
// The controller
|
||||
Ctrl Controller
|
||||
ViewModel ViewModel
|
||||
|
||||
// Root CanvasObject of the view
|
||||
CanvasObject fyne.CanvasObject
|
||||
@ -42,29 +42,29 @@ type BaseView struct {
|
||||
// }
|
||||
func NewBaseView(
|
||||
concreteView View,
|
||||
controller Controller,
|
||||
viewModel ViewModel,
|
||||
) *BaseView {
|
||||
v := new(BaseView)
|
||||
v.id = uuid.NewString()
|
||||
v.concreteView = concreteView
|
||||
v.Ctrl = controller
|
||||
v.ViewModel = viewModel
|
||||
return v
|
||||
}
|
||||
|
||||
func NewBaseViewWithScreen(
|
||||
concreteView View,
|
||||
controller Controller,
|
||||
viewModel ViewModel,
|
||||
filesystem embed.FS,
|
||||
screenName string,
|
||||
localizer *i18n.Localizer,
|
||||
) *BaseView {
|
||||
v := NewBaseView(concreteView, controller)
|
||||
v := NewBaseView(concreteView, viewModel)
|
||||
|
||||
var err error
|
||||
v.ScreenHandler, err = NewScreenHandler(
|
||||
filesystem,
|
||||
screenName,
|
||||
controller,
|
||||
viewModel,
|
||||
localizer)
|
||||
if err != nil {
|
||||
LogWindowError(v, LoadScreen, err)
|
||||
@ -95,8 +95,8 @@ func (v BaseView) Title() string {
|
||||
|
||||
// Initialize initializes the view
|
||||
func (v *BaseView) Initialize() fyne.CanvasObject {
|
||||
LogWindowEvent(v, Initialize)
|
||||
if err := v.Ctrl.Initialize(); err != nil {
|
||||
//LogWindowEvent(v, Initialize)
|
||||
if err := v.ViewModel.Initialize(); err != nil {
|
||||
LogWindowError(v, Initialize, err)
|
||||
}
|
||||
if v.ScreenHandler != nil && v.ScreenDefinition() != nil {
|
||||
@ -112,7 +112,7 @@ func (v *BaseView) Initialize() fyne.CanvasObject {
|
||||
|
||||
// Refresh is called when the view needs a full update
|
||||
func (v *BaseView) Refresh() {
|
||||
LogWindowEvent(v, Refresh)
|
||||
//LogWindowEvent(v, Refresh)
|
||||
if v.CanvasObject != nil {
|
||||
v.CanvasObject.Refresh()
|
||||
}
|
||||
@ -120,13 +120,13 @@ func (v *BaseView) Refresh() {
|
||||
|
||||
// OnShow is called when the view becomes visible on the screen
|
||||
func (v *BaseView) OnShow() {
|
||||
LogWindowEvent(v, OnShow)
|
||||
//LogWindowEvent(v, OnShow)
|
||||
}
|
||||
|
||||
func (v *BaseView) OnHide() {
|
||||
LogWindowEvent(v, OnHide)
|
||||
//LogWindowEvent(v, OnHide)
|
||||
}
|
||||
|
||||
func (v *BaseView) GetBinding(bindingName string) binding.DataItem {
|
||||
return v.Ctrl.GetBinding(bindingName)
|
||||
return v.ViewModel.GetBinding(bindingName)
|
||||
}
|
||||
|
44
dialog.go
44
dialog.go
@ -58,7 +58,7 @@ type BaseDialog struct {
|
||||
Data binding.DataItem
|
||||
focusItem fyne.Focusable
|
||||
|
||||
Ctrl DialogController
|
||||
ViewModel DialogViewModel
|
||||
*ScreenHandler
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ func NewBaseDialog(
|
||||
concreteDialog Dialog,
|
||||
name DialogName,
|
||||
kind DialogKind,
|
||||
controller DialogController,
|
||||
viewModel DialogViewModel,
|
||||
parent fyne.Window,
|
||||
confirm OnConfirmFn,
|
||||
) *BaseDialog {
|
||||
@ -77,7 +77,7 @@ func NewBaseDialog(
|
||||
dlgKind: kind,
|
||||
window: parent,
|
||||
onConfirm: confirm,
|
||||
Ctrl: controller,
|
||||
ViewModel: viewModel,
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,7 +85,7 @@ func NewBaseDialogWithScreen(
|
||||
concreteDialog Dialog,
|
||||
name DialogName,
|
||||
kind DialogKind,
|
||||
controller DialogController,
|
||||
viewModel DialogViewModel,
|
||||
parent fyne.Window,
|
||||
confirm OnConfirmFn,
|
||||
filesystem embed.FS,
|
||||
@ -93,12 +93,12 @@ func NewBaseDialogWithScreen(
|
||||
localizer *i18n.Localizer,
|
||||
) *BaseDialog {
|
||||
d := NewBaseDialog(
|
||||
concreteDialog, name, kind, controller,
|
||||
concreteDialog, name, kind, viewModel,
|
||||
parent, confirm)
|
||||
|
||||
var err error
|
||||
d.ScreenHandler, err = NewScreenHandler(
|
||||
filesystem, screenName, controller, localizer)
|
||||
filesystem, screenName, viewModel, localizer)
|
||||
if err != nil {
|
||||
LogWindowError(d, LoadScreen, err)
|
||||
return nil
|
||||
@ -110,7 +110,7 @@ func NewBaseDialogWithData(
|
||||
concreteDialog Dialog,
|
||||
name DialogName,
|
||||
kind DialogKind,
|
||||
controller DialogController,
|
||||
viewModel DialogViewModel,
|
||||
parent fyne.Window,
|
||||
confirm OnConfirmFn,
|
||||
data binding.DataItem,
|
||||
@ -123,7 +123,7 @@ func NewBaseDialogWithData(
|
||||
window: parent,
|
||||
onConfirm: confirm,
|
||||
Data: data,
|
||||
Ctrl: controller,
|
||||
ViewModel: viewModel,
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,7 +131,7 @@ func NewBaseDialogWithDataAndScreen(
|
||||
concreteDialog Dialog,
|
||||
name DialogName,
|
||||
kind DialogKind,
|
||||
controller DialogController,
|
||||
viewModel DialogViewModel,
|
||||
parent fyne.Window,
|
||||
confirm OnConfirmFn,
|
||||
data binding.DataItem,
|
||||
@ -140,12 +140,12 @@ func NewBaseDialogWithDataAndScreen(
|
||||
localizer *i18n.Localizer,
|
||||
) *BaseDialog {
|
||||
d := NewBaseDialogWithData(
|
||||
concreteDialog, name, kind, controller,
|
||||
concreteDialog, name, kind, viewModel,
|
||||
parent, confirm, data)
|
||||
|
||||
var err error
|
||||
d.ScreenHandler, err = NewScreenHandler(
|
||||
filesystem, screenName, controller, localizer)
|
||||
filesystem, screenName, viewModel, localizer)
|
||||
if err != nil {
|
||||
LogWindowError(d, LoadScreen, err)
|
||||
return nil
|
||||
@ -215,7 +215,7 @@ func (d BaseDialog) Title() string {
|
||||
}
|
||||
|
||||
func (d *BaseDialog) Initialize() fyne.CanvasObject {
|
||||
if err := d.Ctrl.Initialize(d.Data); err != nil {
|
||||
if err := d.ViewModel.Initialize(d.Data); err != nil {
|
||||
LogWindowError(d, Initialize, err)
|
||||
}
|
||||
if d.ScreenHandler != nil && d.ScreenDefinition() != nil {
|
||||
@ -236,11 +236,11 @@ func (d *BaseDialog) Refresh() {
|
||||
}
|
||||
|
||||
func (d *BaseDialog) OnShow() {
|
||||
LogWindowEvent(d, OnShow)
|
||||
//LogWindowEvent(d, OnShow)
|
||||
}
|
||||
|
||||
func (d *BaseDialog) OnHide() {
|
||||
LogWindowEvent(d, OnHide)
|
||||
//LogWindowEvent(d, OnHide)
|
||||
}
|
||||
|
||||
func (d *BaseDialog) OnClose(confirmed bool) {
|
||||
@ -264,14 +264,14 @@ func NewFormDialog(
|
||||
concreteDialog Dialog,
|
||||
name DialogName,
|
||||
kind DialogKind,
|
||||
controller DialogController,
|
||||
viewModel DialogViewModel,
|
||||
parent fyne.Window,
|
||||
confirm OnConfirmFn,
|
||||
itemsFn FormDialogItemsFn,
|
||||
) *FormDialog {
|
||||
return &FormDialog{
|
||||
BaseDialog: NewBaseDialog(
|
||||
concreteDialog, name, kind, controller, parent, confirm),
|
||||
concreteDialog, name, kind, viewModel, parent, confirm),
|
||||
itemsFn: itemsFn,
|
||||
confirmLabel: "OK",
|
||||
dismissLabel: "Cancel",
|
||||
@ -282,7 +282,7 @@ func NewFormDialogWithScreen(
|
||||
concreteDialog Dialog,
|
||||
name DialogName,
|
||||
kind DialogKind,
|
||||
controller DialogController,
|
||||
viewModel DialogViewModel,
|
||||
parent fyne.Window,
|
||||
confirm OnConfirmFn,
|
||||
filesystem embed.FS,
|
||||
@ -291,7 +291,7 @@ func NewFormDialogWithScreen(
|
||||
) *FormDialog {
|
||||
return &FormDialog{
|
||||
BaseDialog: NewBaseDialogWithScreen(
|
||||
concreteDialog, name, kind, controller, parent, confirm,
|
||||
concreteDialog, name, kind, viewModel, parent, confirm,
|
||||
filesystem, screenName, localizer),
|
||||
confirmLabel: "OK",
|
||||
dismissLabel: "Cancel",
|
||||
@ -302,7 +302,7 @@ func NewformDialogWithData(
|
||||
concreteDialog Dialog,
|
||||
name DialogName,
|
||||
kind DialogKind,
|
||||
controller DialogController,
|
||||
viewModel DialogViewModel,
|
||||
parent fyne.Window,
|
||||
confirm OnConfirmFn,
|
||||
itemsFn FormDialogItemsFn,
|
||||
@ -310,7 +310,7 @@ func NewformDialogWithData(
|
||||
) *FormDialog {
|
||||
return &FormDialog{
|
||||
BaseDialog: NewBaseDialogWithData(
|
||||
concreteDialog, name, kind, controller, parent, confirm, data),
|
||||
concreteDialog, name, kind, viewModel, parent, confirm, data),
|
||||
itemsFn: itemsFn,
|
||||
confirmLabel: "OK",
|
||||
dismissLabel: "Cancel",
|
||||
@ -321,7 +321,7 @@ func NewFormDialogWithDataAndScreen(
|
||||
concreteDialog Dialog,
|
||||
name DialogName,
|
||||
kind DialogKind,
|
||||
controller DialogController,
|
||||
viewModel DialogViewModel,
|
||||
parent fyne.Window,
|
||||
confirm OnConfirmFn,
|
||||
data binding.DataItem,
|
||||
@ -331,7 +331,7 @@ func NewFormDialogWithDataAndScreen(
|
||||
) *FormDialog {
|
||||
return &FormDialog{
|
||||
BaseDialog: NewBaseDialogWithDataAndScreen(
|
||||
concreteDialog, name, kind, controller, parent, confirm, data,
|
||||
concreteDialog, name, kind, viewModel, parent, confirm, data,
|
||||
filesystem, screenName, localizer),
|
||||
confirmLabel: "OK",
|
||||
dismissLabel: "Cancel",
|
||||
|
@ -3,6 +3,7 @@ package ui
|
||||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"bitbucket.org/hevanto/ui/screen"
|
||||
@ -24,7 +25,7 @@ import (
|
||||
type ScreenHandler struct {
|
||||
screenDefinition *screen.Screen
|
||||
localizer *i18n.Localizer
|
||||
ctrl ScreenController
|
||||
viewModel BaseViewModel
|
||||
|
||||
// Map of screen elements that got an id assigned
|
||||
exportedElements map[string]*screen.UIElement
|
||||
@ -56,12 +57,12 @@ type ScreenHandler struct {
|
||||
func NewScreenHandler(
|
||||
filesystem embed.FS,
|
||||
screenName string,
|
||||
ctrl ScreenController,
|
||||
viewModel BaseViewModel,
|
||||
localizer *i18n.Localizer,
|
||||
) (h *ScreenHandler, err error) {
|
||||
h = new(ScreenHandler)
|
||||
|
||||
h.ctrl = ctrl
|
||||
h.viewModel = viewModel
|
||||
h.localizer = localizer
|
||||
|
||||
def, err := screen.New(filesystem, screenName, h)
|
||||
@ -217,7 +218,7 @@ func (h *ScreenHandler) RegisterOnValidationChangedHandler(
|
||||
// This function forwards the call to the controller. In the controller the
|
||||
// required bindings should be mapped to the screen elements.
|
||||
func (h *ScreenHandler) GetBinding(name string) binding.DataItem {
|
||||
return h.ctrl.GetBinding(name)
|
||||
return h.viewModel.GetBinding(name)
|
||||
}
|
||||
|
||||
// GetValidator returns the validator with the given name.
|
||||
@ -225,7 +226,7 @@ func (h *ScreenHandler) GetBinding(name string) binding.DataItem {
|
||||
// This function forwards the call to the controller. In the controller the
|
||||
// required validators should be mapped to the screen elements.
|
||||
func (h *ScreenHandler) GetValidator(name string) fyne.StringValidator {
|
||||
return h.ctrl.GetValidator(name)
|
||||
return h.viewModel.GetValidator(name)
|
||||
}
|
||||
|
||||
// GetElement returns the UIElement with the given ID.
|
||||
@ -236,10 +237,12 @@ func (h *ScreenHandler) GetValidator(name string) fyne.StringValidator {
|
||||
// is present it's advices to do hide and show operations on the decorator, and
|
||||
// all other operators on the object.
|
||||
func (h *ScreenHandler) GetElement(id string) *screen.UIElement {
|
||||
if elem, ok := h.exportedElements[id]; ok {
|
||||
return elem
|
||||
}
|
||||
elem, ok := h.exportedElements[id]
|
||||
if !ok {
|
||||
log.Printf("element %s not found", id)
|
||||
return nil
|
||||
}
|
||||
return elem
|
||||
}
|
||||
|
||||
// GetLocalizer returns the i18n.Localizer used for localization.
|
||||
@ -257,6 +260,7 @@ func (h *ScreenHandler) GetIcon(iconName string) fyne.Resource {
|
||||
iconName := strings.SplitN(iconName, ".", 2)[1]
|
||||
return theme.DefaultTheme().Icon(fyne.ThemeIconName(iconName))
|
||||
}
|
||||
log.Printf("icon %s not found", iconName)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -264,6 +268,7 @@ func (h *ScreenHandler) GetIcon(iconName string) fyne.Resource {
|
||||
func (h *ScreenHandler) GetListItemTemplate(name string) screen.ListItemTemplateFn {
|
||||
fn, ok := h.listItemTemplates[name]
|
||||
if !ok {
|
||||
log.Printf("list template %s not found", name)
|
||||
return nil
|
||||
}
|
||||
return fn
|
||||
@ -273,6 +278,7 @@ func (h *ScreenHandler) GetListItemTemplate(name string) screen.ListItemTemplate
|
||||
func (h *ScreenHandler) GetListDataItemRenderer(name string) screen.ListDataItemRendererFn {
|
||||
fn, ok := h.listDataItemRenderers[name]
|
||||
if !ok {
|
||||
log.Printf("list renderer %s not found", name)
|
||||
return nil
|
||||
}
|
||||
return fn
|
||||
@ -282,6 +288,7 @@ func (h *ScreenHandler) GetListDataItemRenderer(name string) screen.ListDataItem
|
||||
func (h *ScreenHandler) GetListItemRenderer(name string) screen.ListItemRendererFn {
|
||||
fn, ok := h.listItemRenderers[name]
|
||||
if !ok {
|
||||
log.Printf("list renderer %s not found", name)
|
||||
return nil
|
||||
}
|
||||
return fn
|
||||
@ -291,6 +298,7 @@ func (h *ScreenHandler) GetListItemRenderer(name string) screen.ListItemRenderer
|
||||
func (h *ScreenHandler) GetListLength(name string) screen.ListLengthFn {
|
||||
fn, ok := h.listLengths[name]
|
||||
if !ok {
|
||||
log.Printf("list length %s not found", name)
|
||||
return nil
|
||||
}
|
||||
return fn
|
||||
@ -300,6 +308,7 @@ func (h *ScreenHandler) GetListLength(name string) screen.ListLengthFn {
|
||||
func (h *ScreenHandler) GetOnListItemSelectedHandler(name string) screen.ListItemHandlerFn {
|
||||
fn, ok := h.onListItemSelectedHandlers[name]
|
||||
if !ok {
|
||||
log.Printf("list item selected handler %s not found", name)
|
||||
return nil
|
||||
}
|
||||
return fn
|
||||
@ -309,6 +318,7 @@ func (h *ScreenHandler) GetOnListItemSelectedHandler(name string) screen.ListIte
|
||||
func (h *ScreenHandler) GetOnListItemUnselectedHandler(name string) screen.ListItemHandlerFn {
|
||||
fn, ok := h.onListItemUnselectedHandlers[name]
|
||||
if !ok {
|
||||
log.Printf("list item unselected handler %s not found", name)
|
||||
return nil
|
||||
}
|
||||
return fn
|
||||
@ -318,6 +328,7 @@ func (h *ScreenHandler) GetOnListItemUnselectedHandler(name string) screen.ListI
|
||||
func (h *ScreenHandler) GetOnClickedHandler(name string) screen.ClickHandlerFn {
|
||||
fn, ok := h.onClickedHandlers[name]
|
||||
if !ok {
|
||||
log.Printf("clicked handler %s not found", name)
|
||||
return nil
|
||||
}
|
||||
return fn
|
||||
@ -327,6 +338,7 @@ func (h *ScreenHandler) GetOnClickedHandler(name string) screen.ClickHandlerFn {
|
||||
func (h *ScreenHandler) GetOnCheckChangedHandler(name string) screen.CheckHandlerFn {
|
||||
fn, ok := h.onCheckChangedHandlers[name]
|
||||
if !ok {
|
||||
log.Printf("check changed handler %s not found", name)
|
||||
return nil
|
||||
}
|
||||
return fn
|
||||
@ -336,6 +348,7 @@ func (h *ScreenHandler) GetOnCheckChangedHandler(name string) screen.CheckHandle
|
||||
func (h *ScreenHandler) GetOnDateSelectedHandler(name string) screen.DateSelectedHandlerFn {
|
||||
fn, ok := h.onDateSelectedHandlers[name]
|
||||
if !ok {
|
||||
log.Printf("date selected handler %s not found", name)
|
||||
return nil
|
||||
}
|
||||
return fn
|
||||
@ -345,6 +358,7 @@ func (h *ScreenHandler) GetOnDateSelectedHandler(name string) screen.DateSelecte
|
||||
func (h *ScreenHandler) GetOnValidationChangedHandler(name string) screen.ValidationChangedHandlerFn {
|
||||
fn, ok := h.onValidationChangedHandlers[name]
|
||||
if !ok {
|
||||
log.Printf("validation changed handler %s not found", name)
|
||||
return nil
|
||||
}
|
||||
return fn
|
||||
|
@ -29,7 +29,7 @@ type TabbedView struct {
|
||||
|
||||
// NewTabbedView creates a new tabbed view
|
||||
func NewTabbedView(
|
||||
controller Controller,
|
||||
controller ViewModel,
|
||||
tabLocation container.TabLocation,
|
||||
tabview ...View,
|
||||
) *TabbedView {
|
||||
|
@ -5,20 +5,20 @@ import (
|
||||
"fyne.io/fyne/v2/data/binding"
|
||||
)
|
||||
|
||||
type ScreenController interface {
|
||||
type BaseViewModel interface {
|
||||
GetBinding(string) binding.DataItem
|
||||
GetValidator(string) fyne.StringValidator
|
||||
}
|
||||
|
||||
type Controller interface {
|
||||
ScreenController
|
||||
type ViewModel interface {
|
||||
BaseViewModel
|
||||
|
||||
Initialize() error
|
||||
RefreshData() error
|
||||
}
|
||||
|
||||
type DialogController interface {
|
||||
ScreenController
|
||||
type DialogViewModel interface {
|
||||
BaseViewModel
|
||||
|
||||
Initialize(data binding.DataItem) error
|
||||
RefreshData() error
|
Loading…
Reference in New Issue
Block a user