Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A Counterclockwise User Plugin adding a Command for reloading User Plugins from the ~/.ccw directory ( Alt+U S ) . How cool / meta is that, heh ? :-)
(ns plugin-additions
(:require [ :as io]
[ccw.e4.dsl :refer :all]
[ccw.e4.model :as m]
[ccw.eclipse :as e]
[ccw.file :as f]
[ccw.core.user-plugins :as p]))
;; Alt+U S - re[S]tart user plugins
(defn restart [context]
(e/info-dialog "User plugins"
"User plugins have been restarted successfully!")
(catch Exception e
(e/error-dialog "User plugins" (str
"An error occured while starting User plugins: \n"
(.getMessage e))))))
(defcommand start-user-plugins "Start/restart user plugins")
(defhandler start-user-plugins restart)
(defkeybinding start-user-plugins "Alt+U S")
;; Alt+U N - create [N]ew user plugin
(defn validate-project-name
([s] (validate-project-name s (io/file (p/plugins-root-dir) s)))
([s proj-location]
(and (zero? (count s)) "You must type a project name")
(e/validate-name-as-resource-type s :project)
(and (e/project-exists s) (format "A project with name '%s' already exists" s))
(e/validate-project-location proj-location))))
(defn create-user-plugin [context]
(let [project-name @(e/input-dialog
"New User Plugin"
"Enter the name for your Plugin:"
proj-location (io/file (p/plugins-root-dir) project-name)]
(when-not (.exists proj-location)
(.mkdirs proj-location)
(spit (io/file proj-location "script.clj")
(format "(ns %s)\n\n" project-name)))
(when-not (e/project-exists project-name)
(e/project-create project-name proj-location))
(e/project-open project-name)
(doseq [f (filter #(and (e/worskpace-file? %)
(= "clj" (e/file-extension %)))
(e/project-members project-name))]
(-> f e/open-workspace-file (e/goto-editor-line -1)))))
(defcommand create-user-plugin-cmd "New User plugin")
(defhandler create-user-plugin-cmd create-user-plugin)
(defkeybinding create-user-plugin-cmd "Alt+U N")
;; Alt+U I - Import all user plugins as projects in workspace
(defn create-update-projects [context]
(doseq [p (p/user-plugins (p/plugins-root-dir))]
(if-let [msg (validate-project-name (.getName p) p)]
"User Plugin"
(format "Wont create project '%s' in workspace ; reason='%s'"
p msg))
(e/project-create (.getName p) p)
(e/project-open (.getName p))
(defcommand create-user-plugins-projects "Import user plugins as projects in Workspace")
(defhandler create-user-plugins-projects create-update-projects)
(defkeybinding create-user-plugins-projects "Alt+U I")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment