diff --git a/ui/confview.go b/ui/confview.go index 9db43f86..581a98dd 100644 --- a/ui/confview.go +++ b/ui/confview.go @@ -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 { diff --git a/ui/detailview.go b/ui/detailview.go index c0de63e2..13839f6c 100644 --- a/ui/detailview.go +++ b/ui/detailview.go @@ -86,6 +86,8 @@ type ConfSectionView struct { toggleService func(bool) } +var lastEditSection = -1 + func NewConfSectionView() *ConfSectionView { csv := new(ConfSectionView) return csv @@ -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 { @@ -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 { @@ -265,6 +274,9 @@ func (t *ConfSectionView) View() Widget { OnCurrentIndexChanged: func() { sectionDataBinder.Reset() }, + OnItemActivated: func() { + t.onEditSection(true) + }, }, }, } diff --git a/ui/listview.go b/ui/listview.go index 106e8f19..168cbfa3 100644 --- a/ui/listview.go +++ b/ui/listview.go @@ -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 }