Skip to content

Commit 0fecad5

Browse files
committed
Track FileHistory panel open context correctly
Earlier logic for tracking whether the quick panel showing the history was open or not was a bit messy. This changes it to be more explicit by having the FileHistory object expose public routines the command is supposed to call when the context is activated or deactivated.
1 parent b1ffa39 commit 0fecad5

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
File History Changelog
22
======================
33

4+
v1.4.7 (2014-07-07)
5+
-------------------
6+
7+
- Fix for issue #16 due to which "right" key shortcut to open file was broken
8+
49
v1.4.6 (2014-01-23)
510
-------------------
611

file_history.py

+16-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# DONE introduce a settings file to get settings from
44
# DONE [ST3] use api function (only available in ST3) to get the project name/id (rather than using a hash of the project folders)
55
# DONE [ST3] preview the file while cycling through the quick panel history entries
6-
# SONE [ST3] support "quick open" from the quick panel (mapped by default to the "right" key)
6+
# DONE [ST3] support "quick open" from the quick panel (mapped by default to the "right" key)
77
# DONE [ST3] removed unnecessary view settings (and associated code) by listening for the on_pre_close event rather than the on_close event
88
# DONE added setting for using monospaced font in the quick panel
99
# DONE fixed ST2 support
@@ -41,7 +41,7 @@ def __load_settings(self):
4141
"""Load the plugin settings from FileHistory.sublime-settings"""
4242
app_settings = sublime.load_settings(self.SETTINGS_FILE)
4343
settings_exist = app_settings.has('history_file')
44-
44+
4545
self.PRINT_DEBUG = self.__ensure_setting(app_settings, 'debug', True)
4646
self.GLOBAL_MAX_ENTRIES = self.__ensure_setting(app_settings, 'global_max_entries', 100)
4747
self.PROJECT_MAX_ENTRIES = self.__ensure_setting(app_settings, 'project_max_entries', 50)
@@ -124,9 +124,6 @@ def __save_history(self):
124124
def get_history(self, current_project_only=True):
125125
"""Return the requested history (global or project-specific): closed files followed by opened files"""
126126

127-
# Set a special setting so we can isolate the context for the quick-open command's keymap entry
128-
self.sublime_settings.set('file_history_active', True)
129-
130127
# Make sure the history is loaded
131128
if len(self.history) == 0:
132129
self.__load_history()
@@ -241,9 +238,6 @@ def __clear_context(self):
241238
self.current_view = None
242239
self.current_history_entry = None
243240

244-
# Remove the special setting (used by the quick-open command)
245-
self.sublime_settings.erase('file_history_active')
246-
247241
def __track_calling_view(self, window):
248242
"""Remember the view that the command was run from (including the group and index positions),
249243
so we can return to the "calling" view if the user cancels the preview
@@ -258,7 +252,7 @@ def __track_calling_view(self, window):
258252
else:
259253
self.calling_view_index = [0, 0]
260254
self.calling_view_is_empty = True
261-
255+
262256
def __calculate_view_index(self, window, history_entry):
263257
# Get the group of the new view (the currently active group is the default)
264258
group = history_entry['group']
@@ -299,6 +293,14 @@ def preview_history(self, window, history_entry):
299293
self.__close_preview(window)
300294
self.__remove_view(filepath, self.get_current_project_key(), True)
301295

296+
def on_file_history_open(self):
297+
# Set a special setting so we can isolate the context for the quick-open command's keymap entry
298+
self.sublime_settings.set('file_history_active', True)
299+
300+
def on_file_history_closed(self):
301+
# Remove the special setting that was set when the quick panel was opened
302+
self.sublime_settings.erase('file_history_active')
303+
302304
def quick_open_preview(self, window):
303305
"""Open the file that is currently being previewed"""
304306
if not self.current_history_entry: return
@@ -380,6 +382,9 @@ def run(self, show_quick_panel=True, current_project_only=True):
380382
filepath = node['filename']
381383
display_list.append([os.path.basename(filepath), os.path.dirname(filepath)])
382384
font_flag = sublime.MONOSPACE_FONT if FileHistory.instance().USE_MONOSPACE else 0
385+
386+
FileHistory.instance().on_file_history_open()
387+
383388
if is_ST2:
384389
self.window.show_quick_panel(display_list, self.open_file, font_flag)
385390
else:
@@ -396,6 +401,8 @@ def show_preview(self, selected_index):
396401
FileHistory.instance().preview_history(self.window, self.history_list[selected_index])
397402

398403
def open_file(self, selected_index):
404+
FileHistory.instance().on_file_history_closed()
405+
399406
if self.is_valid(selected_index):
400407
FileHistory.instance().open_history(self.window, self.history_list[selected_index])
401408
else:

messages.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"install": "messages/install.txt",
3-
"1.4.6": "CHANGELOG.md"
3+
"1.4.7": "CHANGELOG.md"
44
}

0 commit comments

Comments
 (0)