Skip to content

Commit

Permalink
alpha another window support added
Browse files Browse the repository at this point in the history
  • Loading branch information
qiray committed May 17, 2018
1 parent 2b9c927 commit 1fbd85e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 26 deletions.
54 changes: 32 additions & 22 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from listview import List

def view_name(view):
"""Function to get view name"""
result = UNTITLED_NAME
filename = view.file_name()
name = view.name()
Expand Down Expand Up @@ -55,12 +56,12 @@ def generate_list(view_list):
result.add_filename(name, view.id(), is_file=False if view.file_name() is None else True)
return result

def draw_view(window, edit, view_object, focus=False):
def draw_view(window, edit, view_object, focus=False, other_window=False):
plugin_settings = sublime.load_settings('opened_files.sublime-settings')
group_position = plugin_settings.get('group_position')
if group_position != 'left' and group_position != 'right':
group_position = 'left'
view = show(window, 'Opened Files', view_id=OpenedFilesCommand.OPENED_FILES_VIEW, other_group=group_position,focus=focus)
view = show(window, 'Opened Files', other_window=other_window, view_id=OpenedFilesCommand.OPENED_FILES_VIEW, other_group=group_position,focus=focus)
if not view:
OpenedFilesCommand.OPENED_FILES_VIEW = None
return
Expand All @@ -76,28 +77,31 @@ class OpenedFilesCommand(sublime_plugin.TextCommand): #view.run_command('opened_
tree = Tree()
files_list = List()

def run(self, edit, focus=False):
def run(self, edit, focus=False, other_window=False):
window = self.view.window()
view_list = window.views()

temp = []
for view in view_list:
settings = view.settings()
if settings.get("opened_files_type"):
OpenedFilesCommand.OPENED_FILES_VIEW = view.id()
elif settings.get('dired_path'):
pass
else:
temp.append(view)
view_list = temp
#if we already have OpenedFiles window we shouldn't create anymore
if OpenedFilesListener.current_window is not None and \
OpenedFilesListener.current_window != window:
return
windows = sublime.windows()
view_list = []
for win in windows:
for view in win.views():
settings = view.settings()
if settings.get("opened_files_type"):
OpenedFilesCommand.OPENED_FILES_VIEW = view.id()
elif settings.get('dired_path'):
pass
else:
view_list.append(view)

plugin_settings = sublime.load_settings('opened_files.sublime-settings')
if plugin_settings.get('tree_view'): #treeview
OpenedFilesCommand.tree = generate_tree(view_list, OpenedFilesCommand.tree)
draw_view(window, edit, OpenedFilesCommand.tree, focus)
draw_view(window, edit, OpenedFilesCommand.tree, focus, other_window)
else: #listview
OpenedFilesCommand.files_list = generate_list(view_list)
draw_view(window, edit, OpenedFilesCommand.files_list, focus)
draw_view(window, edit, OpenedFilesCommand.files_list, focus, other_window)

class OpenedFilesActCommand(sublime_plugin.TextCommand):
def run(self, edit, act='default'):
Expand All @@ -106,7 +110,7 @@ def run(self, edit, act='default'):

def open_file(self, edit, selection, act):
window = self.view.window()
(row, ) = self.view.rowcol(selection.begin())
(row, col) = self.view.rowcol(selection.begin())

plugin_settings = sublime.load_settings('opened_files.sublime-settings')
if not plugin_settings.get('tree_view'): #list view
Expand Down Expand Up @@ -143,7 +147,7 @@ def open_file(self, edit, selection, act):
class OpenedFilesOpenExternalCommand(sublime_plugin.TextCommand):
def run(self, edit):
selection = self.view.sel()[0]
(row, ) = self.view.rowcol(selection.begin())
(row, col) = self.view.rowcol(selection.begin())
action = OpenedFilesCommand.tree.get_action(row)
if action is None:
return
Expand Down Expand Up @@ -181,7 +185,7 @@ def run_(self, args):
# Event listners

def get_opened_files_view():
windows = sublime.windows()#[0].views()
windows = sublime.windows()
for win in windows:
views = win.views()
if OpenedFilesCommand.OPENED_FILES_VIEW is not None:
Expand All @@ -192,10 +196,10 @@ def get_opened_files_view():
return view
return None

def update_opened_files_view():
def update_opened_files_view(other_window=False):
view = get_opened_files_view()
if view:
view.run_command('opened_files')
view.run_command('opened_files', {"other_window": other_window})

def is_transient_view(window, view): # from https://github.com/FichteFoll/FileHistory (MIT license)
if not ST3:
Expand Down Expand Up @@ -227,12 +231,14 @@ def on_activated(self, view): #save last opened documents or dired view
def on_close(self, view):
w = sublime.active_window()
if w != OpenedFilesListener.current_window or is_transient_view(w, view) and not view.id() in OpenedFilesListener.active_list:
update_opened_files_view(True)
return
if view.id() in OpenedFilesListener.active_list:
OpenedFilesListener.active_list[view.id()] = False
if not 'opened_files' in view.scope_name(0):
update_opened_files_view()
return
OpenedFilesListener.current_window = None #reset current window
# check if closed view was a single one in group
if ST3:
single = not w.views_in_group(0) or not w.views_in_group(1)
Expand All @@ -247,6 +253,7 @@ def on_new(self, view):
opened_view = get_opened_files_view()
w = sublime.active_window()
if w != OpenedFilesListener.current_window or not opened_view or is_transient_view(w, view):
update_opened_files_view(True)
return
active_view = w.active_view()
num_groups = w.num_groups()
Expand All @@ -262,18 +269,21 @@ def on_new(self, view):
def on_load(self, view):
w = sublime.active_window()
if w != OpenedFilesListener.current_window:
update_opened_files_view(True)
return
self.on_new(view)

def on_clone(self, view):
w = sublime.active_window()
if w != OpenedFilesListener.current_window:
update_opened_files_view(True)
return
self.on_new(view)

def on_post_save_async(self, view):
w = sublime.active_window()
if w != OpenedFilesListener.current_window:
update_opened_files_view(True)
return
self.on_new(view)

Expand Down
9 changes: 5 additions & 4 deletions show.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def set_view(view_id, window):
return view


def show(window, path, view_id=None, ignore_existing=False, single_pane=False, other_group=False, focus=False):
def show(window, path, view_id=None, other_window=False, single_pane=False, other_group=False, focus=False):
"""
Determines the correct view to use, creating one if necessary, and prepares it.
"""
Expand Down Expand Up @@ -113,8 +113,9 @@ def show(window, path, view_id=None, ignore_existing=False, single_pane=False, o
view.settings().set('opened_files_type', True)

# forcibly shoot on_activated, because when view was created it didnot have any settings
window.show_quick_panel(['a', 'b'], None)
window.run_command('hide_overlay')
if view_id is None or focus:
if not other_window:
window.show_quick_panel(['a', 'b'], None)
window.run_command('hide_overlay')
if not other_window and (view_id is None or focus):
window.focus_view(view)
return view

0 comments on commit 1fbd85e

Please sign in to comment.