Skip to content

Commit

Permalink
feat: add copy filename function
Browse files Browse the repository at this point in the history
  • Loading branch information
lizyChy0329 committed Nov 22, 2024
1 parent ced5429 commit 3bd4fae
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@
"command": "copy-image-size.copyImageBasename",
"title": "Copy Basename"
},
{
"command": "copy-image-size.copyImageFilename",
"title": "Copy Filename"
},
{
"command": "copy-image-size.copyImageExtname",
"title": "Copy Extname"
Expand Down Expand Up @@ -143,9 +147,14 @@
"group": "z_copy@3"
},
{
"command": "copy-image-size.copyImageExtname",
"command": "copy-image-size.copyImageFilename",
"when": "webviewId == '1_pineconeViews' && webviewSection == 'imgItem'",
"group": "z_copy@4"
},
{
"command": "copy-image-size.copyImageExtname",
"when": "webviewId == '1_pineconeViews' && webviewSection == 'imgItem'",
"group": "z_copy@5"
}
]
}
Expand Down
20 changes: 18 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const { activate, deactivate } = defineExtension(() => {
commands.executeCommand('setContext', 'copy-image-size.showPineConeGalleryIcon', true);

const { postMessage, view } = usePineConeWebviewView()
const currentWorkspaceFolder = workspace.getWorkspaceFolder(urix)

const currentWorkspaceFolder = workspace.getWorkspaceFolder(urix)
if (!currentWorkspaceFolder) {
commands.executeCommand('setContext', 'copy-image-size.showPineConeGalleryIcon', false);
window.showErrorMessage('Get Workspace Folder Fail')
Expand Down Expand Up @@ -72,7 +72,7 @@ const { activate, deactivate } = defineExtension(() => {
if (newVal) {
setTimeout(async () => {
vscode2Webview('updateImages', urix, view)
}, 500);
}, 300);

readyToUpdate.value = false
}
Expand Down Expand Up @@ -195,6 +195,22 @@ const { activate, deactivate } = defineExtension(() => {
}
})

// Copy Image Basename
useCommand('copy-image-size.copyImageFilename', async (uri: MaybeUriOrWebviewContext) => {
const { urix } = resolveVscodeOrWebviewUri(uri)
if (!urix) {
return window.showErrorMessage(`urix is undefinded`)
}

const uriExtname = extname(urix.toString())
const filename = basename(urix.toString(), uriExtname)

const [clipboardErr] = await to(Promise.resolve(env.clipboard.writeText(filename)))
if (clipboardErr) {
return logger.error(clipboardErr)
}
})

// Copy Image Extname
useCommand('copy-image-size.copyImageExtname', async (uri: MaybeUriOrWebviewContext) => {
const { urix } = resolveVscodeOrWebviewUri(uri)
Expand Down
2 changes: 1 addition & 1 deletion views/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import List from './components/List.vue'
import SearchBar from './components/SearchBar.vue'
import { imageSize, isLandscape } from './state'
// const { window, workspace } = acquireVsCodeApi()
// const { setState, getState } = acquireVsCodeApi()
const vscodePostData = ref()
Expand Down

0 comments on commit 3bd4fae

Please sign in to comment.