file search improved
This commit is contained in:
BIN
bin/nwg-drawer
BIN
bin/nwg-drawer
Binary file not shown.
61
main.go
61
main.go
@@ -83,10 +83,9 @@ var desktopEntries []desktopEntry
|
|||||||
|
|
||||||
// UI elements
|
// UI elements
|
||||||
var (
|
var (
|
||||||
userDirsListBox *gtk.ListBox
|
|
||||||
resultWindow *gtk.ScrolledWindow
|
resultWindow *gtk.ScrolledWindow
|
||||||
fileSearchResults map[string]string
|
//fileSearchResults map[string]string
|
||||||
fileSearchResultWindow *gtk.ScrolledWindow
|
fileSearchResults []string
|
||||||
searchEntry *gtk.SearchEntry
|
searchEntry *gtk.SearchEntry
|
||||||
phrase string
|
phrase string
|
||||||
fileSearchResultListBox *gtk.ListBox
|
fileSearchResultListBox *gtk.ListBox
|
||||||
@@ -102,6 +101,7 @@ var (
|
|||||||
catButtons []*gtk.Button
|
catButtons []*gtk.Button
|
||||||
statusLabel *gtk.Label
|
statusLabel *gtk.Label
|
||||||
status string
|
status string
|
||||||
|
mainColumnWidth int
|
||||||
)
|
)
|
||||||
|
|
||||||
// Flags
|
// Flags
|
||||||
@@ -243,15 +243,10 @@ func main() {
|
|||||||
if key.KeyVal() == gdk.KEY_Escape {
|
if key.KeyVal() == gdk.KEY_Escape {
|
||||||
s, _ := searchEntry.GetText()
|
s, _ := searchEntry.GetText()
|
||||||
if s != "" {
|
if s != "" {
|
||||||
clearSearchResult()
|
|
||||||
searchEntry.GrabFocus()
|
searchEntry.GrabFocus()
|
||||||
searchEntry.SetText("")
|
searchEntry.SetText("")
|
||||||
} else {
|
} else {
|
||||||
if resultWindow == nil || !resultWindow.GetVisible() {
|
|
||||||
gtk.MainQuit()
|
gtk.MainQuit()
|
||||||
} else {
|
|
||||||
clearSearchResult()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -268,6 +263,7 @@ func main() {
|
|||||||
cancelClose()
|
cancelClose()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Set up UI
|
||||||
outerVBox, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
|
outerVBox, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
|
||||||
win.Add(outerVBox)
|
win.Add(outerVBox)
|
||||||
|
|
||||||
@@ -305,62 +301,23 @@ func main() {
|
|||||||
appFlowBox = setUpAppsFlowBox(nil, "")
|
appFlowBox = setUpAppsFlowBox(nil, "")
|
||||||
|
|
||||||
userDirsMap = mapXdgUserDirs()
|
userDirsMap = mapXdgUserDirs()
|
||||||
|
fmt.Println(userDirsMap)
|
||||||
|
|
||||||
placeholder, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
|
placeholder, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
|
||||||
resultsWrapper.PackStart(placeholder, true, true, 0)
|
resultsWrapper.PackStart(placeholder, true, true, 0)
|
||||||
|
|
||||||
|
wrapper, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
||||||
fileSearchResultWrapper, _ = gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
fileSearchResultWrapper, _ = gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
||||||
resultsWrapper.PackEnd(fileSearchResultWrapper, false, false, 10)
|
wrapper.PackStart(fileSearchResultWrapper, true, false, 0)
|
||||||
|
resultsWrapper.PackEnd(wrapper, false, false, 10)
|
||||||
|
|
||||||
statusLineWrapper, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
statusLineWrapper, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
||||||
outerVBox.PackStart(statusLineWrapper, false, false, 10)
|
outerVBox.PackStart(statusLineWrapper, false, false, 10)
|
||||||
statusLabel, _ = gtk.LabelNew(status)
|
statusLabel, _ = gtk.LabelNew(status)
|
||||||
statusLineWrapper.PackStart(statusLabel, true, false, 0)
|
statusLineWrapper.PackStart(statusLabel, true, false, 0)
|
||||||
|
|
||||||
/*alignmentBox, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
|
||||||
outerBox.PackStart(alignmentBox, true, true, 0)
|
|
||||||
|
|
||||||
rightColumn, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
|
|
||||||
|
|
||||||
alignmentBox.PackStart(rightColumn, true, true, 0)
|
|
||||||
|
|
||||||
wrapper, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
|
||||||
searchEntry = setUpSearchEntry()
|
|
||||||
searchEntry.SetMaxWidthChars(30)
|
|
||||||
wrapper.PackStart(searchEntry, true, false, 0)
|
|
||||||
rightColumn.PackStart(wrapper, false, false, 10)
|
|
||||||
|
|
||||||
wrapper, _ = gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
|
||||||
pinnedFlowBoxWrapper, _ = gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
|
|
||||||
pinnedFlowBox = setUpPinnedFlowBox()
|
|
||||||
wrapper.PackStart(pinnedFlowBoxWrapper, true, true, 0)
|
|
||||||
rightColumn.PackStart(wrapper, false, false, 10)
|
|
||||||
|
|
||||||
wrapper, _ = gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
|
||||||
categoriesMenuBar := setUpCategoriesButtonBox()
|
|
||||||
wrapper.PackStart(categoriesMenuBar, true, false, 0)
|
|
||||||
rightColumn.PackStart(wrapper, false, false, 10)
|
|
||||||
|
|
||||||
wrapper, _ = gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
|
||||||
resultWrapper, _ = gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 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()
|
|
||||||
})
|
|
||||||
rightColumn.PackStart(resultWindow, true, true, 0)
|
|
||||||
resultWindow.Add(wrapper)
|
|
||||||
//resultWrapper.PackStart(resultWindow, true, true, 0)
|
|
||||||
|
|
||||||
appFlowBoxWrapper, _ = gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
|
|
||||||
resultWindow.Add(appFlowBoxWrapper)
|
|
||||||
appFlowBox = setUpAppsFlowBox(nil, "")*/
|
|
||||||
|
|
||||||
win.ShowAll()
|
win.ShowAll()
|
||||||
|
fileSearchResultWrapper.SetSizeRequest(appFlowBox.GetAllocatedWidth(), 1)
|
||||||
|
|
||||||
//searchEntry.GrabFocus()
|
//searchEntry.GrabFocus()
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
|
|||||||
2
tools.go
2
tools.go
@@ -430,7 +430,7 @@ func parseDesktopFiles(desktopFiles []string) string {
|
|||||||
return desktopEntries[i].NameLoc < desktopEntries[j].NameLoc
|
return desktopEntries[i].NameLoc < desktopEntries[j].NameLoc
|
||||||
})
|
})
|
||||||
summary := fmt.Sprintf("%v entries (+%v hidden)", len(desktopEntries)-hidden, hidden)
|
summary := fmt.Sprintf("%v entries (+%v hidden)", len(desktopEntries)-hidden, hidden)
|
||||||
println("Skipped %v duplicates; %v .desktop entries hidden by \"NoDisplay=true\"", skipped, hidden)
|
println(fmt.Sprintf("Skipped %v duplicates; %v .desktop entries hidden by \"NoDisplay=true\"", skipped, hidden))
|
||||||
return summary
|
return summary
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -99,7 +99,6 @@ func setUpCategoriesButtonBox() *gtk.EventBox {
|
|||||||
eventBox.Add(hBox)
|
eventBox.Add(hBox)
|
||||||
button, _ := gtk.ButtonNewWithLabel("All")
|
button, _ := gtk.ButtonNewWithLabel("All")
|
||||||
button.Connect("clicked", func(item *gtk.Button) {
|
button.Connect("clicked", func(item *gtk.Button) {
|
||||||
//clearSearchResult()
|
|
||||||
searchEntry.GrabFocus()
|
searchEntry.GrabFocus()
|
||||||
searchEntry.SetText("")
|
searchEntry.SetText("")
|
||||||
appFlowBox = setUpAppsFlowBox(nil, "")
|
appFlowBox = setUpAppsFlowBox(nil, "")
|
||||||
@@ -119,7 +118,6 @@ func setUpCategoriesButtonBox() *gtk.EventBox {
|
|||||||
name := cat.Name
|
name := cat.Name
|
||||||
b := *button
|
b := *button
|
||||||
button.Connect("clicked", func(item *gtk.Button) {
|
button.Connect("clicked", func(item *gtk.Button) {
|
||||||
//clearSearchResult()
|
|
||||||
searchEntry.GrabFocus()
|
searchEntry.GrabFocus()
|
||||||
searchEntry.SetText("")
|
searchEntry.SetText("")
|
||||||
// !!! since gotk3 FlowBox type does not implement set_filter_func, we need to rebuild appFlowBox
|
// !!! since gotk3 FlowBox type does not implement set_filter_func, we need to rebuild appFlowBox
|
||||||
@@ -250,14 +248,7 @@ func setUpFileSearchResult() *gtk.ListBox {
|
|||||||
listBox.Connect("enter-notify-event", func() {
|
listBox.Connect("enter-notify-event", func() {
|
||||||
cancelClose()
|
cancelClose()
|
||||||
})
|
})
|
||||||
/*fileSearchResultWindow, _ = gtk.ScrolledWindowNew(nil, nil)
|
fileSearchResultWrapper.PackStart(listBox, false, false, 10)
|
||||||
fileSearchResultWindow.SetPolicy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
|
|
||||||
fileSearchResultWindow.Connect("enter-notify-event", func() {
|
|
||||||
cancelClose()
|
|
||||||
})*/
|
|
||||||
fileSearchResultWrapper.PackStart(listBox, true, false, 10)
|
|
||||||
|
|
||||||
//fileSearchResultWindow.Add(listBox)
|
|
||||||
listBox.ShowAll()
|
listBox.ShowAll()
|
||||||
|
|
||||||
return listBox
|
return listBox
|
||||||
@@ -267,13 +258,13 @@ func walk(path string, d fs.DirEntry, e error) error {
|
|||||||
if e != nil {
|
if e != nil {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
if !d.IsDir() {
|
//if !d.IsDir() {
|
||||||
parts := strings.Split(path, "/")
|
parts := strings.Split(path, "/")
|
||||||
fileName := parts[len(parts)-1]
|
fileName := parts[len(parts)-1]
|
||||||
if strings.Contains(strings.ToLower(fileName), strings.ToLower(phrase)) {
|
if strings.Contains(strings.ToLower(fileName), strings.ToLower(phrase)) {
|
||||||
fileSearchResults[fileName] = path
|
fileSearchResults = append(fileSearchResults, path)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
//}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -300,7 +291,7 @@ func setUpSearchEntry() *gtk.SearchEntry {
|
|||||||
fileSearchResultListBox = setUpFileSearchResult()
|
fileSearchResultListBox = setUpFileSearchResult()
|
||||||
for key := range userDirsMap {
|
for key := range userDirsMap {
|
||||||
if key != "home" {
|
if key != "home" {
|
||||||
fileSearchResults = make(map[string]string)
|
fileSearchResults = nil
|
||||||
if len(fileSearchResults) == 0 {
|
if len(fileSearchResults) == 0 {
|
||||||
fileSearchResultListBox.Show()
|
fileSearchResultListBox.Show()
|
||||||
}
|
}
|
||||||
@@ -317,7 +308,9 @@ func setUpSearchEntry() *gtk.SearchEntry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//clearSearchResult()
|
if fileSearchResultListBox != nil {
|
||||||
|
fileSearchResultListBox.Destroy()
|
||||||
|
}
|
||||||
appFlowBox = setUpAppsFlowBox(nil, "")
|
appFlowBox = setUpAppsFlowBox(nil, "")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -329,16 +322,63 @@ func setUpSearchEntry() *gtk.SearchEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func searchUserDir(dir string) {
|
func searchUserDir(dir string) {
|
||||||
fileSearchResults = make(map[string]string)
|
fileSearchResults = nil
|
||||||
filepath.WalkDir(userDirsMap[dir], walk)
|
filepath.WalkDir(userDirsMap[dir], walk)
|
||||||
if len(fileSearchResults) > 0 {
|
if fileSearchResults != nil && 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)
|
partOfPathToShow := strings.Split(path, userDirsMap[dir])[1]
|
||||||
|
if partOfPathToShow != "" {
|
||||||
|
row := setUpUserFileSearchResultRow(partOfPathToShow, path)
|
||||||
fileSearchResultListBox.Add(row)
|
fileSearchResultListBox.Add(row)
|
||||||
}
|
}
|
||||||
fileSearchResultListBox.ShowAll()
|
|
||||||
statusLabel.SetText(fmt.Sprintf("%v files", fileSearchResultListBox.GetChildren().Length()))
|
|
||||||
}
|
}
|
||||||
|
fileSearchResultListBox.ShowAll()
|
||||||
|
statusLabel.SetText(fmt.Sprintf("%v results", fileSearchResultListBox.GetChildren().Length()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func setUpUserDirsListRow(iconName, displayName, entryName string, userDirsMap map[string]string) *gtk.ListBoxRow {
|
||||||
|
if displayName == "" {
|
||||||
|
parts := strings.Split(userDirsMap[entryName], "/")
|
||||||
|
displayName = parts[(len(parts) - 1)]
|
||||||
|
}
|
||||||
|
row, _ := gtk.ListBoxRowNew()
|
||||||
|
//row.SetCanFocus(false)
|
||||||
|
row.SetSelectable(false)
|
||||||
|
vBox, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
|
||||||
|
eventBox, _ := gtk.EventBoxNew()
|
||||||
|
hBox, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 6)
|
||||||
|
eventBox.Add(hBox)
|
||||||
|
vBox.PackStart(eventBox, false, false, *itemPadding*3)
|
||||||
|
|
||||||
|
img, _ := gtk.ImageNewFromIconName(iconName, gtk.ICON_SIZE_DND)
|
||||||
|
hBox.PackStart(img, false, false, 0)
|
||||||
|
|
||||||
|
if len(displayName) > 45 {
|
||||||
|
displayName = fmt.Sprintf("%s...", displayName[:42])
|
||||||
|
}
|
||||||
|
lbl, _ := gtk.LabelNew(displayName)
|
||||||
|
hBox.PackStart(lbl, false, false, 0)
|
||||||
|
row.Add(vBox)
|
||||||
|
|
||||||
|
row.Connect("activate", func() {
|
||||||
|
launch(fmt.Sprintf("%s %s", *fileManager, userDirsMap[entryName]), false)
|
||||||
|
})
|
||||||
|
|
||||||
|
eventBox.Connect("button-release-event", func(row *gtk.ListBoxRow, e *gdk.Event) bool {
|
||||||
|
btnEvent := gdk.EventButtonNewFromEvent(e)
|
||||||
|
if btnEvent.Button() == 1 {
|
||||||
|
launch(fmt.Sprintf("%s %s", *fileManager, userDirsMap[entryName]), false)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
|
||||||
|
return row
|
||||||
}
|
}
|
||||||
|
|
||||||
func setUpUserFileSearchResultRow(fileName, filePath string) *gtk.ListBoxRow {
|
func setUpUserFileSearchResultRow(fileName, filePath string) *gtk.ListBoxRow {
|
||||||
@@ -371,15 +411,3 @@ func setUpUserFileSearchResultRow(fileName, filePath string) *gtk.ListBoxRow {
|
|||||||
})
|
})
|
||||||
return row
|
return row
|
||||||
}
|
}
|
||||||
|
|
||||||
func clearSearchResult() {
|
|
||||||
if resultWindow != nil {
|
|
||||||
resultWindow.Destroy()
|
|
||||||
}
|
|
||||||
if fileSearchResultWindow != nil {
|
|
||||||
fileSearchResultWindow.Destroy()
|
|
||||||
}
|
|
||||||
if userDirsListBox != nil {
|
|
||||||
userDirsListBox.ShowAll()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user