| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | import utils from "./utils.js"; | 
					
						
							|  |  |  | import treeService from "./tree.js"; | 
					
						
							|  |  |  | import linkService from "./link.js"; | 
					
						
							| 
									
										
										
										
											2018-06-02 13:02:20 -04:00
										 |  |  | import zoomService from "./zoom.js"; | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | import noteRevisionsDialog from "../dialogs/note_revisions.js"; | 
					
						
							| 
									
										
										
										
											2018-04-01 17:41:28 -04:00
										 |  |  | import optionsDialog from "../dialogs/options.js"; | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | import addLinkDialog from "../dialogs/add_link.js"; | 
					
						
							|  |  |  | import jumpToNoteDialog from "../dialogs/jump_to_note.js"; | 
					
						
							|  |  |  | import noteSourceDialog from "../dialogs/note_source.js"; | 
					
						
							|  |  |  | import recentChangesDialog from "../dialogs/recent_changes.js"; | 
					
						
							|  |  |  | import sqlConsoleDialog from "../dialogs/sql_console.js"; | 
					
						
							| 
									
										
										
										
											2018-06-04 19:48:02 -04:00
										 |  |  | import searchNotesService from "./search_notes.js"; | 
					
						
							| 
									
										
										
										
											2018-08-03 11:11:57 +02:00
										 |  |  | import attributesDialog from "../dialogs/attributes.js"; | 
					
						
							| 
									
										
										
										
											2019-02-10 10:38:18 +01:00
										 |  |  | import helpDialog from "../dialogs/help.js"; | 
					
						
							| 
									
										
										
										
											2019-02-14 20:56:33 +01:00
										 |  |  | import noteInfoDialog from "../dialogs/note_info.js"; | 
					
						
							| 
									
										
										
										
											2019-03-24 23:01:33 +01:00
										 |  |  | import aboutDialog from "../dialogs/about.js"; | 
					
						
							| 
									
										
										
										
											2018-05-31 20:00:39 -04:00
										 |  |  | import protectedSessionService from "./protected_session.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; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     utils.bindShortcut('ctrl+l', addLinkDialog.showDialog); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-05 23:28:10 -04:00
										 |  |  |     $("#jump-to-note-dialog-button").click(jumpToNoteDialog.showDialog); | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  |     utils.bindShortcut('ctrl+j', jumpToNoteDialog.showDialog); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-19 09:54:33 +01:00
										 |  |  |     $("#show-note-revisions-button").click(function() { | 
					
						
							|  |  |  |         if ($(this).hasClass("disabled")) { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-19 09:54:33 +01:00
										 |  |  |         noteRevisionsDialog.showCurrentNoteRevisions(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $("#show-source-button").click(function() { | 
					
						
							|  |  |  |         if ($(this).hasClass("disabled")) { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         noteSourceDialog.showDialog(); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     $("#recent-changes-button").click(recentChangesDialog.showDialog); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-25 14:12:33 +01:00
										 |  |  |     $("#enter-protected-session-button").click(protectedSessionService.enterProtectedSession); | 
					
						
							|  |  |  |     $("#leave-protected-session-button").click(protectedSessionService.leaveProtectedSession); | 
					
						
							| 
									
										
										
										
											2018-05-31 20:00:39 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-04 19:48:02 -04:00
										 |  |  |     $("#toggle-search-button").click(searchNotesService.toggleSearch); | 
					
						
							|  |  |  |     utils.bindShortcut('ctrl+s', searchNotesService.toggleSearch); | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-03 11:11:57 +02:00
										 |  |  |     $(".show-attributes-button").click(attributesDialog.showDialog); | 
					
						
							|  |  |  |     utils.bindShortcut('alt+a', attributesDialog.showDialog); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-01 17:41:28 -04:00
										 |  |  |     $("#options-button").click(optionsDialog.showDialog); | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-10 10:38:18 +01:00
										 |  |  |     $("#show-help-button").click(helpDialog.showDialog); | 
					
						
							| 
									
										
										
										
											2019-02-10 12:19:48 +01:00
										 |  |  |     utils.bindShortcut('f1', helpDialog.showDialog); | 
					
						
							| 
									
										
										
										
											2019-02-10 10:38:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     $("#open-sql-console-button").click(sqlConsoleDialog.showDialog); | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  |     utils.bindShortcut('alt+o', sqlConsoleDialog.showDialog); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-14 20:56:33 +01:00
										 |  |  |     $("#show-note-info-button").click(noteInfoDialog.showDialog); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-24 23:01:33 +01:00
										 |  |  |     $("#show-about-dialog-button").click(aboutDialog.showDialog); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
 | 
					
						
							|  |  |  |             utils.bindShortcut('meta+left', window.history.back); | 
					
						
							|  |  |  |             utils.bindShortcut('meta+right', window.history.forward); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |             utils.bindShortcut('alt+left', window.history.back); | 
					
						
							|  |  |  |             utils.bindShortcut('alt+right', window.history.forward); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-10 10:53:39 -04:00
										 |  |  |     utils.bindShortcut('alt+m', e => { | 
					
						
							|  |  |  |         $(".hide-toggle").toggle(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-14 13:37:45 +01:00
										 |  |  |         const $container = $("#container"); | 
					
						
							| 
									
										
										
										
											2018-06-10 10:53:39 -04:00
										 |  |  |         // when hiding switch display to block, otherwise grid still tries to display columns which shows
 | 
					
						
							|  |  |  |         // left empty column
 | 
					
						
							| 
									
										
										
										
											2018-11-14 13:37:45 +01:00
										 |  |  |         $container.css("display", $container.css("display") === "grid" ? "block" : "grid"); | 
					
						
							| 
									
										
										
										
											2018-11-14 13:42:50 +01: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
 | 
					
						
							|  |  |  |     utils.bindShortcut('alt+t', e => { | 
					
						
							|  |  |  |         const date = new Date(); | 
					
						
							|  |  |  |         const dateString = utils.formatDateTime(date); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         linkService.addTextToEditor(dateString); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     utils.bindShortcut('f5', utils.reloadApp); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     utils.bindShortcut('ctrl+r', utils.reloadApp); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  |         }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         utils.bindShortcut('ctrl+shift+i', openDevTools); | 
					
						
							|  |  |  |         $("#open-dev-tools-button").click(openDevTools); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-10 20:44:50 +01:00
										 |  |  |     function openInPageSearch() { | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  |         if (utils.isElectron()) { | 
					
						
							| 
									
										
										
										
											2018-11-21 23:39:19 +01:00
										 |  |  |             const $searchWindowWebview = $(".electron-in-page-search-window"); | 
					
						
							|  |  |  |             $searchWindowWebview.show(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             const searchInPage = require('electron-in-page-search').default; | 
					
						
							|  |  |  |             const {remote} = require('electron'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             const inPageSearch = searchInPage(remote.getCurrentWebContents(), { | 
					
						
							|  |  |  |                 searchWindowWebview: $searchWindowWebview[0], | 
					
						
							|  |  |  |                 //openDevToolsOfSearchWindow: true,
 | 
					
						
							|  |  |  |                 customCssPath: '/libraries/electron-in-page-search/default-style.css' | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             inPageSearch.openSearchWindow(); | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-12-10 20:44:50 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     utils.bindShortcut('ctrl+f', openInPageSearch); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-26 23:48:45 -04:00
										 |  |  |     // FIXME: do we really need these at this point?
 | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  |     utils.bindShortcut("ctrl+shift+up", () => { | 
					
						
							| 
									
										
										
										
											2019-03-20 22:28:54 +01:00
										 |  |  |         const node = treeService.getActiveNode(); | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  |         node.navigate($.ui.keyCode.UP, true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-26 23:48:45 -04:00
										 |  |  |         $("#note-detail-text").focus(); | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-26 23:48:45 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // FIXME: do we really need these at this point?
 | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  |     utils.bindShortcut("ctrl+shift+down", () => { | 
					
						
							| 
									
										
										
										
											2019-03-20 22:28:54 +01:00
										 |  |  |         const node = treeService.getActiveNode(); | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  |         node.navigate($.ui.keyCode.DOWN, true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-26 23:48:45 -04:00
										 |  |  |         $("#note-detail-text").focus(); | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-02 13:02:20 -04:00
										 |  |  |     if (utils.isElectron()) { | 
					
						
							| 
									
										
										
										
											2019-01-13 18:57:46 +01:00
										 |  |  |         utils.bindShortcut('ctrl+-', zoomService.decreaseZoomFactor); | 
					
						
							|  |  |  |         utils.bindShortcut('ctrl+=', zoomService.increaseZoomFactor); | 
					
						
							| 
									
										
										
										
											2018-06-02 13:02:20 -04:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-26 23:48:45 -04:00
										 |  |  |     $("#note-title").bind('keydown', 'return', () => $("#note-detail-text").focus()); | 
					
						
							| 
									
										
										
										
											2018-03-26 22:29:14 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default { | 
					
						
							|  |  |  |     registerEntrypoints | 
					
						
							|  |  |  | } |