diff --git a/bin/nwg-drawer b/bin/nwg-drawer index 4691d53..75afe08 100755 Binary files a/bin/nwg-drawer and b/bin/nwg-drawer differ diff --git a/main.go b/main.go index 532e5bd..44a123c 100644 --- a/main.go +++ b/main.go @@ -83,10 +83,9 @@ var desktopEntries []desktopEntry // UI elements var ( - userDirsListBox *gtk.ListBox - resultWindow *gtk.ScrolledWindow - fileSearchResults map[string]string - fileSearchResultWindow *gtk.ScrolledWindow + resultWindow *gtk.ScrolledWindow + //fileSearchResults map[string]string + fileSearchResults []string searchEntry *gtk.SearchEntry phrase string fileSearchResultListBox *gtk.ListBox @@ -102,6 +101,7 @@ var ( catButtons []*gtk.Button statusLabel *gtk.Label status string + mainColumnWidth int ) // Flags @@ -243,15 +243,10 @@ func main() { if key.KeyVal() == gdk.KEY_Escape { s, _ := searchEntry.GetText() if s != "" { - clearSearchResult() searchEntry.GrabFocus() searchEntry.SetText("") } else { - if resultWindow == nil || !resultWindow.GetVisible() { - gtk.MainQuit() - } else { - clearSearchResult() - } + gtk.MainQuit() } } }) @@ -268,6 +263,7 @@ func main() { cancelClose() }) + // Set up UI outerVBox, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0) win.Add(outerVBox) @@ -305,62 +301,23 @@ func main() { appFlowBox = setUpAppsFlowBox(nil, "") userDirsMap = mapXdgUserDirs() + fmt.Println(userDirsMap) placeholder, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0) resultsWrapper.PackStart(placeholder, true, true, 0) + wrapper, _ := 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) outerVBox.PackStart(statusLineWrapper, false, false, 10) statusLabel, _ = gtk.LabelNew(status) 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() + fileSearchResultWrapper.SetSizeRequest(appFlowBox.GetAllocatedWidth(), 1) //searchEntry.GrabFocus() t := time.Now() diff --git a/tools.go b/tools.go index 2efcfac..8cbb1e3 100644 --- a/tools.go +++ b/tools.go @@ -430,7 +430,7 @@ func parseDesktopFiles(desktopFiles []string) string { return desktopEntries[i].NameLoc < desktopEntries[j].NameLoc }) 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 } diff --git a/uicomponents.go b/uicomponents.go index ad77582..e1756d1 100644 --- a/uicomponents.go +++ b/uicomponents.go @@ -99,7 +99,6 @@ func setUpCategoriesButtonBox() *gtk.EventBox { eventBox.Add(hBox) button, _ := gtk.ButtonNewWithLabel("All") button.Connect("clicked", func(item *gtk.Button) { - //clearSearchResult() searchEntry.GrabFocus() searchEntry.SetText("") appFlowBox = setUpAppsFlowBox(nil, "") @@ -119,7 +118,6 @@ func setUpCategoriesButtonBox() *gtk.EventBox { name := cat.Name b := *button button.Connect("clicked", func(item *gtk.Button) { - //clearSearchResult() searchEntry.GrabFocus() searchEntry.SetText("") // !!! 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() { cancelClose() }) - /*fileSearchResultWindow, _ = gtk.ScrolledWindowNew(nil, nil) - fileSearchResultWindow.SetPolicy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) - fileSearchResultWindow.Connect("enter-notify-event", func() { - cancelClose() - })*/ - fileSearchResultWrapper.PackStart(listBox, true, false, 10) - - //fileSearchResultWindow.Add(listBox) + fileSearchResultWrapper.PackStart(listBox, false, false, 10) listBox.ShowAll() return listBox @@ -267,13 +258,13 @@ func walk(path string, d fs.DirEntry, e error) error { if e != nil { return e } - if !d.IsDir() { - parts := strings.Split(path, "/") - fileName := parts[len(parts)-1] - if strings.Contains(strings.ToLower(fileName), strings.ToLower(phrase)) { - fileSearchResults[fileName] = path - } + //if !d.IsDir() { + parts := strings.Split(path, "/") + fileName := parts[len(parts)-1] + if strings.Contains(strings.ToLower(fileName), strings.ToLower(phrase)) { + fileSearchResults = append(fileSearchResults, path) } + //} return nil } @@ -300,7 +291,7 @@ func setUpSearchEntry() *gtk.SearchEntry { fileSearchResultListBox = setUpFileSearchResult() for key := range userDirsMap { if key != "home" { - fileSearchResults = make(map[string]string) + fileSearchResults = nil if len(fileSearchResults) == 0 { fileSearchResultListBox.Show() } @@ -317,7 +308,9 @@ func setUpSearchEntry() *gtk.SearchEntry { } } } else { - //clearSearchResult() + if fileSearchResultListBox != nil { + fileSearchResultListBox.Destroy() + } appFlowBox = setUpAppsFlowBox(nil, "") } }) @@ -329,18 +322,65 @@ func setUpSearchEntry() *gtk.SearchEntry { } func searchUserDir(dir string) { - fileSearchResults = make(map[string]string) + fileSearchResults = nil 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 { - row := setUpUserFileSearchResultRow(path, path) - fileSearchResultListBox.Add(row) + partOfPathToShow := strings.Split(path, userDirsMap[dir])[1] + if partOfPathToShow != "" { + row := setUpUserFileSearchResultRow(partOfPathToShow, path) + fileSearchResultListBox.Add(row) + } } fileSearchResultListBox.ShowAll() - statusLabel.SetText(fmt.Sprintf("%v files", fileSearchResultListBox.GetChildren().Length())) + 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 { row, _ := gtk.ListBoxRowNew() row.SetSelectable(false) @@ -371,15 +411,3 @@ func setUpUserFileSearchResultRow(fileName, filePath string) *gtk.ListBoxRow { }) return row } - -func clearSearchResult() { - if resultWindow != nil { - resultWindow.Destroy() - } - if fileSearchResultWindow != nil { - fileSearchResultWindow.Destroy() - } - if userDirsListBox != nil { - userDirsListBox.ShowAll() - } -}