mirror of
https://github.com/lxsang/antos-frontend.git
synced 2025-02-22 01:42:47 +01:00
add shortcut support to application
This commit is contained in:
parent
10dbe6ea99
commit
c1781d1741
@ -3,6 +3,11 @@ class BaseApplication extends this.OS.GUI.BaseModel
|
|||||||
super name, args
|
super name, args
|
||||||
_OS.setting.applications[@name] = {} if not _OS.setting.applications[@name]
|
_OS.setting.applications[@name] = {} if not _OS.setting.applications[@name]
|
||||||
@setting = _OS.setting.applications[@name]
|
@setting = _OS.setting.applications[@name]
|
||||||
|
@keycomb =
|
||||||
|
ALT: {}
|
||||||
|
CTRL: {}
|
||||||
|
SHIFT: {}
|
||||||
|
META: {}
|
||||||
init: ->
|
init: ->
|
||||||
me = @
|
me = @
|
||||||
# first register some base event to the app
|
# first register some base event to the app
|
||||||
@ -29,6 +34,20 @@ class BaseApplication extends this.OS.GUI.BaseModel
|
|||||||
path = "#{@meta().path}/scheme.html"
|
path = "#{@meta().path}/scheme.html"
|
||||||
@.render path
|
@.render path
|
||||||
|
|
||||||
|
bindKey: (k, f) ->
|
||||||
|
arr = k.split "-"
|
||||||
|
return unless arr.length is 2
|
||||||
|
fnk = arr[0].toUpperCase()
|
||||||
|
c = arr[1].toUpperCase()
|
||||||
|
return unless @keycomb[fnk]
|
||||||
|
@keycomb[fnk][c] = f
|
||||||
|
|
||||||
|
shortcut: (fnk, c) ->
|
||||||
|
return true unless @keycomb[fnk]
|
||||||
|
return true unless @keycomb[fnk][c]
|
||||||
|
@keycomb[fnk][c]()
|
||||||
|
return false
|
||||||
|
|
||||||
applySetting: (k) ->
|
applySetting: (k) ->
|
||||||
registry: (k, v) ->
|
registry: (k, v) ->
|
||||||
@setting[k] = v
|
@setting[k] = v
|
||||||
|
@ -183,6 +183,24 @@ self.OS.GUI =
|
|||||||
|
|
||||||
initDM: ->
|
initDM: ->
|
||||||
# check login first
|
# check login first
|
||||||
|
($ window).bind 'keydown', (event) ->
|
||||||
|
app = ($ "#sysdock")[0].get "selectedApp"
|
||||||
|
return true unless app
|
||||||
|
c = String.fromCharCode(event.which).toUpperCase()
|
||||||
|
fnk = undefined
|
||||||
|
if event.ctrlKey
|
||||||
|
fnk = "CTRL"
|
||||||
|
else if event.metaKey
|
||||||
|
fnk = "META"
|
||||||
|
else if event.shiftKey
|
||||||
|
fnk = "SHIFT"
|
||||||
|
else if event.altKey
|
||||||
|
fnk = "ALT"
|
||||||
|
|
||||||
|
return unless fnk
|
||||||
|
r = app.shortcut fnk, c
|
||||||
|
event.preventDefault() if not r
|
||||||
|
|
||||||
_API.resource "schemes/dm.html", (x) ->
|
_API.resource "schemes/dm.html", (x) ->
|
||||||
return null unless x
|
return null unless x
|
||||||
scheme = $.parseHTML x
|
scheme = $.parseHTML x
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
this.status = opts.status == undefined?true:opts.status
|
this.status = opts.status == undefined?true:opts.status
|
||||||
this.selectedFile = undefined
|
this.selectedFile = undefined
|
||||||
this.showhidden = opts.showhidden
|
this.showhidden = opts.showhidden
|
||||||
|
this.preventUpdate = false
|
||||||
this.fetch = opts.fetch
|
this.fetch = opts.fetch
|
||||||
this.chdir = opts.chdir
|
this.chdir = opts.chdir
|
||||||
this.rid = $(self.root).attr("data-id") || Math.floor(Math.random() * 100000) + 1
|
this.rid = $(self.root).attr("data-id") || Math.floor(Math.random() * 100000) + 1
|
||||||
@ -32,7 +33,8 @@
|
|||||||
switchView()
|
switchView()
|
||||||
if(k == "data")
|
if(k == "data")
|
||||||
self.selectedFile = undefined
|
self.selectedFile = undefined
|
||||||
self.update()
|
if(k != "preventUpdate")
|
||||||
|
self.update()
|
||||||
}
|
}
|
||||||
self.root.get = function(k)
|
self.root.get = function(k)
|
||||||
{
|
{
|
||||||
@ -141,7 +143,12 @@
|
|||||||
calibre_size()
|
calibre_size()
|
||||||
}
|
}
|
||||||
self.on("updated", function(){
|
self.on("updated", function(){
|
||||||
refreshData()
|
if(self.preventUpdate)
|
||||||
|
{
|
||||||
|
self.preventUpdate = false
|
||||||
|
}
|
||||||
|
else
|
||||||
|
refreshData()
|
||||||
//calibre_size()
|
//calibre_size()
|
||||||
})
|
})
|
||||||
self.on("mount", function(){
|
self.on("mount", function(){
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
<a href="#" onclick = {parent.onselect}>
|
<a href="#" onclick = {parent.onselect}>
|
||||||
<afx-switch if = {data.switch || data.radio} class = {checked:parent.checkItem(data)} enable = false swon = {data.checked} ></afx-switch>
|
<afx-switch if = {data.switch || data.radio} class = {checked:parent.checkItem(data)} enable = false swon = {data.checked} ></afx-switch>
|
||||||
<afx-label color = {data.color} iconclass = {data.iconclass} icon = {data.icon} text = {data.text} ></afx-label>
|
<afx-label color = {data.color} iconclass = {data.iconclass} icon = {data.icon} text = {data.text} ></afx-label>
|
||||||
|
<span if={data.shortcut} class = "shortcut">{data.shortcut}</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<afx-menu if={data.child != null && data.child.length > 0} child={data.child} onmenuselect = {data.onmenuselect} observable = {parent.root.observable} rootid = {parent.rid}></afx-menu>
|
<afx-menu if={data.child != null && data.child.length > 0} child={data.child} onmenuselect = {data.onmenuselect} observable = {parent.root.observable} rootid = {parent.rid}></afx-menu>
|
||||||
|
@ -1,10 +1,16 @@
|
|||||||
<afx-switch>
|
<afx-switch>
|
||||||
<span class = {swon: swon} onclick = {toggle}></span>
|
<span class = {swon: swon} onclick = {toggle}></span>
|
||||||
<script>
|
<script>
|
||||||
this.swon = opts.swon || false
|
if(opts.swon != undefined)
|
||||||
|
this.swon = opts.swon
|
||||||
|
else
|
||||||
|
this.swon = false
|
||||||
var self = this
|
var self = this
|
||||||
this.root.observable = opts.observable
|
this.root.observable = opts.observable
|
||||||
this.enable = opts.enable || true
|
if(opts.enable != undefined)
|
||||||
|
this.enable = opts.enable
|
||||||
|
else
|
||||||
|
this.enable = true
|
||||||
this.onchange = opts.onchange
|
this.onchange = opts.onchange
|
||||||
this.rid = $(self.root).attr("data-id") || Math.floor(Math.random() * 100000) + 1
|
this.rid = $(self.root).attr("data-id") || Math.floor(Math.random() * 100000) + 1
|
||||||
self.root.set = function(k,v)
|
self.root.set = function(k,v)
|
||||||
|
@ -14,9 +14,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.root.update = function(){
|
self.root.update = function(){
|
||||||
self.update()
|
self.update(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.on("mount", function(){
|
self.on("mount", function(){
|
||||||
self.refs.list.root.observable = self.root.observable
|
self.refs.list.root.observable = self.root.observable
|
||||||
/*self.root.observable.on("listselect", function(){
|
/*self.root.observable.on("listselect", function(){
|
||||||
|
@ -165,6 +165,19 @@ class Blogger extends this.OS.GUI.BaseApplication
|
|||||||
return unless sel
|
return unless sel
|
||||||
me.editor.value atob(sel.content)
|
me.editor.value atob(sel.content)
|
||||||
me.inputtags.value = sel.tags
|
me.inputtags.value = sel.tags
|
||||||
|
(me.find "blog-publish").set "swon", (if sel.publish then true else false)
|
||||||
|
|
||||||
|
@.bloglist.set "onitemclose", (e) ->
|
||||||
|
me.openDialog "YesNoDialog", (b) ->
|
||||||
|
return unless b
|
||||||
|
me.blogdb.delete e.item.item.id, (r) ->
|
||||||
|
return me.error "Cannot delete: #{r.error}" if r.error
|
||||||
|
me.bloglist.remove e.item.item, true
|
||||||
|
me.bloglist.set "selected", -1
|
||||||
|
me.clearEditor()
|
||||||
|
, "Delete a post" ,
|
||||||
|
{ iconclass: "fa fa-question-circle", text: "Do you really want to delete this post ?" }
|
||||||
|
return false
|
||||||
|
|
||||||
@on "vboxchange", () ->
|
@on "vboxchange", () ->
|
||||||
me.resizeContent()
|
me.resizeContent()
|
||||||
@ -300,16 +313,21 @@ class Blogger extends this.OS.GUI.BaseApplication
|
|||||||
utime: d.timestamp()
|
utime: d.timestamp()
|
||||||
utimestr: d.toString()
|
utimestr: d.toString()
|
||||||
rendered: me.editor.options.previewRender(content).asBase64()
|
rendered: me.editor.options.previewRender(content).asBase64()
|
||||||
|
publish: if ((@find "blog-publish").get "swon") then 1 else 0
|
||||||
data.id = sel.id if sel
|
data.id = sel.id if sel
|
||||||
|
|
||||||
#save the data
|
#save the data
|
||||||
@blogdb.save data, (r) ->
|
@blogdb.save data, (r) ->
|
||||||
return me.error "Cannot save blog: #{r.error}" if r.error
|
return me.error "Cannot save blog: #{r.error}" if r.error
|
||||||
me.loadBlogs()
|
me.loadBlogs()
|
||||||
|
clearEditor:() ->
|
||||||
|
@.editor.value ""
|
||||||
|
@.inputtags.value = ""
|
||||||
|
(@.find "blog-publish").set "swon", false
|
||||||
# load blog
|
# load blog
|
||||||
loadBlogs: () ->
|
loadBlogs: () ->
|
||||||
me = @
|
me = @
|
||||||
|
selidx = @bloglist.get "selidx"
|
||||||
cond =
|
cond =
|
||||||
order:
|
order:
|
||||||
ctime: "DESC"
|
ctime: "DESC"
|
||||||
@ -323,20 +341,12 @@ class Blogger extends this.OS.GUI.BaseApplication
|
|||||||
v.detail = [
|
v.detail = [
|
||||||
{ text: "Created: #{v.ctimestr}", class: "blog-dates" },
|
{ text: "Created: #{v.ctimestr}", class: "blog-dates" },
|
||||||
{ text: "Updated: #{v.utimestr}", class: "blog-dates" }]
|
{ text: "Updated: #{v.utimestr}", class: "blog-dates" }]
|
||||||
me.bloglist.set "onitemclose", (e) ->
|
|
||||||
me.openDialog "YesNoDialog", (b) ->
|
|
||||||
return unless b
|
|
||||||
me.blogdb.delete e.item.item.id, (r) ->
|
|
||||||
return me.error "Cannot delete: #{r.error}" if r.error
|
|
||||||
me.bloglist.remove e.item.item, true
|
|
||||||
me.bloglist.set "selected", -1
|
|
||||||
me.editor.value ""
|
|
||||||
me.inputtags.value = ""
|
|
||||||
, "Delete a post" ,
|
|
||||||
{ iconclass: "fa fa-question-circle", text: "Do you really want to delete this post ?" }
|
|
||||||
return false
|
|
||||||
me.bloglist.set "items", r.result
|
me.bloglist.set "items", r.result
|
||||||
|
if selidx isnt -1
|
||||||
|
me.bloglist.set "selected", selidx
|
||||||
|
else
|
||||||
|
me.clearEditor()
|
||||||
|
me.bloglist.set "selected", -1
|
||||||
resizeContent: () ->
|
resizeContent: () ->
|
||||||
container = @find "editor-container"
|
container = @find "editor-container"
|
||||||
children = ($ container).children()
|
children = ($ container).children()
|
||||||
|
@ -61,7 +61,13 @@
|
|||||||
<textarea data-id="markarea" ></textarea>
|
<textarea data-id="markarea" ></textarea>
|
||||||
</div>
|
</div>
|
||||||
<afx-label text = "Tags:" style="font-weight:bold;" data-height="25" ></afx-label>
|
<afx-label text = "Tags:" style="font-weight:bold;" data-height="25" ></afx-label>
|
||||||
<input type = "text" data-id = "input-tags" data-height="25"/>
|
<afx-hbox data-height="25">
|
||||||
|
<input type = "text" data-id = "input-tags" />
|
||||||
|
<div data-width="5"></div>
|
||||||
|
<afx-switch data data-id = "blog-publish" data-width="30"></afx-switch>
|
||||||
|
<div data-width="5"></div>
|
||||||
|
</afx-hbox>
|
||||||
|
|
||||||
<div data-height="5"></div>
|
<div data-height="5"></div>
|
||||||
</afx-vbox>
|
</afx-vbox>
|
||||||
</afx-hbox>
|
</afx-hbox>
|
||||||
|
@ -104,6 +104,9 @@ class NotePad extends this.OS.GUI.BaseApplication
|
|||||||
, "Close tab", { text: "Close without saving ?" }
|
, "Close tab", { text: "Close without saving ?" }
|
||||||
return false
|
return false
|
||||||
#@tabarea.set "closable", true
|
#@tabarea.set "closable", true
|
||||||
|
@bindKey "META-O", () -> me.actionFile "#{me.name}-Open"
|
||||||
|
@bindKey "CTRL-S", () -> me.actionFile "#{me.name}-Save"
|
||||||
|
@bindKey "META-S", () -> me.actionFile "#{me.name}-Saveas"
|
||||||
@open @currfile
|
@open @currfile
|
||||||
|
|
||||||
open: (file) ->
|
open: (file) ->
|
||||||
@ -188,6 +191,7 @@ class NotePad extends this.OS.GUI.BaseApplication
|
|||||||
@currfile.selected = false
|
@currfile.selected = false
|
||||||
file.selected = true
|
file.selected = true
|
||||||
#console.log cnt
|
#console.log cnt
|
||||||
|
@fileview.set "preventUpdate", true
|
||||||
@tabarea.push file, true
|
@tabarea.push file, true
|
||||||
#@currfile = @file
|
#@currfile = @file
|
||||||
#TODO: fix problem : @tabarea.set "selected", cnt
|
#TODO: fix problem : @tabarea.set "selected", cnt
|
||||||
@ -239,11 +243,11 @@ class NotePad extends this.OS.GUI.BaseApplication
|
|||||||
menu = [{
|
menu = [{
|
||||||
text: "File",
|
text: "File",
|
||||||
child: [
|
child: [
|
||||||
{ text: "Open", dataid: "#{@name}-Open" },
|
{ text: "Open", dataid: "#{@name}-Open", shortcut: "META-O" },
|
||||||
{ text: "Save", dataid: "#{@name}-Save" },
|
{ text: "Save", dataid: "#{@name}-Save", shortcut: "CTRL-S" },
|
||||||
{ text: "Save as", dataid: "#{@name}-Saveas" }
|
{ text: "Save as", dataid: "#{@name}-Saveas", shortcut: "META-S" }
|
||||||
],
|
],
|
||||||
onmenuselect: (e) -> me.actionFile e
|
onmenuselect: (e) -> me.actionFile e.item.data.dataid
|
||||||
}]
|
}]
|
||||||
menu
|
menu
|
||||||
|
|
||||||
@ -254,7 +258,7 @@ class NotePad extends this.OS.GUI.BaseApplication
|
|||||||
me.currfile.setPath "#{d}/#{n}"
|
me.currfile.setPath "#{d}/#{n}"
|
||||||
me.save me.currfile
|
me.save me.currfile
|
||||||
, "Save as", { file: me.currfile }
|
, "Save as", { file: me.currfile }
|
||||||
switch e.item.data.dataid
|
switch e
|
||||||
when "#{@name}-Open"
|
when "#{@name}-Open"
|
||||||
@openDialog "FileDiaLog", ( d, f ) ->
|
@openDialog "FileDiaLog", ( d, f ) ->
|
||||||
me.open "#{d}/#{f}".asFileHandler()
|
me.open "#{d}/#{f}".asFileHandler()
|
||||||
|
@ -23,6 +23,7 @@ afx-list-view > div.list-container > ul > li{
|
|||||||
padding: 5px;
|
padding: 5px;
|
||||||
padding-top:3px;
|
padding-top:3px;
|
||||||
padding-bottom: 3px;
|
padding-bottom: 3px;
|
||||||
|
padding-right: 10px;
|
||||||
color: #414339;
|
color: #414339;
|
||||||
background-color: white;
|
background-color: white;
|
||||||
position: relative;
|
position: relative;
|
||||||
@ -36,17 +37,18 @@ afx-list-view i.closable{
|
|||||||
width: 16px;
|
width: 16px;
|
||||||
height: 16px;
|
height: 16px;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
position:absolute;
|
||||||
|
top:0px;
|
||||||
|
right:2px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
afx-list-view i.closable:before{
|
afx-list-view i.closable:before{
|
||||||
content: "\f00d";
|
content: "\f00d";
|
||||||
font-family: "FontAwesome";
|
font-family: "FontAwesome";
|
||||||
font-size: 10px;
|
font-size: 10px;
|
||||||
right:5px;
|
margin-left: 10px;
|
||||||
color: #414339;
|
color: #414339;
|
||||||
position:absolute;
|
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
top:5px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
afx-list-view > div.list-container > ul > li > i {
|
afx-list-view > div.list-container > ul > li > i {
|
||||||
|
@ -7,9 +7,13 @@ afx-menu {
|
|||||||
afx-menu a{
|
afx-menu a{
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
color: #414339;
|
color: #414339;
|
||||||
display: inline-block;
|
display: flex;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
afx-menu a afx-label{
|
||||||
|
flex:1;
|
||||||
}
|
}
|
||||||
afx-menu ul{
|
afx-menu ul{
|
||||||
padding:0;
|
padding:0;
|
||||||
@ -22,6 +26,10 @@ afx-menu afx-switch span{
|
|||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
/*margin-top:5px;*/
|
/*margin-top:5px;*/
|
||||||
}
|
}
|
||||||
|
afx-menu span.shortcut{
|
||||||
|
width:45px;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
afx-menu li:hover > a afx-switch span:before{
|
afx-menu li:hover > a afx-switch span:before{
|
||||||
color:white;
|
color:white;
|
||||||
}
|
}
|
||||||
|
@ -7,11 +7,12 @@ afx-tab-container afx-list-view {
|
|||||||
padding:0;
|
padding:0;
|
||||||
margin:0;
|
margin:0;
|
||||||
}
|
}
|
||||||
afx-tab-container afx-list-view li{
|
afx-tab-container afx-list-view > div.list-container > ul > li{
|
||||||
float:left;
|
float:left;
|
||||||
border-top-left-radius: 5px;
|
border-top-left-radius: 5px;
|
||||||
border-top-right-radius: 5px;
|
border-top-right-radius: 5px;
|
||||||
padding-bottom: 2px;
|
padding-bottom: 2px;
|
||||||
|
padding-right:15px;
|
||||||
padding-top:2px;
|
padding-top:2px;
|
||||||
border:1px solid #c3c3c3;
|
border:1px solid #c3c3c3;
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user