|
3 | 3 | import shutil |
4 | 4 | import sublime_plugin |
5 | 5 |
|
6 | | -from ..vcs.git.git_command_base import GitCommandBase |
7 | | -from .command_base import AdvancedNewFileBase |
| 6 | +from .duplicate_file_base import DuplicateFileBase |
8 | 7 | from ..anf_util import * |
| 8 | +from ..vcs.git.git_command_base import GitCommandBase |
9 | 9 |
|
10 | 10 |
|
11 | | -class AdvancedNewFileMove(AdvancedNewFileBase, sublime_plugin.WindowCommand, |
12 | | - GitCommandBase): |
| 11 | +class AdvancedNewFileMove(DuplicateFileBase, GitCommandBase): |
13 | 12 | def __init__(self, window): |
14 | 13 | super(AdvancedNewFileMove, self).__init__(window) |
15 | 14 |
|
16 | | - def run(self, is_python=False, initial_path=None, rename_file=None): |
17 | | - self.is_python = is_python |
18 | | - self.run_setup() |
19 | | - self.rename_filename = rename_file |
20 | | - |
21 | | - path = self.settings.get(RENAME_DEFAULT_SETTING) |
22 | | - current_file = self.view.file_name() |
23 | | - if current_file: |
24 | | - directory, current_file_name = os.path.split(current_file) |
25 | | - path = path.replace("<filepath>", current_file) |
26 | | - path = path.replace("<filedirectory>", directory + os.sep) |
27 | | - else: |
28 | | - current_file_name = "" |
29 | | - |
30 | | - path = path.replace("<filename>", current_file_name) |
31 | | - self.show_filename_input( |
32 | | - path if len(path) > 0 else self.generate_initial_path()) |
| 15 | + def get_default_setting(self): |
| 16 | + return RENAME_DEFAULT_SETTING |
33 | 17 |
|
34 | 18 | def input_panel_caption(self): |
35 | 19 | caption = 'Enter a new path for current file' |
36 | | - view = self.window.active_view() |
37 | | - self.original_name = None |
38 | | - if view is not None: |
39 | | - view_file_name = view.file_name() |
40 | | - if view_file_name: |
41 | | - self.original_name = os.path.basename(view_file_name) |
42 | | - |
43 | | - if self.original_name is None: |
44 | | - self.original_name = "" |
45 | | - |
46 | 20 | if self.is_python: |
47 | 21 | caption = '%s (creates __init__.py in new dirs)' % caption |
48 | 22 | return caption |
@@ -72,36 +46,24 @@ def entered_file_action(self, path): |
72 | 46 | if attempt_open: |
73 | 47 | self._rename_file(path) |
74 | 48 |
|
75 | | - def is_copy_original_name(self, path): |
76 | | - return (os.path.isdir(path) or |
77 | | - os.path.basename(path) == "") |
78 | | - |
79 | | - def try_append_extension(self, path): |
80 | | - if self.settings.get(APPEND_EXTENSION_ON_MOVE_SETTING, False): |
81 | | - if not self.is_copy_original_name(path): |
82 | | - _, new_path_extension = os.path.splitext(path) |
83 | | - if new_path_extension == "": |
84 | | - if self.rename_filename is None: |
85 | | - _, extension = os.path.splitext(self.view.file_name()) |
86 | | - else: |
87 | | - _, extension = os.path.splitext(self.rename_filename) |
88 | | - path += extension |
89 | | - return path |
| 49 | + def get_append_extension_setting(self): |
| 50 | + return APPEND_EXTENSION_ON_MOVE_SETTING |
90 | 51 |
|
91 | 52 | def _rename_file(self, file_path): |
92 | 53 | if os.path.isdir(file_path) or re.search(r"(/|\\)$", file_path): |
93 | 54 | # use original name if a directory path has been passed in. |
94 | 55 | file_path = os.path.join(file_path, self.original_name) |
95 | 56 |
|
96 | 57 | window = self.window |
97 | | - if self.rename_filename: |
98 | | - file_view = self._find_open_file(self.rename_filename) |
| 58 | + rename_filename = self.get_argument_name() |
| 59 | + if rename_filename: |
| 60 | + file_view = self._find_open_file(rename_filename) |
99 | 61 | if file_view is not None: |
100 | 62 | self.view.run_command("save") |
101 | 63 | window.focus_view(file_view) |
102 | 64 | window.run_command("close") |
103 | 65 |
|
104 | | - self._move_action(self.rename_filename, file_path) |
| 66 | + self._move_action(rename_filename, file_path) |
105 | 67 |
|
106 | 68 | if file_view is not None: |
107 | 69 | self.open_file(file_path) |
@@ -131,16 +93,8 @@ def _move_action(self, from_file, to_file): |
131 | 93 | else: |
132 | 94 | shutil.move(from_file, to_file) |
133 | 95 |
|
134 | | - def update_status_message(self, creation_path): |
135 | | - if self.is_copy_original_name(creation_path): |
136 | | - creation_path = os.path.join(creation_path, self.original_name) |
137 | | - else: |
138 | | - creation_path = self.try_append_extension(creation_path) |
139 | | - if self.view is not None: |
140 | | - self.view.set_status("AdvancedNewFile", "Moving file to %s " % |
141 | | - creation_path) |
142 | | - else: |
143 | | - sublime.status_message("Moving file to %s" % creation_path) |
| 96 | + def get_status_prefix(self): |
| 97 | + return "Moving file to" |
144 | 98 |
|
145 | 99 |
|
146 | 100 | class AdvancedNewFileMoveAtCommand(sublime_plugin.WindowCommand): |
|
0 commit comments