Skip to content

Commit

Permalink
comments + refactoring started
Browse files Browse the repository at this point in the history
  • Loading branch information
qiray committed May 17, 2018
1 parent dea5846 commit 2b9c927
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
7 changes: 4 additions & 3 deletions common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
else:
SYNTAX_EXTENSION = '.hidden-tmLanguage'

debug_level = 1
untitled_name = 'untitled' #const
DEBUG_LEVEL = 1
UNTITLED_NAME = 'untitled' #const

def debug(level, *args):
if level <= debug_level:
"""Log debug info according to debug level"""
if level <= DEBUG_LEVEL:
print('[DEBUG]', level, args)
11 changes: 9 additions & 2 deletions listview.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,26 @@
ST3 = int(sublime.version()) >= 3000

class Element(object):

"""This is an object representing view storing in listview"""
def __init__(self, name, node_id):
self.node_id = node_id
self.name = name
self.stringnum = 0

def get_name(self):
"""Return view name"""
return '≡ '+ self.name

class List(object):

"""Object for storing and showing views in listview mode"""
def __init__(self):
self.views = {}

def add_filename(self, filename, view_id, is_file):
"""
Function to add view into the list
is_file param is used to differ opened files from nonfile views
"""
arr = filename.split(os.sep)
name = arr[-1]
if not is_file:
Expand All @@ -31,6 +36,7 @@ def add_filename(self, filename, view_id, is_file):
self.views[name] = Element(name, view_id)

def __str__(self):
"""Function to draw listview"""
result = ''
templist = sorted(self.views)
stringnum = 1
Expand All @@ -41,6 +47,7 @@ def __str__(self):
return result

def get_view_id(self, stringnum):
"""Get view id by string number"""
for elm in self.views:
if self.views[elm].stringnum == stringnum:
return self.views[elm].node_id
Expand Down
10 changes: 5 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
#TODO: add comments

if ST3:
from .common import untitled_name, debug, SYNTAX_EXTENSION
from .common import UNTITLED_NAME, debug, SYNTAX_EXTENSION
from .show import show, first
from .treeview import Tree
from .listview import List
else: # ST2 imports
from common import untitled_name, debug, SYNTAX_EXTENSION
from common import UNTITLED_NAME, debug, SYNTAX_EXTENSION
from show import show, first
from treeview import Tree
from listview import List

def view_name(view):
result = untitled_name
result = UNTITLED_NAME
filename = view.file_name()
name = view.name()
if filename is not None and filename != '':
Expand Down Expand Up @@ -106,7 +106,7 @@ def run(self, edit, act='default'):

def open_file(self, edit, selection, act):
window = self.view.window()
(row, col) = self.view.rowcol(selection.begin())
(row, ) = 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 +143,7 @@ def open_file(self, edit, selection, act):
class OpenedFilesOpenExternalCommand(sublime_plugin.TextCommand):
def run(self, edit):
selection = self.view.sel()[0]
(row, col) = self.view.rowcol(selection.begin())
(row, ) = self.view.rowcol(selection.begin())
action = OpenedFilesCommand.tree.get_action(row)
if action is None:
return
Expand Down
14 changes: 6 additions & 8 deletions show.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ def first(seq, pred):
return next((item for item in seq if pred(item)), None)

def set_proper_scheme(view):
'''set color scheme'''
settings = sublime.load_settings('opened_files.sublime-settings')
if view.settings().get('color_scheme') == settings.get('color_scheme'):
return
view.settings().set('color_scheme', settings.get('color_scheme'))

def calc_width(view):
return 0.2 #default value

def get_group(groups, nag):
'''
groups amount of groups in window
Expand All @@ -42,12 +40,13 @@ def get_group(groups, nag):
return group

def set_active_group(window, view, other_group, view_exist):
"""Function from SublimeFileBrowser with some modifications"""
nag = window.active_group()
if other_group:
group = 0 if other_group == 'left' else 1
groups = window.num_groups()
if groups == 1:
width = calc_width(view)
width = 0.2 #default value
cols = [0.0, width, 1.0] if other_group == 'left' else [0.0, 1 - width, 1.0]
window.set_layout({"cols": cols, "rows": [0.0, 1.0], "cells": [[0, 0, 1, 1], [1, 0, 2, 1]]})
elif view:
Expand All @@ -57,15 +56,14 @@ def set_active_group(window, view, other_group, view_exist):
else:
group = nag

# when other_group is left, we need move all views to right except FB view
# when other_group is left, we need move all views to right except our view
if nag == 0 and other_group == 'left' and group == 0:
for v in reversed(window.views_in_group(nag)[1:]):
window.set_view_index(v, 1, 0)

return (nag, group)


def set_view(view_id, window):
"""select or create view for plugin"""
view = None
if view_id:
view = first(window.views(), lambda v: v.id() == view_id)
Expand Down Expand Up @@ -96,7 +94,7 @@ def show(window, path, view_id=None, ignore_existing=False, single_pane=False, o

view = set_view(view_id, window)

nag, group = set_active_group(window, view, other_group, view_exist)
set_active_group(window, view, other_group, view_exist)

if other_group and prev_focus:
window.focus_view(prev_focus)
Expand Down

0 comments on commit 2b9c927

Please sign in to comment.