saving size and visibility state of the panes

This commit is contained in:
zadam 2019-12-23 20:34:29 +01:00
parent e0368e395c
commit c89514f9bb
6 changed files with 65 additions and 23 deletions

View File

@ -175,8 +175,6 @@ noteTooltipService.setupGlobalTooltip();
noteAutocompleteService.init(); noteAutocompleteService.init();
splitService.setupSplitWithSidebar();
if (utils.isElectron()) { if (utils.isElectron()) {
import("./services/spell_check.js").then(spellCheckService => spellCheckService.initSpellCheck()); import("./services/spell_check.js").then(spellCheckService => spellCheckService.initSpellCheck());
} }

View File

@ -2,30 +2,45 @@ import bundleService from "./bundle.js";
import ws from "./ws.js"; import ws from "./ws.js";
import optionsService from "./options.js"; import optionsService from "./options.js";
import splitService from "./split.js"; import splitService from "./split.js";
import optionService from "./options.js";
import server from "./server.js";
import noteDetailService from "./note_detail.js";
const $sidebar = $("#right-pane"); const $sidebar = $("#right-pane");
const $sidebarContainer = $('#sidebar-container'); const $sidebarContainer = $('#sidebar-container');
const $showSideBarButton = $("#show-sidebar-button"); const $showSidebarButton = $("#show-sidebar-button");
const $hideSidebarButton = $("#hide-sidebar-button"); const $hideSidebarButton = $("#hide-sidebar-button");
$showSideBarButton.hide(); optionService.waitForOptions().then(options => toggleSidebar(options.is('rightPaneVisible')));
function toggleSidebar(show) {
$sidebar.toggle(show);
$showSidebarButton.toggle(!show);
$hideSidebarButton.toggle(show);
if (show) {
splitService.setupSplitWithSidebar();
}
else {
splitService.setupSplitWithoutSidebar();
}
}
$hideSidebarButton.on('click', () => { $hideSidebarButton.on('click', () => {
$sidebar.hide(); toggleSidebar(false);
$showSideBarButton.show();
$hideSidebarButton.hide();
splitService.setupSplitWithoutSidebar(); server.put('options/rightPaneVisible/false');
}); });
// FIXME shoud run note loaded! $showSidebarButton.on('click', async () => {
$showSideBarButton.on('click', () => { toggleSidebar(true);
$sidebar.show();
$showSideBarButton.hide();
$hideSidebarButton.show();
splitService.setupSplitWithSidebar(); await server.put('options/rightPaneVisible/true');
const {sidebar} = noteDetailService.getActiveTabContext();
await sidebar.noteLoaded();
sidebar.show();
}); });
class Sidebar { class Sidebar {

View File

@ -1,24 +1,47 @@
import server from "./server.js";
import optionService from "./options.js";
let instance; let instance;
function setupSplitWithSidebar() { async function getPaneWidths() {
const options = await optionService.waitForOptions();
return {
leftPaneWidth: options.getInt('leftPaneWidth'),
rightPaneWidth: options.getInt('rightPaneWidth')
};
}
async function setupSplitWithSidebar() {
if (instance) { if (instance) {
instance.destroy(); instance.destroy();
} }
const {leftPaneWidth, rightPaneWidth} = await getPaneWidths();
instance = Split(['#left-pane', '#center-pane', '#right-pane'], { instance = Split(['#left-pane', '#center-pane', '#right-pane'], {
sizes: [25, 50, 25], sizes: [leftPaneWidth, 100 - leftPaneWidth - rightPaneWidth, rightPaneWidth],
gutterSize: 5 gutterSize: 5,
onDragEnd: sizes => {
server.put('options/leftPaneWidth/' + Math.round(sizes[0]));
server.put('options/rightPaneWidth/' + Math.round(sizes[2]));
}
}); });
} }
function setupSplitWithoutSidebar() { async function setupSplitWithoutSidebar() {
if (instance) { if (instance) {
instance.destroy(); instance.destroy();
} }
const {leftPaneWidth} = await getPaneWidths();
instance = Split(['#left-pane', '#center-pane'], { instance = Split(['#left-pane', '#center-pane'], {
sizes: [25, 75], sizes: [leftPaneWidth, 100 - leftPaneWidth],
gutterSize: 5 gutterSize: 5,
onDragEnd: sizes => {
server.put('options/leftPaneWidth/' + Math.round(sizes[0]));
}
}); });
} }

View File

@ -30,7 +30,10 @@ const ALLOWED_OPTIONS = new Set([
'spellCheckEnabled', 'spellCheckEnabled',
'spellCheckLanguageCode', 'spellCheckLanguageCode',
'imageMaxWidthHeight', 'imageMaxWidthHeight',
'imageJpegQuality' 'imageJpegQuality',
'leftPaneWidth',
'rightPaneWidth',
'rightPaneVisible'
]); ]);
async function getOptions() { async function getOptions() {

View File

@ -76,7 +76,10 @@ const defaultOptions = [
{ name: 'imageMaxWidthHeight', value: '1200', isSynced: true }, { name: 'imageMaxWidthHeight', value: '1200', isSynced: true },
{ name: 'imageJpegQuality', value: '75', isSynced: true }, { name: 'imageJpegQuality', value: '75', isSynced: true },
{ name: 'autoFixConsistencyIssues', value: 'true', isSynced: false }, { name: 'autoFixConsistencyIssues', value: 'true', isSynced: false },
{ name: 'codeNotesMimeTypes', value: '["text/x-csrc","text/x-c++src","text/x-csharp","text/css","text/x-go","text/x-groovy","text/x-haskell","text/html","message/http","text/x-java","application/javascript;env=frontend","application/javascript;env=backend","application/json","text/x-kotlin","text/x-markdown","text/x-perl","text/x-php","text/x-python","text/x-ruby",null,"text/x-sql","text/x-swift","text/xml","text/x-yaml"]', isSynced: true } { name: 'codeNotesMimeTypes', value: '["text/x-csrc","text/x-c++src","text/x-csharp","text/css","text/x-go","text/x-groovy","text/x-haskell","text/html","message/http","text/x-java","application/javascript;env=frontend","application/javascript;env=backend","application/json","text/x-kotlin","text/x-markdown","text/x-perl","text/x-php","text/x-python","text/x-ruby",null,"text/x-sql","text/x-swift","text/xml","text/x-yaml"]', isSynced: true },
{ name: 'leftPaneWidth', value: '25', isSynced: false },
{ name: 'rightPaneWidth', value: '25', isSynced: false },
{ name: 'rightPaneVisible', value: 'true', isSynced: false }
]; ];
async function initStartupOptions() { async function initStartupOptions() {

View File

@ -1,7 +1,7 @@
<div id="center-pane"> <div id="center-pane">
<div id="note-tab-container"> <div id="note-tab-container">
<div class="note-tab-content note-tab-content-template"> <div class="note-tab-content note-tab-content-template">
<div class="note-detail-content" style="width: <%= contentWidthPercent %>%"> <div class="note-detail-content">
<% include title.ejs %> <% include title.ejs %>
<div class="note-detail-script-area"></div> <div class="note-detail-script-area"></div>