2018-09-13 00:41:06 +02:00
|
|
|
class OpenPage extends this.OS.GUI.BaseApplication
|
|
|
|
constructor: ( args ) ->
|
|
|
|
super "OpenPage", args
|
|
|
|
|
|
|
|
main: () ->
|
2018-09-13 20:21:07 +02:00
|
|
|
# load session class
|
2018-09-15 01:12:36 +02:00
|
|
|
#if not OpenPage.EditorSession
|
|
|
|
# require ["webodf/editor/EditorSession"], (ES) ->
|
|
|
|
# OpenPage.EditorSession = ES
|
2018-09-15 21:36:01 +02:00
|
|
|
me =@
|
2018-09-13 20:21:07 +02:00
|
|
|
@eventSubscriptions = new core.EventSubscriptions()
|
|
|
|
@initToolbox()
|
2018-09-15 21:36:01 +02:00
|
|
|
@userid = "#{@systemsetting.user.username}@#{@pid}"
|
|
|
|
#file = "home://welcome.odt"
|
|
|
|
#file = "#{@_api.handler.get}/home://welcome.odt"
|
|
|
|
#@canvas.load file
|
|
|
|
#odfContainer = new odf.OdfContainer file, (c) ->
|
|
|
|
# me.canvas.setOdfContainer c, false
|
2018-09-14 19:35:01 +02:00
|
|
|
@currentStyle = ""
|
2018-09-15 21:36:01 +02:00
|
|
|
if @args and @args.length > 0 then @open @args[0] else @newdoc()
|
2018-09-14 19:35:01 +02:00
|
|
|
@resource =
|
|
|
|
fonts: []
|
|
|
|
formats: []
|
2018-09-15 21:36:01 +02:00
|
|
|
@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"
|
2018-09-14 19:35:01 +02:00
|
|
|
|
2018-09-15 21:36:01 +02:00
|
|
|
|
|
|
|
menu: () ->
|
|
|
|
me = @
|
|
|
|
menu = [{
|
|
|
|
text: "__(File)",
|
|
|
|
child: [
|
|
|
|
{ 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
|
|
|
|
}]
|
|
|
|
menu
|
|
|
|
|
|
|
|
actionFile: (e) ->
|
|
|
|
me = @
|
|
|
|
saveas = () ->
|
|
|
|
me.openDialog "FileDiaLog", (d, n, p) ->
|
2018-09-29 11:19:26 +02:00
|
|
|
me.currfile.setPath "#{d}/#{n}"
|
2018-09-15 21:36:01 +02:00
|
|
|
me.save()
|
|
|
|
, __("Save as"), { file: me.currfile }
|
|
|
|
switch e
|
|
|
|
when "#{@name}-Open"
|
|
|
|
@openDialog "FileDiaLog", ( d, f , p) ->
|
|
|
|
me.open p
|
|
|
|
, __("Open file"), { mimes: me.meta().mimes }
|
|
|
|
when "#{@name}-Save"
|
|
|
|
#@currfile.cache = @editor.value()
|
|
|
|
return @save() if @currfile.basename
|
|
|
|
saveas()
|
|
|
|
when "#{@name}-Saveas"
|
|
|
|
saveas()
|
|
|
|
when "#{@name}-New"
|
|
|
|
@newdoc()
|
|
|
|
|
|
|
|
|
|
|
|
newdoc: () ->
|
|
|
|
blank = "#{@meta().path}/blank.odt"
|
|
|
|
@open blank, true
|
|
|
|
open: (p,b) ->
|
|
|
|
me = @
|
|
|
|
@pathAsDataURL(p)
|
|
|
|
.then (r) ->
|
|
|
|
me.closeDocument() if me.editorSession
|
|
|
|
me.initCanvas()
|
2018-09-29 11:19:26 +02:00
|
|
|
OdfContainer = new odf.OdfContainer r.data, (c) ->
|
2018-09-15 21:36:01 +02:00
|
|
|
me.canvas.setOdfContainer c, false
|
|
|
|
return me.currfile = "Untitled".asFileHandler() if b
|
2018-09-29 11:19:26 +02:00
|
|
|
if me.currfile then me.currfile.setPath p else me.currfile = p.asFileHandler()
|
2018-09-15 21:36:01 +02:00
|
|
|
me.scheme.set "apptitle", me.currfile.basename
|
|
|
|
me.notify __("File {0} opened", p)
|
|
|
|
.catch (e) ->
|
|
|
|
me.error __("Problem read file {0}", e)
|
|
|
|
|
|
|
|
save: () ->
|
|
|
|
me = @
|
|
|
|
return unless @editorSession
|
|
|
|
container = @canvas.odfContainer()
|
|
|
|
return @error __("No document container found") unless container
|
|
|
|
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
|
2018-09-16 20:26:49 +02:00
|
|
|
me.editorFocus()
|
2018-09-15 21:36:01 +02:00
|
|
|
, (err) ->
|
|
|
|
@error __("Cannot create byte array from container: {0}", err|| "")
|
|
|
|
|
2018-09-13 20:21:07 +02:00
|
|
|
initToolbox: () ->
|
|
|
|
me = @
|
|
|
|
@basictool =
|
|
|
|
undo: @find("btundo"),
|
|
|
|
redo: @find("btredo"),
|
|
|
|
bold: @find("btbold"),
|
|
|
|
italic:@find("btitalic"),
|
|
|
|
underline:@find("btunderline"),
|
|
|
|
strike: @find("btstrike"),
|
|
|
|
note: @find("btnote"),
|
|
|
|
link: @find("btlink"),
|
|
|
|
unlink: @find("btunlink"),
|
|
|
|
image:@find("btimage"),
|
|
|
|
ac: @find("btac"),
|
|
|
|
al: @find("btal"),
|
|
|
|
ar: @find("btar"),
|
|
|
|
aj: @find("btaj"),
|
|
|
|
indent: @find("btindent"),
|
|
|
|
outdent: @find("btoutdent"),
|
|
|
|
fonts: @find("font-list"),
|
2018-09-14 19:35:01 +02:00
|
|
|
fontsize: @find("font-size"),
|
|
|
|
styles: @find("format-list"),
|
|
|
|
zoom: @find("slzoom")
|
|
|
|
format: @find("btformat")
|
|
|
|
|
2018-09-13 20:21:07 +02:00
|
|
|
fn = (name, el) ->
|
2018-09-14 19:35:01 +02:00
|
|
|
if name is "fonts" or name is "styles"
|
2018-09-13 20:21:07 +02:00
|
|
|
act = "onlistselect"
|
2018-09-14 19:35:01 +02:00
|
|
|
else if name is "fontsize" or name is "zoom"
|
2018-09-13 20:21:07 +02:00
|
|
|
act = "onchange"
|
|
|
|
else
|
|
|
|
act = "onbtclick"
|
|
|
|
el.set act, (e) ->
|
|
|
|
return unless me.directFormattingCtl
|
|
|
|
return unless me[name]
|
|
|
|
me[name](e)
|
|
|
|
me.editorFocus()
|
|
|
|
for name, el of @basictool
|
|
|
|
fn name, el
|
|
|
|
|
2018-09-14 19:35:01 +02:00
|
|
|
(@find "btzoomfix").set "onbtclick", (e) -> me.zoom 100
|
|
|
|
@basictool.zoom.set "onchanging", (e) ->
|
|
|
|
zlb = me.find "lbzoom"
|
|
|
|
zlb.set "text", Math.floor(e) + "%"
|
|
|
|
|
2018-09-13 20:21:07 +02:00
|
|
|
initCanvas: () ->
|
2018-09-13 00:41:06 +02:00
|
|
|
el = @find "odfcanvas"
|
|
|
|
me = @
|
|
|
|
el.setAttribute "translate", "no"
|
|
|
|
el.classList.add "notranslate"
|
|
|
|
@canvas = new odf.OdfCanvas(el)
|
2018-09-13 20:21:07 +02:00
|
|
|
@documentChanged = (e) ->
|
2018-09-15 21:36:01 +02:00
|
|
|
return if me.currfile.dirty
|
|
|
|
me.currfile.dirty = true
|
|
|
|
me.scheme.set "apptitle", me.currfile.basename + "*"
|
2018-09-13 22:32:56 +02:00
|
|
|
#console.log e
|
2018-09-13 20:21:07 +02:00
|
|
|
@metaChanged = (e) ->
|
2018-09-15 21:36:01 +02:00
|
|
|
return if me.currfile.dirty
|
|
|
|
me.currfile.dirty = true
|
|
|
|
me.scheme.set "apptitle", me.currfile.basename + "*"
|
2018-09-13 22:32:56 +02:00
|
|
|
#console.log e
|
2018-09-13 20:21:07 +02:00
|
|
|
@textStylingChanged = (e) ->
|
|
|
|
me.updateToolbar e
|
2018-09-14 19:35:01 +02:00
|
|
|
@paragrahStyleChanged = (e) ->
|
|
|
|
return unless e.type is "style"
|
|
|
|
items = me.basictool.styles.get "items"
|
|
|
|
item = i for v, i in items when v.name is e.styleName
|
|
|
|
me.currentStyle = e.styleName
|
|
|
|
me.basictool.styles.set "selected", item
|
|
|
|
|
2018-09-15 01:12:36 +02:00
|
|
|
@styleAdded = (e) ->
|
|
|
|
return unless e.family is 'paragraph'
|
|
|
|
items = me.basictool.styles.get "items"
|
|
|
|
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
|
|
|
|
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}
|
|
|
|
|
2018-09-14 19:35:01 +02:00
|
|
|
@updateSlider = (v) ->
|
|
|
|
value = Math.floor v*100
|
|
|
|
me.basictool.zoom.set "value", value
|
|
|
|
zlb = me.find "lbzoom"
|
|
|
|
zlb.set "text", value+"%"
|
2018-09-15 21:36:01 +02:00
|
|
|
#me.canvas.enableAnnotations true, true
|
2018-09-13 00:41:06 +02:00
|
|
|
@canvas.addListener "statereadychange", ()->
|
|
|
|
me.session = new ops.Session(me.canvas)
|
|
|
|
viewOptions =
|
|
|
|
editInfoMarkersInitiallyVisible: false,
|
|
|
|
caretAvatarsInitiallyVisible: false,
|
|
|
|
caretBlinksOnRangeSelect: true
|
|
|
|
|
2018-09-13 20:21:07 +02:00
|
|
|
me.editorSession = new OpenPage.EditorSession(me.session,me.userid, {
|
2018-09-13 00:41:06 +02:00
|
|
|
viewOptions: viewOptions,
|
|
|
|
directTextStylingEnabled: true,
|
|
|
|
directParagraphStylingEnabled: true,
|
|
|
|
paragraphStyleSelectingEnabled: true,
|
|
|
|
paragraphStyleEditingEnabled: true,
|
|
|
|
imageEditingEnabled: true,
|
|
|
|
hyperlinkEditingEnabled: true,
|
|
|
|
annotationsEnabled: true,
|
|
|
|
zoomingEnabled: true,
|
|
|
|
reviewModeEnabled: false
|
|
|
|
})
|
2018-09-15 21:36:01 +02:00
|
|
|
me.initFontList me.editorSession.getDeclaredFonts()
|
|
|
|
me.initStyles me.editorSession.getAvailableParagraphStyles()
|
|
|
|
#fix annotation problem on canvas
|
|
|
|
#console.log $("office:body").css "background-color", "red"
|
2018-09-13 20:21:07 +02:00
|
|
|
# basic format
|
|
|
|
me.directFormattingCtl = me.editorSession.sessionController.getDirectFormattingController()
|
|
|
|
me.directFormattingCtl.subscribe gui.DirectFormattingController.textStylingChanged, me.textStylingChanged
|
|
|
|
me.directFormattingCtl.subscribe gui.DirectFormattingController.paragraphStylingChanged, me.textStylingChanged
|
2018-09-14 19:35:01 +02:00
|
|
|
me.editorSession.subscribe OpenPage.EditorSession.signalParagraphChanged, me.paragrahStyleChanged
|
|
|
|
|
2018-09-13 20:21:07 +02:00
|
|
|
# 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()
|
2018-09-13 22:32:56 +02:00
|
|
|
|
2018-09-15 21:36:01 +02:00
|
|
|
#annotation controller
|
|
|
|
me.annotationController = me.editorSession.sessionController.getAnnotationController()
|
2018-09-14 19:35:01 +02:00
|
|
|
|
2018-09-13 22:32:56 +02:00
|
|
|
#image controller
|
|
|
|
me.imageController = me.editorSession.sessionController.getImageController()
|
|
|
|
#imageController.subscribe(gui.ImageController.enabledChanged, enableButtons)
|
|
|
|
|
|
|
|
#text controller
|
|
|
|
me.textController = me.editorSession.sessionController.getTextController()
|
|
|
|
|
2018-09-14 19:35:01 +02:00
|
|
|
# zoom controller
|
|
|
|
me.zoomHelper = me.editorSession.getOdfCanvas().getZoomHelper()
|
|
|
|
me.zoomHelper.subscribe gui.ZoomHelper.signalZoomChanged, me.updateSlider
|
|
|
|
me.updateSlider me.zoomHelper.getZoomLevel()
|
|
|
|
|
2018-09-15 01:12:36 +02:00
|
|
|
# format controller
|
|
|
|
me.editorSession.subscribe OpenPage.EditorSession.signalCommonStyleCreated, me.styleAdded
|
|
|
|
|
2018-09-13 00:41:06 +02:00
|
|
|
me.editorSession.sessionController.setUndoManager new gui.TrivialUndoManager()
|
2018-09-13 20:21:07 +02:00
|
|
|
me.editorSession.sessionController.getUndoManager().subscribe gui.UndoManager.signalDocumentModifiedChanged, me.documentChanged
|
|
|
|
me.editorSession.sessionController.getMetadataController().subscribe gui.MetadataController.signalMetadataChanged, me.metaChanged
|
2018-09-13 00:41:06 +02:00
|
|
|
op = new ops.OpAddMember()
|
|
|
|
op.init {
|
2018-09-13 20:21:07 +02:00
|
|
|
memberid: me.userid,
|
2018-09-13 00:41:06 +02:00
|
|
|
setProperties:{
|
2018-09-14 19:35:01 +02:00
|
|
|
"fullName": me.userid,
|
2018-09-13 00:41:06 +02:00
|
|
|
"color": "blue"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
me.session.enqueue([op])
|
|
|
|
me.editorSession.sessionController.insertLocalCursor()
|
|
|
|
me.editorSession.sessionController.startEditing()
|
2018-09-13 20:21:07 +02:00
|
|
|
#console.log me.editorSession.getDeclaredFonts()
|
|
|
|
#
|
|
|
|
|
|
|
|
initFontList: (list) ->
|
|
|
|
v.text = v.name for v in list
|
2018-09-14 19:35:01 +02:00
|
|
|
@resource.fonts.push { text: v.text, name: v.family } for v in list
|
2018-09-13 20:21:07 +02:00
|
|
|
@basictool.fonts.set "items", list
|
|
|
|
|
2018-09-14 19:35:01 +02:00
|
|
|
initStyles: (list) ->
|
2018-09-15 01:12:36 +02:00
|
|
|
list.unshift {name:"", displayName: 'Default style' }
|
2018-09-14 19:35:01 +02:00
|
|
|
v.text = v.displayName for v in list
|
2018-09-15 01:12:36 +02:00
|
|
|
@resource.formats.push { text: v.text, name: v.name } for v in list
|
2018-09-14 19:35:01 +02:00
|
|
|
@basictool.styles.set "items", list
|
|
|
|
|
2018-09-13 20:21:07 +02:00
|
|
|
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"
|
|
|
|
@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"
|
|
|
|
|
|
|
|
updateHyperlinkButtons: (e) ->
|
|
|
|
selectedLinks = @editorSession.getSelectedHyperlinks()
|
|
|
|
@basictool.unlink.set "enable", selectedLinks.length > 0
|
|
|
|
|
|
|
|
selectFont: (name) ->
|
|
|
|
items = @basictool.fonts.get "items"
|
|
|
|
item = i for v, i in items when v.name is name
|
|
|
|
@basictool.fonts.set "selected", item
|
|
|
|
|
|
|
|
editorFocus: () ->
|
|
|
|
@editorSession.sessionController.getEventManager().focus()
|
2018-09-13 00:41:06 +02:00
|
|
|
|
2018-09-13 20:21:07 +02:00
|
|
|
bold: (e) ->
|
|
|
|
#console.log @, e
|
|
|
|
@directFormattingCtl.setBold (not @basictool.bold.get "selected")
|
|
|
|
|
|
|
|
italic: (e) ->
|
|
|
|
@directFormattingCtl.setItalic (not @basictool.italic.get "selected")
|
|
|
|
|
|
|
|
underline: (e) ->
|
|
|
|
@directFormattingCtl.setHasUnderline (not @basictool.underline.get "selected")
|
|
|
|
|
|
|
|
strike: (e) ->
|
|
|
|
@directFormattingCtl.setHasStrikethrough (not @basictool.strike.get "selected")
|
|
|
|
|
|
|
|
fonts: (e) ->
|
|
|
|
@directFormattingCtl.setFontName e.data.name
|
|
|
|
|
|
|
|
fontsize: (e) ->
|
|
|
|
@directFormattingCtl.setFontSize e
|
|
|
|
|
|
|
|
al: (e) ->
|
|
|
|
@directFormattingCtl.alignParagraphLeft()
|
|
|
|
|
|
|
|
ar: (e) ->
|
|
|
|
@directFormattingCtl.alignParagraphRight()
|
|
|
|
|
|
|
|
ac: (e) ->
|
|
|
|
@directFormattingCtl.alignParagraphCenter()
|
|
|
|
|
2018-09-15 21:36:01 +02:00
|
|
|
note: (e) ->
|
|
|
|
@annotationController.addAnnotation()
|
|
|
|
|
2018-09-13 20:21:07 +02:00
|
|
|
aj: (e) ->
|
|
|
|
@directFormattingCtl.alignParagraphJustified()
|
|
|
|
|
|
|
|
indent: (e) ->
|
|
|
|
@directFormattingCtl.indent()
|
|
|
|
|
|
|
|
outdent: (e) ->
|
|
|
|
@directFormattingCtl.outdent()
|
|
|
|
|
|
|
|
link: (e) ->
|
|
|
|
# get the link first
|
|
|
|
me = @
|
|
|
|
textSerializer = new odf.TextSerializer()
|
|
|
|
selection = @editorSession.getSelectedRange()
|
|
|
|
linksInSelection = @editorSession.getSelectedHyperlinks()
|
|
|
|
linkTarget = if linksInSelection[0] then odf.OdfUtils.getHyperlinkTarget(linksInSelection[0]) else "http://"
|
|
|
|
data =
|
|
|
|
link: linkTarget,
|
|
|
|
text: "",
|
|
|
|
readonly: true,
|
|
|
|
action: "new"
|
|
|
|
if selection and selection.collapsed and linksInSelection.length == 1
|
|
|
|
# selection is collapsed within a single link
|
|
|
|
# text in this case is read only
|
|
|
|
data.text = textSerializer.writeToString linksInSelection[0]
|
|
|
|
data.action = "edit"
|
|
|
|
else if selection and !selection.collapsed
|
|
|
|
# user select part of link or a block of text
|
|
|
|
# user convert a selection to a link
|
|
|
|
data.text = textSerializer.writeToString selection.cloneContents()
|
|
|
|
else
|
|
|
|
data.readonly = false
|
|
|
|
@openDialog new HyperLinkDialog(), (d) ->
|
|
|
|
selectionController = me.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
|
|
|
|
else
|
|
|
|
me.hyperlinkController.addHyperlink d.link, d.text
|
|
|
|
linksInSelection = me.editorSession.getSelectedHyperlinks()
|
|
|
|
selectedLinkRange = selection.cloneRange()
|
|
|
|
selectedLinkRange.selectNode(linksInSelection[0])
|
|
|
|
selectionController.selectRange(selectedLinkRange, true)
|
|
|
|
, "__(Insert/edit link)", data
|
|
|
|
|
|
|
|
unlink: (e) ->
|
|
|
|
@hyperlinkController.removeHyperlinks()
|
|
|
|
|
2018-09-13 22:32:56 +02:00
|
|
|
undo: (e) ->
|
|
|
|
@editorSession.undo()
|
|
|
|
|
|
|
|
redo: (e) ->
|
|
|
|
@editorSession.redo()
|
|
|
|
|
2018-09-15 21:36:01 +02:00
|
|
|
pathAsDataURL: (p) ->
|
|
|
|
return new Promise (resolve, error) ->
|
2018-09-13 22:32:56 +02:00
|
|
|
fp = p.asFileHandler()
|
2018-09-15 21:36:01 +02:00
|
|
|
fp.read (data) ->
|
2018-09-13 22:32:56 +02:00
|
|
|
blob = new Blob [data], { type: fp.info.mime }
|
|
|
|
reader = new FileReader()
|
|
|
|
reader.onloadend = () ->
|
2018-09-15 21:36:01 +02:00
|
|
|
return error(p) if reader.readyState isnt 2
|
2018-09-29 11:19:26 +02:00
|
|
|
resolve {data: reader.result, fp: fp }
|
2018-09-15 21:36:01 +02:00
|
|
|
reader.readAsDataURL blob
|
|
|
|
, "binary"
|
2018-09-29 11:19:26 +02:00
|
|
|
###
|
|
|
|
if not isText
|
|
|
|
|
|
|
|
else
|
|
|
|
fp.read (data) ->
|
|
|
|
# convert to base64
|
|
|
|
b64 = btoa data
|
|
|
|
dataurl = "data:#{fp.info.mime};base64," + b64
|
|
|
|
resolve { reader: {result: dataurl}, fp:fp }
|
|
|
|
###
|
2018-09-15 21:36:01 +02:00
|
|
|
|
|
|
|
image: (e) ->
|
|
|
|
me = @
|
|
|
|
@openDialog "FileDiaLog", (d, n, p) ->
|
|
|
|
me.pathAsDataURL(p)
|
|
|
|
.then (r) ->
|
2018-09-13 22:32:56 +02:00
|
|
|
hiddenImage = new Image()
|
|
|
|
hiddenImage.style.position = "absolute"
|
|
|
|
hiddenImage.style.left = "-99999px"
|
|
|
|
document.body.appendChild hiddenImage
|
|
|
|
hiddenImage.onload = () ->
|
2018-09-29 11:19:26 +02:00
|
|
|
content = r.data.substring(r.data.indexOf(",") + 1)
|
2018-09-13 22:32:56 +02:00
|
|
|
#insert image
|
|
|
|
me.textController.removeCurrentSelection()
|
2018-09-15 21:36:01 +02:00
|
|
|
me.imageController.insertImage r.fp.info.mime, content, hiddenImage.width, hiddenImage.height
|
2018-09-13 22:32:56 +02:00
|
|
|
document.body.removeChild hiddenImage
|
2018-09-29 11:19:26 +02:00
|
|
|
hiddenImage.src = r.data
|
2018-09-15 21:36:01 +02:00
|
|
|
.catch () ->
|
|
|
|
me.error __("Couldnt load image {0}", p)
|
2018-09-13 22:32:56 +02:00
|
|
|
, __("Select image file"), { mimes: ["image/.*"] }
|
|
|
|
|
2018-09-14 19:35:01 +02:00
|
|
|
styles: (e) ->
|
|
|
|
return if e.data.name is @currentStyle
|
|
|
|
@editorSession.setCurrentParagraphStyle e.data.name
|
|
|
|
|
|
|
|
zoom: (e) ->
|
|
|
|
#console.log "zooming", e
|
2018-09-15 21:36:01 +02:00
|
|
|
return unless @zoomHelper
|
2018-09-14 19:35:01 +02:00
|
|
|
@zoomHelper.setZoomLevel e/100.0
|
|
|
|
|
|
|
|
format: (e) ->
|
|
|
|
@openDialog new FormatDialog(), (d) ->
|
2018-09-15 21:36:01 +02:00
|
|
|
return
|
2018-09-14 19:35:01 +02:00
|
|
|
, __("Add/Modify paragraph format"), @resource
|
|
|
|
|
2018-09-16 20:26:49 +02:00
|
|
|
closeDocument: (f) ->
|
2018-09-13 20:21:07 +02:00
|
|
|
# finish editing
|
|
|
|
return unless @editorSession and @session
|
|
|
|
me = @
|
|
|
|
@eventSubscriptions.unsubscribeAll()
|
|
|
|
@editorSession.sessionController.endEditing()
|
|
|
|
@editorSession.sessionController.removeLocalCursor()
|
|
|
|
# remove user
|
|
|
|
op = new ops.OpRemoveMember()
|
|
|
|
op.init {
|
|
|
|
memberid: @userid
|
|
|
|
}
|
|
|
|
@session.enqueue [op]
|
|
|
|
# close the session
|
|
|
|
@session.close (e) ->
|
2018-09-13 22:37:41 +02:00
|
|
|
return me.error __("Cannot close session {0}", e) if e
|
2018-09-13 20:21:07 +02:00
|
|
|
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
|
2018-09-14 19:35:01 +02:00
|
|
|
me.editorSession.unsubscribe OpenPage.EditorSession.signalParagraphChanged, me.paragrahStyleChanged
|
|
|
|
me.zoomHelper.unsubscribe gui.ZoomHelper.signalZoomChanged, me.updateSlider
|
2018-09-15 01:12:36 +02:00
|
|
|
me.editorSession.unsubscribe OpenPage.EditorSession.signalCommonStyleCreated, me.styleAdded
|
2018-09-13 20:21:07 +02:00
|
|
|
# destry editorSession
|
|
|
|
me.editorSession.destroy (e) ->
|
2018-09-13 22:37:41 +02:00
|
|
|
return me.error __("Cannot destroy editor session {0}", e) if e
|
2018-09-13 20:21:07 +02:00
|
|
|
me.editorSession = undefined
|
|
|
|
# destroy session
|
|
|
|
me.session.destroy (e) ->
|
2018-09-13 22:37:41 +02:00
|
|
|
return me.error __("Cannot destroy document session {0}", e) if e
|
2018-09-13 20:21:07 +02:00
|
|
|
core.Async.destroyAll [me.canvas.destroy], (e) ->
|
2018-09-13 22:37:41 +02:00
|
|
|
return me.error __("Cannot destroy canvas {0}", e) if e
|
2018-09-13 20:21:07 +02:00
|
|
|
me.notify "Document closed"
|
2018-09-16 20:26:49 +02:00
|
|
|
f() if f
|
2018-09-13 20:21:07 +02:00
|
|
|
me.session = undefined
|
2018-09-15 21:36:01 +02:00
|
|
|
me.annotationController = undefined
|
2018-09-13 20:21:07 +02:00
|
|
|
me.directFormattingCtl = undefined
|
2018-09-13 22:32:56 +02:00
|
|
|
me.textController = undefined
|
|
|
|
me.imageController = undefined
|
2018-09-14 19:35:01 +02:00
|
|
|
me.ZoomHelper = undefined
|
|
|
|
me.metaChanged = undefined
|
|
|
|
me.documentChanged = undefined
|
|
|
|
me.textStylingChanged = undefined
|
|
|
|
me.paragrahStyleChanged = undefined
|
|
|
|
me.updateSlider = undefined
|
2018-09-15 01:12:36 +02:00
|
|
|
me.styleAdded = undefined
|
2018-09-15 21:36:01 +02:00
|
|
|
me.basictool.fonts.set "selected", -1
|
|
|
|
me.basictool.styles.set "selected", -1
|
2018-09-16 20:26:49 +02:00
|
|
|
|
2018-09-13 20:21:07 +02:00
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
cleanup: (e) ->
|
2018-09-16 20:26:49 +02:00
|
|
|
me = @
|
|
|
|
if @editorSession
|
|
|
|
e.preventDefault()
|
|
|
|
me.closeDocument ()->
|
|
|
|
me.quit()
|
2018-09-13 20:21:07 +02:00
|
|
|
|
2018-09-13 00:41:06 +02:00
|
|
|
this.OS.register "OpenPage", OpenPage
|