Skip to content

Commit

Permalink
Merge pull request #72 from prestsauce/openNoteSetting
Browse files Browse the repository at this point in the history
Added new setting 'openPageOnCompletion'
  • Loading branch information
anpigon authored Oct 18, 2023
2 parents ec50ea5 + f8513cd commit 520920f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [0.5.11](https://github.com/anpigon/obsidian-book-search-plugin/compare/0.5.10...0.5.11) (2023-07-15)

### [0.5.10](https://github.com/anpigon/obsidian-book-search-plugin/compare/0.5.9...0.5.10) (2023-04-26)

### [0.5.9](https://github.com/anpigon/obsidian-book-search-plugin/compare/0.5.8...0.5.9) (2023-01-07)
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-book-search-plugin",
"name": "Book Search",
"version": "0.5.10",
"version": "0.5.11",
"minAppVersion": "0.15.0",
"description": "Helps you find books and create notes.",
"author": "anpigon",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-book-search-plugin",
"version": "0.5.10",
"version": "0.5.11",
"description": "This is a plugin to help you create book notes.",
"homepage": "https://anpigon.github.io/obsidian-book-search-plugin/",
"main": "main.js",
Expand Down
36 changes: 22 additions & 14 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MarkdownView, Notice, Plugin } from 'obsidian';
import { MarkdownView, Notice, Plugin, TFile } from 'obsidian';

import { BookSearchModal } from '@views/book_search_modal';
import { BookSuggestModal } from '@views/book_suggest_modal';
Expand Down Expand Up @@ -112,14 +112,6 @@ export default class BookSearchPlugin extends Plugin {
async createNewBookNote(): Promise<void> {
try {
const book = await this.searchBookMetadata();

// open file
const activeLeaf = this.app.workspace.getLeaf();
if (!activeLeaf) {
console.warn('No active leaf');
return;
}

const renderedContents = await this.getRenderedContents(book);

// TODO: If the same file exists, it asks if you want to overwrite it.
Expand All @@ -130,19 +122,35 @@ export default class BookSearchPlugin extends Plugin {

// if use Templater plugin
await useTemplaterPluginInFile(this.app, targetFile);
this.openNewBookNote(targetFile);

} catch (err) {
console.warn(err);
this.showNotice(err);
}
}


async openNewBookNote(targetFile: TFile) {
if (!this.settings.openPageOnCompletion)
return;


// open file
const activeLeaf = this.app.workspace.getLeaf();
if (!activeLeaf) {
console.warn('No active leaf');
return;
}

await activeLeaf.openFile(targetFile, { state: { mode: 'source' } });
activeLeaf.setEphemeralState({ rename: 'all' });

// cursor focus
await new CursorJumper(this.app).jumpToNextCursorLocation();
} catch (err) {
console.warn(err);
this.showNotice(err);
}
}



async openBookSearchModal(query = ''): Promise<Book[]> {
return new Promise((resolve, reject) => {
return new BookSearchModal(this, query, (error, results) => {
Expand Down
15 changes: 15 additions & 0 deletions src/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface BookSearchPluginSettings {
naverClientId: string;
naverClientSecret: string;
localePreference: string;
openPageOnCompletion: boolean;
}

export const DEFAULT_SETTINGS: BookSearchPluginSettings = {
Expand All @@ -41,6 +42,7 @@ export const DEFAULT_SETTINGS: BookSearchPluginSettings = {
naverClientId: '',
naverClientSecret: '',
localePreference: 'default',
openPageOnCompletion: true
};

export class BookSearchSettingTab extends PluginSettingTab {
Expand Down Expand Up @@ -206,6 +208,19 @@ export class BookSearchSettingTab extends PluginSettingTab {
});
});

new Setting(containerEl)
.setName("Open New Book Note")
.setDesc("Enable or disable the automatic opening of the note on creation.")
.addToggle(toggle =>
toggle
.setValue(this.plugin.settings.openPageOnCompletion)
.onChange(async value => {
this.plugin.settings.openPageOnCompletion = value;
await this.plugin.saveSettings();
})
);


// Frontmatter Settings
const formatterSettingsChildren: Setting[] = [];
createFoldingHeader(containerEl, 'Frontmatter Settings', formatterSettingsChildren);
Expand Down

0 comments on commit 520920f

Please sign in to comment.