From ae623ed82d361acac88f3d69220bee7d15707220 Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Fri, 25 Oct 2013 22:28:42 -0500 Subject: [PATCH] separate out state for spell checking string constants from that for spell checking scribble {} content --- .../gui-doc/scribblings/framework/color.scrbl | 14 +++++++++- .../gui-lib/framework/private/color.rkt | 26 +++++++++++++++---- .../gui-lib/framework/private/main.rkt | 10 +++++++ 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/pkgs/gui-pkgs/gui-doc/scribblings/framework/color.scrbl b/pkgs/gui-pkgs/gui-doc/scribblings/framework/color.scrbl index ef15abaf7a..42a930118d 100644 --- a/pkgs/gui-pkgs/gui-doc/scribblings/framework/color.scrbl +++ b/pkgs/gui-pkgs/gui-doc/scribblings/framework/color.scrbl @@ -200,7 +200,19 @@ @defmethod[(set-spell-check-strings [b? boolean?]) void?]{ If called with @racket[#t], tell the colorer to spell-check - string constants. Otherwise, disable spell-checking of constants. + string constants. Otherwise, disable spell-checking of + string constants. + } + + @defmethod[(get-spell-check-text) boolean?]{ + Returns @racket[#t] if the colorer will attempt to + spell-check text (e.g., the words inside @litchar[@"{"] and + @litchar[@"}"] in Scribble documents). + } + + @defmethod[(set-spell-check-text [b? boolean?]) void?]{ + If called with @racket[#t], tell the colorer to spell-check + text constants. Otherwise, disable spell-checking of text. } @defmethod[(set-spell-current-dict [dict (or/c string? #f)]) void?]{ diff --git a/pkgs/gui-pkgs/gui-lib/framework/private/color.rkt b/pkgs/gui-pkgs/gui-lib/framework/private/color.rkt index effd95ef0f..0fafe7de66 100644 --- a/pkgs/gui-pkgs/gui-lib/framework/private/color.rkt +++ b/pkgs/gui-pkgs/gui-lib/framework/private/color.rkt @@ -67,6 +67,8 @@ added get-regions set-spell-check-strings get-spell-check-strings + set-spell-check-text + get-spell-check-text get-spell-current-dict)) (define text-mixin @@ -233,15 +235,24 @@ added get-regions ;; ---------------------- Preferences ------------------------------- (define should-color? #t) (define token-sym->style #f) - (define spell-check-strings? (preferences:get 'framework:spell-check-on?)) + (define spell-check-strings? (preferences:get 'framework:spell-check-strings?)) + (define spell-check-text? (preferences:get 'framework:spell-check-text?)) (define/public (get-spell-check-strings) spell-check-strings?) + (define/public (get-spell-check-text) spell-check-text?) (define/public (set-spell-check-strings s) (define new-val (and s #t)) - (unless (eq? new-val spell-check-strings?) + (unless (equal? new-val spell-check-strings?) (set! spell-check-strings? s) - (reset-tokens) - (start-colorer token-sym->style get-token pairs))) + (spell-checking-values-changed))) + (define/public (set-spell-check-text s) + (define new-val (and s #t)) + (unless (equal? new-val spell-check-text?) + (set! spell-check-text? s) + (spell-checking-values-changed))) + (define/private (spell-checking-values-changed) + (reset-tokens) + (start-colorer token-sym->style get-token pairs)) (define current-dict (preferences:get 'framework:aspell-dict)) (define/public (set-spell-current-dict d) (unless (equal? d current-dict) @@ -390,8 +401,13 @@ added get-regions (define ep (+ in-start-pos (sub1 new-token-end))) (define style-name (token-sym->style type)) (define color (send (get-style-list) find-named-style style-name)) + (define do-spell-check? + (cond + [(equal? type 'string) spell-check-strings?] + [(equal? type 'text) spell-check-text?] + [else #f])) (cond - [(and spell-check-strings? (eq? type 'string)) + [do-spell-check? (define misspelled-color (send (get-style-list) find-named-style misspelled-text-color-style-name)) (cond [misspelled-color diff --git a/pkgs/gui-pkgs/gui-lib/framework/private/main.rkt b/pkgs/gui-pkgs/gui-lib/framework/private/main.rkt index 503429fd73..5013f8152f 100644 --- a/pkgs/gui-pkgs/gui-lib/framework/private/main.rkt +++ b/pkgs/gui-pkgs/gui-lib/framework/private/main.rkt @@ -40,7 +40,17 @@ ;; used to time how long it takes to set a preference; the value is not actually used. (preferences:set-default 'drracket:prefs-debug #f (λ (x) #t)) +;; 'framework:spell-check-on? is only for people who had set +;; prefs in old versions; it isn't used except to provide the +;; default values for the newer prefs: 'framework:spell-check-strings? +;; and 'framework:spell-check-text? (preferences:set-default 'framework:spell-check-on? #f boolean?) +(preferences:set-default 'framework:spell-check-strings? + (preferences:get 'framework:spell-check-on?) + boolean?) +(preferences:set-default 'framework:spell-check-text? + (preferences:get 'framework:spell-check-on?) + boolean?) (preferences:set-default 'framework:always-use-platform-specific-linefeed-convention #f boolean?)