forked from math2001/FileManager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileManager.py
110 lines (94 loc) · 4.26 KB
/
FileManager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# -*- encoding: utf-8 -*-
import sys
import sublime
import sublime_plugin
# Clear module cache to force reloading all modules of this package.
prefix = __package__ + "." # don't clear the base package
for module_name in [
module_name
for module_name in sys.modules
if module_name.startswith(prefix) and module_name != __name__
]:
del sys.modules[module_name]
prefix = None
from .commands.copy import FmCopyCommand
from .commands.create import FmCreaterCommand, FmCreateCommand
from .commands.create_php_class import FmCreaterPhpClassCommand, FmCreatePhpClassCommand
from .commands.create_from_selection import FmCreateFileFromSelectionCommand
from .commands.delete import FmDeleteCommand
from .commands.duplicate import FmDuplicateCommand
from .commands.editto import FmEditToTheLeftCommand, FmEditToTheRightCommand
from .commands.find_in_files import FmFindInFilesCommand
from .commands.move import FmMoveCommand
from .commands.open_all import FmOpenAllCommand
from .commands.open_in_browser import FmOpenInBrowserCommand
from .commands.open_in_explorer import FmOpenInExplorerCommand
from .commands.open_terminal import FmOpenTerminalCommand
from .commands.rename import FmRenameCommand, FmRenamePathCommand
def plugin_loaded():
settings = sublime.load_settings("FileManager.sublime-settings")
# this use to be a supported setting, but we dropped it. (see #27)
if settings.get("auto_close_empty_groups") is not None:
# we could remove the setting automatically, and install the
# package if it was set to true, but it'd be an extra source
# of bugs, and it doesn't take that much effort (it's a one
# time thing, so it doesn't need to be automated)
sublime.error_message(
"FileManager\n\n"
"auto_close_empty_groups is set, but this setting is no longer "
"supported.\n\n"
"Auto closing empty groups (in the layout) use to be a feature "
"of FileManager, but it has now moved to it's own package.\n\n"
"If you still want this behaviour, you can install "
"AutoCloseEmptyGroup, it's available on package control.\n\n"
"To disable this warning, unset the setting "
"auto_close_empty_groups in FileManager.sublime-settings (search "
"for Preferences: FileManager Settings in the command palette)"
)
class FmEditReplace(sublime_plugin.TextCommand):
def run(self, edit, **kwargs):
kwargs.get("view", self.view).replace(
edit, sublime.Region(*kwargs["region"]), kwargs["text"]
)
class FmListener(sublime_plugin.EventListener):
def on_load(self, view):
settings = view.settings()
snippet = settings.get("fm_insert_snippet_on_load", None)
if snippet:
view.run_command("insert_snippet", {"contents": snippet})
settings.erase("fm_insert_snippet_on_load")
if sublime.load_settings("FileManager.sublime-settings").get(
"save_after_creating"
):
view.run_command("save")
if settings.get("fm_reveal_in_sidebar"):
view.window().run_command("reveal_in_side_bar")
def on_text_command(self, view, command, args):
if (
command not in ["undo", "unindent"]
or view.name() != "FileManager::input-for-path"
):
return
settings = view.settings()
if command == "unindent":
index = settings.get("completions_index")
settings.set("go_backwards", True)
view.run_command("insert", {"characters": "\t"})
return
# command_history: (command, args, times)
first = view.command_history(0)
if first[0] != "fm_edit_replace" or first[2] != 1:
return
second = view.command_history(-1)
if (second[0] != "reindent") and not (
second[0] == "insert" and second[1] == {"characters": "\t"}
):
return
settings.set("ran_undo", True)
view.run_command("undo")
index = settings.get("completions_index")
if index == 0 or index is None:
settings.erase("completions")
settings.erase("completions_index")
else:
settings.set("completions_index", index - 1)