代码拉取完成,页面将自动刷新
package main
import (
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/widgets"
)
func (s *myWindow) showCategores(menubar *widgets.QMenuBar) {
s.categories = menubar.AddMenu2(T("Categories"))
newcategory := s.categories.AddAction(T("New Category"))
newcategory.ConnectTriggered(func(b bool) {
var ok bool
name := widgets.QInputDialog_GetText(s.window, T("New Category Name"), T("Category"), 0, "", &ok, core.Qt__Dialog, 0)
if ok {
id := s.db.AddCategory(name)
s.addCategoryMenuItem(id, name)
}
})
renameCategory := s.categories.AddAction(T("Rename Category"))
renameCategory.ConnectTriggered(func(b bool) {
var ok bool
name := widgets.QInputDialog_GetText(s.window, T("Rename Category")+" : "+s.categoryName, T("Rename Category")+" : "+s.categoryName, 0, "", &ok, core.Qt__Dialog, 0)
if ok {
c := s.categoryItem
id, ok := c.Data().ToInterface().(int)
if ok && id > 0 {
s.db.RenameCategory(id, name)
c.SetText(name)
s.categoryName = name
s.model.SetHorizontalHeaderLabels([]string{T("Diary List") + " - " + s.categoryName})
s.modelFind.SetHorizontalHeaderLabels([]string{T("Result List") + " - " + s.categoryName})
}
}
})
removeCategory := s.categories.AddAction(T("Remove Category"))
removeCategory.ConnectTriggered(func(b bool) {
s.removeCurCategory()
})
s.categories.AddSeparator()
}
func (s *myWindow) loadUserCategorys() {
c := s.addCategoryMenuItem(0, T("Default"))
categoryDict := s.db.GetCategories()
for id, name := range categoryDict {
s.addCategoryMenuItem(id, name)
}
c.Triggered(true)
}
func (s *myWindow) addCategoryMenuItem(id int, name string) *widgets.QAction {
c := s.categories.AddAction(name)
c.SetCheckable(true)
c.SetData(core.NewQVariant1(id))
c.ConnectTriggered(func(b bool) {
data, ok := c.Data().ToInterface().(int)
if ok == false {
return
}
s.saveCurDiary()
s.curDiary.Item = nil
s.category = data
s.categoryName = c.Text()
//set last selected item to false
if s.categoryItem != nil && b {
s.categoryItem.SetChecked(false)
}
s.categoryItem = c
s.showCurCategory(data)
c.SetChecked(true)
})
return c
}
func (s *myWindow) showCurCategory(c int) {
s.db.setCategory(c)
s.clearModel()
s.clearModelFind()
s.addYearMonthsFromDb()
}
func (s *myWindow) removeCurCategory() {
if s.category == 0 {
widgets.QMessageBox_Information(s.window, T("Error"), T("Can not remove default category."), widgets.QMessageBox__Ok, widgets.QMessageBox__Ok)
return
}
ret := widgets.QMessageBox_Question(s.window, T("Remove Category")+" : "+s.categoryName, T("Are you sure? All files in this category will move to default category."), widgets.QMessageBox__Yes|widgets.QMessageBox__No, widgets.QMessageBox__Yes)
if ret == widgets.QMessageBox__No {
return
}
s.db.RemoveCategory(s.category)
s.categories.RemoveAction(s.categoryItem)
s.categoryItem = nil
for _, v := range s.categories.Children() {
item := widgets.NewQActionFromPointer(v.Pointer())
id, ok := item.Data().ToInterface().(int)
if ok && id == 0 {
item.Triggered(true)
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。