Пример #1
0
    def run(self):
        """Run command."""

        errors = False
        full_name = path.join(FuzzyFileNavCommand.cwd, FuzzyPanelText.get_content())
        FuzzyPanelText.clear_content()
        multi_file = (
            bool(sublime.load_settings(FUZZY_SETTINGS).get("keep_panel_open_after_action", False)) and
            "mkdir" not in sublime.load_settings(FUZZY_SETTINGS).get("keep_panel_open_exceptions", [])
        )
        if not multi_file:
            self.window.run_command("hide_overlay")
            FuzzyFileNavCommand.reset()
        else:
            FuzzyFileNavCommand.fuzzy_reload = True

        try:
            os.makedirs(full_name)
        except Exception:
            errors = True
            error("Could not create %d!" % full_name)

        if multi_file:
            if errors:
                FuzzyFileNavCommand.reset()
            else:
                self.window.run_command("hide_overlay")
                self.window.run_command("fuzzy_file_nav", {"start": FuzzyFileNavCommand.cwd})
Пример #2
0
    def run(self):
        """Run command."""

        errors = False
        full_name = path.join(FuzzyFileNavCommand.cwd, FuzzyPanelText.get_content())
        FuzzyPanelText.clear_content()
        multi_file = (
            bool(sublime.load_settings(FUZZY_SETTINGS).get("keep_panel_open_after_action", False)) and
            "delete" not in sublime.load_settings(FUZZY_SETTINGS).get("keep_panel_open_exceptions", [])
        )

        if not multi_file:
            self.window.run_command("hide_overlay")
            FuzzyFileNavCommand.reset()
        else:
            FuzzyFileNavCommand.fuzzy_reload = True

        if sublime.ok_cancel_dialog("Delete %s?\n\nWarning: this is permanent!" % full_name):
            try:
                if path.isdir(full_name):
                    shutil.rmtree(full_name)
                else:
                    os.remove(full_name)
            except Exception:
                errors = True
                error("Error deleting %d!" % full_name)

        if multi_file:
            if errors:
                FuzzyFileNavCommand.reset()
            else:
                self.window.run_command("hide_overlay")
                self.window.run_command("fuzzy_file_nav", {"start": FuzzyFileNavCommand.cwd})
Пример #3
0
    def run(self):
        """Run command."""

        errors = False
        full_name = path.join(FuzzyFileNavCommand.cwd,
                              FuzzyPanelText.get_content())
        FuzzyPanelText.clear_content()
        multi_file = (bool(
            sublime.load_settings(FUZZY_SETTINGS).get(
                "keep_panel_open_after_action", False)) and "mkdir"
                      not in sublime.load_settings(FUZZY_SETTINGS).get(
                          "keep_panel_open_exceptions", []))
        if not multi_file:
            self.window.run_command("hide_overlay")
            FuzzyFileNavCommand.reset()
        else:
            FuzzyFileNavCommand.fuzzy_reload = True

        try:
            os.makedirs(full_name)
        except Exception:
            errors = True
            error("Could not create %d!" % full_name)

        if multi_file:
            if errors:
                FuzzyFileNavCommand.reset()
            else:
                self.window.run_command("hide_overlay")
                self.window.run_command("fuzzy_file_nav",
                                        {"start": FuzzyFileNavCommand.cwd})
Пример #4
0
    def run(self):
        """Run the command."""

        file_name = FuzzyPanelText.get_content()
        FuzzyPanelText.clear_content()
        proj_file = self.window.project_file_name()
        data = self.window.project_data()
        if data is None:
            data = {}
        new_folder = path.join(FuzzyFileNavCommand.cwd, file_name)
        if not path.exists(new_folder):
            return
        if not path.isdir(new_folder):
            new_folder = path.dirname(new_folder)
        if "folders" not in data:
            data["folders"] = []
        already_exists = self.compare(data["folders"], new_folder, proj_file)

        if not already_exists:
            true_path = get_path_true_case(new_folder)
            if true_path is not None:
                if (
                    sublime.load_settings(FUZZY_SETTINGS).get("add_folder_to_project_relative", False) and
                    proj_file is not None
                ):
                    new_folder = path.relpath(new_folder, path.dirname(proj_file))
                follow_sym = sublime.load_settings(FUZZY_SETTINGS).get("add_folder_to_project_follow_symlink", True)
                data["folders"].append({'follow_symlinks': follow_sym, 'path': new_folder})
                self.window.set_project_data(data)
            else:
                error("Couldn't resolve case for path %s!" % new_folder)
Пример #5
0
    def file_copy(self):
        """Hanlde file copy."""

        errors = False
        try:
            if path.exists(self.to_path):
                if path.isdir(self.to_path):
                    file_name = path.join(self.to_path,
                                          path.basename(self.from_path))
                    if path.exists(file_name):
                        if not sublime.ok_cancel_dialog(
                                "%s exists!\n\nOverwrite file?" % file_name):
                            return
                    self.action(self.from_path, file_name)
                elif sublime.ok_cancel_dialog("%s exists!\n\nOverwrite file?" %
                                              self.to_path):
                    self.action(self.from_path, self.to_path)
            elif path.exists(path.dirname(self.to_path)):
                self.action(self.from_path, self.to_path)
            else:
                errors = True
                error("Cannot copy %s" % self.from_path)
        except Exception:
            errors = True
            error("Cannot copy %s" % self.from_path)
        return errors
Пример #6
0
    def run(self):
        """Run the command."""

        file_name = FuzzyPanelText.get_content()
        FuzzyPanelText.clear_content()
        proj_file = self.window.project_file_name()
        data = self.window.project_data()
        if data is None:
            data = {}
        new_folder = path.join(FuzzyFileNavCommand.cwd, file_name)
        if not path.exists(new_folder):
            return
        if not path.isdir(new_folder):
            new_folder = path.dirname(new_folder)
        if "folders" not in data:
            data["folders"] = []
        already_exists = self.compare(data["folders"], new_folder, proj_file)

        if not already_exists:
            true_path = get_path_true_case(new_folder)
            if true_path is not None:
                if (sublime.load_settings(FUZZY_SETTINGS).get(
                        "add_folder_to_project_relative", False)
                        and proj_file is not None):
                    new_folder = path.relpath(new_folder,
                                              path.dirname(proj_file))
                follow_sym = sublime.load_settings(FUZZY_SETTINGS).get(
                    "add_folder_to_project_follow_symlink", True)
                data["folders"].append({
                    'follow_symlinks': follow_sym,
                    'path': new_folder
                })
                self.window.set_project_data(data)
            else:
                error("Couldn't resolve case for path %s!" % new_folder)
Пример #7
0
    def run(self):
        """Run command."""

        full_name = path.join(FuzzyFileNavCommand.cwd,
                              FuzzyPanelText.get_content())
        file_exists = path.exists(full_name)
        if file_exists:
            if not sublime.ok_cancel_dialog(
                    "%s exists!\n\nOverwrite file?" % full_name):
                return

        FuzzyPanelText.clear_content()
        self.multi_file = (bool(
            sublime.load_settings(FUZZY_SETTINGS).get(
                "keep_panel_open_after_action", False)) and "saveas"
                           not in sublime.load_settings(FUZZY_SETTINGS).get(
                               "keep_panel_open_exceptions", []))
        active_view = self.window.active_view()
        if active_view is None:
            return
        self.bfr = active_view.substr(sublime.Region(0, active_view.size()))
        self.current_sels = [s for s in active_view.sel()]
        self.position = active_view.viewport_position()
        if not self.multi_file:
            self.window.run_command("hide_overlay")
            FuzzyFileNavCommand.reset()
        else:
            FuzzyFileNavCommand.fuzzy_reload = True

        try:
            if not file_exists:
                with open(full_name, "a"):
                    pass
            active_view.set_scratch(True)
            self.window.run_command("close")
            self.view = self.window.open_file(full_name)
            sublime.set_timeout(self.save, 100)
        except Exception:
            error("Could not create %s!" % full_name)
            if self.multi_file:
                FuzzyFileNavCommand.reset()
Пример #8
0
    def run(self):
        """Run command."""

        full_name = path.join(FuzzyFileNavCommand.cwd, FuzzyPanelText.get_content())
        file_exists = path.exists(full_name)
        if file_exists:
            if not sublime.ok_cancel_dialog("%s exists!\n\nOverwrite file?" % full_name):
                return

        FuzzyPanelText.clear_content()
        self.multi_file = (
            bool(sublime.load_settings(FUZZY_SETTINGS).get("keep_panel_open_after_action", False)) and
            "saveas" not in sublime.load_settings(FUZZY_SETTINGS).get("keep_panel_open_exceptions", [])
        )
        active_view = self.window.active_view()
        if active_view is None:
            return
        self.bfr = active_view.substr(sublime.Region(0, active_view.size()))
        self.current_sels = [s for s in active_view.sel()]
        self.position = active_view.viewport_position()
        if not self.multi_file:
            self.window.run_command("hide_overlay")
            FuzzyFileNavCommand.reset()
        else:
            FuzzyFileNavCommand.fuzzy_reload = True

        try:
            if not file_exists:
                with open(full_name, "a"):
                    pass
            active_view.set_scratch(True)
            self.window.run_command("close")
            self.view = self.window.open_file(full_name)
            sublime.set_timeout(self.save, 100)
        except Exception:
            error("Could not create %s!" % full_name)
            if self.multi_file:
                FuzzyFileNavCommand.reset()
Пример #9
0
    def file_copy(self):
        """Hanlde file copy."""

        errors = False
        try:
            if path.exists(self.to_path):
                if path.isdir(self.to_path):
                    file_name = path.join(self.to_path, path.basename(self.from_path))
                    if path.exists(file_name):
                        if not sublime.ok_cancel_dialog("%s exists!\n\nOverwrite file?" % file_name):
                            return
                    self.action(self.from_path, file_name)
                elif sublime.ok_cancel_dialog("%s exists!\n\nOverwrite file?" % self.to_path):
                    self.action(self.from_path, self.to_path)
            elif path.exists(path.dirname(self.to_path)):
                self.action(self.from_path, self.to_path)
            else:
                errors = True
                error("Cannot copy %s" % self.from_path)
        except Exception:
            errors = True
            error("Cannot copy %s" % self.from_path)
        return errors
Пример #10
0
    def run(self):
        """Run command."""

        errors = False
        full_name = path.join(FuzzyFileNavCommand.cwd,
                              FuzzyPanelText.get_content())
        FuzzyPanelText.clear_content()
        multi_file = (bool(
            sublime.load_settings(FUZZY_SETTINGS).get(
                "keep_panel_open_after_action", False)) and "delete"
                      not in sublime.load_settings(FUZZY_SETTINGS).get(
                          "keep_panel_open_exceptions", []))

        if not multi_file:
            self.window.run_command("hide_overlay")
            FuzzyFileNavCommand.reset()
        else:
            FuzzyFileNavCommand.fuzzy_reload = True

        if sublime.ok_cancel_dialog(
                "Delete %s?\n\nWarning: this is permanent!" % full_name):
            try:
                if path.isdir(full_name):
                    shutil.rmtree(full_name)
                else:
                    os.remove(full_name)
            except Exception:
                errors = True
                error("Error deleting %d!" % full_name)

        if multi_file:
            if errors:
                FuzzyFileNavCommand.reset()
            else:
                self.window.run_command("hide_overlay")
                self.window.run_command("fuzzy_file_nav",
                                        {"start": FuzzyFileNavCommand.cwd})
Пример #11
0
    def dir_copy(self):
        """Handle directory copy."""

        errors = False
        try:
            if path.exists(self.to_path):
                if path.isdir(self.to_path):
                    self.action(self.from_path, path.join(self.to_path, path.basename(self.from_path)))
                else:
                    errors = True
                    error("%s already exists!" % self.to_path)
            elif path.exists(path.dirname(self.to_path)):
                self.action(self.from_path, self.to_path)
            else:
                errors = True
                error("Cannot copy %s" % self.from_path)
        except Exception:
            errors = True
            error("Cannot copy %s" % self.from_path)
        return errors
Пример #12
0
    def dir_copy(self):
        """Handle directory copy."""

        errors = False
        try:
            if path.exists(self.to_path):
                if path.isdir(self.to_path):
                    self.action(
                        self.from_path,
                        path.join(self.to_path, path.basename(self.from_path)))
                else:
                    errors = True
                    error("%s already exists!" % self.to_path)
            elif path.exists(path.dirname(self.to_path)):
                self.action(self.from_path, self.to_path)
            else:
                errors = True
                error("Cannot copy %s" % self.from_path)
        except Exception:
            errors = True
            error("Cannot copy %s" % self.from_path)
        return errors