예제 #1
0
def show_input_panel(
    window: sublime.Window,
    caption: str,
    *,
    initial_text: str = "",
    on_done: "Callback[[str], None]" = None
) -> None:
    window.show_input_panel(
        caption=caption,
        initial_text=initial_text,
        on_done=on_done,
        on_change=None,
        on_cancel=None,
    )
예제 #2
0
def sublime_show_input_panel_async(
        window: sublime.Window, caption: str, initial_text: str,
        on_change: Callable[[str], None]) -> awaitable[Optional[str]]:
    result = main_loop.create_future()

    def on_done(value: str) -> None:
        result.set_result(value)

    def on_cancel() -> None:
        result.set_result(None)

    window.show_input_panel(caption, initial_text, on_done, on_change,
                            on_cancel)
    r = yield from result
    return r
예제 #3
0
파일: input.py 프로젝트: klmp200/sublime_db
    def __init__(self, window: sublime.Window, label: str, text: str,
                 on_change: Callable[[str], None],
                 on_done: Callable[[Optional[str]], None]):
        def on_cancel() -> None:
            self.close()
            on_done(None)

        def on_done_inner(value: str) -> None:
            self.close()
            on_done(value)

        self.window = window
        self.active_panel = window.active_panel()
        window.show_input_panel(label,
                                text,
                                on_done=on_done_inner,
                                on_change=on_change,
                                on_cancel=on_cancel)
예제 #4
0
def show_input_panel(
    window: sublime.Window,
    caption: Optional[str] = None,
    initial_text: Optional[str] = None,
    on_change: Optional[Callable[[str], Any]] = None,
) -> Awaitable[str]:
    """
    See https://www.sublimetext.com/docs/api_reference.html
    """
    future = asyncio.get_running_loop().create_future()
    try:
        window.show_input_panel(
            caption=caption,
            initial_text=initial_text,
            on_done=lambda s: call_soon_threadsafe(lambda: future.set_result(s)),
            on_change=on_change,
            on_cancel=lambda: call_soon_threadsafe(lambda: future.set_exception(asyncio.CancelledError())),
        )
    except Exception as ex:
        future.set_exception(ex)
    return future
예제 #5
0
def sublime_show_input_panel_async(
    window: sublime.Window,
    caption: str,
    initial_text: str,
    on_change: Optional[Callable[[str],
                                 None]] = None) -> awaitable[Optional[str]]:
    result = create_future()
    active_panel = window.active_panel()

    def on_done(value: str) -> None:
        call_soon_threadsafe(result.set_result, value)

    def on_cancel() -> None:
        call_soon_threadsafe(result.set_result, None)

    view = window.show_input_panel(caption, initial_text, on_done, on_change,
                                   on_cancel)
    r = yield from result
    # restore the previous panel
    window.run_command('show_panel', {'panel': '{}'.format(active_panel)})
    return r