~chrisppy/beagles

86a60492d542f47e0b686a7c3dab6fbb27f1b95e — Chris Palmer 7 months ago c3967c6
Fix remove from sub
4 files changed, 42 insertions(+), 19 deletions(-)

M go.mod
M go.sum
M ui/actions.go
M ui/tree.go
M go.mod => go.mod +1 -1
@@ 14,7 14,7 @@ require (
	github.com/jaytaylor/html2text v0.0.0-20200412013138-3577fbdbcff7
	github.com/kr/pretty v0.1.0 // indirect
	github.com/mmcdole/gofeed v1.1.0
	github.com/olekukonko/tablewriter v0.0.4 // indirect
	github.com/olekukonko/tablewriter v0.0.5 // indirect
	github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect
	gitlab.com/tslocum/cbind v0.1.4
	gitlab.com/tslocum/cview v1.5.3

M go.sum => go.sum +2 -2
@@ 59,8 59,8 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OH
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/olekukonko/tablewriter v0.0.4 h1:vHD/YYe1Wolo78koG299f7V/VAS08c6IpCLn+Ejf/w8=
github.com/olekukonko/tablewriter v0.0.4/go.mod h1:zq6QwlOf5SlnkVbMSr5EoBv3636FWnp+qbPhuoO21uA=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=

M ui/actions.go => ui/actions.go +5 -2
@@ 623,7 623,7 @@ func (i *UI) addFeed(args []string) {
		for _, v := range nitems.Sort() {
			i.list.insert(v)

			if node, _ := i.sub.find(v.FeedURL, i.sub.Node.GetChildren()); node == nil {
			if node, _ := i.sub.find(v.FeedURL, i.sub.getRoot().GetChildren()); node == nil {
				f := i.DB.Feeds[v.FeedURL]
				i.sub.add(f, i.DB.Items, i.hideRead)
			}


@@ 674,7 674,10 @@ func (i *UI) deleteFeed(args []string) {
			i.list.removeByKey(v)
			i.fav.removeByKey(v)
		}
		i.sub.removeFeedByKey(feed)

		nkey := i.sub.removeFeedByKey(feed)
		nf := i.DB.Feeds[nkey]
		i.subContent.setDescription(nf.Description, nf.Updated, false)

		i.commandLine.setText("")
		i.setStatus(i.status)

M ui/tree.go => ui/tree.go +34 -14
@@ 32,7 32,6 @@ import (

type tree struct {
	Widget      *tui.TreeView
	Node        *tui.TreeNode
	TextColor   tcell.Color
	ReadColor   tcell.Color
	Dates       map[string]time.Time


@@ 43,6 42,7 @@ type tree struct {
func (i *UI) newTree() *tree {
	view := tui.NewTreeView()
	view.SetGraphics(true)
	view.SetTopLevel(1)

	view.SetBackgroundColor(i.Config.Theme.TreeBGColor)
	view.SetGraphicsColor(i.Config.Theme.TreeFGColor)


@@ 58,7 58,6 @@ func (i *UI) newTree() *tree {

	w := &tree{
		Widget:      view,
		Node:        node,
		TextColor:   i.Config.Theme.TreeFGColor,
		ReadColor:   i.Config.Theme.ReadColor,
		Dates:       make(map[string]time.Time),


@@ 84,6 83,10 @@ func (i *UI) newTree() *tree {
	return w
}

func (w *tree) getRoot() *tui.TreeNode {
	return w.Widget.GetRoot()
}

func (w *tree) convert(item *db.Item) (*tui.TreeNode, bool) {
	name := item.Title



@@ 143,7 146,7 @@ func (w *tree) add(f *db.Feed, itemMap db.Items, hide bool) {
	node.SetChildren(items)
	node.Collapse()

	w.Node.AddChild(node)
	w.getRoot().AddChild(node)
}

func getTitle(title string, unread int, increment bool, decrement bool) string {


@@ 202,7 205,7 @@ func getTitle(title string, unread int, increment bool, decrement bool) string {
}

func (w *tree) size() int {
	return len(w.Node.GetChildren())
	return len(w.getRoot().GetChildren())
}

func (w *tree) ref(node *tui.TreeNode) string {


@@ 240,7 243,7 @@ func (w *tree) pageDown() {
}

func (w *tree) markReadByKey(key string) {
	node, _ := w.find(key, w.Node.GetChildren())
	node, _ := w.find(key, w.getRoot().GetChildren())
	if node == nil {
		return
	}


@@ 310,7 313,7 @@ func (w *tree) toggle() {
}

func (w *tree) insert(item *db.Item, hide bool, appendItem bool) {
	node, _ := w.find(item.FeedURL, w.Node.GetChildren())
	node, _ := w.find(item.FeedURL, w.getRoot().GetChildren())
	if node == nil {
		return
	}


@@ 329,30 332,47 @@ func (w *tree) insert(item *db.Item, hide bool, appendItem bool) {
	}

	ch := append([]*tui.TreeNode{n}, node.GetChildren()...)
	node.ClearChildren()
	//node.ClearChildren()
	node.SetChildren(ch)
}

func (w *tree) find(ref string, nodes []*tui.TreeNode) (*tui.TreeNode, int) {
func (w *tree) find(key string, nodes []*tui.TreeNode) (*tui.TreeNode, int) {
	for i, node := range nodes {
		if ref == fmt.Sprintf("%v", node.GetReference()) {
		if key == w.ref(node) {
			return node, i
		} else if n, j := w.find(ref, node.GetChildren()); n != nil {
		} else if n, j := w.find(key, node.GetChildren()); n != nil {
			return n, j
		}
	}
	return nil, 0
}

func (w *tree) removeFeedByKey(feed *db.Feed) {
	node, i := w.find(feed.Link, w.Node.GetChildren())
func (w *tree) removeFeedByKey(feed *db.Feed) string {
	node, i := w.find(feed.UpdateURL, w.getRoot().GetChildren())
	if node == nil {
		return
		return ""
	}

	for k := range feed.Items {
		delete(w.ChildParent, k)
	}

	w.Node.SetChildren(append(w.Node.GetChildren()[:i], w.Node.GetChildren()[i+1:]...))
	ch := w.getRoot().GetChildren()
	ch = append(ch[:i], ch[i+1:]...)
	//w.getRoot().ClearChildren()
	w.getRoot().SetChildren(ch)
	size := len(ch)

	var n *tui.TreeNode
	if size == 0 {
		return ""
	} else if size == 1 {
		n = ch[0]
	} else if i == 0 {
		n = ch[1]
	} else {
		n = ch[i-1]
	}
	w.Widget.SetCurrentNode(n)
	return w.ref(n)
}