def command__paste(manager): if not manager._copy_mode: return fullpath = manager._copy_file basename = os.path.basename(fullpath) cwd = manager._getExplorer().cwd to_path = os.path.join(cwd, basename) if os.path.exists(to_path): name, ext = os.path.splitext(basename) to_path = os.path.join(cwd, "{}_copy{}".format(name, ext)) # *_copy があったら、だめ if os.path.exists(to_path): echo_error(" Already exists. '{}'".format(to_path.replace("\\", "/"))) manager._refresh() return if os.path.isdir(fullpath): # shutil.copytree(src, dst) shutil.copytree(fullpath, to_path) else: shutil.copy2(fullpath, to_path) manager._refresh() manager._move_cursor_if_fullpath_match(to_path) lfCmd("redraw | echon ' Pasted.'")
def command__open_current(manager): if manager._cli.pattern == "..": _open_parent(manager) return line = manager._getInstance().currentLine if line == NO_CONTENT_MSG: return if line == "": return file_info = manager._getExplorer()._contents[line] if not file_info["isdir"]: manager.accept() return True if not accessable(file_info["fullpath"]): echo_error("Permission denied `{}`".format(file_info["fullpath"])) return if manager._getInstance().isReverseOrder(): lfCmd("normal! G") else: manager._gotoFirstLine() manager._chcwd(os.path.abspath(file_info["fullpath"])) manager._history.add(manager._getExplorer().cwd)
def _remove_trash(manager, path_list): try: import send2trash except ImportError: echo_error('"Send2Trash" is not installed') return for path in path_list: send2trash.send2trash(path) if manager._instance.getWinPos() not in ("popup", "floatwin"): manager._refresh() else: manager._refresh(write_history=False, normal_mode=True)
def command__rename(manager): line = manager._instance.currentLine if len(manager._selections) > 0: echo_error(" Rename does not support multiple files.") return if invalid_line(line): return from_path = manager._getExplorer()._contents[line]["fullpath"] basename = os.path.basename(from_path) save_context(manager, **{"from_path": from_path, "basename": basename}) input_prompt(manager, "rename", [{"prompt": "Rename: ", "text": basename}])
def command__copy(manager): if len(manager._selections) > 0: echo_error(" Copy does not support multiple files.") return line = manager._getInstance().currentLine if invalid_line(line): return manager._copy_file = manager._getExplorer()._contents[line]["fullpath"] manager._copy_mode = True lfCmd("redraw | echon ' Copied.'") # Updat estatus line manager._getExplorer().setCommandMode("COPY") manager._redrawStlCwd()
def command___do_create_file(manager, context, results): file_name = results[0] if file_name == "": echo_cancel() return path = os.path.join(manager._getExplorer().cwd, file_name) if os.path.exists(path): echo_error(" Already exists. '{}'".format(path.replace("\\", "/"))) return open(path, "w").close() if manager._instance.getWinPos() not in ("popup", "floatwin"): manager._refresh() else: manager._refresh(write_history=False, normal_mode=True) manager._move_cursor_if_fullpath_match(path)
def command___do_rename(manager, context, results): renamed = results[0] if renamed == "": echo_cancel() return if renamed == context["basename"]: return to_path = os.path.join(os.path.dirname(context["from_path"]), renamed) if os.path.exists(to_path): echo_error(" Already exists. '{}'".format(to_path.replace("\\", "/"))) return os.rename(context["from_path"], to_path) if manager._instance.getWinPos() not in ("popup", "floatwin"): manager._refresh() else: manager._refresh(write_history=False, normal_mode=True) manager._move_cursor_if_fullpath_match(to_path)
def startExplorer(self, win_pos, *args, **kwargs): _dir = "" if kwargs.get("arguments", {}).get("directory"): _dir = kwargs.get("arguments", {}).get("directory")[0] # Get a quoted path # e,g, # :Leaderf filer 'C:\Program Files' # :Leaderf filer "C:\Program Files" m = re.match(r"""("[^"]+"|'[^']+')""", _dir) if m: _dir = m.groups()[0][1:-1] _dir = os.path.expanduser(lfDecode(_dir)) _dir = os.path.expandvars(_dir) _dir = os.path.abspath(_dir) if not os.path.exists(_dir): echo_error("Unknown directory `{}`".format(_dir)) return elif not accessable(_dir): echo_error("Permission denied `{}`".format(_dir)) return _dir = _dir or os.getcwd() # Set vars because super().startExplorer() is calling self._getExplorer() self._getExplorer().cwd = _dir # To call _buildPrompt() in super().startExplorer() if lfEval("get(g:, 'Lf_FilerShowPromptPath', 0)") == "1": self._getInstance( )._cli._additional_prompt_string = self._adjust_path(_dir) super(FilerExplManager, self).startExplorer(win_pos, *args, **kwargs) # super().startExplorer() updates cwd to os.getcwd() self._getInstance().setCwd(_dir) self._history.add(_dir)
def command___do_mkdir(manager, context, results): dir_name = results[0] if dir_name == "": echo_cancel() return path = os.path.join(manager._getExplorer().cwd, dir_name) if os.path.exists(os.path.join(manager._getExplorer().cwd, dir_name)): echo_error(" Already exists. '{}'".format(path.replace("\\", "/"))) return os.makedirs(path) if manager._instance.getWinPos() not in ("popup", "floatwin"): if lfEval("get(g:, 'Lf_FilerMkdirAutoChdir', 0)") == "1": manager._chcwd(path) else: manager._refresh() else: if lfEval("get(g:, 'Lf_FilerMkdirAutoChdir', 0)") == "1": manager._chcwd(path, write_history=False, normal_mode=True) else: manager._refresh(write_history=False, normal_mode=True) manager._move_cursor_if_fullpath_match(path)
def do_command(self, cmd_name): if self._command.contains(cmd_name): return self._command.execute_command(cmd_name) else: echo_error("Not found command: {}".format(cmd_name))