add shortcut support to application

This commit is contained in:
Xuan Sang LE 2018-02-27 00:55:02 +01:00
parent 10dbe6ea99
commit c1781d1741
12 changed files with 112 additions and 31 deletions

View File

@ -3,6 +3,11 @@ class BaseApplication extends this.OS.GUI.BaseModel
super name, args
_OS.setting.applications[@name] = {} if not _OS.setting.applications[@name]
@setting = _OS.setting.applications[@name]
@keycomb =
ALT: {}
CTRL: {}
SHIFT: {}
META: {}
init: ->
me = @
# first register some base event to the app
@ -29,6 +34,20 @@ class BaseApplication extends this.OS.GUI.BaseModel
path = "#{@meta().path}/scheme.html"
@.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) ->
registry: (k, v) ->
@setting[k] = v

View File

@ -183,6 +183,24 @@ self.OS.GUI =
initDM: ->
# 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) ->
return null unless x
scheme = $.parseHTML x

View File

@ -16,6 +16,7 @@
this.status = opts.status == undefined?true:opts.status
this.selectedFile = undefined
this.showhidden = opts.showhidden
this.preventUpdate = false
this.fetch = opts.fetch
this.chdir = opts.chdir
this.rid = $(self.root).attr("data-id") || Math.floor(Math.random() * 100000) + 1
@ -32,7 +33,8 @@
switchView()
if(k == "data")
self.selectedFile = undefined
self.update()
if(k != "preventUpdate")
self.update()
}
self.root.get = function(k)
{
@ -141,7 +143,12 @@
calibre_size()
}
self.on("updated", function(){
refreshData()
if(self.preventUpdate)
{
self.preventUpdate = false
}
else
refreshData()
//calibre_size()
})
self.on("mount", function(){

View File

@ -5,6 +5,7 @@
<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-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>
<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>

View File

@ -1,10 +1,16 @@
<afx-switch>
<span class = {swon: swon} onclick = {toggle}></span>
<script>
this.swon = opts.swon || false
if(opts.swon != undefined)
this.swon = opts.swon
else
this.swon = false
var self = this
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.rid = $(self.root).attr("data-id") || Math.floor(Math.random() * 100000) + 1
self.root.set = function(k,v)

View File

@ -14,9 +14,8 @@
}
self.root.update = function(){
self.update()
self.update(true)
}
self.on("mount", function(){
self.refs.list.root.observable = self.root.observable
/*self.root.observable.on("listselect", function(){

View File

@ -165,6 +165,19 @@ class Blogger extends this.OS.GUI.BaseApplication
return unless sel
me.editor.value atob(sel.content)
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", () ->
me.resizeContent()
@ -300,16 +313,21 @@ class Blogger extends this.OS.GUI.BaseApplication
utime: d.timestamp()
utimestr: d.toString()
rendered: me.editor.options.previewRender(content).asBase64()
publish: if ((@find "blog-publish").get "swon") then 1 else 0
data.id = sel.id if sel
#save the data
@blogdb.save data, (r) ->
return me.error "Cannot save blog: #{r.error}" if r.error
me.loadBlogs()
clearEditor:() ->
@.editor.value ""
@.inputtags.value = ""
(@.find "blog-publish").set "swon", false
# load blog
loadBlogs: () ->
me = @
selidx = @bloglist.get "selidx"
cond =
order:
ctime: "DESC"
@ -323,20 +341,12 @@ class Blogger extends this.OS.GUI.BaseApplication
v.detail = [
{ text: "Created: #{v.ctimestr}", 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
if selidx isnt -1
me.bloglist.set "selected", selidx
else
me.clearEditor()
me.bloglist.set "selected", -1
resizeContent: () ->
container = @find "editor-container"
children = ($ container).children()

View File

@ -61,7 +61,13 @@
<textarea data-id="markarea" ></textarea>
</div>
<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>
</afx-vbox>
</afx-hbox>

View File

@ -104,6 +104,9 @@ class NotePad extends this.OS.GUI.BaseApplication
, "Close tab", { text: "Close without saving ?" }
return false
#@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: (file) ->
@ -188,6 +191,7 @@ class NotePad extends this.OS.GUI.BaseApplication
@currfile.selected = false
file.selected = true
#console.log cnt
@fileview.set "preventUpdate", true
@tabarea.push file, true
#@currfile = @file
#TODO: fix problem : @tabarea.set "selected", cnt
@ -239,11 +243,11 @@ class NotePad extends this.OS.GUI.BaseApplication
menu = [{
text: "File",
child: [
{ text: "Open", dataid: "#{@name}-Open" },
{ text: "Save", dataid: "#{@name}-Save" },
{ text: "Save as", dataid: "#{@name}-Saveas" }
{ text: "Open", dataid: "#{@name}-Open", shortcut: "META-O" },
{ text: "Save", dataid: "#{@name}-Save", shortcut: "CTRL-S" },
{ text: "Save as", dataid: "#{@name}-Saveas", shortcut: "META-S" }
],
onmenuselect: (e) -> me.actionFile e
onmenuselect: (e) -> me.actionFile e.item.data.dataid
}]
menu
@ -254,7 +258,7 @@ class NotePad extends this.OS.GUI.BaseApplication
me.currfile.setPath "#{d}/#{n}"
me.save me.currfile
, "Save as", { file: me.currfile }
switch e.item.data.dataid
switch e
when "#{@name}-Open"
@openDialog "FileDiaLog", ( d, f ) ->
me.open "#{d}/#{f}".asFileHandler()

View File

@ -23,6 +23,7 @@ afx-list-view > div.list-container > ul > li{
padding: 5px;
padding-top:3px;
padding-bottom: 3px;
padding-right: 10px;
color: #414339;
background-color: white;
position: relative;
@ -36,17 +37,18 @@ afx-list-view i.closable{
width: 16px;
height: 16px;
display: inline-block;
position:absolute;
top:0px;
right:2px;
cursor: pointer;
}
afx-list-view i.closable:before{
content: "\f00d";
font-family: "FontAwesome";
font-size: 10px;
right:5px;
margin-left: 10px;
color: #414339;
position:absolute;
font-style: normal;
top:5px;
}
afx-list-view > div.list-container > ul > li > i {

View File

@ -7,9 +7,13 @@ afx-menu {
afx-menu a{
text-decoration: none;
color: #414339;
display: inline-block;
display: flex;
width: 100%;
height: 100%;
flex-direction: row;
}
afx-menu a afx-label{
flex:1;
}
afx-menu ul{
padding:0;
@ -22,6 +26,10 @@ afx-menu afx-switch span{
font-size: 16px;
/*margin-top:5px;*/
}
afx-menu span.shortcut{
width:45px;
text-align: right;
}
afx-menu li:hover > a afx-switch span:before{
color:white;
}

View File

@ -7,11 +7,12 @@ afx-tab-container afx-list-view {
padding:0;
margin:0;
}
afx-tab-container afx-list-view li{
afx-tab-container afx-list-view > div.list-container > ul > li{
float:left;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
padding-bottom: 2px;
padding-right:15px;
padding-top:2px;
border:1px solid #c3c3c3;
}