Add OpenPage release

This commit is contained in:
lxsang 2020-06-25 16:23:33 +00:00
parent eb26c964b2
commit 50159758a2
15 changed files with 407 additions and 3137 deletions

View File

@ -12,3 +12,7 @@
**Credit:** **Credit:**
OpenPage is heavily based on the WebODF javascript library: https://webodf.org 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.

View File

@ -22,7 +22,7 @@
<afx-button data-width = "25" data-id="btformat" iconclass = "fa fa-paint-brush"></afx-button> <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> <afx-list-view dropdown = "true" data-width="100" data-id="format-list"></afx-list-view>
<div data-width="5"></div> <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> <div data-width="5"></div>
<afx-list-view dropdown = "true" data-width="150" data-id="font-list"></afx-list-view> <afx-list-view dropdown = "true" data-width="150" data-id="font-list"></afx-list-view>
<div data-width="5"></div> <div data-width="5"></div>

Binary file not shown.

View File

@ -8,10 +8,16 @@ afx-app-window[data-id="OpenPage"] div[data-id="container"]
padding-top: 10px; padding-top: 10px;
padding-bottom: 10px; padding-bottom: 10px;
text-align: center; text-align: center;
background-color: #f2f1f0; /*background-color: #f2f1f0;*/
/*position: relative;*/ /*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 @media screen, print, handheld, projection
{ {
@ -37,7 +43,8 @@ afx-app-window[data-id="OpenPage"] div[data-id="odfcanvas"]
{ {
cursor: text; cursor: text;
margin:auto; margin:auto;
box-shadow: 1px 1px 3px 3px #9f9F9F; /*box-shadow: 1px 1px 3px 3px #9f9F9F;*/
border: 1px solid #2c2c2c;
/*added*/ /*added*/
transform-origin: top center; transform-origin: top center;
-webkit-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"] afx-app-window[data-id="OpenPage"] afx-hbox[data-id="toolbox"]
{ {
background-color: #f5f5f5; /*background-color: #f5f5f5;
border: 1px solid #eaeaea; 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"] afx-app-window[data-id="OpenPage"] afx-hbox[data-id="status-bar"]
{ {
background-color: #f5f5f5; /*background-color: #f5f5f5;
border: 1px solid #eaeaea; 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 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; /*border: 1px solid #f5f5f5;
background-color: transparent; background-color: transparent;*/
width:100%; width:100%;
height: 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 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; border: 1px solid #759DC0;

File diff suppressed because one or more lines are too long

View File

@ -6,7 +6,7 @@
"author": "Xuan Sang LE", "author": "Xuan Sang LE",
"email": "xsang.le@gmail.com" "email": "xsang.le@gmail.com"
}, },
"version":"0.0.2-a", "version":"0.1.3-a",
"category":"Other", "category":"Other",
"icon":"icon.png", "icon":"icon.png",
"mimes":["application/vnd.oasis.opendocument.text"] "mimes":["application/vnd.oasis.opendocument.text"]

View File

@ -22,7 +22,7 @@
<afx-button data-width = "25" data-id="btformat" iconclass = "fa fa-paint-brush"></afx-button> <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> <afx-list-view dropdown = "true" data-width="100" data-id="format-list"></afx-list-view>
<div data-width="5"></div> <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> <div data-width="5"></div>
<afx-list-view dropdown = "true" data-width="150" data-id="font-list"></afx-list-view> <afx-list-view dropdown = "true" data-width="150" data-id="font-list"></afx-list-view>
<div data-width="5"></div> <div data-width="5"></div>

Binary file not shown.

View File

@ -1,43 +1,60 @@
class HyperLinkDialog extends this.OS.GUI.BasicDialog class HyperLinkDialog extends this.OS.GUI.BasicDialog
constructor: () -> constructor: () ->
super "HyperLinkDialog", { super "HyperLinkDialog", HyperLinkDialog.scheme
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)
}
class FormatDialog extends this.OS.GUI.BaseDialog
constructor: () ->
super "FormatDialog"
init: () ->
@_gui.htmlToScheme FormatDialog.scheme, @, @host
main: () -> 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 = @ui =
aligment: aligment:
left:@find("swleft"), left:@find("swleft"),
@ -99,64 +116,68 @@ class FormatDialog extends this.OS.GUI.BaseDialog
size: 12 size: 12
initUIEvent: () -> initUIEvent: () ->
me = @
set = (e, o, k ,f) -> set = (e, o, k ,f) =>
me.ui[o][k].set e, (r) -> @ui[o][k][e] = (r) =>
v = r v = r
v = f r if f v = f r if f
me.currentStyle[o][k] = v @currentStyle[o][k] = v
me.previewStyle() @previewStyle()
for k,v of @ui.aligment 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 for k,v of @ui.spacing
set "onchange", "spacing", k set "onvaluechange", "spacing", k, ((e) => e.data)
for k,v of @ui.padding for k,v of @ui.padding
set "onchange", "padding", k set "onvaluechange", "padding", k, ((e) => e.data)
for k,v of @ui.style for k,v of @ui.style
set "onchange", "style", k, ((e) -> e.data) if k isnt "color" and k isnt "bgcolor" set "onswchange", "style", k, ((e) => e.data) if k isnt "color" and k isnt "bgcolor"
set "onchange", "font", "size" set "onvaluechange", "font", "size"
$(@ui.style.color).click (e) -> $(@ui.style.color).click (e) =>
me.openDialog "ColorPickerDialog", (d) -> @openDialog "ColorPickerDialog"
me.currentStyle.style.color = d .then (d) =>
me.previewStyle() @currentStyle.style.color = d
$(@ui.style.bgcolor).click (e) -> @previewStyle()
me.openDialog "ColorPickerDialog", (d) -> $(@ui.style.bgcolor).click (e) =>
me.currentStyle.style.bgcolor = d @openDialog "ColorPickerDialog"
me.previewStyle() .then (d) =>
@currentStyle.style.bgcolor = d
@previewStyle()
#font #font
@ui.font.family.set "items", @data.fonts if @data and @data.fonts @ui.font.family.data = @data.data.fonts if @data.data and @data.data.fonts
set "onlistselect", "font", "family", ( (e) -> e.data) set "onlistselect", "font", "family", ( (e) => e.data.item.data)
#format list #format list
@ui.formats.set "selected", -1 @ui.formats.selected = -1
@ui.formats.set "items", @data.formats if @data and @data.formats @ui.formats.data = @data.data.formats if @data.data and @data.data.formats
@ui.formats.set "onlistselect", (e) -> @ui.formats.onlistselect = (e) =>
me.fromODFStyleFormat e.data @fromODFStyleFormat e.data.item.data
@ui.formats.set "selected", 0 @ui.formats.selected = 0
(@find "btok").set "onbtclick", (e) -> (@find "btok").onbtclick = (e) =>
me.saveCurrentStyle() @saveCurrentStyle()
(@find "btx").set "onbtclick", (e) -> (@find "btx").onbtclick = (e) =>
me.quit() @quit()
(@find "bt-clone").set "onbtclick", (e) -> (@find "bt-clone").onbtclick = (e) =>
me.clone() @clone()
clone: ()-> clone: ()->
me = @
selected = @ui.formats.get "selected" selected = @ui.formats.selectedItem
return unless selected return unless selected
@openDialog "PromptDialog", (d) -> selected = selected.data
return me.notify __("Abort: no style name is specified") unless d and d.trim() isnt "" @openDialog "PromptDialog", { title: __("Clone style: {0}", selected.text), label: __("New style name:") }
newstyle = me.parent.editorSession.cloneParagraphStyle selected.name, d .then (d) =>
me.ui.formats.push { text:d, name: newstyle } return @notify __("Abort: no style name is specified") unless d and d.trim() isnt ""
me.ui.formats.set "selected", ((me.ui.formats.get 'count') - 1) newstyle = @parent.editorSession.cloneParagraphStyle selected.name, d
me.notify __("New style: {0} added", newstyle) @ui.formats.push { text:d, name: newstyle }
, __("Clone style: {0}", selected.text), { label: __("New style name:") } @ui.formats.selected = (@ui.formats.data.length - 1)
@notify __("New style: {0} added", newstyle)
saveCurrentStyle: () -> saveCurrentStyle: () ->
selected = @ui.formats.get "selected" selected = @ui.formats.selectedItem
return unless selected return unless selected
selected = selected.data
odfs = odfs =
"style:paragraph-properties": "style:paragraph-properties":
"fo:margin-top": @currentStyle.spacing.top + "mm" "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) @notify __("Paragraph format [{0}] is saved", selected.text)
fromODFStyleFormat: (odfs) -> fromODFStyleFormat: (odfs) ->
me = @
@initStyleObject() @initStyleObject()
cssUnits = new core.CSSUnits() cssUnits = new core.CSSUnits()
findFont = (name) -> findFont = (name) =>
items = me.ui.font.family.get "items" items = @ui.font.family.data
item = v for v in items when v.text is name item = v for v in items when v.text is name
return undefined unless item return undefined unless item
return item return item
@ -216,34 +237,34 @@ class FormatDialog extends this.OS.GUI.BaseDialog
previewStyle: () -> previewStyle: () ->
#console.log "previewing" #console.log "previewing"
# reset ui # reset ui
@ui.aligment.left.set "swon", @currentStyle.aligment.left @ui.aligment.left.swon = @currentStyle.aligment.left
@ui.aligment.right.set "swon", @currentStyle.aligment.right @ui.aligment.right.swon = @currentStyle.aligment.right
@ui.aligment.center.set "swon", @currentStyle.aligment.center @ui.aligment.center.swon = @currentStyle.aligment.center
@ui.aligment.justify.set "swon", @currentStyle.aligment.justify @ui.aligment.justify.swon = @currentStyle.aligment.justify
@ui.spacing.left.set "value", @currentStyle.spacing.left @ui.spacing.left.value = @currentStyle.spacing.left
@ui.spacing.right.set "value", @currentStyle.spacing.right @ui.spacing.right.value = @currentStyle.spacing.right
@ui.spacing.top.set "value", @currentStyle.spacing.top @ui.spacing.top.value = @currentStyle.spacing.top
@ui.spacing.bottom.set "value", @currentStyle.spacing.bottom @ui.spacing.bottom.value = @currentStyle.spacing.bottom
@ui.spacing.lineheight.set "value", @currentStyle.spacing.lineheight @ui.spacing.lineheight.value = @currentStyle.spacing.lineheight
@ui.padding.left.set "value", @currentStyle.padding.left @ui.padding.left.value = @currentStyle.padding.left
@ui.padding.right.set "value", @currentStyle.padding.right @ui.padding.right.value = @currentStyle.padding.right
@ui.padding.top.set "value", @currentStyle.padding.top @ui.padding.top.value = @currentStyle.padding.top
@ui.padding.bottom.set "value", @currentStyle.padding.bottom @ui.padding.bottom.value = @currentStyle.padding.bottom
@ui.style.bold.set "swon", @currentStyle.style.bold @ui.style.bold.swon = @currentStyle.style.bold
@ui.style.italic.set "swon", @currentStyle.style.italic @ui.style.italic.swon = @currentStyle.style.italic
@ui.style.underline.set "swon", @currentStyle.style.underline @ui.style.underline.swon = @currentStyle.style.underline
@ui.font.size.set "value", @currentStyle.font.size @ui.font.size.value = @currentStyle.font.size
#console.log @currentStyle #console.log @currentStyle
if @currentStyle.font.family 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 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.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 # set the preview css
el = $ @preview el = $ @preview
el.css "text-align", if @currentStyle.aligment.selected then @currentStyle.aligment.selected else "left" 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"> <afx-hbox data-height="23" data-id="spacingbox">
<div ></div> <div ></div>
<afx-label data-width="50" text="__(Left:)"></afx-label> <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> <div></div>
<afx-label data-width="50" text="__(Right:)"></afx-label> <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> <div></div>
<afx-label data-width="50" text="__(Top:)"></afx-label> <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> <div></div>
<afx-label data-width="50" text="__(Bottom:)"></afx-label> <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> <div ></div>
</afx-hbox> </afx-hbox>
<div data-height="5"></div> <div data-height="5"></div>
@ -319,16 +340,16 @@ FormatDialog.scheme = """
<afx-hbox data-height="23" data-id="spacingbox"> <afx-hbox data-height="23" data-id="spacingbox">
<div ></div> <div ></div>
<afx-label data-width="50" text="__(Left:)"></afx-label> <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> <div></div>
<afx-label data-width="50" text="__(Right:)"></afx-label> <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> <div></div>
<afx-label data-width="50" text="__(Top:)"></afx-label> <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> <div></div>
<afx-label data-width="50" text="__(Bottom:)"></afx-label> <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> <div ></div>
</afx-hbox> </afx-hbox>
@ -358,7 +379,7 @@ FormatDialog.scheme = """
<afx-list-view data-id="lstfont" dropdown = "true"></afx-list-view> <afx-list-view data-id="lstfont" dropdown = "true"></afx-list-view>
<div data-width="5" ></div> <div data-width="5" ></div>
<afx-label data-width="35" text="__(Size:)"></afx-label> <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> <div data-width="5" ></div>
<afx-label data-width="80" text="__(Line Height:)"></afx-label> <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> <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> <div data-height="5"></div>
<afx-hbox> <afx-hbox>
<div data-width="5"></div> <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> <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>
<div data-width="5"></div> <div data-width="5"></div>

View File

@ -1,4 +1,4 @@
class OpenPage extends this.OS.GUI.BaseApplication class OpenPage extends this.OS.application.BaseApplication
constructor: ( args ) -> constructor: ( args ) ->
super "OpenPage", args super "OpenPage", args
@ -7,52 +7,55 @@ class OpenPage extends this.OS.GUI.BaseApplication
#if not OpenPage.EditorSession #if not OpenPage.EditorSession
# require ["webodf/editor/EditorSession"], (ES) -> # require ["webodf/editor/EditorSession"], (ES) ->
# OpenPage.EditorSession = ES # OpenPage.EditorSession = ES
me =@
@eventSubscriptions = new core.EventSubscriptions() @eventSubscriptions = new core.EventSubscriptions()
@initToolbox() @initToolbox()
@userid = "#{@systemsetting.user.username}@#{@pid}" @userid = "#{@systemsetting.user.username}@#{@pid}"
#file = "home://welcome.odt" #file = "home://welco@odt"
#file = "#{@_api.handler.get}/home://welcome.odt" #file = "#{@_api.handler.get}/home://welcome.odt"
#@canvas.load file #@canvas.load file
#odfContainer = new odf.OdfContainer file, (c) -> #odfContainer = new odf.OdfContainer file, (c) ->
# me.canvas.setOdfContainer c, false # @canvas.setOdfContainer c, false
@currentStyle = "" @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 = @resource =
fonts: [] fonts: []
formats: [] formats: []
@bindKey "ALT-N", () -> me.actionFile "#{me.name}-New" @bindKey "ALT-N", () => @actionFile "#{@name}-New"
@bindKey "ALT-O", () -> me.actionFile "#{me.name}-Open" @bindKey "ALT-O", () => @actionFile "#{@name}-Open"
@bindKey "CTRL-S", () -> me.actionFile "#{me.name}-Save" @bindKey "CTRL-S", () => @actionFile "#{@name}-Save"
@bindKey "ALT-W", () -> me.actionFile "#{me.name}-Saveas" @bindKey "ALT-W", () => @actionFile "#{@name}-Saveas"
menu: () -> menu: () ->
me = @
menu = [{ menu = [{
text: "__(File)", text: "__(File)",
child: [ nodes: [
{ text: "__(New)", dataid: "#{@name}-New", shortcut: "A-N" }, { text: "__(New)", dataid: "#{@name}-New", shortcut: "A-N" },
{ text: "__(Open)", dataid: "#{@name}-Open", shortcut: "A-O" }, { text: "__(Open)", dataid: "#{@name}-Open", shortcut: "A-O" },
{ text: "__(Save)", dataid: "#{@name}-Save", shortcut: "C-S" }, { text: "__(Save)", dataid: "#{@name}-Save", shortcut: "C-S" },
{ text: "__(Save as)", dataid: "#{@name}-Saveas", shortcut: "A-W" } { 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 menu
actionFile: (e) -> actionFile: (e) ->
me = @
saveas = () -> saveas = () =>
me.openDialog "FileDiaLog", (d, n, p) -> @openDialog "FileDialog", { title: __("Save as"), file: @currfile }
me.currfile.setPath "#{d}/#{n}" .then (f) =>
me.save() d = f.file.path.asFileHandle()
, __("Save as"), { file: me.currfile } d = d.parent() if f.file.type is "file"
@currfile.setPath "#{d.path}/#{f.name}"
@save()
switch e switch e
when "#{@name}-Open" when "#{@name}-Open"
@openDialog "FileDiaLog", ( d, f , p) -> @openDialog "FileDialog", { title: __("Open file"), mimes: @meta().mimes }
me.open p .then (f) =>
, __("Open file"), { mimes: me.meta().mimes } @open f.file.path
when "#{@name}-Save" when "#{@name}-Save"
#@currfile.cache = @editor.value() #@currfile.cache = @editor.value()
return @save() if @currfile.basename return @save() if @currfile.basename
@ -68,39 +71,41 @@ class OpenPage extends this.OS.GUI.BaseApplication
@open blank, true @open blank, true
open: (p,b) -> open: (p,b) ->
me = @
@pathAsDataURL(p) @pathAsDataURL(p)
.then (r) -> .then (r) =>
me.closeDocument() if me.editorSession @closeDocument() if @editorSession
me.initCanvas() @initCanvas()
OdfContainer = new odf.OdfContainer r.data, (c) -> OdfContainer = new odf.OdfContainer r.data, (c) =>
me.canvas.setOdfContainer c, false @canvas.setOdfContainer c, false
return me.currfile = "Untitled".asFileHandler() if b return @currfile = "Untitled".asFileHandle() if b
if me.currfile then me.currfile.setPath p else me.currfile = p.asFileHandler() if @currfile then @currfile.setPath p else @currfile = p.asFileHandle()
me.scheme.set "apptitle", me.currfile.basename @scheme.apptitle = @currfile.basename
me.notify __("File {0} opened", p) @notify __("File {0} opened", p)
.catch (e) -> .catch (e) =>
me.error __("Problem read file {0}", e) @error __("Problem read file {0}", e.toString()), e
save: () -> save: () ->
me = @
return unless @editorSession return unless @editorSession
container = @canvas.odfContainer() container = @canvas.odfContainer()
return @error __("No document container found") unless container return @error __("No document container found") unless container
container.createByteArray (ba) -> container.createByteArray (ba) =>
# create blob # create blob
me.currfile.cache = new Blob [ba], { type: "application/vnd.oasis.opendocument.text" } @currfile.cache = new Blob [ba], { type: "application/vnd.oasis.opendocument.text" }
me.currfile.write "application/vnd.oasis.opendocument.text", (r) -> @currfile.write "application/vnd.oasis.opendocument.text"
return me.error __("Cannot save file: {0}", r.error) if r.error .then (r) =>
me.notify __("File {0} saved", me.currfile.basename) @notify __("File {0} saved", @currfile.basename)
me.scheme.set "apptitle", me.currfile.basename @scheme.apptitle = @currfile.basename
me.currfile.dirty = false @currfile.dirty = false
me.editorFocus() @editorFocus()
, (err) -> .catch (e) =>
@error __("Cannot create byte array from container: {0}", err|| "") @error __("Cannot save file: {0}", e.toString()), e
, (err) =>
@error __("Cannot create byte array from container: {0}", err.toString() || ""), err
initToolbox: () -> initToolbox: () ->
me = @
@basictool = @basictool =
undo: @find("btundo"), undo: @find("btundo"),
redo: @find("btredo"), redo: @find("btredo"),
@ -124,76 +129,77 @@ class OpenPage extends this.OS.GUI.BaseApplication
zoom: @find("slzoom") zoom: @find("slzoom")
format: @find("btformat") format: @find("btformat")
fn = (name, el) -> fn = (name, el) =>
if name is "fonts" or name is "styles" if name is "fonts" or name is "styles"
act = "onlistselect" act = "onlistselect"
else if name is "fontsize" or name is "zoom" else if name is "fontsize" or name is "zoom"
act = "onchange" act = "onvaluechange"
else else
act = "onbtclick" act = "onbtclick"
el.set act, (e) -> el[act] = (e) =>
return unless me.directFormattingCtl return unless @directFormattingCtl
return unless me[name] return unless @[name]
me[name](e) @[name](e)
me.editorFocus() @editorFocus()
for name, el of @basictool for name, el of @basictool
fn name, el fn name, el
(@find "btzoomfix").set "onbtclick", (e) -> me.zoom 100 (@find "btzoomfix").onbtclick = (e) => @zoom { data: 100 }
@basictool.zoom.set "onchanging", (e) -> @basictool.zoom.onvaluechanging = (e) =>
zlb = me.find "lbzoom" zlb = @find "lbzoom"
zlb.set "text", Math.floor(e) + "%" zlb.text = Math.floor(e.data) + "%"
initCanvas: () -> initCanvas: () ->
el = @find "odfcanvas" el = @find "odfcanvas"
me = @
el.setAttribute "translate", "no" el.setAttribute "translate", "no"
el.classList.add "notranslate" el.classList.add "notranslate"
@canvas = new odf.OdfCanvas(el) @canvas = new odf.OdfCanvas(el)
@documentChanged = (e) -> @documentChanged = (e) =>
return if me.currfile.dirty return if @currfile.dirty
me.currfile.dirty = true @currfile.dirty = true
me.scheme.set "apptitle", me.currfile.basename + "*" @scheme.apptitle = @currfile.basename + "*"
#console.log e #console.log e
@metaChanged = (e) -> @metaChanged = (e) =>
return if me.currfile.dirty return if @currfile.dirty
me.currfile.dirty = true @currfile.dirty = true
me.scheme.set "apptitle", me.currfile.basename + "*" @scheme.apptitle = @currfile.basename + "*"
#console.log e #console.log e
@textStylingChanged = (e) -> @textStylingChanged = (e) =>
me.updateToolbar e @updateToolbar e
@paragrahStyleChanged = (e) -> @paragrahStyleChanged = (e) =>
return unless e.type is "style" 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 item = i for v, i in items when v.name is e.styleName
me.currentStyle = e.styleName return unless item isnt undefined
me.basictool.styles.set "selected", item @currentStyle = e.styleName
@basictool.styles.selected = item
@styleAdded = (e) -> @styleAdded = (e) =>
return unless e.family is 'paragraph' 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 item = v for v in items when v.name is e.name
return if item return if item
stylens = "urn:oasis:names:tc:opendocument:xmlns:style:1.0" 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' dtext = el.getAttributeNS stylens, 'display-name'
me.basictool.styles.push { text: dtext , name: e.name }, true @basictool.styles.push { text: dtext , name: e.name }, true
#me.resource.formats.push {text: dtext, name:e.name} #@resource.formats.push {text: dtext, name:e.name}
@updateSlider = (v) -> @updateSlider = (v) =>
value = Math.floor v*100 value = Math.floor v*100
me.basictool.zoom.set "value", value @basictool.zoom.value = value
zlb = me.find "lbzoom" zlb = @find "lbzoom"
zlb.set "text", value+"%" zlb.text = value + "%"
#me.canvas.enableAnnotations true, true @canvas.enableAnnotations true, true
@canvas.addListener "statereadychange", ()-> @canvas.addListener "statereadychange", ()=>
me.session = new ops.Session(me.canvas) @session = new ops.Session(@canvas)
viewOptions = viewOptions =
editInfoMarkersInitiallyVisible: false, editInfoMarkersInitiallyVisible: false,
caretAvatarsInitiallyVisible: false, caretAvatarsInitiallyVisible: false,
caretBlinksOnRangeSelect: true caretBlinksOnRangeSelect: true
me.editorSession = new OpenPage.EditorSession(me.session,me.userid, { @editorSession = new OpenPage.EditorSession(@session,@userid, {
viewOptions: viewOptions, viewOptions: viewOptions,
directTextStylingEnabled: true, directTextStylingEnabled: true,
directParagraphStylingEnabled: true, directParagraphStylingEnabled: true,
@ -205,112 +211,121 @@ class OpenPage extends this.OS.GUI.BaseApplication
zoomingEnabled: true, zoomingEnabled: true,
reviewModeEnabled: false reviewModeEnabled: false
}) })
me.initFontList me.editorSession.getDeclaredFonts() @initFontList @editorSession.getDeclaredFonts()
me.initStyles me.editorSession.getAvailableParagraphStyles() @initStyles @editorSession.getAvailableParagraphStyles()
#fix annotation problem on canvas #fix annotation problem on canvas
#console.log $("office:body").css "background-color", "red" #console.log $("office:body").css "background-color", "red"
# basic format # basic format
me.directFormattingCtl = me.editorSession.sessionController.getDirectFormattingController() @directFormattingCtl = @editorSession.sessionController.getDirectFormattingController()
me.directFormattingCtl.subscribe gui.DirectFormattingController.textStylingChanged, me.textStylingChanged @directFormattingCtl.subscribe gui.DirectFormattingController.textStylingChanged, @textStylingChanged
me.directFormattingCtl.subscribe gui.DirectFormattingController.paragraphStylingChanged, me.textStylingChanged @directFormattingCtl.subscribe gui.DirectFormattingController.paragraphStylingChanged, @textStylingChanged
me.editorSession.subscribe OpenPage.EditorSession.signalParagraphChanged, me.paragrahStyleChanged @editorSession.subscribe OpenPage.EditorSession.signalParagraphChanged, @paragrahStyleChanged
# hyper link controller # hyper link controller
me.hyperlinkController = me.editorSession.sessionController.getHyperlinkController() @hyperlinkController = @editorSession.sessionController.getHyperlinkController()
me.eventSubscriptions.addFrameSubscription me.editorSession, OpenPage.EditorSession.signalCursorMoved, ()-> me.updateHyperlinkButtons() @eventSubscriptions.addFrameSubscription @editorSession, OpenPage.EditorSession.signalCursorMoved, ()=> @updateHyperlinkButtons()
me.eventSubscriptions.addFrameSubscription me.editorSession, OpenPage.EditorSession.signalParagraphChanged, ()-> me.updateHyperlinkButtons() @eventSubscriptions.addFrameSubscription @editorSession, OpenPage.EditorSession.signalParagraphChanged, ()=> @updateHyperlinkButtons()
me.eventSubscriptions.addFrameSubscription me.editorSession, OpenPage.EditorSession.signalParagraphStyleModified, ()-> me.updateHyperlinkButtons() @eventSubscriptions.addFrameSubscription @editorSession, OpenPage.EditorSession.signalParagraphStyleModified, ()=> @updateHyperlinkButtons()
#annotation controller #annotation controller
me.annotationController = me.editorSession.sessionController.getAnnotationController() @annotationController = @editorSession.sessionController.getAnnotationController()
#image controller #image controller
me.imageController = me.editorSession.sessionController.getImageController() @imageController = @editorSession.sessionController.getImageController()
#imageController.subscribe(gui.ImageController.enabledChanged, enableButtons) #imageController.subscribe(gui.ImageController.enabledChanged, enableButtons)
#text controller #text controller
me.textController = me.editorSession.sessionController.getTextController() @textController = @editorSession.sessionController.getTextController()
# zoom controller # zoom controller
me.zoomHelper = me.editorSession.getOdfCanvas().getZoomHelper() @zoomHelper = @editorSession.getOdfCanvas().getZoomHelper()
me.zoomHelper.subscribe gui.ZoomHelper.signalZoomChanged, me.updateSlider @zoomHelper.subscribe gui.ZoomHelper.signalZoomChanged, @updateSlider
me.updateSlider me.zoomHelper.getZoomLevel() @updateSlider @zoomHelper.getZoomLevel()
# format controller # format controller
me.editorSession.subscribe OpenPage.EditorSession.signalCommonStyleCreated, me.styleAdded @editorSession.subscribe OpenPage.EditorSession.signalCommonStyleCreated, @styleAdded
me.editorSession.sessionController.setUndoManager new gui.TrivialUndoManager() @editorSession.sessionController.setUndoManager new gui.TrivialUndoManager()
me.editorSession.sessionController.getUndoManager().subscribe gui.UndoManager.signalDocumentModifiedChanged, me.documentChanged @editorSession.sessionController.getUndoManager().subscribe gui.UndoManager.signalDocumentModifiedChanged, @documentChanged
me.editorSession.sessionController.getMetadataController().subscribe gui.MetadataController.signalMetadataChanged, me.metaChanged @editorSession.sessionController.getMetadataController().subscribe gui.MetadataController.signalMetadataChanged, @metaChanged
op = new ops.OpAddMember() op = new ops.OpAddMember()
op.init { op.init {
memberid: me.userid, memberid: @userid,
setProperties:{ setProperties:{
"fullName": me.userid, "fullName": @userid,
"color": "blue" "color": "blue"
} }
} }
me.session.enqueue([op]) @session.enqueue([op])
me.editorSession.sessionController.insertLocalCursor() @editorSession.sessionController.insertLocalCursor()
me.editorSession.sessionController.startEditing() @editorSession.sessionController.startEditing()
#console.log me.editorSession.getDeclaredFonts() @fontsize {data: @basictool.fontsize.value}
#console.log @editorSession.getDeclaredFonts()
# #
initFontList: (list) -> initFontList: (list) ->
v.text = v.name for v in list v.text = v.name for v in list
@resource.fonts = []
@resource.fonts.push { text: v.text, name: v.family } for v in list @resource.fonts.push { text: v.text, name: v.family } for v in list
@basictool.fonts.set "items", list @basictool.fonts.data = list
initStyles: (list) -> initStyles: (list) ->
list.unshift {name:"", displayName: 'Default style' } list.unshift {name:"", displayName: 'Default style' }
v.text = v.displayName for v in list v.text = v.displayName for v in list
@resource.formats.push { text: v.text, name: v.name } 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) -> updateToolbar: (changes) ->
# basic style # basic style
(@basictool.bold.set "selected", changes.isBold) if changes.hasOwnProperty 'isBold' (@basictool.bold.selected = changes.isBold) if changes.hasOwnProperty 'isBold'
(@basictool.italic.set "selected", changes.isItalic) if changes.hasOwnProperty 'isItalic' (@basictool.italic.selected = changes.isItalic) if changes.hasOwnProperty 'isItalic'
(@basictool.underline.set "selected", changes.hasUnderline) if changes.hasOwnProperty 'hasUnderline' (@basictool.underline.selected = changes.hasUnderline) if changes.hasOwnProperty 'hasUnderline'
(@basictool.strike.set "selected", changes.hasStrikeThrough) if changes.hasOwnProperty 'hasStrikeThrough' (@basictool.strike.selected = changes.hasStrikeThrough) if changes.hasOwnProperty 'hasStrikeThrough'
(@basictool.fontsize.set "value", changes.fontSize) if changes.hasOwnProperty "fontSize" 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" @selectFont changes.fontName if changes.hasOwnProperty "fontName"
#pharagraph style #pharagraph style
@basictool.al.set "selected", changes.isAlignedLeft if changes.hasOwnProperty "isAlignedLeft" @basictool.al.selected = changes.isAlignedLeft if changes.hasOwnProperty "isAlignedLeft"
@basictool.ar.set "selected", changes.isAlignedRight if changes.hasOwnProperty "isAlignedRight" @basictool.ar.selected = changes.isAlignedRight if changes.hasOwnProperty "isAlignedRight"
@basictool.ac.set "selected", changes.isAlignedCenter if changes.hasOwnProperty "isAlignedCenter" @basictool.ac.selected = changes.isAlignedCenter if changes.hasOwnProperty "isAlignedCenter"
@basictool.aj.set "selected", changes.isAlignedJustified if changes.hasOwnProperty "isAlignedJustified" @basictool.aj.selected = changes.isAlignedJustified if changes.hasOwnProperty "isAlignedJustified"
updateHyperlinkButtons: (e) -> updateHyperlinkButtons: (e) ->
selectedLinks = @editorSession.getSelectedHyperlinks() selectedLinks = @editorSession.getSelectedHyperlinks()
@basictool.unlink.set "enable", selectedLinks.length > 0 @basictool.unlink.enable = selectedLinks.length > 0
selectFont: (name) -> selectFont: (name) ->
items = @basictool.fonts.get "items" items = @basictool.fonts.data
item = i for v, i in items when v.name is name 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: () -> editorFocus: () ->
@editorSession.sessionController.getEventManager().focus() @editorSession.sessionController.getEventManager().focus()
bold: (e) -> bold: (e) ->
#console.log @, e #console.log @, e
@directFormattingCtl.setBold (not @basictool.bold.get "selected") @directFormattingCtl.setBold (not @basictool.bold.selected)
italic: (e) -> italic: (e) ->
@directFormattingCtl.setItalic (not @basictool.italic.get "selected") @directFormattingCtl.setItalic (not @basictool.italic.selected)
underline: (e) -> underline: (e) ->
@directFormattingCtl.setHasUnderline (not @basictool.underline.get "selected") @directFormattingCtl.setHasUnderline (not @basictool.underline.selected)
strike: (e) -> strike: (e) ->
@directFormattingCtl.setHasStrikethrough (not @basictool.strike.get "selected") @directFormattingCtl.setHasStrikethrough (not @basictool.strike.selected)
fonts: (e) -> fonts: (e) ->
@directFormattingCtl.setFontName e.data.name @directFormattingCtl.setFontName e.data.item.data.name
fontsize: (e) -> fontsize: (e) ->
@directFormattingCtl.setFontSize e # present the value change from enter infinity loop
@directFormattingCtl.setFontSize e.data
al: (e) -> al: (e) ->
@directFormattingCtl.alignParagraphLeft() @directFormattingCtl.alignParagraphLeft()
@ -335,7 +350,7 @@ class OpenPage extends this.OS.GUI.BaseApplication
link: (e) -> link: (e) ->
# get the link first # get the link first
me = @
textSerializer = new odf.TextSerializer() textSerializer = new odf.TextSerializer()
selection = @editorSession.getSelectedRange() selection = @editorSession.getSelectedRange()
linksInSelection = @editorSession.getSelectedHyperlinks() linksInSelection = @editorSession.getSelectedHyperlinks()
@ -356,23 +371,23 @@ class OpenPage extends this.OS.GUI.BaseApplication
data.text = textSerializer.writeToString selection.cloneContents() data.text = textSerializer.writeToString selection.cloneContents()
else else
data.readonly = false data.readonly = false
@openDialog new HyperLinkDialog(), (d) -> @openDialog new HyperLinkDialog(), {title: "__(Insert/edit link)", data: data}
selectionController = me.editorSession.sessionController.getSelectionController() .then (d) =>
selectionController = @editorSession.sessionController.getSelectionController()
if d.readonly if d.readonly
# edit the existing link # edit the existing link
if d.action is "edit" if d.action is "edit"
selectedLinkRange = selection.cloneRange() selectedLinkRange = selection.cloneRange()
selectedLinkRange.selectNode(linksInSelection[0]) selectedLinkRange.selectNode(linksInSelection[0])
selectionController.selectRange(selectedLinkRange, true) selectionController.selectRange(selectedLinkRange, true)
me.hyperlinkController.removeHyperlinks() @hyperlinkController.removeHyperlinks()
me.hyperlinkController.addHyperlink d.link @hyperlinkController.addHyperlink d.link
else else
me.hyperlinkController.addHyperlink d.link, d.text @hyperlinkController.addHyperlink d.link, d.text
linksInSelection = me.editorSession.getSelectedHyperlinks() linksInSelection = @editorSession.getSelectedHyperlinks()
selectedLinkRange = selection.cloneRange() selectedLinkRange = selection.cloneRange()
selectedLinkRange.selectNode(linksInSelection[0]) selectedLinkRange.selectNode(linksInSelection[0])
selectionController.selectRange(selectedLinkRange, true) selectionController.selectRange(selectedLinkRange, true)
, "__(Insert/edit link)", data
unlink: (e) -> unlink: (e) ->
@hyperlinkController.removeHyperlinks() @hyperlinkController.removeHyperlinks()
@ -384,21 +399,22 @@ class OpenPage extends this.OS.GUI.BaseApplication
@editorSession.redo() @editorSession.redo()
pathAsDataURL: (p) -> pathAsDataURL: (p) ->
return new Promise (resolve, error) -> return new Promise (resolve, error) =>
fp = p.asFileHandler() fp = p.asFileHandle()
fp.read (data) -> fp.read("binary").then (data) =>
blob = new Blob [data], { type: fp.info.mime } blob = new Blob [data], { type: fp.info.mime }
reader = new FileReader() reader = new FileReader()
reader.onloadend = () -> reader.onloadend = () =>
return error(p) if reader.readyState isnt 2 return error(@throwe __("Unable to load file {0}", p)) if reader.readyState isnt 2
resolve {data: reader.result, fp: fp } resolve {data: reader.result, fp: fp }
reader.readAsDataURL blob reader.readAsDataURL blob
, "binary" .catch (e) => error __e e
### ###
if not isText if not isText
else else
fp.read (data) -> fp.read (data) =>
# convert to base64 # convert to base64
b64 = btoa data b64 = btoa data
dataurl = "data:#{fp.info.mime};base64," + b64 dataurl = "data:#{fp.info.mime};base64," + b64
@ -406,43 +422,44 @@ class OpenPage extends this.OS.GUI.BaseApplication
### ###
image: (e) -> image: (e) ->
me = @
@openDialog "FileDiaLog", (d, n, p) -> @openDialog "FileDialog", { title: __("Select image file"), mimes: ["image/.*"] }
me.pathAsDataURL(p) .then (f) =>
.then (r) -> p = f.file.path
@pathAsDataURL(p)
.then (r) =>
hiddenImage = new Image() hiddenImage = new Image()
hiddenImage.style.position = "absolute" hiddenImage.style.position = "absolute"
hiddenImage.style.left = "-99999px" hiddenImage.style.left = "-99999px"
document.body.appendChild hiddenImage document.body.appendChild hiddenImage
hiddenImage.onload = () -> hiddenImage.onload = () =>
content = r.data.substring(r.data.indexOf(",") + 1) content = r.data.substring(r.data.indexOf(",") + 1)
#insert image #insert image
me.textController.removeCurrentSelection() @textController.removeCurrentSelection()
me.imageController.insertImage r.fp.info.mime, content, hiddenImage.width, hiddenImage.height @imageController.insertImage r.fp.info.mime, content, hiddenImage.width, hiddenImage.height
document.body.removeChild hiddenImage document.body.removeChild hiddenImage
hiddenImage.src = r.data hiddenImage.src = r.data
.catch () -> .catch (e) =>
me.error __("Couldnt load image {0}", p) @error __("Couldnt load image {0}", p), e
, __("Select image file"), { mimes: ["image/.*"] }
styles: (e) -> styles: (e) ->
return if e.data.name is @currentStyle return if e.data.item.data.name is @currentStyle
@editorSession.setCurrentParagraphStyle e.data.name @editorSession.setCurrentParagraphStyle e.data.item.data.name
zoom: (e) -> zoom: (e) ->
#console.log "zooming", e #console.log "zooming", e
return unless @zoomHelper return unless @zoomHelper
@zoomHelper.setZoomLevel e/100.0 @zoomHelper.setZoomLevel e.data/100.0
format: (e) -> format: (e) ->
@openDialog new FormatDialog(), (d) -> @openDialog new FormatDialog(), { title: __("Add/Modify paragraph format"), data: @resource }
.then (d) =>
return return
, __("Add/Modify paragraph format"), @resource
closeDocument: (f) -> closeDocument: (f) ->
# finish editing # finish editing
return unless @editorSession and @session return unless @editorSession and @session
me = @
@eventSubscriptions.unsubscribeAll() @eventSubscriptions.unsubscribeAll()
@editorSession.sessionController.endEditing() @editorSession.sessionController.endEditing()
@editorSession.sessionController.removeLocalCursor() @editorSession.sessionController.removeLocalCursor()
@ -453,49 +470,49 @@ class OpenPage extends this.OS.GUI.BaseApplication
} }
@session.enqueue [op] @session.enqueue [op]
# close the session # close the session
@session.close (e) -> @session.close (e) =>
return me.error __("Cannot close session {0}", e) if e return @error __("Cannot close session {0}", e.toString()), e if e
me.editorSession.sessionController.getMetadataController().unsubscribe gui.MetadataController.signalMetadataChanged, me.metaChanged @editorSession.sessionController.getMetadataController().unsubscribe gui.MetadataController.signalMetadataChanged, @metaChanged
me.editorSession.sessionController.getUndoManager().unsubscribe gui.UndoManager.signalDocumentModifiedChanged, me.documentChanged @editorSession.sessionController.getUndoManager().unsubscribe gui.UndoManager.signalDocumentModifiedChanged, @documentChanged
me.directFormattingCtl.unsubscribe gui.DirectFormattingController.textStylingChanged, me.textStylingChanged @directFormattingCtl.unsubscribe gui.DirectFormattingController.textStylingChanged, @textStylingChanged
me.directFormattingCtl.unsubscribe gui.DirectFormattingController.paragraphStylingChanged, me.textStylingChanged @directFormattingCtl.unsubscribe gui.DirectFormattingController.paragraphStylingChanged, @textStylingChanged
me.editorSession.unsubscribe OpenPage.EditorSession.signalParagraphChanged, me.paragrahStyleChanged @editorSession.unsubscribe OpenPage.EditorSession.signalParagraphChanged, @paragrahStyleChanged
me.zoomHelper.unsubscribe gui.ZoomHelper.signalZoomChanged, me.updateSlider @zoomHelper.unsubscribe gui.ZoomHelper.signalZoomChanged, @updateSlider
me.editorSession.unsubscribe OpenPage.EditorSession.signalCommonStyleCreated, me.styleAdded @editorSession.unsubscribe OpenPage.EditorSession.signalCommonStyleCreated, @styleAdded
# destry editorSession # destry editorSession
me.editorSession.destroy (e) -> @editorSession.destroy (e) =>
return me.error __("Cannot destroy editor session {0}", e) if e return @error __("Cannot destroy editor session {0}", e.toString()), e if e
me.editorSession = undefined @editorSession = undefined
# destroy session # destroy session
me.session.destroy (e) -> @session.destroy (e) =>
return me.error __("Cannot destroy document session {0}", e) if e return @error __("Cannot destroy document session {0}", e.toString()), e if e
core.Async.destroyAll [me.canvas.destroy], (e) -> core.Async.destroyAll [@canvas.destroy], (e) =>
return me.error __("Cannot destroy canvas {0}", e) if e return @error __("Cannot destroy canvas {0}", e.toString()), e if e
me.notify "Document closed" @notify "Document closed"
f() if f f() if f
me.session = undefined @session = undefined
me.annotationController = undefined @annotationController = undefined
me.directFormattingCtl = undefined @directFormattingCtl = undefined
me.textController = undefined @textController = undefined
me.imageController = undefined @imageController = undefined
me.ZoomHelper = undefined @ZoomHelper = undefined
me.metaChanged = undefined @metaChanged = undefined
me.documentChanged = undefined @documentChanged = undefined
me.textStylingChanged = undefined @textStylingChanged = undefined
me.paragrahStyleChanged = undefined @paragrahStyleChanged = undefined
me.updateSlider = undefined @updateSlider = undefined
me.styleAdded = undefined @styleAdded = undefined
me.basictool.fonts.set "selected", -1 @basictool.fonts.selected = -1
me.basictool.styles.set "selected", -1 @basictool.styles.selected = -1
# #
cleanup: (e) -> cleanup: (e) ->
me = @
if @editorSession if @editorSession
e.preventDefault() e.preventDefault()
me.closeDocument ()-> @closeDocument ()=>
me.quit() @quit()
this.OS.register "OpenPage", OpenPage this.OS.register "OpenPage", OpenPage

View File

@ -7,10 +7,16 @@ afx-app-window[data-id="OpenPage"] div[data-id="container"]
padding-top: 10px; padding-top: 10px;
padding-bottom: 10px; padding-bottom: 10px;
text-align: center; text-align: center;
background-color: #f2f1f0; /*background-color: #f2f1f0;*/
/*position: relative;*/ /*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 @media screen, print, handheld, projection
{ {
@ -36,7 +42,8 @@ afx-app-window[data-id="OpenPage"] div[data-id="odfcanvas"]
{ {
cursor: text; cursor: text;
margin:auto; margin:auto;
box-shadow: 1px 1px 3px 3px #9f9F9F; /*box-shadow: 1px 1px 3px 3px #9f9F9F;*/
border: 1px solid #2c2c2c;
/*added*/ /*added*/
transform-origin: top center; transform-origin: top center;
-webkit-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"] afx-app-window[data-id="OpenPage"] afx-hbox[data-id="toolbox"]
{ {
background-color: #f5f5f5; /*background-color: #f5f5f5;
border: 1px solid #eaeaea; 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"] afx-app-window[data-id="OpenPage"] afx-hbox[data-id="status-bar"]
{ {
background-color: #f5f5f5; /*background-color: #f5f5f5;
border: 1px solid #eaeaea; 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 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; /*border: 1px solid #f5f5f5;
background-color: transparent; background-color: transparent;*/
width:100%; width:100%;
height: 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 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; border: 1px solid #759DC0;

View File

@ -27,7 +27,7 @@
/*define("webodf/editor/EditorSession", [ /*define("webodf/editor/EditorSession", [
"dojo/text!resources/fonts/fonts.css" "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"; "use strict";
runtime.loadClass("core.Async"); runtime.loadClass("core.Async");

View File

@ -6,7 +6,7 @@
"author": "Xuan Sang LE", "author": "Xuan Sang LE",
"email": "xsang.le@gmail.com" "email": "xsang.le@gmail.com"
}, },
"version":"0.0.2-a", "version":"0.1.3-a",
"category":"Other", "category":"Other",
"icon":"icon.png", "icon":"icon.png",
"mimes":["application/vnd.oasis.opendocument.text"] "mimes":["application/vnd.oasis.opendocument.text"]

View File

@ -80,6 +80,15 @@
"version": "0.0.6-a", "version": "0.0.6-a",
"download": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/MarkOn/build/release/MarkOn.zip" "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", "pkgname": "Preview",
"name": "Preview", "name": "Preview",