Skip to content

Commit e294eb1

Browse files
committed
Fix command settings property
The settings attribute may be initialized upon first use to ensure the plugin API to be ready, when calling load_settings()
1 parent 4fc25a5 commit e294eb1

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

commands/create_from_selection.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ class FmCreateFileFromSelectionCommand(sublime_plugin.TextCommand):
3131
MATCH_JS_REQUIRE = re_comp(r"require\(\s*$")
3232
MATCH_RUBY_REQUIRE = re_comp(r"require_relative\s*\(?\s*$")
3333

34+
@property
35+
def settings(cls):
36+
try:
37+
return cls.settings_
38+
except AttributeError:
39+
cls.settings_ = sublime.load_settings("FileManager.sublime-settings")
40+
return cls.settings_
41+
3442
def run(self, edit, event):
3543
base_path, input_path = self.get_path(event)
3644
abspath = computer_friendly(os.path.join(base_path, input_path))
@@ -139,7 +147,7 @@ def is_visible(self, event=None):
139147
if event is None:
140148
return False
141149
return (
142-
self.settings.get("show_create_from_selection_command")
150+
self.settings.get("show_create_from_selection_command") is True
143151
and self.view.file_name() is not None
144152
and self.get_path(event) is not None
145153
)

commands/fmcommand.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@
55

66
class FmWindowCommand(sublime_plugin.WindowCommand):
77

8-
settings = sublime.load_settings("FileManager.sublime-settings")
8+
@property
9+
def settings(cls):
10+
try:
11+
return cls.settings_
12+
except AttributeError:
13+
cls.settings_ = sublime.load_settings("FileManager.sublime-settings")
14+
return cls.settings_
915

1016
def is_visible(self, *args, **kwargs):
11-
show = self.settings.get(
12-
"show_{}_command".format(self.name().replace("fm_", ""))
13-
)
17+
name = "show_{}_command".format(self.name().replace("fm_", ""))
18+
show = self.settings.get(name)
1419
if show is None:
1520
# this should never happen, this is an error
1621
# we could nag the user to get him to report that issue,

0 commit comments

Comments
 (0)