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

Copy Paste Data #2928

Merged
merged 17 commits into from
Dec 20, 2023
Merged
1 change: 1 addition & 0 deletions apps/zui/src/domain/loads/handlers/preview-load-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Pools from "src/js/state/Pools"
import {quickLoadFiles} from "./quick-load-files"

export const previewLoadFiles = createHandler(
"loads.previewLoadFiles",
async (
{dispatch, invoke, select},
opts: {files: string[]; poolId?: string}
Expand Down
2 changes: 2 additions & 0 deletions apps/zui/src/domain/loads/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ export type LoadsOperations = {
"loads.getFileTypes": typeof ops.getFileTypes
"loads.abortPreview": typeof ops.abortPreview
"loads.abort": typeof ops.abort
"loads.paste": typeof ops.paste
}

export type LoadsHandlers = {
"loads.chooseFiles": typeof handlers.chooseFiles
"loads.previewLoadFiles": typeof handlers.previewLoadFiles
}
1 change: 1 addition & 0 deletions apps/zui/src/domain/loads/operations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from "./get-file-types"
export * from "./preview"
export * from "./create"
export * from "./abort"
export * from "./paste"
14 changes: 14 additions & 0 deletions apps/zui/src/domain/loads/operations/paste.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {clipboard} from "electron"
import {createOperation} from "src/core/operations"
import path from "path"
import os from "os"
import {writeFileSync} from "fs-extra"
import {sendToFocusedWindow} from "src/core/ipc"

export const paste = createOperation("loads.paste", () => {
const data = clipboard.readText()
const file = path.join(os.tmpdir(), "clipboard.txt")
writeFileSync(file, data)
sendToFocusedWindow("loads.previewLoadFiles", {files: [file]})
return path
})
19 changes: 18 additions & 1 deletion apps/zui/src/electron/windows/search/app-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {showReleaseNotesOp} from "../../ops/show-release-notes-op"
import {SearchWindow} from "./search-window"
import {sendToFocusedWindow} from "src/core/ipc"
import {open as openUpdateWindow} from "src/domain/updates/operations"
import {paste} from "src/domain/loads/operations"

export const defaultAppMenuState = () => ({
showRightPane: true,
Expand Down Expand Up @@ -85,6 +86,12 @@ export function compileTemplate(
accelerator: "CmdOrCtrl+O",
}

const pasteData: MenuItemConstructorOptions = {
label: "Paste Data...",
click: paste,
accelerator: "CmdOrCtrl+Shift+V",
}

const appNameMenu: MenuItemConstructorOptions = {
label: app.getName(),
submenu: [
Expand All @@ -104,12 +111,22 @@ export function compileTemplate(

function fileSubmenu(): MenuItemConstructorOptions[] {
if (mac) {
return [newWindow, __, openFile, exportResults, __, closeTab, closeWindow]
return [
newWindow,
__,
openFile,
pasteData,
exportResults,
__,
closeTab,
closeWindow,
]
} else {
return [
newWindow,
__,
openFile,
pasteData,
exportResults,
__,
settings,
Expand Down
Loading