Skip to content

Build your personal knowledge base with Trilium Notes

resizing sidebar in options

zadam9888850c22af
diff --git a/db/migrations/0138__sidebar_sizing.sql b/db/migrations/0138__sidebar_sizing.sql
new file mode 100644
index 0000000000..2ecb582d4e
--- /dev/null
+++ b/db/migrations/0138__sidebar_sizing.sql
@@ -0,0 +1,5 @@
+INSERT INTO options (name, value, utcDateCreated, utcDateModified, isSynced)
+VALUES ('sidebarMinWidth', '350', '2018-07-29T18:31:00.874Z', '2018-07-29T18:31:00.874Z', 0);
+
+INSERT INTO options (name, value, utcDateCreated, utcDateModified, isSynced)
+VALUES ('sidebarWidthPercent', '25', '2018-07-29T18:31:00.874Z', '2018-07-29T18:31:00.874Z', 0);
\ No newline at end of file
diff --git a/package.json b/package.json
index 3763b20e30..5bb2513da2 100644
--- a/package.json
+++ b/package.json
@@ -77,7 +77,6 @@
"xml2js": "0.4.19"
},
"devDependencies": {
- "devtron": "1.4.0",
"electron": "6.0.2",
"electron-builder": "21.2.0",
"electron-compile": "6.4.4",
diff --git a/src/public/javascripts/dialogs/options.js b/src/public/javascripts/dialogs/options.js
index 17c47bca0e..d50c0746e9 100644
--- a/src/public/javascripts/dialogs/options.js
+++ b/src/public/javascripts/dialogs/options.js
@@ -349,4 +349,43 @@ addTabHandler((async function () {
});
return {};
+})());
+
+addTabHandler((function() {
+ const $sidebarMinWidth = $("#sidebar-min-width");
+ const $sidebarWidthPercent = $("#sidebar-width-percent");
+
+ async function optionsLoaded(options) {
+ $sidebarMinWidth.val(options.sidebarMinWidth);
+ $sidebarWidthPercent.val(options.sidebarWidthPercent);
+ }
+
+ function resizeSidebar() {
+ const sidebarWidthPercent = parseInt($sidebarWidthPercent.val());
+ const sidebarMinWidth = $sidebarMinWidth.val();
+
+ // need to find them dynamically since they change
+ const $sidebar = $(".note-detail-sidebar");
+
+ console.log("Resizing to ", sidebarWidthPercent, sidebarMinWidth);
+
+ $sidebar.css("width", sidebarWidthPercent + '%');
+ $sidebar.css("min-width", sidebarMinWidth + 'px');
+ }
+
+ $sidebarMinWidth.change(async function() {
+ await server.put('options/sidebarMinWidth/' + $(this).val());
+
+ resizeSidebar();
+ });
+
+ $sidebarWidthPercent.change(async function() {
+ await server.put('options/sidebarWidthPercent/' + $(this).val());
+
+ resizeSidebar();
+ });
+
+ return {
+ optionsLoaded
+ };
})());
\ No newline at end of file
diff --git a/src/public/stylesheets/style.css b/src/public/stylesheets/style.css
index 3a09634d56..2e4851f05c 100644
--- a/src/public/stylesheets/style.css
+++ b/src/public/stylesheets/style.css
@@ -102,7 +102,7 @@ ul.fancytree-container {
.note-detail-sidebar {
min-width: 350px;
- max-width: 350px;
+ width: 50%;
overflow: auto;
padding-top: 12px;
padding-left: 7px;
diff --git a/src/routes/api/options.js b/src/routes/api/options.js
index 60783a509d..32dc59cab4 100644
--- a/src/routes/api/options.js
+++ b/src/routes/api/options.js
@@ -15,6 +15,8 @@ const ALLOWED_OPTIONS = [
'syncProxy',
'leftPaneMinWidth',
'leftPaneWidthPercent',
+ 'sidebarMinWidth',
+ 'sidebarWidthPercent',
'hoistedNoteId',
'mainFontSize',
'treeFontSize',
diff --git a/src/routes/index.js b/src/routes/index.js
index d41a3dc748..d924189149 100644
--- a/src/routes/index.js
+++ b/src/routes/index.js
@@ -21,6 +21,8 @@ async function index(req, res) {
leftPaneMinWidth: parseInt(options.leftPaneMinWidth),
leftPaneWidthPercent: parseInt(options.leftPaneWidthPercent),
rightPaneWidthPercent: 100 - parseInt(options.leftPaneWidthPercent),
+ sidebarMinWidth: parseInt(options.sidebarMinWidth),
+ sidebarWidthPercent: parseInt(options.sidebarWidthPercent),
mainFontSize: parseInt(options.mainFontSize),
treeFontSize: parseInt(options.treeFontSize),
detailFontSize: parseInt(options.detailFontSize),
diff --git a/src/services/app_info.js b/src/services/app_info.js
index 2fe2f4f19d..7c6bd436c6 100644
--- a/src/services/app_info.js
+++ b/src/services/app_info.js
@@ -4,7 +4,7 @@ const build = require('./build');
const packageJson = require('../../package');
const {TRILIUM_DATA_DIR} = require('./data_dir');
-const APP_DB_VERSION = 137;
+const APP_DB_VERSION = 138;
const SYNC_VERSION = 10;
const CLIPPER_PROTOCOL_VERSION = "1.0";
diff --git a/src/views/dialogs/options/appearance.ejs b/src/views/dialogs/options/appearance.ejs
index f5f6330e1d..0be29c4bdc 100644
--- a/src/views/dialogs/options/appearance.ejs
+++ b/src/views/dialogs/options/appearance.ejs
@@ -70,13 +70,25 @@
<div class="col-6">
<label for="left-pane-min-width">Left pane minimum width (in pixels)</label>
- <input type="number" class="form-control" id="left-pane-min-width" min="100" max="2000" step="1"/>
+ <div class="input-group">
+ <input type="number" class="form-control" id="left-pane-min-width" min="100" max="2000" step="1"/>
+
+ <div class="input-group-append">
+ <span class="input-group-text">px</span>
+ </div>
+ </div>
</div>
<div class="col-6">
<label for="left-pane-min-width">Left pane width percent of window size</label>
- <input type="number" class="form-control" id="left-pane-width-percent" min="0" max="99" step="1"/>
+ <div class="input-group">
+ <input type="number" class="form-control" id="left-pane-width-percent" min="0" max="99" step="1"/>
+
+ <div class="input-group-append">
+ <span class="input-group-text">%</span>
+ </div>
+ </div>
</div>
</div>
diff --git a/src/views/dialogs/options/sidebar.ejs b/src/views/dialogs/options/sidebar.ejs
index 1bbbd88239..e2f7275077 100644
--- a/src/views/dialogs/options/sidebar.ejs
+++ b/src/views/dialogs/options/sidebar.ejs
@@ -1,3 +1,31 @@
<div id="options-sidebar" class="tab-pane">
- Hi!
+ <h3>Sidebar sizing</h3>
+
+ <div class="form-group row">
+ <div class="col-6">
+ <label for="sidebar-min-width">Sidebar minimum width (in pixels)</label>
+
+ <div class="input-group">
+ <input type="number" class="form-control" id="sidebar-min-width" min="100" max="2000" step="1"/>
+
+ <div class="input-group-append">
+ <span class="input-group-text">px</span>
+ </div>
+ </div>
+ </div>
+
+ <div class="col-6">
+ <label for="left-pane-min-width">Sidebar width percent of the detail pane</label>
+
+ <div class="input-group">
+ <input type="number" class="form-control" id="sidebar-width-percent" min="0" max="70" step="1"/>
+
+ <div class="input-group-append">
+ <span class="input-group-text">%</span>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <p>Sidebar width is calculated from the percent of the detail pane, if this is smaller than minimum width, then minimum width is used. If you want to have fixed width sidebar, set minimum width to the desired width and set percent to 0.</p>
</div>
\ No newline at end of file
diff --git a/src/views/sidebar.ejs b/src/views/sidebar.ejs
index 8e904d608d..c487043c3e 100644
--- a/src/views/sidebar.ejs
+++ b/src/views/sidebar.ejs
@@ -1,4 +1,4 @@
-<div class="note-detail-sidebar">
+<div class="note-detail-sidebar" style="width: <%= sidebarWidthPercent %>%; min-width: <%= sidebarMinWidth %>px">
<div style="text-align: center; margin-bottom: 10px;">
<button class="hide-sidebar-button" style="background: none; border: none;">hide sidebar <span class="jam jam-chevron-right"></span></button>
</div>