| 1 | import { BaseContextProvider } from ".."; |
| 2 | import { |
| 3 | ContextItem, |
| 4 | ContextProviderDescription, |
| 5 | ContextProviderExtras, |
| 6 | ContextSubmenuItem, |
| 7 | LoadSubmenuItemsArgs, |
| 8 | } from "../.."; |
| 9 | import { clipboardCache } from "../../util/clipboardCache"; |
| 10 | |
| 11 | const MAX_CLIPBOARD_ITEMS = 10; |
| 12 | |
| 13 | class ClipboardContextProvider extends BaseContextProvider { |
| 14 | static description: ContextProviderDescription = { |
| 15 | title: "clipboard", |
| 16 | displayTitle: "Clipboard", |
| 17 | description: "Recent copies", |
| 18 | type: "submenu", |
| 19 | }; |
| 20 | |
| 21 | get deprecationMessage() { |
| 22 | return "The clipboard context provider is deprecated as it is not used. It will be removed in a future version."; |
| 23 | } |
| 24 | |
| 25 | async getContextItems( |
| 26 | query: string, |
| 27 | extras: ContextProviderExtras, |
| 28 | ): Promise<ContextItem[]> { |
| 29 | // Assume the query is a cache id |
| 30 | const id = query.trim(); |
| 31 | const content = clipboardCache.get(id); |
| 32 | |
| 33 | if (content) { |
| 34 | clipboardCache.select(id); |
| 35 | return [ |
| 36 | { |
| 37 | name: "Clipboard item", |
| 38 | description: content.slice(0, 20), |
| 39 | content, |
| 40 | }, |
| 41 | ]; |
| 42 | } |
| 43 | return []; |
| 44 | } |
| 45 | |
| 46 | async loadSubmenuItems( |
| 47 | args: LoadSubmenuItemsArgs, |
| 48 | ): Promise<ContextSubmenuItem[]> { |
| 49 | const recentClipboardItems = clipboardCache.getNItems(MAX_CLIPBOARD_ITEMS); |
| 50 | console.log(recentClipboardItems); |
| 51 | return recentClipboardItems.map((item, index) => { |
| 52 | return { |
| 53 | id: item.id, |
| 54 | title: item.content.slice(0, 20), |
| 55 | description: `#${index + 1}`, |
| 56 | }; |
| 57 | }); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | export default ClipboardContextProvider; |