From 5e6d7768e13088cc0082614fd106b327214fdc6d Mon Sep 17 00:00:00 2001 From: Christian Stimming Date: Sat, 2 Feb 2008 10:20:17 +0100 Subject: git-gui: (i18n) Fix a bunch of still untranslated strings. Signed-off-by: Christian Stimming Signed-off-by: Shawn O. Pearce diff --git a/lib/checkout_op.tcl b/lib/checkout_op.tcl index f243966..6e14117 100644 --- a/lib/checkout_op.tcl +++ b/lib/checkout_op.tcl @@ -280,7 +280,7 @@ The rescan will be automatically started now. } elseif {[is_config_true gui.trustmtime]} { _readtree $this } else { - ui_status {Refreshing file status...} + ui_status [mc "Refreshing file status..."] set fd [git_read update-index \ -q \ --unmerged \ @@ -320,7 +320,7 @@ method _readtree {} { set readtree_d {} $::main_status start \ [mc "Updating working directory to '%s'..." [_name $this]] \ - {files checked out} + [mc "files checked out"] set fd [git_read --stderr read-tree \ -m \ @@ -447,7 +447,7 @@ If you wanted to be on a branch, create one now starting from 'This Detached Che } else { repository_state commit_type HEAD MERGE_HEAD set PARENT $HEAD - ui_status "Checked out '$name'." + ui_status [mc "Checked out '%s'." $name] } delete_this } diff --git a/lib/commit.tcl b/lib/commit.tcl index 947b201..40a7103 100644 --- a/lib/commit.tcl +++ b/lib/commit.tcl @@ -218,7 +218,7 @@ A good commit message has the following format: return } - ui_status {Calling pre-commit hook...} + ui_status [mc "Calling pre-commit hook..."] set pch_error {} fconfigure $fd_ph -blocking 0 -translation binary -eofchar {} fileevent $fd_ph readable \ @@ -233,7 +233,7 @@ proc commit_prehook_wait {fd_ph curHEAD msg_p} { if {[eof $fd_ph]} { if {[catch {close $fd_ph}]} { catch {file delete $msg_p} - ui_status {Commit declined by pre-commit hook.} + ui_status [mc "Commit declined by pre-commit hook."] hook_failed_popup pre-commit $pch_error unlock_index } else { @@ -256,7 +256,7 @@ proc commit_commitmsg {curHEAD msg_p} { return } - ui_status {Calling commit-msg hook...} + ui_status [mc "Calling commit-msg hook..."] set pch_error {} fconfigure $fd_ph -blocking 0 -translation binary -eofchar {} fileevent $fd_ph readable \ @@ -271,7 +271,7 @@ proc commit_commitmsg_wait {fd_ph curHEAD msg_p} { if {[eof $fd_ph]} { if {[catch {close $fd_ph}]} { catch {file delete $msg_p} - ui_status {Commit declined by commit-msg hook.} + ui_status [mc "Commit declined by commit-msg hook."] hook_failed_popup commit-msg $pch_error unlock_index } else { @@ -284,7 +284,7 @@ proc commit_commitmsg_wait {fd_ph curHEAD msg_p} { } proc commit_writetree {curHEAD msg_p} { - ui_status {Committing changes...} + ui_status [mc "Committing changes..."] set fd_wt [git_read write-tree] fileevent $fd_wt readable \ [list commit_committree $fd_wt $curHEAD $msg_p] @@ -301,7 +301,7 @@ proc commit_committree {fd_wt curHEAD msg_p} { if {[catch {close $fd_wt} err]} { catch {file delete $msg_p} error_popup [strcat [mc "write-tree failed:"] "\n\n$err"] - ui_status {Commit failed.} + ui_status [mc "Commit failed."] unlock_index return } @@ -345,7 +345,7 @@ A rescan will be automatically started now. if {[catch {set cmt_id [eval git $cmd]} err]} { catch {file delete $msg_p} error_popup [strcat [mc "commit-tree failed:"] "\n\n$err"] - ui_status {Commit failed.} + ui_status [mc "Commit failed."] unlock_index return } @@ -365,7 +365,7 @@ A rescan will be automatically started now. } err]} { catch {file delete $msg_p} error_popup [strcat [mc "update-ref failed:"] "\n\n$err"] - ui_status {Commit failed.} + ui_status [mc "Commit failed."] unlock_index return } diff --git a/lib/index.tcl b/lib/index.tcl index 30a244c..3c1fce7 100644 --- a/lib/index.tcl +++ b/lib/index.tcl @@ -310,7 +310,7 @@ proc add_helper {txt paths} { update_index \ $txt \ $pathList \ - [concat $after {ui_status {Ready to commit.}}] + [concat $after {ui_status [mc "Ready to commit."]}] } } diff --git a/lib/merge.tcl b/lib/merge.tcl index 63e1427..cc26b07 100644 --- a/lib/merge.tcl +++ b/lib/merge.tcl @@ -116,8 +116,7 @@ method _start {} { lappend cmd HEAD lappend cmd $name - set msg [mc "Merging %s and %s" $current_branch $stitle] - ui_status "$msg..." + ui_status [mc "Merging %s and %s..." $current_branch $stitle] set cons [console::new [mc "Merge"] "merge $stitle"] console::exec $cons $cmd [cb _finish $cons] @@ -236,7 +235,7 @@ Continue with resetting the current changes?"] set fd [git_read --stderr read-tree --reset -u -v HEAD] fconfigure $fd -blocking 0 -translation binary fileevent $fd readable [namespace code [list _reset_wait $fd]] - $::main_status start [mc "Aborting"] {files reset} + $::main_status start [mc "Aborting"] [mc "files reset"] } else { unlock_index } diff --git a/po/git-gui.pot b/po/git-gui.pot index dfa48ae..3f139da 100644 --- a/po/git-gui.pot +++ b/po/git-gui.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2007-11-24 10:36+0100\n" +"POT-Creation-Date: 2008-02-02 10:14+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -386,31 +386,31 @@ msgstr "" msgid "File:" msgstr "" -#: git-gui.sh:2545 -msgid "Refresh" +#: git-gui.sh:2573 +msgid "Apply/Reverse Hunk" msgstr "" -#: git-gui.sh:2566 -msgid "Apply/Reverse Hunk" +#: git-gui.sh:2579 +msgid "Show Less Context" msgstr "" -#: git-gui.sh:2572 -msgid "Decrease Font Size" +#: git-gui.sh:2586 +msgid "Show More Context" msgstr "" -#: git-gui.sh:2576 -msgid "Increase Font Size" +#: git-gui.sh:2594 +msgid "Refresh" msgstr "" -#: git-gui.sh:2581 -msgid "Show Less Context" +#: git-gui.sh:2615 +msgid "Decrease Font Size" msgstr "" -#: git-gui.sh:2588 -msgid "Show More Context" +#: git-gui.sh:2619 +msgid "Increase Font Size" msgstr "" -#: git-gui.sh:2602 +#: git-gui.sh:2630 msgid "Unstage Hunk From Commit" msgstr "" @@ -766,6 +766,10 @@ msgstr "" msgid "Updating working directory to '%s'..." msgstr "" +#: lib/checkout_op.tcl:323 +msgid "files checked out" +msgstr "" + #: lib/checkout_op.tcl:353 #, tcl-format msgid "Aborted checkout of '%s' (file level merging is required)." @@ -1182,11 +1186,40 @@ msgid "" "- Remaining lines: Describe why this change is good.\n" msgstr "" -#: lib/commit.tcl:257 +#: lib/commit.tcl:207 +#, tcl-format +msgid "warning: Tcl does not support encoding '%s'." +msgstr "" + +#: lib/commit.tcl:221 +msgid "Calling pre-commit hook..." +msgstr "" + +#: lib/commit.tcl:236 +msgid "Commit declined by pre-commit hook." +msgstr "" + +#: lib/commit.tcl:259 +msgid "Calling commit-msg hook..." +msgstr "" + +#: lib/commit.tcl:274 +msgid "Commit declined by commit-msg hook." +msgstr "" + +#: lib/commit.tcl:287 +msgid "Committing changes..." +msgstr "" + +#: lib/commit.tcl:303 msgid "write-tree failed:" msgstr "" -#: lib/commit.tcl:275 +#: lib/commit.tcl:304 lib/commit.tcl:348 lib/commit.tcl:368 +msgid "Commit failed." +msgstr "" + +#: lib/commit.tcl:321 #, tcl-format msgid "Commit %s appears to be corrupt" msgstr "" @@ -1204,12 +1237,7 @@ msgstr "" msgid "No changes to commit." msgstr "" -#: lib/commit.tcl:303 -#, tcl-format -msgid "warning: Tcl does not support encoding '%s'." -msgstr "" - -#: lib/commit.tcl:317 +#: lib/commit.tcl:347 msgid "commit-tree failed:" msgstr "" @@ -1373,6 +1401,10 @@ msgstr "" msgid "Unstaging %s from commit" msgstr "" +#: lib/index.tcl:313 +msgid "Ready to commit." +msgstr "" + #: lib/index.tcl:326 #, tcl-format msgid "Adding %s" @@ -1491,7 +1523,11 @@ msgstr "" msgid "Aborting" msgstr "" -#: lib/merge.tcl:266 +#: lib/merge.tcl:238 +msgid "files reset" +msgstr "" + +#: lib/merge.tcl:265 msgid "Abort failed." msgstr "" -- cgit v0.10.2-6-g49f6 From 5f09a37bbb3507a1e66734e9feae915fa6e8cea6 Mon Sep 17 00:00:00 2001 From: Christian Stimming Date: Sat, 2 Feb 2008 10:18:27 +0100 Subject: git-gui: Update German translation. Signed-off-by: Christian Stimming Signed-off-by: Shawn O. Pearce diff --git a/po/de.po b/po/de.po index 2dfe07e..d7c38f9 100644 --- a/po/de.po +++ b/po/de.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: git-gui\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2007-11-24 10:36+0100\n" -"PO-Revision-Date: 2008-01-15 20:33+0100\n" +"POT-Creation-Date: 2008-02-02 10:14+0100\n" +"PO-Revision-Date: 2008-02-02 10:18+0100\n" "Last-Translator: Christian Stimming \n" "Language-Team: German\n" "MIME-Version: 1.0\n" @@ -343,7 +343,9 @@ msgstr "Online-Dokumentation" #: git-gui.sh:2201 #, tcl-format msgid "fatal: cannot stat path %s: No such file or directory" -msgstr "Fehler: Verzeichnis »%s« kann nicht gelesen werden: Datei oder Verzeichnis nicht gefunden" +msgstr "" +"Fehler: Verzeichnis »%s« kann nicht gelesen werden: Datei oder Verzeichnis " +"nicht gefunden" #: git-gui.sh:2234 msgid "Current Branch:" @@ -371,19 +373,19 @@ msgstr "Erste Versionsbeschreibung:" #: git-gui.sh:2370 msgid "Amended Commit Message:" -msgstr "Nachgebesserte Versionsbeschreibung:" +msgstr "Nachgebesserte Beschreibung:" #: git-gui.sh:2371 msgid "Amended Initial Commit Message:" -msgstr "Nachgebesserte erste Versionsbeschreibung:" +msgstr "Nachgebesserte erste Beschreibung:" #: git-gui.sh:2372 msgid "Amended Merge Commit Message:" -msgstr "Nachgebesserte Zusammenführungs-Versionsbeschreibung:" +msgstr "Nachgebesserte Zusammenführungs-Beschreibung:" #: git-gui.sh:2373 msgid "Merge Commit Message:" -msgstr "Zusammenführungs-Versionsbeschreibung:" +msgstr "Zusammenführungs-Beschreibung:" #: git-gui.sh:2374 msgid "Commit Message:" @@ -397,31 +399,31 @@ msgstr "Alle kopieren" msgid "File:" msgstr "Datei:" -#: git-gui.sh:2545 -msgid "Refresh" -msgstr "Aktualisieren" - -#: git-gui.sh:2566 +#: git-gui.sh:2573 msgid "Apply/Reverse Hunk" msgstr "Kontext anwenden/umkehren" -#: git-gui.sh:2572 -msgid "Decrease Font Size" -msgstr "Schriftgröße verkleinern" - -#: git-gui.sh:2576 -msgid "Increase Font Size" -msgstr "Schriftgröße vergrößern" - -#: git-gui.sh:2581 +#: git-gui.sh:2579 msgid "Show Less Context" msgstr "Weniger Zeilen anzeigen" -#: git-gui.sh:2588 +#: git-gui.sh:2586 msgid "Show More Context" msgstr "Mehr Zeilen anzeigen" -#: git-gui.sh:2602 +#: git-gui.sh:2594 +msgid "Refresh" +msgstr "Aktualisieren" + +#: git-gui.sh:2615 +msgid "Decrease Font Size" +msgstr "Schriftgröße verkleinern" + +#: git-gui.sh:2619 +msgid "Increase Font Size" +msgstr "Schriftgröße vergrößern" + +#: git-gui.sh:2630 msgid "Unstage Hunk From Commit" msgstr "Kontext aus Bereitstellung herausnehmen" @@ -542,7 +544,7 @@ msgstr "Kopiert oder verschoben durch:" #: lib/branch_checkout.tcl:14 lib/branch_checkout.tcl:19 msgid "Checkout Branch" -msgstr "Zweig umstellen" +msgstr "Auf Zweig umstellen" #: lib/branch_checkout.tcl:23 msgid "Checkout" @@ -805,11 +807,15 @@ msgstr "" msgid "Updating working directory to '%s'..." msgstr "Arbeitskopie umstellen auf »%s«..." +#: lib/checkout_op.tcl:323 +msgid "files checked out" +msgstr "Dateien aktualisiert" + #: lib/checkout_op.tcl:353 #, tcl-format msgid "Aborted checkout of '%s' (file level merging is required)." msgstr "" -"Zweig umstellen von »%s« abgebrochen (Zusammenführen der Dateien ist " +"Auf Zweig »%s« umstellen abgebrochen (Zusammenführen der Dateien ist " "notwendig)." #: lib/checkout_op.tcl:354 @@ -1069,15 +1075,21 @@ msgstr "Für Objekt konnte kein Hardlink erstellt werden: %s" #: lib/choose_repository.tcl:847 msgid "Cannot fetch branches and objects. See console output for details." -msgstr "Zweige und Objekte konnten nicht angefordert werden. Kontrollieren Sie die Ausgaben auf der Konsole für weitere Angaben." +msgstr "" +"Zweige und Objekte konnten nicht angefordert werden. Kontrollieren Sie die " +"Ausgaben auf der Konsole für weitere Angaben." #: lib/choose_repository.tcl:858 msgid "Cannot fetch tags. See console output for details." -msgstr "Markierungen konnten nicht angefordert werden. Kontrollieren Sie die Ausgaben auf der Konsole für weitere Angaben." +msgstr "" +"Markierungen konnten nicht angefordert werden. Kontrollieren Sie die " +"Ausgaben auf der Konsole für weitere Angaben." #: lib/choose_repository.tcl:882 msgid "Cannot determine HEAD. See console output for details." -msgstr "Die Zweigspitze (HEAD) konnte nicht gefunden werden. Kontrollieren Sie die Ausgaben auf der Konsole für weitere Angaben." +msgstr "" +"Die Zweigspitze (HEAD) konnte nicht gefunden werden. Kontrollieren Sie die " +"Ausgaben auf der Konsole für weitere Angaben." #: lib/choose_repository.tcl:891 #, tcl-format @@ -1273,11 +1285,40 @@ msgstr "" "\n" "- Rest: Eine ausführliche Beschreibung, warum diese Änderung hilfreich ist.\n" -#: lib/commit.tcl:257 +#: lib/commit.tcl:207 +#, tcl-format +msgid "warning: Tcl does not support encoding '%s'." +msgstr "Warning: Tcl/Tk unterstützt die Zeichencodierung »%s« nicht." + +#: lib/commit.tcl:221 +msgid "Calling pre-commit hook..." +msgstr "" + +#: lib/commit.tcl:236 +msgid "Commit declined by pre-commit hook." +msgstr "" + +#: lib/commit.tcl:259 +msgid "Calling commit-msg hook..." +msgstr "" + +#: lib/commit.tcl:274 +msgid "Commit declined by commit-msg hook." +msgstr "" + +#: lib/commit.tcl:287 +msgid "Committing changes..." +msgstr "Änderungen eintragen..." + +#: lib/commit.tcl:303 msgid "write-tree failed:" msgstr "write-tree fehlgeschlagen:" -#: lib/commit.tcl:275 +#: lib/commit.tcl:304 lib/commit.tcl:348 lib/commit.tcl:368 +msgid "Commit failed." +msgstr "Eintragen fehlgeschlagen." + +#: lib/commit.tcl:321 #, tcl-format msgid "Commit %s appears to be corrupt" msgstr "Version »%s« scheint beschädigt zu sein" @@ -1301,12 +1342,7 @@ msgstr "" msgid "No changes to commit." msgstr "Keine Änderungen, die eingetragen werden können." -#: lib/commit.tcl:303 -#, tcl-format -msgid "warning: Tcl does not support encoding '%s'." -msgstr "Warning: Tcl/Tk unterstützt die Zeichencodierung »%s« nicht." - -#: lib/commit.tcl:317 +#: lib/commit.tcl:347 msgid "commit-tree failed:" msgstr "commit-tree fehlgeschlagen:" @@ -1440,7 +1476,8 @@ msgstr "Fehler beim Laden des Vergleichs:" #: lib/diff.tcl:302 msgid "Failed to unstage selected hunk." -msgstr "Fehler beim Herausnehmen des gewählten Kontexts aus der Bereitstellung." +msgstr "" +"Fehler beim Herausnehmen des gewählten Kontexts aus der Bereitstellung." #: lib/diff.tcl:309 msgid "Failed to stage selected hunk." @@ -1471,7 +1508,10 @@ msgstr "Fehler in Bereitstellung" msgid "" "Updating the Git index failed. A rescan will be automatically started to " "resynchronize git-gui." -msgstr "Das Aktualisieren der Git-Bereitstellung ist fehlgeschlagen. Eine allgemeine Git-Aktualisierung wird jetzt gestartet, um git-gui wieder mit git zu synchronisieren." +msgstr "" +"Das Aktualisieren der Git-Bereitstellung ist fehlgeschlagen. Eine allgemeine " +"Git-Aktualisierung wird jetzt gestartet, um git-gui wieder mit git zu " +"synchronisieren." #: lib/index.tcl:27 msgid "Continue" @@ -1486,6 +1526,10 @@ msgstr "Bereitstellung freigeben" msgid "Unstaging %s from commit" msgstr "Datei »%s« aus der Bereitstellung herausnehmen" +#: lib/index.tcl:313 +msgid "Ready to commit." +msgstr "Bereit zum Eintragen." + #: lib/index.tcl:326 #, tcl-format msgid "Adding %s" @@ -1503,7 +1547,8 @@ msgstr "Änderungen in den gewählten %i Dateien verwerfen?" #: lib/index.tcl:389 msgid "Any unstaged changes will be permanently lost by the revert." -msgstr "Alle nicht bereitgestellten Änderungen werden beim Verwerfen verloren gehen." +msgstr "" +"Alle nicht bereitgestellten Änderungen werden beim Verwerfen verloren gehen." #: lib/index.tcl:392 msgid "Do Nothing" @@ -1641,7 +1686,11 @@ msgstr "" msgid "Aborting" msgstr "Abbruch" -#: lib/merge.tcl:266 +#: lib/merge.tcl:238 +msgid "files reset" +msgstr "Dateien zurückgesetzt" + +#: lib/merge.tcl:265 msgid "Abort failed." msgstr "Abbruch fehlgeschlagen." -- cgit v0.10.2-6-g49f6 From 20a87ecc5861b0e1b76b99549cfaa965b2b27618 Mon Sep 17 00:00:00 2001 From: Jay Soffian Date: Mon, 11 Feb 2008 21:33:52 -0500 Subject: git-gui: support Git Gui.app under OS X 10.5 The Tk Framework moved its location in 10.5 compared to 10.4 Signed-off-by: Jay Soffian Tested-by: Seth Falcon Signed-off-by: Shawn O. Pearce diff --git a/Makefile b/Makefile index 34438cd..081d755 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,7 @@ GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') uname_O := $(shell sh -c 'uname -o 2>/dev/null || echo not') +uname_R := $(shell sh -c 'uname -r 2>/dev/null || echo not') SCRIPT_SH = git-gui.sh GITGUI_MAIN := git-gui @@ -93,7 +94,14 @@ endif TCL_PATH ?= tclsh TCLTK_PATH ?= wish -TKFRAMEWORK = /Library/Frameworks/Tk.framework/Resources/Wish.app + +ifeq ($(uname_S),Darwin) + TKFRAMEWORK = /Library/Frameworks/Tk.framework/Resources/Wish.app + ifeq ($(shell expr "$(uname_R)" : '9\.'),2) + TKFRAMEWORK = /System/Library/Frameworks/Tk.framework/Resources/Wish\ Shell.app + endif + TKEXECUTABLE = $(shell basename "$(TKFRAMEWORK)" .app) +endif ifeq ($(findstring $(MAKEFLAGS),s),s) QUIET_GEN = @@ -147,7 +155,7 @@ git-gui: GIT-VERSION-FILE GIT-GUI-VARS echo then >>$@+ && \ echo ' 'echo \'git-gui version '$(GITGUI_VERSION)'\' >>$@+ && \ echo else >>$@+ && \ - echo ' 'exec \''$(libdir_SQ)/Git Gui.app/Contents/MacOS/Wish'\' \ + echo ' 'exec \''$(libdir_SQ)/Git Gui.app/Contents/MacOS/$(subst \,,$(TKEXECUTABLE))'\' \ '"$$0" "$$@"' >>$@+ && \ echo fi >>$@+ && \ chmod +x $@+ && \ @@ -157,14 +165,15 @@ Git\ Gui.app: GIT-VERSION-FILE GIT-GUI-VARS \ macosx/Info.plist \ macosx/git-gui.icns \ macosx/AppMain.tcl \ - $(TKFRAMEWORK)/Contents/MacOS/Wish + $(TKFRAMEWORK)/Contents/MacOS/$(TKEXECUTABLE) $(QUIET_GEN)rm -rf '$@' '$@'+ && \ mkdir -p '$@'+/Contents/MacOS && \ mkdir -p '$@'+/Contents/Resources/Scripts && \ - cp '$(subst ','\'',$(TKFRAMEWORK))/Contents/MacOS/Wish' \ + cp '$(subst ','\'',$(subst \,,$(TKFRAMEWORK)/Contents/MacOS/$(TKEXECUTABLE)))' \ '$@'+/Contents/MacOS && \ cp macosx/git-gui.icns '$@'+/Contents/Resources && \ sed -e 's/@@GITGUI_VERSION@@/$(GITGUI_VERSION)/g' \ + -e 's/@@GITGUI_TKEXECUTABLE@@/$(TKEXECUTABLE)/g' \ macosx/Info.plist \ >'$@'+/Contents/Info.plist && \ sed -e 's|@@gitexecdir@@|$(gitexecdir_SQ)|' \ diff --git a/macosx/Info.plist b/macosx/Info.plist index 99913ec..b3bf15f 100644 --- a/macosx/Info.plist +++ b/macosx/Info.plist @@ -5,7 +5,7 @@ CFBundleDevelopmentRegion English CFBundleExecutable - Wish + @@GITGUI_TKEXECUTABLE@@ CFBundleGetInfoString Git Gui @@GITGUI_VERSION@@ © 2006-2007 Shawn Pearce, et. al. CFBundleIconFile -- cgit v0.10.2-6-g49f6 From 95b002eeb38de89feb7f0cc1a55721b45fd3cf11 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Thu, 7 Feb 2008 02:35:25 -0500 Subject: git-gui: Automatically spell check commit messages as the user types Many user friendly tools like word processors, email editors and web browsers allow users to spell check the message they are writing as they type it, making it easy to identify a common misspelling of a word and correct it on the fly. We now open a bi-directional pipe to Aspell and feed the message text the user is editing off to the program about once every 300 milliseconds. This is frequent enough that the user sees the results almost immediately, but is not so frequent as to cause significant additional load on the system. If the user has modified the message text during the last 300 milliseconds we delay until the next period, ensuring that we avoid flooding the Aspell process with a lot of text while the user is actively typing their message. We wait to send the current message buffer to Aspell until the user is at a word boundary, thus ensuring that we are not likely to ask for misspelled word detection on a word that the user is actively typing, as most words are misspelled when only partially typed, even if the user has thus far typed it correctly. Misspelled words are highlighted in red and are given an underline, causing the word to stand out from the others in the buffer. This is a very common user interface idiom for displaying misspelled words, but differs from one platform to the next in slight variations. For example the Mac OS X system prefers using a dashed red underline, leaving the word in the original text color. Unfortunately the control that Tk gives us over text display is not powerful enough to handle such formatting so we have to work with the least common denominator. The top suggestions for a misspelling are saved in an array and offered to the user when they right-click (or on the Mac ctrl-click) a misspelled word. Selecting an entry from this menu will replace the misspelling with the correction shown. Replacement is integrated with the undo/redo stack so undoing a replacement will restore the misspelled original text. If Aspell could not be started during git-gui launch we silently eat the error and run without spell checking support. This way users who do not have Aspell in their $PATH can continue to use git-gui, although they will not get the advanced spelling functionality. If Aspell started successfully the version line and language are shown in git-gui's about box, below the Tcl/Tk versions. This way the user can verify the Aspell function has been activated. If Aspell crashes while we are running we inform the user with an error dialog and then disable Aspell entirely for the rest of this git-gui session. This prevents us from fork-bombing the system with Aspell instances that always crash when presented with the current message text, should there be a bug in either Aspell or in git-gui's output to it. We escape all input lines with ^, as recommended by the Aspell manual page, as this allows Aspell to properly ignore any input line that is otherwise looking like a command (e.g. ! to enable terse output). By using this escape however we need to correct all word offsets by -1 as Aspell is apparently considering the ^ escape to be part of the line's character count, but our Tk text widget obviously does not. Available dictionaries are offered in the Options dialog, allowing the user to select the language they want to spellcheck commit messages with for the current repository, as well as the global user setting that all repositories inherit. Special thanks to Adam Flott for suggesting connecting git-gui to Aspell for the purpose of spell checking the commit message, and to Wincent Colaiuta for the idea to wait for a word boundary before passing the message over for checking. Signed-off-by: Shawn O. Pearce diff --git a/git-gui.sh b/git-gui.sh index f42e461..5d65272 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -612,6 +612,7 @@ set default_config(gui.pruneduringfetch) false set default_config(gui.trustmtime) false set default_config(gui.diffcontext) 5 set default_config(gui.newbranchtemplate) {} +set default_config(gui.spellingdictionary) {} set default_config(gui.fontui) [font configure font_ui] set default_config(gui.fontdiff) [font configure font_diff] set font_descs { @@ -1683,6 +1684,7 @@ set is_quitting 0 proc do_quit {} { global ui_comm is_quitting repo_config commit_type global GITGUI_BCK_exists GITGUI_BCK_i + global ui_comm_spell if {$is_quitting} return set is_quitting 1 @@ -1710,6 +1712,12 @@ proc do_quit {} { } } + # -- Cancel our spellchecker if its running. + # + if {[info exists ui_comm_spell]} { + $ui_comm_spell stop + } + # -- Remove our editor backup, its not needed. # after cancel $GITGUI_BCK_i @@ -2454,7 +2462,7 @@ $ctxm add separator $ctxm add command \ -label [mc "Sign Off"] \ -command do_signoff -bind_button3 $ui_comm "tk_popup $ctxm %X %Y" +set ui_comm_ctxm $ctxm # -- Diff Header # @@ -2857,6 +2865,30 @@ if {[winfo exists $ui_comm]} { } backup_commit_buffer + + # -- If the user has aspell available we can drive it + # in pipe mode to spellcheck the commit message. + # + set spell_cmd [list |] + set spell_dict [get_config gui.spellingdictionary] + lappend spell_cmd aspell + if {$spell_dict ne {}} { + lappend spell_cmd --master=$spell_dict + } + lappend spell_cmd --mode=none + lappend spell_cmd --encoding=utf-8 + lappend spell_cmd pipe + if {$spell_dict eq {none} + || [catch {set spell_fd [open $spell_cmd r+]} spell_err]} { + bind_button3 $ui_comm [list tk_popup $ui_comm_ctxm %X %Y] + } else { + set ui_comm_spell [spellcheck::init \ + $spell_fd \ + $ui_comm \ + $ui_comm_ctxm \ + ] + } + unset -nocomplain spell_cmd spell_fd spell_err spell_dict } lock_index begin-read diff --git a/lib/about.tcl b/lib/about.tcl index 719fc54..47be8eb 100644 --- a/lib/about.tcl +++ b/lib/about.tcl @@ -4,6 +4,7 @@ proc do_about {} { global appvers copyright oguilib global tcl_patchLevel tk_patchLevel + global ui_comm_spell set w .about_dialog toplevel $w @@ -40,6 +41,10 @@ proc do_about {} { append v "Tcl version $tcl_patchLevel" append v ", Tk version $tk_patchLevel" } + if {[info exists ui_comm_spell]} { + append v "\n" + append v [$ui_comm_spell version] + } set d {} append d "git wrapper: $::_git\n" diff --git a/lib/option.tcl b/lib/option.tcl index f812e5e..3bfa2ed 100644 --- a/lib/option.tcl +++ b/lib/option.tcl @@ -5,6 +5,7 @@ proc save_config {} { global default_config font_descs global repo_config global_config global repo_config_new global_config_new + global ui_comm_spell foreach option $font_descs { set name [lindex $option 0] @@ -52,11 +53,23 @@ proc save_config {} { set repo_config($name) $value } } + + if {[info exists repo_config(gui.spellingdictionary)]} { + set value $repo_config(gui.spellingdictionary) + if {$value eq {none}} { + if {[info exists ui_comm_spell]} { + $ui_comm_spell stop + } + } elseif {[info exists ui_comm_spell]} { + $ui_comm_spell lang $value + } + } } proc do_options {} { global repo_config global_config font_descs global repo_config_new global_config_new + global ui_comm_spell array unset repo_config_new array unset global_config_new @@ -159,6 +172,34 @@ proc do_options {} { } } + set all_dicts [linsert \ + [spellcheck::available_langs] \ + 0 \ + none] + incr optid + foreach f {repo global} { + if {![info exists ${f}_config_new(gui.spellingdictionary)]} { + if {[info exists ui_comm_spell]} { + set value [$ui_comm_spell lang] + } else { + set value none + } + set ${f}_config_new(gui.spellingdictionary) $value + } + + frame $w.$f.$optid + label $w.$f.$optid.l -text [mc "Spelling Dictionary:"] + eval tk_optionMenu $w.$f.$optid.v \ + ${f}_config_new(gui.spellingdictionary) \ + $all_dicts + pack $w.$f.$optid.l -side left -anchor w -fill x + pack $w.$f.$optid.v -side left -anchor w \ + -fill x -expand 1 \ + -padx 5 + pack $w.$f.$optid -side top -anchor w -fill x + } + unset all_dicts + set all_fonts [lsort [font families]] foreach option $font_descs { set name [lindex $option 0] diff --git a/lib/spellcheck.tcl b/lib/spellcheck.tcl new file mode 100644 index 0000000..01c2c4f --- /dev/null +++ b/lib/spellcheck.tcl @@ -0,0 +1,363 @@ +# git-gui spellchecking support through aspell +# Copyright (C) 2008 Shawn Pearce + +class spellcheck { + +field s_fd {} ; # pipe to aspell +field s_version ; # aspell version string +field s_lang ; # current language code + +field w_text ; # text widget we are spelling +field w_menu ; # context menu for the widget +field s_menuidx 0 ; # last index of insertion into $w_menu + +field s_i ; # timer registration for _run callbacks +field s_clear 0 ; # did we erase mispelled tags yet? +field s_seen [list] ; # lines last seen from $w_text in _run +field s_checked [list] ; # lines already checked +field s_pending [list] ; # [$line $data] sent to aspell +field s_suggest ; # array, list of suggestions, keyed by misspelling + +constructor init {pipe_fd ui_text ui_menu} { + set w_text $ui_text + set w_menu $ui_menu + + _connect $this $pipe_fd + return $this +} + +method _connect {pipe_fd} { + fconfigure $pipe_fd \ + -encoding utf-8 \ + -eofchar {} \ + -translation lf + + if {[gets $pipe_fd s_version] <= 0} { + close $pipe_fd + error [mc "Not connected to aspell"] + } + if {{@(#) } ne [string range $s_version 0 4]} { + close $pipe_fd + error [strcat [mc "Unrecognized aspell version"] ": $s_version"] + } + set s_version [string range $s_version 5 end] + + puts $pipe_fd ! ; # enable terse mode + puts $pipe_fd {$$cr master} ; # fetch the language + flush $pipe_fd + + gets $pipe_fd s_lang + regexp {[/\\]([^/\\]+)\.[^\.]+$} $s_lang _ s_lang + + if {$::default_config(gui.spellingdictionary) eq {} + && [get_config gui.spellingdictionary] eq {}} { + set ::default_config(gui.spellingdictionary) $s_lang + } + + if {$s_fd ne {}} { + catch {close $s_fd} + } + set s_fd $pipe_fd + + fconfigure $s_fd -blocking 0 + fileevent $s_fd readable [cb _read] + + $w_text tag conf misspelled \ + -foreground red \ + -underline 1 + bind_button3 $w_text [cb _popup_suggest %X %Y @%x,%y] + + array unset s_suggest + set s_seen [list] + set s_checked [list] + set s_pending [list] + _run $this +} + +method lang {{n {}}} { + if {$n ne {} && $s_lang ne $n} { + set spell_cmd [list |] + lappend spell_cmd aspell + lappend spell_cmd --master=$n + lappend spell_cmd --mode=none + lappend spell_cmd --encoding=UTF-8 + lappend spell_cmd pipe + _connect $this [open $spell_cmd r+] + } + return $s_lang +} + +method version {} { + return "$s_version, $s_lang" +} + +method stop {} { + while {$s_menuidx > 0} { + $w_menu delete 0 + incr s_menuidx -1 + } + $w_text tag delete misspelled + + catch {close $s_fd} + catch {after cancel $s_i} + set s_fd {} + set s_i {} + set s_lang {} +} + +method _popup_suggest {X Y pos} { + while {$s_menuidx > 0} { + $w_menu delete 0 + incr s_menuidx -1 + } + + set b_loc [$w_text index "$pos wordstart"] + set e_loc [_wordend $this $b_loc] + set orig [$w_text get $b_loc $e_loc] + set tags [$w_text tag names $b_loc] + + if {[lsearch -exact $tags misspelled] >= 0} { + if {[info exists s_suggest($orig)]} { + set cnt 0 + foreach s $s_suggest($orig) { + if {$cnt < 5} { + $w_menu insert $s_menuidx command \ + -label $s \ + -command [cb _replace $b_loc $e_loc $s] + incr s_menuidx + incr cnt + } else { + break + } + } + } else { + $w_menu insert $s_menuidx command \ + -label [mc "No Suggestions"] \ + -state disabled + incr s_menuidx + } + $w_menu insert $s_menuidx separator + incr s_menuidx + } + + $w_text mark set saved-insert insert + tk_popup $w_menu $X $Y +} + +method _replace {b_loc e_loc word} { + $w_text configure -autoseparators 0 + $w_text edit separator + + $w_text delete $b_loc $e_loc + $w_text insert $b_loc $word + + $w_text edit separator + $w_text configure -autoseparators 1 + $w_text mark set insert saved-insert +} + +method _restart_timer {} { + set s_i [after 300 [cb _run]] +} + +proc _match_length {max_line arr_name} { + upvar $arr_name a + + if {[llength $a] > $max_line} { + set a [lrange $a 0 $max_line] + } + while {[llength $a] <= $max_line} { + lappend a {} + } +} + +method _wordend {pos} { + set pos [$w_text index "$pos wordend"] + set tags [$w_text tag names $pos] + while {[lsearch -exact $tags misspelled] >= 0} { + set pos [$w_text index "$pos +1c"] + set tags [$w_text tag names $pos] + } + return $pos +} + +method _run {} { + set cur_pos [$w_text index {insert -1c}] + set cur_line [lindex [split $cur_pos .] 0] + set max_line [lindex [split [$w_text index end] .] 0] + _match_length $max_line s_seen + _match_length $max_line s_checked + + # Nothing in the message buffer? Nothing to spellcheck. + # + if {$cur_line == 1 + && $max_line == 2 + && [$w_text get 1.0 end] eq "\n"} { + array unset s_suggest + _restart_timer $this + return + } + + set active 0 + for {set n 1} {$n <= $max_line} {incr n} { + set s [$w_text get "$n.0" "$n.end"] + + # Don't spellcheck the current line unless we are at + # a word boundary. The user might be typing on it. + # + if {$n == $cur_line + && ![regexp {^\W$} [$w_text get $cur_pos insert]]} { + + # If the current word is mispelled remove the tag + # but force a spellcheck later. + # + set tags [$w_text tag names $cur_pos] + if {[lsearch -exact $tags misspelled] >= 0} { + $w_text tag remove misspelled \ + "$cur_pos wordstart" \ + [_wordend $this $cur_pos] + lset s_seen $n $s + lset s_checked $n {} + } + + continue + } + + if {[lindex $s_seen $n] eq $s + && [lindex $s_checked $n] ne $s} { + # Don't send empty lines to Aspell it doesn't check them. + # + if {$s eq {}} { + lset s_checked $n $s + continue + } + + # Don't send typical s-b-o lines as the emails are + # almost always misspelled according to Aspell. + # + if {[regexp -nocase {^[a-z-]+-by:.*<.*@.*>$} $s]} { + $w_text tag remove misspelled "$n.0" "$n.end" + lset s_checked $n $s + continue + } + + puts $s_fd ^$s + lappend s_pending [list $n $s] + set active 1 + } else { + # Delay until another idle loop to make sure we don't + # spellcheck lines the user is actively changing. + # + lset s_seen $n $s + } + } + + if {$active} { + set s_clear 1 + flush $s_fd + } else { + _restart_timer $this + } +} + +method _read {} { + while {[gets $s_fd line] >= 0} { + set lineno [lindex $s_pending 0 0] + + if {$s_clear} { + $w_text tag remove misspelled "$lineno.0" "$lineno.end" + set s_clear 0 + } + + if {$line eq {}} { + lset s_checked $lineno [lindex $s_pending 0 1] + set s_pending [lrange $s_pending 1 end] + set s_clear 1 + continue + } + + set sugg [list] + switch -- [string range $line 0 1] { + {& } { + set line [split [string range $line 2 end] :] + set info [split [lindex $line 0] { }] + set orig [lindex $info 0] + set offs [lindex $info 2] + foreach s [split [lindex $line 1] ,] { + lappend sugg [string range $s 1 end] + } + } + {# } { + set info [split [string range $line 2 end] { }] + set orig [lindex $info 0] + set offs [lindex $info 1] + } + default { + puts stderr " $line" + continue + } + } + + incr offs -1 + set b_loc "$lineno.$offs" + set e_loc [$w_text index "$lineno.$offs wordend"] + set curr [$w_text get $b_loc $e_loc] + + # At least for English curr = "bob", orig = "bob's" + # so Tk didn't include the 's but Aspell did. We + # try to round out the word. + # + while {$curr ne $orig + && [string equal -length [llength $curr] $curr $orig]} { + set n_loc [$w_text index "$e_loc +1c"] + set n_curr [$w_text get $b_loc $n_loc] + if {$n_curr eq $curr} { + break + } + set curr $n_curr + set e_loc $n_loc + } + + if {$curr eq $orig} { + $w_text tag add misspelled $b_loc $e_loc + if {[llength $sugg] > 0} { + set s_suggest($orig) $sugg + } else { + unset -nocomplain s_suggest($orig) + } + } else { + unset -nocomplain s_suggest($orig) + } + } + + fconfigure $s_fd -block 1 + if {[eof $s_fd]} { + if {![catch {close $s_fd} err]} { + set err [mc "unexpected eof from aspell"] + } + catch {after cancel $s_i} + $w_text tag remove misspelled 1.0 end + error_popup [strcat "Spell Checker Failed" "\n\n" $err] + return + } + fconfigure $s_fd -block 0 + + if {[llength $s_pending] == 0} { + _restart_timer $this + } +} + +proc available_langs {} { + set langs [list] + catch { + set fd [open [list | aspell dump dicts] r] + while {[gets $fd line] >= 0} { + if {$line eq {}} continue + lappend langs $line + } + close $fd + } + return $langs +} + +} -- cgit v0.10.2-6-g49f6