mirror of
https://github.com/lxsang/antos-frontend.git
synced 2024-12-26 09:28:21 +01:00
add extension to codepad
This commit is contained in:
parent
e20ee262fc
commit
95cfddb389
@ -117,9 +117,9 @@ class BaseApplication extends this.OS.GUI.BaseModel
|
||||
# implement by subclasses
|
||||
# to add menu to application
|
||||
[]
|
||||
open:->
|
||||
open: () ->
|
||||
#implement by subclasses
|
||||
data:->
|
||||
data: ->
|
||||
#implement by subclasses
|
||||
# to return app data
|
||||
|
||||
|
@ -31,7 +31,9 @@ class SubWindow extends this.OS.GUI.BaseModel
|
||||
init: () ->
|
||||
main: () ->
|
||||
meta: () ->
|
||||
@parent.meta()
|
||||
return @parent.meta() if @parent and @parent.meta
|
||||
{}
|
||||
|
||||
show: () ->
|
||||
@trigger 'focus'
|
||||
($ @scheme).css "z-index", window._zindex + 2
|
||||
|
@ -98,7 +98,16 @@ class BaseModel
|
||||
mt = @meta()
|
||||
icon = undefined
|
||||
icon = "#{mt.path}/#{mt.icon}" if mt.icon
|
||||
Ant.OS.announcer.trigger t, { id: @pid, name: @name, data: { m: m, icon: icon, iconclass: mt.iconclass }, error: e }
|
||||
Ant.OS.announcer.trigger t, {
|
||||
id: @pid,
|
||||
name: @name,
|
||||
data: {
|
||||
m: m,
|
||||
icon: icon,
|
||||
iconclass: mt.iconclass,
|
||||
e: e
|
||||
}
|
||||
}
|
||||
|
||||
notify: (m) ->
|
||||
@publish "notification", m
|
||||
@ -115,7 +124,7 @@ class BaseModel
|
||||
throwe: () ->
|
||||
@_api.throwe @name
|
||||
|
||||
update:->
|
||||
update: () ->
|
||||
@scheme.update() if @scheme
|
||||
|
||||
find: (id) -> ($ "[data-id='#{id}']", @scheme)[0] if @scheme
|
||||
|
@ -307,16 +307,17 @@ Ant.OS.API =
|
||||
})
|
||||
.appendTo 'head'
|
||||
Ant.OS.API.shared[l] = true
|
||||
console.log "loaded css:", l
|
||||
console.log "Loaded :", l
|
||||
Ant.OS.announcer.trigger "sharedlibraryloaded", l
|
||||
resolve undefined
|
||||
.catch (e) -> reject e
|
||||
when "js"
|
||||
Ant.OS.API.script libfp.getlink()
|
||||
.then () ->
|
||||
.then (data) ->
|
||||
Ant.OS.API.shared[l] = true
|
||||
console.log "loaded javascript:", l
|
||||
console.log "Loaded :", l
|
||||
Ant.OS.announcer.trigger "sharedlibraryloaded", l
|
||||
resolve(l)
|
||||
resolve(data)
|
||||
.catch (e) ->
|
||||
reject e
|
||||
else
|
||||
|
@ -34,6 +34,9 @@ Ant.OS or=
|
||||
register: (name, x) ->
|
||||
if x.type is 3 then Ant.OS.GUI.subwindows[name] = x else Ant.OS.APP[name] = x
|
||||
|
||||
# import proprety from an App
|
||||
|
||||
|
||||
PM:
|
||||
pidalloc: 0
|
||||
processes: {}
|
||||
|
@ -51,6 +51,10 @@ class BaseFileHandle
|
||||
@basename = @genealogy[@genealogy.length - 1] unless @isRoot()
|
||||
@ext = @basename.split( "." ).pop() unless @basename.lastIndexOf(".") is 0 or @basename.indexOf( "." ) is -1
|
||||
|
||||
setCache: (v) ->
|
||||
@cache = v
|
||||
@
|
||||
|
||||
asFileHandle: () -> @
|
||||
|
||||
isRoot: () -> (not @genealogy) or (@genealogy.size is 0)
|
||||
|
@ -1,10 +1,13 @@
|
||||
coffee_files = coffees/CommandPalette.coffee coffees/main.coffee
|
||||
|
||||
module_dir = extensions
|
||||
module_dir_src = coffees/extensions
|
||||
|
||||
jsfiles =
|
||||
|
||||
cssfiles = css/main.css
|
||||
|
||||
copyfiles = assets/scheme.html package.json
|
||||
copyfiles = assets/scheme.html package.json extensions.json
|
||||
|
||||
|
||||
PKG_NAME=CodePad
|
||||
|
105
src/packages/CodePad/coffees/extensions/AntOSDK.coffee
Normal file
105
src/packages/CodePad/coffees/extensions/AntOSDK.coffee
Normal file
@ -0,0 +1,105 @@
|
||||
# import the CodePad application module
|
||||
App = this.OS.APP.CodePad
|
||||
|
||||
# define the extension
|
||||
class App.extensions.AntOSDK extends App.BaseExtension
|
||||
constructor: (app) ->
|
||||
super app
|
||||
|
||||
# public functions
|
||||
create: () ->
|
||||
me = @
|
||||
@app.openDialog("FileDialog", {
|
||||
title: "__(New Project at)",
|
||||
file: { basename: __("ProjectName") },
|
||||
mimes: ["dir"]
|
||||
}).then (d) ->
|
||||
me.mktpl d.file.path, d.name, true
|
||||
|
||||
init: () ->
|
||||
me = @
|
||||
dir = @app.currdir
|
||||
return @create() unless dir and dir.basename
|
||||
dir.read()
|
||||
.then (d) ->
|
||||
return me.notify __("Cannot read folder: {0}", dir.path) if d.error
|
||||
return me.notify __("The folder is not empty: {0}", dir.path) unless d.result.length is 0
|
||||
me.mktpl dir.parent().path, dir.basename
|
||||
|
||||
build: () ->
|
||||
console.log "build"
|
||||
|
||||
release: () ->
|
||||
console.log "release"
|
||||
|
||||
options: () ->
|
||||
console.log "options"
|
||||
|
||||
dependencies: () ->
|
||||
[
|
||||
"AntOSDK/coffeescript.js"
|
||||
]
|
||||
|
||||
# private functions
|
||||
mktpl: (path, name, flag) ->
|
||||
me = @
|
||||
rpath = "#{path}/#{name}"
|
||||
dirs = [
|
||||
"#{rpath}/build",
|
||||
"#{rpath}/build/release",
|
||||
"#{rpath}/build/debug",
|
||||
"#{rpath}/javascripts",
|
||||
"#{rpath}/css",
|
||||
"#{rpath}/coffees",
|
||||
"#{rpath}/assets"
|
||||
]
|
||||
dirs.unshift rpath if flag
|
||||
files = [
|
||||
["main.tpl", "#{rpath}/coffees/main.coffee"],
|
||||
["package.tpl", "#{rpath}/package.json"],
|
||||
["project.tpl", "#{rpath}/project.apj"],
|
||||
["README.tpl", "#{rpath}/README.md"],
|
||||
["scheme.tpl", "#{rpath}/assets/scheme.html"]
|
||||
]
|
||||
@mkdirAll dirs
|
||||
.then () ->
|
||||
me.mkfileAll(files, path, name)
|
||||
.then () ->
|
||||
me.app.currdir = rpath.asFileHandle()
|
||||
me.app.initSideBar()
|
||||
me.app.openFile "#{rpath}/README.md".asFileHandle()
|
||||
.catch (e) -> me.error e.stack
|
||||
.catch (e) -> me.error e.stack
|
||||
|
||||
mkdirAll: (list) ->
|
||||
me = @
|
||||
new Promise (resolve, reject) ->
|
||||
return resolve() if list.length is 0
|
||||
path = (list.splice 0, 1)[0].asFileHandle()
|
||||
path.parent().mk path.basename
|
||||
.then () ->
|
||||
me.mkdirAll list
|
||||
.then () -> resolve()
|
||||
.catch (e) -> reject e
|
||||
.catch (e) -> reject e
|
||||
|
||||
mkfileAll: (list, path, name) ->
|
||||
me = @
|
||||
new Promise (resolve, reject) ->
|
||||
return resolve() if list.length is 0
|
||||
item = (list.splice 0, 1)[0]
|
||||
"#{me.basedir()}/AntOSDK/templates/#{item[0]}"
|
||||
.asFileHandle()
|
||||
.read()
|
||||
.then (data) ->
|
||||
file = item[1].asFileHandle()
|
||||
.setCache(data.format name, "#{path}/#{name}")
|
||||
.write "text/plain"
|
||||
.then () ->
|
||||
me.mkfileAll list, path, name
|
||||
.then () -> resolve()
|
||||
.catch (e) -> reject e
|
||||
.catch (e) -> reject e
|
||||
.catch (e) -> reject e
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,24 @@
|
||||
# {0}
|
||||
This is an example project, generated by AntOS Development Kit
|
||||
|
||||
## Howto
|
||||
|
||||
1. Open the project.apj file with AntOSDK (simply double Click on it)
|
||||
2. Modify the UI in *assets/scheme.html*
|
||||
3. Modify application code in *coffees/main.coffee*
|
||||
4. Modify CSS style in *css/main.css*
|
||||
5. Other files need to be copied: put in to assets
|
||||
|
||||
## Set up build target
|
||||
|
||||
Click **Menu> Build > Build Option** or simply hit **ALT-Y**
|
||||
|
||||
In the build options dialog, add or remove files that need to be
|
||||
included into the build
|
||||
|
||||
Click **Save**
|
||||
|
||||
## Build application
|
||||
* To build: **Menu > Build > Build** or **ALT-C**
|
||||
* To build and run: **Menu > Build > Build and Run** or **CTRL-R**
|
||||
* To release: **Menu > Build > Build release** or **ALT-P**
|
@ -0,0 +1,7 @@
|
||||
class {0} extends this.OS.GUI.BaseApplication
|
||||
constructor: ( args ) ->
|
||||
super "{0}", args
|
||||
|
||||
main: () ->
|
||||
|
||||
this.OS.register "{0}", {0}
|
@ -0,0 +1,13 @@
|
||||
{
|
||||
"app":"{0}",
|
||||
"name":"{0}",
|
||||
"description":"",
|
||||
"info":{
|
||||
"author": "",
|
||||
"email": ""
|
||||
},
|
||||
"version":"0.0.1-a",
|
||||
"category":"Other",
|
||||
"iconclass":"fa fa-adn",
|
||||
"mimes":["none"]
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "{0}",
|
||||
"root": "{1}",
|
||||
"css": [],
|
||||
"javascripts": [],
|
||||
"coffees": ["coffees/main.coffee"],
|
||||
"copies": ["assets/scheme.html", "package.json", "README.md"]
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
<afx-app-window apptitle="{0}" width="600" height="500" data-id="{0}">
|
||||
<afx-hbox ></afx-hbox>
|
||||
</afx-app-window>
|
@ -1,38 +1,4 @@
|
||||
class CMDMenu
|
||||
constructor: (@text, @shortcut) ->
|
||||
@child = []
|
||||
@parent = undefined
|
||||
@select = (e) ->
|
||||
|
||||
addAction: (v) ->
|
||||
v.parent = @
|
||||
@child.push v
|
||||
@
|
||||
|
||||
addActions: (list) ->
|
||||
@addAction v for v in list
|
||||
|
||||
onchildselect: (f) ->
|
||||
@select = f
|
||||
@
|
||||
|
||||
run: (root) ->
|
||||
me = @
|
||||
root.openDialog(new CommandPalette(), @)
|
||||
.then (d) ->
|
||||
data = d.data.item.get("data")
|
||||
return data.run root if data.run
|
||||
me.select d, root
|
||||
|
||||
CMDMenu.fromMenu = (mn) ->
|
||||
m = new CMDMenu mn.text, mn.shortcut
|
||||
m.onchildselect mn.onchildselect
|
||||
for v in mn.child
|
||||
if v.child
|
||||
m.addAction CMDMenu.fromMenu v
|
||||
else
|
||||
m.addAction v
|
||||
m
|
||||
Ant = this
|
||||
|
||||
class CodePad extends this.OS.GUI.BaseApplication
|
||||
constructor: (args) ->
|
||||
@ -48,6 +14,7 @@ class CodePad extends this.OS.GUI.BaseApplication
|
||||
|
||||
main: () ->
|
||||
me = @
|
||||
@extensions = {}
|
||||
@fileview = @find("fileview")
|
||||
@sidebar = @find("sidebar")
|
||||
@tabbar = @find "tabbar"
|
||||
@ -74,7 +41,7 @@ class CodePad extends this.OS.GUI.BaseApplication
|
||||
enableSnippets: true,
|
||||
enableLiveAutocompletion: true,
|
||||
highlightActiveLine: true,
|
||||
useWrapMode: true,
|
||||
wrap: true,
|
||||
fontSize: "11pt"
|
||||
}
|
||||
#themes = ace.require "ace/ext/themelist"
|
||||
@ -134,6 +101,7 @@ class CodePad extends this.OS.GUI.BaseApplication
|
||||
@bindKey "CTRL-S", () -> me.menuAction "save"
|
||||
@bindKey "ALT-W", () -> me.menuAction "saveas"
|
||||
|
||||
@loadExtensionMetaData()
|
||||
@initCommandPalete()
|
||||
@initSideBar()
|
||||
@openFile @currfile
|
||||
@ -249,6 +217,52 @@ class CodePad extends this.OS.GUI.BaseApplication
|
||||
@spotlight.addAction cmdmode
|
||||
@addAction CMDMenu.fromMenu @fileMenu()
|
||||
|
||||
loadExtensionMetaData: () ->
|
||||
me = @
|
||||
"#{@meta().path}/extensions.json"
|
||||
.asFileHandle()
|
||||
.read("json")
|
||||
.then (d) ->
|
||||
for ext in d
|
||||
if me.extensions[ext.name]
|
||||
me.extensions[ext.name].child = {}
|
||||
me.extensions[ext.name].addAction v for v in ext.actions
|
||||
else
|
||||
me.extensions[ext.name] = new CMDMenu ext.text
|
||||
me.extensions[ext.name].name = ext.name
|
||||
me.extensions[ext.name].addAction v for v in ext.actions
|
||||
me.spotlight.addAction me.extensions[ext.name]
|
||||
me.extensions[ext.name].onchildselect (e) ->
|
||||
me.loadAndRunExtensionAction e.data.item.get "data"
|
||||
.catch (e) ->
|
||||
me.error __("Cannot load extension meta data")
|
||||
|
||||
runExtensionAction: (name, action) ->
|
||||
me = @
|
||||
return @error __("Unable to find extension: {0}", name) unless CodePad.extensions[name]
|
||||
ext = new CodePad.extensions[name](me)
|
||||
return @error __("Unable to find action: {0}", action) unless ext[action]
|
||||
ext.preload()
|
||||
.then () ->
|
||||
ext[action]()
|
||||
.catch (e) ->
|
||||
me.error e.stack
|
||||
|
||||
loadAndRunExtensionAction: (data) ->
|
||||
me = @
|
||||
name = data.parent.name
|
||||
action = data.name
|
||||
#verify if the extension is load
|
||||
if not CodePad.extensions[name]
|
||||
#load the extension
|
||||
path = "#{@meta().path}/extensions/#{name}.js"
|
||||
@_api.requires path
|
||||
.then () -> me.runExtensionAction name, action
|
||||
.catch (e) ->
|
||||
me.error __("unable to load extension: {}", name)
|
||||
else
|
||||
@runExtensionAction name, action
|
||||
|
||||
fileMenu: () ->
|
||||
me = @
|
||||
{
|
||||
@ -349,6 +363,66 @@ class CodePad extends this.OS.GUI.BaseApplication
|
||||
]
|
||||
menu
|
||||
|
||||
class CodePad.BaseExtension
|
||||
|
||||
constructor: (@app) ->
|
||||
|
||||
preload: () ->
|
||||
dep = ( "#{@basedir()}/#{v}" for v in @dependencies())
|
||||
Ant.OS.API.require dep
|
||||
|
||||
basedir: () ->
|
||||
"#{@app.meta().path}/extensions"
|
||||
|
||||
notify: (m) ->
|
||||
@app.notify m
|
||||
|
||||
error: (m) ->
|
||||
@app.error m
|
||||
|
||||
dependencies: () ->
|
||||
[]
|
||||
|
||||
class CMDMenu
|
||||
constructor: (@text, @shortcut) ->
|
||||
@child = []
|
||||
@parent = undefined
|
||||
@select = (e) ->
|
||||
|
||||
addAction: (v) ->
|
||||
v.parent = @
|
||||
@child.push v
|
||||
@
|
||||
|
||||
addActions: (list) ->
|
||||
@addAction v for v in list
|
||||
|
||||
onchildselect: (f) ->
|
||||
@select = f
|
||||
@
|
||||
|
||||
run: (root) ->
|
||||
me = @
|
||||
root.openDialog(new CommandPalette(), @)
|
||||
.then (d) ->
|
||||
data = d.data.item.get("data")
|
||||
return data.run root if data.run
|
||||
me.select d, root
|
||||
|
||||
CMDMenu.fromMenu = (mn) ->
|
||||
m = new CMDMenu mn.text, mn.shortcut
|
||||
m.onchildselect mn.onchildselect
|
||||
for v in mn.child
|
||||
if v.child
|
||||
m.addAction CMDMenu.fromMenu v
|
||||
else
|
||||
m.addAction v
|
||||
m
|
||||
|
||||
CodePad.CMDMenu = CMDMenu
|
||||
|
||||
CodePad.extensions = {}
|
||||
|
||||
CodePad.dependencies = [
|
||||
"os://scripts/ace/ace.js",
|
||||
"os://scripts/ace/ext-language_tools.js",
|
||||
|
29
src/packages/CodePad/extensions.json
Normal file
29
src/packages/CodePad/extensions.json
Normal file
@ -0,0 +1,29 @@
|
||||
[
|
||||
{
|
||||
"name": "AntOSDK",
|
||||
"text": "AntOS Software Development Kit",
|
||||
"version": "0.0.1-a",
|
||||
"actions" : [
|
||||
{
|
||||
"text": "__(New Project)",
|
||||
"name": "create"
|
||||
},
|
||||
{
|
||||
"text": "__(New project from current folder)",
|
||||
"name": "init"
|
||||
},
|
||||
{
|
||||
"text": "__(Build and Run)",
|
||||
"name": "build"
|
||||
},
|
||||
{
|
||||
"text": "__(Build release)",
|
||||
"name": "release"
|
||||
},
|
||||
{
|
||||
"text": "__(Build options)",
|
||||
"name": "options"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
@ -9,11 +9,15 @@ title:
|
||||
|
||||
coffee:
|
||||
- mkdir build
|
||||
- [ ! -z "$(module_dir)" ] && [ -d build/$(module_dir) ] && rm -r build/$(module_dir)
|
||||
mkdir -p build/$(module_dir)
|
||||
for f in $(coffee_files); do (cat "$${f}"; echo) >>"build/main.coffee";done
|
||||
coffee --compile build/main.coffee
|
||||
#for f in $(coffee_files); do (coffee -cs < $$f >build/"$$f.js");done
|
||||
#for f in build/*.coffee.js; do (cat "$${f}"; echo) >> build/main.js; done
|
||||
- rm build/*.coffee
|
||||
[ -z "$(module_dir_src)" ] || (for f in $(module_dir_src)/*; do cp -rf "$$f" build/$(module_dir)/; done)
|
||||
[ -z "$(module_dir_src)" ] || (for f in build/$(module_dir)/*.coffee; do coffee --compile "$$f"; done)
|
||||
[ -z "$(module_dir_src)" ] || (rm build/$(module_dir)/*.coffee)
|
||||
|
||||
|
||||
js: coffee
|
||||
for f in $(jsfiles); do (cat "$${f}"; echo) >> build/main.js; done
|
||||
|
Loading…
Reference in New Issue
Block a user