rememeber datagrid manager width

This commit is contained in:
Jan Prochazka
2021-12-30 17:43:26 +01:00
parent 0b81ea8f4e
commit d7ad9be560
2 changed files with 23 additions and 5 deletions

View File

@@ -67,7 +67,7 @@
import registerCommand from '../commands/registerCommand';
import { registerMenu } from '../utility/contextMenu';
import { getBoolSettingsValue } from '../settings/settingsTools';
import { getLocalStorage } from '../utility/storageCache';
import { getLocalStorage, getLocalStorage, getLocalStorage, setLocalStorage } from '../utility/storageCache';
export let config;
export let setConfig;
@@ -144,9 +144,23 @@
{ command: 'dataGrid.switchToJson', tag: 'switch', hideDisabled: true },
{ command: 'dataGrid.toggleLeftPanel', tag: 'switch' }
);
$: if (managerSize) setLocalStorage('dataGridManagerWidth', managerSize);
function getInitialManagerSize() {
const width = getLocalStorage('dataGridManagerWidth');
if (_.isNumber(width) && width > 30 && width < 500) {
return `${width}px`;
}
return '300px';
}
</script>
<HorizontalSplitter initialValue="300px" bind:size={managerSize} hideFirst={$collapsedLeftColumnStore}>
<HorizontalSplitter
initialValue={getInitialManagerSize()}
bind:size={managerSize}
hideFirst={$collapsedLeftColumnStore}
>
<div class="left" slot="1">
<WidgetColumnBar>
<WidgetColumnBarItem

View File

@@ -4,9 +4,13 @@ export function getLocalStorage(key, defaultValue = undefined) {
if (key in cache) return cache[key];
const item = localStorage.getItem(key);
if (item) {
const res = JSON.parse(item);
cache[key] = res;
return res;
try {
const res = JSON.parse(item);
cache[key] = res;
return res;
} catch (e) {
return defaultValue;
}
}
return defaultValue;
}