diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cc2ff39 --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +/target +/lib +/classes +/checkouts +pom.xml +pom.xml.asc +*.jar +*.class +.lein-deps-sum +.lein-failures +.lein-plugins +.lein-repl-history diff --git a/README.md b/README.md new file mode 100644 index 0000000..627e3ad --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# node-webkit-cljs + +Simple wrapper for [node-webkit](https://github.com/rogerwang/node-webkit) native APIs. + +## Documentation + +See + +## License + +Copyright © 2013 Ilia Ablamonov + +Distributed under the Eclipse Public License, the same as Clojure. diff --git a/docs/uberdoc.html b/docs/uberdoc.html new file mode 100644 index 0000000..75dcb17 --- /dev/null +++ b/docs/uberdoc.html @@ -0,0 +1,3083 @@ + +node-webkit-cljs -- Marginalia

node-webkit-cljs

0.1.0-SNAPSHOT


Native UI API wrapper for node-webkit

+

dependencies

org.clojure/clojure
1.4.0



(this space intentionally left almost blank)
 

This is only a thin wrapper for node-webkit Native UI API. Generally, node-webkit's + Native UI API Manual + is a good place to start learning how to use this APIs.

+
(ns node-webkit-cljs.core)
+
(def ^:private gui (js/require "nw.gui"))

Window

+

If window-object is not specifed, then return current window's Window object, + otherwise return window-objects Window object.

+
(defn window
+  ([] (.Window.get gui))
+  ([window-object] (.Window.get gui window-object)))

Menu

+
+
(defn- append-menuitems [menu items]
+  (let [ctor (.-MenuItem gui)]
+    (doseq [item-options items]
+      (.append menu (new ctor (clj->js item-options))))))

Create a new Menu. Items is a vector of MenuItem options. + Options can have following fields: label, icon, tooltip, type, click, checked, enabled and submenu. + See MenuItem documentation.

+
(defn menu
+  [items]
+  (let [ctor (.-Menu gui)]
+    (doto (new ctor)
+      (append-menuitems items))))

Create and set main Window's main Menu. Items is a vector of MenuItem options. + Options can have following fields: label, icon, tooltip, type, click, checked, enabled and submenu. + See MenuItem documentation.

+
(defn menubar!
+  [items]
+  (let [ctor (.-Menu gui)
+        menu (new ctor (js-obj "type" "menubar"))]
+    (append-menuitems menu items)
+    (set! (.-menu (window)) menu)))

App

+

Get the command line arguments when starting the app.

+
(defn argv
+  []
+  (seq (.-App.argv gui)))

Quit current app. This method will not send close event + to windows and app will just quit quietly.

+
(defn quit
+  []
+  (.App.quit gui))

Tray

+
+
(def ^:private ^:dynamic current-tray)

Create a new Tray, options is a map contains initial settings for the Tray. + options can have following fields: title, tooltip, icon and menu. + See Tray documentation.

+
(defn tray!
+  [options]
+  (when current-tray (.remove current-tray))
+  (let [ctor (.-Tray gui)]
+    (def current-tray (new ctor (clj->js options)))))

Assigns new value to one of the following options: title, tooltip, icon and menu. + See Tray documentation.

+
(defn update-tray
+  [option value]
+  (aset current-tray (name option) value))
 
\ No newline at end of file diff --git a/project.clj b/project.clj new file mode 100644 index 0000000..60bc745 --- /dev/null +++ b/project.clj @@ -0,0 +1,7 @@ +(defproject node-webkit-cljs "0.1.0-SNAPSHOT" + :description "Native UI API wrapper for node-webkit" + :url "http://github.com/Flamefork/node-webkit-cljs" + :license {:name "Eclipse Public License" + :url "http://www.eclipse.org/legal/epl-v10.html"} + :dependencies [[org.clojure/clojure "1.4.0"]] + :plugins [[lein-marginalia "0.7.1"]]) diff --git a/src/node_webkit_cljs/core.clj b/src/node_webkit_cljs/core.clj new file mode 100644 index 0000000..d13c540 --- /dev/null +++ b/src/node_webkit_cljs/core.clj @@ -0,0 +1,72 @@ +(ns node-webkit-cljs.core + "This is only a thin wrapper for node-webkit Native UI API. Generally, node-webkit's + [Native UI API Manual](https://github.com/rogerwang/node-webkit/wiki/Native-UI-API-Manual) + is a good place to start learning how to use this APIs.") + +(def ^:private gui (js/require "nw.gui")) + +;; ## Window + +(defn window + "If `window-object` is not specifed, then return current window's Window object, + otherwise return `window-object`s Window object." + ([] (.Window.get gui)) + ([window-object] (.Window.get gui window-object))) + +;; ## Menu + +(defn- append-menuitems [menu items] + (let [ctor (.-MenuItem gui)] + (doseq [item-options items] + (.append menu (new ctor (clj->js item-options)))))) + +(defn menu + "Create a new Menu. Items is a vector of MenuItem options. + Options can have following fields: `label`, `icon`, `tooltip`, `type`, `click`, `checked`, `enabled` and `submenu`. + See [MenuItem documentation](https://github.com/rogerwang/node-webkit/wiki/MenuItem)." + [items] + (let [ctor (.-Menu gui)] + (doto (new ctor) + (append-menuitems items)))) + +(defn menubar! + "Create and set main Window's main Menu. Items is a vector of MenuItem options. + Options can have following fields: `label`, `icon`, `tooltip`, `type`, `click`, `checked`, `enabled` and `submenu`. + See [MenuItem documentation](https://github.com/rogerwang/node-webkit/wiki/MenuItem)." + [items] + (let [ctor (.-Menu gui) + menu (new ctor (js-obj "type" "menubar"))] + (append-menuitems menu items) + (set! (.-menu (window)) menu))) + +;; ## App + +(defn argv + "Get the command line arguments when starting the app." + [] + (seq (.-App.argv gui))) + +(defn quit + "Quit current app. This method will not send close event + to windows and app will just quit quietly." + [] + (.App.quit gui)) + +;; ## Tray + +(def ^:private ^:dynamic current-tray) + +(defn tray! + "Create a new Tray, options is a map contains initial settings for the Tray. + `options` can have following fields: `title`, `tooltip`, `icon` and `menu`. + See [Tray documentation](https://github.com/rogerwang/node-webkit/wiki/Tray)." + [options] + (when current-tray (.remove current-tray)) + (let [ctor (.-Tray gui)] + (def current-tray (new ctor (clj->js options))))) + +(defn update-tray + "Assigns new value to one of the following options: `title`, `tooltip`, `icon` and `menu`. + See [Tray documentation](https://github.com/rogerwang/node-webkit/wiki/Tray)." + [option value] + (aset current-tray (name option) value))