From 59658bb98e27ca60cd8ae7f7029edf9ca46830c4 Mon Sep 17 00:00:00 2001 From: Luke Adams Date: Thu, 4 Oct 2018 13:22:26 -0600 Subject: Use labelSelect to edit labels in bugView --- termui/show_bug.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'termui/show_bug.go') diff --git a/termui/show_bug.go b/termui/show_bug.go index 72bcfe2f..71237cbf 100644 --- a/termui/show_bug.go +++ b/termui/show_bug.go @@ -628,13 +628,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,12 +646,19 @@ 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) editLabels(g *gocui.Gui, snap *bug.Snapshot) error { + ui.labelSelect.SetBug(sb.cache, sb.bug) + return ui.activateWindow(ui.labelSelect) +} + func (sb *showBug) addLabel(g *gocui.Gui, v *gocui.View) error { c := ui.inputPopup.Activate("Add labels") -- cgit From da1af3458402449cbdfc3cdf0319c890196ccf1a Mon Sep 17 00:00:00 2001 From: Luke Adams Date: Thu, 4 Oct 2018 13:30:04 -0600 Subject: Remove old label editing code from showBug --- termui/show_bug.go | 76 +----------------------------------------------------- 1 file changed, 1 insertion(+), 75 deletions(-) (limited to 'termui/show_bug.go') diff --git a/termui/show_bug.go b/termui/show_bug.go index 71237cbf..6cf0784f 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 } @@ -658,61 +642,3 @@ func (sb *showBug) editLabels(g *gocui.Gui, snap *bug.Snapshot) error { ui.labelSelect.SetBug(sb.cache, sb.bug) return ui.activateWindow(ui.labelSelect) } - -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 -} -- cgit