diff --git a/docs/explanations/img/menu-bar.png b/docs/explanations/img/menu-bar.png index d8bc19c..67ad3c1 100644 Binary files a/docs/explanations/img/menu-bar.png and b/docs/explanations/img/menu-bar.png differ diff --git a/docs/img/menu-bar.png b/docs/img/menu-bar.png index d8bc19c..67ad3c1 100644 Binary files a/docs/img/menu-bar.png and b/docs/img/menu-bar.png differ diff --git a/docs/references/changelog.md b/docs/references/changelog.md index 9cbbf95..e6bc1f1 100644 --- a/docs/references/changelog.md +++ b/docs/references/changelog.md @@ -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 diff --git a/kele.el b/kele.el index f6bf869..5682886 100644 --- a/kele.el +++ b/kele.el @@ -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 () @@ -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) @@ -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