mirror of
https://github.com/lxsang/antos-frontend.git
synced 2024-12-26 01:18:21 +01:00
add DotEditor package
This commit is contained in:
parent
f1616d0240
commit
a0008663ab
7
Makefile
7
Makefile
@ -97,6 +97,13 @@ package:
|
||||
cp -rf src/packages/$$PKG/build/* $(BUILDDIR)/packages/$$PKG/;\
|
||||
test -d src/packages/$$PKG/build && rm -r src/packages/$$PKG/build;
|
||||
|
||||
pkgar:
|
||||
read -r -p "Enter package name: " PKG;\
|
||||
echo $$PKG | make package &&\
|
||||
test -f $(BUILDDIR)/packages/$$PKG/main.js && uglifyjs $(BUILDDIR)/packages/$$PKG/main.js --compress --mangle --output $(BUILDDIR)/packages/$$PKG/main.js;\
|
||||
test -f $(BUILDDIR)/packages/$$PKG/main.css && minify --output $(BUILDDIR)/packages/$$PKG/main.css $(BUILDDIR)/packages/$$PKG/main.css;\
|
||||
cd $(BUILDDIR)/packages/$$PKG && zip -r "$$PKG.zip" ./ ; \
|
||||
cd ../../ && mv packages/$$PKG/"$$PKG.zip" repo/ && rm -r packages/$$PKG
|
||||
|
||||
uglify:
|
||||
# uglify antos.js
|
||||
|
@ -158,6 +158,7 @@ class RemoteFileHandler extends self.OS.API.VFS.BaseFileHandler
|
||||
return f { error: __("{0} is not a directory", @path) } if @info.type is "file"
|
||||
_API.handler.mkdir "#{@path}/#{p}", f
|
||||
when "write"
|
||||
return _API.handler.write me.path, me.cache, f if p is "base64"
|
||||
@sendB64 p, (data) ->
|
||||
_API.handler.write me.path, data, f
|
||||
when "upload"
|
||||
|
@ -122,7 +122,7 @@ class GoogleDriveHandler extends this.OS.API.VFS.BaseFileHandler
|
||||
error xhr, xhr.status
|
||||
xhr.onerror = () ->
|
||||
error xhr, xhr.status
|
||||
|
||||
return xhr.send me.cache.replace /^data:[^;]+;base64,/g, "" if m is "base64"
|
||||
@sendB64 m, (data) ->
|
||||
xhr.send data.replace /^data:[^;]+;base64,/g, ""
|
||||
|
||||
|
11
src/packages/DotEditor/Makefile
Normal file
11
src/packages/DotEditor/Makefile
Normal file
@ -0,0 +1,11 @@
|
||||
coffee_files = main.coffee
|
||||
|
||||
jsfiles = viz-lite.js svg-pan-zoom.js
|
||||
|
||||
cssfiles = main.css
|
||||
|
||||
copyfiles = scheme.html package.json
|
||||
|
||||
|
||||
PKG_NAME=DotEditor
|
||||
include ../pkg.mk
|
199
src/packages/DotEditor/main.coffee
Normal file
199
src/packages/DotEditor/main.coffee
Normal file
@ -0,0 +1,199 @@
|
||||
class DotEditor extends this.OS.GUI.BaseApplication
|
||||
constructor: ( args ) ->
|
||||
super "DotEditor", args
|
||||
|
||||
main: () ->
|
||||
me = @
|
||||
@currfile = if @args and @args.length > 0 then @args[0].asFileHandler() else "Untitled".asFileHandler()
|
||||
@currfile.dirty = false
|
||||
@datarea = @find "datarea"
|
||||
@preview = @find "preview"
|
||||
|
||||
@.editor = ace.edit @datarea
|
||||
@.editor.setOptions {
|
||||
enableBasicAutocompletion: true,
|
||||
enableLiveAutocompletion: true,
|
||||
fontSize: "9pt"
|
||||
}
|
||||
#@.editor.completers.push { getCompletions: ( editor, session, pos, prefix, callback ) -> }
|
||||
@.editor.getSession().setUseWrapMode true
|
||||
@editor.session.setMode "ace/mode/dot"
|
||||
@editor.setTheme "ace/theme/monokai"
|
||||
@editor.on "input", () ->
|
||||
if me.editormux
|
||||
me.editormux = false
|
||||
return false
|
||||
if not me.currfile.dirty
|
||||
me.currfile.dirty = true
|
||||
@editormux = true
|
||||
@editor.setValue DotEditor.dummygraph
|
||||
@editor.container.addEventListener "keydown", (e) ->
|
||||
me.renderSVG true if e.key is ";"
|
||||
, true
|
||||
|
||||
@bindKey "CTRL-R", () -> me.renderSVG false
|
||||
@bindKey "ALT-G", () -> me.export "SVG"
|
||||
@bindKey "ALT-P", () -> me.export "PNG"
|
||||
@bindKey "ALT-N", () -> me.actionFile "#{me.name}-New"
|
||||
@bindKey "ALT-O", () -> me.actionFile "#{me.name}-Open"
|
||||
@bindKey "CTRL-S", () -> me.actionFile "#{me.name}-Save"
|
||||
@bindKey "ALT-W", () -> me.actionFile "#{me.name}-Saveas"
|
||||
|
||||
|
||||
@on "hboxchange", () ->
|
||||
me.editor.resize()
|
||||
me.calibrate()
|
||||
@on "focus", () -> me.editor.focus()
|
||||
me.renderSVG true
|
||||
(@find "btn-zoomin").set "onbtclick", (e) ->
|
||||
me.pan.zoomIn() if me.pan
|
||||
(@find "btn-zoomout").set "onbtclick", (e) ->
|
||||
me.pan.zoomOut() if me.pan
|
||||
(@find "btn-reset").set "onbtclick", (e) ->
|
||||
me.pan.resetZoom() if me.pan
|
||||
@open @currfile
|
||||
menu: () ->
|
||||
me = @
|
||||
menu = [{
|
||||
text: "__(File)",
|
||||
child: [
|
||||
{ text: "__(New)", dataid: "#{@name}-New", shortcut: "A-N" },
|
||||
{ text: "__(Open)", dataid: "#{@name}-Open", shortcut: "A-O" },
|
||||
{ text: "__(Save)", dataid: "#{@name}-Save", shortcut: "C-S" },
|
||||
{ text: "__(Save as)",dataid: "#{@name}-Saveas" , shortcut: "A-W" },
|
||||
{ text: "__(Render)", dataid: "#{@name}-Render", shortcut: "C-R" },
|
||||
{
|
||||
text: "__(Export as)",
|
||||
child: [
|
||||
{ text: "SVG", shortcut: "A-G" },
|
||||
{ text: "PNG", shortcut: "A-P" }
|
||||
],
|
||||
onmenuselect: (e) -> me.export e.item.data.text
|
||||
},
|
||||
],
|
||||
onmenuselect: (e) -> me.actionFile e.item.data.dataid
|
||||
}]
|
||||
menu
|
||||
open: (file) ->
|
||||
return if file.path is "Untitled"
|
||||
me = @
|
||||
file.dirty = false
|
||||
file.read (d) ->
|
||||
me.currfile = file
|
||||
me.editormux = true
|
||||
me.currfile.dirty = false
|
||||
me.editor.setValue d
|
||||
me.scheme.set "apptitle", "#{me.currfile.basename}"
|
||||
me.renderSVG false
|
||||
save: (file) ->
|
||||
me = @
|
||||
file.write "text/plain", (d) ->
|
||||
return me.error __("Error saving file {0}", file.basename) if d.error
|
||||
file.dirty = false
|
||||
file.text = file.basename
|
||||
me.scheme.set "apptitle", "#{me.currfile.basename}"
|
||||
|
||||
actionFile: (e) ->
|
||||
me = @
|
||||
saveas = () ->
|
||||
me.openDialog "FileDiaLog", (d, n) ->
|
||||
me.currfile.setPath "#{d}/#{n}"
|
||||
me.save me.currfile
|
||||
, __("Save as"), { file: me.currfile }
|
||||
switch e
|
||||
when "#{@name}-Open"
|
||||
@openDialog "FileDiaLog", ( d, f ) ->
|
||||
me.open "#{d}/#{f}".asFileHandler()
|
||||
, __("Open file")
|
||||
when "#{@name}-Save"
|
||||
@currfile.cache = @editor.getValue()
|
||||
return @save @currfile if @currfile.basename
|
||||
saveas()
|
||||
when "#{@name}-Saveas"
|
||||
@currfile.cache = @editor.getValue()
|
||||
saveas()
|
||||
when "#{@name}-Render"
|
||||
me.renderSVG false
|
||||
when "#{@name}-New"
|
||||
@currfile = "Untitled".asFileHandler()
|
||||
@currfile.cache = ""
|
||||
@currfile.dirty = false
|
||||
@editormux = true
|
||||
@editor.setValue("")
|
||||
|
||||
export: (t) ->
|
||||
me = @
|
||||
me.openDialog "FileDiaLog", (d, n) ->
|
||||
fp = "#{d}/#{n}".asFileHandler()
|
||||
try
|
||||
switch t
|
||||
when "SVG"
|
||||
fp.cache = Viz me.editor.getValue(), { format: "svg", scale: 1 }
|
||||
fp.write "text/plain", (r) ->
|
||||
return me.error __("Cannot export to {0}: {1}", t, r.error) if r.error
|
||||
me.notify __("File exported")
|
||||
when "PNG"
|
||||
content = Viz me.editor.getValue(), { format: "png-image-element", scale: 1}
|
||||
content.onload = () ->
|
||||
fp.cache = @src
|
||||
fp.write "base64", (r) ->
|
||||
return me.error __("Cannot export to {0}: {1}", t, r.error) if r.error
|
||||
me.notify __("File exported")
|
||||
catch e
|
||||
me.error __("Cannot export: {0}", e.message)
|
||||
, __("Export as"), { file: me.currfile }
|
||||
|
||||
renderSVG: (silent) ->
|
||||
console.log "render svg"
|
||||
try
|
||||
result = Viz @editor.getValue(), { format: "svg", scale: 1 }
|
||||
svg = $.parseHTML result
|
||||
$(@preview).children("svg").remove()
|
||||
$(@preview).append svg
|
||||
svg = $(@preview).children("svg")[0]
|
||||
@calibrate()
|
||||
@pan = svgPanZoom svg, {
|
||||
zoomEnabled: true,
|
||||
controlIconsEnabled: false,
|
||||
fit: true,
|
||||
center: true,
|
||||
minZoom: 0.1
|
||||
}
|
||||
catch e
|
||||
@error e.message unless silent
|
||||
|
||||
calibrate: () ->
|
||||
svg = ($ @preview).children("svg")[0]
|
||||
if svg
|
||||
prs = [$(@preview).width(), $(@preview).height()]
|
||||
$(svg).attr "width", prs[0] + "px"
|
||||
$(svg).attr "height", prs[1] + "px"
|
||||
|
||||
cleanup: (evt) ->
|
||||
return unless @currfile.dirty
|
||||
me = @
|
||||
evt.preventDefault()
|
||||
@.openDialog "YesNoDialog", (d) ->
|
||||
if d
|
||||
me.currfile.dirty = false
|
||||
me.quit()
|
||||
, __("Quit"), { text: __("Quit without saving ?") }
|
||||
|
||||
DotEditor.dummygraph = """
|
||||
graph graphname {
|
||||
// This attribute applies to the graph itself
|
||||
size="2";
|
||||
// The label attribute can be used to change the label of a node
|
||||
a [label="Foo"];
|
||||
// Here, the node shape is changed.
|
||||
b [shape=box];
|
||||
// These edges both have different line properties
|
||||
a -- b -- c [color=blue];
|
||||
b -- d [style=dotted];
|
||||
// [style=invis] hides a node.
|
||||
}
|
||||
"""
|
||||
DotEditor.dependencies = [
|
||||
"ace/ace"
|
||||
]
|
||||
this.OS.register "DotEditor", DotEditor
|
22
src/packages/DotEditor/main.css
Normal file
22
src/packages/DotEditor/main.css
Normal file
@ -0,0 +1,22 @@
|
||||
afx-app-window[data-id="dot-edit-win"] div[data-id="preview"]
|
||||
{
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
afx-app-window[data-id="dot-edit-win"] afx-button button
|
||||
{
|
||||
border-radius: 0;
|
||||
padding-top:2px;
|
||||
padding-bottom: 2px;
|
||||
}
|
||||
afx-app-window[data-id="dot-edit-win"] afx-resizer{
|
||||
background-color: transparent;
|
||||
}
|
||||
afx-app-window[data-id="dot-edit-win"] div[data-id="btn-container"]{
|
||||
background-color: transparent;
|
||||
position: absolute;
|
||||
bottom:10px;
|
||||
right: 10px;
|
||||
display: inline;
|
||||
}
|
14
src/packages/DotEditor/package.json
Normal file
14
src/packages/DotEditor/package.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"app":"DotEditor",
|
||||
"name":"Dot Graph Editor",
|
||||
"description":"Create graph with dot language",
|
||||
"info":{
|
||||
"author": "Xuan Sang LE",
|
||||
"email": "xsang.le@gmail.com",
|
||||
"licences": "MIT"
|
||||
},
|
||||
"version":"0.1a",
|
||||
"category":"Office",
|
||||
"iconclass": "fa fa-sitemap",
|
||||
"mimes":["text/.*graphviz"]
|
||||
}
|
14
src/packages/DotEditor/scheme.html
Normal file
14
src/packages/DotEditor/scheme.html
Normal file
@ -0,0 +1,14 @@
|
||||
<afx-app-window data-id="dot-edit-win" apptitle="__(Dot editor)" width="650" height="500">
|
||||
<afx-hbox>
|
||||
<div data-id="datarea"></div>
|
||||
<afx-resizer data-width="5"></afx-resizer>
|
||||
<div data-id="preview">
|
||||
<div data-height="25" data-id="btn-container" >
|
||||
<afx-button data-id="btn-zoomin" iconclass="fa fa-search-plus"></afx-button>
|
||||
<afx-button data-id="btn-zoomout" iconclass="fa fa-search-minus"></afx-button>
|
||||
<afx-button data-id="btn-reset" iconclass="fa fa-square-o"></afx-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</afx-hbox>
|
||||
</afx-app-window>
|
1899
src/packages/DotEditor/svg-pan-zoom.js
Normal file
1899
src/packages/DotEditor/svg-pan-zoom.js
Normal file
File diff suppressed because it is too large
Load Diff
207
src/packages/DotEditor/viz-lite.js
Normal file
207
src/packages/DotEditor/viz-lite.js
Normal file
File diff suppressed because one or more lines are too long
@ -65,6 +65,7 @@ class MarkOn extends this.OS.GUI.BaseApplication
|
||||
me = @
|
||||
file.dirty = false
|
||||
file.read (d) ->
|
||||
me.currfile = file
|
||||
me.editormux = true
|
||||
me.editor.value d
|
||||
me.scheme.set "apptitle", "#{me.currfile.basename}"
|
||||
@ -73,7 +74,7 @@ class MarkOn extends this.OS.GUI.BaseApplication
|
||||
|
||||
save: (file) ->
|
||||
me = @
|
||||
file.write (file.getb64 "text/plain"), (d) ->
|
||||
file.write "text/plain", (d) ->
|
||||
return me.error __("Error saving file {0}", file.basename) if d.error
|
||||
file.dirty = false
|
||||
file.text = file.basename
|
||||
|
Loading…
Reference in New Issue
Block a user