Skip to content

Commit

Permalink
WIP Add GUI for ignoring scenes (#209)
Browse files Browse the repository at this point in the history
* 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
b-camphart authored Dec 11, 2023
1 parent 6875afa commit f42371c
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 41 deletions.
7 changes: 7 additions & 0 deletions src/view/explorer/ExplorerPane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { drafts, pluginSettings, selectedDraft } from "src/model/stores";
import { insertScene } from "src/model/draft-utils";
import NewDraftModal from "src/view/project-lifecycle/new-draft-modal";
import { UndoManager } from "../undo/undo-manager";
import { ignoreScene } from "./scene-menu-items";

export const VIEW_TYPE_LONGFORM_EXPLORER = "VIEW_TYPE_LONGFORM_EXPLORER";

Expand Down Expand Up @@ -174,6 +175,7 @@ export class ExplorerPane extends ItemView {
return;
}
const menu = new Menu();
menu.addSeparator()
menu.addItem((item) => {
item.setTitle("Rename");
item.setIcon("pencil");
Expand Down Expand Up @@ -203,6 +205,11 @@ export class ExplorerPane extends ItemView {
item.setIcon("document");
item.onClick(() => addRelativeScene("after", file));
});
menu.addItem((item) => {
item.setTitle("Ignore note in Longform");
item.setIcon("minus-circle");
item.onClick(() => ignoreScene(file.name.endsWith('.md') ? file.name.slice(0, -3) : file.name));
})
// Triggering this event lets other apps insert menu items
// including Obsidian, giving us lots of stuff for free.
this.app.workspace.trigger("file-menu", menu, file, "longform");
Expand Down
50 changes: 9 additions & 41 deletions src/view/explorer/SceneList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import { cloneDeep } from "lodash";
import { scenePath } from "src/model/scene-navigation";
import { selectElementContents } from "../utils";
import { addAll, addScene, ignoreAll, ignoreScene } from "./scene-menu-items";
let currentDraftIndex: number;
$: {
Expand Down Expand Up @@ -230,51 +231,18 @@
}
function doWithUnknown(fileName: string, action: "add" | "ignore") {
const currentDraftIndex = $drafts.findIndex(
(d) => d.vaultPath === $selectedDraft.vaultPath
);
if (currentDraftIndex >= 0 && $selectedDraft.format === "scenes") {
drafts.update((d) => {
const targetDraft = d[currentDraftIndex] as MultipleSceneDraft;
if (action === "add") {
(d[currentDraftIndex] as MultipleSceneDraft).scenes = [
...targetDraft.scenes,
{ title: fileName, indent: 0 },
];
} else {
(d[currentDraftIndex] as MultipleSceneDraft).ignoredFiles = [
...targetDraft.ignoredFiles,
fileName,
];
}
(d[currentDraftIndex] as MultipleSceneDraft).unknownFiles =
targetDraft.unknownFiles.filter((f) => f !== fileName);
return d;
});
if (action === "add") {
addScene(fileName);
} else {
ignoreScene(fileName);
}
}
function doWithAll(action: "add" | "ignore") {
const currentDraftIndex = $drafts.findIndex(
(d) => d.vaultPath === $selectedDraft.vaultPath
);
if (currentDraftIndex >= 0 && $selectedDraft.format === "scenes") {
drafts.update((d) => {
const targetDraft = d[currentDraftIndex] as MultipleSceneDraft;
if (action === "add") {
(d[currentDraftIndex] as MultipleSceneDraft).scenes = [
...targetDraft.scenes,
...targetDraft.unknownFiles.map((f) => ({ title: f, indent: 0 })),
];
} else {
(d[currentDraftIndex] as MultipleSceneDraft).ignoredFiles = [
...targetDraft.ignoredFiles,
...targetDraft.unknownFiles,
];
}
(d[currentDraftIndex] as MultipleSceneDraft).unknownFiles = [];
return d;
});
if (action === "add") {
addAll();
} else {
ignoreAll();
}
}
Expand Down
75 changes: 75 additions & 0 deletions src/view/explorer/scene-menu-items.ts
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;
});
}
}

0 comments on commit f42371c

Please sign in to comment.