Uninote
Uninote
用户根目录
brdr
common
programming
docs
tests
后端试题
问题讨论

sel form/quick cmd form 迁移

  • codex://threads/01a11a85-3e16-7ef0-8274-bab949948e9a

  • codex://threads/01a11e76-9515-7102-b37b-5f6cc36c9615

  • Quick Cmd Form

  • 禁用热键排除自己

  • selform只会弹出界面并置顶,但并不会抢夺焦点,这样还能够复制目标窗口的内容.

  • 用的是 hook,不会被输入法影响

  • vv 命令无效果

  • 所有粘贴命令,粘贴之后都要加一个换行符

  • code snippet 选项支持

  • 获取不到路径时不要报错,路径位置留空即可

  • 现在获取不了焦点了,选择粘贴目标时可以鼠标点击一下就切换下一个目标。然后把 F1 F2 的切换快捷键提示加到对应的地方。

  • 右上角关闭等三个按钮不能屏蔽

  • 改为任务完成后再关闭界面,下面加个状态栏,显式当前的操作进度

  • code snippet paste 选项也要迁移,与现有的 code snippet 功能结合

迁移以下命令:X:\project\Visual Studio Projects\FindHelper\FindHelper\SelForm.cs

    case "h":// toggle hot key

    case "s":// 改为常规全文搜索

    case "n"://copy & sarch as node

    case "z"://自动粘贴,无分隔符

    case "vv"://仅复制文本

    case "da"://自动粘贴,有分隔符
    case "o1"://粘贴为1级大纲
    case "o2"://粘贴为2级大纲
    case "o3"://粘贴为3级大纲

    case "cc":// clear console
    case "cm":// 复制文本作为 cwd, run cmd.exe

    case "q1":// compare, copy & save as cmp1; if file exists, use the file as cmp1
    case "qq":// show compare
    case "q2":// compare, copy & save as cmp2; if file exists, use the file as cmp2
    case "q3":// compare, copy & save as cmp2; if file exists, use the file as cmp2; show compare directly

codes

  ipcMain.handle('quick-cmd-form:execute', async (event, command, temporary) => {
    if (!authorized(event)) throw new Error('此窗口无权执行 Quick Cmd Form 命令');
    if (busy) throw new Error('上一条 Quick Cmd Form 命令尚未完成');
    try {
      const result = await execute(command, temporary);
      reportProgress(`${command}:已完成`, false);
      hide();
      return result;
    }
    catch (error) {
      reportProgress(`${command}:执行失败`, false);
      // Restore the utility on failure without recapturing the source window.
      reveal();
      throw error;
    }
  });
// Register application actions once; local widget navigation remains with its widget.
/** Capture only while the command form is visible, before Windows IME processing.
 * Reuse the same Koffi/message-loop pattern as the existing global mouse hook. */
function createQuickCmdInput({ koffi = null, platform = process.platform } = {}) {
  let native;
  return {
    start(onKey) {
      if (platform !== 'win32') return () => {};
      const ffi = koffi || require('koffi');
      if (!native) {
        const user32 = ffi.load('user32.dll');
        const proc = ffi.proto('intptr_t __stdcall MynoteQuickCmdHook(int code, uintptr_t message, intptr_t data)');
        const data = ffi.struct({ vkCode: 'uint32_t', scanCode: 'uint32_t', flags: 'uint32_t',
          time: 'uint32_t', extra: 'uintptr_t' });
        native = { proc, data,
          install: user32.func('__stdcall', 'SetWindowsHookExW', 'void *', ['int', ffi.pointer(proc), 'void *', 'uint32_t']),
          remove: user32.func('bool __stdcall UnhookWindowsHookEx(void *hook)'),
          next: user32.func('intptr_t __stdcall CallNextHookEx(void *hook, int code, uintptr_t message, intptr_t data)') };
      }
//.,, 监听,组装命令
  function startCapture() {
    if (platform === 'win32' && !stopInput) stopInput = input.start((key) => window?.webContents.send('quick-cmd-form:key', key));
  }
contextBridge.exposeInMainWorld('quickCmdFormAPI', {
  execute: (command, temporary) => ipcRenderer.invoke('quick-cmd-form:execute', command, temporary),
  hide: () => ipcRenderer.invoke('quick-cmd-form:hide'),
  setSnippetMode: (enabled) => ipcRenderer.invoke('quick-cmd-form:snippet-mode', enabled),
  onReset: (callback) => ipcRenderer.on('quick-cmd-form:reset', (_event, options) => callback(options)),
  onProgress: (callback) => ipcRenderer.on('quick-cmd-form:progress', (_event, progress) => callback(progress)),
  onKey: (callback) => ipcRenderer.on('quick-cmd-form:key', (_event, key) => callback(key))
});
//.,, 区分窗口的复制路径
        if (key === 'path') {
          const buffer = Buffer.alloc(512);
          api.windowClass(previousWindow, buffer, 256);
          const name = buffer.toString('utf16le').replace(/\0.*$/s, '');
          // These are the original IDE copy-path shortcuts. Unknown applications
          // require an explicit path rather than silently recording a wrong one.
          if (name === 'wndclass_desked_gsk' || name === 'Notepad++' || name.startsWith('HwndWrapper[DefaultDomain')) code = 0x46;
          else if (['Chrome_WidgetWin_1', 'SunAwtFrame'].includes(name)) code = 0x43;
          else throw new Error('无法自动获取此应用的路径,请从支持复制路径快捷键的 IDE 采集');
          modifiers = [0x12, 0x10]; // Alt+Shift+F / Alt+Shift+C
        }

misc

snippet-form

点赞(0) 阅读(6) 举报
目录
标题