fragment: dome doc + save as fragment mode

This commit is contained in:
bordun 2021-04-15 16:24:54 +02:00
parent f35c3cf523
commit 44f43cb144
13 changed files with 85 additions and 5 deletions

View file

@ -7,6 +7,7 @@
- Open: browse session files on the server
- Open recent: open a recent session on the server
- Save / Save as: save session file on the server
- Fragment mode: when enabled, the session will be saved as a fragment file (only the root's first child will be saved)
- Import: import a session file from the client's filesystem
- Export: export a session file to the client's filesystem
- State

View file

@ -28,6 +28,7 @@ Right clicking on a widget displays a menu with the following actions
- `Clone` : create a clone widget targetting the copied widget
- `Add widget`: create a new widget in selected container
- `Add tab`: create a new tab in selected container
- `Export`: export as fragment file
- `Delete`: delete selected tab or widget

View file

@ -12,7 +12,7 @@
- Clear: clear console
- Autoscrell: enable/disable console autoscroll
- Check for update at startup: enable/disable this feature
- Always on top: pin the launcher window above other the windows
The "play/stop" icon can be used to start and stop the server without opening the menu.

View file

@ -0,0 +1,15 @@
# Fragments
Fragments allow breaking sessions into multiple files and reusable components made of multiple widgets.
## Fragment files
When right-clicking on a widget in the editor mode, it is possible to export it as a fragment file.
Fragment files have the same extension as session files (`.json`) and can be opened like regular sessions. When doing so, keep in mind that only the first child of the root widget will be saved. It is possible to save a fragment file as a session file (and vice versa) by toggling the `Fragment mode` in the main menu.
## Fragment widgets
Fragment widgets work like clone widget except their source widget are loaded from fragment files or session files. When the sources files are modified, the fragment widgets are updated automatically.

View file

@ -44,6 +44,7 @@ nav:
- docs/widgets/properties-reference.md
- docs/widgets/advanced-syntaxes.md
- docs/widgets/scripting.md
- docs/widgets/fragments.md
- MIDI:
- MIDI configuration: docs/midi/midi-configuration.md
- MIDI messages: docs/midi/midi-messages.md

View file

@ -15,6 +15,7 @@ module.exports = {
if (session.session) {
cache.set('backup', {
session: session.session.data,
saveMode: session.saveMode,
sessionPath: session.sessionPath,
fragments: session.fragments,
state: state.get(),
@ -43,6 +44,7 @@ module.exports = {
}
session.load(data.session, ()=>{
session.setSaveMode(data.saveMode)
state.set(data.state, false)
editor.clearHistory()

View file

@ -48,6 +48,11 @@ module.exports = {
file_import: 'Import',
file_export: 'Export',
// fragment mode
fragment_mode: 'Fragment mode',
fragment_mode_warning: 'Fragment mode enabled',
fragment_mode_explanation: 'The session will be saved as a fragment: only the first child of root will be saved.',
// fullscreen
fullscreen: 'Fullscreen',
fullscreen_unnavailable: 'Fullscreen not available',

View file

@ -53,6 +53,11 @@ module.exports = {
fs_unnavailable: 'Plein écran indisponible',
fs_addtohome: 'Vous devez ajouter cette page à votre écran d\'accueil pour pouvoir l\'ouvrir en plein écran.',
// fragment mode
fragment_mode: 'Mode fragment',
fragment_mode_warning: 'Mode fragment activé',
fragment_mode_explanation: 'La session sera enregistrée sous forme de fragment : seul le premier descendant de l\'élément root sera sauvegardé.',
// inspector
inspector_color_confirm: 'Confirmer',
inspector_color_apply: 'Appliquer',

View file

@ -20,6 +20,7 @@ var SessionManager = class SessionManager extends EventEmitter {
super()
this.session = null
this.saveMode = 'session'
this.fragments = {}
this.lock = false
this.lastDir = null
@ -55,6 +56,7 @@ var SessionManager = class SessionManager extends EventEmitter {
})
editor.clearHistory()
DOM.get(document, '#osc-greeting-header')[0].classList.add('hidden')
this.setSaveMode(this.session.isFragment ? 'fragment' : 'session')
} catch (err) {
uiLoading(false)
@ -103,10 +105,28 @@ var SessionManager = class SessionManager extends EventEmitter {
if (!this.sessionPath) return this.saveAs()
ipc.send('sessionSave', {
session: this.session.toJSON(),
path: this.sessionPath
})
if (this.saveMode === 'session') {
ipc.send('sessionSave', {
session: this.session.toJSON(),
path: this.sessionPath
})
} else {
var data = this.session.data.content.widgets.length ?
this.session.data.content.widgets[0] :
this.session.data.content.tabs[0]
ipc.send('sessionSave', {
session: new Session({
content: data,
version: PACKAGE.version
}, 'fragment'),
path: this.sessionPath
})
}
}
@ -236,6 +256,13 @@ var SessionManager = class SessionManager extends EventEmitter {
}
setSaveMode(mode) {
this.saveMode = mode
document.body.classList.toggle('fragment-mode', mode === 'fragment')
}
}
var sessionManager = new SessionManager()

View file

@ -49,6 +49,7 @@ module.exports = class Session {
} else {
data.content = {type: 'root', widgets: [data.content]}
}
this.isFragment = true
}
if (type === 'fragment' && data.type === 'session') {

View file

@ -50,6 +50,11 @@ var menuEntries = [
shortcut: 'mod + shift + s',
class: ()=>{return READ_ONLY || sessionManager.session === null ? 'disabled' :''}
},
{
label: locales('fragment_mode'),
class: ()=>{return 'toggle ' + (sessionManager.saveMode === 'fragment' ? 'on' : 'off')},
action: ()=>{sessionManager.setSaveMode(sessionManager.saveMode === 'session' ? 'fragment' : 'session')}
},
{
separator: true
},

View file

@ -4,6 +4,8 @@ var UiWidget = require('./ui-widget'),
Sortable = require('sortablejs'),
morph = require('nanomorph'),
locales = require('../locales'),
raw = require('nanohtml/raw'),
{icon} = require('./utils'),
Root, Panel, Matrix, Keyboard, widgetManager,
init = false
@ -20,6 +22,7 @@ class UiTree extends UiWidget {
super(options)
this.mounted = false
this.container.appendChild(html`<div class="fragment-mode-warning" title="${locales('fragment_mode_explanation')}">${raw(icon('exclamation-triangle'))} ${locales('fragment_mode_warning')}</div>`)
this.filter = this.container.appendChild(html`<input class="filter" type="text" placeholder="${locales('tree_filter')}..."/>`)
this.list = this.container.appendChild(html`<ol style="--depth: 1"></ol`)
this.dragDummy = html`<span></span>`

View file

@ -129,4 +129,18 @@
display:none;
}
.fragment-mode-warning {
margin-left: #{-$padding * 2};
width: calc(100% + #{$padding * 2});
color: var(--color-warning);
padding: 8rem $padding;
padding-left: #{$padding * 2};
line-height: $field-height - 4rem;
display: none;
}
}
.fragment-mode .fragment-mode-warning {
display: block!important;
}