Skip to content

Commit

Permalink
feature: implement selection sub-menu for context switch in menu bar (#…
Browse files Browse the repository at this point in the history
…169)

Contributes to #166.

Closes #168.
  • Loading branch information
jinnovation authored Apr 11, 2024
1 parent f82049f commit a2561d0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
Binary file modified docs/explanations/img/menu-bar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/menu-bar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions docs/references/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ versioning][semver].

### Added

- [Menu bar] integration. Now you can access common tasks via the **Kubernetes**
section on the menu bar
- **[Menu bar] integration**. Now you can access common tasks via the
**Kubernetes** section on the menu bar
- Added ability to switch contexts from within the menu bar; available contexts
are shown as a sub-menu

## 0.4.2

Expand Down
22 changes: 20 additions & 2 deletions kele.el
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,8 @@ This is idempotent."
;; FIXME: Update the watcher when `kele-cache-dir' changes.
(kele--cache-start kele--global-discovery-cache :bootstrap t)

(add-hook 'menu-bar-update-hook 'kele--update-contexts-menu)

(kele--setup-embark-maybe)))

(defun kele--disable ()
Expand All @@ -1236,6 +1238,8 @@ This is idempotent."
(setq kele--enabled nil)
(kele--cache-stop kele--global-kubeconfig-cache)
(kele--cache-stop kele--global-discovery-cache)

(remove-hook 'menu-bar-update-hook 'kele--update-contexts-menu)
(kele--teardown-embark-maybe)))

(defvar kele-mode-map (make-sparse-keymap)
Expand Down Expand Up @@ -1724,12 +1728,26 @@ The `scope' is the current context name."
Similar to `kele-dispatch'."
'("Kubernetes"
("Configuration"
;; TODO: Make this a menu where user can select from the available contexts
["Switch context" kele-context-switch]

;; placeholder for dynamic fill-in (see `kele--update-contexts-menu')
["Switch context to..." nil]

["Switch namespace for current context" kele-namespace-switch-for-current-context]
"---"
["Find config file" kele-find-kubeconfig])))

(defun kele--update-contexts-menu ()
"Fill in the context-switch sub-menu with candidate contexts."
(easy-menu-add-item
kele-menu-map
'("Configuration")
(append '("Switch context to...")
(mapcar (lambda (ctx)
(vector ctx (lambda ()
(interactive)
(kele-context-switch ctx))))
(kele-context-names)))))

(provide 'kele)

;;; kele.el ends here

0 comments on commit a2561d0

Please sign in to comment.