add cancle button

This commit is contained in:
2025-07-01 10:49:28 +02:00
parent c48ded07c7
commit 43e02dee33

View File

@@ -8,8 +8,7 @@
"\n") "\n")
(defun my-tool-bar-function-save (event) (defun my-tool-bar-function-save (event)
"Pop up the same menu as displayed by the menu bar. "Run `save-buffer'."
Used by `tab-bar-format-menu-bar'."
(interactive "e") (interactive "e")
(let () (let ()
;;(message "%s" event) ;;(message "%s" event)
@@ -18,11 +17,10 @@ Used by `tab-bar-format-menu-bar'."
)) ))
(defvar my-tool-bar-button-save "Save " (defvar my-tool-bar-button-save "Save "
"Button for going back in tab history.") "Button to run `save-buffer'.")
(defun my-tool-bar-function-open (event) (defun my-tool-bar-function-open (event)
"Pop up the same menu as displayed by the menu bar. "Run `find-file' or 'counsel-find-file' if available."
Used by `tab-bar-format-menu-bar'."
(interactive "e") (interactive "e")
(let () (let ()
;;(message "%s" event) ;;(message "%s" event)
@@ -33,7 +31,19 @@ Used by `tab-bar-format-menu-bar'."
)) ))
(defvar my-tool-bar-button-open "Open " (defvar my-tool-bar-button-open "Open "
"Button for going back in tab history.") "Button to run `find-file' or `counsel-find-file' if available.")
(defun my-tool-bar-function-cancle (event)
"Run `keyboard-escape-quit'."
;; "Run `keyboard-quit'."
(interactive "e")
(let ()
;; (keyboard-quit)
(keyboard-escape-quit)))
(defvar my-tool-bar-button-cancle "Cancle "
"Button to run `keyboard-escape-quit'.")
;; "Button to run `keyboard-quit'."
;; (defun my-tool-bar-format-save () ;; (defun my-tool-bar-format-save ()
;; "Produce the Menu button for the tool bar that shows the menu bar." ;; "Produce the Menu button for the tool bar that shows the menu bar."
@@ -54,15 +64,17 @@ You can hide these buttons by customizing `tab-bar-format' and removing
(open (open
menu-item ,my-tool-bar-button-open my-tool-bar-function-open menu-item ,my-tool-bar-button-open my-tool-bar-function-open
:help "Open File...") :help "Open File...")
(sep-tool-bar menu-item ,(my-tool-bar-newline) ignore) (cancle
))) menu-item ,my-tool-bar-button-cancle my-tool-bar-function-cancle
:help "Cancle")
(sep-tool-bar menu-item ,(my-tool-bar-newline) ignore))))
(defun my-tool-bar--load-buttons () (defun my-tool-bar--load-buttons ()
"Load the icons for the tool bar buttons." "Load the icons for the tool bar buttons."
;; (emoji "<empji>") see e.g. https://emojipedia.org/hamburger ;; (emoji "<empji>") see e.g. https://emojipedia.org/hamburger
;; (symbol "<unicode>") see e.g. https://www.compart.com/en/unicode/U+2630 ;; (symbol "<unicode>") see e.g. https://www.compart.com/en/unicode/U+2630
(require 'icons) (require 'icons)
(unless (iconp 'my-tool-bar-icon-save) (unless (iconp 'my-tool-bar-icon-save)
(define-icon my-tool-bar-icon-save nil (define-icon my-tool-bar-icon-save nil
`((image "save.xpm" `((image "save.xpm"
@@ -74,10 +86,10 @@ You can hide these buttons by customizing `tab-bar-format' and removing
(text "Save" (text "Save"
;; :face tab-bar-tab-inactive ;; :face tab-bar-tab-inactive
)) ))
"Icon for the menu bar." "Icon for save."
:version "29.1")) :version "29.1"))
(setq my-tool-bar-button-save (icon-string 'my-tool-bar-icon-save)) (setq my-tool-bar-button-save (icon-string 'my-tool-bar-icon-save))
(unless (iconp 'my-tool-bar-icon-open) (unless (iconp 'my-tool-bar-icon-open)
(define-icon my-tool-bar-icon-open nil (define-icon my-tool-bar-icon-open nil
`((image "open.xpm" `((image "open.xpm"
@@ -89,28 +101,41 @@ You can hide these buttons by customizing `tab-bar-format' and removing
(text "Open" (text "Open"
;; :face tab-bar-tab-inactive ;; :face tab-bar-tab-inactive
)) ))
"Icon for the menu bar." "Icon for open file."
:version "29.1")) :version "29.1"))
(setq my-tool-bar-button-open (icon-string 'my-tool-bar-icon-open)) (setq my-tool-bar-button-open (icon-string 'my-tool-bar-icon-open))
) (unless (iconp 'my-tool-bar-icon-cancle)
(define-icon my-tool-bar-icon-cancle nil
`((image "cancel.xpm"
:height (1.5 . em)
:margin ,tab-bar-button-margin
:ascent center)
(text "Quit"
;; :face tab-bar-tab-inactive
))
"Icon for quit."
:version "29.1"))
(setq my-tool-bar-button-cancle (icon-string 'my-tool-bar-icon-cancle))
)
(define-minor-mode my-tool-bar-mode (define-minor-mode my-tool-bar-mode
"Toggle tab history mode for the tab bar. "Toggle tool bar mode for the tab bar.
Tab history mode remembers window configurations used in every tab, Tool bar mode displays action buttons.
and can restore them." It will enable `tab-bar-mode' if not already."
:global t :group 'tab-bar :global t :group 'tab-bar
(if my-tool-bar-mode (if my-tool-bar-mode
(progn (progn
(my-tool-bar--load-buttons) (my-tool-bar--load-buttons)
(unless tab-bar-mode
(tab-bar-mode 1))
;;(add-hook 'pre-command-hook #'tab-bar--history-pre-change) ;;(add-hook 'pre-command-hook #'tab-bar--history-pre-change)
;;(add-hook 'window-configuration-change-hook #'tab-bar--history-change) ;;(add-hook 'window-configuration-change-hook #'tab-bar--history-change)
) )
;;(remove-hook 'pre-command-hook #'tab-bar--history-pre-change) ;;(remove-hook 'pre-command-hook #'tab-bar--history-pre-change)
;;(remove-hook 'window-configuration-change-hook #'tab-bar--history-change) ;;(remove-hook 'window-configuration-change-hook #'tab-bar--history-change)
) ))
)
(provide 'my-tool-bar) (provide 'my-tool-bar)