generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP Add GUI for ignoring scenes (#209)
* Add "Ignore scene" menu item And a separator to isolate the Longform items. * Move add/ignore scene logic to external function * Remove Circular imports * Remove unneeded formatting changes * Rename file to `scene-menu-items` * Enhance Ignore note context menu item * Revert tab replacement * Add newline to end of file
- Loading branch information
1 parent
6875afa
commit f42371c
Showing
3 changed files
with
91 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { drafts, selectedDraft } from "src/model/stores"; | ||
import type { MultipleSceneDraft } from "src/model/types"; | ||
import { get } from "svelte/store"; | ||
|
||
|
||
const getSelectedDraftWithIndex = () => { | ||
const draft = get(selectedDraft) as MultipleSceneDraft; | ||
const index = get(drafts).findIndex( | ||
(d) => d.vaultPath === draft.vaultPath | ||
); | ||
return { index, draft } | ||
} | ||
|
||
export const addScene = (fileName: string) => { | ||
const { index, draft } = getSelectedDraftWithIndex() | ||
if (index >= 0 && draft.format === "scenes") { | ||
drafts.update((d) => { | ||
const targetDraft = d[index] as MultipleSceneDraft; | ||
(d[index] as MultipleSceneDraft).scenes = [ | ||
...targetDraft.scenes, | ||
{ title: fileName, indent: 0 }, | ||
]; | ||
(d[index] as MultipleSceneDraft).unknownFiles = | ||
targetDraft.unknownFiles.filter((f) => f !== fileName); | ||
return d; | ||
}); | ||
} | ||
} | ||
|
||
export const ignoreScene = (fileName: string) => { | ||
const { index, draft } = getSelectedDraftWithIndex() | ||
if (index >= 0 && draft.format === "scenes") { | ||
drafts.update((d) => { | ||
const targetDraft = d[index] as MultipleSceneDraft; | ||
(d[index] as MultipleSceneDraft).scenes = targetDraft.scenes.filter(it => it.title != fileName); | ||
(d[index] as MultipleSceneDraft).ignoredFiles = [ | ||
...targetDraft.ignoredFiles, | ||
fileName, | ||
]; | ||
(d[index] as MultipleSceneDraft).unknownFiles = | ||
targetDraft.unknownFiles.filter((f) => f !== fileName); | ||
return d; | ||
}); | ||
} | ||
} | ||
|
||
export const addAll = () => { | ||
const { index, draft } = getSelectedDraftWithIndex() | ||
if (index >= 0 && draft.format === "scenes") { | ||
drafts.update((d) => { | ||
const targetDraft = d[index] as MultipleSceneDraft; | ||
(d[index] as MultipleSceneDraft).scenes = [ | ||
...targetDraft.scenes, | ||
...targetDraft.unknownFiles.map((f) => ({ title: f, indent: 0 })), | ||
]; | ||
(d[index] as MultipleSceneDraft).unknownFiles = []; | ||
return d; | ||
}); | ||
} | ||
} | ||
|
||
export const ignoreAll = () => { | ||
const { index, draft } = getSelectedDraftWithIndex() | ||
if (index >= 0 && draft.format === "scenes") { | ||
drafts.update((d) => { | ||
const targetDraft = d[index] as MultipleSceneDraft; | ||
(d[index] as MultipleSceneDraft).ignoredFiles = [ | ||
...targetDraft.ignoredFiles, | ||
...targetDraft.unknownFiles, | ||
]; | ||
(d[index] as MultipleSceneDraft).unknownFiles = []; | ||
return d; | ||
}); | ||
} | ||
} |