mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 13:01:31 +08:00 
			
		
		
		
	note type context submenu WIP
This commit is contained in:
		
							parent
							
								
									62650a4545
								
							
						
					
					
						commit
						177caec011
					
				| @ -5,9 +5,10 @@ function initContextMenu(event, itemContainer, selectContextMenuItem) { | |||||||
| 
 | 
 | ||||||
|     $contextMenuContainer.empty(); |     $contextMenuContainer.empty(); | ||||||
| 
 | 
 | ||||||
|     for (const item of itemContainer.getItems()) { |     function addItems($parent, items) { | ||||||
|  |         for (const item of items) { | ||||||
|             if (item.title === '----') { |             if (item.title === '----') { | ||||||
|             $contextMenuContainer.append($("<div>").addClass("dropdown-divider")); |                 $parent.append($("<div>").addClass("dropdown-divider")); | ||||||
|             } else { |             } else { | ||||||
|                 const $icon = $("<span>"); |                 const $icon = $("<span>"); | ||||||
| 
 | 
 | ||||||
| @ -17,19 +18,22 @@ function initContextMenu(event, itemContainer, selectContextMenuItem) { | |||||||
|                     $icon.append(" "); |                     $icon.append(" "); | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|             const $item = $("<a>") |                 const $item = $("<li>") | ||||||
|  |                     .addClass("dropdown-item"); | ||||||
|  | 
 | ||||||
|  |                 const $link = $("<a>") | ||||||
|                     .append($icon) |                     .append($icon) | ||||||
|                     .append("   ") // some space between icon and text
 |                     .append("   ") // some space between icon and text
 | ||||||
|                 .addClass("dropdown-item") |  | ||||||
|                     .prop("data-cmd", item.cmd) |                     .prop("data-cmd", item.cmd) | ||||||
|                     .append(item.title); |                     .append(item.title); | ||||||
| 
 | 
 | ||||||
|  |                 $item.append($link); | ||||||
| 
 | 
 | ||||||
|                 if (item.enabled !== undefined && !item.enabled) { |                 if (item.enabled !== undefined && !item.enabled) { | ||||||
|                 $item.addClass("disabled"); |                     $link.addClass("disabled"); | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|             $item.click(async function (e) { |                 $link.click(async function (e) { | ||||||
|                     const cmd = $(e.target).prop("data-cmd"); |                     const cmd = $(e.target).prop("data-cmd"); | ||||||
| 
 | 
 | ||||||
|                     e.originalTarget = event.target; |                     e.originalTarget = event.target; | ||||||
| @ -37,9 +41,23 @@ function initContextMenu(event, itemContainer, selectContextMenuItem) { | |||||||
|                     await selectContextMenuItem(e, cmd); |                     await selectContextMenuItem(e, cmd); | ||||||
|                 }); |                 }); | ||||||
| 
 | 
 | ||||||
|             $contextMenuContainer.append($item); |                 if (item.items) { | ||||||
|  |                     $item.addClass("dropdown-submenu"); | ||||||
|  |                     $link.addClass("dropdown-toggle"); | ||||||
|  | 
 | ||||||
|  |                     const $subMenu = $("<ul>").addClass("dropdown-menu"); | ||||||
|  | 
 | ||||||
|  |                     addItems($subMenu, item.items); | ||||||
|  | 
 | ||||||
|  |                     $item.append($subMenu); | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|  |                 $parent.append($item); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     addItems($contextMenuContainer, itemContainer.getItems()); | ||||||
| 
 | 
 | ||||||
|     // code below tries to detect when dropdown would overflow from page
 |     // code below tries to detect when dropdown would overflow from page
 | ||||||
|     // in such case we'll position it above click coordinates so it will fit into client
 |     // in such case we'll position it above click coordinates so it will fit into client
 | ||||||
|  | |||||||
| @ -77,9 +77,17 @@ function cut(nodes) { | |||||||
|     infoService.showMessage("Note(s) have been cut into clipboard."); |     infoService.showMessage("Note(s) have been cut into clipboard."); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | const noteTypeItems = [ | ||||||
|  |     {title: "Plain text", cmd: "insertNoteAfter", uiIcon: "file"}, | ||||||
|  |     {title: "Terminal", cmd: "insertNoteAfter", uiIcon: "terminal"}, | ||||||
|  |     {title: "Saved search", cmd: "insertNoteAfter", uiIcon: "search-folder"}, | ||||||
|  |     {title: "Relation Map", cmd: "insertNoteAfter", uiIcon: "map"}, | ||||||
|  |     {title: "Render HTML note", cmd: "insertNoteAfter", uiIcon: "play"} | ||||||
|  | ]; | ||||||
|  | 
 | ||||||
| const contextMenuItems = [ | const contextMenuItems = [ | ||||||
|     {title: "Insert note after <kbd>Ctrl+O</kbd>", cmd: "insertNoteAfter", uiIcon: "plus"}, |     {title: "Insert note after <kbd>Ctrl+O</kbd>", cmd: "insertNoteAfter", uiIcon: "plus", items: noteTypeItems}, | ||||||
|     {title: "Insert child note <kbd>Ctrl+P</kbd>", cmd: "insertChildNote", uiIcon: "plus"}, |     {title: "Insert child note <kbd>Ctrl+P</kbd>", cmd: "insertChildNote", uiIcon: "plus", items: noteTypeItems}, | ||||||
|     {title: "Delete <kbd>Delete</kbd>", cmd: "delete", uiIcon: "trash"}, |     {title: "Delete <kbd>Delete</kbd>", cmd: "delete", uiIcon: "trash"}, | ||||||
|     {title: "----"}, |     {title: "----"}, | ||||||
|     {title: "Hoist note <kbd>Ctrl-H</kbd>", cmd: "hoist", uiIcon: "arrow-up"}, |     {title: "Hoist note <kbd>Ctrl-H</kbd>", cmd: "hoist", uiIcon: "arrow-up"}, | ||||||
|  | |||||||
| @ -71,7 +71,7 @@ body { | |||||||
|     border-radius: 7px; |     border-radius: 7px; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #context-menu-container { | #context-menu-container, #context-menu-container .dropdown-menu { | ||||||
|     padding: 3px 0 0; |     padding: 3px 0 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -114,3 +114,23 @@ body { | |||||||
|     padding-bottom: 0; |     padding-bottom: 0; | ||||||
|     border-bottom: 1px dotted; |     border-bottom: 1px dotted; | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | li.dropdown-submenu:hover > ul.dropdown-menu { | ||||||
|  |     display: block; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | .dropdown-submenu { | ||||||
|  |     position:relative; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | .dropdown-submenu > .dropdown-menu { | ||||||
|  |     top: 0; | ||||||
|  |     left: 100%; | ||||||
|  |     margin-top: -6px; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /* rotate caret on hover */ | ||||||
|  | .dropdown-menu > li > a:hover:after { | ||||||
|  |     text-decoration: underline; | ||||||
|  |     transform: rotate(-90deg); | ||||||
|  | } | ||||||
| @ -1,5 +1,6 @@ | |||||||
| const repository = require('./repository'); | const repository = require('./repository'); | ||||||
| const sql = require('./sql'); | const sql = require('./sql'); | ||||||
|  | const log = require('./log'); | ||||||
| const parseFilters = require('./parse_filters'); | const parseFilters = require('./parse_filters'); | ||||||
| const buildSearchQuery = require('./build_search_query'); | const buildSearchQuery = require('./build_search_query'); | ||||||
| 
 | 
 | ||||||
| @ -8,7 +9,14 @@ async function searchForNotes(searchString) { | |||||||
| 
 | 
 | ||||||
|     const {query, params} = buildSearchQuery(filters); |     const {query, params} = buildSearchQuery(filters); | ||||||
| 
 | 
 | ||||||
|  |     try { | ||||||
|         return await repository.getEntities(query, params); |         return await repository.getEntities(query, params); | ||||||
|  |     } | ||||||
|  |     catch (e) { | ||||||
|  |         log.error("Search failed for " + query); | ||||||
|  | 
 | ||||||
|  |         throw e; | ||||||
|  |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| async function searchForNoteIds(searchString) { | async function searchForNoteIds(searchString) { | ||||||
| @ -16,7 +24,14 @@ async function searchForNoteIds(searchString) { | |||||||
| 
 | 
 | ||||||
|     const {query, params} = buildSearchQuery(filters, 'notes.noteId'); |     const {query, params} = buildSearchQuery(filters, 'notes.noteId'); | ||||||
| 
 | 
 | ||||||
|  |     try { | ||||||
|         return await sql.getColumn(query, params); |         return await sql.getColumn(query, params); | ||||||
|  |     } | ||||||
|  |     catch (e) { | ||||||
|  |         log.error("Search failed for " + query); | ||||||
|  | 
 | ||||||
|  |         throw e; | ||||||
|  |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| module.exports = { | module.exports = { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 zadam
						zadam