aboutsummaryrefslogtreecommitdiffstats
path: root/termui/show_bug.go
diff options
context:
space:
mode:
Diffstat (limited to 'termui/show_bug.go')
-rw-r--r--termui/show_bug.go86
1 files changed, 9 insertions, 77 deletions
diff --git a/termui/show_bug.go b/termui/show_bug.go
index 395d0cd2..a16626a4 100644
--- a/termui/show_bug.go
+++ b/termui/show_bug.go
@@ -95,13 +95,7 @@ func (sb *showBug) layout(g *gocui.Gui) error {
}
v.Clear()
- fmt.Fprintf(v, "[q] Save and return [←↓↑→,hjkl] Navigation ")
-
- if sb.isOnSide {
- fmt.Fprint(v, "[a] Add label [r] Remove label")
- } else {
- fmt.Fprint(v, "[o] Toggle open/close [e] Edit [c] Comment [t] Change title")
- }
+ fmt.Fprintf(v, "[q] Save and return [←↓↑→,hjkl] Navigation [o] Toggle open/close [e] Edit [c] Comment [t] Change title")
_, err = g.SetViewOnTop(showBugInstructionView)
if err != nil {
@@ -190,16 +184,6 @@ func (sb *showBug) keybindings(g *gocui.Gui) error {
return err
}
- // Labels
- if err := g.SetKeybinding(showBugView, 'a', gocui.ModNone,
- sb.addLabel); err != nil {
- return err
- }
- if err := g.SetKeybinding(showBugView, 'r', gocui.ModNone,
- sb.removeLabel); err != nil {
- return err
- }
-
return nil
}
@@ -628,13 +612,12 @@ func (sb *showBug) toggleOpenClose(g *gocui.Gui, v *gocui.View) error {
}
func (sb *showBug) edit(g *gocui.Gui, v *gocui.View) error {
+ snap := sb.bug.Snapshot()
+
if sb.isOnSide {
- ui.msgPopup.Activate(msgPopupErrorTitle, "Selected field is not editable.")
- return nil
+ return sb.editLabels(g, snap)
}
- snap := sb.bug.Snapshot()
-
op, err := snap.SearchTimelineItem(git.Hash(sb.selected))
if err != nil {
return err
@@ -647,66 +630,15 @@ func (sb *showBug) edit(g *gocui.Gui, v *gocui.View) error {
case *bug.CreateTimelineItem:
preMessage := op.(*bug.CreateTimelineItem).Message
return editCommentWithEditor(sb.bug, op.Hash(), preMessage)
+ case *bug.LabelChangeTimelineItem:
+ return sb.editLabels(g, snap)
}
ui.msgPopup.Activate(msgPopupErrorTitle, "Selected field is not editable.")
return nil
}
-func (sb *showBug) addLabel(g *gocui.Gui, v *gocui.View) error {
- c := ui.inputPopup.Activate("Add labels")
-
- go func() {
- input := <-c
-
- labels := strings.FieldsFunc(input, func(r rune) bool {
- return r == ' ' || r == ','
- })
-
- _, err := sb.bug.ChangeLabels(trimLabels(labels), nil)
- if err != nil {
- ui.msgPopup.Activate(msgPopupErrorTitle, err.Error())
- }
-
- g.Update(func(gui *gocui.Gui) error {
- return nil
- })
- }()
-
- return nil
-}
-
-func (sb *showBug) removeLabel(g *gocui.Gui, v *gocui.View) error {
- c := ui.inputPopup.Activate("Remove labels")
-
- go func() {
- input := <-c
-
- labels := strings.FieldsFunc(input, func(r rune) bool {
- return r == ' ' || r == ','
- })
-
- _, err := sb.bug.ChangeLabels(nil, trimLabels(labels))
- if err != nil {
- ui.msgPopup.Activate(msgPopupErrorTitle, err.Error())
- }
-
- g.Update(func(gui *gocui.Gui) error {
- return nil
- })
- }()
-
- return nil
-}
-
-func trimLabels(labels []string) []string {
- var result []string
-
- for _, label := range labels {
- trimmed := strings.TrimSpace(label)
- if len(trimmed) > 0 {
- result = append(result, trimmed)
- }
- }
- return result
+func (sb *showBug) editLabels(g *gocui.Gui, snap *bug.Snapshot) error {
+ ui.labelSelect.SetBug(sb.cache, sb.bug)
+ return ui.activateWindow(ui.labelSelect)
}