Skip to content

Commit

Permalink
Merge pull request #16 from rahul-ramadas/fix-context-tracking
Browse files Browse the repository at this point in the history
Quick open files via "right" key doesn't seem to work
  • Loading branch information
jbjornson committed Jul 8, 2014
2 parents b1ffa39 + 0fecad5 commit 5dd2d8d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
File History Changelog
======================

v1.4.7 (2014-07-07)
-------------------

- Fix for issue #16 due to which "right" key shortcut to open file was broken

v1.4.6 (2014-01-23)
-------------------

Expand Down
25 changes: 16 additions & 9 deletions file_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# DONE introduce a settings file to get settings from
# DONE [ST3] use api function (only available in ST3) to get the project name/id (rather than using a hash of the project folders)
# DONE [ST3] preview the file while cycling through the quick panel history entries
# SONE [ST3] support "quick open" from the quick panel (mapped by default to the "right" key)
# DONE [ST3] support "quick open" from the quick panel (mapped by default to the "right" key)
# DONE [ST3] removed unnecessary view settings (and associated code) by listening for the on_pre_close event rather than the on_close event
# DONE added setting for using monospaced font in the quick panel
# DONE fixed ST2 support
Expand Down Expand Up @@ -41,7 +41,7 @@ def __load_settings(self):
"""Load the plugin settings from FileHistory.sublime-settings"""
app_settings = sublime.load_settings(self.SETTINGS_FILE)
settings_exist = app_settings.has('history_file')

self.PRINT_DEBUG = self.__ensure_setting(app_settings, 'debug', True)
self.GLOBAL_MAX_ENTRIES = self.__ensure_setting(app_settings, 'global_max_entries', 100)
self.PROJECT_MAX_ENTRIES = self.__ensure_setting(app_settings, 'project_max_entries', 50)
Expand Down Expand Up @@ -124,9 +124,6 @@ def __save_history(self):
def get_history(self, current_project_only=True):
"""Return the requested history (global or project-specific): closed files followed by opened files"""

# Set a special setting so we can isolate the context for the quick-open command's keymap entry
self.sublime_settings.set('file_history_active', True)

# Make sure the history is loaded
if len(self.history) == 0:
self.__load_history()
Expand Down Expand Up @@ -241,9 +238,6 @@ def __clear_context(self):
self.current_view = None
self.current_history_entry = None

# Remove the special setting (used by the quick-open command)
self.sublime_settings.erase('file_history_active')

def __track_calling_view(self, window):
"""Remember the view that the command was run from (including the group and index positions),
so we can return to the "calling" view if the user cancels the preview
Expand All @@ -258,7 +252,7 @@ def __track_calling_view(self, window):
else:
self.calling_view_index = [0, 0]
self.calling_view_is_empty = True

def __calculate_view_index(self, window, history_entry):
# Get the group of the new view (the currently active group is the default)
group = history_entry['group']
Expand Down Expand Up @@ -299,6 +293,14 @@ def preview_history(self, window, history_entry):
self.__close_preview(window)
self.__remove_view(filepath, self.get_current_project_key(), True)

def on_file_history_open(self):
# Set a special setting so we can isolate the context for the quick-open command's keymap entry
self.sublime_settings.set('file_history_active', True)

def on_file_history_closed(self):
# Remove the special setting that was set when the quick panel was opened
self.sublime_settings.erase('file_history_active')

def quick_open_preview(self, window):
"""Open the file that is currently being previewed"""
if not self.current_history_entry: return
Expand Down Expand Up @@ -380,6 +382,9 @@ def run(self, show_quick_panel=True, current_project_only=True):
filepath = node['filename']
display_list.append([os.path.basename(filepath), os.path.dirname(filepath)])
font_flag = sublime.MONOSPACE_FONT if FileHistory.instance().USE_MONOSPACE else 0

FileHistory.instance().on_file_history_open()

if is_ST2:
self.window.show_quick_panel(display_list, self.open_file, font_flag)
else:
Expand All @@ -396,6 +401,8 @@ def show_preview(self, selected_index):
FileHistory.instance().preview_history(self.window, self.history_list[selected_index])

def open_file(self, selected_index):
FileHistory.instance().on_file_history_closed()

if self.is_valid(selected_index):
FileHistory.instance().open_history(self.window, self.history_list[selected_index])
else:
Expand Down
2 changes: 1 addition & 1 deletion messages.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"install": "messages/install.txt",
"1.4.6": "CHANGELOG.md"
"1.4.7": "CHANGELOG.md"
}

0 comments on commit 5dd2d8d

Please sign in to comment.