| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | import utils from "./utils.js"; | 
					
						
							|  |  |  | import linkService from "./link.js"; | 
					
						
							| 
									
										
										
										
											2018-06-02 13:02:20 -04:00
										 |  |  | import zoomService from "./zoom.js"; | 
					
						
							| 
									
										
										
										
											2018-05-31 20:00:39 -04:00
										 |  |  | import protectedSessionService from "./protected_session.js"; | 
					
						
							| 
									
										
										
										
											2019-08-20 21:40:47 +02:00
										 |  |  | import searchNotesService from "./search_notes.js"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const NOTE_REVISIONS = "../dialogs/note_revisions.js"; | 
					
						
							|  |  |  | const OPTIONS = "../dialogs/options.js"; | 
					
						
							|  |  |  | const ADD_LINK = "../dialogs/add_link.js"; | 
					
						
							|  |  |  | const JUMP_TO_NOTE = "../dialogs/jump_to_note.js"; | 
					
						
							|  |  |  | const NOTE_SOURCE = "../dialogs/note_source.js"; | 
					
						
							|  |  |  | const RECENT_CHANGES = "../dialogs/recent_changes.js"; | 
					
						
							|  |  |  | const SQL_CONSOLE = "../dialogs/sql_console.js"; | 
					
						
							|  |  |  | const ATTRIBUTES = "../dialogs/attributes.js"; | 
					
						
							|  |  |  | const HELP = "../dialogs/help.js"; | 
					
						
							|  |  |  | const NOTE_INFO = "../dialogs/note_info.js"; | 
					
						
							|  |  |  | const ABOUT = "../dialogs/about.js"; | 
					
						
							|  |  |  | const LINK_MAP = "../dialogs/link_map.js"; | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | function registerEntrypoints() { | 
					
						
							|  |  |  |     // hot keys are active also inside inputs and content editables
 | 
					
						
							|  |  |  |     jQuery.hotkeys.options.filterInputAcceptingElements = false; | 
					
						
							|  |  |  |     jQuery.hotkeys.options.filterContentEditable = false; | 
					
						
							|  |  |  |     jQuery.hotkeys.options.filterTextInputs = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-20 21:40:47 +02:00
										 |  |  |     utils.bindGlobalShortcut('ctrl+l', () => import(ADD_LINK).then(d => d.showDialog())); | 
					
						
							|  |  |  |     utils.bindGlobalShortcut('ctrl+shift+l', () => import(ADD_LINK).then(d => d.showDialogForClone())); | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-20 21:40:47 +02:00
										 |  |  |     $("#jump-to-note-dialog-button").click(() => import(JUMP_TO_NOTE).then(d => d.showDialog())); | 
					
						
							|  |  |  |     utils.bindGlobalShortcut('ctrl+j', () => import(JUMP_TO_NOTE).then(d => d.showDialog())); | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-20 21:40:47 +02:00
										 |  |  |     $("#recent-changes-button").click(() => import(RECENT_CHANGES).then(d => d.showDialog())); | 
					
						
							| 
									
										
										
										
											2019-05-05 18:24:59 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     $("#enter-protected-session-button").click(protectedSessionService.enterProtectedSession); | 
					
						
							|  |  |  |     $("#leave-protected-session-button").click(protectedSessionService.leaveProtectedSession); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $("#toggle-search-button").click(searchNotesService.toggleSearch); | 
					
						
							| 
									
										
										
										
											2019-08-12 22:41:53 +02:00
										 |  |  |     utils.bindGlobalShortcut('ctrl+s', searchNotesService.toggleSearch); | 
					
						
							| 
									
										
										
										
											2019-05-05 18:24:59 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     const $noteTabContainer = $("#note-tab-container"); | 
					
						
							| 
									
										
										
										
											2019-08-20 21:40:47 +02:00
										 |  |  |     $noteTabContainer.on("click", ".show-attributes-button", () => import(ATTRIBUTES).then(d => d.showDialog())); | 
					
						
							|  |  |  |     utils.bindGlobalShortcut('alt+a', () => import(ATTRIBUTES).then(d => d.showDialog())); | 
					
						
							| 
									
										
										
										
											2019-05-05 18:24:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-20 21:40:47 +02:00
										 |  |  |     $noteTabContainer.on("click", ".show-note-info-button", () => import(NOTE_INFO).then(d => d.showDialog())); | 
					
						
							| 
									
										
										
										
											2019-05-05 18:24:59 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     $noteTabContainer.on("click", ".show-note-revisions-button", function() { | 
					
						
							| 
									
										
										
										
											2018-11-19 09:54:33 +01:00
										 |  |  |         if ($(this).hasClass("disabled")) { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-20 21:40:47 +02:00
										 |  |  |         import(NOTE_REVISIONS).then(d => d.showDialog()); | 
					
						
							| 
									
										
										
										
											2018-11-19 09:54:33 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-05 18:24:59 +02:00
										 |  |  |     $noteTabContainer.on("click", ".show-source-button", function() { | 
					
						
							| 
									
										
										
										
											2018-11-19 09:54:33 +01:00
										 |  |  |         if ($(this).hasClass("disabled")) { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-30 21:22:52 +02:00
										 |  |  |         import(NOTE_SOURCE).then(d => d.showDialog()); | 
					
						
							| 
									
										
										
										
											2018-11-19 09:54:33 +01:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-02 15:35:57 +02:00
										 |  |  |     $noteTabContainer.on("click", ".show-link-map-button", function() { | 
					
						
							| 
									
										
										
										
											2019-08-20 21:40:47 +02:00
										 |  |  |         import(LINK_MAP).then(d => d.showDialog()); | 
					
						
							| 
									
										
										
										
											2019-06-02 15:35:57 +02:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-20 21:40:47 +02:00
										 |  |  |     $("#options-button").click(() => import(OPTIONS).then(d => d.showDialog())); | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-20 21:40:47 +02:00
										 |  |  |     $("#show-help-button").click(() => import(HELP).then(d => d.showDialog())); | 
					
						
							|  |  |  |     utils.bindGlobalShortcut('f1', () => import(HELP).then(d => d.showDialog())); | 
					
						
							| 
									
										
										
										
											2019-02-10 10:38:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-20 21:40:47 +02:00
										 |  |  |     $("#open-sql-console-button").click(() => import(SQL_CONSOLE).then(d => d.showDialog())); | 
					
						
							|  |  |  |     utils.bindGlobalShortcut('alt+o', () => import(SQL_CONSOLE).then(d => d.showDialog())); | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-20 21:40:47 +02:00
										 |  |  |     $("#show-about-dialog-button").click(() => import(ABOUT).then(d => d.showDialog())); | 
					
						
							| 
									
										
										
										
											2019-03-24 23:01:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  |     if (utils.isElectron()) { | 
					
						
							| 
									
										
										
										
											2018-05-26 22:54:06 -04:00
										 |  |  |         $("#history-navigation").show(); | 
					
						
							|  |  |  |         $("#history-back-button").click(window.history.back); | 
					
						
							|  |  |  |         $("#history-forward-button").click(window.history.forward); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-23 20:15:33 +01:00
										 |  |  |         if (utils.isMac()) { | 
					
						
							|  |  |  |             // Mac has a different history navigation shortcuts - https://github.com/zadam/trilium/issues/376
 | 
					
						
							| 
									
										
										
										
											2019-08-12 22:41:53 +02:00
										 |  |  |             utils.bindGlobalShortcut('meta+left', window.history.back); | 
					
						
							|  |  |  |             utils.bindGlobalShortcut('meta+right', window.history.forward); | 
					
						
							| 
									
										
										
										
											2019-01-23 20:15:33 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							| 
									
										
										
										
											2019-08-12 22:41:53 +02:00
										 |  |  |             utils.bindGlobalShortcut('alt+left', window.history.back); | 
					
						
							|  |  |  |             utils.bindGlobalShortcut('alt+right', window.history.forward); | 
					
						
							| 
									
										
										
										
											2019-01-23 20:15:33 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-12 22:41:53 +02:00
										 |  |  |     utils.bindGlobalShortcut('alt+m', e => { | 
					
						
							| 
									
										
										
										
											2018-06-10 10:53:39 -04:00
										 |  |  |         $(".hide-toggle").toggle(); | 
					
						
							| 
									
										
										
										
											2019-04-28 21:24:13 +02:00
										 |  |  |         $("#container").toggleClass("distraction-free-mode"); | 
					
						
							| 
									
										
										
										
											2018-06-10 10:53:39 -04:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // hide (toggle) everything except for the note content for distraction free writing
 | 
					
						
							| 
									
										
										
										
											2019-08-12 22:41:53 +02:00
										 |  |  |     utils.bindGlobalShortcut('alt+t', e => { | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  |         const date = new Date(); | 
					
						
							|  |  |  |         const dateString = utils.formatDateTime(date); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         linkService.addTextToEditor(dateString); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-12 22:41:53 +02:00
										 |  |  |     utils.bindGlobalShortcut('f5', utils.reloadApp); | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-14 12:48:50 +02:00
										 |  |  |     $("#reload-frontend-button").click(utils.reloadApp); | 
					
						
							| 
									
										
										
										
											2019-08-12 22:41:53 +02:00
										 |  |  |     utils.bindGlobalShortcut('ctrl+r', utils.reloadApp); | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-09 19:25:55 +01:00
										 |  |  |     $("#open-dev-tools-button").toggle(utils.isElectron()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (utils.isElectron()) { | 
					
						
							|  |  |  |         const openDevTools = () => { | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  |             require('electron').remote.getCurrentWindow().toggleDevTools(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return false; | 
					
						
							| 
									
										
										
										
											2019-02-09 19:25:55 +01:00
										 |  |  |         }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-12 22:41:53 +02:00
										 |  |  |         utils.bindGlobalShortcut('ctrl+shift+i', openDevTools); | 
					
						
							| 
									
										
										
										
											2019-02-09 19:25:55 +01:00
										 |  |  |         $("#open-dev-tools-button").click(openDevTools); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-02 21:44:56 +02:00
										 |  |  |     let findInPage; | 
					
						
							| 
									
										
										
										
											2018-11-21 23:39:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-02 21:44:56 +02:00
										 |  |  |     if (utils.isElectron()) { | 
					
						
							|  |  |  |         const { remote } = require('electron'); | 
					
						
							|  |  |  |         const { FindInPage } = require('electron-find'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         findInPage = new FindInPage(remote.getCurrentWebContents(), { | 
					
						
							|  |  |  |             offsetTop: 10, | 
					
						
							|  |  |  |             offsetRight: 10, | 
					
						
							|  |  |  |             boxBgColor: 'var(--main-background-color)', | 
					
						
							|  |  |  |             boxShadowColor: '#000', | 
					
						
							|  |  |  |             inputColor: 'var(--input-text-color)', | 
					
						
							|  |  |  |             inputBgColor: 'var(--input-background-color)', | 
					
						
							|  |  |  |             inputFocusColor: '#555', | 
					
						
							|  |  |  |             textColor: 'var(--main-text-color)', | 
					
						
							|  |  |  |             textHoverBgColor: '#555', | 
					
						
							|  |  |  |             caseSelectedColor: 'var(--main-border-color)' | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-11-21 23:39:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-09 21:16:18 +02:00
										 |  |  |     if (utils.isElectron()) { | 
					
						
							| 
									
										
										
										
											2019-08-12 22:41:53 +02:00
										 |  |  |         utils.bindGlobalShortcut('ctrl+f', () => { | 
					
						
							| 
									
										
										
										
											2019-04-02 21:44:56 +02:00
										 |  |  |             findInPage.openFindWindow(); | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |             return false; | 
					
						
							| 
									
										
										
										
											2019-04-09 21:16:18 +02:00
										 |  |  |         }); | 
					
						
							| 
									
										
										
										
											2018-12-10 20:44:50 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-28 21:52:25 +02:00
										 |  |  |     if (utils.isElectron()) { | 
					
						
							| 
									
										
										
										
											2019-04-28 21:59:29 +02:00
										 |  |  |         const toggleFullscreen = function() { | 
					
						
							| 
									
										
										
										
											2019-04-28 21:52:25 +02:00
										 |  |  |             const win = require('electron').remote.getCurrentWindow(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (win.isFullScreenable()) { | 
					
						
							|  |  |  |                 win.setFullScreen(!win.isFullScreen()); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return false; | 
					
						
							| 
									
										
										
										
											2019-04-28 21:59:29 +02:00
										 |  |  |         }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $("#toggle-fullscreen-button").click(toggleFullscreen); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-12 22:41:53 +02:00
										 |  |  |         utils.bindGlobalShortcut('f11', toggleFullscreen); | 
					
						
							| 
									
										
										
										
											2019-04-28 21:59:29 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |         // outside of electron this is handled by the browser
 | 
					
						
							|  |  |  |         $("#toggle-fullscreen-button").hide(); | 
					
						
							| 
									
										
										
										
											2019-04-28 21:52:25 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-02 13:02:20 -04:00
										 |  |  |     if (utils.isElectron()) { | 
					
						
							| 
									
										
										
										
											2019-08-12 22:41:53 +02:00
										 |  |  |         utils.bindGlobalShortcut('ctrl+-', zoomService.decreaseZoomFactor); | 
					
						
							|  |  |  |         utils.bindGlobalShortcut('ctrl+=', zoomService.increaseZoomFactor); | 
					
						
							| 
									
										
										
										
											2018-06-02 13:02:20 -04:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default { | 
					
						
							|  |  |  |     registerEntrypoints | 
					
						
							|  |  |  | } |