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

Right click on sidebar gives option to create new directory / note #250

Closed
wants to merge 16 commits into from
Closed
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
53 changes: 52 additions & 1 deletion electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import {
} from "./Store/storeHandlers";
import WindowsManager from "./windowManager";

const fs = require('fs').promises;

const store = new Store<StoreSchema>();
// store.clear(); // clear store for testing
const windowsManager = new WindowsManager();
Expand Down Expand Up @@ -167,8 +169,31 @@ ipcMain.handle("index-files-in-directory", async (event) => {
}
});

ipcMain.handle("show-context-menu-file-item", (event, file) => {
ipcMain.handle("show-context-menu-file-item", async (event, file) => {
const menu = new Menu();
const stats = await fs.stat(file.path);
const isDirectory = stats.isDirectory();

if (isDirectory) {
menu.append(
new MenuItem({
label: "New Note",
click: () => {
event.sender.send("add-new-note-listener", file.relativePath);
},
})
);

menu.append(
new MenuItem({
label: "New Directory",
click: () => {
event.sender.send("add-new-directory-listener", file.path);
},
})
);
}

menu.append(
new MenuItem({
label: "Delete",
Expand Down Expand Up @@ -227,6 +252,32 @@ ipcMain.handle("show-context-menu-file-item", (event, file) => {
}
});

ipcMain.handle("show-context-menu-item", (event) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have the handler for show-context-menu-file-item. Why not include these new context menu items there?

(For my personal vault, I have the fileexplorer sidebar so i could not actually get it to show these new context menu items you've added. Only by opening a vault which doesn't have lots of files would it actually leave space in the file explorer sidebar to hit these context menu items)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this one is specifically for right clicking on the file explorer sidebar (if a file does not exist there) that creates a menu to create a new note or directory. The current show-context-menu-file-item has options like delete, rename, and create a flashcard set that would not be appropriate.

This is just something I like to have for note apps, but I understand if other people do not think it's necessary!

const menu = new Menu();

menu.append(
new MenuItem({
label: "New Note",
click: () => {
event.sender.send("add-new-note-listener");
},
})
);

menu.append(
new MenuItem({
label: "New Directory",
click: () => {
event.sender.send("add-new-directory-listener");
},
})
);

const browserWindow = BrowserWindow.fromWebContents(event.sender);
if (browserWindow)
menu.popup({ window: browserWindow })
});

ipcMain.handle("show-chat-menu-item", (event, chatID) => {
const menu = new Menu();

Expand Down
17 changes: 13 additions & 4 deletions electron/preload/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { IpcRendererEvent, contextBridge, ipcRenderer } from "electron";
import { PromptWithRagResults } from "electron/main/database/dbSessionHandlers";
import { BasePromptRequirements } from "electron/main/database/dbSessionHandlerTypes";
import { DBEntry, DBQueryResult } from "electron/main/database/Schema";
import {
AugmentPromptWithFileProps,
FileInfoNode,
Expand All @@ -15,9 +12,12 @@ import {
EmbeddingModelWithLocalPath,
EmbeddingModelWithRepo,
HardwareConfig,
LLMGenerationParameters,
LLMConfig,
LLMGenerationParameters,
} from "electron/main/Store/storeConfig";
import { DBEntry, DBQueryResult } from "electron/main/database/Schema";
import { BasePromptRequirements } from "electron/main/database/dbSessionHandlerTypes";
import { PromptWithRagResults } from "electron/main/database/dbSessionHandlers";

import { ChatHistory } from "@/components/Chat/Chat";
import { ChatHistoryMetadata } from "@/components/Chat/hooks/use-chat-history";
Expand All @@ -39,6 +39,9 @@ declare global {
contextMenu: {
showFileItemContextMenu: (filePath: FileInfoNode) => void;
};
contextFileMenu: {
showMenuItemContext: () => void;
}
contextChatMenu: {
showChatItemContext: (chatRow: ChatHistoryMetadata) => void;
};
Expand Down Expand Up @@ -328,6 +331,12 @@ contextBridge.exposeInMainWorld("contextMenu", {
},
});

contextBridge.exposeInMainWorld("contextFileMenu", {
showMenuItemContext: () => {
ipcRenderer.invoke("show-context-menu-item");
},
});

contextBridge.exposeInMainWorld("contextChatMenu", {
showChatItemContext: (chatRow: ChatHistoryMetadata) => {
ipcRenderer.invoke("show-chat-menu-item", chatRow.id);
Expand Down
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@tiptap/extension-link": "^2.2.4",
"@tiptap/extension-task-item": "^2.2.4",
"@tiptap/extension-task-list": "^2.2.4",
"@tiptap/extension-text-style": "^2.4.0",
"@tiptap/pm": "^2.2.4",
"@tiptap/react": "^2.2.4",
"@tiptap/starter-kit": "^2.2.4",
Expand All @@ -60,6 +61,7 @@
"ollama": "^0.4.9",
"openai": "^4.20.0",
"posthog-js": "^1.130.2",
"prosemirror-utils": "^1.2.2",
"react-card-flip": "^1.2.2",
"react-icons": "^4.12.0",
"react-markdown": "^9.0.1",
Expand Down
Loading