Skip to content

Commit

Permalink
Merge pull request nwg-piotr#18 from nwg-piotr/searchres
Browse files Browse the repository at this point in the history
focus first search result nwg-piotr#17
  • Loading branch information
nwg-piotr authored Aug 30, 2021
2 parents 9d0c4d2 + ce48848 commit c5e39f1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
Binary file modified bin/nwg-drawer
Binary file not shown.
5 changes: 2 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/gotk3/gotk3/gtk"
)

const version = "0.1.8"
const version = "0.1.9"

var (
appDirs []string
Expand Down Expand Up @@ -197,7 +197,6 @@ func main() {
println(fmt.Sprintf("Custom associations file %s not found or invalid", paFile))
} else {
println(fmt.Sprintf("Found %v associations in %s", len(preferredApps), paFile))
fmt.Println(preferredApps)
}

// USER INTERFACE
Expand Down Expand Up @@ -273,7 +272,7 @@ func main() {

default:
if !searchEntry.IsFocus() {
searchEntry.GrabFocus()
searchEntry.GrabFocusWithoutSelecting()
}
return false
}
Expand Down
33 changes: 31 additions & 2 deletions uicomponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,29 @@ func setUpSearchEntry() *gtk.SearchEntry {
fileSearchResultWrapper.Hide()
}
}
// 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 {
//f.SetCanFocus(false)
button, err := f.GetChild()
if err == nil {
button.ToWidget().SetCanFocus(true)
button.ToWidget().GrabFocus()
}
}
}
} else {
// clear search results
appFlowBox = setUpAppsFlowBox(nil, "")
Expand All @@ -364,9 +387,9 @@ func setUpSearchEntry() *gtk.SearchEntry {
}
}
})
searchEntry.Connect("focus-in-event", func() {
/*searchEntry.Connect("focus-in-event", func() {
searchEntry.SetText("")
})
})*/

return searchEntry
}
Expand Down Expand Up @@ -409,6 +432,7 @@ func setUpUserDirButton(iconName, displayName, entryName string, userDirsMap map
}
box, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
button, _ := gtk.ButtonNew()
button.SetAlwaysShowImage(true)
img, _ := gtk.ImageNewFromIconName(iconName, gtk.ICON_SIZE_MENU)
button.SetImage(img)

Expand Down Expand Up @@ -441,6 +465,7 @@ func setUpUserFileSearchResultButton(fileName, filePath string) *gtk.Box {
if strings.HasPrefix(filePath, "#is_dir#") {
filePath = filePath[8:]
img, _ := gtk.ImageNewFromIconName("folder", gtk.ICON_SIZE_MENU)
button.SetAlwaysShowImage(true)
button.SetImage(img)
}

Expand All @@ -466,6 +491,10 @@ func setUpUserFileSearchResultButton(fileName, filePath string) *gtk.Box {
return false
})

button.Connect("activate", func() {
open(filePath, true)
})

box.PackStart(button, false, true, 0)
return box
}

0 comments on commit c5e39f1

Please sign in to comment.