Skip to content

Commit b51fe23

Browse files
committed
Improve Icon selection in preferences
1 parent fa783c1 commit b51fe23

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

source/core/preferences.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ def draw(self, context: Context) -> None:
104104

105105
row = subbox.row()
106106
row.prop(subpath, "icon", text="Icon")
107-
row.operator("iv.icons_show", text="Browse Icons")
107+
op = row.operator("iv.icons_show", text="Browse Icons")
108+
op.project_index = project_index
109+
op.subpath_index = subpath_index
108110

109111
# Add subpath button
110112
op = box.operator("preferences.add_project_subpath", text="Add Subpath", icon="ADD")

source/operators/icon_selector.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import bpy
33
import math
44
from bpy.types import Operator, Context, Event
5-
from bpy.props import StringProperty
5+
from bpy.props import StringProperty, IntProperty
66

77

88
def get_all_icons() -> List[str]:
@@ -16,11 +16,19 @@ class N_OT_IconShow(Operator):
1616
bl_description = "Browse and select an icon"
1717

1818
icon: StringProperty(default="")
19+
project_index: IntProperty(default=-1)
20+
subpath_index: IntProperty(default=-1)
1921

2022
def execute(self, context: Context) -> set[str]:
21-
if self.icon:
22-
context.window_manager.clipboard = self.icon
23-
self.report({"INFO"}, f"Icon '{self.icon}' copied to clipboard")
23+
if self.icon and self.project_index >= 0 and self.subpath_index >= 0:
24+
from ..core.preferences import get_preferences
25+
prefs = get_preferences(context)
26+
27+
if self.project_index < len(prefs.custom_project_paths):
28+
project = prefs.custom_project_paths[self.project_index]
29+
if self.subpath_index < len(project.subpaths):
30+
project.subpaths[self.subpath_index].icon = self.icon
31+
self.report({"INFO"}, f"Icon '{self.icon}' set for subpath")
2432
return {"FINISHED"}
2533

2634
def invoke(self, context: Context, event: Event) -> set[str]:
@@ -39,3 +47,5 @@ def draw(self, context: Context) -> None:
3947
for icon_name in icons:
4048
op = flow.operator(self.bl_idname, text="", icon=icon_name, emboss=False)
4149
op.icon = icon_name
50+
op.project_index = self.project_index
51+
op.subpath_index = self.subpath_index

0 commit comments

Comments
 (0)