2020-06-25 18:23:33 +02:00
|
|
|
class OpenPage extends this.OS.application.BaseApplication
|
2018-09-13 00:41:06 +02:00
|
|
|
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
|
2020-06-25 18:23:33 +02:00
|
|
|
|
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}"
|
2020-06-25 18:23:33 +02:00
|
|
|
#file = "home://welco@odt"
|
2018-09-15 21:36:01 +02:00
|
|
|
#file = "#{@_api.handler.get}/home://welcome.odt"
|
|
|
|
#@canvas.load file
|
|
|
|
#odfContainer = new odf.OdfContainer file, (c) ->
|
2020-06-25 18:23:33 +02:00
|
|
|
# @canvas.setOdfContainer c, false
|
2018-09-14 19:35:01 +02:00
|
|
|
@currentStyle = ""
|
2020-06-25 18:23:33 +02:00
|
|
|
if @args and @args.length > 0 then @open @args[0].path else @newdoc()
|
2018-09-14 19:35:01 +02:00
|
|
|
@resource =
|
|
|
|
fonts: []
|
|
|
|
formats: []
|
2020-06-25 18:23:33 +02:00
|
|
|
@bindKey "ALT-N", () => @actionFile "#{@name}-New"
|
|
|
|
@bindKey "ALT-O", () => @actionFile "#{@name}-Open"
|
|
|
|
@bindKey "CTRL-S", () => @actionFile "#{@name}-Save"
|
|
|
|
@bindKey "ALT-W", () => @actionFile "#{@name}-Saveas"
|
2018-09-14 19:35:01 +02:00
|
|
|
|
2018-09-15 21:36:01 +02:00
|
|
|
|
|
|
|
menu: () ->
|
2020-06-25 18:23:33 +02:00
|
|
|
|
2018-09-15 21:36:01 +02:00
|
|
|
menu = [{
|
|
|
|
text: "__(File)",
|
2020-06-25 18:23:33 +02:00
|
|
|
nodes: [
|
2018-09-15 21:36:01 +02:00
|
|
|
{ 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" }
|
|
|
|
],
|
2020-06-25 18:23:33 +02:00
|
|
|
onchildselect: (e) => @actionFile e.data.item.data.dataid
|
2018-09-15 21:36:01 +02:00
|
|
|
}]
|
|
|
|
menu
|
|
|
|
|
|
|
|
actionFile: (e) ->
|
2020-06-25 18:23:33 +02:00
|
|
|
|
|
|
|
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()
|
2018-09-15 21:36:01 +02:00
|
|
|
switch e
|
|
|
|
when "#{@name}-Open"
|
2020-06-25 18:23:33 +02:00
|
|
|
@openDialog "FileDialog", { title: __("Open file"), mimes: @meta().mimes }
|
|
|
|
.then (f) =>
|
|
|
|
@open f.file.path
|
|
|
|
|
2018-09-15 21:36:01 +02:00
|
|
|
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
|
2020-05-21 21:56:16 +02:00
|
|
|
|
2018-09-15 21:36:01 +02:00
|
|
|
open: (p,b) ->
|
2020-06-25 18:23:33 +02:00
|
|
|
|
2018-09-15 21:36:01 +02:00
|
|
|
@pathAsDataURL(p)
|
2020-06-25 18:23:33 +02:00
|
|
|
.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
|
2018-09-15 21:36:01 +02:00
|
|
|
|
|
|
|
save: () ->
|
2020-06-25 18:23:33 +02:00
|
|
|
|
2018-09-15 21:36:01 +02:00
|
|
|
return unless @editorSession
|
|
|
|
container = @canvas.odfContainer()
|
|
|
|
return @error __("No document container found") unless container
|
2020-06-25 18:23:33 +02:00
|
|
|
container.createByteArray (ba) =>
|
2018-09-15 21:36:01 +02:00
|
|
|
# create blob
|
2020-06-25 18:23:33 +02:00
|
|
|
@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
|
2018-09-15 21:36:01 +02:00
|
|
|
|
2018-09-13 20:21:07 +02:00
|
|
|
initToolbox: () ->
|
2020-06-25 18:23:33 +02:00
|
|
|
|
2018-09-13 20:21:07 +02:00
|
|
|
@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")
|
|
|
|
|
2020-06-25 18:23:33 +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"
|
2020-06-25 18:23:33 +02:00
|
|
|
act = "onvaluechange"
|
2018-09-13 20:21:07 +02:00
|
|
|
else
|
|
|
|
act = "onbtclick"
|
2020-06-25 18:23:33 +02:00
|
|
|
el[act] = (e) =>
|
|
|
|
return unless @directFormattingCtl
|
|
|
|
return unless @[name]
|
|
|
|
@[name](e)
|
|
|
|
@editorFocus()
|
2018-09-13 20:21:07 +02:00
|
|
|
for name, el of @basictool
|
|
|
|
fn name, el
|
|
|
|
|
2020-06-25 18:23:33 +02:00
|
|
|
(@find "btzoomfix").onbtclick = (e) => @zoom { data: 100 }
|
|
|
|
@basictool.zoom.onvaluechanging = (e) =>
|
|
|
|
zlb = @find "lbzoom"
|
|
|
|
zlb.text = Math.floor(e.data) + "%"
|
2018-09-14 19:35:01 +02:00
|
|
|
|
2018-09-13 20:21:07 +02:00
|
|
|
initCanvas: () ->
|
2018-09-13 00:41:06 +02:00
|
|
|
el = @find "odfcanvas"
|
2020-06-25 18:23:33 +02:00
|
|
|
|
2018-09-13 00:41:06 +02:00
|
|
|
el.setAttribute "translate", "no"
|
|
|
|
el.classList.add "notranslate"
|
|
|
|
@canvas = new odf.OdfCanvas(el)
|
2020-06-25 18:23:33 +02:00
|
|
|
@documentChanged = (e) =>
|
|
|
|
return if @currfile.dirty
|
|
|
|
@currfile.dirty = true
|
|
|
|
@scheme.apptitle = @currfile.basename + "*"
|
2018-09-13 22:32:56 +02:00
|
|
|
#console.log e
|
2020-06-25 18:23:33 +02:00
|
|
|
@metaChanged = (e) =>
|
|
|
|
return if @currfile.dirty
|
|
|
|
@currfile.dirty = true
|
|
|
|
@scheme.apptitle = @currfile.basename + "*"
|
2018-09-13 22:32:56 +02:00
|
|
|
#console.log e
|
2020-06-25 18:23:33 +02:00
|
|
|
@textStylingChanged = (e) =>
|
|
|
|
@updateToolbar e
|
|
|
|
@paragrahStyleChanged = (e) =>
|
2018-09-14 19:35:01 +02:00
|
|
|
return unless e.type is "style"
|
2020-06-25 18:23:33 +02:00
|
|
|
items = @basictool.styles.data
|
2018-09-14 19:35:01 +02:00
|
|
|
item = i for v, i in items when v.name is e.styleName
|
2020-06-25 18:23:33 +02:00
|
|
|
return unless item isnt undefined
|
|
|
|
@currentStyle = e.styleName
|
|
|
|
@basictool.styles.selected = item
|
2018-09-14 19:35:01 +02:00
|
|
|
|
2020-06-25 18:23:33 +02:00
|
|
|
@styleAdded = (e) =>
|
2018-09-15 01:12:36 +02:00
|
|
|
return unless e.family is 'paragraph'
|
2020-06-25 18:23:33 +02:00
|
|
|
items = @basictool.styles.data
|
2018-09-15 01:12:36 +02:00
|
|
|
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"
|
2020-06-25 18:23:33 +02:00
|
|
|
el = @editorSession.getParagraphStyleElement e.name
|
2018-09-15 01:12:36 +02:00
|
|
|
dtext = el.getAttributeNS stylens, 'display-name'
|
2020-06-25 18:23:33 +02:00
|
|
|
@basictool.styles.push { text: dtext , name: e.name }, true
|
|
|
|
#@resource.formats.push {text: dtext, name:e.name}
|
2018-09-15 01:12:36 +02:00
|
|
|
|
2020-06-25 18:23:33 +02:00
|
|
|
@updateSlider = (v) =>
|
2018-09-14 19:35:01 +02:00
|
|
|
value = Math.floor v*100
|
2020-06-25 18:23:33 +02:00
|
|
|
@basictool.zoom.value = value
|
|
|
|
zlb = @find "lbzoom"
|
|
|
|
zlb.text = value + "%"
|
|
|
|
@canvas.enableAnnotations true, true
|
|
|
|
@canvas.addListener "statereadychange", ()=>
|
|
|
|
@session = new ops.Session(@canvas)
|
2018-09-13 00:41:06 +02:00
|
|
|
viewOptions =
|
|
|
|
editInfoMarkersInitiallyVisible: false,
|
|
|
|
caretAvatarsInitiallyVisible: false,
|
|
|
|
caretBlinksOnRangeSelect: true
|
|
|
|
|
2020-06-25 18:23:33 +02:00
|
|
|
@editorSession = new OpenPage.EditorSession(@session,@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
|
|
|
|
})
|
2020-06-25 18:23:33 +02:00
|
|
|
@initFontList @editorSession.getDeclaredFonts()
|
|
|
|
@initStyles @editorSession.getAvailableParagraphStyles()
|
2018-09-15 21:36:01 +02:00
|
|
|
#fix annotation problem on canvas
|
|
|
|
#console.log $("office:body").css "background-color", "red"
|
2018-09-13 20:21:07 +02:00
|
|
|
# basic format
|
2020-06-25 18:23:33 +02:00
|
|
|
@directFormattingCtl = @editorSession.sessionController.getDirectFormattingController()
|
|
|
|
@directFormattingCtl.subscribe gui.DirectFormattingController.textStylingChanged, @textStylingChanged
|
|
|
|
@directFormattingCtl.subscribe gui.DirectFormattingController.paragraphStylingChanged, @textStylingChanged
|
|
|
|
@editorSession.subscribe OpenPage.EditorSession.signalParagraphChanged, @paragrahStyleChanged
|
2018-09-14 19:35:01 +02:00
|
|
|
|
2018-09-13 20:21:07 +02:00
|
|
|
# hyper link controller
|
2020-06-25 18:23:33 +02:00
|
|
|
@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()
|
2018-09-13 22:32:56 +02:00
|
|
|
|
2018-09-15 21:36:01 +02:00
|
|
|
#annotation controller
|
2020-06-25 18:23:33 +02:00
|
|
|
@annotationController = @editorSession.sessionController.getAnnotationController()
|
2018-09-14 19:35:01 +02:00
|
|
|
|
2018-09-13 22:32:56 +02:00
|
|
|
#image controller
|
2020-06-25 18:23:33 +02:00
|
|
|
@imageController = @editorSession.sessionController.getImageController()
|
2018-09-13 22:32:56 +02:00
|
|
|
#imageController.subscribe(gui.ImageController.enabledChanged, enableButtons)
|
|
|
|
|
|
|
|
#text controller
|
2020-06-25 18:23:33 +02:00
|
|
|
@textController = @editorSession.sessionController.getTextController()
|
2018-09-13 22:32:56 +02:00
|
|
|
|
2018-09-14 19:35:01 +02:00
|
|
|
# zoom controller
|
2020-06-25 18:23:33 +02:00
|
|
|
@zoomHelper = @editorSession.getOdfCanvas().getZoomHelper()
|
|
|
|
@zoomHelper.subscribe gui.ZoomHelper.signalZoomChanged, @updateSlider
|
|
|
|
@updateSlider @zoomHelper.getZoomLevel()
|
2018-09-14 19:35:01 +02:00
|
|
|
|
2018-09-15 01:12:36 +02:00
|
|
|
# format controller
|
2020-06-25 18:23:33 +02:00
|
|
|
@editorSession.subscribe OpenPage.EditorSession.signalCommonStyleCreated, @styleAdded
|
2018-09-15 01:12:36 +02:00
|
|
|
|
2020-06-25 18:23:33 +02:00
|
|
|
@editorSession.sessionController.setUndoManager new gui.TrivialUndoManager()
|
|
|
|
@editorSession.sessionController.getUndoManager().subscribe gui.UndoManager.signalDocumentModifiedChanged, @documentChanged
|
|
|
|
@editorSession.sessionController.getMetadataController().subscribe gui.MetadataController.signalMetadataChanged, @metaChanged
|
2018-09-13 00:41:06 +02:00
|
|
|
op = new ops.OpAddMember()
|
|
|
|
op.init {
|
2020-06-25 18:23:33 +02:00
|
|
|
memberid: @userid,
|
2018-09-13 00:41:06 +02:00
|
|
|
setProperties:{
|
2020-06-25 18:23:33 +02:00
|
|
|
"fullName": @userid,
|
2018-09-13 00:41:06 +02:00
|
|
|
"color": "blue"
|
|
|
|
}
|
|
|
|
}
|
2020-06-25 18:23:33 +02:00
|
|
|
@session.enqueue([op])
|
|
|
|
@editorSession.sessionController.insertLocalCursor()
|
|
|
|
@editorSession.sessionController.startEditing()
|
|
|
|
@fontsize {data: @basictool.fontsize.value}
|
|
|
|
#console.log @editorSession.getDeclaredFonts()
|
2018-09-13 20:21:07 +02:00
|
|
|
#
|
|
|
|
|
|
|
|
initFontList: (list) ->
|
|
|
|
v.text = v.name for v in list
|
2020-06-25 18:23:33 +02:00
|
|
|
@resource.fonts = []
|
2018-09-14 19:35:01 +02:00
|
|
|
@resource.fonts.push { text: v.text, name: v.family } for v in list
|
2020-06-25 18:23:33 +02:00
|
|
|
@basictool.fonts.data = list
|
2018-09-13 20:21:07 +02:00
|
|
|
|
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
|
2020-06-25 18:23:33 +02:00
|
|
|
@basictool.styles.data = list
|
2018-09-14 19:35:01 +02:00
|
|
|
|
2018-09-13 20:21:07 +02:00
|
|
|
updateToolbar: (changes) ->
|
|
|
|
# basic style
|
2020-06-25 18:23:33 +02:00
|
|
|
(@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
|
|
|
|
|
2018-09-13 20:21:07 +02:00
|
|
|
@selectFont changes.fontName if changes.hasOwnProperty "fontName"
|
|
|
|
#pharagraph style
|
2020-06-25 18:23:33 +02:00
|
|
|
@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"
|
2018-09-13 20:21:07 +02:00
|
|
|
|
|
|
|
updateHyperlinkButtons: (e) ->
|
|
|
|
selectedLinks = @editorSession.getSelectedHyperlinks()
|
2020-06-25 18:23:33 +02:00
|
|
|
@basictool.unlink.enable = selectedLinks.length > 0
|
2018-09-13 20:21:07 +02:00
|
|
|
|
|
|
|
selectFont: (name) ->
|
2020-06-25 18:23:33 +02:00
|
|
|
items = @basictool.fonts.data
|
2018-09-13 20:21:07 +02:00
|
|
|
item = i for v, i in items when v.name is name
|
2020-06-25 18:23:33 +02:00
|
|
|
return unless item isnt undefined
|
|
|
|
@basictool.fonts.selected = item
|
2018-09-13 20:21:07 +02:00
|
|
|
|
|
|
|
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
|
2020-06-25 18:23:33 +02:00
|
|
|
@directFormattingCtl.setBold (not @basictool.bold.selected)
|
2018-09-13 20:21:07 +02:00
|
|
|
|
|
|
|
italic: (e) ->
|
2020-06-25 18:23:33 +02:00
|
|
|
@directFormattingCtl.setItalic (not @basictool.italic.selected)
|
2018-09-13 20:21:07 +02:00
|
|
|
|
|
|
|
underline: (e) ->
|
2020-06-25 18:23:33 +02:00
|
|
|
@directFormattingCtl.setHasUnderline (not @basictool.underline.selected)
|
2018-09-13 20:21:07 +02:00
|
|
|
|
|
|
|
strike: (e) ->
|
2020-06-25 18:23:33 +02:00
|
|
|
@directFormattingCtl.setHasStrikethrough (not @basictool.strike.selected)
|
2018-09-13 20:21:07 +02:00
|
|
|
|
|
|
|
fonts: (e) ->
|
2020-06-25 18:23:33 +02:00
|
|
|
@directFormattingCtl.setFontName e.data.item.data.name
|
2018-09-13 20:21:07 +02:00
|
|
|
|
|
|
|
fontsize: (e) ->
|
2020-06-25 18:23:33 +02:00
|
|
|
# present the value change from enter infinity loop
|
|
|
|
@directFormattingCtl.setFontSize e.data
|
2018-09-13 20:21:07 +02:00
|
|
|
|
|
|
|
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
|
2020-06-25 18:23:33 +02:00
|
|
|
|
2018-09-13 20:21:07 +02:00
|
|
|
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
|
2020-06-25 18:23:33 +02:00
|
|
|
@openDialog new HyperLinkDialog(), {title: "__(Insert/edit link)", data: data}
|
|
|
|
.then (d) =>
|
|
|
|
selectionController = @editorSession.sessionController.getSelectionController()
|
2018-09-13 20:21:07 +02:00
|
|
|
if d.readonly
|
|
|
|
# edit the existing link
|
|
|
|
if d.action is "edit"
|
|
|
|
selectedLinkRange = selection.cloneRange()
|
|
|
|
selectedLinkRange.selectNode(linksInSelection[0])
|
|
|
|
selectionController.selectRange(selectedLinkRange, true)
|
2020-06-25 18:23:33 +02:00
|
|
|
@hyperlinkController.removeHyperlinks()
|
|
|
|
@hyperlinkController.addHyperlink d.link
|
2018-09-13 20:21:07 +02:00
|
|
|
else
|
2020-06-25 18:23:33 +02:00
|
|
|
@hyperlinkController.addHyperlink d.link, d.text
|
|
|
|
linksInSelection = @editorSession.getSelectedHyperlinks()
|
2018-09-13 20:21:07 +02:00
|
|
|
selectedLinkRange = selection.cloneRange()
|
|
|
|
selectedLinkRange.selectNode(linksInSelection[0])
|
|
|
|
selectionController.selectRange(selectedLinkRange, true)
|
|
|
|
|
|
|
|
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) ->
|
2020-06-25 18:23:33 +02:00
|
|
|
return new Promise (resolve, error) =>
|
|
|
|
fp = p.asFileHandle()
|
|
|
|
fp.read("binary").then (data) =>
|
2018-09-13 22:32:56 +02:00
|
|
|
blob = new Blob [data], { type: fp.info.mime }
|
|
|
|
reader = new FileReader()
|
2020-06-25 18:23:33 +02:00
|
|
|
reader.onloadend = () =>
|
|
|
|
return error(@throwe __("Unable to load file {0}", 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
|
2020-06-25 18:23:33 +02:00
|
|
|
.catch (e) => error __e e
|
|
|
|
|
2018-09-29 11:19:26 +02:00
|
|
|
###
|
|
|
|
if not isText
|
|
|
|
|
|
|
|
else
|
2020-06-25 18:23:33 +02:00
|
|
|
fp.read (data) =>
|
2018-09-29 11:19:26 +02:00
|
|
|
# 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) ->
|
2020-06-25 18:23:33 +02:00
|
|
|
|
|
|
|
@openDialog "FileDialog", { title: __("Select image file"), mimes: ["image/.*"] }
|
|
|
|
.then (f) =>
|
|
|
|
p = f.file.path
|
|
|
|
@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
|
2020-06-25 18:23:33 +02:00
|
|
|
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
|
2020-06-25 18:23:33 +02:00
|
|
|
@textController.removeCurrentSelection()
|
|
|
|
@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
|
2020-06-25 18:23:33 +02:00
|
|
|
.catch (e) =>
|
|
|
|
@error __("Couldnt load image {0}", p), e
|
2018-09-13 22:32:56 +02:00
|
|
|
|
2018-09-14 19:35:01 +02:00
|
|
|
styles: (e) ->
|
2020-06-25 18:23:33 +02:00
|
|
|
return if e.data.item.data.name is @currentStyle
|
|
|
|
@editorSession.setCurrentParagraphStyle e.data.item.data.name
|
2018-09-14 19:35:01 +02:00
|
|
|
|
|
|
|
zoom: (e) ->
|
|
|
|
#console.log "zooming", e
|
2018-09-15 21:36:01 +02:00
|
|
|
return unless @zoomHelper
|
2020-06-25 18:23:33 +02:00
|
|
|
@zoomHelper.setZoomLevel e.data/100.0
|
2018-09-14 19:35:01 +02:00
|
|
|
|
|
|
|
format: (e) ->
|
2020-06-25 18:23:33 +02:00
|
|
|
@openDialog new FormatDialog(), { title: __("Add/Modify paragraph format"), data: @resource }
|
|
|
|
.then (d) =>
|
2018-09-15 21:36:01 +02:00
|
|
|
return
|
2018-09-14 19:35:01 +02:00
|
|
|
|
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
|
2020-06-25 18:23:33 +02:00
|
|
|
|
2018-09-13 20:21:07 +02:00
|
|
|
@eventSubscriptions.unsubscribeAll()
|
|
|
|
@editorSession.sessionController.endEditing()
|
|
|
|
@editorSession.sessionController.removeLocalCursor()
|
|
|
|
# remove user
|
|
|
|
op = new ops.OpRemoveMember()
|
|
|
|
op.init {
|
|
|
|
memberid: @userid
|
|
|
|
}
|
|
|
|
@session.enqueue [op]
|
|
|
|
# close the session
|
2020-06-25 18:23:33 +02:00
|
|
|
@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
|
2018-09-13 20:21:07 +02:00
|
|
|
# destry editorSession
|
2020-06-25 18:23:33 +02:00
|
|
|
@editorSession.destroy (e) =>
|
|
|
|
return @error __("Cannot destroy editor session {0}", e.toString()), e if e
|
|
|
|
@editorSession = undefined
|
2018-09-13 20:21:07 +02:00
|
|
|
# destroy session
|
2020-06-25 18:23:33 +02:00
|
|
|
@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"
|
2018-09-16 20:26:49 +02:00
|
|
|
f() if f
|
2020-06-25 18:23:33 +02:00
|
|
|
@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
|
2018-09-16 20:26:49 +02:00
|
|
|
|
2018-09-13 20:21:07 +02:00
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
cleanup: (e) ->
|
2020-06-25 18:23:33 +02:00
|
|
|
|
2018-09-16 20:26:49 +02:00
|
|
|
if @editorSession
|
|
|
|
e.preventDefault()
|
2020-06-25 18:23:33 +02:00
|
|
|
@closeDocument ()=>
|
|
|
|
@quit()
|
2018-09-13 20:21:07 +02:00
|
|
|
|
2018-09-13 00:41:06 +02:00
|
|
|
this.OS.register "OpenPage", OpenPage
|