use fat arrow for this reference

This commit is contained in:
Xuan Sang LE
2020-05-17 17:05:12 +02:00
parent 95cfddb389
commit fa22fc5413
41 changed files with 1086 additions and 1072 deletions

View File

@ -21,12 +21,11 @@ class ActivityMonitor extends this.OS.GUI.BaseApplication
constructor: (args) ->
super "ActivityMonitor", args
main: () ->
me = @
@scheme.set "apptitle", "Activity Monitor"
@grid = @find "mygrid"
@on "btclick", (e) ->
@on "btclick", (e) =>
return unless e.id == "btkill"
item = me.grid.get "selectedRow"
item = @grid.get "selectedRow"
return unless item
data = item.get("data")[0]
app = _PM.appByPid data.text
@ -57,17 +56,16 @@ class ActivityMonitor extends this.OS.GUI.BaseApplication
@monitor()
monitor: () ->
me = @
#get all current running process
me.gdata.alive = []
@gdata.alive = []
now = (new Date).getTime()
$.each _PM.processes, (i, d) ->
$.each d , (j, a) ->
if me.gdata.processes[a.pid] #update it
me.gdata.processes[a.pid][3].text = now - a.birth
me.gdata.processes[a.pid][3].domel.update()
$.each _PM.processes, (i, d) =>
$.each d , (j, a) =>
if @gdata.processes[a.pid] #update it
@gdata.processes[a.pid][3].text = now - a.birth
@gdata.processes[a.pid][3].domel.update()
else #add it
me.gdata.processes[a.pid] = [
@gdata.processes[a.pid] = [
{ text: a.pid },
{
icon: if _APP[a.name].type == 1 then _APP[a.name].meta.icon else a.icon,
@ -81,16 +79,16 @@ class ActivityMonitor extends this.OS.GUI.BaseApplication
text: now - a.birth
}
]
me.grid.push me.gdata.processes[a.pid]
me.gdata.alive.push a.pid
@grid.push @gdata.processes[a.pid]
@gdata.alive.push a.pid
$.each @gdata.processes, (i, e) ->
if ($.inArray (Number i), me.gdata.alive) < 0
me.grid.remove me.gdata.processes[i].domel
me.gdata.processes[i] = undefined
delete me.gdata.processes[i]
$.each @gdata.processes, (i, e) =>
if ($.inArray (Number i), @gdata.alive) < 0
@grid.remove @gdata.processes[i].domel
@gdata.processes[i] = undefined
delete @gdata.processes[i]
@timer = setTimeout (() -> me.monitor()), 500
@timer = setTimeout (() => @monitor()), 500
cleanup: (e) ->
clearTimeout @timer if @timer

View File

@ -3,27 +3,26 @@ class CommandPalette extends this.OS.GUI.BasicDialog
super "CommandPalete", CommandPalette.scheme
init: () ->
me = @
offset = $(".afx-window-content", @parent.scheme).offset()
pw = @parent.scheme.get("width") / 5
@scheme.set "width", 3 * pw
$(@scheme).offset { top: offset.top - 2, left: offset.left + pw }
cb = (e) ->
if ($ e.target).closest(me.scheme).length > 0
$(me.find "searchbox").focus()
cb = (e) =>
if ($ e.target).closest(@scheme).length > 0
$(@find "searchbox").focus()
else
$(document).unbind "mousedown", cb
me.quit()
@quit()
$(document).on "mousedown", cb
$(me.find "searchbox").focus()
$(@find "searchbox").focus()
@cmdlist = @find("container")
@cmdlist.set "data", (v for v in @data.child) if @data
$(@cmdlist).click (e) ->
me.selectCommand()
$(@cmdlist).click (e) =>
@selectCommand()
@searchbox = @find "searchbox"
($ @searchbox).keyup (e) ->
me.search e
($ @searchbox).keyup (e) =>
@search e
search: (e) ->
switch e.which

View File

@ -8,42 +8,45 @@ class App.extensions.AntOSDK extends App.BaseExtension
# 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
}).then (d) =>
@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
.then (d) =>
return @notify __("Cannot read folder: {0}", dir.path) if d.error
return @notify __("The folder is not empty: {0}", dir.path) unless d.result.length is 0
@mktpl dir.parent().path, dir.basename
build: () ->
console.log "build"
release: () ->
console.log "release"
options: () ->
console.log "options"
buildnrun: () ->
@metadata().then (meta) =>
@build(meta).then () =>
@run(meta).catch (e) => @error.toString()
.catch (e) =>
@error e.toString()
.catch (e) => @error e.toString()
release: () ->
@metadata().then (meta) =>
@build(meta).then () =>
@mkar(meta)
.then () ->
.catch (e) => @error.toString()
.catch (e) =>
@error e.toString()
.catch (e) => @error e.toString()
dependencies: () ->
[
"AntOSDK/coffeescript.js"
]
# private functions
mktpl: (path, name, flag) ->
me = @
rpath = "#{path}/#{name}"
console.log rpath
dirs = [
"#{rpath}/build",
"#{rpath}/build/release",
@ -57,49 +60,198 @@ class App.extensions.AntOSDK extends App.BaseExtension
files = [
["main.tpl", "#{rpath}/coffees/main.coffee"],
["package.tpl", "#{rpath}/package.json"],
["project.tpl", "#{rpath}/project.apj"],
["project.tpl", "#{rpath}/project.json"],
["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
.then () =>
@mkfileAll(files, path, name)
.then () =>
@app.currdir = rpath.asFileHandle()
@app.initSideBar()
@app.openFile "#{rpath}/README.md".asFileHandle()
.catch (e) => @error e.stack
.catch (e) => @error e.stack
mkdirAll: (list) ->
me = @
new Promise (resolve, reject) ->
new Promise (resolve, reject) =>
return resolve() if list.length is 0
path = (list.splice 0, 1)[0].asFileHandle()
console.log path.parent().path, path.basename
path.parent().mk path.basename
.then () ->
me.mkdirAll list
.then (d) =>
@mkdirAll list
.then () -> resolve()
.catch (e) -> reject e
.catch (e) -> reject e
mkfileAll: (list, path, name) ->
me = @
new Promise (resolve, reject) ->
new Promise (resolve, reject) =>
return resolve() if list.length is 0
item = (list.splice 0, 1)[0]
"#{me.basedir()}/AntOSDK/templates/#{item[0]}"
"#{@basedir()}/AntOSDK/templates/#{item[0]}"
.asFileHandle()
.read()
.then (data) ->
.then (data) =>
file = item[1].asFileHandle()
.setCache(data.format name, "#{path}/#{name}")
.write "text/plain"
.then () ->
me.mkfileAll list, path, name
.then () =>
@mkfileAll list, path, name
.then () -> resolve()
.catch (e) -> reject e
.catch (e) -> reject e
.catch (e) -> reject e
metadata: () ->
new Promise (resolve, reject) =>
if not @app.currdir
return reject @app._api.throwe __("Project folder is not found")
"#{@app.currdir.path}/project.json"
.asFileHandle()
.read("json")
.then (data) ->
resolve data
.catch (e) =>
reject @app._api.throwe __("Unable to read project meta-data")
verify: (list) ->
new Promise (resolve, reject) =>
return resolve() if list.length is 0
file = (list.splice 0, 1)[0].asFileHandle()
@notify __("Verifying: {0}", file.path)
file.read().then (data) =>
try
CoffeeScript.nodes data
@verify list
.then () -> resolve()
.catch (e) -> reject e
catch ex
reject ex
.catch (e) -> reject e
compile: (meta) ->
new Promise (resolve, reject) =>
@import("#{@basedir()}/AntOSDK/coffeescript.js").then () =>
list = ("#{meta.root}/#{v}" for v in meta.coffees)
@verify((f for f in list)).then () =>
@cat(list).then (code) =>
jsrc = CoffeeScript.compile code
@notify __("Compiled successful")
resolve jsrc
.catch (e) -> reject e
.catch (e) -> reject e
.catch (e) -> reject e
build: (meta) ->
new Promise (resolve, reject) =>
@compile(meta).then (src) =>
@cat ("#{meta.root}/#{v}" for v in meta.javascripts), src
.then (jsrc) ->
new Promise (r, e) ->
"#{meta.root}/build/debug/main.js"
.asFileHandle()
.setCache jsrc
.write("text/plain")
.then (d) ->
return e d if d.error
r()
.catch (ex) -> e ex
.then () =>
new Promise (r, e) =>
@cat ("#{meta.root}/#{v}" for v in meta.css), ""
.then (txt) ->
return r() if txt is ""
"#{meta.root}/build/debug/main.css"
.asFileHandle()
.setCache txt
.write("text/plain")
.then (d) ->
return e d if d.error
r()
.catch (ex) -> e ex
.then () =>
@copy ("#{meta.root}/#{v}" for v in meta.copies), "#{meta.root}/build/debug"
.then () -> resolve()
.catch (e) -> reject e
.catch (e) -> reject e
run: (meta) ->
"#{meta.root}/build/debug/package.json"
.asFileHandle()
.read("json")
.then (v) =>
v.text = v.name
v.path = "#{meta.root}/build/debug"
v.filename = meta.name
v.type = "app"
v.mime = "antos/app"
v.icon = "#{v.path}/#{v.icon}" if v.icon
v.iconclass = "fa fa-adn" unless v.iconclass or v.icon
@notify __("Installing...")
@app.systemsetting.system.packages[meta.name] = v
@notify __("Running {0}...", meta.name)
@app._gui.forceLaunch meta.name
cat: (list, data) ->
new Promise (resolve, reject) =>
return resolve data if list.length is 0
file = (list.splice 0, 1)[0].asFileHandle()
file
.read()
.then (text) =>
data = data + "\n" + text
@cat list, data
.then (d) -> resolve d
.catch (e) -> reject e
.catch (e) -> reject e
copy: (files, to) ->
new Promise (resolve, reject) =>
return resolve() if files.length is 0
file = (files.splice 0, 1)[0].asFileHandle()
tof = "#{to}/#{file.basename}".asFileHandle()
file.read("binary")
.then (data) =>
tof.setCache(new Blob [data], { type: file.info.mime })
.write(file.info.mime)
.then (d) =>
@copy files, to
.then () -> resolve()
.catch (e) -> reject e
.catch (e) -> reject e
mkar: (meta) ->
@notify __("Preparing for release")
new Promise (r, e) =>
@import("os://scripts/jszip.min.js").then () ->
"#{meta.root}/build/debug".asFileHandle()
.read().then (d) ->
return e d.error if d.error
r d.result
.catch (ex) -> e ex
.catch (ex) -> e ex
.then (files) =>
new Promise (r, e) =>
zip = new JSZip()
fn = (list) =>
return r zip if list.length is 0
f = (list.splice 0, 1)[0].path.asFileHandle()
return fn list if f.type is "dir"
f.read("binary").then (d) =>
zip.file f.basename, d, { binary: true }
@notify __("add {0} to zip", f.basename)
fn list
.catch (ex) -> e ex
fn files
.then (zip) =>
zip.generateAsync({ type: "base64" }).then (data) =>
"#{meta.root}/build/release/#{meta.name}.zip"
.asFileHandle()
.setCache('data:application/zip;base64,' + data)
.write("base64").then (r) =>
return @error __("Cannot save the zip file: {0}", r.error) if r.error
@notify __("Package is generated in release folder")
.catch (e) => @error e.toString()
.catch (e) => @error e.toString()

View File

@ -13,7 +13,6 @@ class CodePad extends this.OS.GUI.BaseApplication
@currdir = @currfile.parent()
main: () ->
me = @
@extensions = {}
@fileview = @find("fileview")
@sidebar = @find("sidebar")
@ -27,12 +26,10 @@ class CodePad extends this.OS.GUI.BaseApplication
dir = path.asFileHandle() if typeof path is "string"
dir.read().then (d) ->
return reject d.error if d.error
me.currdir = dir
resolve d.result
@setup()
setup: () ->
me = @
ace.config.set('basePath', '/scripts/ace')
ace.require "ace/ext/language_tools"
@editor = ace.edit @find("datarea")
@ -50,56 +47,56 @@ class CodePad extends this.OS.GUI.BaseApplication
@editor.completers.push { getCompletions: ( editor, session, pos, prefix, callback ) -> }
@editor.getSession().setUseWrapMode true
@editormux = false
@editor.on "input", () ->
if me.editormux
me.editormux = false
@editor.on "input", () =>
if @editormux
@editormux = false
return false
if not me.currfile.dirty
me.currfile.dirty = true
me.currfile.text += "*"
me.tabbar.update()
@editor.getSession().selection.on "changeCursor", (e) ->
me.updateStatus()
if not @currfile.dirty
@currfile.dirty = true
@currfile.text += "*"
@tabbar.update()
@editor.getSession().selection.on "changeCursor", (e) =>
@updateStatus()
@tabbar.set "ontabselect", (e) ->
me.selecteTab $(e.data.item).index()
@tabbar.set "ontabclose", (e) ->
@tabbar.set "ontabselect", (e) =>
@selecteTab $(e.data.item).index()
@tabbar.set "ontabclose", (e) =>
it = e.data.item
return false unless it
return me.closeTab it unless it.get("data").dirty
me.openDialog("YesNoDialog", {
return @closeTab it unless it.get("data").dirty
@openDialog("YesNoDialog", {
title: __("Close tab"),
text: __("Close without saving ?")
}).then (d) ->
return me.closeTab it if d
me.editor.focus()
}).then (d) =>
return @closeTab it if d
@editor.focus()
return false
@fileview.set "onfileopen", (e) ->
@fileview.set "onfileopen", (e) =>
return if e.data.type is "dir"
me.openFile e.data.path.asFileHandle()
@openFile e.data.path.asFileHandle()
@fileview.set "onfileselect", (e) ->
@fileview.set "onfileselect", (e) =>
return unless e.data or e.data.type is "dir"
i = me.findTabByFile e.data.path.asFileHandle()
return me.tabbar.set "selected", i if i isnt -1
i = @findTabByFile e.data.path.asFileHandle()
return @tabbar.set "selected", i if i isnt -1
@on "resize", () -> me.editor.resize()
@on "focus", () -> me.editor.focus()
@on "resize", () => @editor.resize()
@on "focus", () => @editor.focus()
@spotlight = new CMDMenu __("Command palette")
@bindKey "ALT-P", () -> me.spotlight.run me
@find("datarea").contextmenuHandle = (e, m) ->
@bindKey "ALT-P", () => @spotlight.run @
@find("datarea").contextmenuHandle = (e, m) =>
m.set "items", [{
text: __("Command palete"),
onmenuselect: (e) ->
me.spotlight.run me
onmenuselect: (e) =>
@spotlight.run @
}]
m.show e
@bindKey "ALT-N", () -> me.menuAction "new"
@bindKey "ALT-O", () -> me.menuAction "open"
@bindKey "ALT-F", () -> me.menuAction "opendir"
@bindKey "CTRL-S", () -> me.menuAction "save"
@bindKey "ALT-W", () -> me.menuAction "saveas"
@bindKey "ALT-N", () => @menuAction "new"
@bindKey "ALT-O", () => @menuAction "open"
@bindKey "ALT-F", () => @menuAction "opendir"
@bindKey "CTRL-S", () => @menuAction "save"
@bindKey "ALT-W", () => @menuAction "saveas"
@loadExtensionMetaData()
@initCommandPalete()
@ -112,13 +109,13 @@ class CodePad extends this.OS.GUI.BaseApplication
i = @findTabByFile file
return @tabbar.set "selected", i if i isnt -1
return @newTab file if file.path.toString() is "Untitled"
me = @
file.read()
.then (d) ->
.then (d) =>
file.cache = d or ""
me.newTab file
.catch (e) ->
me.error __("Unable to open: {0}", file.path)
@newTab file
.catch (e) =>
@error __("Unable to open: {0}", file.path)
findTabByFile: (file) ->
lst = @tabbar.get "items"
@ -218,38 +215,35 @@ class CodePad extends this.OS.GUI.BaseApplication
@addAction CMDMenu.fromMenu @fileMenu()
loadExtensionMetaData: () ->
me = @
"#{@meta().path}/extensions.json"
.asFileHandle()
.read("json")
.then (d) ->
.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
if @extensions[ext.name]
@extensions[ext.name].child = {}
@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")
@extensions[ext.name] = new CMDMenu ext.text
@extensions[ext.name].name = ext.name
@extensions[ext.name].addAction v for v in ext.actions
@spotlight.addAction @extensions[ext.name]
@extensions[ext.name].onchildselect (e) =>
@loadAndRunExtensionAction e.data.item.get "data"
.catch (e) =>
@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)
ext = new CodePad.extensions[name](@)
return @error __("Unable to find action: {0}", action) unless ext[action]
ext.preload()
.then () ->
ext[action]()
.catch (e) ->
me.error e.stack
.catch (e) =>
@error e.stack
loadAndRunExtensionAction: (data) ->
me = @
name = data.parent.name
action = data.name
#verify if the extension is load
@ -257,14 +251,13 @@ class CodePad extends this.OS.GUI.BaseApplication
#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)
.then () => @runExtensionAction name, action
.catch (e) =>
@error __("unable to load extension: {}", name)
else
@runExtensionAction name, action
fileMenu: () ->
me = @
{
text: __("File"),
child: [
@ -274,35 +267,33 @@ class CodePad extends this.OS.GUI.BaseApplication
{ text: __("Save"), dataid: "save", shortcut: "C-S" },
{ text: __("Save as"), dataid: "saveas", shortcut: "A-W" }
],
onchildselect: (e, r) ->
me.menuAction e.data.item.get("data").dataid, r
onchildselect: (e, r) =>
@menuAction e.data.item.get("data").dataid, r
}
save: (file) ->
me = @
file.write("text/plain")
.then (d) ->
return me.error __("Error saving file {0}: {1}", file.basename, d.error) if d.error
.then (d) =>
return @error __("Error saving file {0}: {1}", file.basename, d.error) if d.error
file.dirty = false
file.text = file.basename
me.tabbar.update()
me.scheme.set "apptitle", "#{me.currfile.basename}"
.catch (e) -> me.error e.stack
@tabbar.update()
@scheme.set "apptitle", "#{@currfile.basename}"
.catch (e) => @error e.stack
saveAs: () ->
me = @
me.openDialog("FileDialog", {
@openDialog("FileDialog", {
title: __("Save as"),
file: me.currfile
file: @currfile
})
.then (f) ->
.then (f) =>
d = f.file.path.asFileHandle()
d = d.parent() if f.file.type is "file"
me.currfile.setPath "#{d.path}/#{f.name}"
me.save me.currfile
.catch (e) ->
me.error e.stack
@currfile.setPath "#{d.path}/#{f.name}"
@save @currfile
.catch (e) =>
@error e.stack
menuAction: (dataid, r) ->
me = @
@ -338,18 +329,16 @@ class CodePad extends this.OS.GUI.BaseApplication
cleanup: (evt) ->
dirties = ( v for v in @tabbar.get "items" when v.dirty )
return if dirties.length is 0
me = @
evt.preventDefault()
@.openDialog("YesNoDialog", {
title: "__(Quit)",
text: __("Ignore all {0} unsaved files ?", dirties.length)
}).then (d) ->
}).then (d) =>
if d
v.dirty = false for v in dirties
me.quit()
@quit()
menu: () ->
me = @
menu = [
@fileMenu()
{
@ -357,8 +346,8 @@ class CodePad extends this.OS.GUI.BaseApplication
child: [
{ text: "__(Command Palette)", dataid: "cmdpalette", shortcut: "A-P" }
],
onchildselect: (e, r) ->
me.spotlight.run me
onchildselect: (e, r) =>
@spotlight.run @
}
]
menu
@ -368,8 +357,10 @@ class CodePad.BaseExtension
constructor: (@app) ->
preload: () ->
dep = ( "#{@basedir()}/#{v}" for v in @dependencies())
Ant.OS.API.require dep
Ant.OS.API.require @dependencies()
import: (lib) ->
Ant.OS.API.requires lib
basedir: () ->
"#{@app.meta().path}/extensions"
@ -402,12 +393,11 @@ class CMDMenu
@
run: (root) ->
me = @
root.openDialog(new CommandPalette(), @)
.then (d) ->
.then (d) =>
data = d.data.item.get("data")
return data.run root if data.run
me.select d, root
@select d, root
CMDMenu.fromMenu = (mn) ->
m = new CMDMenu mn.text, mn.shortcut

View File

@ -14,15 +14,11 @@
},
{
"text": "__(Build and Run)",
"name": "build"
"name": "buildnrun"
},
{
"text": "__(Build release)",
"name": "release"
},
{
"text": "__(Build options)",
"name": "options"
}
]
}

View File

@ -23,11 +23,10 @@ class Calendar extends this.OS.GUI.BaseService
@iconclass = "fa fa-calendar"
init: ->
#update time each second
me = @
@watch 1000, () ->
@watch 1000, () =>
now = new Date
me.text = now.toString()
me.domel.set "text", me.text
@text = now.toString()
@domel.set "text", @text
awake: (e) ->

View File

@ -37,27 +37,26 @@ class PushNotification extends this.OS.GUI.BaseService
@update()
main: ->
me = @
@mlist = @find "notifylist"
@mfeed = @find "notifeed"
@nzone = @find "notifyzone"
@fzone = @find "feedzone"
(@find "btclear").set "onbtclick", (e) -> me.mlist.set "data", []
(@find "btclear").set "onbtclick", (e) => @mlist.set "data", []
#@subscribe "fail", (e) -> console.log e
@subscribe "notification", (o) -> me.pushout 'INFO', o
@subscribe "fail", (o) -> me.pushout 'FAIL', o
@subscribe "error", (o) -> me.pushout 'ERROR', o
@subscribe "info", (o) -> me.pushout 'INFO', o
@subscribe "VFS", (o) -> me.pushout 'INFO', o
@subscribe "notification", (o) => @pushout 'INFO', o
@subscribe "fail", (o) => @pushout 'FAIL', o
@subscribe "error", (o) => @pushout 'ERROR', o
@subscribe "info", (o) => @pushout 'INFO', o
#@subscribe "VFS", (o) => @pushout 'INFO', o
@subscribe "loading", (o) ->
me.pending.push o.id
me.spin true
@subscribe "loading", (o) =>
@pending.push o.id
@spin true
@subscribe "loaded", (o) ->
i = me.pending.indexOf o.id
me.pending.splice i, 1 if i >= 0
me.spin false if me.pending.length is 0
@subscribe "loaded", (o) =>
i = @pending.indexOf o.id
@pending.splice i, 1 if i >= 0
@spin false if @pending.length is 0
@nzone.set "height", "100%"
@fzone.set "height", "100%"
@ -83,25 +82,23 @@ class PushNotification extends this.OS.GUI.BaseService
@notifeed d
notifeed: (d) ->
me = @
@mfeed.unshift d, true
($ @fzone).show()
timer = setTimeout () ->
me.mfeed.remove d.domel
($ me.fzone).hide() if me.mfeed.get("data").length is 0
timer = setTimeout () =>
@mfeed.remove d.domel
($ @fzone).hide() if @mfeed.get("data").length is 0
clearTimeout timer
, 3000
awake: (evt) ->
if @view then ($ @nzone).hide() else ($ @nzone).show()
@view = not @view
me = @
if not @cb
@cb = (e) ->
if not ($ e.target).closest($ me.nzone).length and not ($ e.target).closest(evt.data.item).length
($ me.nzone).hide()
$(document).unbind "click", me.cb
me.view = not me.view
@cb = (e) =>
if not ($ e.target).closest($ @nzone).length and not ($ e.target).closest(evt.data.item).length
($ @nzone).hide()
$(document).unbind "click", @cb
@view = not @view
if @view
$(document).on "click", @cb
else

View File

@ -21,7 +21,6 @@ class Files extends this.OS.GUI.BaseApplication
super "Files", args
main: () ->
me = @
@scheme.set "apptitle", "Files manager"
@view = @find "fileview"
@navinput = @find "navinput"
@ -34,54 +33,55 @@ class Files extends this.OS.GUI.BaseApplication
@clipboard = undefined
@viewType = @_api.switcher "icon", "list", "tree"
@viewType.list = true
@apps = []
@view.contextmenuHandle = (e, m) ->
m.set "items", [ me.mnFile(), me.mnEdit() ]
# Fix m.set "onmenuselect", (evt) ->
# me._gui.launch evt.item.data.app, evt.item.data.args if evt.item.data.app
@view.contextmenuHandle = (e, m) =>
file = @view.get "selectedFile"
apps = []
if file and file.mime
file.mime = "dir" if file.type is "dir"
for v in @_gui.appsByMime file.mime
v.args = [ file.path ]
apps.push v
m.set "items", [
{ text: "__(Open with)", dataid: "#{@name}-open", child: apps },
@mnFile(),
@mnEdit()
]
m.show e
@view.set "onfileopen", (e) ->
@view.set "onfileopen", (e) =>
return unless e.data
return if e.data.type is "dir"
me._gui.openWith e.data
@_gui.openWith e.data
@favo.set "onlistselect", (e) ->
me.view.set "path", e.data.item.get("data").path
@favo.set "onlistselect", (e) =>
@view.set "path", e.data.item.get("data").path
($ @find "btback").click () ->
return if me.currdir.isRoot()
p = me.currdir.parent()
me.favo.set "selected", -1
me.view.set "path", p.path
($ @find "btback").click () =>
return if @currdir.isRoot()
p = @currdir.parent()
@favo.set "selected", -1
@view.set "path", p.path
($ @navinput).keyup (e) ->
me.view.set "path", ($ me.navinput).val() if e.keyCode is 13 #enter
($ @navinput).keyup (e) =>
@view.set "path", ($ @navinput).val() if e.keyCode is 13 #enter
@view.set "fetch", (path) ->
new Promise (resolve, reject) ->
@view.set "fetch", (path) =>
new Promise (resolve, reject) =>
dir = path
dir = path.asFileHandle() if typeof path is "string"
dir.read().then (d) ->
dir.read().then (d) =>
return reject d.error if d.error
if not dir.isRoot()
p = dir.parent()
p.filename = "[..]"
p.type = "dir"
d.result.unshift p
me.currdir = dir
($ me.navinput).val dir.path
@currdir = dir
($ @navinput).val dir.path
resolve d.result
@view.set "onfileselect", (e) ->
file = e.data
return unless file and file.mime
file.mime = "dir" if file.type is "dir"
me.apps.length = 0
for v in me._gui.appsByMime file.mime
v.args = [ file.path ]
me.apps.push v
@setting.sidebar = true if @setting.sidebar is undefined
@setting.nav = true if @setting.nav is undefined
@setting.showhidden = false if @setting.showhidden is undefined
@ -92,29 +92,29 @@ class Files extends this.OS.GUI.BaseApplication
@favo.set "data", mntpoints
#@favo.set "selected", -1
@view.set "view", @setting.view if @setting.view
@subscribe "VFS", (d) ->
@subscribe "VFS", (d) =>
return if ["read", "publish", "download"].includes d.data.m
if d.data.file.hash() is me.currdir.hash() or d.data.file.parent().hash() is me.currdir.hash()
me.view.set "path", me.currdir
@bindKey "CTRL-F", () -> me.actionFile "#{me.name}-mkf"
@bindKey "CTRL-D", () -> me.actionFile "#{me.name}-mkdir"
@bindKey "CTRL-U", () -> me.actionFile "#{me.name}-upload"
@bindKey "CTRL-S", () -> me.actionFile "#{me.name}-share"
@bindKey "CTRL-I", () -> me.actionFile "#{me.name}-info"
if d.data.file.hash() is @currdir.hash() or d.data.file.parent().hash() is @currdir.hash()
@view.set "path", @currdir
@bindKey "CTRL-F", () => @actionFile "#{@name}-mkf"
@bindKey "CTRL-D", () => @actionFile "#{@name}-mkdir"
@bindKey "CTRL-U", () => @actionFile "#{@name}-upload"
@bindKey "CTRL-S", () => @actionFile "#{@name}-share"
@bindKey "CTRL-I", () => @actionFile "#{@name}-info"
@bindKey "CTRL-R", () -> me.actionEdit "#{me.name}-mv"
@bindKey "CTRL-M", () -> me.actionEdit "#{me.name}-rm"
@bindKey "CTRL-X", () -> me.actionEdit "#{me.name}-cut"
@bindKey "CTRL-C", () -> me.actionEdit "#{me.name}-copy"
@bindKey "CTRL-P", () -> me.actionEdit "#{me.name}-paste"
@bindKey "CTRL-R", () => @actionEdit "#{@name}-mv"
@bindKey "CTRL-M", () => @actionEdit "#{@name}-rm"
@bindKey "CTRL-X", () => @actionEdit "#{@name}-cut"
@bindKey "CTRL-C", () => @actionEdit "#{@name}-copy"
@bindKey "CTRL-P", () => @actionEdit "#{@name}-paste"
(@find "btgrid").set "onbtclick", (e) ->
me.view.set 'view', "icon"
me.viewType.icon = true
(@find "btgrid").set "onbtclick", (e) =>
@view.set 'view', "icon"
@viewType.icon = true
(@find "btlist").set "onbtclick", (e) ->
me.view.set 'view', "list"
me.viewType.list = true
(@find "btlist").set "onbtclick", (e) =>
@view.set 'view', "list"
@viewType.list = true
@view.set "path", @currdir
applySetting: (k) ->
@ -126,22 +126,19 @@ class Files extends this.OS.GUI.BaseApplication
mnFile: () ->
#console.log file
me = @
arr = {
text: "__(File)",
child: [
{ text: "__(New file)", dataid: "#{@name}-mkf", shortcut: 'C-F' },
{ text: "__(New folder)", dataid: "#{@name}-mkdir", shortcut: 'C-D' },
{ text: "__(Open with)", dataid: "#{@name}-open", child: @apps },
{ text: "__(Upload)", dataid: "#{@name}-upload", shortcut: 'C-U' },
{ text: "__(Download)", dataid: "#{@name}-download" },
{ text: "__(Share file)", dataid: "#{@name}-share", shortcut: 'C-S' },
{ text: "__(Properties)", dataid: "#{@name}-info", shortcut: 'C-I' }
], onchildselect: (e) -> me.actionFile e.data.item.get("data").dataid
], onchildselect: (e) => @actionFile e.data.item.get("data").dataid
}
return arr
mnEdit: () ->
me = @
{
text: "__(Edit)",
child: [
@ -150,10 +147,10 @@ class Files extends this.OS.GUI.BaseApplication
{ text: "__(Cut)", dataid: "#{@name}-cut", shortcut: 'C-X' },
{ text: "__(Copy)", dataid: "#{@name}-copy", shortcut: 'C-C' },
{ text: "__(Paste)", dataid: "#{@name}-paste", shortcut: 'C-P' }
], onchildselect: (e) -> me.actionEdit e.data.item.get("data").dataid
], onchildselect: (e) => @actionEdit e.data.item.get("data").dataid
}
menu: () ->
me = @
menu = [
@mnFile(),
@mnEdit(),
@ -165,15 +162,15 @@ class Files extends this.OS.GUI.BaseApplication
{ text: "__(Navigation bar)", switch: true, checked: @setting.nav, dataid: "#{@name}-nav" },
{ text: "__(Hidden files)", switch: true, checked: @setting.showhidden, dataid: "#{@name}-hidden" },
{ text: "__(Type)", child: [
{ text: "__(Icon view)", radio: true, checked: me.viewType.icon, dataid: "#{@name}-icon", type: 'icon' },
{ text: "__(List view)", radio:true, checked: me.viewType.list, dataid: "#{@name}-list", type: 'list' },
{ text: "__(Tree view)", radio:true, checked: me.viewType.tree, dataid: "#{@name}-tree", type: 'tree' }
], onchildselect: (e) ->
{ text: "__(Icon view)", radio: true, checked: @viewType.icon, dataid: "#{@name}-icon", type: 'icon' },
{ text: "__(List view)", radio:true, checked: @viewType.list, dataid: "#{@name}-list", type: 'list' },
{ text: "__(Tree view)", radio:true, checked: @viewType.tree, dataid: "#{@name}-tree", type: 'tree' }
], onchildselect: (e) =>
type = e.data.item.get("data").type
me.view.set 'view', type
me.viewType[type] = true
@view.set 'view', type
@viewType[type] = true
},
], onchildselect: (e) -> me.actionView e
], onchildselect: (e) => @actionView e
},
]
menu
@ -205,7 +202,6 @@ class Files extends this.OS.GUI.BaseApplication
#@toggleNav e.item.data.checked
actionEdit: (e) ->
me = @
file = @view.get "selectedFile"
switch e
when "#{@name}-mv"
@ -215,14 +211,14 @@ class Files extends this.OS.GUI.BaseApplication
label: "__(File name)",
value: file.filename
})
.then (d) ->
.then (d) =>
return if d is file.filename
file.path.asFileHandle().move "#{me.currdir.path}/#{d}"
.then (r) ->
me.error __("Fail to rename to {0}: {1}", d, r.error) if r.error
.catch (e) ->
file.path.asFileHandle().move "#{@currdir.path}/#{d}"
.then (r) =>
@error __("Fail to rename to {0}: {1}", d, r.error) if r.error
.catch (e) =>
console.log e
me.error __("Fail to rename: {0}", e.stack)
@error __("Fail to rename: {0}", e.stack)
when "#{@name}-rm"
return unless file
@ -231,13 +227,13 @@ class Files extends this.OS.GUI.BaseApplication
iconclass: "fa fa-question-circle",
text: __("Do you really want to delete: {0}?", file.filename)
})
.then (d) ->
.then (d) =>
return unless d
file.path.asFileHandle().remove()
.then (r) ->
me.error __("Fail to delete {0}: {1}", file.filename, r.error) if r.error
.catch (e) ->
me.error __("Fail to delete: {0}", e.stack)
.then (r) =>
@error __("Fail to delete {0}: {1}", file.filename, r.error) if r.error
.catch (e) =>
@error __("Fail to delete: {0}", e.stack)
when "#{@name}-cut"
return unless file
@ -254,32 +250,30 @@ class Files extends this.OS.GUI.BaseApplication
@notify __("File {0} copied", file.filename)
when "#{@name}-paste"
me = @
return unless @clipboard
if @clipboard.cut
@clipboard.file.move "#{me.currdir.path}/#{@clipboard.file.basename}"
.then (r) ->
me.clipboard = undefined
me.error __("Fail to paste: {0}", r.error) if r.error
.catch (e) ->
me.error __("Fail to paste: {0}", e.stack)
@clipboard.file.move "#{@currdir.path}/#{@clipboard.file.basename}"
.then (r) =>
@clipboard = undefined
@error __("Fail to paste: {0}", r.error) if r.error
.catch (e) =>
@error __("Fail to paste: {0}", e.stack)
else
@clipboard.file.read("binary")
.then (d) ->
blob = new Blob [d], { type: me.clipboard.file.info.mime }
fp = "#{me.currdir.path}/#{me.clipboard.file.basename}".asFileHandle()
.then (d) =>
blob = new Blob [d], { type: @clipboard.file.info.mime }
fp = "#{@currdir.path}/#{@clipboard.file.basename}".asFileHandle()
fp.cache = blob
fp.write(me.clipboard.file.info.mime)
.then (r) ->
me.clipboard = undefined
me.error __("Fail to paste: {0}", r.error) if r.error
.catch (e) ->
me.error __("Fail to paste: {0}", e.stack)
fp.write(@clipboard.file.info.mime)
.then (r) =>
@clipboard = undefined
@error __("Fail to paste: {0}", r.error) if r.error
.catch (e) =>
@error __("Fail to paste: {0}", e.stack)
else
@_api.handle.setting()
actionFile: (e) ->
me = @
file = @view.get "selectedFile"
switch e
when "#{@name}-mkdir"
@ -287,53 +281,51 @@ class Files extends this.OS.GUI.BaseApplication
title: "__(New folder)",
label: "__(Folder name)"
})
.then (d) ->
me.currdir.mk(d)
.then (r) ->
me.error __("Fail to create {0}: {1}", d, r.error) if r.error
.catch (e) ->
me.error __("Fail to create: {0}", e.stack)
.then (d) =>
@currdir.mk(d)
.then (r) =>
@error __("Fail to create {0}: {1}", d, r.error) if r.error
.catch (e) =>
@error __("Fail to create: {0}", e.stack)
when "#{@name}-mkf"
@openDialog("PromptDialog", {
title: "__(New file)",
label: "__(File name)"
})
.then (d) ->
fp = "#{me.currdir.path}/#{d}".asFileHandle()
.then (d) =>
fp = "#{@currdir.path}/#{d}".asFileHandle()
fp.write("text/plain")
.then (r) ->
me.error __("Fail to create {0}: {1}", d, r.error) if r.error
.catch (e) ->
me.error __("Fail to create: {0}", e.stack)
.then (r) =>
@error __("Fail to create {0}: {1}", d, r.error) if r.error
.catch (e) =>
@error __("Fail to create: {0}", e.stack)
when "#{@name}-info"
return unless file
@openDialog "InfoDialog", file
when "#{@name}-upload"
me = @
@currdir.upload()
.then (r) ->
me.error __("Fail to upload to {0}: {1}", me.currdir.path, r.error) if r.error
.catch (e) ->
me.error __("Fail to upload: {0}", e.stack)
.then (r) =>
@error __("Fail to upload to {0}: {1}", @currdir.path, r.error) if r.error
.catch (e) =>
@error __("Fail to upload: {0}", e.stack)
when "#{@name}-share"
me = @
return unless file and file.type is "file"
file.path.asFileHandle().publish()
.then (r) ->
return me.error __("Cannot share file: {0}", r.error) if r.error
return me.notify __("Shared url: {0}", r.result)
.catch (e) ->
me.error __("Fail to publish: {0}", e.stack)
.then (r) =>
return @error __("Cannot share file: {0}", r.error) if r.error
return @notify __("Shared url: {0}", r.result)
.catch (e) =>
@error __("Fail to publish: {0}", e.stack)
when "#{@name}-download"
return unless file.type is "file"
file.path.asFileHandle().download()
.catch (e) ->
me.error __("Fail to download: {0}", e.stack)
.catch (e) =>
@error __("Fail to download: {0}", e.stack)
else
console.log e

View File

@ -19,53 +19,52 @@
class AppearanceHandle extends SettingHandle
constructor:(scheme, parent) ->
super(scheme, parent)
me = @
@wplist = @find "wplist"
@wpreview = @find "wp-preview"
@wpsize = @find "wpsize"
@wprepeat = @find "wprepeat"
@themelist = @find "theme-list"
@syswp = undefined
@wplist.set "onlistselect", (e) ->
@wplist.set "onlistselect", (e) =>
data = e.data.item.get("data")
$(me.wpreview)
$(@wpreview)
.css("background-image", "url(#{data.path.asFileHandle().getlink()})" )
.css("background-size", "cover")
me.parent.systemsetting.appearance.wp.url = data.path
me.parent._gui.wallpaper()
@parent.systemsetting.appearance.wp.url = data.path
@parent._gui.wallpaper()
@wplist.set "buttons", [
{
text: "+", onbtclick: (e) ->
me.parent.openDialog("FileDialog", {
text: "+", onbtclick: (e) =>
@parent.openDialog("FileDialog", {
title: __("Select image file"),
mimes: ["image/.*"]
}).then (d) ->
me.parent.systemsetting.appearance.wps.push d.file.path
me.wplist.set "data", me.getwplist()
}).then (d) =>
@parent.systemsetting.appearance.wps.push d.file.path
@wplist.set "data", @getwplist()
}
]
@wpsize.set "onlistselect", (e) ->
me.parent.systemsetting.appearance.wp.size = e.data.item.get("data").text
me.parent._gui.wallpaper()
@wpsize.set "onlistselect", (e) =>
@parent.systemsetting.appearance.wp.size = e.data.item.get("data").text
@parent._gui.wallpaper()
sizes = [
{ text: "cover", selected: me.parent.systemsetting.appearance.wp.size is "cover" },
{ text: "auto", selected: me.parent.systemsetting.appearance.wp.size is "auto" },
{ text: "contain", selected: me.parent.systemsetting.appearance.wp.size is "contain" }
{ text: "cover", selected: @parent.systemsetting.appearance.wp.size is "cover" },
{ text: "auto", selected: @parent.systemsetting.appearance.wp.size is "auto" },
{ text: "contain", selected: @parent.systemsetting.appearance.wp.size is "contain" }
]
@wpsize.set "data", sizes
repeats = [
{ text: "repeat", selected: me.parent.systemsetting.appearance.wp.repeat is "repeat" },
{ text: "repeat-x", selected: me.parent.systemsetting.appearance.wp.repeat is "repeat-x" },
{ text: "repeat-y", selected: me.parent.systemsetting.appearance.wp.repeat is "repeat-y" },
{ text: "no-repeat", selected: me.parent.systemsetting.appearance.wp.repeat is "no-repeat" }
{ text: "repeat", selected: @parent.systemsetting.appearance.wp.repeat is "repeat" },
{ text: "repeat-x", selected: @parent.systemsetting.appearance.wp.repeat is "repeat-x" },
{ text: "repeat-y", selected: @parent.systemsetting.appearance.wp.repeat is "repeat-y" },
{ text: "no-repeat", selected: @parent.systemsetting.appearance.wp.repeat is "no-repeat" }
]
@wprepeat.set "onlistselect", (e) ->
me.parent.systemsetting.appearance.wp.repeat = e.data.item.get("data").text
me.parent._gui.wallpaper()
@wprepeat.set "onlistselect", (e) =>
@parent.systemsetting.appearance.wp.repeat = e.data.item.get("data").text
@parent._gui.wallpaper()
@wprepeat.set "data", repeats
@themelist.set "data" , [{ text: "antos", selected: true }]
@ -73,17 +72,17 @@ class AppearanceHandle extends SettingHandle
if not @syswp
path = "os://resources/themes/system/wp"
path.asFileHandle().read()
.then (d) ->
return me.parent.error __("Cannot read wallpaper list from {0}", path) if d.error
.then (d) =>
return @parent.error __("Cannot read wallpaper list from {0}", path) if d.error
for v in d.result
v.text = v.filename
v.iconclass = "fa fa-file-image-o"
me.syswp = d.result
me.wplist.set "data", me.getwplist()
.catch (e) -> me.parent.error e.stack
@syswp = d.result
@wplist.set "data", @getwplist()
.catch (e) => @parent.error e.stack
else
me.wplist.set "data", me.getwplist()
@wplist.set "data", @getwplist()
getwplist: () ->
list = []

View File

@ -19,21 +19,20 @@
class LocaleHandle extends SettingHandle
constructor: (scheme, parent) ->
super(scheme, parent)
me = @
@lglist = @find "lglist"
@localelist = undefined
@lglist.set "onlistselect", (e) ->
me.parent._api.setLocale e.data.item.get("data").text
@lglist.set "onlistselect", (e) =>
@parent._api.setLocale e.data.item.get("data").text
if not @localelist
path = "os://resources/languages"
path.asFileHandle().read()
.then (d) ->
return me.parent.error __("Cannot fetch system locales: {0}", d.error) if d.derror
.then (d) =>
return @parent.error __("Cannot fetch system locales: {0}", d.error) if d.derror
for v in d.result
v.text = v.filename.replace /\.json$/g, ""
v.selected = v.text is me.parent.systemsetting.system.locale
me.localelist = d.result
me.lglist.set "data", me.localelist
.catch (e) -> me.parent.error e.stack
v.selected = v.text is @parent.systemsetting.system.locale
@localelist = d.result
@lglist.set "data", @localelist
.catch (e) => @parent.error e.stack
else
me.lglist.set "data", me.localelist
@lglist.set "data", @localelist

View File

@ -19,52 +19,51 @@
class StartupHandle extends SettingHandle
constructor: (scheme, parent) ->
super(scheme, parent)
me = @
@srvlist = @find "srvlist"
@applist = @find "applist"
@srvlist.set "buttons", [
{
text: "+", onbtclick: (e) ->
text: "+", onbtclick: (e) =>
services = []
for k, v of me.parent.systemsetting.system.packages
for k, v of @parent.systemsetting.system.packages
if v.services
srvs = ({ text: "#{k}/#{x}", iconclass: "fa fa-tasks" } for x in v.services)
services = services.concat srvs
me.parent.openDialog("SelectionDialog", {
@parent.openDialog("SelectionDialog", {
title: "__(Add service)",
data: services
}).then (d) ->
me.parent.systemsetting.system.startup.services.push d.text
me.refresh()
}).then (d) =>
@parent.systemsetting.system.startup.services.push d.text
@refresh()
},
{
text: "-", onbtclick: (e) ->
item = me.srvlist.get "selectedItem"
text: "-", onbtclick: (e) =>
item = @srvlist.get "selectedItem"
return unless item
selidx = $(item).index()
me.parent.systemsetting.system.startup.services.splice selidx, 1
me.refresh()
@parent.systemsetting.system.startup.services.splice selidx, 1
@refresh()
}
]
@applist.set "buttons", [
{
text: "+", onbtclick: (e) ->
apps = ( { text: k, iconclass: v.iconclass } for k, v of me.parent.systemsetting.system.packages )
me.parent.openDialog("SelectionDialog", {
text: "+", onbtclick: (e) =>
apps = ( { text: k, iconclass: v.iconclass } for k, v of @parent.systemsetting.system.packages )
@parent.openDialog("SelectionDialog", {
title: "__(Add application)",
data: apps
}).then (d) ->
me.parent.systemsetting.system.startup.apps.push d.text
me.refresh()
}).then (d) =>
@parent.systemsetting.system.startup.apps.push d.text
@refresh()
},
{
text: "-", onbtclick: (e) ->
item = me.applist.get "selectedItem"
text: "-", onbtclick: (e) =>
item = @applist.get "selectedItem"
return unless item
selidx = $(item).index()
me.parent.systemsetting.system.startup.apps.splice selidx, 1
me.refresh()
@parent.systemsetting.system.startup.apps.splice selidx, 1
@refresh()
}
]
@refresh()
@ -72,30 +71,3 @@ class StartupHandle extends SettingHandle
refresh: () ->
@srvlist.set "data", ( { text:v } for v in @parent.systemsetting.system.startup.services )
@applist.set "data", ( { text:v } for v in @parent.systemsetting.system.startup.apps )
mkdialog: () ->
return @parent._gui.mkdialog {
name: "StartupDialog",
layout: {
tags: [
{ tag: "afx-list-view" }
],
width: 250,
height: 200,
resizable: false,
buttons: [
{
label: "__(Ok)", onclick: (d) ->
sel = (d.find "content0").get "selected"
return d.error __("Please select an entry") unless sel
d.handler(sel.text) if d.handler
d.quit()
},
{ label: "__(Cancel)", onclick: (d) -> d.quit() }
],
filldata: (dia) ->
(dia.find "content0").set "items", dia.data if dia.data
}
}

View File

@ -21,28 +21,27 @@ class VFSSettingDialog extends this.OS.GUI.BasicDialog
super "VFSSettingDialog", VFSSettingDialog.scheme
init: () ->
me = @
$(@find("txtPath")).click (e) ->
me.openDialog("FileDialog", {
$(@find("txtPath")).click (e) =>
@openDialog("FileDialog", {
title: "__(Select a directory)",
mimes: ["dir"],
hidden: true
})
.then (d) ->
(me.find "txtPath").value = d.file.path
.then (d) =>
(@find "txtPath").value = d.file.path
@find("btnOk").set "onbtclick", (e) ->
@find("btnOk").set "onbtclick", (e) =>
data = {
path: (me.find "txtPath").value,
name: (me.find "txtName").value
path: (@find "txtPath").value,
name: (@find "txtName").value
}
return me.error __("Please enter mount point name") unless data.name and data.name isnt ""
return me .error __("Please select a directory") unless data.path and data.path isnt ""
me.handle(data) if me.handle
me.quit()
return @error __("Please enter mount point name") unless data.name and data.name isnt ""
return @error __("Please select a directory") unless data.path and data.path isnt ""
@handle(data) if @handle
@quit()
(@find "btnCancel").set "onbtclick", (e) ->
me.quit()
(@find "btnCancel").set "onbtclick", (e) =>
@quit()
return unless @data
(@find "txtName").value = @data.text if @data.text
@ -76,75 +75,73 @@ VFSSettingDialog.scheme = """
class VFSHandle extends SettingHandle
constructor: (scheme, parent) ->
super(scheme, parent)
me = @
@mplist = @find "mplist"
@dpath = @find "dpath"
@ppath = @find "ppath"
@mplist.set "buttons", [
{
text: "+",
onbtclick: (e) ->
me.parent.openDialog(new VFSSettingDialog(), {
onbtclick: (e) =>
@parent.openDialog(new VFSSettingDialog(), {
title: "__(Add mount point)"
})
.then (d) ->
me.parent.systemsetting.VFS.mountpoints.push {
.then (d) =>
@parent.systemsetting.VFS.mountpoints.push {
text: d.name, path: d.path, iconclass: "fa fa-folder", type: "fs"
}
me.refresh()
@refresh()
},
{
text: "-",
onbtclick: (e) ->
item = me.mplist.get "selectedItem"
onbtclick: (e) =>
item = @mplist.get "selectedItem"
return unless item
selidx = $(item).index()
me.parent.openDialog("YesNoDialog", {
@parent.openDialog("YesNoDialog", {
title: "__(Remove)",
text: __("Remove: {0}?", item.get("data").text)
}).then (d) ->
}).then (d) =>
return unless d
me.parent.systemsetting.VFS.mountpoints.splice selidx, 1
me.refresh()
@parent.systemsetting.VFS.mountpoints.splice selidx, 1
@refresh()
},
{
text: "",
iconclass: "fa fa-pencil",
onbtclick: (e) ->
sel = me.mplist.get "selectedItem"
onbtclick: (e) =>
sel = @mplist.get "selectedItem"
return unless sel
me.parent.openDialog(new VFSSettingDialog(), {
@parent.openDialog(new VFSSettingDialog(), {
title: "__(Edit mount point)",
text: sel.get("data").text,
path: sel.get("data").path
}).then (d) ->
}).then (d) =>
sel.get("data").text = d.name
sel.get("data").path = d.path
me.refresh()
@refresh()
}
]
(@find "btndpath").set 'onbtclick', (e) ->
me.parent.openDialog("FileDialog", {
(@find "btndpath").set 'onbtclick', (e) =>
@parent.openDialog("FileDialog", {
title: "__(Select a directory)",
mimes: ["dir"],
hidden: true
}).then (d) ->
me.parent.systemsetting.desktop.path = d.file.path
me.parent._gui.refreshDesktop()
me.refresh()
}).then (d) =>
@parent.systemsetting.desktop.path = d.file.path
@parent._gui.refreshDesktop()
@refresh()
(@find "btnppath").set 'onbtclick', (e) ->
me.parent.openDialog("FileDialog", {
(@find "btnppath").set 'onbtclick', (e) =>
@parent.openDialog("FileDialog", {
title: "__(Select a directory)",
mimes: ["dir"],
hidden: true
}).then (d) ->
me.parent.systemsetting.system.pkgpaths.user = d.file.path
me.refresh()
me.refresh()
}).then (d) =>
@parent.systemsetting.system.pkgpaths.user = d.file.path
@refresh()
@refresh()
refresh: () ->
me = @
@mplist.set "data", @parent.systemsetting.VFS.mountpoints
@dpath.set "text", @parent.systemsetting.desktop.path
@ppath.set "text", @parent.systemsetting.system.pkgpaths.user

View File

@ -28,7 +28,6 @@ class Setting extends this.OS.GUI.BaseApplication
super "Setting", args
main: () ->
me = @
@container = @find "container"
new AppearanceHandle @find("appearance"), @
@ -36,12 +35,12 @@ class Setting extends this.OS.GUI.BaseApplication
new LocaleHandle @find("locale"), @
new StartupHandle @find("startup"), @
(@find "btnsave").set "onbtclick", (e) ->
me._api.setting()
.then (d) ->
return me.error __("Cannot save system setting: {0}", d.error) if d.error
me.notify __("System setting saved")
.catch (e) ->
me.error __("Cannot save system setting: {0}", e.stack)
(@find "btnsave").set "onbtclick", (e) =>
@_api.setting()
.then (d) =>
return @error __("Cannot save system setting: {0}", d.error) if d.error
@notify __("System setting saved")
.catch (e) =>
@error __("Cannot save system setting: {0}", e.stack)
Setting.singleton = true
this.OS.register "Setting", Setting

View File

@ -4,17 +4,16 @@ class ShowCase extends this.OS.GUI.BaseApplication
super "ShowCase", args
main: () ->
me = @
bt = @find 'bttest'
bt.set "onbtclick", (e) ->
me.notify "btclicked"
bt.set "onbtclick", (e) =>
@notify "btclicked"
@observable.on "btclick", (e) ->
me.notify "button clicked"
@observable.on "btclick", (e) =>
@notify "button clicked"
@observable.on "menuselect", (e) ->
me.notify e.id
@observable.on "menuselect", (e) =>
@notify e.id
list = @find 'list'
@ -27,28 +26,28 @@ class ShowCase extends this.OS.GUI.BaseApplication
{ text: "some thing 5" }
]
list.unshift { text: "shifted el" }
list.set "onlistselect", (e) -> me.notify(e.data.items)
list.set "onlistselect", (e) => @notify(e.data.items)
sw = @find 'switch'
sw.set "onchange", (e) ->
me.notify e.data
sw.set "onchange", (e) =>
@notify e.data
spin = @find 'spin'
spin.set "onchange", (e) ->
me.notify e.data
spin.set "onchange", (e) =>
@notify e.data
menu = @find 'menu'
menu.set "items", @menu()
list.contextmenuHandle = (e, m) ->
m.set "items", me.menu()
list.contextmenuHandle = (e, m) =>
m.set "items", @menu()
m.show e
grid = @find 'grid'
grid.set "oncelldbclick", (e) ->
me.notify "on dbclick", e
grid.set "onrowselect", (e) ->
me.notify "on rowselect", e.data.items
grid.set "oncelldbclick", (e) =>
@notify "on dbclick", e
grid.set "onrowselect", (e) =>
@notify "on rowselect", e.data.items
@observable.on "cellselect", (e) ->
console.log "observable", e
@ -99,30 +98,30 @@ class ShowCase extends this.OS.GUI.BaseApplication
tree = @find 'tree'
tree.set "data", tdata
tree.set "ontreeselect", (e) ->
me.notify e.data.item.get "treepath"
tree.set "ontreedbclick", (e) ->
me.notify "treedbclick", e
@observable.on "treedbclick", (e) ->
me.notify "observable treedbclick", e
tree.set "ontreeselect", (e) =>
@notify e.data.item.get "treepath"
tree.set "ontreedbclick", (e) =>
@notify "treedbclick", e
@observable.on "treedbclick", (e) =>
@notify "observable treedbclick", e
slider = @find 'slider'
slider.set "onchange", (v) ->
me.notify v
slider.set "onchange", (v) =>
@notify v
cal = @find 'cal'
cal.set "ondateselect", (e) ->
me.notify e
cal.set "ondateselect", (e) =>
@notify e
pk = @find 'cpk'
pk.set "oncolorselect", (e) ->
me.notify e
pk.set "oncolorselect", (e) ->
me.notify e
pk.set "oncolorselect", (e) =>
@notify e
pk.set "oncolorselect", (e) =>
@notify e
fileview = @find 'fileview'
fileview.set "fetch", (path) ->
new Promise (resolve, reject) ->
fileview.set "fetch", (path) =>
new Promise (resolve, reject) =>
dir = path.asFileHandle()
dir.read().then (d) ->
p = dir.parent().asFileHandle()
@ -139,8 +138,8 @@ class ShowCase extends this.OS.GUI.BaseApplication
{ text: "list" },
{ text: "tree" }
]
viewoption.set "onlistselect", (e) ->
me.notify e.data.item.get("data").text
viewoption.set "onlistselect", (e) =>
@notify e.data.item.get("data").text
fileview.set "view", e.data.item.get("data").text
dllist = @find "dialoglist"
@ -157,30 +156,30 @@ class ShowCase extends this.OS.GUI.BaseApplication
{ text: "File dialog", id: "file" }
]
btrun.set "onbtclick", (e) ->
btrun.set "onbtclick", (e) =>
item = dllist.get "selectedItem"
return unless item
switch item.get("data").id
when "prompt"
me.openDialog("PromptDialog", {
@openDialog("PromptDialog", {
title: "Prompt review",
value: "txt data",
label: "enter value"
})
.then (d) ->
me.notify d
.then (d) =>
@notify d
when "calendar"
me.openDialog("CalendarDialog", {
@openDialog("CalendarDialog", {
title: "Calendar"
})
.then (d) ->
me.notify d
.then (d) =>
@notify d
when "colorpicker"
me.openDialog("ColorPickerDialog")
.then (d) ->
me.notify d
@openDialog("ColorPickerDialog")
.then (d) =>
@notify d
when "info"
me.openDialog("InfoDialog", {
@openDialog("InfoDialog", {
title: "Info application",
name: "Show case",
date: "10/12/2014",
@ -188,14 +187,14 @@ class ShowCase extends this.OS.GUI.BaseApplication
})
.then (d) ->
when "yesno"
me.openDialog("YesNoDialog", {
@openDialog("YesNoDialog", {
title: "Question ?",
text: "Do you realy want to delete file ?"
})
.then (d) ->
me.notify d
.then (d) =>
@notify d
when "selection"
me.openDialog("SelectionDialog", {
@openDialog("SelectionDialog", {
title: "Select data ?",
data: [
{ text: "Option 1" },
@ -203,27 +202,26 @@ class ShowCase extends this.OS.GUI.BaseApplication
{ text: "Option 3", iconclass: "fa fa-camera-retro fa-lg" }
]
})
.then (d) ->
me.notify d.text
.then (d) =>
@notify d.text
when "about"
me.openDialog("AboutDialog" )
.then (d) ->
@openDialog("AboutDialog" )
.then (d) =>
when "file"
me.openDialog("FileDialog", {
@openDialog("FileDialog", {
title: "Select file ?",
#root: "home:///",
mimes: ["text/*", "dir"],
file: "Untitled".asFileHandle()
})
.then (f, name) ->
me.notify f, name
.then (f, name) =>
@notify f, name
else return
mnFile: () ->
#me.notify file
me = @
#@notify file
arr = {
text: "__(File)",
child: [
@ -234,11 +232,11 @@ class ShowCase extends this.OS.GUI.BaseApplication
{ text: "__(Download)", dataid: "#{@name}-download" },
{ text: "__(Share file)", dataid: "#{@name}-share", shortcut: 'C-S' },
{ text: "__(Properties)", dataid: "#{@name}-info", shortcut: 'C-I' }
], onchildselect: (e) -> me.notify "child", e
], onchildselect: (e) => @notify "child", e
}
return arr
mnEdit: () ->
me = @
{
text: "__(Edit)",
child: [
@ -247,11 +245,10 @@ class ShowCase extends this.OS.GUI.BaseApplication
{ text: "__(Cut)", dataid: "#{@name}-cut", shortcut: 'C-X' },
{ text: "__(Copy)", dataid: "#{@name}-copy", shortcut: 'C-C' },
{ text: "__(Paste)", dataid: "#{@name}-paste", shortcut: 'C-P' }
], onchildselect: (e) -> console.log "child", e
], onchildselect: (e) => console.log "child", e
}
menu: () ->
me = @
menu = [
@mnFile(),
@mnEdit(),
@ -268,7 +265,7 @@ class ShowCase extends this.OS.GUI.BaseApplication
{ text: "__(Tree view)", radio:true, checked: false, dataid: "#{@name}-tree", type: 'tree' }
], onchildselect: (e) -> console.log "child", e
},
], onchildselect: (e) -> console.log "child", e
], onchildselect: (e) => console.log "child", e
},
]
menu