launchbar WIP

This commit is contained in:
zadam 2022-08-04 23:00:32 +02:00
parent b86dbc088d
commit 7565458332
9 changed files with 115 additions and 46 deletions

View file

@ -3,7 +3,7 @@
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_18" default="true" project-jdk-name="openjdk-18" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_16" default="true" project-jdk-name="openjdk-16" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View file

@ -78,6 +78,7 @@ import OptionsDialog from "../widgets/dialogs/options.js";
import FloatingButtons from "../widgets/floating_buttons/floating_buttons.js";
import RelationMapButtons from "../widgets/floating_buttons/relation_map_buttons.js";
import MermaidExportButton from "../widgets/floating_buttons/mermaid_export_button.js";
import ShortcutContainer from "../widgets/containers/shortcut_container.js";
export default class DesktopLayout {
constructor(customWidgets) {
@ -93,33 +94,34 @@ export default class DesktopLayout {
.id("launcher-pane")
.css("width", "53px")
.child(new GlobalMenuWidget())
.child(new ButtonWidget()
.icon("bx-file-blank")
.title("New note")
.command("createNoteIntoInbox"))
.child(new ButtonWidget()
.icon("bx-search")
.title("Search")
.command("searchNotes"))
.child(new ButtonWidget()
.icon("bx-send")
.title("Jump to note")
.command("jumpToNote"))
.child(new OpenNoteButtonWidget()
.targetNote('globalnotemap'))
.child(new ButtonWidget()
.icon("bx-history")
.title("Show recent changes")
.command("showRecentChanges"))
.child(new CalendarWidget())
.child(new SpacerWidget(40, 0))
.child(new FlexContainer("column")
.id("plugin-buttons")
.contentSized())
.child(new BookmarkButtons())
.child(new SpacerWidget(0, 1000))
.child(new ProtectedSessionStatusWidget())
.child(new SyncStatusWidget())
.child(new ShortcutContainer())
// .child(new ButtonWidget()
// .icon("bx-file-blank")
// .title("New note")
// .command("createNoteIntoInbox"))
// .child(new ButtonWidget()
// .icon("bx-search")
// .title("Search")
// .command("searchNotes"))
// .child(new ButtonWidget()
// .icon("bx-send")
// .title("Jump to note")
// .command("jumpToNote"))
// .child(new OpenNoteButtonWidget()
// .targetNote('globalnotemap'))
// .child(new ButtonWidget()
// .icon("bx-history")
// .title("Show recent changes")
// .command("showRecentChanges"))
// .child(new CalendarWidget())
// .child(new SpacerWidget(40, 0))
// .child(new FlexContainer("column")
// .id("plugin-buttons")
// .contentSized())
// .child(new BookmarkButtons())
// .child(new SpacerWidget(0, 1000))
// .child(new ProtectedSessionStatusWidget())
// .child(new SyncStatusWidget())
.child(new LeftPaneToggleWidget())
)
.child(new LeftPaneContainer()

View file

@ -70,4 +70,8 @@ export default class RootCommandExecutor extends Component {
toggleLeftPaneCommand() {
options.toggle('leftPaneVisible');
}
showLaunchBarShortcutsCommand() {
appContext.tabManager.openContextWithNote('lb_root', true, null, 'lb_root');
}
}

View file

@ -47,6 +47,11 @@ const TPL = `
</button>
<div class="dropdown-menu dropdown-menu-right">
<a class="dropdown-item options-button" data-trigger-command="showLaunchBarShortcuts">
<span class="bx bx-slider"></span>
Show launchbar shortcuts
</a>
<a class="dropdown-item options-button" data-trigger-command="showOptions">
<span class="bx bx-slider"></span>
Options

View file

@ -30,7 +30,10 @@ export default class Container extends BasicWidget {
doRender() {
this.$widget = $(`<div>`);
this.renderChildren();
}
renderChildren() {
for (const widget of this.children) {
this.$widget.append(widget.render());
}

View file

@ -11,7 +11,7 @@ export default class LeftPaneContainer extends FlexContainer {
}
isEnabled() {
return super.isEnabled() && options.is( 'leftPaneVisible');
return super.isEnabled() && options.is('leftPaneVisible');
}
entitiesReloadedEvent({loadResults}) {

View file

@ -0,0 +1,42 @@
import FlexContainer from "./flex_container.js";
import froca from "../../services/froca.js";
import ButtonWidget from "../buttons/button_widget.js";
export default class ShortcutContainer extends FlexContainer {
constructor() {
super('column');
this.id('shortcut-container');
this.css('height', '100%');
this.filling();
this.load();
}
async load() {
this.children = [];
const visibleShortcutsRoot = await froca.getNote('lb_visibleshortcuts');
console.log(await visibleShortcutsRoot.getChildNotes());
for (const shortcut of await visibleShortcutsRoot.getChildNotes()) {
this.child(new ButtonWidget()
.icon(shortcut.getLabelValue("iconClass"))
.title(shortcut.title)
.command(shortcut.getLabelValue("command")));
}
this.$widget.empty();
this.renderChildren();
this.handleEventInChildren('initialRenderComplete');
}
entitiesReloadedEvent({loadResults}) {
if (loadResults.getNotes().find(note => note.noteId.startsWith("lb_"))
|| loadResults.getBranches().find(branch => branch.branchId.startsWith("lb_"))) {
this.load();
}
}
}

View file

@ -601,10 +601,6 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
}
for (const branch of childBranches) {
if (branch.noteId === 'hidden') {
continue;
}
if (hideArchivedNotes) {
const note = branch.getNoteFromCache();
@ -936,7 +932,6 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
if (this.noteContext
&& this.noteContext.notePath
&& !this.noteContext.note.isDeleted
&& !this.noteContext.notePath.includes("root/hidden")
) {
const newActiveNode = await this.getNodeFromPath(this.noteContext.notePath);
@ -1083,7 +1078,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
}
}
if (!ecBranch.isDeleted && ecBranch.noteId !== 'hidden') {
if (!ecBranch.isDeleted) {
for (const parentNode of this.getNodesByNoteId(ecBranch.parentNoteId)) {
if (parentNode.isFolder() && !parentNode.isLoaded()) {
continue;

View file

@ -237,12 +237,12 @@ function getBulkActionNote() {
}
function getLaunchBarRoot() {
let note = becca.getNote('launchbar');
let note = becca.getNote('lb_root');
if (!note) {
note = noteService.createNewNote({
branchId: 'launchbar',
noteId: 'launchbar',
branchId: 'lb_root',
noteId: 'lb_root',
title: 'Launch bar',
type: 'text',
content: '',
@ -288,13 +288,11 @@ function getLaunchBarVisibleShortcutsRoot() {
}
const shortcuts = [
{ id: 'lb_newnote', command: 'createNoteIntoInbox', title: 'New note', icon: 'bx bx-file-blank' },
{ id: 'lb_searcj', command: 'searchNotes', title: 'Search notes', icon: 'bx bx-search' },
{ id: 'lb_jumpto', command: 'jumpToNote', title: 'Jump to note', icon: 'bx bx-send' },
{ id: 'lb_notemap', targetNote: 'globalnotemap', title: 'Note map', icon: 'bx bx-map' },
{ id: 'lb_recentchanges', command: 'showRecentChanges', title: 'Show recent changes', icon: 'bx bx-history' },
{ id: 'lb_recentchanges', command: 'jumpToNote', title: 'Jump to note', icon: 'bx bx-send' },
{ id: 'lb_newnote', command: 'createNoteIntoInbox', title: 'New note', icon: 'bx bx-file-blank', isVisible: true },
{ id: 'lb_search', command: 'searchNotes', title: 'Search notes', icon: 'bx bx-search', isVisible: true },
{ id: 'lb_jumpto', command: 'jumpToNote', title: 'Jump to note', icon: 'bx bx-send', isVisible: true },
{ id: 'lb_notemap', targetNote: 'globalnotemap', title: 'Note map', icon: 'bx bx-map-alt', isVisible: true },
{ id: 'lb_recentchanges', command: 'showRecentChanges', title: 'Show recent changes', icon: 'bx bx-history', isVisible: false }
];
function createMissingSpecialNotes() {
@ -304,7 +302,27 @@ function createMissingSpecialNotes() {
getBulkActionNote();
getLaunchBarRoot();
getLaunchBarAvailableShortcutsRoot();
getLaunchBarVisibleShortcutsRoot();
getLaunchBarVisibleShortcutsRoot()
for (const shortcut of shortcuts) {
let note = becca.getNote(shortcut.id);
const parentNoteId = shortcut.isVisible ? getLaunchBarVisibleShortcutsRoot().noteId : getLaunchBarAvailableShortcutsRoot().noteId;
if (!note) {
note = noteService.createNewNote({
branchId: shortcut.id,
noteId: shortcut.id,
title: shortcut.title,
type: 'text',
content: '',
parentNoteId: parentNoteId
}).note;
note.addLabel('builtinShortcut');
note.addLabel('iconClass', shortcut.icon);
note.addLabel('command', shortcut.command);
}
}
// share root is not automatically created since it's visible in the tree and many won't need it/use it