diff --git a/src/blenderbim/blenderbim/bim/module/project/operator.py b/src/blenderbim/blenderbim/bim/module/project/operator.py index 032d409f40..ea4aa48ce3 100644 --- a/src/blenderbim/blenderbim/bim/module/project/operator.py +++ b/src/blenderbim/blenderbim/bim/module/project/operator.py @@ -735,7 +735,7 @@ class LoadProject(bpy.types.Operator, IFCFileSelector): context.scene.BIMProjectProperties.is_loading = True context.scene.BIMProjectProperties.total_elements = len(tool.Ifc.get().by_type("IfcElement")) tool.Blender.register_toolbar() - tool.Blender.add_recent_ifc_project(filepath.absolute()) + tool.Project.add_recent_ifc_project(filepath.absolute()) if not self.is_advanced: bpy.ops.bim.load_project_elements() @@ -759,7 +759,7 @@ class ClearRecentIFCProjects(bpy.types.Operator): bl_options = {"REGISTER"} def execute(self, context): - tool.Blender.clear_recent_ifc_projects() + tool.Project.clear_recent_ifc_projects() return {"FINISHED"} diff --git a/src/blenderbim/blenderbim/bim/module/project/ui.py b/src/blenderbim/blenderbim/bim/module/project/ui.py index 62a5b38123..b7403e07dc 100644 --- a/src/blenderbim/blenderbim/bim/module/project/ui.py +++ b/src/blenderbim/blenderbim/bim/module/project/ui.py @@ -42,7 +42,7 @@ class BIM_MT_recent_projects(Menu): bl_label = "Open Recent IFC Project" def draw(self, context): - paths = tool.Blender.get_recent_ifc_projects() + paths = tool.Project.get_recent_ifc_projects() if not paths: self.layout.label(text="No Recent IFC Projects") return diff --git a/src/blenderbim/blenderbim/tool/blender.py b/src/blenderbim/blenderbim/tool/blender.py index 55959a096a..5641f6cf67 100644 --- a/src/blenderbim/blenderbim/tool/blender.py +++ b/src/blenderbim/blenderbim/tool/blender.py @@ -1076,68 +1076,6 @@ class Blender(blenderbim.core.tool.Blender): bpy.utils.register_class(panel) del polls[panel] - @classmethod - def get_recent_ifc_projects_path(cls) -> Path: - return Path(bpy.utils.user_resource("CONFIG")) / "recent-ifc-projects.txt" - - _recent_ifc_projects_loaded: bool = False - _recent_ifc_projects: list[Path] = [] - - @classmethod - def get_recent_ifc_projects(cls) -> list[Path]: - if cls._recent_ifc_projects_loaded: - return cls._recent_ifc_projects - - filepath = cls.get_recent_ifc_projects_path() - if not filepath.exists(): - cls._recent_ifc_projects = [] - return [] - - paths = [] - with open(filepath, "r") as fi: - for line in fi: - line = line.strip() - if not line: - continue - paths.append(Path(line)) - - cls._recent_ifc_projects = paths - return paths - - @classmethod - def write_recent_ifc_projects(cls, filepaths: list[Path]) -> None: - recent_projects_path = cls.get_recent_ifc_projects_path() - try: - recent_projects_path.parent.mkdir(parents=True, exist_ok=True) - with open(recent_projects_path, "w") as fo: - fo.write("\n".join(str(p) for p in filepaths)) - cls._recent_ifc_projects_loaded = False - except PermissionError: - msg = ( - f"WARNING. PermissionError trying to access '{str(recent_projects_path)}'. " - "List of recently opened IFC projects won't be stored between Blender sessions." - ) - print(msg) - cls._recent_ifc_projects = filepaths - - @classmethod - def add_recent_ifc_project(cls, filepath: Path) -> None: - """Add `filepath` to the list of the recently opened IFC projects. - - If `filepath` was opened before, bump it in the list. - """ - current_filepaths = cls.get_recent_ifc_projects() - if filepath in current_filepaths: - current_filepaths.remove(filepath) - current_filepaths = [filepath] + current_filepaths - # Limit it to 20 recent files. - current_filepaths = current_filepaths[:20] - cls.write_recent_ifc_projects(current_filepaths) - - @classmethod - def clear_recent_ifc_projects(cls) -> None: - cls.write_recent_ifc_projects([]) - @classmethod def get_blender_addon_package_name(cls) -> str: if bpy.app.version >= (4, 2, 0): diff --git a/src/blenderbim/blenderbim/tool/project.py b/src/blenderbim/blenderbim/tool/project.py index 6b1e8cd695..b99c24a36e 100644 --- a/src/blenderbim/blenderbim/tool/project.py +++ b/src/blenderbim/blenderbim/tool/project.py @@ -142,3 +142,65 @@ class Project(blenderbim.core.tool.Project): props.x = 0.5 props.y = 0.5 props.z = 0.5 + + @classmethod + def get_recent_ifc_projects_path(cls) -> Path: + return Path(bpy.utils.user_resource("CONFIG")) / "recent-ifc-projects.txt" + + _recent_ifc_projects_loaded: bool = False + _recent_ifc_projects: list[Path] = [] + + @classmethod + def get_recent_ifc_projects(cls) -> list[Path]: + if cls._recent_ifc_projects_loaded: + return cls._recent_ifc_projects + + filepath = cls.get_recent_ifc_projects_path() + if not filepath.exists(): + cls._recent_ifc_projects = [] + return [] + + paths = [] + with open(filepath, "r") as fi: + for line in fi: + line = line.strip() + if not line: + continue + paths.append(Path(line)) + + cls._recent_ifc_projects = paths + return paths + + @classmethod + def write_recent_ifc_projects(cls, filepaths: list[Path]) -> None: + recent_projects_path = cls.get_recent_ifc_projects_path() + try: + recent_projects_path.parent.mkdir(parents=True, exist_ok=True) + with open(recent_projects_path, "w") as fo: + fo.write("\n".join(str(p) for p in filepaths)) + cls._recent_ifc_projects_loaded = False + except PermissionError: + msg = ( + f"WARNING. PermissionError trying to access '{str(recent_projects_path)}'. " + "List of recently opened IFC projects won't be stored between Blender sessions." + ) + print(msg) + cls._recent_ifc_projects = filepaths + + @classmethod + def add_recent_ifc_project(cls, filepath: Path) -> None: + """Add `filepath` to the list of the recently opened IFC projects. + + If `filepath` was opened before, bump it in the list. + """ + current_filepaths = cls.get_recent_ifc_projects() + if filepath in current_filepaths: + current_filepaths.remove(filepath) + current_filepaths = [filepath] + current_filepaths + # Limit it to 20 recent files. + current_filepaths = current_filepaths[:20] + cls.write_recent_ifc_projects(current_filepaths) + + @classmethod + def clear_recent_ifc_projects(cls) -> None: + cls.write_recent_ifc_projects([])