style definition

This commit is contained in:
lxsang 2018-09-15 01:12:36 +02:00
parent f1b94435c5
commit 890dd4b4d1
4 changed files with 383 additions and 65 deletions

File diff suppressed because one or more lines are too long

View File

@ -49,6 +49,11 @@ class FormatDialog extends this.OS.GUI.BaseDialog
right: @find("spnright"), right: @find("spnright"),
top: @find("spntop"), top: @find("spntop"),
bottom: @find("spnbottom"), bottom: @find("spnbottom"),
padding:
left: @find("pspnleft"),
right: @find("pspnright"),
top: @find("pspntop"),
bottom: @find("pspnbottom"),
style: style:
bold: @find("swbold"), bold: @find("swbold"),
italic: @find("switalic"), italic: @find("switalic"),
@ -59,6 +64,15 @@ class FormatDialog extends this.OS.GUI.BaseDialog
family: @find("lstfont"), family: @find("lstfont"),
size: @find("spnfsize") size: @find("spnfsize")
formats: @find("lstformats") formats: @find("lstformats")
@initStyleObject()
@preview = ($(@find "preview").find "p")[0]
$(@preview)
.css "padding", "0"
.css "margin", "0"
@initUIEvent()
#@previewStyle()
initStyleObject: ()->
# init the format object # init the format object
@currentStyle = @currentStyle =
aligment: @_api.switcher("left", "right", "center", "justify"), aligment: @_api.switcher("left", "right", "center", "justify"),
@ -67,6 +81,11 @@ class FormatDialog extends this.OS.GUI.BaseDialog
top:0, top:0,
right:0, right:0,
bottom:0 bottom:0
padding:
left:0
top:0,
right:0,
bottom:0
style: style:
bold:false, bold:false,
italic: false, italic: false,
@ -76,12 +95,6 @@ class FormatDialog extends this.OS.GUI.BaseDialog
font: font:
family: undefined, family: undefined,
size: 12 size: 12
@preview = ($(@find "preview").find "p")[0]
$(@preview)
.css "padding", "0"
.css "margin", "0"
@initUIEvent()
@previewStyle()
initUIEvent: () -> initUIEvent: () ->
me = @ me = @
@ -96,6 +109,8 @@ class FormatDialog extends this.OS.GUI.BaseDialog
set "onchange", "aligment", k, ((e) -> e.data) set "onchange", "aligment", k, ((e) -> e.data)
for k,v of @ui.spacing for k,v of @ui.spacing
set "onchange", "spacing", k set "onchange", "spacing", k
for k,v of @ui.padding
set "onchange", "padding", k
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 "onchange", "style", k, ((e) -> e.data) if k isnt "color" and k isnt "bgcolor"
set "onchange", "font", "size" set "onchange", "font", "size"
@ -116,14 +131,86 @@ class FormatDialog extends this.OS.GUI.BaseDialog
@ui.formats.set "onlistselect", (e) -> @ui.formats.set "onlistselect", (e) ->
me.fromODFStyleFormat e.data me.fromODFStyleFormat e.data
@ui.formats.set "selected", 0 @ui.formats.set "selected", 0
#@currentStyle = (@find "btok").set "onbtclick", (e) ->
me.saveCurrentStyle()
(@find "btx").set "onbtclick", (e) ->
me.quit()
(@find "bt-clone").set "onbtclick", (e) ->
me.clone()
clone: ()->
me = @
selected = @ui.formats.get "selected"
return unless selected
@openDialog "PromptDialog", (d) ->
return me.notify __("Abort: no style name is specified") unless d and d.trim() isnt ""
newstyle = me.parent.editorSession.cloneParagraphStyle selected.name, d
me.ui.formats.push { text:d, name: newstyle }
me.ui.formats.set "selected", ((me.ui.formats.get 'count') - 1)
me.notify __("New style: {0} added", newstyle)
, __("Clone style: {0}", selected.text), { label: __("New style name:") }
saveCurrentStyle: () ->
selected = @ui.formats.get "selected"
return unless selected
odfs =
"style:paragraph-properties":
"fo:margin-top": @currentStyle.spacing.top + "mm"
"fo:margin-left": @currentStyle.spacing.left + "mm"
"fo:margin-bottom": @currentStyle.spacing.bottom + "mm"
"fo:margin-right": @currentStyle.spacing.right + "mm"
"fo:padding-top": @currentStyle.padding.top + "mm"
"fo:padding-left": @currentStyle.padding.left + "mm"
"fo:padding-bottom": @currentStyle.padding.bottom + "mm"
"fo:padding-right": @currentStyle.padding.right + "mm"
"fo:text-align": @currentStyle.aligment.selected || "left"
"style:text-properties":
"fo:font-weight": if @currentStyle.style.bold then "bold" else "normal"
"fo:font-style": if @currentStyle.style.italic then "italic" else "normal"
"style:text-underline-style": if @currentStyle.style.underline then "solid" else "none"
"fo:font-size": @currentStyle.font.size + "pt"
"fo:font-name": @currentStyle.font.family.text
"fo:color": if @currentStyle.style.color then @currentStyle.style.color.hex else "#000000"
"fo:background-color": if @currentStyle.style.bgcolor then @currentStyle.style.bgcolor.hex else "transparent"
@parent.editorSession.updateParagraphStyle selected.name, odfs
@notify __("Paragraph format [{0}] is saved", selected.text)
fromODFStyleFormat: (odfs) -> fromODFStyleFormat: (odfs) ->
console.log "change style" me = @
console.log odfs @initStyleObject()
cssUnits = new core.CSSUnits()
findFont = (name) ->
items = me.ui.font.family.get "items"
item = v for v in items when v.text is name
return undefined unless item
return item
# spacing
style = @parent.editorSession.getParagraphStyleAttributes(odfs.name)['style:paragraph-properties']
if style
@currentStyle.spacing.top = cssUnits.convertMeasure(style['fo:margin-top'], 'mm') || 0
@currentStyle.spacing.left = cssUnits.convertMeasure(style['fo:margin-left'], 'mm') || 0
@currentStyle.spacing.right = cssUnits.convertMeasure(style['fo:margin-right'], 'mm') || 0
@currentStyle.spacing.bottom = cssUnits.convertMeasure(style['fo:margin-bottom'], 'mm') || 0
@currentStyle.padding.top = cssUnits.convertMeasure(style['fo:padding-top'], 'mm') || 0
@currentStyle.padding.left = cssUnits.convertMeasure(style['fo:padding-left'], 'mm') || 0
@currentStyle.padding.right = cssUnits.convertMeasure(style['fo:padding-right'], 'mm') || 0
@currentStyle.padding.bottom = cssUnits.convertMeasure(style['fo:padding-bottom'], 'mm') || 0
@currentStyle.aligment[style['fo:text-align']] = true if style['fo:text-align']
style = @parent.editorSession.getParagraphStyleAttributes(odfs.name)['style:text-properties']
if style
@currentStyle.style.bold = style['fo:font-weight'] is 'bold'
@currentStyle.style.italic = style['fo:font-style'] is 'italic'
@currentStyle.style.underline = true if style['style:text-underline-style'] and style['style:text-underline-style'] isnt 'none'
@currentStyle.font.size = parseFloat style['fo:font-size']
@currentStyle.font.family = findFont style['style:font-name']
@currentStyle.style.color = { hex: style['fo:color'] } if style['fo:color']
@currentStyle.style.bgcolor = { hex: style['fo:background-color'] } if style['fo:background-color']
@previewStyle()
previewStyle: () -> previewStyle: () ->
console.log "previewing" #console.log "previewing"
# reset ui # reset ui
@ui.aligment.left.set "swon", @currentStyle.aligment.left @ui.aligment.left.set "swon", @currentStyle.aligment.left
@ui.aligment.right.set "swon", @currentStyle.aligment.right @ui.aligment.right.set "swon", @currentStyle.aligment.right
@ -133,24 +220,38 @@ class FormatDialog extends this.OS.GUI.BaseDialog
@ui.spacing.right.set "value", @currentStyle.spacing.right @ui.spacing.right.set "value", @currentStyle.spacing.right
@ui.spacing.top.set "value", @currentStyle.spacing.top @ui.spacing.top.set "value", @currentStyle.spacing.top
@ui.spacing.bottom.set "value", @currentStyle.spacing.bottom @ui.spacing.bottom.set "value", @currentStyle.spacing.bottom
@ui.padding.left.set "value", @currentStyle.padding.left
@ui.padding.right.set "value", @currentStyle.padding.right
@ui.padding.top.set "value", @currentStyle.padding.top
@ui.padding.bottom.set "value", @currentStyle.padding.bottom
@ui.style.bold.set "swon", @currentStyle.style.bold @ui.style.bold.set "swon", @currentStyle.style.bold
@ui.style.italic.set "swon", @currentStyle.style.italic @ui.style.italic.set "swon", @currentStyle.style.italic
@ui.style.underline.set "swon", @currentStyle.style.underline @ui.style.underline.set "swon", @currentStyle.style.underline
@ui.font.size.set "value", @currentStyle.font.size @ui.font.size.set "value", @currentStyle.font.size
items = @ui.font.family.get "items" #console.log @currentStyle
item = i for v, i in items when v.name is name if @currentStyle.font.family
@ui.font.family.set "selected", item if item >= 0 items = @ui.font.family.get "items"
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.style.color).css "background-color", @currentStyle.style.color.hex if @currentStyle.style.color $(@ui.style.color).css "background-color", @currentStyle.style.color.hex if @currentStyle.style.color
$(@ui.style.bgcolor).css "background-color", @currentStyle.style.bgcolor.hex if @currentStyle.style.bgcolor $(@ui.style.bgcolor).css "background-color", @currentStyle.style.bgcolor.hex if @currentStyle.style.bgcolor
# set the preview css # set the preview css
el = $ @preview el = $ @preview
el.css "text-align", @currentStyle.aligment.selected el.css "text-align", @currentStyle.aligment.selected
el.css "padding-left", @currentStyle.spacing.left + "mm" el.css "margin-left", @currentStyle.spacing.left + "mm"
el.css "padding-right", @currentStyle.spacing.right + "mm" el.css "margin-right", @currentStyle.spacing.right + "mm"
el.css "padding-top", @currentStyle.spacing.top + "mm" el.css "margin-top", @currentStyle.spacing.top + "mm"
el.css "padding-bottom", @currentStyle.spacing.bottom + "mm" el.css "margin-bottom", @currentStyle.spacing.bottom + "mm"
el.css "padding-left", @currentStyle.padding.left + "mm"
el.css "padding-right", @currentStyle.padding.right + "mm"
el.css "padding-top", @currentStyle.padding.top + "mm"
el.css "padding-bottom", @currentStyle.padding.bottom + "mm"
el el
.css "font-weight", "normal" .css "font-weight", "normal"
.css "font-style", "normal" .css "font-style", "normal"
@ -164,14 +265,14 @@ class FormatDialog extends this.OS.GUI.BaseDialog
el.css "font-family", @currentStyle.font.family.name if @currentStyle.font.family el.css "font-family", @currentStyle.font.family.name if @currentStyle.font.family
FormatDialog.scheme = """ FormatDialog.scheme = """
<afx-app-window apptitle="__(Format Dialog)" width="500" height="450" data-id="FormatDialog"> <afx-app-window apptitle="__(Format Dialog)" width="500" height="500" data-id="FormatDialog">
<afx-vbox> <afx-vbox>
<div data-height="5"></div> <div data-height="5"></div>
<afx-hbox data-height="30"> <afx-hbox data-height="30">
<div data-width="5"></div> <div data-width="5"></div>
<afx-list-view data-id="lstformats" dropdown = "true"></afx-list-view> <afx-list-view data-id="lstformats" dropdown = "true"></afx-list-view>
<div data-width="5" ></div> <div data-width="5" ></div>
<afx-button text="clone" data-id="bt-clone" iconclass = "fa fa-copy" data-width="60"></afx-button> <afx-button text="clone" data-id="bt-clone" iconclass = "fa fa-copy" data-width="65"></afx-button>
<div data-width="5"></div> <div data-width="5"></div>
</afx-hbox> </afx-hbox>
<afx-label text="__(Aligment)" class="header" data-height="20"></afx-label> <afx-label text="__(Aligment)" class="header" data-height="20"></afx-label>
@ -205,6 +306,25 @@ FormatDialog.scheme = """
<afx-nspinner data-width="50" data-id="spnbottom" step="0.5"></afx-nspinner> <afx-nspinner data-width="50" data-id="spnbottom" step="0.5"></afx-nspinner>
<div ></div> <div ></div>
</afx-hbox> </afx-hbox>
<div data-height="5"></div>
<afx-label text="__(Padding)" class="header" data-height="20"></afx-label>
<div data-height="5"></div>
<afx-hbox data-height="23" data-id="spacingbox">
<div ></div>
<afx-label data-width="50" text="__(Left:)"></afx-label>
<afx-nspinner data-width="50" data-id="pspnleft" step="0.5"></afx-nspinner>
<div></div>
<afx-label data-width="50" text="__(Right:)"></afx-label>
<afx-nspinner data-width="50" data-id="pspnright" step="0.5"></afx-nspinner>
<div></div>
<afx-label data-width="50" text="__(Top:)"></afx-label>
<afx-nspinner data-width="50" data-id="pspntop" step="0.5"></afx-nspinner>
<div></div>
<afx-label data-width="50" text="__(Bottom:)"></afx-label>
<afx-nspinner data-width="50" data-id="pspnbottom" step="0.5"></afx-nspinner>
<div ></div>
</afx-hbox>
<div data-height="5"></div> <div data-height="5"></div>
<afx-label text="__(Style)" class="header" data-height="20"></afx-label> <afx-label text="__(Style)" class="header" data-height="20"></afx-label>
<div data-height="5"></div> <div data-height="5"></div>
@ -248,7 +368,7 @@ FormatDialog.scheme = """
<div data-height="5"></div> <div data-height="5"></div>
<afx-hbox data-height="30"> <afx-hbox data-height="30">
<div></div> <div></div>
<afx-button text="__(Ok)" data-width="30" data-id="btok"></afx-button> <afx-button text="__(Save)" data-width="35" data-id="btok"></afx-button>
<div data-width="5"></div> <div data-width="5"></div>
<afx-button text="__(Cancel)" data-width="55" data-id="btx"></afx-button> <afx-button text="__(Cancel)" data-width="55" data-id="btx"></afx-button>
</afx-hbox> </afx-hbox>

View File

@ -4,9 +4,9 @@ class OpenPage extends this.OS.GUI.BaseApplication
main: () -> main: () ->
# load session class # load session class
if not OpenPage.EditorSession #if not OpenPage.EditorSession
require ["webodf/editor/EditorSession"], (ES) -> # require ["webodf/editor/EditorSession"], (ES) ->
OpenPage.EditorSession = ES # OpenPage.EditorSession = ES
@userid = @systemsetting.user.username @userid = @systemsetting.user.username
@eventSubscriptions = new core.EventSubscriptions() @eventSubscriptions = new core.EventSubscriptions()
@initToolbox() @initToolbox()
@ -81,6 +81,17 @@ class OpenPage extends this.OS.GUI.BaseApplication
me.currentStyle = e.styleName me.currentStyle = e.styleName
me.basictool.styles.set "selected", item me.basictool.styles.set "selected", item
@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}
@updateSlider = (v) -> @updateSlider = (v) ->
value = Math.floor v*100 value = Math.floor v*100
me.basictool.zoom.set "value", value me.basictool.zoom.set "value", value
@ -132,6 +143,9 @@ class OpenPage extends this.OS.GUI.BaseApplication
me.zoomHelper.subscribe gui.ZoomHelper.signalZoomChanged, me.updateSlider me.zoomHelper.subscribe gui.ZoomHelper.signalZoomChanged, me.updateSlider
me.updateSlider me.zoomHelper.getZoomLevel() me.updateSlider me.zoomHelper.getZoomLevel()
# format controller
me.editorSession.subscribe OpenPage.EditorSession.signalCommonStyleCreated, me.styleAdded
me.editorSession.sessionController.setUndoManager new gui.TrivialUndoManager() me.editorSession.sessionController.setUndoManager new gui.TrivialUndoManager()
me.editorSession.sessionController.getUndoManager().subscribe gui.UndoManager.signalDocumentModifiedChanged, me.documentChanged me.editorSession.sessionController.getUndoManager().subscribe gui.UndoManager.signalDocumentModifiedChanged, me.documentChanged
me.editorSession.sessionController.getMetadataController().subscribe gui.MetadataController.signalMetadataChanged, me.metaChanged me.editorSession.sessionController.getMetadataController().subscribe gui.MetadataController.signalMetadataChanged, me.metaChanged
@ -157,8 +171,9 @@ class OpenPage extends this.OS.GUI.BaseApplication
@basictool.fonts.set "items", list @basictool.fonts.set "items", list
initStyles: (list) -> initStyles: (list) ->
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, el: @editorSession.getParagraphStyleElement(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.set "items", list
updateToolbar: (changes) -> updateToolbar: (changes) ->
@ -335,6 +350,7 @@ class OpenPage extends this.OS.GUI.BaseApplication
me.directFormattingCtl.unsubscribe gui.DirectFormattingController.paragraphStylingChanged, me.textStylingChanged me.directFormattingCtl.unsubscribe gui.DirectFormattingController.paragraphStylingChanged, me.textStylingChanged
me.editorSession.unsubscribe OpenPage.EditorSession.signalParagraphChanged, me.paragrahStyleChanged me.editorSession.unsubscribe OpenPage.EditorSession.signalParagraphChanged, me.paragrahStyleChanged
me.zoomHelper.unsubscribe gui.ZoomHelper.signalZoomChanged, me.updateSlider me.zoomHelper.unsubscribe gui.ZoomHelper.signalZoomChanged, me.updateSlider
me.editorSession.unsubscribe OpenPage.EditorSession.signalCommonStyleCreated, me.styleAdded
# destry editorSession # destry editorSession
me.editorSession.destroy (e) -> me.editorSession.destroy (e) ->
return me.error __("Cannot destroy editor session {0}", e) if e return me.error __("Cannot destroy editor session {0}", e) if e
@ -355,6 +371,7 @@ class OpenPage extends this.OS.GUI.BaseApplication
me.textStylingChanged = undefined me.textStylingChanged = undefined
me.paragrahStyleChanged = undefined me.paragrahStyleChanged = undefined
me.updateSlider = undefined me.updateSlider = undefined
me.styleAdded = undefined
# #

View File

@ -24,9 +24,10 @@
/*global runtime, define, document, core, odf, gui, ops*/ /*global runtime, define, document, core, odf, gui, ops*/
define("webodf/editor/EditorSession", [ /*define("webodf/editor/EditorSession", [
"dojo/text!resources/fonts/fonts.css" "dojo/text!resources/fonts/fonts.css"
], function (fontsCSS) { // fontsCSS is retrieved as a string, using dojo's text retrieval AMD plugin ],*/
this.OS.APP.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");
@ -656,5 +657,5 @@ define("webodf/editor/EditorSession", [
/**@const*/EditorSession.signalUndoStackChanged = "signalUndoStackChanged"; /**@const*/EditorSession.signalUndoStackChanged = "signalUndoStackChanged";
return EditorSession; return EditorSession;
}); })("");