~chrisppy/beagles

fc86f6d2c37351aa3f06fd83970c91df9ff840f1 — Chris Palmer 19 days ago ba5fc33
stay on current item in list on update
3 files changed, 49 insertions(+), 14 deletions(-)

M CHANGELOG.md
M ui/list.go
M ui/ui.go
M CHANGELOG.md => CHANGELOG.md +3 -0
@@ 10,6 10,8 @@
    delete and let beagles regenerate it (~chrisppy)

### Added
  - Add Automatic Updates (~willt)
    - Added to config (~willt)
  - Added ability to create directory for config and database if it does not
      exist (~rek2)
  - Added subscription Page (~chrisppy)


@@ 34,6 36,7 @@
  - Merged models into db (~chrisppy)
  - Updated man pages and internal help page (~chrisppy)
  - Makefile enhancements for check command (~chrisppy)
  - Update now runs using a goroutine, no longer is it blocking (~willt)

### Fixed
  - Multiple performance fixes for update (~chrisppy)

M ui/list.go => ui/list.go +37 -11
@@ 65,8 65,15 @@ func (w *list) pageDown() string {
	return w.getKey()
}

func (w *list) getTitle(index int) (string, string) {
	if w.size() == 0 {
		return "", ""
	}
	return w.Widget.GetItemText(index)
}

func (w *list) getKey() string {
	_, key := w.Widget.GetItemText(w.index())
	_, key := w.getTitle(w.index())

	return key
}


@@ 75,9 82,13 @@ func (w *list) setIndex(newIndex int) {
	w.Widget.SetCurrentItem(newIndex)
}

//func (w *list) setIndexByKey(key string) {
//	w.setIndex(w.find(key))
//}
func (w *list) setIndexByKey(item *db.Item) {
	if item == nil {
		return
	}

	w.setIndex(w.find(item))
}

func (w *list) index() int {
	return w.Widget.GetCurrentItem()


@@ 88,7 99,6 @@ func (w *list) size() int {
}

func (w *list) remove() string {

	key := w.getKey()

	w.Widget.RemoveItem(w.index())


@@ 96,8 106,12 @@ func (w *list) remove() string {
	return key
}

func (w *list) find(key string) int {
	indices := w.Widget.FindItems("", key, false, false)
func (w *list) find(item *db.Item) int {
	if item == nil {
		return 0
	}

	indices := w.Widget.FindItems(item.Title, item.Link, true, false)

	if len(indices) == 0 {
		return 0


@@ 106,8 120,12 @@ func (w *list) find(key string) int {
	return indices[0]
}

func (w *list) removeByKey(key string) {
	w.setIndex(w.find(key))
func (w *list) removeByKey(item *db.Item) {
	if item == nil {
		return
	}

	w.setIndex(w.find(item))
	w.remove()
}



@@ 124,12 142,14 @@ func (w *list) clear() {
}

func (w *list) refresh(queue db.Queue, items db.Items) *db.Item {
	w.clear()

	if len(queue) == 0 {
		return nil
	}

	item := items[w.getKey()]

	w.clear()

	i := 0
	qitems := make([]*db.Item, len(queue))
	for key := range queue {


@@ 146,6 166,12 @@ func (w *list) refresh(queue db.Queue, items db.Items) *db.Item {
		w.add(item)
	}

	w.setIndexByKey(item)

	if item != nil {
		return item
	}

	return it
}


M ui/ui.go => ui/ui.go +9 -3
@@ 654,6 654,7 @@ func (i *UI) markRead(event *tcell.EventKey) *tcell.EventKey {
		return event
	}

	treeRefresh := false
	var key string
	switch i.status {
	case listStatus, contentStatus:


@@ 677,9 678,8 @@ func (i *UI) markRead(event *tcell.EventKey) *tcell.EventKey {
				}
				i.content.setText(i.DB.Items[i.list.getKey()])
			}

			i.subTree.refresh(i.DB.Feeds, i.DB.Items, i.hideRead)
		})
		treeRefresh = true
	case subStatus, subContentStatus:
		key = i.subTree.getKey()



@@ 691,8 691,10 @@ func (i *UI) markRead(event *tcell.EventKey) *tcell.EventKey {

		i.app.draw(func() {
			i.subTree.markRead()
			i.list.removeByKey(key)
		})

		i.list.removeByKey(i.DB.Items[key])

	default:
		return event
	}


@@ 708,6 710,10 @@ func (i *UI) markRead(event *tcell.EventKey) *tcell.EventKey {
			item := i.DB.Items[k]
			item.DeleteFile(i.DownloadPath, i.DB.Feeds)
		}

		if treeRefresh {
			i.subTree.refresh(i.DB.Feeds, i.DB.Items, i.hideRead)
		}
	})

	return nil