mirror of
https://github.com/lxsang/antos-frontend.git
synced 2024-11-16 17:48:21 +01:00
finish CodePad
This commit is contained in:
parent
74534e976c
commit
e20ee262fc
@ -271,11 +271,13 @@ class SelectionDialog extends BasicDialog
|
|||||||
super.init()
|
super.init()
|
||||||
me = @
|
me = @
|
||||||
(@find "list").set "data", @data.data if @data and @data.data
|
(@find "list").set "data", @data.data if @data and @data.data
|
||||||
(@find "btnOk").set "onbtclick", (e) ->
|
fn = (e) ->
|
||||||
data = (me.find "list").get "selectedItem"
|
data = (me.find "list").get "selectedItem"
|
||||||
return me.notify __("Please select an item") unless data
|
return me.notify __("Please select an item") unless data
|
||||||
me.handle(data.get("data")) if me.handle
|
me.handle(data.get("data")) if me.handle
|
||||||
me.quit()
|
me.quit()
|
||||||
|
(@find "list").set "onlistdbclick", fn
|
||||||
|
(@find "btnOk").set "onbtclick", fn
|
||||||
|
|
||||||
(@find "btnCancel").set "onbtclick", (e) ->
|
(@find "btnCancel").set "onbtclick", (e) ->
|
||||||
me.quit()
|
me.quit()
|
||||||
@ -384,7 +386,8 @@ class FileDialog extends BasicDialog
|
|||||||
(@find "bt-ok").set "onbtclick", (e) ->
|
(@find "bt-ok").set "onbtclick", (e) ->
|
||||||
f = fileview.get "selectedFile"
|
f = fileview.get "selectedFile"
|
||||||
return me.notify __("Please select a file/fofler") unless f
|
return me.notify __("Please select a file/fofler") unless f
|
||||||
return me.notify __("Please select {0} only", me.data.type) if me.data and me.data.type and me.data.type isnt f.type
|
if me.data and me.data.type and me.data.type isnt f.type
|
||||||
|
return me.notify __("Please select {0} only", me.data.type)
|
||||||
if me.data and me.data.mimes
|
if me.data and me.data.mimes
|
||||||
#verify the mime
|
#verify the mime
|
||||||
m = false
|
m = false
|
||||||
|
@ -295,28 +295,31 @@ Ant.OS.API =
|
|||||||
requires: (l) ->
|
requires: (l) ->
|
||||||
new Promise (resolve, reject) ->
|
new Promise (resolve, reject) ->
|
||||||
if not Ant.OS.API.shared[l]
|
if not Ant.OS.API.shared[l]
|
||||||
link = l
|
libfp = l.asFileHandle()
|
||||||
if not l.match /^(https?:\/\/[^\s]+)/g
|
switch libfp.ext
|
||||||
path = "os://scripts/"
|
when "css"
|
||||||
cssFile = "#{path}#{l}.css".asFileHandle()
|
libfp.onready()
|
||||||
cssFile.onready()
|
.then () ->
|
||||||
|
$('<link>', {
|
||||||
|
rel: 'stylesheet',
|
||||||
|
type: 'text/css',
|
||||||
|
'href': "#{libfp.getlink()}"
|
||||||
|
})
|
||||||
|
.appendTo 'head'
|
||||||
|
Ant.OS.API.shared[l] = true
|
||||||
|
console.log "loaded css:", l
|
||||||
|
Ant.OS.announcer.trigger "sharedlibraryloaded", l
|
||||||
|
.catch (e) -> reject e
|
||||||
|
when "js"
|
||||||
|
Ant.OS.API.script libfp.getlink()
|
||||||
.then () ->
|
.then () ->
|
||||||
$('<link>', {
|
Ant.OS.API.shared[l] = true
|
||||||
rel: 'stylesheet',
|
console.log "loaded javascript:", l
|
||||||
type: 'text/css',
|
Ant.OS.announcer.trigger "sharedlibraryloaded", l
|
||||||
'href': "#{cssFile.getlink()}"
|
resolve(l)
|
||||||
})
|
|
||||||
.appendTo 'head'
|
|
||||||
.catch (e) ->
|
.catch (e) ->
|
||||||
js = "#{path}#{l}.js"
|
reject e
|
||||||
link = js.asFileHandle().getlink()
|
else
|
||||||
Ant.OS.API.script link
|
|
||||||
.then () ->
|
|
||||||
Ant.OS.API.shared[l] = true
|
|
||||||
console.log "loaded:", l
|
|
||||||
Ant.OS.announcer.trigger "sharedlibraryloaded", l
|
|
||||||
resolve(l)
|
|
||||||
.catch (e) ->
|
|
||||||
reject e
|
reject e
|
||||||
else
|
else
|
||||||
console.log l, "Library exist, no need to load"
|
console.log l, "Library exist, no need to load"
|
||||||
|
@ -119,9 +119,11 @@ Ant.OS.GUI =
|
|||||||
return Ant.OS.announcer.osinfo __("No application available to open {0}", it.filename) if apps.length is 0
|
return Ant.OS.announcer.osinfo __("No application available to open {0}", it.filename) if apps.length is 0
|
||||||
return Ant.OS.GUI.launch apps[0].app, [it.path] if apps.length is 1
|
return Ant.OS.GUI.launch apps[0].app, [it.path] if apps.length is 1
|
||||||
list = ( { text: e.app, icon: e.icon, iconclass: e.iconclass } for e in apps )
|
list = ( { text: e.app, icon: e.icon, iconclass: e.iconclass } for e in apps )
|
||||||
Ant.OS.GUI.openDialog "SelectionDialog", ( d ) ->
|
Ant.OS.GUI.openDialog("SelectionDialog", {
|
||||||
Ant.OS.GUI.launch d.text, [it.path]
|
title: __("Open with"),
|
||||||
, __("Open with"), list
|
data: list
|
||||||
|
}).then ( d ) ->
|
||||||
|
Ant.OS.GUI.launch d.text, [ { path: it.path, type: it.type }]
|
||||||
|
|
||||||
forceLaunch: (app, args) ->
|
forceLaunch: (app, args) ->
|
||||||
console.warn "This method is used for developing only, please use the launch method instead"
|
console.warn "This method is used for developing only, please use the launch method instead"
|
||||||
@ -377,6 +379,7 @@ Ant.OS.GUI =
|
|||||||
return Ant.OS.GUI.openWith it.get("data") if it
|
return Ant.OS.GUI.openWith it.get("data") if it
|
||||||
it = Ant.OS.setting.desktop.path.asFileHandle()
|
it = Ant.OS.setting.desktop.path.asFileHandle()
|
||||||
it.mime = "dir"
|
it.mime = "dir"
|
||||||
|
it.type = "dir"
|
||||||
Ant.OS.GUI.openWith it
|
Ant.OS.GUI.openWith it
|
||||||
when "desktop-refresh"
|
when "desktop-refresh"
|
||||||
desktop[0].fetch()
|
desktop[0].fetch()
|
||||||
|
@ -9,6 +9,7 @@ class FileViewTag extends Ant.OS.GUI.BaseTag
|
|||||||
@setopt "showhidden", false
|
@setopt "showhidden", false
|
||||||
@setopt "fetch", undefined
|
@setopt "fetch", undefined
|
||||||
@setopt "path", undefined
|
@setopt "path", undefined
|
||||||
|
@setopt "chdir", true
|
||||||
@setopt "view", "list"
|
@setopt "view", "list"
|
||||||
@preventUpdate = false
|
@preventUpdate = false
|
||||||
@header = [
|
@header = [
|
||||||
@ -150,6 +151,9 @@ class FileViewTag extends Ant.OS.GUI.BaseTag
|
|||||||
@refs.status.set("text", " ") if @get "status"
|
@refs.status.set("text", " ") if @get "status"
|
||||||
|
|
||||||
fileselect: (e) ->
|
fileselect: (e) ->
|
||||||
|
if e.path is @get "path"
|
||||||
|
e.type = "dir"
|
||||||
|
e.mime = "dir"
|
||||||
if @get "status"
|
if @get "status"
|
||||||
@refs.status.set "text", __(
|
@refs.status.set "text", __(
|
||||||
"Selected: {0} ({1} bytes)",
|
"Selected: {0} ({1} bytes)",
|
||||||
@ -161,7 +165,10 @@ class FileViewTag extends Ant.OS.GUI.BaseTag
|
|||||||
@observable.trigger "fileselect", evt
|
@observable.trigger "fileselect", evt
|
||||||
|
|
||||||
filedbclick: (e) ->
|
filedbclick: (e) ->
|
||||||
if e.type is "dir"
|
if e.path is @get "path"
|
||||||
|
e.type = "dir"
|
||||||
|
e.mime = "dir"
|
||||||
|
if e.type is "dir" and @get "chdir"
|
||||||
@set "path", e.path
|
@set "path", e.path
|
||||||
else
|
else
|
||||||
evt = { id: @aid(), data: e }
|
evt = { id: @aid(), data: e }
|
||||||
|
@ -60,6 +60,9 @@ class SimpleListItemTag extends ListViewItemTag
|
|||||||
@set "selected", v.selected if v.selected
|
@set "selected", v.selected if v.selected
|
||||||
@set "closable", v.closable if v.closable
|
@set "closable", v.closable if v.closable
|
||||||
|
|
||||||
|
update: () ->
|
||||||
|
@set "data", @get("data")
|
||||||
|
|
||||||
itemlayout: () ->
|
itemlayout: () ->
|
||||||
{ el: "afx-label", ref: "label" }
|
{ el: "afx-label", ref: "label" }
|
||||||
|
|
||||||
|
@ -3,9 +3,13 @@ class TabBarTag extends Ant.OS.GUI.BaseTag
|
|||||||
super r, o
|
super r, o
|
||||||
@setopt "closable", false
|
@setopt "closable", false
|
||||||
@setopt "ontabselect", (e) ->
|
@setopt "ontabselect", (e) ->
|
||||||
|
@setopt "ontabclose", (e) ->
|
||||||
@setopt "items", []
|
@setopt "items", []
|
||||||
|
@setopt "selected", -1
|
||||||
me = @
|
me = @
|
||||||
@root.push = (e) -> me.refs.list.push e
|
@root.push = (e) ->
|
||||||
|
e.closable = me.get "closable"
|
||||||
|
me.refs.list.push e
|
||||||
@root.remove = (e) -> me.refs.list.remove e
|
@root.remove = (e) -> me.refs.list.remove e
|
||||||
@root.unshift = (e) -> me.refs.list.unshift e
|
@root.unshift = (e) -> me.refs.list.unshift e
|
||||||
@refs.list.set "onlistselect", (e) ->
|
@refs.list.set "onlistselect", (e) ->
|
||||||
@ -13,14 +17,18 @@ class TabBarTag extends Ant.OS.GUI.BaseTag
|
|||||||
me.observable.trigger "tabselect", e
|
me.observable.trigger "tabselect", e
|
||||||
|
|
||||||
__items__: (v) ->
|
__items__: (v) ->
|
||||||
|
i.closable = @get "closable" for i in v
|
||||||
@refs.list.set "data", v
|
@refs.list.set "data", v
|
||||||
|
|
||||||
|
__selected__: (v) ->
|
||||||
|
@refs.list.set "selected", v
|
||||||
|
|
||||||
mount: () ->
|
mount: () ->
|
||||||
me = @
|
me = @
|
||||||
@root.push = (e) -> me.refs.list.push e
|
|
||||||
@root.unshift = (e) -> me.refs.list.unshift e
|
|
||||||
@root.remove = (e) -> me.refs.list.remove e
|
|
||||||
$(@refs.list).css "height", "100%"
|
$(@refs.list).css "height", "100%"
|
||||||
|
@refs.list.set "onitemclose", (e) ->
|
||||||
|
e.id = me.aid()
|
||||||
|
me.get("ontabclose") e
|
||||||
|
|
||||||
layout: () ->
|
layout: () ->
|
||||||
[{
|
[{
|
||||||
|
@ -1,19 +1,20 @@
|
|||||||
<afx-app-window apptitle="Code" width="600" height="400" data-id="notepad">
|
<afx-app-window apptitle="Code" width="600" height="400" data-id="codepad">
|
||||||
<afx-vbox>
|
<afx-vbox>
|
||||||
<afx-hbox>
|
<afx-hbox>
|
||||||
<afx-file-view data-width = "155" min-width="155" data-id = "fileview" view="tree" status = "false">
|
<afx-vbox data-width = "155" min-width="155" data-id = "sidebar">
|
||||||
</afx-file-view>
|
<div data-height="10"></div>
|
||||||
|
<afx-file-view chdir="false" data-id = "fileview" view="tree" status = "false">
|
||||||
|
</afx-file-view>
|
||||||
|
</afx-vbox>
|
||||||
<afx-resizer data-width = "3" ></afx-resizer>
|
<afx-resizer data-width = "3" ></afx-resizer>
|
||||||
<afx-vbox>
|
<afx-vbox>
|
||||||
<afx-tab-bar data-height="25" id = "tabbar"></afx-tab-bar>
|
<afx-tab-bar closable="true" data-height="27" data-id = "tabbar"></afx-tab-bar>
|
||||||
<div data-id="datarea"></div>
|
<div data-id="datarea"></div>
|
||||||
</afx-vbox>
|
</afx-vbox>
|
||||||
</afx-hbox>
|
</afx-hbox>
|
||||||
<afx-hbox data-height="20" data-id="bottom-hbox">
|
<div data-height="20" data-id="statctn">
|
||||||
<afx-label data-id="editorstat"></afx-label>
|
<afx-label data-id="langstat" ></afx-label>
|
||||||
<!-- <afx-list-view data-width="160" data-id = "themelist" dropdown = "true" width="135"></afx-list-view>
|
<afx-label data-id="editorstat" ></afx-label>
|
||||||
<afx-list-view data-width="125" data-id = "modelist" dropdown = "true" width="100"></afx-list-view>
|
</div>
|
||||||
-->
|
|
||||||
</afx-hbox>
|
|
||||||
</afx-vbox>
|
</afx-vbox>
|
||||||
</afx-app-window>
|
</afx-app-window>
|
@ -17,7 +17,7 @@ class CommandPalette extends this.OS.GUI.BasicDialog
|
|||||||
$(document).on "mousedown", cb
|
$(document).on "mousedown", cb
|
||||||
$(me.find "searchbox").focus()
|
$(me.find "searchbox").focus()
|
||||||
@cmdlist = @find("container")
|
@cmdlist = @find("container")
|
||||||
@cmdlist.set "data", @data if @data
|
@cmdlist.set "data", (v for v in @data.child) if @data
|
||||||
$(@cmdlist).click (e) ->
|
$(@cmdlist).click (e) ->
|
||||||
me.selectCommand()
|
me.selectCommand()
|
||||||
|
|
||||||
@ -27,6 +27,10 @@ class CommandPalette extends this.OS.GUI.BasicDialog
|
|||||||
|
|
||||||
search: (e) ->
|
search: (e) ->
|
||||||
switch e.which
|
switch e.which
|
||||||
|
when 27
|
||||||
|
# escape key
|
||||||
|
@quit()
|
||||||
|
@data.parent.run(@parent) if @data.parent and @data.parent.run
|
||||||
when 37
|
when 37
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
when 38
|
when 38
|
||||||
@ -42,20 +46,20 @@ class CommandPalette extends this.OS.GUI.BasicDialog
|
|||||||
@selectCommand()
|
@selectCommand()
|
||||||
else
|
else
|
||||||
text = @searchbox.value
|
text = @searchbox.value
|
||||||
@cmdlist.set "data", @data if text.length is 2
|
@cmdlist.set "data", (v for v in @data.child) if text.length is 2
|
||||||
return if text.length < 3
|
return if text.length < 3
|
||||||
result = []
|
result = []
|
||||||
term = new RegExp text, 'i'
|
term = new RegExp text, 'i'
|
||||||
result.push v for v in @data when v.text.match term
|
result.push v for v in @data.child when v.text.match term
|
||||||
@cmdlist.set "data", result
|
@cmdlist.set "data", result
|
||||||
|
|
||||||
|
|
||||||
selectCommand: () ->
|
selectCommand: () ->
|
||||||
el = @cmdlist.get "selectedItem"
|
el = @cmdlist.get "selectedItem"
|
||||||
return unless el
|
return unless el
|
||||||
@quit()
|
result = false
|
||||||
@handle { data: { item: el } } if @handle
|
result = @handle { data: { item: el } } if @handle
|
||||||
|
return @quit() unless result
|
||||||
|
|
||||||
CommandPalette.scheme = """
|
CommandPalette.scheme = """
|
||||||
<afx-app-window data-id = "cmd-win"
|
<afx-app-window data-id = "cmd-win"
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
class CMDMenu
|
class CMDMenu
|
||||||
constructor: (@text, @shortcut) ->
|
constructor: (@text, @shortcut) ->
|
||||||
@child = []
|
@child = []
|
||||||
|
@parent = undefined
|
||||||
@select = (e) ->
|
@select = (e) ->
|
||||||
|
|
||||||
addAction: (v) ->
|
addAction: (v) ->
|
||||||
|
v.parent = @
|
||||||
@child.push v
|
@child.push v
|
||||||
@
|
@
|
||||||
|
|
||||||
@ -16,7 +18,7 @@ class CMDMenu
|
|||||||
|
|
||||||
run: (root) ->
|
run: (root) ->
|
||||||
me = @
|
me = @
|
||||||
root.openDialog(new CommandPalette(), @child)
|
root.openDialog(new CommandPalette(), @)
|
||||||
.then (d) ->
|
.then (d) ->
|
||||||
data = d.data.item.get("data")
|
data = d.data.item.get("data")
|
||||||
return data.run root if data.run
|
return data.run root if data.run
|
||||||
@ -35,10 +37,23 @@ CMDMenu.fromMenu = (mn) ->
|
|||||||
class CodePad extends this.OS.GUI.BaseApplication
|
class CodePad extends this.OS.GUI.BaseApplication
|
||||||
constructor: (args) ->
|
constructor: (args) ->
|
||||||
super "CodePad", args
|
super "CodePad", args
|
||||||
|
@currfile = "Untitled".asFileHandle()
|
||||||
|
@currdir = undefined
|
||||||
|
if @args and @args.length > 0
|
||||||
|
if @args[0].type is "dir"
|
||||||
|
@currdir = @args[0].path.asFileHandle()
|
||||||
|
else
|
||||||
|
@currfile = @args[0].path.asFileHandle()
|
||||||
|
@currdir = @currfile.parent()
|
||||||
|
|
||||||
main: () ->
|
main: () ->
|
||||||
me = @
|
me = @
|
||||||
@fileview = @find("fileview")
|
@fileview = @find("fileview")
|
||||||
|
@sidebar = @find("sidebar")
|
||||||
|
@tabbar = @find "tabbar"
|
||||||
|
@langstat = @find "langstat"
|
||||||
|
@editorstat = @find "editorstat"
|
||||||
|
|
||||||
@fileview.set "fetch", (path) ->
|
@fileview.set "fetch", (path) ->
|
||||||
new Promise (resolve, reject) ->
|
new Promise (resolve, reject) ->
|
||||||
dir = path
|
dir = path
|
||||||
@ -47,7 +62,6 @@ class CodePad extends this.OS.GUI.BaseApplication
|
|||||||
return reject d.error if d.error
|
return reject d.error if d.error
|
||||||
me.currdir = dir
|
me.currdir = dir
|
||||||
resolve d.result
|
resolve d.result
|
||||||
@fileview.set "path", "desktop://"
|
|
||||||
@setup()
|
@setup()
|
||||||
|
|
||||||
setup: () ->
|
setup: () ->
|
||||||
@ -61,12 +75,47 @@ class CodePad extends this.OS.GUI.BaseApplication
|
|||||||
enableLiveAutocompletion: true,
|
enableLiveAutocompletion: true,
|
||||||
highlightActiveLine: true,
|
highlightActiveLine: true,
|
||||||
useWrapMode: true,
|
useWrapMode: true,
|
||||||
fontSize: "9pt"
|
fontSize: "11pt"
|
||||||
}
|
}
|
||||||
#themes = ace.require "ace/ext/themelist"
|
#themes = ace.require "ace/ext/themelist"
|
||||||
@editor.setTheme "ace/theme/monokai"
|
@editor.setTheme "ace/theme/monokai"
|
||||||
|
@modes = ace.require "ace/ext/modelist"
|
||||||
@editor.completers.push { getCompletions: ( editor, session, pos, prefix, callback ) -> }
|
@editor.completers.push { getCompletions: ( editor, session, pos, prefix, callback ) -> }
|
||||||
@editor.getSession().setUseWrapMode true
|
@editor.getSession().setUseWrapMode true
|
||||||
|
@editormux = false
|
||||||
|
@editor.on "input", () ->
|
||||||
|
if me.editormux
|
||||||
|
me.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()
|
||||||
|
|
||||||
|
@tabbar.set "ontabselect", (e) ->
|
||||||
|
me.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", {
|
||||||
|
title: __("Close tab"),
|
||||||
|
text: __("Close without saving ?")
|
||||||
|
}).then (d) ->
|
||||||
|
return me.closeTab it if d
|
||||||
|
me.editor.focus()
|
||||||
|
return false
|
||||||
|
@fileview.set "onfileopen", (e) ->
|
||||||
|
return if e.data.type is "dir"
|
||||||
|
me.openFile e.data.path.asFileHandle()
|
||||||
|
|
||||||
|
@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
|
||||||
|
|
||||||
@on "resize", () -> me.editor.resize()
|
@on "resize", () -> me.editor.resize()
|
||||||
@on "focus", () -> me.editor.focus()
|
@on "focus", () -> me.editor.focus()
|
||||||
@spotlight = new CMDMenu __("Command palette")
|
@spotlight = new CMDMenu __("Command palette")
|
||||||
@ -78,8 +127,99 @@ class CodePad extends this.OS.GUI.BaseApplication
|
|||||||
me.spotlight.run me
|
me.spotlight.run me
|
||||||
}]
|
}]
|
||||||
m.show e
|
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"
|
||||||
|
|
||||||
@initCommandPalete()
|
@initCommandPalete()
|
||||||
@editor.resize()
|
@initSideBar()
|
||||||
|
@openFile @currfile
|
||||||
|
|
||||||
|
|
||||||
|
openFile: (file) ->
|
||||||
|
#find tab
|
||||||
|
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) ->
|
||||||
|
file.cache = d or ""
|
||||||
|
me.newTab file
|
||||||
|
.catch (e) ->
|
||||||
|
me.error __("Unable to open: {0}", file.path)
|
||||||
|
|
||||||
|
findTabByFile: (file) ->
|
||||||
|
lst = @tabbar.get "items"
|
||||||
|
its = ( i for d, i in lst when d.hash() is file.hash() )
|
||||||
|
return -1 if its.length is 0
|
||||||
|
return its[0]
|
||||||
|
|
||||||
|
newTab: (file) ->
|
||||||
|
file.text = if file.basename then file.basename else file.path
|
||||||
|
file.cache = "" unless file.cache
|
||||||
|
file.um = new ace.UndoManager()
|
||||||
|
@currfile.selected = false
|
||||||
|
file.selected = true
|
||||||
|
#console.log cnt
|
||||||
|
@tabbar.push file
|
||||||
|
|
||||||
|
closeTab: (it) ->
|
||||||
|
@tabbar.remove it
|
||||||
|
cnt = @tabbar.get("items").length
|
||||||
|
|
||||||
|
if cnt is 0
|
||||||
|
@openFile "Untitled".asFileHandle()
|
||||||
|
return false
|
||||||
|
@tabbar.set "selected", cnt - 1
|
||||||
|
return false
|
||||||
|
|
||||||
|
selecteTab: (i) ->
|
||||||
|
#return if i is @tabbar.get "selidx"
|
||||||
|
file = (@tabbar.get "items")[i]
|
||||||
|
return unless file
|
||||||
|
@scheme.set "apptitle", file.text.toString()
|
||||||
|
#return if file is @currfile
|
||||||
|
if @currfile isnt file
|
||||||
|
@currfile.cache = @editor.getValue()
|
||||||
|
@currfile.cursor = @editor.selection.getCursor()
|
||||||
|
@currfile.selected = false
|
||||||
|
@currfile = file
|
||||||
|
|
||||||
|
if not file.langmode
|
||||||
|
if file.path.toString() isnt "Untitled"
|
||||||
|
m = @modes.getModeForPath(file.path)
|
||||||
|
file.langmode = { caption: m.caption, mode: m.mode }
|
||||||
|
else
|
||||||
|
file.langmode = { caption: "Text", mode: "ace/mode/text" }
|
||||||
|
@editormux = true
|
||||||
|
@editor.setValue file.cache, -1
|
||||||
|
@editor.session.setMode file.langmode.mode
|
||||||
|
@editor.session.setUndoManager file.um
|
||||||
|
if file.cursor
|
||||||
|
@editor.renderer.scrollCursorIntoView {
|
||||||
|
row: file.cursor.row, column: file.cursor.column
|
||||||
|
}, 0.5
|
||||||
|
@editor.selection.moveTo file.cursor.row, file.cursor.column
|
||||||
|
@updateStatus()
|
||||||
|
@editor.focus()
|
||||||
|
|
||||||
|
updateStatus: () ->
|
||||||
|
c = @editor.session.selection.getCursor()
|
||||||
|
l = @editor.session.getLength()
|
||||||
|
@editorstat.set "text", __("Row {0}, col {1}, lines: {2}", c.row + 1, c.column + 1, l)
|
||||||
|
@langstat.set "text", @currfile.langmode.caption
|
||||||
|
|
||||||
|
initSideBar: () ->
|
||||||
|
if @currdir
|
||||||
|
$(@sidebar).show()
|
||||||
|
@fileview.set "path", @currdir.path
|
||||||
|
else
|
||||||
|
$(@sidebar).hide()
|
||||||
|
@trigger "resize"
|
||||||
|
|
||||||
addAction: (action) ->
|
addAction: (action) ->
|
||||||
@spotlight.addAction action
|
@spotlight.addAction action
|
||||||
@ -98,13 +238,13 @@ class CodePad extends this.OS.GUI.BaseApplication
|
|||||||
r.editor.setTheme data.theme
|
r.editor.setTheme data.theme
|
||||||
r.editor.focus()
|
r.editor.focus()
|
||||||
@spotlight.addAction cmdtheme
|
@spotlight.addAction cmdtheme
|
||||||
|
|
||||||
modes = ace.require "ace/ext/modelist"
|
|
||||||
cmdmode = new CMDMenu __("Change language mode")
|
cmdmode = new CMDMenu __("Change language mode")
|
||||||
cmdmode.addAction { text: v.name, mode: v.mode } for v in modes.modes
|
cmdmode.addAction { text: v.caption, mode: v.mode } for v in @modes.modes
|
||||||
cmdmode.onchildselect (d, r) ->
|
cmdmode.onchildselect (d, r) ->
|
||||||
data = d.data.item.get("data")
|
data = d.data.item.get("data")
|
||||||
r.editor.session.setMode data.mode
|
r.editor.session.setMode data.mode
|
||||||
|
r.currfile.langmode = { caption: data.text, mode: data.mode }
|
||||||
|
r.updateStatus()
|
||||||
r.editor.focus()
|
r.editor.focus()
|
||||||
@spotlight.addAction cmdmode
|
@spotlight.addAction cmdmode
|
||||||
@addAction CMDMenu.fromMenu @fileMenu()
|
@addAction CMDMenu.fromMenu @fileMenu()
|
||||||
@ -116,13 +256,83 @@ class CodePad extends this.OS.GUI.BaseApplication
|
|||||||
child: [
|
child: [
|
||||||
{ text: __("New"), dataid: "new", shortcut: "A-N" },
|
{ text: __("New"), dataid: "new", shortcut: "A-N" },
|
||||||
{ text: __("Open"), dataid: "open", shortcut: "A-O" },
|
{ text: __("Open"), dataid: "open", shortcut: "A-O" },
|
||||||
|
{ text: __("Open Folder"), dataid: "opendir", shortcut: "A-F" },
|
||||||
{ text: __("Save"), dataid: "save", shortcut: "C-S" },
|
{ text: __("Save"), dataid: "save", shortcut: "C-S" },
|
||||||
{ text: __("Save as"), dataid: "saveas", shortcut: "A-W" }
|
{ text: __("Save as"), dataid: "saveas", shortcut: "A-W" }
|
||||||
],
|
],
|
||||||
onchildselect: (e, r) ->
|
onchildselect: (e, r) ->
|
||||||
console.log e.data.item.get "data"
|
me.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
|
||||||
|
file.dirty = false
|
||||||
|
file.text = file.basename
|
||||||
|
me.tabbar.update()
|
||||||
|
me.scheme.set "apptitle", "#{me.currfile.basename}"
|
||||||
|
.catch (e) -> me.error e.stack
|
||||||
|
|
||||||
|
|
||||||
|
saveAs: () ->
|
||||||
|
me = @
|
||||||
|
me.openDialog("FileDialog", {
|
||||||
|
title: __("Save as"),
|
||||||
|
file: me.currfile
|
||||||
|
})
|
||||||
|
.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
|
||||||
|
|
||||||
|
menuAction: (dataid, r) ->
|
||||||
|
me = @
|
||||||
|
me = r if r
|
||||||
|
switch dataid
|
||||||
|
when "new"
|
||||||
|
me.openFile "Untitled".asFileHandle()
|
||||||
|
when "open"
|
||||||
|
me.openDialog("FileDialog", {
|
||||||
|
title: __("Open file"),
|
||||||
|
mimes: (v for v in me.meta().mimes when v isnt "dir")
|
||||||
|
})
|
||||||
|
.then (f) ->
|
||||||
|
me.openFile f.file.path.asFileHandle()
|
||||||
|
when "opendir"
|
||||||
|
me.openDialog("FileDialog", {
|
||||||
|
title: __("Open folder"),
|
||||||
|
mimes: ["dir"]
|
||||||
|
})
|
||||||
|
.then (f) ->
|
||||||
|
me.currdir = f.file.path.asFileHandle()
|
||||||
|
me.initSideBar()
|
||||||
|
when "save"
|
||||||
|
me.currfile.cache = me.editor.getValue()
|
||||||
|
return me.save me.currfile if me.currfile.basename
|
||||||
|
me.saveAs()
|
||||||
|
when "saveas"
|
||||||
|
me.currfile.cache = me.editor.getValue()
|
||||||
|
me.saveAs()
|
||||||
|
else
|
||||||
|
console.log dataid
|
||||||
|
|
||||||
|
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) ->
|
||||||
|
if d
|
||||||
|
v.dirty = false for v in dirties
|
||||||
|
me.quit()
|
||||||
|
|
||||||
menu: () ->
|
menu: () ->
|
||||||
me = @
|
me = @
|
||||||
@ -140,9 +350,9 @@ class CodePad extends this.OS.GUI.BaseApplication
|
|||||||
menu
|
menu
|
||||||
|
|
||||||
CodePad.dependencies = [
|
CodePad.dependencies = [
|
||||||
"ace/ace",
|
"os://scripts/ace/ace.js",
|
||||||
"ace/ext-language_tools",
|
"os://scripts/ace/ext-language_tools.js",
|
||||||
"ace/ext-modelist",
|
"os://scripts/ace/ext-modelist.js",
|
||||||
"ace/ext-themelist"
|
"os://scripts/ace/ext-themelist.js"
|
||||||
]
|
]
|
||||||
this.OS.register "CodePad", CodePad
|
this.OS.register "CodePad", CodePad
|
@ -1,36 +1,68 @@
|
|||||||
afx-app-window[data-id = "notepad"] .afx-window-wrapper afx-file-view{
|
afx-app-window[data-id = "codepad"] afx-tab-bar> afx-list-view > div.list-container
|
||||||
|
{
|
||||||
|
border-top: 1px solid #272822;
|
||||||
|
overflow: hidden;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
afx-app-window[data-id = "codepad"] afx-tab-bar> afx-list-view ul afx-list-item:nth-child(even) li.selected,
|
||||||
|
afx-app-window[data-id = "codepad"] afx-tab-bar> afx-list-view > div.list-container > ul > afx-list-item > li.selected{
|
||||||
|
background-color:#272822;
|
||||||
|
color:white;
|
||||||
|
border: 0;
|
||||||
|
border-radius: 0;
|
||||||
|
}
|
||||||
|
afx-app-window[data-id = "codepad"] afx-tab-bar> afx-list-view afx-list-view i.closable:before {
|
||||||
|
color:afafaf;
|
||||||
|
}
|
||||||
|
afx-app-window[data-id = "codepad"] afx-tab-bar> afx-list-view ul afx-list-item:nth-child(even) li,
|
||||||
|
afx-app-window[data-id = "codepad"] afx-tab-bar> afx-list-view > div.list-container > ul li{
|
||||||
|
background-color:#333333;
|
||||||
|
color:#afafaf;
|
||||||
|
border-radius: 0;
|
||||||
|
border: 0;
|
||||||
|
padding-top: 5px;
|
||||||
|
padding-bottom: 5px;
|
||||||
|
padding-right: 20px;
|
||||||
|
border-right: 1px solid #272822;
|
||||||
|
}
|
||||||
|
afx-app-window[data-id = "codepad"] .afx-window-wrapper afx-vbox[data-id = "sidebar"]{
|
||||||
background-color:#272822;
|
background-color:#272822;
|
||||||
}
|
}
|
||||||
afx-app-window[data-id = "notepad"] div.afx-window-content {
|
afx-app-window[data-id = "codepad"] div.afx-window-content {
|
||||||
background-color:#2d2d2d;
|
background-color:#333333;
|
||||||
}
|
}
|
||||||
afx-app-window[data-id = "notepad"] afx-resizer {
|
afx-app-window[data-id = "codepad"] afx-resizer {
|
||||||
background-color:#272822;
|
background-color:#272822;
|
||||||
border-right: 1px solid #37373d;
|
border-right: 1px solid #37373d;
|
||||||
}
|
}
|
||||||
afx-app-window[data-id = "notepad"] .afx-window-wrapper .treecontainer{
|
afx-app-window[data-id = "codepad"] .afx-window-wrapper afx-tree-view{
|
||||||
padding-top: 10px;
|
|
||||||
}
|
|
||||||
afx-app-window[data-id = "notepad"] .afx-window-wrapper afx-tree-view{
|
|
||||||
color: white;
|
color: white;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
afx-app-window[data-id = "notepad"] .afx-window-wrapper afx-tree-view afx-tree-view-item ul li{
|
afx-app-window[data-id = "codepad"] .afx-window-wrapper afx-tree-view afx-tree-view-item ul li{
|
||||||
padding-left: 10px;
|
padding-left: 10px;
|
||||||
}
|
}
|
||||||
afx-app-window[data-id = "notepad"] .afx-window-wrapper .afx_tree_item_selected ul{
|
afx-app-window[data-id = "codepad"] .afx-window-wrapper .afx_tree_item_selected ul{
|
||||||
background-color: #116cd6;
|
background-color: #116cd6;
|
||||||
}
|
}
|
||||||
|
|
||||||
afx-app-window[data-id = "notepad"] afx-file-view afx-tree-view .afx-tree-view-item:before{
|
afx-app-window[data-id = "codepad"] afx-file-view afx-tree-view .afx-tree-view-item:before{
|
||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
afx-app-window[data-id = "notepad"] .afx-window-wrapper afx-hbox[data-id="bottom-hbox"]{
|
afx-app-window[data-id = "codepad"] .afx-window-wrapper div[data-id="statctn"]{
|
||||||
color: white;
|
color: white;
|
||||||
background-color: #007acc;
|
background-color: #007acc;
|
||||||
|
padding-right: 10px;
|
||||||
|
padding-top: 5px;
|
||||||
|
font-size: 11px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
afx-app-window[data-id = "codepad"] .afx-window-wrapper div[data-id="statctn"] afx-label {
|
||||||
|
float: right;
|
||||||
|
padding-left: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
afx-app-window[data-id = "cmd-win"] .afx-window-wrapper{
|
afx-app-window[data-id = "cmd-win"] .afx-window-wrapper{
|
||||||
border-radius: 0px;
|
border-radius: 0px;
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
"text/.*",
|
"text/.*",
|
||||||
"[^/]*/json.*",
|
"[^/]*/json.*",
|
||||||
"[^/]*/.*ml",
|
"[^/]*/.*ml",
|
||||||
"[^/]*/javascript"
|
"[^/]*/javascript",
|
||||||
|
"dir"
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -78,7 +78,7 @@ class PushNotification extends this.OS.GUI.BaseService
|
|||||||
icon: o.data.icon,
|
icon: o.data.icon,
|
||||||
iconclass: o.data.iconclass,
|
iconclass: o.data.iconclass,
|
||||||
closable: true }
|
closable: true }
|
||||||
console.log o
|
console.log o.data.e
|
||||||
@mlist.unshift d
|
@mlist.unshift d
|
||||||
@notifeed d
|
@notifeed d
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ class Files extends this.OS.GUI.BaseApplication
|
|||||||
@navinput = @find "navinput"
|
@navinput = @find "navinput"
|
||||||
@navbar = @find "nav-bar"
|
@navbar = @find "nav-bar"
|
||||||
if @args and @args.length > 0
|
if @args and @args.length > 0
|
||||||
@currdir = @args[0].asFileHandle()
|
@currdir = @args[0].path.asFileHandle()
|
||||||
else
|
else
|
||||||
@currdir = "home://".asFileHandle()
|
@currdir = "home://".asFileHandle()
|
||||||
@favo = @find "favouri"
|
@favo = @find "favouri"
|
||||||
|
@ -26,7 +26,7 @@ class MarkOn extends this.OS.GUI.BaseApplication
|
|||||||
@container = @find "mycontainer"
|
@container = @find "mycontainer"
|
||||||
@previewOn = false
|
@previewOn = false
|
||||||
if @args and @args.length > 0
|
if @args and @args.length > 0
|
||||||
@currfile = @args[0].asFileHandle()
|
@currfile = @args[0].path.asFileHandle()
|
||||||
else
|
else
|
||||||
@currfile = "Untitled".asFileHandle()
|
@currfile = "Untitled".asFileHandle()
|
||||||
@editormux = false
|
@editormux = false
|
||||||
@ -165,6 +165,9 @@ class MarkOn extends this.OS.GUI.BaseApplication
|
|||||||
me.quit()
|
me.quit()
|
||||||
, __("Quit"), { text: __("Quit without saving ?") }
|
, __("Quit"), { text: __("Quit without saving ?") }
|
||||||
|
|
||||||
MarkOn.dependencies = [ "mde/simplemde.min" ]
|
MarkOn.dependencies = [
|
||||||
|
"os://scripts/mde/simplemde.min.js",
|
||||||
|
"os://scripts/mde/simplemde.min.css"
|
||||||
|
]
|
||||||
|
|
||||||
this.OS.register "MarkOn", MarkOn
|
this.OS.register "MarkOn", MarkOn
|
Loading…
Reference in New Issue
Block a user