mirror of
https://github.com/nwg-piotr/nwg-drawer.git
synced 2024-08-16 17:20:22 +03:00
search by category
This commit is contained in:
parent
d48f9a31d3
commit
6033eb2e51
31
main.go
31
main.go
@ -100,6 +100,9 @@ var (
|
||||
buttonBox *gtk.EventBox
|
||||
confirmationBox *gtk.Box
|
||||
userDirsMap map[string]string
|
||||
appFlowBox *gtk.FlowBox
|
||||
appFlowBoxWrapper *gtk.Box
|
||||
catButtons []*gtk.Button
|
||||
)
|
||||
|
||||
// Flags
|
||||
@ -329,20 +332,36 @@ func main() {
|
||||
wrapper, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
||||
searchEntry = setUpSearchEntry()
|
||||
searchEntry.SetMaxWidthChars(30)
|
||||
wrapper.PackStart(searchEntry, true, false, 0)
|
||||
emptyBox, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
||||
wrapper.PackEnd(searchEntry, true, false, 0)
|
||||
rightColumn.PackStart(wrapper, false, false, 10)
|
||||
|
||||
wrapper.PackEnd(emptyBox, false, false, 0)
|
||||
wrapper, _ = gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
||||
categoriesMenuBar := setUpCategoriesButtonBox()
|
||||
wrapper.PackStart(categoriesMenuBar, true, false, 0)
|
||||
rightColumn.PackStart(wrapper, false, false, 10)
|
||||
|
||||
backButton = setUpBackButton()
|
||||
wrapper.PackEnd(backButton, false, false, 10)
|
||||
/*wrapper.PackEnd(backButton, false, false, 10)*/
|
||||
|
||||
wrapper, _ = gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
||||
resultWrapper, _ = gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
|
||||
rightColumn.PackStart(resultWrapper, true, true, 0)
|
||||
wrapper.PackStart(resultWrapper, true, false, 0)
|
||||
|
||||
rightColumn.PackStart(wrapper, true, true, 0)
|
||||
|
||||
resultWindow, _ = gtk.ScrolledWindowNew(nil, nil)
|
||||
resultWindow.SetPolicy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
|
||||
resultWindow.Connect("enter-notify-event", func() {
|
||||
cancelClose()
|
||||
restoreButtonBox()
|
||||
})
|
||||
resultWrapper.PackStart(resultWindow, true, true, 0)
|
||||
|
||||
appFlowBoxWrapper, _ = gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
|
||||
resultWindow.Add(appFlowBoxWrapper)
|
||||
appFlowBox = setUpAppsFlowBox(nil, "")
|
||||
|
||||
win.ShowAll()
|
||||
emptyBox.SetSizeRequest(leftColumn.GetAllocatedWidth(), 0)
|
||||
|
||||
backButton.Hide()
|
||||
|
||||
|
113
uicomponents.go
113
uicomponents.go
@ -119,6 +119,64 @@ func setUpCategoriesListBox() *gtk.ListBox {
|
||||
return listBox
|
||||
}
|
||||
|
||||
func setUpCategoriesButtonBox() *gtk.EventBox {
|
||||
lists := map[string][]string{
|
||||
"utility": listUtility,
|
||||
"development": listDevelopment,
|
||||
"game": listGame,
|
||||
"graphics": listGraphics,
|
||||
"internet-and-network": listInternetAndNetwork,
|
||||
"office": listOffice,
|
||||
"audio-video": listAudioVideo,
|
||||
"system-tools": listSystemTools,
|
||||
"other": listOther,
|
||||
}
|
||||
|
||||
eventBox, _ := gtk.EventBoxNew()
|
||||
eventBox.Connect("enter-notify-event", func() {
|
||||
cancelClose()
|
||||
})
|
||||
hBox, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
||||
eventBox.Add(hBox)
|
||||
button, _ := gtk.ButtonNewWithLabel("All")
|
||||
button.Connect("clicked", func(item *gtk.Button) {
|
||||
//clearSearchResult()
|
||||
searchEntry.GrabFocus()
|
||||
searchEntry.SetText("")
|
||||
appFlowBox = setUpAppsFlowBox(nil, "")
|
||||
for _, btn := range catButtons {
|
||||
btn.SetImagePosition(gtk.POS_LEFT)
|
||||
btn.SetSizeRequest(0, 0)
|
||||
}
|
||||
})
|
||||
hBox.PackStart(button, false, false, 0)
|
||||
|
||||
for _, cat := range categories {
|
||||
if isSupposedToShowUp(cat.Name) {
|
||||
button, _ = gtk.ButtonNewFromIconName(cat.Icon, gtk.ICON_SIZE_MENU)
|
||||
catButtons = append(catButtons, button)
|
||||
button.SetLabel(cat.DisplayName)
|
||||
hBox.PackStart(button, false, false, 0)
|
||||
name := cat.Name
|
||||
b := *button
|
||||
button.Connect("clicked", func(item *gtk.Button) {
|
||||
//clearSearchResult()
|
||||
searchEntry.GrabFocus()
|
||||
searchEntry.SetText("")
|
||||
// !!! since gotk3 FlowBox type does not implement set_filter_func, we need to rebuild appFlowBox
|
||||
appFlowBox = setUpAppsFlowBox(lists[name], "")
|
||||
for _, btn := range catButtons {
|
||||
btn.SetImagePosition(gtk.POS_LEFT)
|
||||
}
|
||||
w := b.GetAllocatedWidth()
|
||||
b.SetImagePosition(gtk.POS_TOP)
|
||||
b.SetSizeRequest(w, 0)
|
||||
})
|
||||
}
|
||||
}
|
||||
return eventBox
|
||||
}
|
||||
|
||||
func isSupposedToShowUp(catName string) bool {
|
||||
result := catName == "utility" && notEmpty(listUtility) ||
|
||||
catName == "development" && notEmpty(listDevelopment) ||
|
||||
@ -219,10 +277,6 @@ func setUpBackButton() *gtk.Box {
|
||||
})
|
||||
hBox.PackEnd(button, false, true, 0)
|
||||
|
||||
/*sep, _ := gtk.SeparatorNew(gtk.ORIENTATION_HORIZONTAL)
|
||||
sep.SetCanFocus(false)
|
||||
vBox.Add(sep)*/
|
||||
|
||||
return vBox
|
||||
}
|
||||
|
||||
@ -345,6 +399,57 @@ func setUpCategorySearchResult(searchPhrase string) *gtk.ListBox {
|
||||
return listBox
|
||||
}
|
||||
|
||||
func setUpAppsFlowBox(categoryList []string, searchPhrase string) *gtk.FlowBox {
|
||||
if appFlowBox != nil {
|
||||
appFlowBox.Destroy()
|
||||
}
|
||||
flowBox, _ := gtk.FlowBoxNew()
|
||||
flowBox.SetMinChildrenPerLine(6)
|
||||
flowBox.SetColumnSpacing(20)
|
||||
flowBox.SetRowSpacing(20)
|
||||
for _, entry := range desktopEntries {
|
||||
if categoryList != nil {
|
||||
if !entry.NoDisplay && isIn(categoryList, entry.DesktopID) {
|
||||
button, _ := gtk.ButtonNew()
|
||||
button.SetAlwaysShowImage(true)
|
||||
|
||||
pixbuf, _ := createPixbuf(entry.Icon, *iconSizeLarge)
|
||||
img, _ := gtk.ImageNewFromPixbuf(pixbuf)
|
||||
button.SetImage(img)
|
||||
button.SetImagePosition(gtk.POS_TOP)
|
||||
name := entry.NameLoc
|
||||
if len(name) > 20 {
|
||||
name = fmt.Sprintf("%s...", name[:17])
|
||||
}
|
||||
button.SetLabel(name)
|
||||
|
||||
flowBox.Add(button)
|
||||
}
|
||||
} else {
|
||||
if !entry.NoDisplay {
|
||||
button, _ := gtk.ButtonNew()
|
||||
button.SetAlwaysShowImage(true)
|
||||
|
||||
pixbuf, _ := createPixbuf(entry.Icon, *iconSizeLarge)
|
||||
img, _ := gtk.ImageNewFromPixbuf(pixbuf)
|
||||
button.SetImage(img)
|
||||
button.SetImagePosition(gtk.POS_TOP)
|
||||
name := entry.NameLoc
|
||||
if len(name) > 20 {
|
||||
name = fmt.Sprintf("%s...", name[:17])
|
||||
}
|
||||
button.SetLabel(name)
|
||||
|
||||
flowBox.Add(button)
|
||||
}
|
||||
}
|
||||
}
|
||||
appFlowBoxWrapper.PackStart(flowBox, false, false, 0)
|
||||
resultWindow.ShowAll()
|
||||
|
||||
return flowBox
|
||||
}
|
||||
|
||||
func setUpFileSearchResult() *gtk.ListBox {
|
||||
listBox, _ := gtk.ListBoxNew()
|
||||
if fileSearchResultWindow != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user