From 3e13936e08c5bb97fb96e68ca27b1e9739c16a50 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sat, 21 Nov 2020 17:15:43 +1100 Subject: [PATCH] notify user upon copying something to clipboard --- pkg/gui/app_status_manager.go | 2 +- pkg/gui/branches_panel.go | 2 +- pkg/gui/commits_panel.go | 9 ++++++++- pkg/gui/global_handlers.go | 11 ++++++++++- pkg/i18n/dutch.go | 2 ++ pkg/i18n/english.go | 4 ++++ pkg/i18n/polish.go | 2 ++ 7 files changed, 28 insertions(+), 4 deletions(-) diff --git a/pkg/gui/app_status_manager.go b/pkg/gui/app_status_manager.go index 089344701..aa1df4c04 100644 --- a/pkg/gui/app_status_manager.go +++ b/pkg/gui/app_status_manager.go @@ -84,7 +84,7 @@ func (m *statusManager) getStatusString() string { return topStatus.message } -func (gui *Gui) raiseToastStatus(message string) { +func (gui *Gui) raiseToast(message string) { gui.statusManager.addToastStatus(message) gui.renderAppStatus() diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go index 9208f7085..48e322025 100644 --- a/pkg/gui/branches_panel.go +++ b/pkg/gui/branches_panel.go @@ -107,7 +107,7 @@ func (gui *Gui) handleCopyPullRequestURLPress(g *gocui.Gui, v *gocui.View) error return gui.surfaceError(err) } - gui.raiseToastStatus(gui.Tr.PullRequestURLCopiedToClipboard) + gui.raiseToast(gui.Tr.PullRequestURLCopiedToClipboard) return nil } diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go index 92c3c9380..5e0c18bfd 100644 --- a/pkg/gui/commits_panel.go +++ b/pkg/gui/commits_panel.go @@ -589,5 +589,12 @@ func (gui *Gui) handleCopySelectedCommitMessageToClipboard() error { if err != nil { return gui.surfaceError(err) } - return gui.OSCommand.CopyToClipboard(message) + + if err := gui.OSCommand.CopyToClipboard(message); err != nil { + return gui.surfaceError(err) + } + + gui.raiseToast(gui.Tr.CommitMessageCopiedToClipboard) + + return nil } diff --git a/pkg/gui/global_handlers.go b/pkg/gui/global_handlers.go index 77a93436b..a17e79b65 100644 --- a/pkg/gui/global_handlers.go +++ b/pkg/gui/global_handlers.go @@ -1,6 +1,7 @@ package gui import ( + "fmt" "math" "strings" @@ -191,5 +192,13 @@ func (gui *Gui) handleCopySelectedSideContextItemToClipboard() error { return nil } - return gui.OSCommand.CopyToClipboard(itemId) + if err := gui.OSCommand.CopyToClipboard(itemId); err != nil { + return gui.surfaceError(err) + } + + truncatedItemId := utils.TruncateWithEllipsis(strings.ReplaceAll(itemId, "\n", " "), 50) + + gui.raiseToast(fmt.Sprintf("'%s' %s", truncatedItemId, gui.Tr.LcCopiedToClipboard)) + + return nil } diff --git a/pkg/i18n/dutch.go b/pkg/i18n/dutch.go index 9036f02b2..9b50ec79e 100644 --- a/pkg/i18n/dutch.go +++ b/pkg/i18n/dutch.go @@ -382,5 +382,7 @@ func dutchTranslationSet() TranslationSet { BranchNotFoundTitle: "Branch niet gevonden", BranchNotFoundPrompt: "Branch niet gevonden. Creëer een nieuwe branch genaamd", PullRequestURLCopiedToClipboard: "Pull-aanvraag-URL gekopieerd naar klembord", + CommitMessageCopiedToClipboard: "Commit message gekopieerd naar klembord", + LcCopiedToClipboard: "gekopieerd naar klembord", } } diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 50dea7d49..81a648928 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -431,6 +431,8 @@ type TranslationSet struct { NavigationTitle string PushingTagStatus string PullRequestURLCopiedToClipboard string + CommitMessageCopiedToClipboard string + LcCopiedToClipboard string } const englishReleaseNotes = `## lazygit 0.23.2 Release Notes @@ -932,5 +934,7 @@ func englishTranslationSet() TranslationSet { NavigationTitle: "List Panel Navigation", PushingTagStatus: "pushing tag", PullRequestURLCopiedToClipboard: "Pull request URL copied to clipboard", + CommitMessageCopiedToClipboard: "Commit message copied to clipboard", + LcCopiedToClipboard: "copied to clipboard", } } diff --git a/pkg/i18n/polish.go b/pkg/i18n/polish.go index 0edb697d1..c6ffba11a 100644 --- a/pkg/i18n/polish.go +++ b/pkg/i18n/polish.go @@ -252,5 +252,7 @@ func polishTranslationSet() TranslationSet { BranchNotFoundTitle: "Branch not found", BranchNotFoundPrompt: "Branch not found. Create a new branch named", PullRequestURLCopiedToClipboard: "URL żądania ściągnięcia skopiowany do schowka", + CommitMessageCopiedToClipboard: "Commit message skopiowany do schowka", + LcCopiedToClipboard: "skopiowany do schowka", } }