Skip to content

Commit

Permalink
Add method to access PanelManager buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
jwortmann committed Mar 10, 2024
1 parent c24f4e2 commit 36218f9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
11 changes: 8 additions & 3 deletions plugin/core/panels.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .types import PANEL_FILE_REGEX
from .types import PANEL_LINE_REGEX
from .typing import Optional
from .typing import Iterable, Optional
import sublime


Expand Down Expand Up @@ -38,7 +38,7 @@ class PanelName:
class PanelManager:
def __init__(self, window: sublime.Window) -> None:
self._window = window
self.rename_panel_buttons = None # type: Optional[sublime.PhantomSet]
self._rename_panel_buttons = None # type: Optional[sublime.PhantomSet]

def destroy_output_panels(self) -> None:
for field in filter(lambda a: not a.startswith('__'), PanelName.__dict__.keys()):
Expand All @@ -47,6 +47,7 @@ def destroy_output_panels(self) -> None:
if panel and panel.is_valid():
panel.settings().set("syntax", "Packages/Text/Plain text.tmLanguage")
self._window.destroy_output_panel(panel_name)
self._rename_panel_buttons = None

def toggle_output_panel(self, panel_type: str) -> None:
panel_name = "output.{}".format(panel_type)
Expand Down Expand Up @@ -93,7 +94,7 @@ def _create_panel(self, name: str, result_file_regex: str, result_line_regex: st
if not panel:
return None
if name == PanelName.Rename:
self.rename_panel_buttons = sublime.PhantomSet(panel, "lsp_rename_buttons")
self._rename_panel_buttons = sublime.PhantomSet(panel, "lsp_rename_buttons")
settings = panel.settings()
if result_file_regex:
settings.set("result_file_regex", result_file_regex)
Expand Down Expand Up @@ -124,3 +125,7 @@ def show_diagnostics_panel_async(self) -> None:
def hide_diagnostics_panel_async(self) -> None:
if self.is_panel_open(PanelName.Diagnostics):
self.toggle_output_panel(PanelName.Diagnostics)

def update_rename_panel_buttons(self, phantoms: Iterable[sublime.Phantom]) -> None:
if self._rename_panel_buttons:
self._rename_panel_buttons.update(phantoms)
15 changes: 4 additions & 11 deletions plugin/rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,6 @@ def _render_rename_panel(
selection.add(sublime.Region(0, panel.size()))
panel.run_command('toggle_inline_diff')
selection.clear()
buttons = pm.rename_panel_buttons
if not buttons:
return
buttons_position = sublime.Region(len(to_render[0]) - 1)
BUTTONS_HTML = BUTTONS_TEMPLATE.format(
apply=sublime.command_url('chain', {
'commands': [
Expand All @@ -317,8 +313,8 @@ def _render_rename_panel(
}),
discard=DISCARD_COMMAND_URL
)
buttons.update([
sublime.Phantom(buttons_position, BUTTONS_HTML, sublime.LAYOUT_BLOCK)
pm.update_rename_panel_buttons([
sublime.Phantom(sublime.Region(len(to_render[0]) - 1), BUTTONS_HTML, sublime.LAYOUT_BLOCK)
])


Expand Down Expand Up @@ -350,8 +346,5 @@ def run(self) -> None:
if not wm:
return
pm = wm.panel_manager
if not pm:
return
buttons = pm.rename_panel_buttons
if buttons:
buttons.update([])
if pm:
pm.update_rename_panel_buttons([])

0 comments on commit 36218f9

Please sign in to comment.