Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add title, so user can modify noteTabs outside by text editor. #67

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ joplin.plugins.register({
// settings
const settings: Settings = new Settings();
await settings.register();

// note tabs
const tabs = new NoteTabs(settings);
// last active note
Expand All @@ -24,6 +25,25 @@ joplin.plugins.register({
const panel = new Panel(tabs, settings);
await panel.register();

await settings.read();
let updateTitle = false
for (const noteTab of tabs.tabs) {
let note: any = null;
// get real note from database, if no longer exists remove tab and continue with next one
if (noteTab.title == undefined || noteTab.title.length==0){
try {
note = await joplin.data.get(['notes', noteTab.id], { fields: ['id', 'title'] });
} catch (error) {
continue;
}
noteTab.title = note.title;
updateTitle = true
}
}
if (updateTitle) {
await settings.storeTabs();
}

//#region HELPERS

/**
Expand All @@ -43,7 +63,7 @@ joplin.plugins.register({
tabs.replaceTemp(noteId);
} else {
// or add as new temporary tab at the end
await tabs.add(noteId, NoteTabType.Temporary);
await tabs.add(noteId, '', NoteTabType.Temporary);
}
}
}
Expand All @@ -52,7 +72,7 @@ joplin.plugins.register({
* Add new or pin tab for handled note. Optionally at the specified index of targetId.
*/
async function pinTab(noteId: string, addAsNew: boolean, targetId?: string) {
const note: any = await DATA.get(['notes', noteId], { fields: ['id', 'is_todo', 'todo_completed'] });
const note: any = await DATA.get(['notes', noteId], { fields: ['id', 'title', 'is_todo', 'todo_completed'] });

if (note) {
// do not pin completed todos if auto unpin is enabled
Expand All @@ -64,7 +84,7 @@ joplin.plugins.register({
} else {
// otherwise add as new one
if (addAsNew) {
await tabs.add(note.id, NoteTabType.Pinned, targetId);
await tabs.add(note.id, note.title, NoteTabType.Pinned, targetId);
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/noteTabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export enum NoteTabType {
interface INoteTab {
// Joplin note ID
id: string,
// Joplin note Title
title: string,
// Type of the tab
type: NoteTabType
}
Expand Down Expand Up @@ -115,11 +117,11 @@ export class NoteTabs {
/**
* Adds note as new tab at the end.
*/
async add(newId: string, newType: NoteTabType, targetId?: string) {
async add(newId: string, title: string, newType: NoteTabType, targetId?: string) {
if (newId === undefined || newType === undefined) return;

const index = this.indexOf(targetId);
const newTab: any = { id: newId, type: newType };
const newTab: any = { id: newId, title:title, type: newType };
if (index >= 0) {
this.tabs.splice(index, 0, newTab);
} else {
Expand Down