Skip to content

Commit

Permalink
Rename property for color name usage in color picker
Browse files Browse the repository at this point in the history
Old:
- :prefer-color-names
- :disallow-color-names

New:
- :color-name-usage (enabled or t / disabled / nil)
  • Loading branch information
misohena committed Feb 21, 2025
1 parent a2d75b3 commit a9327f9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 29 deletions.
64 changes: 41 additions & 23 deletions edraw-color-picker.el
Original file line number Diff line number Diff line change
Expand Up @@ -2059,30 +2059,37 @@ but the reverse can also be done."
(plist-get serializer-options :css-prefer-color-syntax))
(prefer-function
(when (eq prefer-syntax 'css-color-function)
(plist-get serializer-options :css-prefer-color-function))))
(plist-get serializer-options :css-prefer-color-function)))
(color-name-usage
(plist-get serializer-options :color-name-usage)))

(when (stringp prefer-function)
(setq prefer-function (downcase prefer-function))) ;; lowercase

;; Note: On Windows, :radio will garble non-ASCII characters
`(((edraw-msg "Output Format (Emacs)")
(((edraw-msg "Prefer Color Names")
edraw-color-picker-toggle-output-format-prefer-color-names
:button (:toggle . ,(not (null (plist-get serializer-options
:prefer-color-names)))))
((edraw-msg "Disallow Color Names")
edraw-color-picker-toggle-output-format-disable-color-names
:button (:toggle . ,(not (null (plist-get serializer-options
:disallow-color-names))))))
(((edraw-msg "Color Name Usage")
(((edraw-msg "Auto")
edraw-color-picker-set-output-format-color-name-usage-auto
:button (:toggle . ,(eq color-name-usage nil)))
((edraw-msg "Disabled")
edraw-color-picker-set-output-format-color-name-usage-disabled
:button (:toggle . ,(eq color-name-usage 'disabled)))
((edraw-msg "Enabled")
edraw-color-picker-set-output-format-color-name-usage-enabled
:button (:toggle . ,(memq color-name-usage '(t enabled)))))))
:visible ,(eq syntax-system 'emacs))
((edraw-msg "Output Format (CSS)")
(((edraw-msg "Prefer Color Names")
edraw-color-picker-toggle-output-format-prefer-color-names
:button (:toggle . ,(not (null (plist-get serializer-options
:prefer-color-names)))))
((edraw-msg "Disallow Color Names")
edraw-color-picker-toggle-output-format-disable-color-names
:button (:toggle . ,(not (null (plist-get serializer-options
:disallow-color-names)))))
(((edraw-msg "Color Name Usage")
(((edraw-msg "Auto")
edraw-color-picker-set-output-format-color-name-usage-auto
:button (:toggle . ,(eq color-name-usage nil)))
((edraw-msg "Disabled")
edraw-color-picker-set-output-format-color-name-usage-disabled
:button (:toggle . ,(eq color-name-usage 'disabled)))
((edraw-msg "Enabled")
edraw-color-picker-set-output-format-color-name-usage-enabled
:button (:toggle . ,(memq color-name-usage '(t enabled))))))
("--single-line")
((edraw-msg "Auto") edraw-color-picker-set-output-format-css-auto
:button (:toggle . ,(null prefer-syntax)))
Expand Down Expand Up @@ -2200,17 +2207,23 @@ but the reverse can also be done."
;; Force update output text (minibuffer or preview text)
(edraw-notify-options-change picker))

(defun edraw-color-picker-toggle-output-format-prefer-color-names ()
(defun edraw-color-picker-set-output-format-color-name-usage-auto ()
(interactive)
(edraw-color-picker-toggle-serializer-options
(edraw-color-picker-set-serializer-options
(edraw-color-picker-at-input-or-error (edraw-this-command-event))
:prefer-color-names))
:color-name-usage nil))

(defun edraw-color-picker-toggle-output-format-disable-color-names ()
(defun edraw-color-picker-set-output-format-color-name-usage-enabled ()
(interactive)
(edraw-color-picker-toggle-serializer-options
(edraw-color-picker-set-serializer-options
(edraw-color-picker-at-input-or-error (edraw-this-command-event))
:disallow-color-names))
:color-name-usage 'enabled))

(defun edraw-color-picker-set-output-format-color-name-usage-disabled ()
(interactive)
(edraw-color-picker-set-serializer-options
(edraw-color-picker-at-input-or-error (edraw-this-command-event))
:color-name-usage 'disabled))

(defun edraw-color-picker-set-output-format-css-auto ()
(interactive)
Expand Down Expand Up @@ -2288,6 +2301,11 @@ but the reverse can also be done."
prefix-km))))

(define-key km (kbd "F") (cons "Format" (make-sparse-keymap)))

(define-key km (kbd "FC") (cons "Color Name Usage" (make-sparse-keymap)))
(define-key km (kbd "FC-") '("Auto" . edraw-color-picker-set-output-format-color-name-usage-auto))
(define-key km (kbd "FC0") '("None" . edraw-color-picker-set-output-format-color-name-usage-disabled))
(define-key km (kbd "FC1") '("None" . edraw-color-picker-set-output-format-color-name-usage-enabled))
(define-key km (kbd "F-") '("Auto" . edraw-color-picker-set-output-format-css-auto))
(define-key km (kbd "F#") '("HEX" . edraw-color-picker-set-output-format-css-hex))
(define-key km (kbd "Fr") '("RGB" . edraw-color-picker-set-output-format-css-rgb))
Expand Down
9 changes: 5 additions & 4 deletions edraw-color.el
Original file line number Diff line number Diff line change
Expand Up @@ -792,16 +792,17 @@ Signals an error if there is a syntax or other problem, never returns nil."
(plist-get options :syntax)
(plist-get options :emacs-default-color-syntax))))
(or (and (not (plist-get options :disallow-color-names))
(not (eq (plist-get options :color-name-usage) 'disabled))
(or (eq syntax 'emacs-color-name)
(plist-get options :prefer-color-names))
(memq (plist-get options :color-name-usage) '(t enabled)))
(edraw-color-to-emacs-color-name color))
(edraw-color-make-hex-color
color "#" t
(max
(or (plist-get options :hex-digits-per-component) 2)
(or (plist-get options :hex-min-digits-per-component) 0))
(plist-get options :hex-upcase)))))
;; TEST: (edraw-color-emacs-serialize (edraw-color-f 0.5 0.5 0.5) '(:prefer-color-names t)) => "gray50"
;; TEST: (edraw-color-emacs-serialize (edraw-color-f 0.5 0.5 0.5) '(:color-name-usage enabled)) => "gray50"
;; TEST: (edraw-color-emacs-serialize (edraw-color-f 0.25 0.5 0.75 0.5)) => "#4080bf"


Expand Down Expand Up @@ -1808,9 +1809,9 @@ Signals an error if there is a syntax or other problem, never returns nil."
(plist-get options :css-default-color-syntax))))
(or
;; Try converting to color name
(when (and (not (plist-get options ::disallow-color-names))
(when (and (not (eq (plist-get options :color-name-usage) 'disabled))
(or (eq syntax 'css-named-color)
(plist-get options :prefer-color-names))) ;;@todo Add :css-?
(memq (plist-get options :color-name-usage) '(t enabled)))) ;;@todo Add :css-?
(edraw-color-css-make-named-color color options))
;; Unable or unwilling to represent as a color name

Expand Down
5 changes: 3 additions & 2 deletions msg/edraw-msg-ja.el
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"Closed" "閉じました"
"Coil Line" "コイル線"
"Color Components" "色成分"
"Color Name Usage" "色名の使用"
"Color Name..." "色名..."
"Color Picker Menu" "カラーピッカーメニュー"
"Color Name: " "色名: "
Expand Down Expand Up @@ -123,7 +124,7 @@
"Deselect All" "全選択解除"
"Deselect" "選択解除"
"Direction(degrees): " "方向(度): "
"Disallow Color Names" "色名を禁止する"
"Disabled" "不許可"
"Discard `use' element with unsupported format" "未対応形式の`use'要素を破棄"
"Discard changes?" "変更を破棄しますか?"
"Discard unsupported attribute: %s" "未対応の属性を破棄: %s"
Expand All @@ -149,6 +150,7 @@
"Empty path data" "空のパスデータ"
"Empty shape" "空の図形"
"Empty shapes cannot be registered" "空の図形は登録できません"
"Enabled" "許可"
"End Marker" "終点マーカー"
"Evaluate this generator's code on your system?" "あなたのシステムでこのジェネレータのコードを評価しますか?"
"Export SVG" "SVGをエクスポート"
Expand Down Expand Up @@ -294,7 +296,6 @@
"Please enter a number, %s, or empty." "数値か%s、または空を入力してください"
"Please enter a number." "数値を入力してください"
"Pointer Input Disabled" "ポインター入力無効"
"Prefer Color Names" "色名を優先する"
"Preset %s exists. Do you want to overwrite?" "プリセット %s は存在しています。上書きしますか?"
"Preset" "プリセット"
"Prev" ""
Expand Down

0 comments on commit a9327f9

Please sign in to comment.