basic app search
This commit is contained in:
BIN
bin/nwg-drawer
BIN
bin/nwg-drawer
Binary file not shown.
7
main.go
7
main.go
@@ -90,10 +90,8 @@ var (
|
|||||||
resultWindow *gtk.ScrolledWindow
|
resultWindow *gtk.ScrolledWindow
|
||||||
fileSearchResults map[string]string
|
fileSearchResults map[string]string
|
||||||
fileSearchResultWindow *gtk.ScrolledWindow
|
fileSearchResultWindow *gtk.ScrolledWindow
|
||||||
backButton *gtk.Box
|
|
||||||
searchEntry *gtk.SearchEntry
|
searchEntry *gtk.SearchEntry
|
||||||
phrase string
|
phrase string
|
||||||
resultListBox *gtk.ListBox
|
|
||||||
fileSearchResultListBox *gtk.ListBox
|
fileSearchResultListBox *gtk.ListBox
|
||||||
buttonsWrapper *gtk.Box
|
buttonsWrapper *gtk.Box
|
||||||
buttonBox *gtk.EventBox
|
buttonBox *gtk.EventBox
|
||||||
@@ -316,9 +314,6 @@ func main() {
|
|||||||
wrapper.PackStart(categoriesMenuBar, true, false, 0)
|
wrapper.PackStart(categoriesMenuBar, true, false, 0)
|
||||||
rightColumn.PackStart(wrapper, false, false, 10)
|
rightColumn.PackStart(wrapper, false, false, 10)
|
||||||
|
|
||||||
backButton = setUpBackButton()
|
|
||||||
/*wrapper.PackEnd(backButton, false, false, 10)*/
|
|
||||||
|
|
||||||
wrapper, _ = gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
wrapper, _ = gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
||||||
resultWrapper, _ = gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
|
resultWrapper, _ = gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
|
||||||
wrapper.PackStart(resultWrapper, true, false, 0)
|
wrapper.PackStart(resultWrapper, true, false, 0)
|
||||||
@@ -338,8 +333,6 @@ func main() {
|
|||||||
|
|
||||||
win.ShowAll()
|
win.ShowAll()
|
||||||
|
|
||||||
backButton.Hide()
|
|
||||||
|
|
||||||
pinnedListBox.UnselectAll()
|
pinnedListBox.UnselectAll()
|
||||||
categoriesListBox.UnselectAll()
|
categoriesListBox.UnselectAll()
|
||||||
searchEntry.GrabFocus()
|
searchEntry.GrabFocus()
|
||||||
|
|||||||
198
uicomponents.go
198
uicomponents.go
@@ -41,7 +41,7 @@ func setUpPinnedFlowBox() *gtk.FlowBox {
|
|||||||
name = entry.Name
|
name = entry.Name
|
||||||
}
|
}
|
||||||
if len(name) > 20 {
|
if len(name) > 20 {
|
||||||
name = fmt.Sprintf("%s...", name[:17])
|
name = fmt.Sprintf("%s ...", name[:17])
|
||||||
}
|
}
|
||||||
btn.SetLabel(name)
|
btn.SetLabel(name)
|
||||||
|
|
||||||
@@ -157,147 +157,6 @@ func notEmpty(listCategory []string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func setUpBackButton() *gtk.Box {
|
|
||||||
vBox, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
|
|
||||||
hBox, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 10)
|
|
||||||
vBox.PackStart(hBox, false, false, 0)
|
|
||||||
button, _ := gtk.ButtonNew()
|
|
||||||
button.SetCanFocus(false)
|
|
||||||
pixbuf, _ := createPixbuf("arrow-left", *iconSizeLarge)
|
|
||||||
image, _ := gtk.ImageNewFromPixbuf(pixbuf)
|
|
||||||
button.SetImage(image)
|
|
||||||
button.SetAlwaysShowImage(true)
|
|
||||||
button.Connect("enter-notify-event", func() {
|
|
||||||
cancelClose()
|
|
||||||
})
|
|
||||||
button.Connect("clicked", func(btn *gtk.Button) {
|
|
||||||
clearSearchResult()
|
|
||||||
searchEntry.GrabFocus()
|
|
||||||
searchEntry.SetText("")
|
|
||||||
})
|
|
||||||
hBox.PackEnd(button, false, true, 0)
|
|
||||||
|
|
||||||
return vBox
|
|
||||||
}
|
|
||||||
|
|
||||||
func setUpCategoryListBox(listCategory []string) *gtk.ListBox {
|
|
||||||
listBox, _ := gtk.ListBoxNew()
|
|
||||||
|
|
||||||
for _, desktopID := range listCategory {
|
|
||||||
entry := id2entry[desktopID]
|
|
||||||
name := entry.NameLoc
|
|
||||||
if name == "" {
|
|
||||||
name = entry.Name
|
|
||||||
}
|
|
||||||
if len(name) > 30 {
|
|
||||||
name = fmt.Sprintf("%s...", name[:27])
|
|
||||||
}
|
|
||||||
if !entry.NoDisplay {
|
|
||||||
row, _ := gtk.ListBoxRowNew()
|
|
||||||
row.SetSelectable(false)
|
|
||||||
vBox, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 10)
|
|
||||||
eventBox, _ := gtk.EventBoxNew()
|
|
||||||
hBox, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 6)
|
|
||||||
eventBox.Add(hBox)
|
|
||||||
vBox.PackStart(eventBox, false, false, *itemPadding)
|
|
||||||
|
|
||||||
ID := entry.DesktopID
|
|
||||||
eventBox.Connect("button-release-event", func(row *gtk.ListBoxRow, e *gdk.Event) bool {
|
|
||||||
btnEvent := gdk.EventButtonNewFromEvent(e)
|
|
||||||
if btnEvent.Button() == 1 {
|
|
||||||
launch(entry.Exec, entry.Terminal)
|
|
||||||
return true
|
|
||||||
} else if btnEvent.Button() == 3 {
|
|
||||||
pinItem(ID)
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
})
|
|
||||||
|
|
||||||
pixbuf, _ := createPixbuf(entry.Icon, *iconSizeLarge)
|
|
||||||
img, _ := gtk.ImageNewFromPixbuf(pixbuf)
|
|
||||||
hBox.PackStart(img, false, false, 0)
|
|
||||||
|
|
||||||
lbl, _ := gtk.LabelNew(name)
|
|
||||||
hBox.PackStart(lbl, false, false, 0)
|
|
||||||
|
|
||||||
row.Add(vBox)
|
|
||||||
listBox.Add(row)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
backButton.Show()
|
|
||||||
return listBox
|
|
||||||
}
|
|
||||||
|
|
||||||
func setUpCategorySearchResult(searchPhrase string) *gtk.ListBox {
|
|
||||||
listBox, _ := gtk.ListBoxNew()
|
|
||||||
|
|
||||||
resultWindow, _ = gtk.ScrolledWindowNew(nil, nil)
|
|
||||||
resultWindow.SetPolicy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
|
|
||||||
resultWindow.Connect("enter-notify-event", func() {
|
|
||||||
cancelClose()
|
|
||||||
})
|
|
||||||
resultWrapper.PackStart(resultWindow, true, true, 0)
|
|
||||||
|
|
||||||
counter := 0
|
|
||||||
for _, entry := range desktopEntries {
|
|
||||||
if len(searchPhrase) == 1 && counter > 9 {
|
|
||||||
break
|
|
||||||
} else if len(searchPhrase) == 2 && counter > 14 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if !entry.NoDisplay && (strings.Contains(strings.ToLower(entry.NameLoc), strings.ToLower(searchPhrase)) ||
|
|
||||||
strings.Contains(strings.ToLower(entry.CommentLoc), strings.ToLower(searchPhrase)) ||
|
|
||||||
strings.Contains(strings.ToLower(entry.Comment), strings.ToLower(searchPhrase))) {
|
|
||||||
|
|
||||||
counter++
|
|
||||||
|
|
||||||
row, _ := gtk.ListBoxRowNew()
|
|
||||||
row.SetSelectable(false)
|
|
||||||
vBox, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 10)
|
|
||||||
eventBox, _ := gtk.EventBoxNew()
|
|
||||||
hBox, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 6)
|
|
||||||
eventBox.Add(hBox)
|
|
||||||
vBox.PackStart(eventBox, false, false, *itemPadding)
|
|
||||||
|
|
||||||
exec := entry.Exec
|
|
||||||
term := entry.Terminal
|
|
||||||
ID := entry.DesktopID
|
|
||||||
row.Connect("activate", func() {
|
|
||||||
launch(exec, term)
|
|
||||||
})
|
|
||||||
eventBox.Connect("button-release-event", func(row *gtk.EventBox, e *gdk.Event) bool {
|
|
||||||
btnEvent := gdk.EventButtonNewFromEvent(e)
|
|
||||||
if btnEvent.Button() == 1 {
|
|
||||||
launch(exec, term)
|
|
||||||
return true
|
|
||||||
} else if btnEvent.Button() == 3 {
|
|
||||||
pinItem(ID)
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
})
|
|
||||||
|
|
||||||
pixbuf, _ := createPixbuf(entry.Icon, *iconSizeLarge)
|
|
||||||
img, _ := gtk.ImageNewFromPixbuf(pixbuf)
|
|
||||||
hBox.PackStart(img, false, false, 0)
|
|
||||||
|
|
||||||
name := entry.NameLoc
|
|
||||||
if len(name) > 45 {
|
|
||||||
name = fmt.Sprintf("%s...", name[:42])
|
|
||||||
}
|
|
||||||
|
|
||||||
lbl, _ := gtk.LabelNew(name)
|
|
||||||
hBox.PackStart(lbl, false, false, 0)
|
|
||||||
|
|
||||||
row.Add(vBox)
|
|
||||||
listBox.Add(row)
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
resultWindow.Add(listBox)
|
|
||||||
resultWindow.ShowAll()
|
|
||||||
return listBox
|
|
||||||
}
|
|
||||||
|
|
||||||
func setUpAppsFlowBox(categoryList []string, searchPhrase string) *gtk.FlowBox {
|
func setUpAppsFlowBox(categoryList []string, searchPhrase string) *gtk.FlowBox {
|
||||||
if appFlowBox != nil {
|
if appFlowBox != nil {
|
||||||
appFlowBox.Destroy()
|
appFlowBox.Destroy()
|
||||||
@@ -306,14 +165,25 @@ func setUpAppsFlowBox(categoryList []string, searchPhrase string) *gtk.FlowBox {
|
|||||||
flowBox.SetMinChildrenPerLine(6)
|
flowBox.SetMinChildrenPerLine(6)
|
||||||
flowBox.SetColumnSpacing(20)
|
flowBox.SetColumnSpacing(20)
|
||||||
flowBox.SetRowSpacing(20)
|
flowBox.SetRowSpacing(20)
|
||||||
|
flowBox.SetHomogeneous(true)
|
||||||
for _, entry := range desktopEntries {
|
for _, entry := range desktopEntries {
|
||||||
if categoryList != nil {
|
if searchPhrase == "" {
|
||||||
if !entry.NoDisplay && isIn(categoryList, entry.DesktopID) {
|
if !entry.NoDisplay {
|
||||||
button := flowBoxButton(entry)
|
if categoryList != nil {
|
||||||
flowBox.Add(button)
|
if isIn(categoryList, entry.DesktopID) {
|
||||||
|
button := flowBoxButton(entry)
|
||||||
|
flowBox.Add(button)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
button := flowBoxButton(entry)
|
||||||
|
flowBox.Add(button)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if !entry.NoDisplay {
|
if !entry.NoDisplay && (strings.Contains(strings.ToLower(entry.NameLoc), strings.ToLower(searchPhrase)) ||
|
||||||
|
strings.Contains(strings.ToLower(entry.CommentLoc), strings.ToLower(searchPhrase)) ||
|
||||||
|
strings.Contains(strings.ToLower(entry.Comment), strings.ToLower(searchPhrase)) ||
|
||||||
|
strings.Contains(strings.ToLower(entry.Exec), strings.ToLower(searchPhrase))) {
|
||||||
button := flowBoxButton(entry)
|
button := flowBoxButton(entry)
|
||||||
flowBox.Add(button)
|
flowBox.Add(button)
|
||||||
}
|
}
|
||||||
@@ -335,7 +205,7 @@ func flowBoxButton(entry desktopEntry) *gtk.Button {
|
|||||||
button.SetImagePosition(gtk.POS_TOP)
|
button.SetImagePosition(gtk.POS_TOP)
|
||||||
name := entry.NameLoc
|
name := entry.NameLoc
|
||||||
if len(name) > 20 {
|
if len(name) > 20 {
|
||||||
name = fmt.Sprintf("%s...", name[:17])
|
name = fmt.Sprintf("%s ...", name[:17])
|
||||||
}
|
}
|
||||||
button.SetLabel(name)
|
button.SetLabel(name)
|
||||||
|
|
||||||
@@ -394,18 +264,15 @@ func setUpSearchEntry() *gtk.SearchEntry {
|
|||||||
cancelClose()
|
cancelClose()
|
||||||
})
|
})
|
||||||
searchEntry.Connect("search-changed", func() {
|
searchEntry.Connect("search-changed", func() {
|
||||||
|
for _, btn := range catButtons {
|
||||||
|
btn.SetImagePosition(gtk.POS_LEFT)
|
||||||
|
btn.SetSizeRequest(0, 0)
|
||||||
|
}
|
||||||
|
|
||||||
phrase, _ = searchEntry.GetText()
|
phrase, _ = searchEntry.GetText()
|
||||||
if len(phrase) > 0 {
|
if len(phrase) > 0 {
|
||||||
userDirsListBox.Hide()
|
|
||||||
backButton.Show()
|
|
||||||
|
|
||||||
if resultWindow != nil {
|
appFlowBox = setUpAppsFlowBox(nil, phrase)
|
||||||
resultWindow.Destroy()
|
|
||||||
}
|
|
||||||
resultListBox = setUpCategorySearchResult(phrase)
|
|
||||||
if resultListBox.GetChildren().Length() == 0 {
|
|
||||||
resultWindow.Hide()
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(phrase) > 2 {
|
if len(phrase) > 2 {
|
||||||
if fileSearchResultWindow != nil {
|
if fileSearchResultWindow != nil {
|
||||||
@@ -430,12 +297,10 @@ func setUpSearchEntry() *gtk.SearchEntry {
|
|||||||
fileSearchResultWindow.Destroy()
|
fileSearchResultWindow.Destroy()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
clearSearchResult()
|
//clearSearchResult()
|
||||||
userDirsListBox.ShowAll()
|
appFlowBox = setUpAppsFlowBox(nil, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
searchEntry.Connect("focus-in-event", func() {
|
searchEntry.Connect("focus-in-event", func() {
|
||||||
searchEntry.SetText("")
|
searchEntry.SetText("")
|
||||||
@@ -448,10 +313,6 @@ func searchUserDir(dir string) {
|
|||||||
fileSearchResults = make(map[string]string)
|
fileSearchResults = make(map[string]string)
|
||||||
filepath.WalkDir(userDirsMap[dir], walk)
|
filepath.WalkDir(userDirsMap[dir], walk)
|
||||||
if len(fileSearchResults) > 0 {
|
if len(fileSearchResults) > 0 {
|
||||||
/*row := setUpUserDirsListRow(fmt.Sprintf("folder-%s", dir), "", dir, userDirsMap)
|
|
||||||
fileSearchResultListBox.Add(row)
|
|
||||||
fileSearchResultListBox.ShowAll()*/
|
|
||||||
|
|
||||||
for _, path := range fileSearchResults {
|
for _, path := range fileSearchResults {
|
||||||
row := setUpUserFileSearchResultRow(path, path)
|
row := setUpUserFileSearchResultRow(path, path)
|
||||||
fileSearchResultListBox.Add(row)
|
fileSearchResultListBox.Add(row)
|
||||||
@@ -470,9 +331,6 @@ func setUpUserFileSearchResultRow(fileName, filePath string) *gtk.ListBoxRow {
|
|||||||
eventBox.Add(hBox)
|
eventBox.Add(hBox)
|
||||||
vBox.PackStart(eventBox, false, false, *itemPadding)
|
vBox.PackStart(eventBox, false, false, *itemPadding)
|
||||||
|
|
||||||
/*if len(fileName) > 45 {
|
|
||||||
fileName = fmt.Sprintf("%s...", fileName[:42])
|
|
||||||
}*/
|
|
||||||
lbl, _ := gtk.LabelNew(fileName)
|
lbl, _ := gtk.LabelNew(fileName)
|
||||||
hBox.PackStart(lbl, false, false, 0)
|
hBox.PackStart(lbl, false, false, 0)
|
||||||
row.Add(vBox)
|
row.Add(vBox)
|
||||||
@@ -489,7 +347,6 @@ func setUpUserFileSearchResultRow(fileName, filePath string) *gtk.ListBoxRow {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
|
|
||||||
return row
|
return row
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -510,7 +367,4 @@ func clearSearchResult() {
|
|||||||
}
|
}
|
||||||
categoriesListBox.UnselectAll()
|
categoriesListBox.UnselectAll()
|
||||||
}
|
}
|
||||||
backButton.Hide()
|
|
||||||
//searchEntry.SetText("")
|
|
||||||
//searchEntry.GrabFocus()
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user