-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add tested version of layer_view extension * Fix linting errors * Modify button style to SVG-Edit colour palette
- Loading branch information
1 parent
59690cd
commit 49dd041
Showing
5 changed files
with
117 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/** | ||
* @file ext-layer_view.js | ||
* | ||
* @license MIT | ||
* | ||
* | ||
*/ | ||
|
||
const name = 'layer_view' | ||
|
||
const loadExtensionTranslation = async function (svgEditor) { | ||
let translationModule | ||
const lang = svgEditor.configObj.pref('lang') | ||
try { | ||
translationModule = await import(`./locale/${lang}.js`) | ||
} catch (_error) { | ||
console.warn(`Missing translation (${lang}) for ${name} - using 'en'`) | ||
translationModule = await import('./locale/en.js') | ||
} | ||
svgEditor.i18next.addResourceBundle(lang, name, translationModule.default) | ||
} | ||
|
||
export default { | ||
name, | ||
async init (_S) { | ||
const svgEditor = this | ||
const { svgCanvas } = svgEditor | ||
const { $id, $click } = svgCanvas | ||
await loadExtensionTranslation(svgEditor) | ||
|
||
const clickLayerView = (e) => { | ||
$id('tool_layerView').pressed = !$id('tool_layerView').pressed | ||
updateLayerView(e) | ||
} | ||
|
||
const updateLayerView = (e) => { | ||
const drawing = svgCanvas.getCurrentDrawing() | ||
const curLayer = drawing.getCurrentLayerName() | ||
let layer = drawing.getNumLayers() | ||
while (layer--) { | ||
const name = drawing.getLayerName(layer) | ||
if (name !== curLayer && $id('tool_layerView').pressed) { | ||
drawing.setLayerVisibility(name, false) | ||
} else { | ||
drawing.setLayerVisibility(name, true) | ||
} | ||
} | ||
$id('layerlist').querySelectorAll('tr.layer').forEach( | ||
function (el) { | ||
const layervis = el.querySelector('td.layervis') | ||
const vis = el.classList.contains('layersel') || !$id('tool_layerView').pressed ? 'layervis' : 'layerinvis layervis' | ||
layervis.setAttribute('class', vis) | ||
} | ||
) | ||
} | ||
|
||
return { | ||
name: svgEditor.i18next.t(`${name}:name`), | ||
// The callback should be used to load the DOM with the appropriate UI items | ||
layersChanged () { | ||
if ($id('tool_layerView').pressed) { | ||
updateLayerView() | ||
} if (svgEditor.configObj.curConfig.layerView) { | ||
svgEditor.configObj.curConfig.layerView = false | ||
$id('tool_layerView').pressed = true | ||
updateLayerView() | ||
} | ||
}, | ||
layerVisChanged () { | ||
if ($id('tool_layerView').pressed) { | ||
$id('tool_layerView').pressed = !$id('tool_layerView').pressed | ||
} | ||
}, | ||
callback () { | ||
const buttonTemplate = document.createElement('template') | ||
const title = `${name}:buttons.0.title` | ||
const key = `${name}:buttons.0.key` | ||
buttonTemplate.innerHTML = ` | ||
<se-button id="tool_layerView" title="${title}" shortcut="${key}" src="layer_view.svg"></se-button>` | ||
$id('editor_panel').append(buttonTemplate.content.cloneNode(true)) | ||
$click($id('tool_layerView'), clickLayerView.bind(this)) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export default { | ||
name: 'layerview', | ||
buttons: [ | ||
{ | ||
title: 'Enable/Disable Layer View', | ||
key: 'Ctrl+Shift+L' | ||
} | ||
] | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters