Skip to content

Commit

Permalink
Remove refresh_all in Windows on settings change. Fixes Issue #15 (#16)
Browse files Browse the repository at this point in the history
* Remove repeated calls to refresh_all in Windows on settings change. Fixes Issue #15

* On Windows update window title on plugin_loaded for top window

* add_on_change for Linux only

* Remove update window title on plugin_loaded in Windows due to freezes
  • Loading branch information
robertcollier4 authored and gwenzek committed Nov 8, 2019
1 parent 665bf6e commit 769c346
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions set_window_title.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,30 @@ def plugin_loaded():
global _READY_
_READY_ = True

# Update all window titles on setting change.
settings = sublime.load_settings("set_window_title.sublime-settings")
setting_keys = [
"unregistered",
"template",
"has_project_true",
"has_project_false",
"is_dirty_true",
"is_dirty_false",
"path_display",
"untitled",
]
for k in setting_keys:
settings.add_on_change(k, refresh_all)

if PLATFORM == "linux":
# Set the title when the plugin is loaded.
# Only enabled on Linux because for some reason it freezes ST on Windows.
# TODO: Find how to enable a similar behavior on Windows.
# Update all window titles on setting change.
settings = sublime.load_settings("set_window_title.sublime-settings")
setting_keys = [
"unregistered",
"template",
"has_project_true",
"has_project_false",
"is_dirty_true",
"is_dirty_false",
"path_display",
"untitled",
]
for k in setting_keys:
settings.add_on_change(k, refresh_all)

# Update all window titles on plugin loaded for Linux.
refresh_all()

# Reported to freeze ST on Windows for some reason to update top or all window titles on loading. TODO: Find how to update window title on plugin loaded for Windows wthout freezing.
# Reference - https://github.com/gwenzek/SublimeSetWindowTitle/pull/16
#elif PLATFORM == "windows":
#SetWindowTitle().run(sublime.active_window().active_view())


def refresh_all():
title_setter = SetWindowTitle()
Expand Down Expand Up @@ -143,7 +146,8 @@ def rename_window_linux(self, window, official_title, new_title, debug=False):
def rename_window_windows(self, new_title):
# PX_WINDOW_CLASS is the ClassName of SublimeText, can be seen via a tool such as Nirsoft WinLister
hwndSublime = ctypes.windll.user32.FindWindowA(b'PX_WINDOW_CLASS', None)
ctypes.windll.user32.SetWindowTextW(hwndSublime, new_title)
if(hwndSublime):
ctypes.windll.user32.SetWindowTextW(hwndSublime, new_title)

def get_project(window):
"""Returns the project name for the given window.
Expand Down

0 comments on commit 769c346

Please sign in to comment.