2021-05-19 01:53:51 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/fs"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
|
2021-09-22 14:51:16 +03:00
|
|
|
log "github.com/sirupsen/logrus"
|
2021-09-23 01:25:35 +03:00
|
|
|
|
2021-05-19 01:53:51 +03:00
|
|
|
"github.com/gotk3/gotk3/gdk"
|
|
|
|
"github.com/gotk3/gotk3/gtk"
|
|
|
|
)
|
|
|
|
|
2021-05-22 01:58:31 +03:00
|
|
|
func setUpPinnedFlowBox() *gtk.FlowBox {
|
|
|
|
if pinnedFlowBox != nil {
|
|
|
|
pinnedFlowBox.Destroy()
|
|
|
|
}
|
|
|
|
flowBox, _ := gtk.FlowBoxNew()
|
2021-05-24 04:46:14 +03:00
|
|
|
if uint(len(pinned)) >= *columnsNumber {
|
|
|
|
flowBox.SetMaxChildrenPerLine(*columnsNumber)
|
2021-07-13 00:23:52 +03:00
|
|
|
} else if len(pinned) > 0 {
|
2021-05-24 04:46:14 +03:00
|
|
|
flowBox.SetMaxChildrenPerLine(uint(len(pinned)))
|
|
|
|
}
|
|
|
|
|
2021-05-29 03:31:04 +03:00
|
|
|
flowBox.SetColumnSpacing(*itemSpacing)
|
|
|
|
flowBox.SetRowSpacing(*itemSpacing)
|
2021-05-22 01:58:31 +03:00
|
|
|
flowBox.SetHomogeneous(true)
|
2021-05-28 04:10:13 +03:00
|
|
|
flowBox.SetProperty("name", "pinned-box")
|
|
|
|
flowBox.SetSelectionMode(gtk.SELECTION_NONE)
|
2021-05-22 01:58:31 +03:00
|
|
|
|
|
|
|
if len(pinned) > 0 {
|
|
|
|
for _, desktopID := range pinned {
|
|
|
|
entry := id2entry[desktopID]
|
2022-11-12 05:41:24 +03:00
|
|
|
if entry.DesktopID == "" {
|
|
|
|
log.Debugf("Pinned item doesn't seem to exist: %s", desktopID)
|
|
|
|
continue
|
|
|
|
}
|
2021-05-22 01:58:31 +03:00
|
|
|
|
|
|
|
btn, _ := gtk.ButtonNew()
|
2021-06-18 04:00:42 +03:00
|
|
|
|
2021-09-22 18:37:33 +03:00
|
|
|
var img *gtk.Image
|
|
|
|
if entry.Icon != "" {
|
2021-09-23 01:25:35 +03:00
|
|
|
pixbuf, _ := createPixbuf(entry.Icon, *iconSize)
|
|
|
|
img, _ = gtk.ImageNewFromPixbuf(pixbuf)
|
2021-09-22 18:37:33 +03:00
|
|
|
} else {
|
2021-09-23 01:25:35 +03:00
|
|
|
img, _ = gtk.ImageNewFromIconName("image-missing", gtk.ICON_SIZE_INVALID)
|
2021-05-22 01:58:31 +03:00
|
|
|
}
|
2021-06-18 04:00:42 +03:00
|
|
|
|
2021-05-22 01:58:31 +03:00
|
|
|
btn.SetImage(img)
|
|
|
|
btn.SetAlwaysShowImage(true)
|
|
|
|
btn.SetImagePosition(gtk.POS_TOP)
|
|
|
|
|
|
|
|
name := ""
|
|
|
|
if entry.NameLoc != "" {
|
|
|
|
name = entry.NameLoc
|
|
|
|
} else {
|
|
|
|
name = entry.Name
|
|
|
|
}
|
|
|
|
if len(name) > 20 {
|
2023-01-12 04:27:27 +03:00
|
|
|
r := substring(name, 0, 17)
|
|
|
|
name = fmt.Sprintf("%s…", string(r))
|
2021-05-22 01:58:31 +03:00
|
|
|
}
|
|
|
|
btn.SetLabel(name)
|
|
|
|
|
|
|
|
btn.Connect("button-release-event", func(row *gtk.Button, e *gdk.Event) bool {
|
|
|
|
btnEvent := gdk.EventButtonNewFromEvent(e)
|
|
|
|
if btnEvent.Button() == 1 {
|
|
|
|
launch(entry.Exec, entry.Terminal)
|
|
|
|
return true
|
|
|
|
} else if btnEvent.Button() == 3 {
|
|
|
|
unpinItem(entry.DesktopID)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
})
|
2021-05-28 04:10:13 +03:00
|
|
|
btn.Connect("activate", func() {
|
|
|
|
launch(entry.Exec, entry.Terminal)
|
|
|
|
})
|
2021-05-29 04:22:14 +03:00
|
|
|
btn.Connect("enter-notify-event", func() {
|
|
|
|
statusLabel.SetText(entry.CommentLoc)
|
|
|
|
})
|
2022-01-09 14:56:51 +03:00
|
|
|
btn.Connect("focus-in-event", func() {
|
|
|
|
statusLabel.SetText(entry.CommentLoc)
|
|
|
|
})
|
2021-05-22 01:58:31 +03:00
|
|
|
flowBox.Add(btn)
|
|
|
|
}
|
2021-07-13 00:23:52 +03:00
|
|
|
pinnedFlowBoxWrapper.PackStart(flowBox, true, false, 0)
|
|
|
|
|
|
|
|
//While moving focus with arrow keys we want buttons to get focus directly
|
|
|
|
flowBox.GetChildren().Foreach(func(item interface{}) {
|
|
|
|
item.(*gtk.Widget).SetCanFocus(false)
|
|
|
|
})
|
2021-05-22 01:58:31 +03:00
|
|
|
}
|
2021-09-24 04:01:55 +03:00
|
|
|
flowBox.ShowAll()
|
2021-05-22 01:58:31 +03:00
|
|
|
|
|
|
|
return flowBox
|
|
|
|
}
|
|
|
|
|
2021-05-21 05:28:50 +03:00
|
|
|
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()
|
2021-09-23 01:45:35 +03:00
|
|
|
|
2021-05-21 05:28:50 +03:00
|
|
|
hBox, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
|
|
|
eventBox.Add(hBox)
|
|
|
|
button, _ := gtk.ButtonNewWithLabel("All")
|
2021-06-29 18:24:48 +03:00
|
|
|
button.SetProperty("name", "category-button")
|
2021-05-21 05:28:50 +03:00
|
|
|
button.Connect("clicked", func(item *gtk.Button) {
|
|
|
|
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)
|
2021-06-29 18:24:48 +03:00
|
|
|
button.SetProperty("name", "category-button")
|
2021-05-21 05:28:50 +03:00
|
|
|
catButtons = append(catButtons, button)
|
|
|
|
button.SetLabel(cat.DisplayName)
|
2021-07-21 02:49:34 +03:00
|
|
|
button.SetAlwaysShowImage(true)
|
2021-05-21 05:28:50 +03:00
|
|
|
hBox.PackStart(button, false, false, 0)
|
|
|
|
name := cat.Name
|
|
|
|
b := *button
|
|
|
|
button.Connect("clicked", func(item *gtk.Button) {
|
|
|
|
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)
|
2021-08-27 02:21:41 +03:00
|
|
|
if fileSearchResultWrapper != nil {
|
|
|
|
fileSearchResultWrapper.Hide()
|
|
|
|
}
|
2021-05-21 05:28:50 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return eventBox
|
|
|
|
}
|
|
|
|
|
2021-05-19 01:53:51 +03:00
|
|
|
func isSupposedToShowUp(catName string) bool {
|
|
|
|
result := catName == "utility" && notEmpty(listUtility) ||
|
|
|
|
catName == "development" && notEmpty(listDevelopment) ||
|
|
|
|
catName == "game" && notEmpty(listGame) ||
|
|
|
|
catName == "graphics" && notEmpty(listGraphics) ||
|
|
|
|
catName == "internet-and-network" && notEmpty(listInternetAndNetwork) ||
|
|
|
|
catName == "office" && notEmpty(listOffice) ||
|
|
|
|
catName == "audio-video" && notEmpty(listAudioVideo) ||
|
|
|
|
catName == "system-tools" && notEmpty(listSystemTools) ||
|
|
|
|
catName == "other" && notEmpty(listOther)
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
func notEmpty(listCategory []string) bool {
|
|
|
|
if len(listCategory) == 0 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
for _, desktopID := range listCategory {
|
|
|
|
entry := id2entry[desktopID]
|
2021-06-17 05:09:03 +03:00
|
|
|
if !entry.NoDisplay {
|
2021-05-19 01:53:51 +03:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-05-21 05:28:50 +03:00
|
|
|
func setUpAppsFlowBox(categoryList []string, searchPhrase string) *gtk.FlowBox {
|
|
|
|
if appFlowBox != nil {
|
|
|
|
appFlowBox.Destroy()
|
|
|
|
}
|
|
|
|
flowBox, _ := gtk.FlowBoxNew()
|
2021-05-24 04:46:14 +03:00
|
|
|
flowBox.SetMinChildrenPerLine(*columnsNumber)
|
|
|
|
flowBox.SetMaxChildrenPerLine(*columnsNumber)
|
2021-05-29 03:31:04 +03:00
|
|
|
flowBox.SetColumnSpacing(*itemSpacing)
|
|
|
|
flowBox.SetRowSpacing(*itemSpacing)
|
2021-05-23 03:22:57 +03:00
|
|
|
flowBox.SetHomogeneous(true)
|
2021-05-28 04:10:13 +03:00
|
|
|
flowBox.SetSelectionMode(gtk.SELECTION_NONE)
|
|
|
|
|
2021-05-21 05:28:50 +03:00
|
|
|
for _, entry := range desktopEntries {
|
2021-05-23 03:22:57 +03:00
|
|
|
if searchPhrase == "" {
|
|
|
|
if !entry.NoDisplay {
|
|
|
|
if categoryList != nil {
|
|
|
|
if isIn(categoryList, entry.DesktopID) {
|
|
|
|
button := flowBoxButton(entry)
|
|
|
|
flowBox.Add(button)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
button := flowBoxButton(entry)
|
|
|
|
flowBox.Add(button)
|
|
|
|
}
|
2021-05-21 05:28:50 +03:00
|
|
|
}
|
|
|
|
} else {
|
2021-05-23 03:22:57 +03:00
|
|
|
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))) {
|
2021-05-22 01:58:31 +03:00
|
|
|
button := flowBoxButton(entry)
|
2021-05-21 05:28:50 +03:00
|
|
|
flowBox.Add(button)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-05-24 04:46:14 +03:00
|
|
|
hWrapper, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
2021-05-25 04:11:55 +03:00
|
|
|
appSearchResultWrapper.PackStart(hWrapper, false, false, 0)
|
2021-05-24 04:46:14 +03:00
|
|
|
hWrapper.PackStart(flowBox, true, false, 0)
|
2021-05-28 04:10:13 +03:00
|
|
|
// While moving focus with arrow keys we want buttons to get focus directly
|
|
|
|
flowBox.GetChildren().Foreach(func(item interface{}) {
|
|
|
|
item.(*gtk.Widget).SetCanFocus(false)
|
|
|
|
})
|
2021-05-21 05:28:50 +03:00
|
|
|
resultWindow.ShowAll()
|
|
|
|
|
|
|
|
return flowBox
|
|
|
|
}
|
|
|
|
|
2021-05-22 01:58:31 +03:00
|
|
|
func flowBoxButton(entry desktopEntry) *gtk.Button {
|
|
|
|
button, _ := gtk.ButtonNew()
|
|
|
|
button.SetAlwaysShowImage(true)
|
|
|
|
|
2021-09-22 18:37:33 +03:00
|
|
|
var pixbuf *gdk.Pixbuf
|
|
|
|
var img *gtk.Image
|
|
|
|
var err error
|
|
|
|
if entry.Icon != "" {
|
|
|
|
pixbuf, err = createPixbuf(entry.Icon, *iconSize)
|
|
|
|
} else {
|
2021-09-23 01:25:35 +03:00
|
|
|
log.Warnf("Undefined icon for %s", entry.Name)
|
2021-09-22 18:37:33 +03:00
|
|
|
pixbuf, err = createPixbuf("image-missing", *iconSize)
|
|
|
|
}
|
2021-09-22 14:51:16 +03:00
|
|
|
if err != nil {
|
2021-09-22 18:37:33 +03:00
|
|
|
pixbuf, _ = createPixbuf("unknown", *iconSize)
|
2021-06-18 04:00:42 +03:00
|
|
|
}
|
2021-09-22 18:37:33 +03:00
|
|
|
img, _ = gtk.ImageNewFromPixbuf(pixbuf)
|
2021-06-18 04:00:42 +03:00
|
|
|
|
2021-05-22 01:58:31 +03:00
|
|
|
button.SetImage(img)
|
|
|
|
button.SetImagePosition(gtk.POS_TOP)
|
|
|
|
name := entry.NameLoc
|
|
|
|
if len(name) > 20 {
|
2023-01-12 04:27:27 +03:00
|
|
|
r := substring(name, 0, 17)
|
|
|
|
name = fmt.Sprintf("%s…", string(r))
|
2021-05-22 01:58:31 +03:00
|
|
|
}
|
|
|
|
button.SetLabel(name)
|
|
|
|
|
|
|
|
ID := entry.DesktopID
|
|
|
|
exec := entry.Exec
|
|
|
|
terminal := entry.Terminal
|
2021-05-24 05:34:11 +03:00
|
|
|
desc := entry.CommentLoc
|
2022-05-08 02:43:16 +03:00
|
|
|
if len(desc) > 120 {
|
2023-01-12 04:27:27 +03:00
|
|
|
r := substring(desc, 0, 117)
|
|
|
|
desc = fmt.Sprintf("%s…", string(r))
|
2022-05-08 02:43:16 +03:00
|
|
|
}
|
2021-05-24 05:34:11 +03:00
|
|
|
button.Connect("button-release-event", func(btn *gtk.Button, e *gdk.Event) bool {
|
2021-05-22 01:58:31 +03:00
|
|
|
btnEvent := gdk.EventButtonNewFromEvent(e)
|
|
|
|
if btnEvent.Button() == 1 {
|
|
|
|
launch(exec, terminal)
|
|
|
|
return true
|
|
|
|
} else if btnEvent.Button() == 3 {
|
|
|
|
pinItem(ID)
|
2021-09-17 03:35:43 +03:00
|
|
|
return true
|
2021-05-22 01:58:31 +03:00
|
|
|
}
|
|
|
|
return false
|
|
|
|
})
|
2021-05-28 04:10:13 +03:00
|
|
|
button.Connect("activate", func() {
|
|
|
|
launch(exec, terminal)
|
|
|
|
})
|
2021-05-24 05:34:11 +03:00
|
|
|
button.Connect("enter-notify-event", func() {
|
|
|
|
statusLabel.SetText(desc)
|
|
|
|
})
|
2022-01-09 14:56:51 +03:00
|
|
|
button.Connect("focus-in-event", func() {
|
|
|
|
statusLabel.SetText(desc)
|
|
|
|
})
|
2021-05-22 01:58:31 +03:00
|
|
|
return button
|
|
|
|
}
|
|
|
|
|
2024-02-01 05:52:56 +03:00
|
|
|
func powerButton(iconPath, command string) *gtk.Button {
|
|
|
|
button, _ := gtk.ButtonNew()
|
|
|
|
button.SetAlwaysShowImage(true)
|
|
|
|
|
|
|
|
var pixbuf *gdk.Pixbuf
|
|
|
|
var img *gtk.Image
|
|
|
|
var err error
|
2024-02-01 06:09:31 +03:00
|
|
|
pixbuf, err = gdk.PixbufNewFromFileAtSize(iconPath, *pbSize, *pbSize)
|
2024-02-01 05:52:56 +03:00
|
|
|
if err != nil {
|
2024-02-01 06:09:31 +03:00
|
|
|
pixbuf, _ = createPixbuf("unknown", *pbSize)
|
2024-02-01 05:52:56 +03:00
|
|
|
log.Warnf("Couldn't find icon %s", iconPath)
|
|
|
|
}
|
|
|
|
img, _ = gtk.ImageNewFromPixbuf(pixbuf)
|
|
|
|
button.SetImage(img)
|
|
|
|
button.SetImagePosition(gtk.POS_TOP)
|
|
|
|
|
|
|
|
button.Connect("button-release-event", func(btn *gtk.Button, e *gdk.Event) bool {
|
|
|
|
btnEvent := gdk.EventButtonNewFromEvent(e)
|
|
|
|
if btnEvent.Button() == 1 {
|
|
|
|
launch(command, false)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
button.Connect("activate", func() {
|
|
|
|
launch(command, false)
|
|
|
|
})
|
|
|
|
button.Connect("enter-notify-event", func() {
|
|
|
|
statusLabel.SetText(command)
|
|
|
|
})
|
|
|
|
button.Connect("focus-in-event", func() {
|
|
|
|
statusLabel.SetText(command)
|
|
|
|
})
|
|
|
|
return button
|
|
|
|
}
|
|
|
|
|
2021-05-30 02:34:47 +03:00
|
|
|
func setUpFileSearchResultContainer() *gtk.FlowBox {
|
2021-05-28 04:10:13 +03:00
|
|
|
if fileSearchResultFlowBox != nil {
|
|
|
|
fileSearchResultFlowBox.Destroy()
|
2021-05-19 01:53:51 +03:00
|
|
|
}
|
2021-05-28 04:10:13 +03:00
|
|
|
flowBox, _ := gtk.FlowBoxNew()
|
|
|
|
flowBox.SetProperty("orientation", gtk.ORIENTATION_VERTICAL)
|
|
|
|
fileSearchResultWrapper.PackStart(flowBox, false, false, 10)
|
2021-05-19 01:53:51 +03:00
|
|
|
|
2021-05-28 04:10:13 +03:00
|
|
|
return flowBox
|
2021-05-19 01:53:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func walk(path string, d fs.DirEntry, e error) error {
|
|
|
|
if e != nil {
|
|
|
|
return e
|
|
|
|
}
|
2021-09-28 03:40:23 +03:00
|
|
|
// don't search leading part of the path, as e.g. '/home/user/Pictures'
|
|
|
|
toSearch := strings.Split(path, ignore)[1]
|
|
|
|
|
|
|
|
// Remaing part of the path (w/o file name) must be checked against being present in excluded dirs
|
|
|
|
doSearch := true
|
|
|
|
parts := strings.Split(toSearch, "/")
|
|
|
|
remainingPart := ""
|
|
|
|
if len(parts) > 1 {
|
|
|
|
remainingPart = strings.Join(parts[:len(parts)-1], "/")
|
|
|
|
}
|
|
|
|
if remainingPart != "" && isExcluded(remainingPart) {
|
|
|
|
doSearch = false
|
|
|
|
}
|
|
|
|
|
|
|
|
if doSearch && strings.Contains(strings.ToLower(toSearch), strings.ToLower(phrase)) {
|
|
|
|
// mark directories
|
|
|
|
if d.IsDir() {
|
|
|
|
fileSearchResults = append(fileSearchResults, fmt.Sprintf("#is_dir#%s", path))
|
|
|
|
} else {
|
|
|
|
fileSearchResults = append(fileSearchResults, path)
|
2021-05-29 02:46:48 +03:00
|
|
|
}
|
2021-05-19 01:53:51 +03:00
|
|
|
}
|
2021-09-25 05:39:05 +03:00
|
|
|
|
2021-05-19 01:53:51 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func setUpSearchEntry() *gtk.SearchEntry {
|
|
|
|
searchEntry, _ := gtk.SearchEntryNew()
|
2021-05-28 04:10:13 +03:00
|
|
|
searchEntry.SetPlaceholderText("Type to search")
|
2021-09-23 01:25:35 +03:00
|
|
|
/*searchEntry.Connect("enter-notify-event", func() {
|
2021-05-19 01:53:51 +03:00
|
|
|
cancelClose()
|
2021-09-23 01:25:35 +03:00
|
|
|
})*/
|
2021-05-19 01:53:51 +03:00
|
|
|
searchEntry.Connect("search-changed", func() {
|
2021-05-23 03:22:57 +03:00
|
|
|
for _, btn := range catButtons {
|
|
|
|
btn.SetImagePosition(gtk.POS_LEFT)
|
|
|
|
btn.SetSizeRequest(0, 0)
|
|
|
|
}
|
|
|
|
|
2021-05-19 01:53:51 +03:00
|
|
|
phrase, _ = searchEntry.GetText()
|
|
|
|
if len(phrase) > 0 {
|
|
|
|
|
2021-08-17 00:26:30 +03:00
|
|
|
// search apps
|
2021-05-23 03:22:57 +03:00
|
|
|
appFlowBox = setUpAppsFlowBox(nil, phrase)
|
2021-05-19 01:53:51 +03:00
|
|
|
|
2021-08-17 00:26:30 +03:00
|
|
|
// search files
|
|
|
|
if !*noFS && len(phrase) > 2 {
|
2021-05-28 04:10:13 +03:00
|
|
|
if fileSearchResultFlowBox != nil {
|
|
|
|
fileSearchResultFlowBox.Destroy()
|
2021-05-19 01:53:51 +03:00
|
|
|
}
|
2021-08-17 00:26:30 +03:00
|
|
|
|
2021-05-30 02:34:47 +03:00
|
|
|
fileSearchResultFlowBox = setUpFileSearchResultContainer()
|
2021-08-17 00:26:30 +03:00
|
|
|
|
2021-05-19 01:53:51 +03:00
|
|
|
for key := range userDirsMap {
|
|
|
|
if key != "home" {
|
2021-05-26 04:53:25 +03:00
|
|
|
fileSearchResults = nil
|
2021-05-19 01:53:51 +03:00
|
|
|
searchUserDir(key)
|
|
|
|
}
|
|
|
|
}
|
2021-05-28 04:10:13 +03:00
|
|
|
if fileSearchResultFlowBox.GetChildren().Length() == 0 {
|
2021-05-30 23:44:38 +03:00
|
|
|
fileSearchResultWrapper.Hide()
|
2021-05-30 02:34:47 +03:00
|
|
|
statusLabel.SetText("0 results")
|
2021-05-19 01:53:51 +03:00
|
|
|
}
|
|
|
|
} else {
|
2021-08-17 00:26:30 +03:00
|
|
|
// search phrase too short
|
2021-05-28 04:10:13 +03:00
|
|
|
if fileSearchResultFlowBox != nil {
|
|
|
|
fileSearchResultFlowBox.Destroy()
|
2021-05-19 01:53:51 +03:00
|
|
|
}
|
2021-08-17 00:26:30 +03:00
|
|
|
if fileSearchResultWrapper != nil {
|
|
|
|
fileSearchResultWrapper.Hide()
|
|
|
|
}
|
2021-05-19 01:53:51 +03:00
|
|
|
}
|
2021-08-29 04:37:00 +03:00
|
|
|
// focus 1st search result #17
|
|
|
|
var w *gtk.Widget
|
|
|
|
if appFlowBox != nil {
|
|
|
|
b := appFlowBox.GetChildAtIndex(0)
|
|
|
|
if b != nil {
|
|
|
|
button, err := b.GetChild()
|
|
|
|
if err == nil {
|
|
|
|
button.ToWidget().GrabFocus()
|
|
|
|
w = button.ToWidget()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if w == nil && fileSearchResultFlowBox != nil {
|
|
|
|
f := fileSearchResultFlowBox.GetChildAtIndex(0)
|
|
|
|
if f != nil {
|
|
|
|
button, err := f.GetChild()
|
|
|
|
if err == nil {
|
|
|
|
button.ToWidget().SetCanFocus(true)
|
|
|
|
button.ToWidget().GrabFocus()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-05-19 01:53:51 +03:00
|
|
|
} else {
|
2021-08-17 00:26:30 +03:00
|
|
|
// clear search results
|
|
|
|
appFlowBox = setUpAppsFlowBox(nil, "")
|
|
|
|
|
2021-05-28 04:10:13 +03:00
|
|
|
if fileSearchResultFlowBox != nil {
|
|
|
|
fileSearchResultFlowBox.Destroy()
|
2021-05-26 04:53:25 +03:00
|
|
|
}
|
2021-08-17 00:26:30 +03:00
|
|
|
|
|
|
|
if fileSearchResultWrapper != nil {
|
|
|
|
fileSearchResultWrapper.Hide()
|
|
|
|
}
|
2021-05-19 01:53:51 +03:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return searchEntry
|
|
|
|
}
|
|
|
|
|
2021-09-25 05:39:05 +03:00
|
|
|
func isExcluded(dir string) bool {
|
|
|
|
for _, exclusion := range exclusions {
|
|
|
|
if strings.Contains(dir, exclusion) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-05-19 01:53:51 +03:00
|
|
|
func searchUserDir(dir string) {
|
2021-05-26 04:53:25 +03:00
|
|
|
fileSearchResults = nil
|
2021-05-29 02:46:48 +03:00
|
|
|
ignore = userDirsMap[dir]
|
2021-05-19 01:53:51 +03:00
|
|
|
filepath.WalkDir(userDirsMap[dir], walk)
|
2021-05-28 04:10:13 +03:00
|
|
|
|
2021-06-17 05:09:03 +03:00
|
|
|
if len(fileSearchResults) > 0 {
|
2021-05-28 04:10:13 +03:00
|
|
|
btn := setUpUserDirButton(fmt.Sprintf("folder-%s", dir), "", dir, userDirsMap)
|
|
|
|
fileSearchResultFlowBox.Add(btn)
|
2021-05-26 04:53:25 +03:00
|
|
|
|
2021-05-19 05:38:54 +03:00
|
|
|
for _, path := range fileSearchResults {
|
2022-11-18 03:40:50 +03:00
|
|
|
log.Debugf("Path: %s", path)
|
2021-05-26 04:53:25 +03:00
|
|
|
partOfPathToShow := strings.Split(path, userDirsMap[dir])[1]
|
|
|
|
if partOfPathToShow != "" {
|
2021-09-28 03:40:23 +03:00
|
|
|
if !(strings.HasPrefix(path, "#is_dir#") && isExcluded(path)) {
|
|
|
|
btn := setUpUserFileSearchResultButton(partOfPathToShow, path)
|
|
|
|
fileSearchResultFlowBox.Add(btn)
|
|
|
|
}
|
|
|
|
|
2021-05-26 04:53:25 +03:00
|
|
|
}
|
2021-05-19 01:53:51 +03:00
|
|
|
}
|
2021-05-28 04:10:13 +03:00
|
|
|
fileSearchResultFlowBox.Hide()
|
|
|
|
|
2021-08-20 05:46:26 +03:00
|
|
|
statusLabel.SetText(fmt.Sprintf("%v results | LMB: xdg-open | RMB: file manager",
|
|
|
|
fileSearchResultFlowBox.GetChildren().Length()))
|
2021-05-29 04:11:16 +03:00
|
|
|
num := uint(fileSearchResultFlowBox.GetChildren().Length() / *fsColumns)
|
2021-05-28 04:10:13 +03:00
|
|
|
fileSearchResultFlowBox.SetMinChildrenPerLine(num + 1)
|
|
|
|
fileSearchResultFlowBox.SetMaxChildrenPerLine(num + 1)
|
|
|
|
//While moving focus with arrow keys we want buttons to get focus directly
|
|
|
|
fileSearchResultFlowBox.GetChildren().Foreach(func(item interface{}) {
|
|
|
|
item.(*gtk.Widget).SetCanFocus(false)
|
|
|
|
})
|
|
|
|
fileSearchResultFlowBox.ShowAll()
|
2021-05-26 04:53:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-28 04:10:13 +03:00
|
|
|
func setUpUserDirButton(iconName, displayName, entryName string, userDirsMap map[string]string) *gtk.Box {
|
2021-05-26 04:53:25 +03:00
|
|
|
if displayName == "" {
|
|
|
|
parts := strings.Split(userDirsMap[entryName], "/")
|
|
|
|
displayName = parts[(len(parts) - 1)]
|
2021-05-19 01:53:51 +03:00
|
|
|
}
|
2021-05-28 04:10:13 +03:00
|
|
|
box, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
|
|
|
button, _ := gtk.ButtonNew()
|
2021-08-29 04:37:00 +03:00
|
|
|
button.SetAlwaysShowImage(true)
|
2021-05-28 04:10:13 +03:00
|
|
|
img, _ := gtk.ImageNewFromIconName(iconName, gtk.ICON_SIZE_MENU)
|
|
|
|
button.SetImage(img)
|
2021-05-26 04:53:25 +03:00
|
|
|
|
2021-05-28 04:10:13 +03:00
|
|
|
if len(displayName) > *nameLimit {
|
2021-05-29 03:07:34 +03:00
|
|
|
displayName = fmt.Sprintf("%s…", displayName[:*nameLimit-3])
|
2021-05-26 04:53:25 +03:00
|
|
|
}
|
2021-05-28 04:10:13 +03:00
|
|
|
button.SetLabel(displayName)
|
2021-05-26 04:53:25 +03:00
|
|
|
|
2021-08-20 05:46:26 +03:00
|
|
|
button.Connect("button-release-event", func(btn *gtk.Button, e *gdk.Event) bool {
|
|
|
|
btnEvent := gdk.EventButtonNewFromEvent(e)
|
|
|
|
if btnEvent.Button() == 1 {
|
|
|
|
open(userDirsMap[entryName], true)
|
|
|
|
return true
|
|
|
|
} else if btnEvent.Button() == 3 {
|
|
|
|
open(userDirsMap[entryName], false)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
2021-05-26 04:53:25 +03:00
|
|
|
})
|
|
|
|
|
2021-05-28 04:10:13 +03:00
|
|
|
box.PackStart(button, false, true, 0)
|
|
|
|
return box
|
2021-05-19 01:53:51 +03:00
|
|
|
}
|
|
|
|
|
2021-05-28 04:10:13 +03:00
|
|
|
func setUpUserFileSearchResultButton(fileName, filePath string) *gtk.Box {
|
|
|
|
box, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
|
|
|
button, _ := gtk.ButtonNew()
|
2021-05-19 01:53:51 +03:00
|
|
|
|
2021-05-29 02:46:48 +03:00
|
|
|
// in the walk function we've marked directories with the '#is_dir#' prefix
|
|
|
|
if strings.HasPrefix(filePath, "#is_dir#") {
|
|
|
|
filePath = filePath[8:]
|
|
|
|
img, _ := gtk.ImageNewFromIconName("folder", gtk.ICON_SIZE_MENU)
|
2021-08-29 04:37:00 +03:00
|
|
|
button.SetAlwaysShowImage(true)
|
2021-05-29 02:46:48 +03:00
|
|
|
button.SetImage(img)
|
|
|
|
}
|
|
|
|
|
2021-05-28 04:10:13 +03:00
|
|
|
tooltipText := ""
|
|
|
|
if len(fileName) > *nameLimit {
|
|
|
|
tooltipText = fileName
|
2021-05-29 03:07:34 +03:00
|
|
|
fileName = fmt.Sprintf("%s…", fileName[:*nameLimit-3])
|
2021-05-28 04:10:13 +03:00
|
|
|
}
|
|
|
|
button.SetLabel(fileName)
|
|
|
|
if tooltipText != "" {
|
|
|
|
button.SetTooltipText(tooltipText)
|
2021-05-25 04:11:55 +03:00
|
|
|
}
|
2021-05-19 01:53:51 +03:00
|
|
|
|
2021-08-20 05:46:26 +03:00
|
|
|
button.Connect("button-release-event", func(btn *gtk.Button, e *gdk.Event) bool {
|
|
|
|
btnEvent := gdk.EventButtonNewFromEvent(e)
|
|
|
|
if btnEvent.Button() == 1 {
|
|
|
|
open(filePath, true)
|
|
|
|
return true
|
|
|
|
} else if btnEvent.Button() == 3 {
|
|
|
|
open(filePath, false)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
2021-05-19 01:53:51 +03:00
|
|
|
})
|
|
|
|
|
2021-08-29 04:37:00 +03:00
|
|
|
button.Connect("activate", func() {
|
|
|
|
open(filePath, true)
|
|
|
|
})
|
|
|
|
|
2021-05-28 04:10:13 +03:00
|
|
|
box.PackStart(button, false, true, 0)
|
|
|
|
return box
|
2021-05-19 01:53:51 +03:00
|
|
|
}
|