summaryrefslogtreecommitdiff
path: root/common.go
blob: 08a7625a2b28eb6feb1ffcf8a72a07462496962d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package repostatus

import (
	"go.wit.com/log"
)

// reports externally if something has changed
// since the last time it was asked about it
func (rs *RepoStatus) Changed() (string, bool) {
	if !rs.Ready() {
		return "", false
	}

	return rs.getChanges(), rs.changed
}

// keeps a human readable list of things that have
// changed. todo: timestampe these?
func (rs *RepoStatus) getChanges() string {
	return rs.changes
}

func (rs *RepoStatus) NoteChange(s string) {
	rs.changed = true
	rs.changes += s + "\n"
}

func (rs *RepoStatus) Show() {
	if !rs.Ready() {
		return
	}
	log.Log(CHANGE, "Show() window ready =", rs.ready)
	rs.window.Show()
}

func (rs *RepoStatus) Hide() {
	if !rs.Ready() {
		return
	}
	log.Log(CHANGE, "Hide() window ready =", rs.ready)
	rs.window.Hide()
}

func (rs *RepoStatus) Toggle() {
	if !rs.Ready() {
		return
	}
	log.Log(CHANGE, "Toggle() window ready =", rs.ready)
	if rs.window.Hidden() {
		rs.Show()
	} else {
		rs.Hide()
	}
}

func (rs *RepoStatus) Ready() bool {
	if rs == nil {
		return false
	}
	if rs.window == nil {
		return false
	}
	return rs.ready
}