Skip to content

Commit

Permalink
Add double click event
Browse files Browse the repository at this point in the history
  • Loading branch information
koho committed Dec 16, 2020
1 parent 5553e94 commit eea7d89
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
21 changes: 10 additions & 11 deletions ui/confview.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,25 +183,24 @@ func (t *ConfView) onExport() {

func (t *ConfView) Initialize() {
t.ToolbarView.Initialize()
t.ToolbarView.addAction.Triggered().Attach(func() {
t.onEditConf(nil)
})
t.ToolbarView.addMenuAction.Triggered().Attach(func() {
editCB := func() {
t.onEditConf(t.ConfListView.CurrentConf())
}
newCB := func() {
t.onEditConf(nil)
})
}
t.ToolbarView.addAction.Triggered().Attach(newCB)
t.ToolbarView.addMenuAction.Triggered().Attach(newCB)
t.ToolbarView.importAction.Triggered().Attach(t.onImport)
t.ToolbarView.deleteAction.Triggered().Attach(t.onDelete)
t.ToolbarView.exportAction.Triggered().Attach(t.onExport)
t.ConfListView.editAction.Triggered().Attach(func() {
t.onEditConf(t.ConfListView.CurrentConf())
})
t.ConfListView.editAction.Triggered().Attach(editCB)
t.ConfListView.editAction.SetDefault(true)
t.ConfListView.newAction.Triggered().Attach(func() {
t.onEditConf(nil)
})
t.ConfListView.newAction.Triggered().Attach(newCB)
t.ConfListView.importAction.Triggered().Attach(t.onImport)
t.ConfListView.exportAction.Triggered().Attach(t.onExport)
t.ConfListView.deleteAction.Triggered().Attach(t.onDelete)
t.ConfListView.view.ItemActivated().Attach(editCB)
}

type ConfListView struct {
Expand Down
12 changes: 12 additions & 0 deletions ui/detailview.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ type ConfSectionView struct {
toggleService func(bool)
}

var lastEditSection = -1

func NewConfSectionView() *ConfSectionView {
csv := new(ConfSectionView)
return csv
Expand All @@ -103,6 +105,10 @@ func (t *ConfSectionView) SetModel(conf *config.Config) {

func (t *ConfSectionView) ResetModel() {
t.sectionView.SetModel(t.model)
if lastEditSection >= 0 && t.model != nil && t.model.Count() > 0 {
t.sectionView.SetCurrentIndex(lastEditSection)
lastEditSection = -1
}
}

func (t *ConfSectionView) mustSelectConf() bool {
Expand Down Expand Up @@ -160,6 +166,9 @@ func (t *ConfSectionView) onEditSection(edit bool) {
}
}
if ret == walk.DlgCmdOK {
if edit {
lastEditSection = t.sectionView.CurrentIndex()
}
t.ResetModel()
t.model.conf.Save()
if running, _ := services.QueryService(t.model.conf.Name); running {
Expand Down Expand Up @@ -265,6 +274,9 @@ func (t *ConfSectionView) View() Widget {
OnCurrentIndexChanged: func() {
sectionDataBinder.Reset()
},
OnItemActivated: func() {
t.onEditSection(true)
},
},
},
}
Expand Down
4 changes: 4 additions & 0 deletions ui/listview.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ func (m *ConfSectionModel) Items() interface{} {
return m.conf.Items
}

func (m *ConfSectionModel) Count() int {
return len(m.conf.Items)
}

type LogModel struct {
walk.ReflectTableModelBase
items []*struct{ Text string }
Expand Down

0 comments on commit eea7d89

Please sign in to comment.