Skip to content

Commit

Permalink
KateDocuments -> OpenedFiles
Browse files Browse the repository at this point in the history
  • Loading branch information
qiray committed Dec 20, 2017
1 parent 42f5cf4 commit d9d1c5c
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 91 deletions.
24 changes: 12 additions & 12 deletions Default.sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,45 @@
[
{
"keys": ["r"],
"command": "kate_documents",
"command": "opened_files",
"context": [
{ "key": "selector", "operator": "equal", "operand": "text.kate_documents" },
{ "key": "selector", "operator": "equal", "operand": "text.opened_files" },
]
},
{
"keys": ["enter"],
"command": "kate_documents_act",
"command": "opened_files_act",
"context": [
{ "key": "selector", "operator": "equal", "operand": "text.kate_documents" },
{ "key": "selector", "operator": "equal", "operand": "text.opened_files" },
]
},

{
"keys": ["right"],
"command": "kate_documents_act", "args": {"act": "unfold"},
"command": "opened_files_act", "args": {"act": "unfold"},
"context": [
{ "key": "selector", "operator": "equal", "operand": "text.kate_documents" },
{ "key": "selector", "operator": "equal", "operand": "text.opened_files" },
]
},
{
"keys": ["left"],
"command": "kate_documents_act", "args": {"act": "fold"},
"command": "opened_files_act", "args": {"act": "fold"},
"context": [
{ "key": "selector", "operator": "equal", "operand": "text.kate_documents" },
{ "key": "selector", "operator": "equal", "operand": "text.opened_files" },
]
},
{
"keys": ["backspace"],
"command": "kate_documents_act", "args": {"act": "fold"},
"command": "opened_files_act", "args": {"act": "fold"},
"context": [
{ "key": "selector", "operator": "equal", "operand": "text.kate_documents" },
{ "key": "selector", "operator": "equal", "operand": "text.opened_files" },
]
},
{
"keys": ["o"],
"command": "kate_documents_open_external",
"command": "opened_files_open_external",
"context": [
{ "key": "selector", "operator": "equal", "operand": "text.kate_documents" },
{ "key": "selector", "operator": "equal", "operand": "text.opened_files" },
]
},
]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Kate Documents
# Sublime Opened Files

Plugin for Sublime Text to show opened files as a treeview like Kate editor
Plugin for Sublime Text to show opened files as a treeview and a listview.
23 changes: 0 additions & 23 deletions kate_documents.sublime-syntax

This file was deleted.

41 changes: 20 additions & 21 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
VERSION_REVISION = 3

ST3 = int(sublime.version()) >= 3000
KATE_DOCUMENTS_VIEW = None
OPENED_FILES_VIEW = None

if ST3:
from .show import show, first
Expand All @@ -23,11 +23,11 @@
tree = Tree()

def debug(level, *args):
if level <= KateDocumentsCommand.debug_level:
if level <= OpenedFilesCommand.debug_level:
print('[DEBUG]', level, args)

def view_name(view):
result = KateDocumentsCommand.untitled_name
result = OpenedFilesCommand.untitled_name
filename = view.file_name()
name = view.name()
if filename is not None and filename != '':
Expand All @@ -44,34 +44,34 @@ def generate_tree(view_list):
return localtree

def draw_tree(window, edit, tree):
global KATE_DOCUMENTS_VIEW
global OPENED_FILES_VIEW

view = show(window, 'Documents', view_id=KATE_DOCUMENTS_VIEW, other_group=True)
view = show(window, 'Documents', view_id=OPENED_FILES_VIEW, other_group=True)
if not view:
KATE_DOCUMENTS_VIEW = None
OPENED_FILES_VIEW = None
return
KATE_DOCUMENTS_VIEW = view.id()
OPENED_FILES_VIEW = view.id()
view.set_read_only(False) #Enable edit for pasting result
view.erase(edit, sublime.Region(0, view.size())) #clear view content
view.insert(edit, 0, str(tree)) #paste result tree
view.set_read_only(True) #Disable edit

class KateDocumentsCommand(sublime_plugin.TextCommand): #view.run_command('kate_documents')
class OpenedFilesCommand(sublime_plugin.TextCommand): #view.run_command('opened_files')

untitled_name = 'untitled' #const
debug_level = 1

def run(self, edit):
global KATE_DOCUMENTS_VIEW
global OPENED_FILES_VIEW
global tree
window = self.view.window()
view_list = window.views()

temp = []
for view in view_list:
s = view.settings()
if s.get("kate_documents_type"):
KATE_DOCUMENTS_VIEW = view.id()
if s.get("opened_files_type"):
OPENED_FILES_VIEW = view.id()
elif s.get('dired_path'):
pass
else:
Expand All @@ -81,7 +81,7 @@ def run(self, edit):
tree = generate_tree(view_list)
draw_tree(window, edit, tree)

class KateDocumentsActCommand(sublime_plugin.TextCommand):
class OpenedFilesActCommand(sublime_plugin.TextCommand):
def run(self, edit, act = 'default'):
selection = self.view.sel()[0]
self.open_file(edit, selection, act)
Expand All @@ -97,8 +97,8 @@ def open_file(self, edit, selection, act):
node = tree.nodes[action['id']]
goto_linenumber = row + 1
if action['action'] == 'file' and act == 'default':
view = first(window.views(), lambda v: v.id() == action['view_id'])
window.focus_view(view)
view = first(window.views(), lambda v: v.id() == action['view_id'])
window.focus_view(view)
elif action['action'] == 'fold' and act != 'unfold':
tree.nodes[action['id']].status = 'unfold'
draw_tree(window, edit, tree)
Expand All @@ -111,10 +111,9 @@ def open_file(self, edit, selection, act):
draw_tree(window, edit, tree)
elif act == 'unfold' and len(node.children) > 0:
goto_linenumber = tree.nodes[sorted(node.children)[0]].stringnum
print(len(node.children))
self.view.run_command("goto_line", {"line": goto_linenumber})

class KateDocumentsOpenExternalCommand(sublime_plugin.TextCommand):
class OpenedFilesOpenExternalCommand(sublime_plugin.TextCommand):
def run(self, edit):
selection = self.view.sel()[0]
(row, col) = self.view.rowcol(selection.begin())
Expand All @@ -128,8 +127,8 @@ def run(self, edit):

def mouse_click_actions(view, args):
s = view.settings()
if s.get("kate_documents_type"):
view.run_command('kate_documents_act') #call user defined command
if s.get("opened_files_type"):
view.run_command('opened_files_act') #call user defined command
elif s.get("dired_path") and not s.get("dired_rename_mode"): #for FileBrowser plugin
if 'directory' in view.scope_name(view.sel()[0].a):
command = ("dired_expand", {"toggle": True})
Expand All @@ -155,10 +154,10 @@ def run_(self, args):
#TODO: add event listener for open/close/new tabs
# class SampleListener(sublime_plugin.EventListener):
# def on_load(self, view):
# view.run_command('kate_documents')
# view.run_command('opened_files')

# def on_pre_close(self, view):
# print('Closing!' + view.name())
# s = view.settings()`
# if not s.get("kate_documents_type"):
# view.run_command('kate_documents')
# if not s.get("opened_files_type"):
# view.run_command('opened_files')
2 changes: 1 addition & 1 deletion nodetree.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-


import os
import sublime

Expand All @@ -17,6 +16,7 @@ def __init__(self, node_id, children, status, parent=None, view_id=None):
self.children = children
self.status = status
self.view_id = view_id
self.stringnum = ''

def add_child(self, child):
if not child in self.children:
Expand Down
38 changes: 19 additions & 19 deletions kate_documents.hidden-tmLanguage → opened_files.hidden-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<plist version="1.0">
<dict>
<key>name</key>
<string>kate_documents</string>
<string>opened_files</string>
<key>scopeName</key>
<string>text.kate_documents</string>
<string>text.opened_files</string>
<key>uuid</key>
<string>638375b8-3509-4d37-a8d8-afad7a95b428</string>
<key>fileTypes</key>
<array>
<string>kate_documents</string>
<string>opened_files</string>
</array>
<key>patterns</key>
<array>
Expand All @@ -19,7 +19,7 @@
<key>match</key>
<string>^(\s*)([▸▾] )([^\\/]*)(\\|/)?(.*)?$</string>
<key>name</key>
<string>kate_documents.item.directory</string>
<string>opened_files.item.directory</string>
<key>captures</key>
<dict>
<key>1</key>
Expand All @@ -30,22 +30,22 @@
<key>2</key>
<dict>
<key>name</key>
<string>punctuation.definition.directory.symbol.kate_documents</string>
<string>punctuation.definition.directory.symbol.opened_files</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>string.name.directory.kate_documents</string>
<string>string.name.directory.opened_files</string>
</dict>
<key>4</key>
<dict>
<key>name</key>
<string>punctuation.definition.directory.slash.kate_documents</string>
<string>punctuation.definition.directory.slash.opened_files</string>
</dict>
<key>5</key>
<dict>
<key>name</key>
<string>string.error.kate_documents</string>
<string>string.error.opened_files</string>
</dict>
</dict>
</dict>
Expand All @@ -54,7 +54,7 @@
<key>match</key>
<string>^(\s*)(≡ )(\S.*?(\.[^\.\n]+)?)( \(.*\))?$</string>
<key>name</key>
<string>kate_documents.item.file</string>
<string>opened_files.item.file</string>
<key>captures</key>
<dict>
<key>1</key>
Expand All @@ -65,22 +65,22 @@
<key>2</key>
<dict>
<key>name</key>
<string>punctuation.definition.file.symbol.kate_documents</string>
<string>punctuation.definition.file.symbol.opened_files</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>string.name.file.kate_documents</string>
<string>string.name.file.opened_files</string>
</dict>
<key>4</key>
<dict>
<key>name</key>
<string>string.name.file.extension.kate_documents</string>
<string>string.name.file.extension.opened_files</string>
</dict>
<key>5</key>
<dict>
<key>name</key>
<string>string.name.file.view_id.kate_documents</string>
<string>string.name.file.view_id.opened_files</string>
</dict>
</dict>
</dict>
Expand All @@ -89,13 +89,13 @@
<key>match</key>
<string>^⠤(\s*\[.+\]){0,1}$</string>
<key>name</key>
<string>kate_documents.item.parent_dir</string>
<string>opened_files.item.parent_dir</string>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>punctuation.definition.rename_mode.kate_documents</string>
<string>punctuation.definition.rename_mode.opened_files</string>
</dict>
</dict>
</dict>
Expand All @@ -106,23 +106,23 @@
<key>end</key>
<string>^(—+)(\[RENAME MODE\]){0,1}(—*)\n</string>
<key>name</key>
<string>header.kate_documents</string>
<string>header.opened_files</string>
<key>endCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>punctuation.definition.separator.kate_documents</string>
<string>punctuation.definition.separator.opened_files</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>punctuation.definition.rename_mode.kate_documents</string>
<string>punctuation.definition.rename_mode.opened_files</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>punctuation.definition.separator.kate_documents</string>
<string>punctuation.definition.separator.opened_files</string>
</dict>
</dict>
</dict>
Expand Down
Loading

0 comments on commit d9d1c5c

Please sign in to comment.