|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function DiagramPage(node, id) |
|
{ |
|
this.node = node; |
|
|
|
if (id != null) |
|
{ |
|
this.node.setAttribute('id', id); |
|
} |
|
else if (this.getId() == null) |
|
{ |
|
this.node.setAttribute('id', Editor.guid()); |
|
} |
|
}; |
|
|
|
|
|
|
|
|
|
DiagramPage.prototype.node = null; |
|
|
|
|
|
|
|
|
|
DiagramPage.prototype.root = null; |
|
|
|
|
|
|
|
|
|
DiagramPage.prototype.viewState = null; |
|
|
|
|
|
|
|
|
|
DiagramPage.prototype.getId = function() |
|
{ |
|
return this.node.getAttribute('id'); |
|
}; |
|
|
|
|
|
|
|
|
|
DiagramPage.prototype.getName = function() |
|
{ |
|
return this.node.getAttribute('name'); |
|
}; |
|
|
|
|
|
|
|
|
|
DiagramPage.prototype.setName = function(value) |
|
{ |
|
if (value == null) |
|
{ |
|
this.node.removeAttribute('name'); |
|
} |
|
else |
|
{ |
|
this.node.setAttribute('name', value); |
|
} |
|
}; |
|
|
|
|
|
|
|
|
|
function RenamePage(ui, page, name) |
|
{ |
|
this.ui = ui; |
|
this.page = page; |
|
this.name = name; |
|
this.previous = name; |
|
} |
|
|
|
|
|
|
|
|
|
RenamePage.prototype.execute = function() |
|
{ |
|
var tmp = this.page.getName(); |
|
this.page.setName(this.previous); |
|
this.name = this.previous; |
|
this.previous = tmp; |
|
|
|
|
|
this.ui.editor.graph.updatePlaceholders(); |
|
this.ui.editor.fireEvent(new mxEventObject('pageRenamed')); |
|
}; |
|
|
|
|
|
|
|
|
|
function MovePage(ui, oldIndex, newIndex) |
|
{ |
|
this.ui = ui; |
|
this.oldIndex = oldIndex; |
|
this.newIndex = newIndex; |
|
} |
|
|
|
|
|
|
|
|
|
MovePage.prototype.execute = function() |
|
{ |
|
this.ui.pages.splice(this.newIndex, 0, this.ui.pages.splice(this.oldIndex, 1)[0]); |
|
var tmp = this.oldIndex; |
|
this.oldIndex = this.newIndex; |
|
this.newIndex = tmp; |
|
|
|
|
|
this.ui.editor.graph.updatePlaceholders(); |
|
this.ui.editor.fireEvent(new mxEventObject('pageMoved')); |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function SelectPage(ui, page, viewState) |
|
{ |
|
this.ui = ui; |
|
this.page = page; |
|
this.previousPage = page; |
|
this.neverShown = true; |
|
|
|
if (page != null) |
|
{ |
|
this.neverShown = page.viewState == null; |
|
this.ui.updatePageRoot(page); |
|
|
|
if (viewState != null) |
|
{ |
|
page.viewState = viewState; |
|
this.neverShown = false; |
|
} |
|
} |
|
}; |
|
|
|
|
|
|
|
|
|
SelectPage.prototype.execute = function() |
|
{ |
|
var prevIndex = mxUtils.indexOf(this.ui.pages, this.previousPage); |
|
|
|
if (this.page != null && prevIndex >= 0) |
|
{ |
|
var page = this.ui.currentPage; |
|
var editor = this.ui.editor; |
|
var graph = editor.graph; |
|
|
|
|
|
var data = Graph.compressNode(editor.getGraphXml(true)); |
|
mxUtils.setTextContent(page.node, data); |
|
page.viewState = graph.getViewState(); |
|
page.root = graph.model.root; |
|
|
|
if (page.model != null) |
|
{ |
|
|
|
page.model.rootChanged(page.root); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
graph.view.clear(page.root, true); |
|
graph.clearSelection(); |
|
|
|
|
|
this.ui.currentPage = this.previousPage; |
|
this.previousPage = page; |
|
page = this.ui.currentPage; |
|
|
|
|
|
graph.model.prefix = Editor.guid() + '-'; |
|
graph.model.rootChanged(page.root); |
|
graph.setViewState(page.viewState); |
|
|
|
|
|
graph.gridEnabled = graph.gridEnabled && (!this.ui.editor.isChromelessView() || |
|
urlParams['grid'] == '1'); |
|
|
|
|
|
editor.updateGraphComponents(); |
|
graph.view.validate(); |
|
graph.blockMathRender = true; |
|
graph.sizeDidChange(); |
|
graph.blockMathRender = false; |
|
|
|
|
|
|
|
|
|
if (this.neverShown) |
|
{ |
|
this.neverShown = false; |
|
graph.selectUnlockedLayer(); |
|
} |
|
|
|
|
|
editor.graph.fireEvent(new mxEventObject(mxEvent.ROOT)); |
|
editor.fireEvent(new mxEventObject('pageSelected', 'change', this)); |
|
} |
|
}; |
|
|
|
|
|
|
|
|
|
function ChangePage(ui, page, select, index, noSelect) |
|
{ |
|
SelectPage.call(this, ui, select); |
|
this.relatedPage = page; |
|
this.index = index; |
|
this.previousIndex = null; |
|
this.noSelect = noSelect; |
|
}; |
|
|
|
mxUtils.extend(ChangePage, SelectPage); |
|
|
|
|
|
|
|
|
|
|
|
|
|
ChangePage.prototype.execute = function() |
|
{ |
|
|
|
this.ui.editor.fireEvent(new mxEventObject('beforePageChange', 'change', this)); |
|
this.previousIndex = this.index; |
|
|
|
if (this.index == null) |
|
{ |
|
var tmp = mxUtils.indexOf(this.ui.pages, this.relatedPage); |
|
this.ui.pages.splice(tmp, 1); |
|
this.index = tmp; |
|
} |
|
else |
|
{ |
|
this.ui.pages.splice(this.index, 0, this.relatedPage); |
|
this.index = null; |
|
} |
|
|
|
if (!this.noSelect) |
|
{ |
|
SelectPage.prototype.execute.apply(this, arguments); |
|
} |
|
}; |
|
|
|
|
|
|
|
|
|
EditorUi.prototype.tabContainerHeight = 38; |
|
|
|
|
|
|
|
|
|
EditorUi.prototype.getSelectedPageIndex = function() |
|
{ |
|
return this.getPageIndex(this.currentPage); |
|
}; |
|
|
|
|
|
|
|
|
|
EditorUi.prototype.getPageIndex = function(page) |
|
{ |
|
var result = null; |
|
|
|
if (this.pages != null && page != null) |
|
{ |
|
for (var i = 0; i < this.pages.length; i++) |
|
{ |
|
if (this.pages[i] == page) |
|
{ |
|
result = i; |
|
|
|
break; |
|
} |
|
} |
|
} |
|
|
|
return result; |
|
}; |
|
|
|
|
|
|
|
|
|
EditorUi.prototype.getPageById = function(id, pages) |
|
{ |
|
pages = (pages != null) ? pages : this.pages; |
|
|
|
if (pages != null) |
|
{ |
|
for (var i = 0; i < pages.length; i++) |
|
{ |
|
if (pages[i].getId() == id) |
|
{ |
|
return pages[i]; |
|
} |
|
} |
|
} |
|
|
|
return null; |
|
}; |
|
|
|
|
|
|
|
|
|
EditorUi.prototype.createImageForPageLink = function(src, sourcePage, sourceGraph) |
|
{ |
|
var comma = src.indexOf(','); |
|
var result = null; |
|
|
|
if (comma > 0) |
|
{ |
|
var page = this.getPageById(src.substring(comma + 1)); |
|
|
|
if (page != null && page != sourcePage) |
|
{ |
|
result = this.getImageForPage(page, sourcePage, sourceGraph); |
|
result.originalSrc = src; |
|
} |
|
} |
|
|
|
if (result == null) |
|
{ |
|
result = {originalSrc: src}; |
|
} |
|
|
|
return result; |
|
}; |
|
|
|
|
|
|
|
|
|
EditorUi.prototype.getImageForPage = function(page, sourcePage, sourceGraph) |
|
{ |
|
sourceGraph = (sourceGraph != null) ? sourceGraph : this.editor.graph; |
|
var graphGetGlobalVariable = sourceGraph.getGlobalVariable; |
|
var graph = this.createTemporaryGraph(sourceGraph.getStylesheet()); |
|
graph.defaultPageBackgroundColor = sourceGraph.defaultPageBackgroundColor; |
|
graph.shapeBackgroundColor = sourceGraph.shapeBackgroundColor; |
|
graph.shapeForegroundColor = sourceGraph.shapeForegroundColor; |
|
var index = this.getPageIndex((sourcePage != null) ? |
|
sourcePage : this.currentPage); |
|
|
|
graph.getGlobalVariable = function(name) |
|
{ |
|
if (name == 'pagenumber') |
|
{ |
|
return index + 1; |
|
} |
|
else if (name == 'page' && sourcePage != null) |
|
{ |
|
return sourcePage.getName(); |
|
} |
|
else |
|
{ |
|
return graphGetGlobalVariable.apply(this, arguments); |
|
} |
|
}; |
|
|
|
document.body.appendChild(graph.container); |
|
|
|
this.updatePageRoot(page); |
|
graph.model.setRoot(page.root); |
|
|
|
var temp = Graph.foreignObjectWarningText; |
|
Graph.foreignObjectWarningText = ''; |
|
var svgRoot = graph.getSvg(null, null, null, null, null, |
|
null, null, null, null, null, null, true); |
|
var bounds = graph.getGraphBounds(); |
|
document.body.removeChild(graph.container); |
|
Graph.foreignObjectWarningText = temp; |
|
|
|
return new mxImage(Editor.createSvgDataUri(mxUtils.getXml(svgRoot)), |
|
bounds.width, bounds.height, bounds.x, bounds.y); |
|
}; |
|
|
|
|
|
|
|
|
|
EditorUi.prototype.initPages = function() |
|
{ |
|
if (!this.editor.graph.standalone) |
|
{ |
|
this.actions.addAction('previousPage', mxUtils.bind(this, function() |
|
{ |
|
this.selectNextPage(false); |
|
})); |
|
|
|
this.actions.addAction('nextPage', mxUtils.bind(this, function() |
|
{ |
|
this.selectNextPage(true); |
|
})); |
|
|
|
if (this.isPagesEnabled()) |
|
{ |
|
this.keyHandler.bindAction(33, true, 'previousPage', true); |
|
this.keyHandler.bindAction(34, true, 'nextPage', true); |
|
} |
|
|
|
|
|
var graph = this.editor.graph; |
|
var graphViewValidateBackground = graph.view.validateBackground; |
|
|
|
graph.view.validateBackground = mxUtils.bind(this, function() |
|
{ |
|
if (this.tabContainer != null) |
|
{ |
|
var prevHeight = this.tabContainer.style.height; |
|
|
|
if (this.fileNode == null || this.pages == null || |
|
(this.pages.length == 1 && urlParams['pages'] == '0')) |
|
{ |
|
this.tabContainer.style.height = '0px'; |
|
} |
|
else |
|
{ |
|
this.tabContainer.style.height = this.tabContainerHeight + 'px'; |
|
} |
|
|
|
if (prevHeight != this.tabContainer.style.height) |
|
{ |
|
this.refresh(false); |
|
} |
|
} |
|
|
|
graphViewValidateBackground.apply(graph.view, arguments); |
|
}); |
|
|
|
var lastPage = null; |
|
|
|
var updateTabs = mxUtils.bind(this, function() |
|
{ |
|
this.updateTabContainer(); |
|
|
|
|
|
var p = this.currentPage; |
|
|
|
if (p != null && p != lastPage) |
|
{ |
|
if (p.viewState == null || p.viewState.scrollLeft == null) |
|
{ |
|
this.resetScrollbars(); |
|
|
|
if (graph.isLightboxView()) |
|
{ |
|
this.lightboxFit(); |
|
} |
|
|
|
if (this.chromelessResize != null) |
|
{ |
|
graph.container.scrollLeft = 0; |
|
graph.container.scrollTop = 0; |
|
this.chromelessResize(); |
|
} |
|
} |
|
else |
|
{ |
|
graph.container.scrollLeft = graph.view.translate.x * graph.view.scale + p.viewState.scrollLeft; |
|
graph.container.scrollTop = graph.view.translate.y * graph.view.scale + p.viewState.scrollTop; |
|
} |
|
|
|
lastPage = p; |
|
} |
|
|
|
|
|
if (this.actions.layersWindow != null) |
|
{ |
|
this.actions.layersWindow.refreshLayers(); |
|
} |
|
|
|
|
|
if (typeof(MathJax) !== 'undefined' && typeof(MathJax.Hub) !== 'undefined') |
|
{ |
|
|
|
if (MathJax.Hub.queue.pending == 1 && this.editor != null && !this.editor.graph.mathEnabled) |
|
{ |
|
|
|
|
|
MathJax.Hub.Queue(mxUtils.bind(this, function() |
|
{ |
|
if (this.editor != null) |
|
{ |
|
this.editor.graph.refresh(); |
|
} |
|
})); |
|
} |
|
} |
|
else if (typeof(Editor.MathJaxClear) !== 'undefined' && (this.editor == null || !this.editor.graph.mathEnabled)) |
|
{ |
|
|
|
Editor.MathJaxClear(); |
|
} |
|
}); |
|
|
|
|
|
this.editor.graph.model.addListener(mxEvent.CHANGE, mxUtils.bind(this, function(sender, evt) |
|
{ |
|
var edit = evt.getProperty('edit'); |
|
var changes = edit.changes; |
|
|
|
for (var i = 0; i < changes.length; i++) |
|
{ |
|
if (changes[i] instanceof SelectPage || |
|
changes[i] instanceof RenamePage || |
|
changes[i] instanceof MovePage || |
|
changes[i] instanceof mxRootChange) |
|
{ |
|
updateTabs(); |
|
break; |
|
} |
|
} |
|
})); |
|
|
|
|
|
if (this.toolbar != null) |
|
{ |
|
this.editor.addListener('pageSelected', this.toolbar.updateZoom); |
|
} |
|
} |
|
}; |
|
|
|
|
|
|
|
|
|
EditorUi.prototype.restoreViewState = function(page, viewState, selection) |
|
{ |
|
var newPage = (page != null) ? this.getPageById(page.getId()) : null; |
|
var graph = this.editor.graph; |
|
|
|
if (newPage != null && this.currentPage != null && this.pages != null) |
|
{ |
|
if (newPage != this.currentPage) |
|
{ |
|
this.selectPage(newPage, true, viewState); |
|
} |
|
else |
|
{ |
|
|
|
graph.setViewState(viewState); |
|
this.editor.updateGraphComponents(); |
|
graph.view.revalidate(); |
|
graph.sizeDidChange(); |
|
} |
|
|
|
graph.container.scrollLeft = graph.view.translate.x * graph.view.scale + viewState.scrollLeft; |
|
graph.container.scrollTop = graph.view.translate.y * graph.view.scale + viewState.scrollTop; |
|
graph.restoreSelection(selection); |
|
} |
|
}; |
|
|
|
|
|
|
|
|
|
Graph.prototype.createViewState = function(node) |
|
{ |
|
var pv = node.getAttribute('page'); |
|
var ps = parseFloat(node.getAttribute('pageScale')); |
|
var pw = parseFloat(node.getAttribute('pageWidth')); |
|
var ph = parseFloat(node.getAttribute('pageHeight')); |
|
var bg = node.getAttribute('background'); |
|
var bgImg = this.parseBackgroundImage(node.getAttribute('backgroundImage')); |
|
var extFonts = node.getAttribute('extFonts'); |
|
|
|
if (extFonts) |
|
{ |
|
try |
|
{ |
|
extFonts = extFonts.split('|').map(function(ef) |
|
{ |
|
var parts = ef.split('^'); |
|
return {name: parts[0], url: parts[1]}; |
|
}); |
|
} |
|
catch(e) |
|
{ |
|
console.log('ExtFonts format error: ' + e.message); |
|
} |
|
} |
|
|
|
return { |
|
gridEnabled: node.getAttribute('grid') != '0', |
|
|
|
gridSize: parseFloat(node.getAttribute('gridSize')) || mxGraph.prototype.gridSize, |
|
guidesEnabled: node.getAttribute('guides') != '0', |
|
foldingEnabled: node.getAttribute('fold') != '0', |
|
shadowVisible: node.getAttribute('shadow') == '1', |
|
pageVisible: (this.isLightboxView()) ? false : ((pv != null) ? (pv != '0') : this.defaultPageVisible), |
|
background: (bg != null && bg.length > 0) ? bg : null, |
|
backgroundImage: bgImg, |
|
pageScale: (!isNaN(ps)) ? ps : mxGraph.prototype.pageScale, |
|
pageFormat: (!isNaN(pw) && !isNaN(ph)) ? new mxRectangle(0, 0, pw, ph) : |
|
((typeof mxSettings === 'undefined' || this.defaultPageFormat != null) ? |
|
mxGraph.prototype.pageFormat : mxSettings.getPageFormat()), |
|
tooltips: node.getAttribute('tooltips') != '0', |
|
connect: node.getAttribute('connect') != '0', |
|
arrows: node.getAttribute('arrows') != '0', |
|
mathEnabled: node.getAttribute('math') == '1', |
|
selectionCells: null, |
|
defaultParent: null, |
|
scrollbars: this.defaultScrollbars, |
|
scale: 1, |
|
hiddenTags: [], |
|
extFonts: extFonts || [] |
|
}; |
|
}; |
|
|
|
|
|
|
|
|
|
Graph.prototype.saveViewState = function(vs, node, ignoreTransient, resolveReferences) |
|
{ |
|
if (!ignoreTransient) |
|
{ |
|
node.setAttribute('grid', ((vs == null) ? this.defaultGridEnabled : vs.gridEnabled) ? '1' : '0'); |
|
node.setAttribute('page', ((vs == null) ? this.defaultPageVisible : vs.pageVisible) ? '1' : '0'); |
|
node.setAttribute('gridSize', (vs != null) ? vs.gridSize : mxGraph.prototype.gridSize); |
|
node.setAttribute('guides', (vs == null || vs.guidesEnabled) ? '1' : '0'); |
|
node.setAttribute('tooltips', (vs == null || vs.tooltips) ? '1' : '0'); |
|
node.setAttribute('connect', (vs == null || vs.connect) ? '1' : '0'); |
|
node.setAttribute('arrows', (vs == null || vs.arrows) ? '1' : '0'); |
|
|
|
|
|
node.setAttribute('fold', (vs == null || vs.foldingEnabled) ? '1' : '0'); |
|
} |
|
|
|
node.setAttribute('pageScale', (vs != null && vs.pageScale != null) ? |
|
vs.pageScale : mxGraph.prototype.pageScale); |
|
|
|
var pf = (vs != null) ? vs.pageFormat : (typeof mxSettings === 'undefined' || |
|
this.defaultPageFormat != null) ? mxGraph.prototype.pageFormat : |
|
mxSettings.getPageFormat(); |
|
|
|
if (pf != null) |
|
{ |
|
node.setAttribute('pageWidth', pf.width); |
|
node.setAttribute('pageHeight', pf.height); |
|
} |
|
|
|
if (vs != null) |
|
{ |
|
if (vs.background != null) |
|
{ |
|
node.setAttribute('background', vs.background); |
|
} |
|
|
|
var bgImg = this.getBackgroundImageObject(vs.backgroundImage, resolveReferences); |
|
|
|
if (bgImg != null) |
|
{ |
|
node.setAttribute('backgroundImage', JSON.stringify(bgImg)); |
|
} |
|
} |
|
|
|
node.setAttribute('math', ((vs == null) ? this.defaultMathEnabled : vs.mathEnabled) ? '1' : '0'); |
|
node.setAttribute('shadow', (vs != null && vs.shadowVisible) ? '1' : '0'); |
|
|
|
if (vs != null && vs.extFonts != null && vs.extFonts.length > 0) |
|
{ |
|
node.setAttribute('extFonts', vs.extFonts.map(function(ef) |
|
{ |
|
return ef.name + '^' + ef.url; |
|
}).join('|')); |
|
} |
|
}; |
|
|
|
|
|
|
|
|
|
Graph.prototype.getViewState = function() |
|
{ |
|
return { |
|
defaultParent: this.defaultParent, |
|
currentRoot: this.view.currentRoot, |
|
gridEnabled: this.gridEnabled, |
|
|
|
gridSize: this.gridSize, |
|
guidesEnabled: this.graphHandler.guidesEnabled, |
|
foldingEnabled: this.foldingEnabled, |
|
shadowVisible: this.shadowVisible, |
|
scrollbars: this.scrollbars, |
|
pageVisible: this.pageVisible, |
|
background: this.background, |
|
backgroundImage: this.backgroundImage, |
|
pageScale: this.pageScale, |
|
pageFormat: this.pageFormat, |
|
tooltips: this.tooltipHandler.isEnabled(), |
|
connect: this.connectionHandler.isEnabled(), |
|
arrows: this.connectionArrowsEnabled, |
|
scale: this.view.scale, |
|
scrollLeft: this.container.scrollLeft - this.view.translate.x * this.view.scale, |
|
scrollTop: this.container.scrollTop - this.view.translate.y * this.view.scale, |
|
translate: this.view.translate.clone(), |
|
lastPasteXml: this.lastPasteXml, |
|
pasteCounter: this.pasteCounter, |
|
mathEnabled: this.mathEnabled, |
|
hiddenTags: this.hiddenTags, |
|
extFonts: this.extFonts |
|
}; |
|
}; |
|
|
|
|
|
|
|
|
|
Graph.prototype.setViewState = function(state, removeOldExtFonts) |
|
{ |
|
if (state != null) |
|
{ |
|
this.lastPasteXml = state.lastPasteXml; |
|
this.pasteCounter = state.pasteCounter || 0; |
|
this.mathEnabled = state.mathEnabled; |
|
this.gridEnabled = state.gridEnabled; |
|
|
|
this.gridSize = state.gridSize; |
|
this.graphHandler.guidesEnabled = state.guidesEnabled; |
|
this.foldingEnabled = state.foldingEnabled; |
|
this.setShadowVisible(state.shadowVisible, false); |
|
this.scrollbars = state.scrollbars; |
|
this.pageVisible = !this.isViewer() && state.pageVisible; |
|
this.background = state.background; |
|
this.pageScale = state.pageScale; |
|
this.pageFormat = state.pageFormat; |
|
this.view.currentRoot = state.currentRoot; |
|
this.defaultParent = state.defaultParent; |
|
this.connectionArrowsEnabled = state.arrows; |
|
this.setTooltips(state.tooltips); |
|
this.setConnectable(state.connect); |
|
this.setBackgroundImage(state.backgroundImage); |
|
this.hiddenTags = state.hiddenTags; |
|
|
|
var oldExtFonts = this.extFonts; |
|
this.extFonts = state.extFonts || []; |
|
|
|
|
|
|
|
if (removeOldExtFonts && oldExtFonts != null) |
|
{ |
|
for (var i = 0; i < oldExtFonts.length; i++) |
|
{ |
|
var fontElem = document.getElementById('extFont_' + oldExtFonts[i].name); |
|
|
|
if (fontElem != null) |
|
{ |
|
fontElem.parentNode.removeChild(fontElem); |
|
} |
|
} |
|
} |
|
|
|
for (var i = 0; i < this.extFonts.length; i++) |
|
{ |
|
this.addExtFont(this.extFonts[i].name, this.extFonts[i].url, true); |
|
} |
|
|
|
if (state.scale != null) |
|
{ |
|
this.view.scale = state.scale; |
|
} |
|
else |
|
{ |
|
this.view.scale = 1; |
|
} |
|
|
|
|
|
if (this.view.currentRoot != null && |
|
!this.model.contains(this.view.currentRoot)) |
|
{ |
|
this.view.currentRoot = null; |
|
} |
|
|
|
if (this.defaultParent != null && |
|
!this.model.contains(this.defaultParent)) |
|
{ |
|
this.setDefaultParent(null); |
|
this.selectUnlockedLayer(); |
|
} |
|
|
|
if (state.translate != null) |
|
{ |
|
this.view.translate = state.translate; |
|
} |
|
} |
|
else |
|
{ |
|
this.view.currentRoot = null; |
|
this.view.scale = 1; |
|
this.gridEnabled = this.defaultGridEnabled; |
|
this.gridSize = mxGraph.prototype.gridSize; |
|
this.pageScale = mxGraph.prototype.pageScale; |
|
this.pageFormat = (typeof mxSettings === 'undefined' || this.defaultPageFormat != null) ? |
|
mxGraph.prototype.pageFormat : mxSettings.getPageFormat(); |
|
this.pageVisible = this.defaultPageVisible; |
|
this.background = null; |
|
this.backgroundImage = null; |
|
this.scrollbars = this.defaultScrollbars; |
|
this.graphHandler.guidesEnabled = true; |
|
this.foldingEnabled = true; |
|
this.setShadowVisible(false, false); |
|
this.defaultParent = null; |
|
this.setTooltips(true); |
|
this.setConnectable(true); |
|
this.lastPasteXml = null; |
|
this.pasteCounter = 0; |
|
this.mathEnabled = this.defaultMathEnabled; |
|
this.connectionArrowsEnabled = true; |
|
this.hiddenTags = []; |
|
this.extFonts = []; |
|
} |
|
|
|
|
|
this.pageBreaksVisible = this.pageVisible; |
|
this.preferPageSize = this.pageVisible; |
|
this.fireEvent(new mxEventObject('viewStateChanged', 'state', state)); |
|
}; |
|
|
|
Graph.prototype.addExtFont = function(fontName, fontUrl, dontRemember) |
|
{ |
|
|
|
if (fontName && fontUrl) |
|
{ |
|
if (urlParams['ext-fonts'] != '1') |
|
{ |
|
|
|
Graph.recentCustomFonts[fontName.toLowerCase()] = {name: fontName, url: fontUrl}; |
|
} |
|
|
|
var fontId = 'extFont_' + fontName; |
|
|
|
if (document.getElementById(fontId) == null) |
|
{ |
|
if (fontUrl.indexOf(Editor.GOOGLE_FONTS) == 0) |
|
{ |
|
mxClient.link('stylesheet', fontUrl, null, fontId); |
|
} |
|
else |
|
{ |
|
var head = document.getElementsByTagName('head')[0]; |
|
|
|
|
|
var style = document.createElement('style'); |
|
|
|
style.appendChild(document.createTextNode('@font-face {\n' + |
|
'\tfont-family: "'+ fontName +'";\n' + |
|
'\tsrc: url("'+ fontUrl +'");\n}')); |
|
|
|
style.setAttribute('id', fontId); |
|
var head = document.getElementsByTagName('head')[0]; |
|
head.appendChild(style); |
|
} |
|
} |
|
|
|
if (!dontRemember) |
|
{ |
|
if (this.extFonts == null) |
|
{ |
|
this.extFonts = []; |
|
} |
|
|
|
var extFonts = this.extFonts, notFound = true; |
|
|
|
for (var i = 0; i < extFonts.length; i++) |
|
{ |
|
if (extFonts[i].name == fontName) |
|
{ |
|
notFound = false; |
|
break; |
|
} |
|
} |
|
|
|
if (notFound) |
|
{ |
|
this.extFonts.push({name: fontName, url: fontUrl}); |
|
} |
|
} |
|
} |
|
}; |
|
|
|
|
|
|
|
|
|
EditorUi.prototype.updatePageRoot = function(page, checked) |
|
{ |
|
if (page.root == null) |
|
{ |
|
var node = this.editor.extractGraphModel(page.node, null, checked); |
|
var cause = Editor.extractParserError(node); |
|
|
|
if (cause) |
|
{ |
|
throw new Error(cause); |
|
} |
|
else if (node != null) |
|
{ |
|
page.graphModelNode = node; |
|
|
|
|
|
page.viewState = this.editor.graph.createViewState(node); |
|
var codec = new mxCodec(node.ownerDocument); |
|
page.root = codec.decode(node).root; |
|
} |
|
else |
|
{ |
|
|
|
page.root = this.editor.graph.model.createRoot(); |
|
} |
|
} |
|
else if (page.viewState == null) |
|
{ |
|
if (page.graphModelNode == null) |
|
{ |
|
var node = this.editor.extractGraphModel(page.node); |
|
|
|
var cause = Editor.extractParserError(node); |
|
|
|
if (cause) |
|
{ |
|
throw new Error(cause); |
|
} |
|
else if (node != null) |
|
{ |
|
page.graphModelNode = node; |
|
} |
|
} |
|
|
|
if (page.graphModelNode != null) |
|
{ |
|
page.viewState = this.editor.graph.createViewState(page.graphModelNode); |
|
} |
|
} |
|
|
|
return page; |
|
}; |
|
|
|
|
|
|
|
|
|
EditorUi.prototype.selectPage = function(page, quiet, viewState) |
|
{ |
|
try |
|
{ |
|
if (page != this.currentPage) |
|
{ |
|
if (this.editor.graph.isEditing()) |
|
{ |
|
this.editor.graph.stopEditing(false); |
|
} |
|
|
|
quiet = (quiet != null) ? quiet : false; |
|
this.editor.graph.isMouseDown = false; |
|
this.editor.graph.reset(); |
|
|
|
var edit = this.editor.graph.model.createUndoableEdit(); |
|
|
|
|
|
edit.ignoreEdit = true; |
|
|
|
var change = new SelectPage(this, page, viewState); |
|
change.execute(); |
|
edit.add(change); |
|
edit.notify(); |
|
|
|
this.editor.graph.tooltipHandler.hide(); |
|
|
|
if (!quiet) |
|
{ |
|
this.editor.graph.model.fireEvent(new mxEventObject(mxEvent.UNDO, 'edit', edit)); |
|
} |
|
} |
|
} |
|
catch (e) |
|
{ |
|
this.handleError(e); |
|
} |
|
}; |
|
|
|
|
|
|
|
|
|
EditorUi.prototype.selectNextPage = function(forward) |
|
{ |
|
var next = this.currentPage; |
|
|
|
if (next != null && this.pages != null) |
|
{ |
|
var tmp = mxUtils.indexOf(this.pages, next); |
|
|
|
if (forward) |
|
{ |
|
this.selectPage(this.pages[mxUtils.mod(tmp + 1, this.pages.length)]); |
|
} |
|
else if (!forward) |
|
{ |
|
this.selectPage(this.pages[mxUtils.mod(tmp - 1, this.pages.length)]); |
|
} |
|
} |
|
}; |
|
|
|
|
|
|
|
|
|
EditorUi.prototype.insertPage = function(page, index) |
|
{ |
|
if (this.editor.graph.isEnabled()) |
|
{ |
|
if (this.editor.graph.isEditing()) |
|
{ |
|
this.editor.graph.stopEditing(false); |
|
} |
|
|
|
page = (page != null) ? page : this.createPage(null, this.createPageId()); |
|
index = (index != null) ? index : this.pages.length; |
|
|
|
|
|
var change = new ChangePage(this, page, page, index); |
|
this.editor.graph.model.execute(change); |
|
} |
|
|
|
return page; |
|
}; |
|
|
|
|
|
|
|
|
|
EditorUi.prototype.createPageId = function() |
|
{ |
|
var id = null; |
|
|
|
do |
|
{ |
|
id = Editor.guid(); |
|
} while (this.getPageById(id) != null) |
|
|
|
return id; |
|
}; |
|
|
|
|
|
|
|
|
|
EditorUi.prototype.createPage = function(name, id) |
|
{ |
|
var page = new DiagramPage(this.fileNode.ownerDocument.createElement('diagram'), id); |
|
page.setName((name != null) ? name : this.createPageName()); |
|
this.initDiagramNode(page); |
|
|
|
return page; |
|
}; |
|
|
|
|
|
|
|
|
|
EditorUi.prototype.createPageName = function() |
|
{ |
|
|
|
var existing = {}; |
|
|
|
for (var i = 0; i < this.pages.length; i++) |
|
{ |
|
var tmp = this.pages[i].getName(); |
|
|
|
if (tmp != null && tmp.length > 0) |
|
{ |
|
existing[tmp] = tmp; |
|
} |
|
} |
|
|
|
|
|
var nr = this.pages.length; |
|
var name = null; |
|
|
|
do |
|
{ |
|
name = mxResources.get('pageWithNumber', [++nr]); |
|
} |
|
while (existing[name] != null); |
|
|
|
return name; |
|
}; |
|
|
|
|
|
|
|
|
|
EditorUi.prototype.removePage = function(page) |
|
{ |
|
try |
|
{ |
|
var graph = this.editor.graph; |
|
var tmp = mxUtils.indexOf(this.pages, page); |
|
|
|
if (graph.isEnabled() && tmp >= 0) |
|
{ |
|
if (this.editor.graph.isEditing()) |
|
{ |
|
this.editor.graph.stopEditing(false); |
|
} |
|
|
|
graph.model.beginUpdate(); |
|
try |
|
{ |
|
var next = this.currentPage; |
|
|
|
if (next == page && this.pages.length > 1) |
|
{ |
|
if (tmp == this.pages.length - 1) |
|
{ |
|
tmp--; |
|
} |
|
else |
|
{ |
|
tmp++; |
|
} |
|
|
|
next = this.pages[tmp]; |
|
} |
|
else if (this.pages.length <= 1) |
|
{ |
|
|
|
|
|
next = this.insertPage(); |
|
graph.model.execute(new RenamePage(this, next, |
|
mxResources.get('pageWithNumber', [1]))); |
|
} |
|
|
|
|
|
graph.model.execute(new ChangePage(this, page, next)); |
|
} |
|
finally |
|
{ |
|
graph.model.endUpdate(); |
|
} |
|
} |
|
} |
|
catch (e) |
|
{ |
|
this.handleError(e); |
|
} |
|
|
|
return page; |
|
}; |
|
|
|
|
|
|
|
|
|
EditorUi.prototype.duplicatePage = function(page, name) |
|
{ |
|
var newPage = null; |
|
|
|
try |
|
{ |
|
var graph = this.editor.graph; |
|
|
|
if (graph.isEnabled()) |
|
{ |
|
if (graph.isEditing()) |
|
{ |
|
graph.stopEditing(); |
|
} |
|
|
|
|
|
var node = page.node.cloneNode(false); |
|
node.removeAttribute('id'); |
|
|
|
var cloneMap = new Object(); |
|
var lookup = graph.createCellLookup([graph.model.root]); |
|
|
|
var newPage = new DiagramPage(node); |
|
newPage.root = graph.cloneCell(graph.model.root, |
|
null, cloneMap); |
|
|
|
var model = new mxGraphModel(); |
|
model.prefix = Editor.guid() + '-'; |
|
model.setRoot(newPage.root); |
|
|
|
|
|
graph.updateCustomLinks(graph.createCellMapping( |
|
cloneMap, lookup), [newPage.root]); |
|
|
|
|
|
newPage.viewState = (page == this.currentPage) ? |
|
graph.getViewState() : page.viewState; |
|
this.initDiagramNode(newPage); |
|
|
|
|
|
newPage.viewState.scale = 1; |
|
newPage.viewState.scrollLeft = null; |
|
newPage.viewState.scrollTop = null; |
|
newPage.viewState.currentRoot = null; |
|
newPage.viewState.defaultParent = null; |
|
newPage.setName(name); |
|
|
|
|
|
newPage = this.insertPage(newPage, |
|
mxUtils.indexOf(this.pages, |
|
page) + 1); |
|
} |
|
} |
|
catch (e) |
|
{ |
|
this.handleError(e); |
|
} |
|
|
|
return newPage; |
|
}; |
|
|
|
|
|
|
|
|
|
EditorUi.prototype.initDiagramNode = function(page) |
|
{ |
|
var enc = new mxCodec(mxUtils.createXmlDocument()); |
|
var temp = enc.encode(new mxGraphModel(page.root)); |
|
this.editor.graph.saveViewState(page.viewState, temp); |
|
mxUtils.setTextContent(page.node, Graph.compressNode(temp)); |
|
}; |
|
|
|
|
|
|
|
|
|
EditorUi.prototype.clonePages = function(pages) |
|
{ |
|
var result = []; |
|
|
|
for (var i = 0; i < pages.length; i++) |
|
{ |
|
result.push(this.clonePage(pages[i])); |
|
} |
|
|
|
return result; |
|
}; |
|
|
|
|
|
|
|
|
|
EditorUi.prototype.clonePage = function(page) |
|
{ |
|
this.updatePageRoot(page); |
|
|
|
var result = new DiagramPage(page.node.cloneNode(true)); |
|
var viewState = (page == this.currentPage) ? |
|
this.editor.graph.getViewState() : |
|
page.viewState; |
|
result.viewState = mxUtils.clone(viewState, |
|
EditorUi.transientViewStateProperties) |
|
result.root = this.editor.graph.model.cloneCell( |
|
page.root, null, true); |
|
|
|
return result; |
|
}; |
|
|
|
|
|
|
|
|
|
EditorUi.prototype.renamePage = function(page) |
|
{ |
|
var graph = this.editor.graph; |
|
|
|
if (graph.isEnabled()) |
|
{ |
|
var dlg = new FilenameDialog(this, page.getName(), mxResources.get('rename'), mxUtils.bind(this, function(name) |
|
{ |
|
if (name != null && name.length > 0) |
|
{ |
|
this.editor.graph.model.execute(new RenamePage(this, page, name)); |
|
} |
|
}), mxResources.get('rename')); |
|
this.showDialog(dlg.container, 300, 80, true, true); |
|
dlg.init(); |
|
} |
|
|
|
return page; |
|
} |
|
|
|
|
|
|
|
|
|
EditorUi.prototype.movePage = function(oldIndex, newIndex) |
|
{ |
|
this.editor.graph.model.execute(new MovePage(this, oldIndex, newIndex)); |
|
} |
|
|
|
|
|
|
|
|
|
EditorUi.prototype.createTabContainer = function() |
|
{ |
|
var div = document.createElement('div'); |
|
div.className = 'geTabContainer'; |
|
div.style.position = 'absolute'; |
|
div.style.whiteSpace = 'nowrap'; |
|
div.style.overflow = 'hidden'; |
|
div.style.height = '0px'; |
|
|
|
return div; |
|
}; |
|
|
|
|
|
|
|
|
|
EditorUi.prototype.updateTabContainer = function() |
|
{ |
|
if (this.tabContainer != null && this.pages != null) |
|
{ |
|
var graph = this.editor.graph; |
|
var wrapper = document.createElement('div'); |
|
wrapper.style.position = 'relative'; |
|
wrapper.style.display = 'inline-block'; |
|
wrapper.style.verticalAlign = 'top'; |
|
wrapper.style.height = this.tabContainer.style.height; |
|
wrapper.style.whiteSpace = 'nowrap'; |
|
wrapper.style.overflow = 'hidden'; |
|
wrapper.style.fontSize = '13px'; |
|
|
|
|
|
wrapper.style.marginLeft = '30px'; |
|
|
|
|
|
|
|
var btnWidth = (this.editor.isChromelessView()) ? 29 : 59; |
|
var tabWidth = Math.min(140, Math.max(20, (this.tabContainer.clientWidth - btnWidth) / this.pages.length) + 1); |
|
var startIndex = null; |
|
|
|
for (var i = 0; i < this.pages.length; i++) |
|
{ |
|
|
|
(mxUtils.bind(this, function(index, tab) |
|
{ |
|
if (this.pages[index] == this.currentPage) |
|
{ |
|
tab.className = 'geActivePage'; |
|
tab.style.backgroundColor = Editor.isDarkMode() ? Editor.darkColor : '#fff'; |
|
} |
|
else |
|
{ |
|
tab.className = 'geInactivePage'; |
|
} |
|
|
|
tab.setAttribute('draggable', 'true'); |
|
|
|
mxEvent.addListener(tab, 'dragstart', mxUtils.bind(this, function(evt) |
|
{ |
|
if (graph.isEnabled()) |
|
{ |
|
|
|
if (mxClient.IS_FF) |
|
{ |
|
|
|
evt.dataTransfer.setData('Text', '<diagram/>'); |
|
} |
|
|
|
startIndex = index; |
|
} |
|
else |
|
{ |
|
|
|
mxEvent.consume(evt); |
|
} |
|
})); |
|
|
|
mxEvent.addListener(tab, 'dragend', mxUtils.bind(this, function(evt) |
|
{ |
|
startIndex = null; |
|
evt.stopPropagation(); |
|
evt.preventDefault(); |
|
})); |
|
|
|
mxEvent.addListener(tab, 'dragover', mxUtils.bind(this, function(evt) |
|
{ |
|
if (startIndex != null) |
|
{ |
|
evt.dataTransfer.dropEffect = 'move'; |
|
} |
|
|
|
evt.stopPropagation(); |
|
evt.preventDefault(); |
|
})); |
|
|
|
mxEvent.addListener(tab, 'drop', mxUtils.bind(this, function(evt) |
|
{ |
|
if (startIndex != null && index != startIndex) |
|
{ |
|
|
|
this.movePage(startIndex, index); |
|
} |
|
|
|
evt.stopPropagation(); |
|
evt.preventDefault(); |
|
})); |
|
|
|
wrapper.appendChild(tab); |
|
}))(i, this.createTabForPage(this.pages[i], tabWidth, this.pages[i] != this.currentPage, i + 1)); |
|
} |
|
|
|
|
|
|
|
this.tabContainer.innerText = ''; |
|
this.tabContainer.appendChild(wrapper); |
|
|
|
|
|
var menutab = this.createPageMenuTab(); |
|
this.tabContainer.appendChild(menutab); |
|
var insertTab = null; |
|
|
|
|
|
if (this.isPageInsertTabVisible()) |
|
{ |
|
insertTab = this.createPageInsertTab(); |
|
this.tabContainer.appendChild(insertTab); |
|
} |
|
|
|
if (wrapper.clientWidth > this.tabContainer.clientWidth - btnWidth) |
|
{ |
|
if (insertTab != null) |
|
{ |
|
insertTab.style.position = 'absolute'; |
|
insertTab.style.right = '0px'; |
|
wrapper.style.marginRight = '30px'; |
|
} |
|
|
|
var temp = this.createControlTab(4, ' ❮ '); |
|
temp.style.position = 'absolute'; |
|
temp.style.right = (this.editor.chromeless) ? '29px' : '55px'; |
|
temp.style.fontSize = '13pt'; |
|
|
|
this.tabContainer.appendChild(temp); |
|
|
|
var temp2 = this.createControlTab(4, ' ❯'); |
|
temp2.style.position = 'absolute'; |
|
temp2.style.right = (this.editor.chromeless) ? '0px' : '29px'; |
|
temp2.style.fontSize = '13pt'; |
|
|
|
this.tabContainer.appendChild(temp2); |
|
|
|
|
|
var dx = Math.max(0, this.tabContainer.clientWidth - ((this.editor.chromeless) ? 86 : 116)); |
|
wrapper.style.width = dx + 'px'; |
|
|
|
var fade = 50; |
|
|
|
mxEvent.addListener(temp, 'click', mxUtils.bind(this, function(evt) |
|
{ |
|
wrapper.scrollLeft -= Math.max(20, dx - 20); |
|
mxUtils.setOpacity(temp, (wrapper.scrollLeft > 0) ? 100 : fade); |
|
mxUtils.setOpacity(temp2, (wrapper.scrollLeft < wrapper.scrollWidth - wrapper.clientWidth) ? 100 : fade); |
|
mxEvent.consume(evt); |
|
})); |
|
|
|
mxUtils.setOpacity(temp, (wrapper.scrollLeft > 0) ? 100 : fade); |
|
mxUtils.setOpacity(temp2, (wrapper.scrollLeft < wrapper.scrollWidth - wrapper.clientWidth) ? 100 : fade); |
|
|
|
mxEvent.addListener(temp2, 'click', mxUtils.bind(this, function(evt) |
|
{ |
|
wrapper.scrollLeft += Math.max(20, dx - 20); |
|
mxUtils.setOpacity(temp, (wrapper.scrollLeft > 0) ? 100 : fade); |
|
mxUtils.setOpacity(temp2, (wrapper.scrollLeft < wrapper.scrollWidth - wrapper.clientWidth) ? 100 : fade); |
|
mxEvent.consume(evt); |
|
})); |
|
} |
|
} |
|
}; |
|
|
|
|
|
|
|
|
|
EditorUi.prototype.isPageInsertTabVisible = function() |
|
{ |
|
return urlParams['embed'] == 1 || (this.getCurrentFile() != null && |
|
this.getCurrentFile().isEditable()); |
|
}; |
|
|
|
|
|
|
|
|
|
EditorUi.prototype.createTab = function(hoverEnabled) |
|
{ |
|
var tab = document.createElement('div'); |
|
tab.style.display = 'inline-block'; |
|
tab.style.whiteSpace = 'nowrap'; |
|
tab.style.boxSizing = 'border-box'; |
|
tab.style.position = 'relative'; |
|
tab.style.overflow = 'hidden'; |
|
tab.style.textAlign = 'center'; |
|
tab.style.marginLeft = '-1px'; |
|
tab.style.height = this.tabContainer.clientHeight + 'px'; |
|
tab.style.padding = '12px 4px 8px 4px'; |
|
tab.style.border = Editor.isDarkMode() ? '1px solid #505759' : '1px solid #e8eaed'; |
|
tab.style.borderTopStyle = 'none'; |
|
tab.style.borderBottomStyle = 'none'; |
|
tab.style.backgroundColor = this.tabContainer.style.backgroundColor; |
|
tab.style.cursor = 'move'; |
|
tab.style.color = 'gray'; |
|
|
|
if (hoverEnabled) |
|
{ |
|
mxEvent.addListener(tab, 'mouseenter', mxUtils.bind(this, function(evt) |
|
{ |
|
if (!this.editor.graph.isMouseDown) |
|
{ |
|
tab.style.backgroundColor = Editor.isDarkMode() ? 'black' : '#e8eaed'; |
|
mxEvent.consume(evt); |
|
} |
|
})); |
|
|
|
mxEvent.addListener(tab, 'mouseleave', mxUtils.bind(this, function(evt) |
|
{ |
|
tab.style.backgroundColor = this.tabContainer.style.backgroundColor; |
|
mxEvent.consume(evt); |
|
})); |
|
} |
|
|
|
return tab; |
|
}; |
|
|
|
|
|
|
|
|
|
EditorUi.prototype.createControlTab = function(paddingTop, html, hoverEnabled) |
|
{ |
|
var tab = this.createTab((hoverEnabled != null) ? hoverEnabled : true); |
|
tab.style.lineHeight = this.tabContainerHeight + 'px'; |
|
tab.style.paddingTop = paddingTop + 'px'; |
|
tab.style.cursor = 'pointer'; |
|
tab.style.width = '30px'; |
|
tab.innerHTML = html; |
|
|
|
if (tab.firstChild != null && tab.firstChild.style != null) |
|
{ |
|
mxUtils.setOpacity(tab.firstChild, 40); |
|
} |
|
|
|
return tab; |
|
}; |
|
|
|
|
|
|
|
|
|
EditorUi.prototype.createPageMenuTab = function(hoverEnabled, invert) |
|
{ |
|
var tab = this.createControlTab(3, '<div class="geSprite geSprite-dots"></div>', hoverEnabled); |
|
tab.setAttribute('title', mxResources.get('pages')); |
|
tab.style.position = 'absolute'; |
|
tab.style.marginLeft = '0px'; |
|
tab.style.top = '0px'; |
|
tab.style.left = '1px'; |
|
|
|
var div = tab.getElementsByTagName('div')[0]; |
|
div.style.display = 'inline-block'; |
|
div.style.marginTop = '5px'; |
|
div.style.width = '21px'; |
|
div.style.height = '21px'; |
|
|
|
mxEvent.addListener(tab, 'click', mxUtils.bind(this, function(evt) |
|
{ |
|
this.editor.graph.popupMenuHandler.hideMenu(); |
|
|
|
var menu = new mxPopupMenu(mxUtils.bind(this, function(menu, parent) |
|
{ |
|
var addPages = mxUtils.bind(this, function() |
|
{ |
|
for (var i = 0; i < this.pages.length; i++) |
|
{ |
|
(mxUtils.bind(this, function(index) |
|
{ |
|
var item = menu.addItem(this.pages[index].getName(), null, mxUtils.bind(this, function() |
|
{ |
|
this.selectPage(this.pages[index]); |
|
}), parent); |
|
|
|
var id = this.pages[index].getId(); |
|
item.setAttribute('title', this.pages[index].getName() + |
|
' (' + (index + 1) + '/' + this.pages.length + ')' + |
|
((id != null) ? ' [' + id + ']' : '')); |
|
|
|
|
|
if (this.pages[index] == this.currentPage) |
|
{ |
|
menu.addCheckmark(item, Editor.checkmarkImage); |
|
} |
|
}))(i); |
|
} |
|
}); |
|
|
|
var addInsert = mxUtils.bind(this, function() |
|
{ |
|
menu.addItem(mxResources.get('insertPage'), null, mxUtils.bind(this, function() |
|
{ |
|
this.insertPage(); |
|
}), parent); |
|
}); |
|
|
|
if (!invert) |
|
{ |
|
addPages(); |
|
} |
|
|
|
if (this.editor.graph.isEnabled()) |
|
{ |
|
if (!invert) |
|
{ |
|
menu.addSeparator(parent); |
|
addInsert(); |
|
} |
|
|
|
var page = this.currentPage; |
|
|
|
if (page != null) |
|
{ |
|
menu.addSeparator(parent); |
|
var pageName = page.getName(); |
|
|
|
menu.addItem(mxResources.get('removeIt', [pageName]), null, mxUtils.bind(this, function() |
|
{ |
|
this.removePage(page); |
|
}), parent); |
|
|
|
menu.addItem(mxResources.get('renameIt', [pageName]), null, mxUtils.bind(this, function() |
|
{ |
|
this.renamePage(page, page.getName()); |
|
}), parent); |
|
|
|
if (!invert) |
|
{ |
|
menu.addSeparator(parent); |
|
} |
|
|
|
menu.addItem(mxResources.get('duplicateIt', [pageName]), null, mxUtils.bind(this, function() |
|
{ |
|
this.duplicatePage(page, mxResources.get('copyOf', [page.getName()])); |
|
}), parent); |
|
} |
|
} |
|
|
|
if (invert) |
|
{ |
|
menu.addSeparator(parent); |
|
addInsert(); |
|
menu.addSeparator(parent); |
|
addPages(); |
|
} |
|
})); |
|
|
|
menu.div.className += ' geMenubarMenu'; |
|
menu.smartSeparators = true; |
|
menu.showDisabled = true; |
|
menu.autoExpand = true; |
|
|
|
|
|
menu.hideMenu = mxUtils.bind(this, function() |
|
{ |
|
mxPopupMenu.prototype.hideMenu.apply(menu, arguments); |
|
menu.destroy(); |
|
}); |
|
|
|
var x = mxEvent.getClientX(evt); |
|
var y = mxEvent.getClientY(evt); |
|
menu.popup(x, y, null, evt); |
|
|
|
|
|
this.setCurrentMenu(menu); |
|
|
|
mxEvent.consume(evt); |
|
})); |
|
|
|
return tab; |
|
}; |
|
|
|
|
|
|
|
|
|
EditorUi.prototype.createPageInsertTab = function() |
|
{ |
|
var tab = this.createControlTab(4, '<div class="geSprite geSprite-plus"></div>'); |
|
tab.setAttribute('title', mxResources.get('insertPage')); |
|
var graph = this.editor.graph; |
|
|
|
mxEvent.addListener(tab, 'click', mxUtils.bind(this, function(evt) |
|
{ |
|
this.insertPage(); |
|
mxEvent.consume(evt); |
|
})); |
|
|
|
var div = tab.getElementsByTagName('div')[0]; |
|
div.style.display = 'inline-block'; |
|
div.style.width = '21px'; |
|
div.style.height = '21px'; |
|
|
|
return tab; |
|
}; |
|
|
|
|
|
|
|
|
|
EditorUi.prototype.createTabForPage = function(page, tabWidth, hoverEnabled, pageNumber) |
|
{ |
|
var tab = this.createTab(hoverEnabled); |
|
var name = page.getName() || mxResources.get('untitled'); |
|
var id = page.getId(); |
|
tab.setAttribute('title', name + ((id != null) ? ' (' + id + ')' : '') + ' [' + pageNumber + ']'); |
|
mxUtils.write(tab, name); |
|
tab.style.maxWidth = tabWidth + 'px'; |
|
tab.style.width = tabWidth + 'px'; |
|
this.addTabListeners(page, tab); |
|
|
|
if (tabWidth > 42) |
|
{ |
|
tab.style.textOverflow = 'ellipsis'; |
|
} |
|
|
|
return tab; |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EditorUi.prototype.addTabListeners = function(page, tab) |
|
{ |
|
mxEvent.disableContextMenu(tab); |
|
var graph = this.editor.graph; |
|
var model = graph.model; |
|
|
|
mxEvent.addListener(tab, 'dblclick', mxUtils.bind(this, function(evt) |
|
{ |
|
this.renamePage(page) |
|
mxEvent.consume(evt); |
|
})); |
|
|
|
var menuWasVisible = false; |
|
var pageWasActive = false; |
|
|
|
mxEvent.addGestureListeners(tab, mxUtils.bind(this, function(evt) |
|
{ |
|
|
|
menuWasVisible = this.currentMenu != null; |
|
pageWasActive = page == this.currentPage; |
|
|
|
if (!graph.isMouseDown && !pageWasActive) |
|
{ |
|
this.selectPage(page); |
|
} |
|
}), null, mxUtils.bind(this, function(evt) |
|
{ |
|
if (graph.isEnabled() && !graph.isMouseDown && |
|
((mxEvent.isTouchEvent(evt) && pageWasActive) || |
|
mxEvent.isPopupTrigger(evt))) |
|
{ |
|
graph.popupMenuHandler.hideMenu(); |
|
this.hideCurrentMenu(); |
|
|
|
if (!mxEvent.isTouchEvent(evt) || !menuWasVisible) |
|
{ |
|
var menu = new mxPopupMenu(this.createPageMenu(page)); |
|
|
|
menu.div.className += ' geMenubarMenu'; |
|
menu.smartSeparators = true; |
|
menu.showDisabled = true; |
|
menu.autoExpand = true; |
|
|
|
|
|
menu.hideMenu = mxUtils.bind(this, function() |
|
{ |
|
mxPopupMenu.prototype.hideMenu.apply(menu, arguments); |
|
this.resetCurrentMenu(); |
|
menu.destroy(); |
|
}); |
|
|
|
var x = mxEvent.getClientX(evt); |
|
var y = mxEvent.getClientY(evt); |
|
menu.popup(x, y, null, evt); |
|
this.setCurrentMenu(menu, tab); |
|
} |
|
|
|
mxEvent.consume(evt); |
|
} |
|
})); |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
EditorUi.prototype.getLinkForPage = function(page, params, lightbox) |
|
{ |
|
if (!mxClient.IS_CHROMEAPP && !EditorUi.isElectronApp) |
|
{ |
|
var file = this.getCurrentFile(); |
|
|
|
if (file != null && file.constructor != LocalFile && this.getServiceName() == 'draw.io') |
|
{ |
|
var search = this.getSearch(['create', 'title', 'mode', 'url', 'drive', 'splash', |
|
'state', 'clibs', 'ui', 'viewbox', 'hide-pages', 'sketch']); |
|
search += ((search.length == 0) ? '?' : '&') + 'page-id=' + page.getId(); |
|
|
|
if (params != null) |
|
{ |
|
search += '&' + params.join('&'); |
|
} |
|
|
|
return ((lightbox && urlParams['dev'] != '1') ? EditorUi.lightboxHost : |
|
(((mxClient.IS_CHROMEAPP || EditorUi.isElectronApp || |
|
!(/.*\.draw\.io$/.test(window.location.hostname))) ? |
|
EditorUi.drawHost : 'https://' + window.location.host))) + |
|
'/' + search + '#' + file.getHash(); |
|
} |
|
} |
|
|
|
return null; |
|
}; |
|
|
|
|
|
|
|
|
|
EditorUi.prototype.createPageMenu = function(page, label) |
|
{ |
|
return mxUtils.bind(this, function(menu, parent) |
|
{ |
|
var graph = this.editor.graph; |
|
var model = graph.model; |
|
|
|
menu.addItem(mxResources.get('insert'), null, mxUtils.bind(this, function() |
|
{ |
|
this.insertPage(null, mxUtils.indexOf(this.pages, page) + 1); |
|
}), parent); |
|
|
|
menu.addItem(mxResources.get('delete'), null, mxUtils.bind(this, function() |
|
{ |
|
this.removePage(page); |
|
}), parent); |
|
|
|
menu.addItem(mxResources.get('rename'), null, mxUtils.bind(this, function() |
|
{ |
|
this.renamePage(page, label); |
|
}), parent); |
|
|
|
var url = this.getLinkForPage(page); |
|
|
|
if (url != null) |
|
{ |
|
menu.addSeparator(parent); |
|
|
|
menu.addItem(mxResources.get('link'), null, mxUtils.bind(this, function() |
|
{ |
|
this.showPublishLinkDialog(mxResources.get('url'), true, null, null, |
|
mxUtils.bind(this, function(linkTarget, linkColor, allPages, lightbox, editLink, layers) |
|
{ |
|
var params = this.createUrlParameters(linkTarget, linkColor, allPages, lightbox, editLink, layers); |
|
|
|
if (!allPages) |
|
{ |
|
params.push('hide-pages=1'); |
|
} |
|
|
|
if (!graph.isSelectionEmpty()) |
|
{ |
|
var bounds = graph.getBoundingBox(graph.getSelectionCells()); |
|
|
|
var t = graph.view.translate; |
|
var s = graph.view.scale; |
|
bounds.width /= s; |
|
bounds.height /= s; |
|
bounds.x = bounds.x / s - t.x; |
|
bounds.y = bounds.y / s - t.y; |
|
|
|
params.push('viewbox=' + encodeURIComponent(JSON.stringify({x: Math.round(bounds.x), y: Math.round(bounds.y), |
|
width: Math.round(bounds.width), height: Math.round(bounds.height), border: 100}))); |
|
} |
|
|
|
var dlg = new EmbedDialog(this, this.getLinkForPage(page, params, lightbox)); |
|
this.showDialog(dlg.container, 450, 240, true, true); |
|
dlg.init(); |
|
})); |
|
})); |
|
} |
|
|
|
menu.addSeparator(parent); |
|
|
|
menu.addItem(mxResources.get('duplicate'), null, mxUtils.bind(this, function() |
|
{ |
|
this.duplicatePage(page, mxResources.get('copyOf', [page.getName()])); |
|
}), parent); |
|
|
|
if (!mxClient.IS_CHROMEAPP && !EditorUi.isElectronApp && this.getServiceName() == 'draw.io') |
|
{ |
|
menu.addSeparator(parent); |
|
|
|
menu.addItem(mxResources.get('openInNewWindow'), null, mxUtils.bind(this, function() |
|
{ |
|
this.editor.editAsNew(this.getFileData(true, null, null, null, true, true)); |
|
}), parent); |
|
} |
|
}); |
|
}; |
|
|
|
|
|
(function() |
|
{ |
|
var editorUiRefresh = EditorUi.prototype.refresh; |
|
|
|
EditorUi.prototype.refresh = function(sizeDidChange) |
|
{ |
|
editorUiRefresh.apply(this, arguments); |
|
this.updateTabContainer(); |
|
} |
|
})(); |
|
|
|
|
|
(function() |
|
{ |
|
var codec = mxCodecRegistry.getCodec(ChangePageSetup); |
|
codec.exclude.push('page'); |
|
})(); |
|
|
|
|
|
(function() |
|
{ |
|
var codec = new mxObjectCodec(new MovePage(), ['ui']); |
|
|
|
codec.beforeDecode = function(dec, node, obj) |
|
{ |
|
obj.ui = dec.ui; |
|
|
|
return node; |
|
}; |
|
|
|
codec.afterDecode = function(dec, node, obj) |
|
{ |
|
var tmp = obj.oldIndex; |
|
obj.oldIndex = obj.newIndex; |
|
obj.newIndex = tmp; |
|
|
|
return obj; |
|
}; |
|
|
|
mxCodecRegistry.register(codec); |
|
})(); |
|
|
|
|
|
(function() |
|
{ |
|
var codec = new mxObjectCodec(new RenamePage(), ['ui', 'page']); |
|
|
|
codec.beforeDecode = function(dec, node, obj) |
|
{ |
|
obj.ui = dec.ui; |
|
|
|
return node; |
|
}; |
|
|
|
codec.afterDecode = function(dec, node, obj) |
|
{ |
|
var tmp = obj.previous; |
|
obj.previous = obj.name; |
|
obj.name = tmp; |
|
|
|
return obj; |
|
}; |
|
|
|
mxCodecRegistry.register(codec); |
|
})(); |
|
|
|
|
|
(function() |
|
{ |
|
var codec = new mxObjectCodec(new ChangePage(), ['ui', 'relatedPage', |
|
'index', 'neverShown', 'page', 'previousPage']); |
|
|
|
codec.afterEncode = function(enc, obj, node) |
|
{ |
|
node.setAttribute('relatedPage', obj.relatedPage.getId()) |
|
|
|
if (obj.index == null) |
|
{ |
|
node.setAttribute('name', obj.relatedPage.getName()); |
|
|
|
if (obj.relatedPage.viewState != null) |
|
{ |
|
node.setAttribute('viewState', JSON.stringify( |
|
obj.relatedPage.viewState, function(key, value) |
|
{ |
|
return (mxUtils.indexOf(EditorUi.transientViewStateProperties, key) < 0) ? value : undefined; |
|
})); |
|
} |
|
|
|
if (obj.relatedPage.root != null) |
|
{ |
|
enc.encodeCell(obj.relatedPage.root, node); |
|
} |
|
} |
|
|
|
return node; |
|
}; |
|
|
|
codec.beforeDecode = function(dec, node, obj) |
|
{ |
|
obj.ui = dec.ui; |
|
obj.relatedPage = obj.ui.getPageById(node.getAttribute('relatedPage')); |
|
|
|
if (obj.relatedPage == null) |
|
{ |
|
var temp = node.ownerDocument.createElement('diagram'); |
|
temp.setAttribute('id', node.getAttribute('relatedPage')); |
|
temp.setAttribute('name', node.getAttribute('name')); |
|
obj.relatedPage = new DiagramPage(temp); |
|
|
|
var vs = node.getAttribute('viewState'); |
|
|
|
if (vs != null) |
|
{ |
|
obj.relatedPage.viewState = JSON.parse(vs); |
|
node.removeAttribute('viewState'); |
|
} |
|
|
|
|
|
node = node.cloneNode(true); |
|
var tmp = node.firstChild; |
|
|
|
if (tmp != null) |
|
{ |
|
obj.relatedPage.root = dec.decodeCell(tmp, false); |
|
|
|
var tmp2 = tmp.nextSibling; |
|
tmp.parentNode.removeChild(tmp); |
|
tmp = tmp2; |
|
|
|
while (tmp != null) |
|
{ |
|
tmp2 = tmp.nextSibling; |
|
|
|
if (tmp.nodeType == mxConstants.NODETYPE_ELEMENT) |
|
{ |
|
|
|
|
|
|
|
|
|
|
|
var id = tmp.getAttribute('id'); |
|
|
|
if (dec.lookup(id) == null) |
|
{ |
|
dec.decodeCell(tmp); |
|
} |
|
} |
|
|
|
tmp.parentNode.removeChild(tmp); |
|
tmp = tmp2; |
|
} |
|
} |
|
} |
|
|
|
return node; |
|
}; |
|
|
|
codec.afterDecode = function(dec, node, obj) |
|
{ |
|
obj.index = obj.previousIndex; |
|
|
|
return obj; |
|
}; |
|
|
|
mxCodecRegistry.register(codec); |
|
})(); |