Skip to content

Commit

Permalink
Cleaned up selection with multiple dbs.
Browse files Browse the repository at this point in the history
  • Loading branch information
tkuhlman committed Nov 27, 2015
1 parent f30f2ed commit 912c044
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Coverage Status](https://coveralls.io/repos/tkuhlman/gopwsafe/badge.svg?branch=master&service=github)](https://coveralls.io/github/tkuhlman/gopwsafe?branch=master)


** In Progress - Currently Read Only **
** Alpha - 0.1.0 release is Read Only and ugly **

A password safe written in go using and implementing the [password safe](http://pwsafe.org/) version 3 database.
Simply download and run, no install needed.
Expand Down Expand Up @@ -36,7 +36,6 @@ Features:
- currently iti is all read only
- Add the ability to create a new empty password db.
- Copy doesn't time out and clear clipboard at this point
- Add opening of more than one file at a time.
- The ability copy/move entries from one open db to another.
- Edit of multiple entries at once for select fields, ie modify the group

Expand Down
2 changes: 1 addition & 1 deletion gui/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func openWindow(dbFile string, dbs *[]pwsafe.DB, conf config.PWSafeDBConfig, mai
}
newdbs := append(*dbs, db)
*dbs = newdbs
updateRecords(*dbs, recordStore, "")
updateRecords(dbs, recordStore, "")
window.Hide()
mainWindow.ShowAll()
})
Expand Down
30 changes: 17 additions & 13 deletions gui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,31 @@ func mainWindow(dbs []pwsafe.DB, conf config.PWSafeDBConfig, dbFile string) {
recordTree.AppendColumn(gtk.NewTreeViewColumnWithAttributes("", gtk.NewCellRendererPixbuf(), "pixbuf", 0))
recordTree.AppendColumn(gtk.NewTreeViewColumnWithAttributes("Name", gtk.NewCellRendererText(), "text", 1))

updateRecords(dbs, recordStore, "")
updateRecords(&dbs, recordStore, "")
recordTree.ExpandAll()

// Select the first record in the tree
// Prepare to select the first record in the tree on update
treeSelection := recordTree.GetSelection()
firstEntryPath := gtk.NewTreePathFromString("0:0:0")
treeSelection.SetMode(gtk.SELECTION_SINGLE)
treeSelection.SelectPath(firstEntryPath)

recordTree.Connect("row_activated", func() {
recordWindow(getSelectedRecord(recordStore, recordTree, dbs))
recordWindow(getSelectedRecord(recordStore, recordTree, &dbs))
})

searchPaned := gtk.NewHPaned()
searchLabel := gtk.NewLabel("Search: ")
searchPaned.Pack1(searchLabel, false, false)
searchBox := gtk.NewEntry()
searchBox.Connect("changed", func() {
updateRecords(dbs, recordStore, searchBox.GetText())
updateRecords(&dbs, recordStore, searchBox.GetText())
recordTree.ExpandAll()
treeSelection.SelectPath(firstEntryPath)
for i := range dbs {
firstEntryPath := gtk.NewTreePathFromString(strconv.Itoa(i) + ":0:0")
treeSelection.SelectPath(firstEntryPath)
if treeSelection.PathIsSelected(firstEntryPath) {
break
}
}
})
searchPaned.Pack2(searchBox, false, false)

Expand All @@ -71,7 +75,7 @@ func mainWindow(dbs []pwsafe.DB, conf config.PWSafeDBConfig, dbFile string) {
// layout
vbox := gtk.NewVBox(false, 1)
vbox.PackStart(mainMenuBar(window, &dbs, conf, recordStore), false, false, 0)
vbox.PackStart(selectedRecordMenuBar(window, recordStore, recordTree, dbs), false, false, 0)
vbox.PackStart(selectedRecordMenuBar(window, recordStore, recordTree, &dbs), false, false, 0)
vbox.PackStart(searchPaned, false, false, 0)
vbox.Add(recordFrame)
window.Add(vbox)
Expand All @@ -86,7 +90,7 @@ func mainWindow(dbs []pwsafe.DB, conf config.PWSafeDBConfig, dbFile string) {
}

// return a db.Record matching the selected entry
func getSelectedRecord(recordStore *gtk.TreeStore, recordTree *gtk.TreeView, dbs []pwsafe.DB) *pwsafe.Record {
func getSelectedRecord(recordStore *gtk.TreeStore, recordTree *gtk.TreeView, dbs *[]pwsafe.DB) *pwsafe.Record {
var iter gtk.TreeIter
var rowValue glib.GValue
selection := recordTree.GetSelection()
Expand All @@ -101,7 +105,7 @@ func getSelectedRecord(recordStore *gtk.TreeStore, recordTree *gtk.TreeView, dbs
var record pwsafe.Record
return &record
}
db := dbs[activeDB]
db := (*dbs)[activeDB]

// todo fail gracefully if a non-leaf is selected.

Expand All @@ -114,9 +118,9 @@ func getSelectedRecord(recordStore *gtk.TreeStore, recordTree *gtk.TreeView, dbs
return &record
}

func updateRecords(dbs []pwsafe.DB, store *gtk.TreeStore, search string) {
func updateRecords(dbs *[]pwsafe.DB, store *gtk.TreeStore, search string) {
store.Clear()
for i, db := range dbs {
for i, db := range *dbs {
name := db.GetName()
if name == "" {
name = strconv.Itoa(i)
Expand Down Expand Up @@ -191,7 +195,7 @@ func mainMenuBar(window *gtk.Window, dbs *[]pwsafe.DB, conf config.PWSafeDBConfi
// todo this is remarkably similar to the recordMenuBar in gui/record.go the difference being this
// one doesn't get a record passed in but finds it from selection. I should think about how I could
// clearly and idiomatically reduce the duplication.
func selectedRecordMenuBar(window *gtk.Window, recordStore *gtk.TreeStore, recordTree *gtk.TreeView, dbs []pwsafe.DB) *gtk.Widget {
func selectedRecordMenuBar(window *gtk.Window, recordStore *gtk.TreeStore, recordTree *gtk.TreeView, dbs *[]pwsafe.DB) *gtk.Widget {
clipboard := gtk.NewClipboardGetForDisplay(gdk.DisplayGetDefault(), gdk.SELECTION_CLIPBOARD)

actionGroup := gtk.NewActionGroup("record")
Expand Down

0 comments on commit 912c044

Please sign in to comment.