emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

emacs-29 1bbb610821e: Implement missing functions for custom-icon widget


From: Stefan Kangas
Subject: emacs-29 1bbb610821e: Implement missing functions for custom-icon widget
Date: Wed, 10 Jan 2024 13:27:06 -0500 (EST)

branch: emacs-29
commit 1bbb610821eb143e0828d2541a3f856d29d67b6f
Author: Mauro Aranda <maurooaranda@gmail.com>
Commit: Stefan Kangas <stefankangas@gmail.com>

    Implement missing functions for custom-icon widget
    
    * lisp/cus-edit.el (custom-icon-reset-saved, custom-icon-mark-to-save)
    (custom-icon-state-set-and-redraw, custom-icon-reset-standard)
    (custom-icon-mark-to-reset-standard): New functions.
    (custom-icon, custom-icon-extended-menu): Register and add them to the
    menu.  (Bug#66947)
---
 lisp/cus-edit.el | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 55 insertions(+), 3 deletions(-)

diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el
index 62564f6dfcb..12eea0fa0e5 100644
--- a/lisp/cus-edit.el
+++ b/lisp/cus-edit.el
@@ -5348,9 +5348,49 @@ The following properties have special meanings for this 
widget:
   :hidden-states '(standard)
   :action #'custom-icon-action
   :custom-set #'custom-icon-set
-  :custom-reset-current #'custom-redraw)
-  ;; Not implemented yet.
-  ;; :custom-reset-saved 'custom-icon-reset-saved)
+  :custom-mark-to-save #'custom-icon-mark-to-save
+  :custom-reset-current #'custom-redraw
+  :custom-reset-saved #'custom-icon-reset-saved
+  :custom-state-set-and-redraw #'custom-icon-state-set-and-redraw
+  :custom-reset-standard #'custom-icon-reset-standard
+  :custom-mark-to-reset-standard #'custom-icon-mark-to-reset-standard)
+
+(defun custom-icon-mark-to-save (widget)
+  "Mark user customization for icon edited by WIDGET to be saved later."
+  (let* ((icon (widget-value widget))
+         (value (custom--icons-widget-value
+                 (car (widget-get widget :children)))))
+    (custom-push-theme 'theme-icon icon 'user 'set value)))
+
+(defun custom-icon-reset-saved (widget)
+  "Restore icon customized by WIDGET to the icon's default attributes.
+
+If there's a theme value for the icon, resets to that.  Otherwise, resets to
+its standard value."
+  (let* ((icon (widget-value widget)))
+    (custom-push-theme 'theme-icon icon 'user 'reset)
+    (custom-icon-state-set widget)
+    (custom-redraw widget)))
+
+(defun custom-icon-state-set-and-redraw (widget)
+  "Set state of icon widget WIDGET and redraw it with up-to-date settings."
+  (custom-icon-state-set widget)
+  (custom-redraw-magic widget))
+
+(defun custom-icon-reset-standard (widget)
+  "Reset icon edited by WIDGET to its standard value."
+  (let* ((icon (widget-value widget))
+         (themes (get icon 'theme-icon)))
+    (dolist (theme themes)
+      (custom-push-theme 'theme-icon icon (car theme) 'reset))
+    (custom-save-all))
+  (widget-put widget :custom-state 'unknown)
+  (custom-redraw widget))
+
+(defun custom-icon-mark-to-reset-standard (widget)
+  "Reset icon edited by WIDGET to its standard value."
+  ;; Don't mark for now, there aren't that many icons.
+  (custom-icon-reset-standard widget))
 
 (defvar custom-icon-extended-menu
   (let ((map (make-sparse-keymap)))
@@ -5369,6 +5409,18 @@ The following properties have special meanings for this 
widget:
                   :enable (memq
                            (widget-get custom-actioned-widget :custom-state)
                            '(modified changed))))
+    (define-key-after map [custom-icon-reset-saved]
+      '(menu-item "Revert This Session's Customization"
+                  custom-icon-reset-saved
+                  :enable (memq
+                           (widget-get custom-actioned-widget :custom-state)
+                           '(modified set changed rogue))))
+    (when (or custom-file init-file-user)
+      (define-key-after map [custom-icon-reset-standard]
+        '(menu-item "Erase Customization" custom-icon-reset-standard
+                    :enable (memq
+                             (widget-get custom-actioned-widget :custom-state)
+                             '(modified set changed saved rogue)))))
     map)
   "A menu for `custom-icon' widgets.
 Used in `custom-icon-action' to show a menu to the user.")



reply via email to

[Prev in Thread] Current Thread [Next in Thread]