Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

focus first search result #17 #18

Merged
merged 1 commit into from
Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}