gpt4 book ai didi

sublimetext3 - 将焦点集中在其他组以打开文件后,如何将焦点恢复到快速面板?

转载 作者:行者123 更新时间:2023-12-03 13:35:05 26 4
gpt4 key购买 nike

情况是这样的:我正在编写一个需要执行以下操作的插件:

  • 打开快速面板
  • 悬停在第一项上时,将其他组放在
  • 在该组中打开
  • 将焦点恢复为快速面板输入,以便我可以移至列表中的下一项,依此类推...

  • 我确实解决了1-3,但第4个给我带来了麻烦。有办法吗?

    最佳答案

    您需要获取与快速面板关联的 View 。方法show_quick_panel不会返回 View ,但是您可以使用带有EventListener插件的on_activated方法来获取 View 。

    当您聚焦任何 View (选项卡,控制台,quick_panel ...)时,将调用此方法(on_activated)。因此,此插件将执行的操作是捕获与快速面板关联的 View 。

    用于获取 View 的示例插件:

    import sublime, sublime_plugin

    class Example(sublime_plugin.EventListener):
    def on_activated(self, view):
    """This method is called whenever a view (tab, quick panel, etc.) gains focus, but we only want to get the quick panel view, so we use a flag"""
    if hasattr(sublime, 'capturingQuickPanelView') and sublime.capturingQuickPanelView == True:
    sublime.capturingQuickPanelView = False
    """View saved as an attribute of the global variable sublime so it can be accesed from your plugin or anywhere"""
    sublime.quickPanelView = view
    print(sublime.quickPanelView)

    现在,在您的插件中,您需要告诉eventListener何时actived View 与快速面板相对应才能捕获它。您的插件中需要的示例:
    import sublime, sublime_plugin

    class Sample(sublime_plugin.WindowCommand):
    def restoreQuickPanelFocus(self):
    """Restore focus to quick panel is as easy as focus in the quick panel view, that the eventListener has previously captured and saved"""
    self.window.focus_view(sublime.quickPanelView)

    def on_highlighted(self, index):
    """Open image[index] in group 1"""
    self.window.focus_group(1)
    self.window.open_file(self.items[index])
    """Wait for image to open and restore focus to quick panel"""
    sublime.set_timeout(self.restoreQuickPanelFocus, 100)

    def run(self):
    print('runando')
    """Divide layout (as an example) """
    self.window.set_layout({
    "cols": [0.0, 0.4, 1.0],
    "rows": [0.0, 0.6, 1.0],
    "cells": [[0, 0, 2, 1], [0, 1, 1, 2], [1, 1, 2, 2]]
    })

    """Items=> images paths"""
    self.items = ('C:/images/img1.jpg','C:/images/img2.jpg','C:/images/img3.jpg','C:/images/img4.jpg','C:/images/img5.jpg')

    """Now we are going to show the quick panel, so we set the capturing flag to true as the next activated view will correspond to quick panel"""
    sublime.capturingQuickPanelView = True
    self.window.show_quick_panel(self.items, None, sublime.KEEP_OPEN_ON_FOCUS_LOST , 0, self.on_highlighted)

    结果:

    Result

    关于sublimetext3 - 将焦点集中在其他组以打开文件后,如何将焦点恢复到快速面板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30626639/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com