mirror of
https://github.com/antos-rde/antosdk-apps.git
synced 2024-12-25 11:48:21 +01:00
Add OpenPage release
This commit is contained in:
parent
eb26c964b2
commit
50159758a2
@ -12,3 +12,7 @@
|
||||
|
||||
**Credit:**
|
||||
OpenPage is heavily based on the WebODF javascript library: https://webodf.org
|
||||
|
||||
|
||||
## Change logs
|
||||
- v.0.1.3-a adapt the code to the new AntOS API
|
Binary file not shown.
@ -22,7 +22,7 @@
|
||||
<afx-button data-width = "25" data-id="btformat" iconclass = "fa fa-paint-brush"></afx-button>
|
||||
<afx-list-view dropdown = "true" data-width="100" data-id="format-list"></afx-list-view>
|
||||
<div data-width="5"></div>
|
||||
<afx-nspinner data-width = "50" data-id="font-size" ></afx-nspinner>
|
||||
<afx-nspinner data-width = "50" data-id="font-size" value = "12" ></afx-nspinner>
|
||||
<div data-width="5"></div>
|
||||
<afx-list-view dropdown = "true" data-width="150" data-id="font-list"></afx-list-view>
|
||||
<div data-width="5"></div>
|
||||
|
Binary file not shown.
@ -8,10 +8,16 @@ afx-app-window[data-id="OpenPage"] div[data-id="container"]
|
||||
padding-top: 10px;
|
||||
padding-bottom: 10px;
|
||||
text-align: center;
|
||||
background-color: #f2f1f0;
|
||||
/*background-color: #f2f1f0;*/
|
||||
/*position: relative;*/
|
||||
}
|
||||
|
||||
afx-app-window[data-id="OpenPage"] office|body, office|document {
|
||||
background-color: white;
|
||||
color: black;
|
||||
background-image: none;
|
||||
user-select: text;
|
||||
overflow: visible;
|
||||
}
|
||||
/*
|
||||
@media screen, print, handheld, projection
|
||||
{
|
||||
@ -37,7 +43,8 @@ afx-app-window[data-id="OpenPage"] div[data-id="odfcanvas"]
|
||||
{
|
||||
cursor: text;
|
||||
margin:auto;
|
||||
box-shadow: 1px 1px 3px 3px #9f9F9F;
|
||||
/*box-shadow: 1px 1px 3px 3px #9f9F9F;*/
|
||||
border: 1px solid #2c2c2c;
|
||||
/*added*/
|
||||
transform-origin: top center;
|
||||
-webkit-transform-origin: top center;
|
||||
@ -48,24 +55,28 @@ afx-app-window[data-id="OpenPage"] div[data-id="odfcanvas"]
|
||||
|
||||
afx-app-window[data-id="OpenPage"] afx-hbox[data-id="toolbox"]
|
||||
{
|
||||
background-color: #f5f5f5;
|
||||
/*background-color: #f5f5f5;
|
||||
border: 1px solid #eaeaea;
|
||||
box-shadow: 3px 3px 3px #9f9F9F;
|
||||
box-shadow: 3px 3px 3px #9f9F9F;*/
|
||||
}
|
||||
afx-app-window[data-id="OpenPage"] afx-hbox[data-id="status-bar"]
|
||||
{
|
||||
background-color: #f5f5f5;
|
||||
/*background-color: #f5f5f5;
|
||||
border: 1px solid #eaeaea;
|
||||
box-shadow: -3px -3px 3px #9f9F9F;
|
||||
box-shadow: -3px -3px 3px #9f9F9F;*/
|
||||
}
|
||||
afx-app-window[data-id="OpenPage"] afx-hbox[data-id="toolbox"] afx-button button, afx-app-window[data-id="OpenPage"] afx-button[data-id="btzoomfix"] button
|
||||
{
|
||||
border: 1px solid #f5f5f5;
|
||||
background-color: transparent;
|
||||
/*border: 1px solid #f5f5f5;
|
||||
background-color: transparent;*/
|
||||
width:100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
afx-app-window[data-id="OpenPage"] button.selected {
|
||||
color:chocolate;
|
||||
}
|
||||
|
||||
afx-app-window[data-id="OpenPage"] afx-hbox[data-id="toolbox"] afx-button button:hover, afx-app-window[data-id="OpenPage"] afx-hbox[data-id="toolbox"] afx-button button.btactive, afx-app-window[data-id="OpenPage"] afx-button[data-id="btzoomfix"] button:hover
|
||||
{
|
||||
border: 1px solid #759DC0;
|
||||
|
File diff suppressed because one or more lines are too long
@ -6,7 +6,7 @@
|
||||
"author": "Xuan Sang LE",
|
||||
"email": "xsang.le@gmail.com"
|
||||
},
|
||||
"version":"0.0.2-a",
|
||||
"version":"0.1.3-a",
|
||||
"category":"Other",
|
||||
"icon":"icon.png",
|
||||
"mimes":["application/vnd.oasis.opendocument.text"]
|
||||
|
@ -22,7 +22,7 @@
|
||||
<afx-button data-width = "25" data-id="btformat" iconclass = "fa fa-paint-brush"></afx-button>
|
||||
<afx-list-view dropdown = "true" data-width="100" data-id="format-list"></afx-list-view>
|
||||
<div data-width="5"></div>
|
||||
<afx-nspinner data-width = "50" data-id="font-size" ></afx-nspinner>
|
||||
<afx-nspinner data-width = "50" data-id="font-size" value = "12" ></afx-nspinner>
|
||||
<div data-width="5"></div>
|
||||
<afx-list-view dropdown = "true" data-width="150" data-id="font-list"></afx-list-view>
|
||||
<div data-width="5"></div>
|
||||
|
BIN
OpenPage/build/release/OpenPage.zip
Normal file
BIN
OpenPage/build/release/OpenPage.zip
Normal file
Binary file not shown.
@ -1,43 +1,60 @@
|
||||
class HyperLinkDialog extends this.OS.GUI.BasicDialog
|
||||
constructor: () ->
|
||||
super "HyperLinkDialog", {
|
||||
tags: [
|
||||
{ tag: "afx-label", att: 'text="__(Text)" data-height="23" class="header"' },
|
||||
{ tag: "input", att: 'data-height="30"' },
|
||||
{ tag: "afx-label", att: 'text="__(Link)" data-height="23" class="header"' },
|
||||
{ tag: "input", att: 'data-height="30"' },
|
||||
{ tag: "div", att: ' data-height="5"' }
|
||||
],
|
||||
width: 350,
|
||||
height: 150,
|
||||
resizable: false,
|
||||
buttons: [
|
||||
{
|
||||
label: "Ok", onclick: (d) ->
|
||||
data =
|
||||
text: (d.find "content1").value,
|
||||
link: (d.find "content3").value,
|
||||
readonly: d.data.readonly,
|
||||
action: d.data.action
|
||||
d.handler data if d.handler
|
||||
d.quit()
|
||||
},
|
||||
{ label: "__(Cancel)", onclick: (d) -> d.quit() }
|
||||
],
|
||||
filldata: (d) ->
|
||||
return unless d.data
|
||||
(d.find "content1").value = d.data.text
|
||||
(d.find "content3").value = d.data.link
|
||||
$(d.find "content1").prop('disabled', d.data.readonly)
|
||||
}
|
||||
super "HyperLinkDialog", HyperLinkDialog.scheme
|
||||
|
||||
class FormatDialog extends this.OS.GUI.BaseDialog
|
||||
constructor: () ->
|
||||
super "FormatDialog"
|
||||
init: () ->
|
||||
@_gui.htmlToScheme FormatDialog.scheme, @, @host
|
||||
|
||||
main: () ->
|
||||
super.main()
|
||||
txtText = @find "txtText"
|
||||
txtLink = @find "txtLink"
|
||||
if @data and @data.data
|
||||
txtText.value = @data.data.text
|
||||
txtLink.value = @data.data.link
|
||||
$(txtText).prop('disabled', @data.data.readonly)
|
||||
|
||||
@find("btnCancel").onbtclick = (e) =>
|
||||
@quit()
|
||||
|
||||
@find("btnOk").onbtclick = (e) =>
|
||||
data =
|
||||
text: txtText.value,
|
||||
link: txtLink.value,
|
||||
readonly: @data.data.readonly,
|
||||
action: @data.data.action
|
||||
@handle data if @handle
|
||||
@quit()
|
||||
|
||||
HyperLinkDialog.scheme = """
|
||||
<afx-app-window width='350' height='150' apptitle = "Hyperlink">
|
||||
<afx-vbox>
|
||||
<afx-hbox>
|
||||
<div data-width = "10" />
|
||||
<afx-vbox>
|
||||
<div data-height="10" />
|
||||
<afx-label class="header" text = "__(Text)" data-height="23" />
|
||||
<input data-height = "30" data-id = "txtText" />
|
||||
<afx-label class="header" text = "__(Link)" data-height="23" />
|
||||
<input data-height = "30" data-id = "txtLink" />
|
||||
<div data-height="10" />
|
||||
<afx-hbox data-height="30">
|
||||
<div />
|
||||
<afx-button data-id = "btnOk" text = "__(Ok)" data-width = "40" />
|
||||
<afx-button data-id = "btnCancel" text = "__(Cancel)" data-width = "40" />
|
||||
<div data-width = "10" />
|
||||
</afx-hbox>
|
||||
</afx-vbox>
|
||||
<div data-width = "10" />
|
||||
</afx-hbox>
|
||||
</afx-vbox>
|
||||
</afx-app-window>
|
||||
"""
|
||||
|
||||
class FormatDialog extends this.OS.GUI.BasicDialog
|
||||
constructor: () ->
|
||||
super "FormatDialog", FormatDialog.scheme
|
||||
|
||||
main: () ->
|
||||
super.main()
|
||||
@ui =
|
||||
aligment:
|
||||
left:@find("swleft"),
|
||||
@ -99,64 +116,68 @@ class FormatDialog extends this.OS.GUI.BaseDialog
|
||||
size: 12
|
||||
|
||||
initUIEvent: () ->
|
||||
me = @
|
||||
set = (e, o, k ,f) ->
|
||||
me.ui[o][k].set e, (r) ->
|
||||
|
||||
set = (e, o, k ,f) =>
|
||||
@ui[o][k][e] = (r) =>
|
||||
v = r
|
||||
v = f r if f
|
||||
me.currentStyle[o][k] = v
|
||||
me.previewStyle()
|
||||
@currentStyle[o][k] = v
|
||||
@previewStyle()
|
||||
|
||||
for k,v of @ui.aligment
|
||||
set "onchange", "aligment", k, ((e) -> e.data)
|
||||
set "onswchange", "aligment", k, ((e) => e.data)
|
||||
for k,v of @ui.spacing
|
||||
set "onchange", "spacing", k
|
||||
set "onvaluechange", "spacing", k, ((e) => e.data)
|
||||
for k,v of @ui.padding
|
||||
set "onchange", "padding", k
|
||||
set "onvaluechange", "padding", k, ((e) => e.data)
|
||||
for k,v of @ui.style
|
||||
set "onchange", "style", k, ((e) -> e.data) if k isnt "color" and k isnt "bgcolor"
|
||||
set "onchange", "font", "size"
|
||||
$(@ui.style.color).click (e) ->
|
||||
me.openDialog "ColorPickerDialog", (d) ->
|
||||
me.currentStyle.style.color = d
|
||||
me.previewStyle()
|
||||
$(@ui.style.bgcolor).click (e) ->
|
||||
me.openDialog "ColorPickerDialog", (d) ->
|
||||
me.currentStyle.style.bgcolor = d
|
||||
me.previewStyle()
|
||||
set "onswchange", "style", k, ((e) => e.data) if k isnt "color" and k isnt "bgcolor"
|
||||
set "onvaluechange", "font", "size"
|
||||
$(@ui.style.color).click (e) =>
|
||||
@openDialog "ColorPickerDialog"
|
||||
.then (d) =>
|
||||
@currentStyle.style.color = d
|
||||
@previewStyle()
|
||||
$(@ui.style.bgcolor).click (e) =>
|
||||
@openDialog "ColorPickerDialog"
|
||||
.then (d) =>
|
||||
@currentStyle.style.bgcolor = d
|
||||
@previewStyle()
|
||||
#font
|
||||
@ui.font.family.set "items", @data.fonts if @data and @data.fonts
|
||||
set "onlistselect", "font", "family", ( (e) -> e.data)
|
||||
@ui.font.family.data = @data.data.fonts if @data.data and @data.data.fonts
|
||||
set "onlistselect", "font", "family", ( (e) => e.data.item.data)
|
||||
#format list
|
||||
@ui.formats.set "selected", -1
|
||||
@ui.formats.set "items", @data.formats if @data and @data.formats
|
||||
@ui.formats.set "onlistselect", (e) ->
|
||||
me.fromODFStyleFormat e.data
|
||||
@ui.formats.set "selected", 0
|
||||
(@find "btok").set "onbtclick", (e) ->
|
||||
me.saveCurrentStyle()
|
||||
@ui.formats.selected = -1
|
||||
@ui.formats.data = @data.data.formats if @data.data and @data.data.formats
|
||||
@ui.formats.onlistselect = (e) =>
|
||||
@fromODFStyleFormat e.data.item.data
|
||||
@ui.formats.selected = 0
|
||||
(@find "btok").onbtclick = (e) =>
|
||||
@saveCurrentStyle()
|
||||
|
||||
(@find "btx").set "onbtclick", (e) ->
|
||||
me.quit()
|
||||
(@find "btx").onbtclick = (e) =>
|
||||
@quit()
|
||||
|
||||
(@find "bt-clone").set "onbtclick", (e) ->
|
||||
me.clone()
|
||||
(@find "bt-clone").onbtclick = (e) =>
|
||||
@clone()
|
||||
|
||||
clone: ()->
|
||||
me = @
|
||||
selected = @ui.formats.get "selected"
|
||||
|
||||
selected = @ui.formats.selectedItem
|
||||
return unless selected
|
||||
@openDialog "PromptDialog", (d) ->
|
||||
return me.notify __("Abort: no style name is specified") unless d and d.trim() isnt ""
|
||||
newstyle = me.parent.editorSession.cloneParagraphStyle selected.name, d
|
||||
me.ui.formats.push { text:d, name: newstyle }
|
||||
me.ui.formats.set "selected", ((me.ui.formats.get 'count') - 1)
|
||||
me.notify __("New style: {0} added", newstyle)
|
||||
, __("Clone style: {0}", selected.text), { label: __("New style name:") }
|
||||
selected = selected.data
|
||||
@openDialog "PromptDialog", { title: __("Clone style: {0}", selected.text), label: __("New style name:") }
|
||||
.then (d) =>
|
||||
return @notify __("Abort: no style name is specified") unless d and d.trim() isnt ""
|
||||
newstyle = @parent.editorSession.cloneParagraphStyle selected.name, d
|
||||
@ui.formats.push { text:d, name: newstyle }
|
||||
@ui.formats.selected = (@ui.formats.data.length - 1)
|
||||
@notify __("New style: {0} added", newstyle)
|
||||
|
||||
saveCurrentStyle: () ->
|
||||
selected = @ui.formats.get "selected"
|
||||
selected = @ui.formats.selectedItem
|
||||
return unless selected
|
||||
selected = selected.data
|
||||
odfs =
|
||||
"style:paragraph-properties":
|
||||
"fo:margin-top": @currentStyle.spacing.top + "mm"
|
||||
@ -181,11 +202,11 @@ class FormatDialog extends this.OS.GUI.BaseDialog
|
||||
@notify __("Paragraph format [{0}] is saved", selected.text)
|
||||
|
||||
fromODFStyleFormat: (odfs) ->
|
||||
me = @
|
||||
|
||||
@initStyleObject()
|
||||
cssUnits = new core.CSSUnits()
|
||||
findFont = (name) ->
|
||||
items = me.ui.font.family.get "items"
|
||||
findFont = (name) =>
|
||||
items = @ui.font.family.data
|
||||
item = v for v in items when v.text is name
|
||||
return undefined unless item
|
||||
return item
|
||||
@ -216,34 +237,34 @@ class FormatDialog extends this.OS.GUI.BaseDialog
|
||||
previewStyle: () ->
|
||||
#console.log "previewing"
|
||||
# reset ui
|
||||
@ui.aligment.left.set "swon", @currentStyle.aligment.left
|
||||
@ui.aligment.right.set "swon", @currentStyle.aligment.right
|
||||
@ui.aligment.center.set "swon", @currentStyle.aligment.center
|
||||
@ui.aligment.justify.set "swon", @currentStyle.aligment.justify
|
||||
@ui.spacing.left.set "value", @currentStyle.spacing.left
|
||||
@ui.spacing.right.set "value", @currentStyle.spacing.right
|
||||
@ui.spacing.top.set "value", @currentStyle.spacing.top
|
||||
@ui.spacing.bottom.set "value", @currentStyle.spacing.bottom
|
||||
@ui.spacing.lineheight.set "value", @currentStyle.spacing.lineheight
|
||||
@ui.aligment.left.swon = @currentStyle.aligment.left
|
||||
@ui.aligment.right.swon = @currentStyle.aligment.right
|
||||
@ui.aligment.center.swon = @currentStyle.aligment.center
|
||||
@ui.aligment.justify.swon = @currentStyle.aligment.justify
|
||||
@ui.spacing.left.value = @currentStyle.spacing.left
|
||||
@ui.spacing.right.value = @currentStyle.spacing.right
|
||||
@ui.spacing.top.value = @currentStyle.spacing.top
|
||||
@ui.spacing.bottom.value = @currentStyle.spacing.bottom
|
||||
@ui.spacing.lineheight.value = @currentStyle.spacing.lineheight
|
||||
|
||||
@ui.padding.left.set "value", @currentStyle.padding.left
|
||||
@ui.padding.right.set "value", @currentStyle.padding.right
|
||||
@ui.padding.top.set "value", @currentStyle.padding.top
|
||||
@ui.padding.bottom.set "value", @currentStyle.padding.bottom
|
||||
@ui.padding.left.value = @currentStyle.padding.left
|
||||
@ui.padding.right.value = @currentStyle.padding.right
|
||||
@ui.padding.top.value = @currentStyle.padding.top
|
||||
@ui.padding.bottom.value = @currentStyle.padding.bottom
|
||||
|
||||
@ui.style.bold.set "swon", @currentStyle.style.bold
|
||||
@ui.style.italic.set "swon", @currentStyle.style.italic
|
||||
@ui.style.underline.set "swon", @currentStyle.style.underline
|
||||
@ui.font.size.set "value", @currentStyle.font.size
|
||||
@ui.style.bold.swon = @currentStyle.style.bold
|
||||
@ui.style.italic.swon = @currentStyle.style.italic
|
||||
@ui.style.underline.swon = @currentStyle.style.underline
|
||||
@ui.font.size.value = @currentStyle.font.size
|
||||
|
||||
#console.log @currentStyle
|
||||
if @currentStyle.font.family
|
||||
items = @ui.font.family.get "items"
|
||||
items = @ui.font.family.data
|
||||
item = i for v, i in items when v.text is @currentStyle.font.family.text
|
||||
@ui.font.family.set "selected", item if item >= 0
|
||||
@ui.font.family.selected = item if item >= 0
|
||||
|
||||
$(@ui.style.color).css "background-color", if @currentStyle.style.color then @currentStyle.style.color.hex else "#000000"
|
||||
$(@ui.style.bgcolor).css "background-color", if @currentStyle.style.bgcolor then @currentStyle.style.bgcolor.hex else "white"
|
||||
$(@ui.style.bgcolor).css "background-color", if @currentStyle.style.bgcolor then @currentStyle.style.bgcolor.hex else "transparent"
|
||||
# set the preview css
|
||||
el = $ @preview
|
||||
el.css "text-align", if @currentStyle.aligment.selected then @currentStyle.aligment.selected else "left"
|
||||
@ -301,16 +322,16 @@ FormatDialog.scheme = """
|
||||
<afx-hbox data-height="23" data-id="spacingbox">
|
||||
<div ></div>
|
||||
<afx-label data-width="50" text="__(Left:)"></afx-label>
|
||||
<afx-nspinner data-width="50" data-id="spnleft" step="0.5"></afx-nspinner>
|
||||
<afx-nspinner data-width="50" data-id="spnleft" value = "0" step="0.5"></afx-nspinner>
|
||||
<div></div>
|
||||
<afx-label data-width="50" text="__(Right:)"></afx-label>
|
||||
<afx-nspinner data-width="50" data-id="spnright" step="0.5"></afx-nspinner>
|
||||
<afx-nspinner data-width="50" data-id="spnright" value = "0" step="0.5"></afx-nspinner>
|
||||
<div></div>
|
||||
<afx-label data-width="50" text="__(Top:)"></afx-label>
|
||||
<afx-nspinner data-width="50" data-id="spntop" step="0.5"></afx-nspinner>
|
||||
<afx-nspinner data-width="50" data-id="spntop" value = "0" step="0.5"></afx-nspinner>
|
||||
<div></div>
|
||||
<afx-label data-width="50" text="__(Bottom:)"></afx-label>
|
||||
<afx-nspinner data-width="50" data-id="spnbottom" step="0.5"></afx-nspinner>
|
||||
<afx-nspinner data-width="50" data-id="spnbottom" value = "0" step="0.5"></afx-nspinner>
|
||||
<div ></div>
|
||||
</afx-hbox>
|
||||
<div data-height="5"></div>
|
||||
@ -319,16 +340,16 @@ FormatDialog.scheme = """
|
||||
<afx-hbox data-height="23" data-id="spacingbox">
|
||||
<div ></div>
|
||||
<afx-label data-width="50" text="__(Left:)"></afx-label>
|
||||
<afx-nspinner data-width="50" data-id="pspnleft" step="0.5"></afx-nspinner>
|
||||
<afx-nspinner data-width="50" data-id="pspnleft" value = "0" step="0.5"></afx-nspinner>
|
||||
<div></div>
|
||||
<afx-label data-width="50" text="__(Right:)"></afx-label>
|
||||
<afx-nspinner data-width="50" data-id="pspnright" step="0.5"></afx-nspinner>
|
||||
<afx-nspinner data-width="50" value = "0" data-id="pspnright" step="0.5"></afx-nspinner>
|
||||
<div></div>
|
||||
<afx-label data-width="50" text="__(Top:)"></afx-label>
|
||||
<afx-nspinner data-width="50" data-id="pspntop" step="0.5"></afx-nspinner>
|
||||
<afx-nspinner data-width="50" value = "0" data-id="pspntop" step="0.5"></afx-nspinner>
|
||||
<div></div>
|
||||
<afx-label data-width="50" text="__(Bottom:)"></afx-label>
|
||||
<afx-nspinner data-width="50" data-id="pspnbottom" step="0.5"></afx-nspinner>
|
||||
<afx-nspinner data-width="50" value = "0" data-id="pspnbottom" step="0.5"></afx-nspinner>
|
||||
<div ></div>
|
||||
</afx-hbox>
|
||||
|
||||
@ -358,7 +379,7 @@ FormatDialog.scheme = """
|
||||
<afx-list-view data-id="lstfont" dropdown = "true"></afx-list-view>
|
||||
<div data-width="5" ></div>
|
||||
<afx-label data-width="35" text="__(Size:)"></afx-label>
|
||||
<afx-nspinner data-width="50" data-id="spnfsize"></afx-nspinner>
|
||||
<afx-nspinner data-width="50" value = "12" data-id="spnfsize"></afx-nspinner>
|
||||
<div data-width="5" ></div>
|
||||
<afx-label data-width="80" text="__(Line Height:)"></afx-label>
|
||||
<afx-nspinner data-width="50" data-id="spnlheight" value="4.2" step="0.2"></afx-nspinner>
|
||||
@ -369,7 +390,7 @@ FormatDialog.scheme = """
|
||||
<div data-height="5"></div>
|
||||
<afx-hbox>
|
||||
<div data-width="5"></div>
|
||||
<div data-id="preview">
|
||||
<div data-id="preview" style="background-color: white;">
|
||||
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce laoreet diam vestibulum massa malesuada quis dignissim libero blandit. Duis sit amet volutpat nisl.</p>
|
||||
</div>
|
||||
<div data-width="5"></div>
|
||||
|
@ -1,4 +1,4 @@
|
||||
class OpenPage extends this.OS.GUI.BaseApplication
|
||||
class OpenPage extends this.OS.application.BaseApplication
|
||||
constructor: ( args ) ->
|
||||
super "OpenPage", args
|
||||
|
||||
@ -7,52 +7,55 @@ class OpenPage extends this.OS.GUI.BaseApplication
|
||||
#if not OpenPage.EditorSession
|
||||
# require ["webodf/editor/EditorSession"], (ES) ->
|
||||
# OpenPage.EditorSession = ES
|
||||
me =@
|
||||
|
||||
@eventSubscriptions = new core.EventSubscriptions()
|
||||
@initToolbox()
|
||||
@userid = "#{@systemsetting.user.username}@#{@pid}"
|
||||
#file = "home://welcome.odt"
|
||||
#file = "home://welco@odt"
|
||||
#file = "#{@_api.handler.get}/home://welcome.odt"
|
||||
#@canvas.load file
|
||||
#odfContainer = new odf.OdfContainer file, (c) ->
|
||||
# me.canvas.setOdfContainer c, false
|
||||
# @canvas.setOdfContainer c, false
|
||||
@currentStyle = ""
|
||||
if @args and @args.length > 0 then @open @args[0] else @newdoc()
|
||||
if @args and @args.length > 0 then @open @args[0].path else @newdoc()
|
||||
@resource =
|
||||
fonts: []
|
||||
formats: []
|
||||
@bindKey "ALT-N", () -> me.actionFile "#{me.name}-New"
|
||||
@bindKey "ALT-O", () -> me.actionFile "#{me.name}-Open"
|
||||
@bindKey "CTRL-S", () -> me.actionFile "#{me.name}-Save"
|
||||
@bindKey "ALT-W", () -> me.actionFile "#{me.name}-Saveas"
|
||||
@bindKey "ALT-N", () => @actionFile "#{@name}-New"
|
||||
@bindKey "ALT-O", () => @actionFile "#{@name}-Open"
|
||||
@bindKey "CTRL-S", () => @actionFile "#{@name}-Save"
|
||||
@bindKey "ALT-W", () => @actionFile "#{@name}-Saveas"
|
||||
|
||||
|
||||
menu: () ->
|
||||
me = @
|
||||
|
||||
menu = [{
|
||||
text: "__(File)",
|
||||
child: [
|
||||
nodes: [
|
||||
{ text: "__(New)", dataid: "#{@name}-New", shortcut: "A-N" },
|
||||
{ text: "__(Open)", dataid: "#{@name}-Open", shortcut: "A-O" },
|
||||
{ text: "__(Save)", dataid: "#{@name}-Save", shortcut: "C-S" },
|
||||
{ text: "__(Save as)", dataid: "#{@name}-Saveas", shortcut: "A-W" }
|
||||
],
|
||||
onmenuselect: (e) -> me.actionFile e.item.data.dataid
|
||||
onchildselect: (e) => @actionFile e.data.item.data.dataid
|
||||
}]
|
||||
menu
|
||||
|
||||
actionFile: (e) ->
|
||||
me = @
|
||||
saveas = () ->
|
||||
me.openDialog "FileDiaLog", (d, n, p) ->
|
||||
me.currfile.setPath "#{d}/#{n}"
|
||||
me.save()
|
||||
, __("Save as"), { file: me.currfile }
|
||||
|
||||
saveas = () =>
|
||||
@openDialog "FileDialog", { title: __("Save as"), file: @currfile }
|
||||
.then (f) =>
|
||||
d = f.file.path.asFileHandle()
|
||||
d = d.parent() if f.file.type is "file"
|
||||
@currfile.setPath "#{d.path}/#{f.name}"
|
||||
@save()
|
||||
switch e
|
||||
when "#{@name}-Open"
|
||||
@openDialog "FileDiaLog", ( d, f , p) ->
|
||||
me.open p
|
||||
, __("Open file"), { mimes: me.meta().mimes }
|
||||
@openDialog "FileDialog", { title: __("Open file"), mimes: @meta().mimes }
|
||||
.then (f) =>
|
||||
@open f.file.path
|
||||
|
||||
when "#{@name}-Save"
|
||||
#@currfile.cache = @editor.value()
|
||||
return @save() if @currfile.basename
|
||||
@ -68,39 +71,41 @@ class OpenPage extends this.OS.GUI.BaseApplication
|
||||
@open blank, true
|
||||
|
||||
open: (p,b) ->
|
||||
me = @
|
||||
|
||||
@pathAsDataURL(p)
|
||||
.then (r) ->
|
||||
me.closeDocument() if me.editorSession
|
||||
me.initCanvas()
|
||||
OdfContainer = new odf.OdfContainer r.data, (c) ->
|
||||
me.canvas.setOdfContainer c, false
|
||||
return me.currfile = "Untitled".asFileHandler() if b
|
||||
if me.currfile then me.currfile.setPath p else me.currfile = p.asFileHandler()
|
||||
me.scheme.set "apptitle", me.currfile.basename
|
||||
me.notify __("File {0} opened", p)
|
||||
.catch (e) ->
|
||||
me.error __("Problem read file {0}", e)
|
||||
.then (r) =>
|
||||
@closeDocument() if @editorSession
|
||||
@initCanvas()
|
||||
OdfContainer = new odf.OdfContainer r.data, (c) =>
|
||||
@canvas.setOdfContainer c, false
|
||||
return @currfile = "Untitled".asFileHandle() if b
|
||||
if @currfile then @currfile.setPath p else @currfile = p.asFileHandle()
|
||||
@scheme.apptitle = @currfile.basename
|
||||
@notify __("File {0} opened", p)
|
||||
.catch (e) =>
|
||||
@error __("Problem read file {0}", e.toString()), e
|
||||
|
||||
save: () ->
|
||||
me = @
|
||||
|
||||
return unless @editorSession
|
||||
container = @canvas.odfContainer()
|
||||
return @error __("No document container found") unless container
|
||||
container.createByteArray (ba) ->
|
||||
container.createByteArray (ba) =>
|
||||
# create blob
|
||||
me.currfile.cache = new Blob [ba], { type: "application/vnd.oasis.opendocument.text" }
|
||||
me.currfile.write "application/vnd.oasis.opendocument.text", (r) ->
|
||||
return me.error __("Cannot save file: {0}", r.error) if r.error
|
||||
me.notify __("File {0} saved", me.currfile.basename)
|
||||
me.scheme.set "apptitle", me.currfile.basename
|
||||
me.currfile.dirty = false
|
||||
me.editorFocus()
|
||||
, (err) ->
|
||||
@error __("Cannot create byte array from container: {0}", err|| "")
|
||||
@currfile.cache = new Blob [ba], { type: "application/vnd.oasis.opendocument.text" }
|
||||
@currfile.write "application/vnd.oasis.opendocument.text"
|
||||
.then (r) =>
|
||||
@notify __("File {0} saved", @currfile.basename)
|
||||
@scheme.apptitle = @currfile.basename
|
||||
@currfile.dirty = false
|
||||
@editorFocus()
|
||||
.catch (e) =>
|
||||
@error __("Cannot save file: {0}", e.toString()), e
|
||||
, (err) =>
|
||||
@error __("Cannot create byte array from container: {0}", err.toString() || ""), err
|
||||
|
||||
initToolbox: () ->
|
||||
me = @
|
||||
|
||||
@basictool =
|
||||
undo: @find("btundo"),
|
||||
redo: @find("btredo"),
|
||||
@ -124,76 +129,77 @@ class OpenPage extends this.OS.GUI.BaseApplication
|
||||
zoom: @find("slzoom")
|
||||
format: @find("btformat")
|
||||
|
||||
fn = (name, el) ->
|
||||
fn = (name, el) =>
|
||||
if name is "fonts" or name is "styles"
|
||||
act = "onlistselect"
|
||||
else if name is "fontsize" or name is "zoom"
|
||||
act = "onchange"
|
||||
act = "onvaluechange"
|
||||
else
|
||||
act = "onbtclick"
|
||||
el.set act, (e) ->
|
||||
return unless me.directFormattingCtl
|
||||
return unless me[name]
|
||||
me[name](e)
|
||||
me.editorFocus()
|
||||
el[act] = (e) =>
|
||||
return unless @directFormattingCtl
|
||||
return unless @[name]
|
||||
@[name](e)
|
||||
@editorFocus()
|
||||
for name, el of @basictool
|
||||
fn name, el
|
||||
|
||||
(@find "btzoomfix").set "onbtclick", (e) -> me.zoom 100
|
||||
@basictool.zoom.set "onchanging", (e) ->
|
||||
zlb = me.find "lbzoom"
|
||||
zlb.set "text", Math.floor(e) + "%"
|
||||
(@find "btzoomfix").onbtclick = (e) => @zoom { data: 100 }
|
||||
@basictool.zoom.onvaluechanging = (e) =>
|
||||
zlb = @find "lbzoom"
|
||||
zlb.text = Math.floor(e.data) + "%"
|
||||
|
||||
initCanvas: () ->
|
||||
el = @find "odfcanvas"
|
||||
me = @
|
||||
|
||||
el.setAttribute "translate", "no"
|
||||
el.classList.add "notranslate"
|
||||
@canvas = new odf.OdfCanvas(el)
|
||||
@documentChanged = (e) ->
|
||||
return if me.currfile.dirty
|
||||
me.currfile.dirty = true
|
||||
me.scheme.set "apptitle", me.currfile.basename + "*"
|
||||
@documentChanged = (e) =>
|
||||
return if @currfile.dirty
|
||||
@currfile.dirty = true
|
||||
@scheme.apptitle = @currfile.basename + "*"
|
||||
#console.log e
|
||||
@metaChanged = (e) ->
|
||||
return if me.currfile.dirty
|
||||
me.currfile.dirty = true
|
||||
me.scheme.set "apptitle", me.currfile.basename + "*"
|
||||
@metaChanged = (e) =>
|
||||
return if @currfile.dirty
|
||||
@currfile.dirty = true
|
||||
@scheme.apptitle = @currfile.basename + "*"
|
||||
#console.log e
|
||||
@textStylingChanged = (e) ->
|
||||
me.updateToolbar e
|
||||
@paragrahStyleChanged = (e) ->
|
||||
@textStylingChanged = (e) =>
|
||||
@updateToolbar e
|
||||
@paragrahStyleChanged = (e) =>
|
||||
return unless e.type is "style"
|
||||
items = me.basictool.styles.get "items"
|
||||
items = @basictool.styles.data
|
||||
item = i for v, i in items when v.name is e.styleName
|
||||
me.currentStyle = e.styleName
|
||||
me.basictool.styles.set "selected", item
|
||||
return unless item isnt undefined
|
||||
@currentStyle = e.styleName
|
||||
@basictool.styles.selected = item
|
||||
|
||||
@styleAdded = (e) ->
|
||||
@styleAdded = (e) =>
|
||||
return unless e.family is 'paragraph'
|
||||
items = me.basictool.styles.get "items"
|
||||
items = @basictool.styles.data
|
||||
item = v for v in items when v.name is e.name
|
||||
return if item
|
||||
stylens = "urn:oasis:names:tc:opendocument:xmlns:style:1.0"
|
||||
el = me.editorSession.getParagraphStyleElement e.name
|
||||
el = @editorSession.getParagraphStyleElement e.name
|
||||
dtext = el.getAttributeNS stylens, 'display-name'
|
||||
me.basictool.styles.push { text: dtext , name: e.name }, true
|
||||
#me.resource.formats.push {text: dtext, name:e.name}
|
||||
@basictool.styles.push { text: dtext , name: e.name }, true
|
||||
#@resource.formats.push {text: dtext, name:e.name}
|
||||
|
||||
@updateSlider = (v) ->
|
||||
@updateSlider = (v) =>
|
||||
value = Math.floor v*100
|
||||
me.basictool.zoom.set "value", value
|
||||
zlb = me.find "lbzoom"
|
||||
zlb.set "text", value+"%"
|
||||
#me.canvas.enableAnnotations true, true
|
||||
@canvas.addListener "statereadychange", ()->
|
||||
me.session = new ops.Session(me.canvas)
|
||||
@basictool.zoom.value = value
|
||||
zlb = @find "lbzoom"
|
||||
zlb.text = value + "%"
|
||||
@canvas.enableAnnotations true, true
|
||||
@canvas.addListener "statereadychange", ()=>
|
||||
@session = new ops.Session(@canvas)
|
||||
viewOptions =
|
||||
editInfoMarkersInitiallyVisible: false,
|
||||
caretAvatarsInitiallyVisible: false,
|
||||
caretBlinksOnRangeSelect: true
|
||||
|
||||
me.editorSession = new OpenPage.EditorSession(me.session,me.userid, {
|
||||
@editorSession = new OpenPage.EditorSession(@session,@userid, {
|
||||
viewOptions: viewOptions,
|
||||
directTextStylingEnabled: true,
|
||||
directParagraphStylingEnabled: true,
|
||||
@ -205,112 +211,121 @@ class OpenPage extends this.OS.GUI.BaseApplication
|
||||
zoomingEnabled: true,
|
||||
reviewModeEnabled: false
|
||||
})
|
||||
me.initFontList me.editorSession.getDeclaredFonts()
|
||||
me.initStyles me.editorSession.getAvailableParagraphStyles()
|
||||
@initFontList @editorSession.getDeclaredFonts()
|
||||
@initStyles @editorSession.getAvailableParagraphStyles()
|
||||
#fix annotation problem on canvas
|
||||
#console.log $("office:body").css "background-color", "red"
|
||||
# basic format
|
||||
me.directFormattingCtl = me.editorSession.sessionController.getDirectFormattingController()
|
||||
me.directFormattingCtl.subscribe gui.DirectFormattingController.textStylingChanged, me.textStylingChanged
|
||||
me.directFormattingCtl.subscribe gui.DirectFormattingController.paragraphStylingChanged, me.textStylingChanged
|
||||
me.editorSession.subscribe OpenPage.EditorSession.signalParagraphChanged, me.paragrahStyleChanged
|
||||
@directFormattingCtl = @editorSession.sessionController.getDirectFormattingController()
|
||||
@directFormattingCtl.subscribe gui.DirectFormattingController.textStylingChanged, @textStylingChanged
|
||||
@directFormattingCtl.subscribe gui.DirectFormattingController.paragraphStylingChanged, @textStylingChanged
|
||||
@editorSession.subscribe OpenPage.EditorSession.signalParagraphChanged, @paragrahStyleChanged
|
||||
|
||||
# hyper link controller
|
||||
me.hyperlinkController = me.editorSession.sessionController.getHyperlinkController()
|
||||
me.eventSubscriptions.addFrameSubscription me.editorSession, OpenPage.EditorSession.signalCursorMoved, ()-> me.updateHyperlinkButtons()
|
||||
me.eventSubscriptions.addFrameSubscription me.editorSession, OpenPage.EditorSession.signalParagraphChanged, ()-> me.updateHyperlinkButtons()
|
||||
me.eventSubscriptions.addFrameSubscription me.editorSession, OpenPage.EditorSession.signalParagraphStyleModified, ()-> me.updateHyperlinkButtons()
|
||||
@hyperlinkController = @editorSession.sessionController.getHyperlinkController()
|
||||
@eventSubscriptions.addFrameSubscription @editorSession, OpenPage.EditorSession.signalCursorMoved, ()=> @updateHyperlinkButtons()
|
||||
@eventSubscriptions.addFrameSubscription @editorSession, OpenPage.EditorSession.signalParagraphChanged, ()=> @updateHyperlinkButtons()
|
||||
@eventSubscriptions.addFrameSubscription @editorSession, OpenPage.EditorSession.signalParagraphStyleModified, ()=> @updateHyperlinkButtons()
|
||||
|
||||
#annotation controller
|
||||
me.annotationController = me.editorSession.sessionController.getAnnotationController()
|
||||
@annotationController = @editorSession.sessionController.getAnnotationController()
|
||||
|
||||
#image controller
|
||||
me.imageController = me.editorSession.sessionController.getImageController()
|
||||
@imageController = @editorSession.sessionController.getImageController()
|
||||
#imageController.subscribe(gui.ImageController.enabledChanged, enableButtons)
|
||||
|
||||
#text controller
|
||||
me.textController = me.editorSession.sessionController.getTextController()
|
||||
@textController = @editorSession.sessionController.getTextController()
|
||||
|
||||
# zoom controller
|
||||
me.zoomHelper = me.editorSession.getOdfCanvas().getZoomHelper()
|
||||
me.zoomHelper.subscribe gui.ZoomHelper.signalZoomChanged, me.updateSlider
|
||||
me.updateSlider me.zoomHelper.getZoomLevel()
|
||||
@zoomHelper = @editorSession.getOdfCanvas().getZoomHelper()
|
||||
@zoomHelper.subscribe gui.ZoomHelper.signalZoomChanged, @updateSlider
|
||||
@updateSlider @zoomHelper.getZoomLevel()
|
||||
|
||||
# format controller
|
||||
me.editorSession.subscribe OpenPage.EditorSession.signalCommonStyleCreated, me.styleAdded
|
||||
@editorSession.subscribe OpenPage.EditorSession.signalCommonStyleCreated, @styleAdded
|
||||
|
||||
me.editorSession.sessionController.setUndoManager new gui.TrivialUndoManager()
|
||||
me.editorSession.sessionController.getUndoManager().subscribe gui.UndoManager.signalDocumentModifiedChanged, me.documentChanged
|
||||
me.editorSession.sessionController.getMetadataController().subscribe gui.MetadataController.signalMetadataChanged, me.metaChanged
|
||||
@editorSession.sessionController.setUndoManager new gui.TrivialUndoManager()
|
||||
@editorSession.sessionController.getUndoManager().subscribe gui.UndoManager.signalDocumentModifiedChanged, @documentChanged
|
||||
@editorSession.sessionController.getMetadataController().subscribe gui.MetadataController.signalMetadataChanged, @metaChanged
|
||||
op = new ops.OpAddMember()
|
||||
op.init {
|
||||
memberid: me.userid,
|
||||
memberid: @userid,
|
||||
setProperties:{
|
||||
"fullName": me.userid,
|
||||
"fullName": @userid,
|
||||
"color": "blue"
|
||||
}
|
||||
}
|
||||
me.session.enqueue([op])
|
||||
me.editorSession.sessionController.insertLocalCursor()
|
||||
me.editorSession.sessionController.startEditing()
|
||||
#console.log me.editorSession.getDeclaredFonts()
|
||||
@session.enqueue([op])
|
||||
@editorSession.sessionController.insertLocalCursor()
|
||||
@editorSession.sessionController.startEditing()
|
||||
@fontsize {data: @basictool.fontsize.value}
|
||||
#console.log @editorSession.getDeclaredFonts()
|
||||
#
|
||||
|
||||
initFontList: (list) ->
|
||||
v.text = v.name for v in list
|
||||
@resource.fonts = []
|
||||
@resource.fonts.push { text: v.text, name: v.family } for v in list
|
||||
@basictool.fonts.set "items", list
|
||||
@basictool.fonts.data = list
|
||||
|
||||
initStyles: (list) ->
|
||||
list.unshift {name:"", displayName: 'Default style' }
|
||||
v.text = v.displayName for v in list
|
||||
@resource.formats.push { text: v.text, name: v.name } for v in list
|
||||
@basictool.styles.set "items", list
|
||||
@basictool.styles.data = list
|
||||
|
||||
updateToolbar: (changes) ->
|
||||
# basic style
|
||||
(@basictool.bold.set "selected", changes.isBold) if changes.hasOwnProperty 'isBold'
|
||||
(@basictool.italic.set "selected", changes.isItalic) if changes.hasOwnProperty 'isItalic'
|
||||
(@basictool.underline.set "selected", changes.hasUnderline) if changes.hasOwnProperty 'hasUnderline'
|
||||
(@basictool.strike.set "selected", changes.hasStrikeThrough) if changes.hasOwnProperty 'hasStrikeThrough'
|
||||
(@basictool.fontsize.set "value", changes.fontSize) if changes.hasOwnProperty "fontSize"
|
||||
(@basictool.bold.selected = changes.isBold) if changes.hasOwnProperty 'isBold'
|
||||
(@basictool.italic.selected = changes.isItalic) if changes.hasOwnProperty 'isItalic'
|
||||
(@basictool.underline.selected = changes.hasUnderline) if changes.hasOwnProperty 'hasUnderline'
|
||||
(@basictool.strike.selected = changes.hasStrikeThrough) if changes.hasOwnProperty 'hasStrikeThrough'
|
||||
if changes.hasOwnProperty "fontSize"
|
||||
size = changes.fontSize
|
||||
size = 12 if size is undefined
|
||||
if @basictool.fontsize.value isnt size
|
||||
@basictool.fontsize.value = size
|
||||
|
||||
@selectFont changes.fontName if changes.hasOwnProperty "fontName"
|
||||
#pharagraph style
|
||||
@basictool.al.set "selected", changes.isAlignedLeft if changes.hasOwnProperty "isAlignedLeft"
|
||||
@basictool.ar.set "selected", changes.isAlignedRight if changes.hasOwnProperty "isAlignedRight"
|
||||
@basictool.ac.set "selected", changes.isAlignedCenter if changes.hasOwnProperty "isAlignedCenter"
|
||||
@basictool.aj.set "selected", changes.isAlignedJustified if changes.hasOwnProperty "isAlignedJustified"
|
||||
@basictool.al.selected = changes.isAlignedLeft if changes.hasOwnProperty "isAlignedLeft"
|
||||
@basictool.ar.selected = changes.isAlignedRight if changes.hasOwnProperty "isAlignedRight"
|
||||
@basictool.ac.selected = changes.isAlignedCenter if changes.hasOwnProperty "isAlignedCenter"
|
||||
@basictool.aj.selected = changes.isAlignedJustified if changes.hasOwnProperty "isAlignedJustified"
|
||||
|
||||
updateHyperlinkButtons: (e) ->
|
||||
selectedLinks = @editorSession.getSelectedHyperlinks()
|
||||
@basictool.unlink.set "enable", selectedLinks.length > 0
|
||||
@basictool.unlink.enable = selectedLinks.length > 0
|
||||
|
||||
selectFont: (name) ->
|
||||
items = @basictool.fonts.get "items"
|
||||
items = @basictool.fonts.data
|
||||
item = i for v, i in items when v.name is name
|
||||
@basictool.fonts.set "selected", item
|
||||
return unless item isnt undefined
|
||||
@basictool.fonts.selected = item
|
||||
|
||||
editorFocus: () ->
|
||||
@editorSession.sessionController.getEventManager().focus()
|
||||
|
||||
bold: (e) ->
|
||||
#console.log @, e
|
||||
@directFormattingCtl.setBold (not @basictool.bold.get "selected")
|
||||
@directFormattingCtl.setBold (not @basictool.bold.selected)
|
||||
|
||||
italic: (e) ->
|
||||
@directFormattingCtl.setItalic (not @basictool.italic.get "selected")
|
||||
@directFormattingCtl.setItalic (not @basictool.italic.selected)
|
||||
|
||||
underline: (e) ->
|
||||
@directFormattingCtl.setHasUnderline (not @basictool.underline.get "selected")
|
||||
@directFormattingCtl.setHasUnderline (not @basictool.underline.selected)
|
||||
|
||||
strike: (e) ->
|
||||
@directFormattingCtl.setHasStrikethrough (not @basictool.strike.get "selected")
|
||||
@directFormattingCtl.setHasStrikethrough (not @basictool.strike.selected)
|
||||
|
||||
fonts: (e) ->
|
||||
@directFormattingCtl.setFontName e.data.name
|
||||
@directFormattingCtl.setFontName e.data.item.data.name
|
||||
|
||||
fontsize: (e) ->
|
||||
@directFormattingCtl.setFontSize e
|
||||
# present the value change from enter infinity loop
|
||||
@directFormattingCtl.setFontSize e.data
|
||||
|
||||
al: (e) ->
|
||||
@directFormattingCtl.alignParagraphLeft()
|
||||
@ -335,7 +350,7 @@ class OpenPage extends this.OS.GUI.BaseApplication
|
||||
|
||||
link: (e) ->
|
||||
# get the link first
|
||||
me = @
|
||||
|
||||
textSerializer = new odf.TextSerializer()
|
||||
selection = @editorSession.getSelectedRange()
|
||||
linksInSelection = @editorSession.getSelectedHyperlinks()
|
||||
@ -356,23 +371,23 @@ class OpenPage extends this.OS.GUI.BaseApplication
|
||||
data.text = textSerializer.writeToString selection.cloneContents()
|
||||
else
|
||||
data.readonly = false
|
||||
@openDialog new HyperLinkDialog(), (d) ->
|
||||
selectionController = me.editorSession.sessionController.getSelectionController()
|
||||
@openDialog new HyperLinkDialog(), {title: "__(Insert/edit link)", data: data}
|
||||
.then (d) =>
|
||||
selectionController = @editorSession.sessionController.getSelectionController()
|
||||
if d.readonly
|
||||
# edit the existing link
|
||||
if d.action is "edit"
|
||||
selectedLinkRange = selection.cloneRange()
|
||||
selectedLinkRange.selectNode(linksInSelection[0])
|
||||
selectionController.selectRange(selectedLinkRange, true)
|
||||
me.hyperlinkController.removeHyperlinks()
|
||||
me.hyperlinkController.addHyperlink d.link
|
||||
@hyperlinkController.removeHyperlinks()
|
||||
@hyperlinkController.addHyperlink d.link
|
||||
else
|
||||
me.hyperlinkController.addHyperlink d.link, d.text
|
||||
linksInSelection = me.editorSession.getSelectedHyperlinks()
|
||||
@hyperlinkController.addHyperlink d.link, d.text
|
||||
linksInSelection = @editorSession.getSelectedHyperlinks()
|
||||
selectedLinkRange = selection.cloneRange()
|
||||
selectedLinkRange.selectNode(linksInSelection[0])
|
||||
selectionController.selectRange(selectedLinkRange, true)
|
||||
, "__(Insert/edit link)", data
|
||||
|
||||
unlink: (e) ->
|
||||
@hyperlinkController.removeHyperlinks()
|
||||
@ -384,21 +399,22 @@ class OpenPage extends this.OS.GUI.BaseApplication
|
||||
@editorSession.redo()
|
||||
|
||||
pathAsDataURL: (p) ->
|
||||
return new Promise (resolve, error) ->
|
||||
fp = p.asFileHandler()
|
||||
fp.read (data) ->
|
||||
return new Promise (resolve, error) =>
|
||||
fp = p.asFileHandle()
|
||||
fp.read("binary").then (data) =>
|
||||
blob = new Blob [data], { type: fp.info.mime }
|
||||
reader = new FileReader()
|
||||
reader.onloadend = () ->
|
||||
return error(p) if reader.readyState isnt 2
|
||||
reader.onloadend = () =>
|
||||
return error(@throwe __("Unable to load file {0}", p)) if reader.readyState isnt 2
|
||||
resolve {data: reader.result, fp: fp }
|
||||
reader.readAsDataURL blob
|
||||
, "binary"
|
||||
.catch (e) => error __e e
|
||||
|
||||
###
|
||||
if not isText
|
||||
|
||||
else
|
||||
fp.read (data) ->
|
||||
fp.read (data) =>
|
||||
# convert to base64
|
||||
b64 = btoa data
|
||||
dataurl = "data:#{fp.info.mime};base64," + b64
|
||||
@ -406,43 +422,44 @@ class OpenPage extends this.OS.GUI.BaseApplication
|
||||
###
|
||||
|
||||
image: (e) ->
|
||||
me = @
|
||||
@openDialog "FileDiaLog", (d, n, p) ->
|
||||
me.pathAsDataURL(p)
|
||||
.then (r) ->
|
||||
|
||||
@openDialog "FileDialog", { title: __("Select image file"), mimes: ["image/.*"] }
|
||||
.then (f) =>
|
||||
p = f.file.path
|
||||
@pathAsDataURL(p)
|
||||
.then (r) =>
|
||||
hiddenImage = new Image()
|
||||
hiddenImage.style.position = "absolute"
|
||||
hiddenImage.style.left = "-99999px"
|
||||
document.body.appendChild hiddenImage
|
||||
hiddenImage.onload = () ->
|
||||
hiddenImage.onload = () =>
|
||||
content = r.data.substring(r.data.indexOf(",") + 1)
|
||||
#insert image
|
||||
me.textController.removeCurrentSelection()
|
||||
me.imageController.insertImage r.fp.info.mime, content, hiddenImage.width, hiddenImage.height
|
||||
@textController.removeCurrentSelection()
|
||||
@imageController.insertImage r.fp.info.mime, content, hiddenImage.width, hiddenImage.height
|
||||
document.body.removeChild hiddenImage
|
||||
hiddenImage.src = r.data
|
||||
.catch () ->
|
||||
me.error __("Couldnt load image {0}", p)
|
||||
, __("Select image file"), { mimes: ["image/.*"] }
|
||||
.catch (e) =>
|
||||
@error __("Couldnt load image {0}", p), e
|
||||
|
||||
styles: (e) ->
|
||||
return if e.data.name is @currentStyle
|
||||
@editorSession.setCurrentParagraphStyle e.data.name
|
||||
return if e.data.item.data.name is @currentStyle
|
||||
@editorSession.setCurrentParagraphStyle e.data.item.data.name
|
||||
|
||||
zoom: (e) ->
|
||||
#console.log "zooming", e
|
||||
return unless @zoomHelper
|
||||
@zoomHelper.setZoomLevel e/100.0
|
||||
@zoomHelper.setZoomLevel e.data/100.0
|
||||
|
||||
format: (e) ->
|
||||
@openDialog new FormatDialog(), (d) ->
|
||||
@openDialog new FormatDialog(), { title: __("Add/Modify paragraph format"), data: @resource }
|
||||
.then (d) =>
|
||||
return
|
||||
, __("Add/Modify paragraph format"), @resource
|
||||
|
||||
closeDocument: (f) ->
|
||||
# finish editing
|
||||
return unless @editorSession and @session
|
||||
me = @
|
||||
|
||||
@eventSubscriptions.unsubscribeAll()
|
||||
@editorSession.sessionController.endEditing()
|
||||
@editorSession.sessionController.removeLocalCursor()
|
||||
@ -453,49 +470,49 @@ class OpenPage extends this.OS.GUI.BaseApplication
|
||||
}
|
||||
@session.enqueue [op]
|
||||
# close the session
|
||||
@session.close (e) ->
|
||||
return me.error __("Cannot close session {0}", e) if e
|
||||
me.editorSession.sessionController.getMetadataController().unsubscribe gui.MetadataController.signalMetadataChanged, me.metaChanged
|
||||
me.editorSession.sessionController.getUndoManager().unsubscribe gui.UndoManager.signalDocumentModifiedChanged, me.documentChanged
|
||||
me.directFormattingCtl.unsubscribe gui.DirectFormattingController.textStylingChanged, me.textStylingChanged
|
||||
me.directFormattingCtl.unsubscribe gui.DirectFormattingController.paragraphStylingChanged, me.textStylingChanged
|
||||
me.editorSession.unsubscribe OpenPage.EditorSession.signalParagraphChanged, me.paragrahStyleChanged
|
||||
me.zoomHelper.unsubscribe gui.ZoomHelper.signalZoomChanged, me.updateSlider
|
||||
me.editorSession.unsubscribe OpenPage.EditorSession.signalCommonStyleCreated, me.styleAdded
|
||||
@session.close (e) =>
|
||||
return @error __("Cannot close session {0}", e.toString()), e if e
|
||||
@editorSession.sessionController.getMetadataController().unsubscribe gui.MetadataController.signalMetadataChanged, @metaChanged
|
||||
@editorSession.sessionController.getUndoManager().unsubscribe gui.UndoManager.signalDocumentModifiedChanged, @documentChanged
|
||||
@directFormattingCtl.unsubscribe gui.DirectFormattingController.textStylingChanged, @textStylingChanged
|
||||
@directFormattingCtl.unsubscribe gui.DirectFormattingController.paragraphStylingChanged, @textStylingChanged
|
||||
@editorSession.unsubscribe OpenPage.EditorSession.signalParagraphChanged, @paragrahStyleChanged
|
||||
@zoomHelper.unsubscribe gui.ZoomHelper.signalZoomChanged, @updateSlider
|
||||
@editorSession.unsubscribe OpenPage.EditorSession.signalCommonStyleCreated, @styleAdded
|
||||
# destry editorSession
|
||||
me.editorSession.destroy (e) ->
|
||||
return me.error __("Cannot destroy editor session {0}", e) if e
|
||||
me.editorSession = undefined
|
||||
@editorSession.destroy (e) =>
|
||||
return @error __("Cannot destroy editor session {0}", e.toString()), e if e
|
||||
@editorSession = undefined
|
||||
# destroy session
|
||||
me.session.destroy (e) ->
|
||||
return me.error __("Cannot destroy document session {0}", e) if e
|
||||
core.Async.destroyAll [me.canvas.destroy], (e) ->
|
||||
return me.error __("Cannot destroy canvas {0}", e) if e
|
||||
me.notify "Document closed"
|
||||
@session.destroy (e) =>
|
||||
return @error __("Cannot destroy document session {0}", e.toString()), e if e
|
||||
core.Async.destroyAll [@canvas.destroy], (e) =>
|
||||
return @error __("Cannot destroy canvas {0}", e.toString()), e if e
|
||||
@notify "Document closed"
|
||||
f() if f
|
||||
me.session = undefined
|
||||
me.annotationController = undefined
|
||||
me.directFormattingCtl = undefined
|
||||
me.textController = undefined
|
||||
me.imageController = undefined
|
||||
me.ZoomHelper = undefined
|
||||
me.metaChanged = undefined
|
||||
me.documentChanged = undefined
|
||||
me.textStylingChanged = undefined
|
||||
me.paragrahStyleChanged = undefined
|
||||
me.updateSlider = undefined
|
||||
me.styleAdded = undefined
|
||||
me.basictool.fonts.set "selected", -1
|
||||
me.basictool.styles.set "selected", -1
|
||||
@session = undefined
|
||||
@annotationController = undefined
|
||||
@directFormattingCtl = undefined
|
||||
@textController = undefined
|
||||
@imageController = undefined
|
||||
@ZoomHelper = undefined
|
||||
@metaChanged = undefined
|
||||
@documentChanged = undefined
|
||||
@textStylingChanged = undefined
|
||||
@paragrahStyleChanged = undefined
|
||||
@updateSlider = undefined
|
||||
@styleAdded = undefined
|
||||
@basictool.fonts.selected = -1
|
||||
@basictool.styles.selected = -1
|
||||
|
||||
#
|
||||
|
||||
|
||||
cleanup: (e) ->
|
||||
me = @
|
||||
|
||||
if @editorSession
|
||||
e.preventDefault()
|
||||
me.closeDocument ()->
|
||||
me.quit()
|
||||
@closeDocument ()=>
|
||||
@quit()
|
||||
|
||||
this.OS.register "OpenPage", OpenPage
|
@ -7,10 +7,16 @@ afx-app-window[data-id="OpenPage"] div[data-id="container"]
|
||||
padding-top: 10px;
|
||||
padding-bottom: 10px;
|
||||
text-align: center;
|
||||
background-color: #f2f1f0;
|
||||
/*background-color: #f2f1f0;*/
|
||||
/*position: relative;*/
|
||||
}
|
||||
|
||||
afx-app-window[data-id="OpenPage"] office|body, office|document {
|
||||
background-color: white;
|
||||
color: black;
|
||||
background-image: none;
|
||||
user-select: text;
|
||||
overflow: visible;
|
||||
}
|
||||
/*
|
||||
@media screen, print, handheld, projection
|
||||
{
|
||||
@ -36,7 +42,8 @@ afx-app-window[data-id="OpenPage"] div[data-id="odfcanvas"]
|
||||
{
|
||||
cursor: text;
|
||||
margin:auto;
|
||||
box-shadow: 1px 1px 3px 3px #9f9F9F;
|
||||
/*box-shadow: 1px 1px 3px 3px #9f9F9F;*/
|
||||
border: 1px solid #2c2c2c;
|
||||
/*added*/
|
||||
transform-origin: top center;
|
||||
-webkit-transform-origin: top center;
|
||||
@ -47,24 +54,28 @@ afx-app-window[data-id="OpenPage"] div[data-id="odfcanvas"]
|
||||
|
||||
afx-app-window[data-id="OpenPage"] afx-hbox[data-id="toolbox"]
|
||||
{
|
||||
background-color: #f5f5f5;
|
||||
/*background-color: #f5f5f5;
|
||||
border: 1px solid #eaeaea;
|
||||
box-shadow: 3px 3px 3px #9f9F9F;
|
||||
box-shadow: 3px 3px 3px #9f9F9F;*/
|
||||
}
|
||||
afx-app-window[data-id="OpenPage"] afx-hbox[data-id="status-bar"]
|
||||
{
|
||||
background-color: #f5f5f5;
|
||||
/*background-color: #f5f5f5;
|
||||
border: 1px solid #eaeaea;
|
||||
box-shadow: -3px -3px 3px #9f9F9F;
|
||||
box-shadow: -3px -3px 3px #9f9F9F;*/
|
||||
}
|
||||
afx-app-window[data-id="OpenPage"] afx-hbox[data-id="toolbox"] afx-button button, afx-app-window[data-id="OpenPage"] afx-button[data-id="btzoomfix"] button
|
||||
{
|
||||
border: 1px solid #f5f5f5;
|
||||
background-color: transparent;
|
||||
/*border: 1px solid #f5f5f5;
|
||||
background-color: transparent;*/
|
||||
width:100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
afx-app-window[data-id="OpenPage"] button.selected {
|
||||
color:chocolate;
|
||||
}
|
||||
|
||||
afx-app-window[data-id="OpenPage"] afx-hbox[data-id="toolbox"] afx-button button:hover, afx-app-window[data-id="OpenPage"] afx-hbox[data-id="toolbox"] afx-button button.btactive, afx-app-window[data-id="OpenPage"] afx-button[data-id="btzoomfix"] button:hover
|
||||
{
|
||||
border: 1px solid #759DC0;
|
||||
|
@ -27,7 +27,7 @@
|
||||
/*define("webodf/editor/EditorSession", [
|
||||
"dojo/text!resources/fonts/fonts.css"
|
||||
],*/
|
||||
this.OS.APP.OpenPage.EditorSession = (function (fontsCSS) { // fontsCSS is retrieved as a string, using dojo's text retrieval AMD plugin
|
||||
this.OS.application.OpenPage.EditorSession = (function (fontsCSS) { // fontsCSS is retrieved as a string, using dojo's text retrieval AMD plugin
|
||||
"use strict";
|
||||
|
||||
runtime.loadClass("core.Async");
|
||||
|
@ -6,7 +6,7 @@
|
||||
"author": "Xuan Sang LE",
|
||||
"email": "xsang.le@gmail.com"
|
||||
},
|
||||
"version":"0.0.2-a",
|
||||
"version":"0.1.3-a",
|
||||
"category":"Other",
|
||||
"icon":"icon.png",
|
||||
"mimes":["application/vnd.oasis.opendocument.text"]
|
||||
|
@ -80,6 +80,15 @@
|
||||
"version": "0.0.6-a",
|
||||
"download": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/MarkOn/build/release/MarkOn.zip"
|
||||
},
|
||||
{
|
||||
"pkgname": "OpenPage",
|
||||
"name": "OpenPage",
|
||||
"description": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/OpenPage/README.md",
|
||||
"category": "Other",
|
||||
"author": "Xuan Sang LE",
|
||||
"version": "0.1.3-a",
|
||||
"download": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/OpenPage/build/release/OpenPage.zip"
|
||||
},
|
||||
{
|
||||
"pkgname": "Preview",
|
||||
"name": "Preview",
|
||||
|
Loading…
Reference in New Issue
Block a user