Fix tool-system index error with mode-specific tools added to groups
It was possible to have invalid indices when a script registered a tool into an existing group of tools. Address issue raised by D7436
This commit is contained in:
@@ -288,7 +288,6 @@ class ToolSelectPanelHelper:
|
|||||||
else:
|
else:
|
||||||
yield item
|
yield item
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _tool_get_active(cls, context, space_type, mode, with_icon=False):
|
def _tool_get_active(cls, context, space_type, mode, with_icon=False):
|
||||||
"""
|
"""
|
||||||
@@ -326,7 +325,7 @@ class ToolSelectPanelHelper:
|
|||||||
if item is not None:
|
if item is not None:
|
||||||
if type(item) is tuple:
|
if type(item) is tuple:
|
||||||
if item[0].idname == idname:
|
if item[0].idname == idname:
|
||||||
index = cls._tool_group_active.get(item[0].idname, 0)
|
index = cls._tool_group_active_get_from_item(item)
|
||||||
return (item[index], index)
|
return (item[index], index)
|
||||||
else:
|
else:
|
||||||
if item.idname == idname:
|
if item.idname == idname:
|
||||||
@@ -342,7 +341,7 @@ class ToolSelectPanelHelper:
|
|||||||
if item is not None:
|
if item is not None:
|
||||||
if type(item) is tuple:
|
if type(item) is tuple:
|
||||||
if item[0].idname == idname:
|
if item[0].idname == idname:
|
||||||
index = cls._tool_group_active.get(item[0].idname, 0)
|
index = cls._tool_group_active_get_from_item(item)
|
||||||
return (item[index], index, item)
|
return (item[index], index, item)
|
||||||
else:
|
else:
|
||||||
if item.idname == idname:
|
if item.idname == idname:
|
||||||
@@ -395,7 +394,7 @@ class ToolSelectPanelHelper:
|
|||||||
if item is not None:
|
if item is not None:
|
||||||
if i == tool_index:
|
if i == tool_index:
|
||||||
if type(item) is tuple:
|
if type(item) is tuple:
|
||||||
index = cls._tool_group_active.get(item[0].idname, 0)
|
index = cls._tool_group_active_get_from_item(item)
|
||||||
item = item[index]
|
item = item[index]
|
||||||
else:
|
else:
|
||||||
index = -1
|
index = -1
|
||||||
@@ -403,6 +402,19 @@ class ToolSelectPanelHelper:
|
|||||||
i += 1
|
i += 1
|
||||||
return None, -1
|
return None, -1
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _tool_group_active_get_from_item(cls, item):
|
||||||
|
index = cls._tool_group_active.get(item[0].idname, 0)
|
||||||
|
# Can happen in the case a group is dynamic.
|
||||||
|
#
|
||||||
|
# NOTE(Campbell): that in this case it's possible the order could change too,
|
||||||
|
# So if we want to support this properly we will need to switch away from using
|
||||||
|
# an index and instead use an ID.
|
||||||
|
# Currently this is such a rare case occurrence that a range check is OK for now.
|
||||||
|
if index >= len(item):
|
||||||
|
index = 0
|
||||||
|
return index
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _tool_group_active_set_by_id(cls, context, idname_group, idname):
|
def _tool_group_active_set_by_id(cls, context, idname_group, idname):
|
||||||
item_group = cls._tool_get_group_by_id(context, idname_group, coerce=True)
|
item_group = cls._tool_get_group_by_id(context, idname_group, coerce=True)
|
||||||
@@ -664,7 +676,7 @@ class ToolSelectPanelHelper:
|
|||||||
# not ideal, write this every time :S
|
# not ideal, write this every time :S
|
||||||
cls._tool_group_active[item[0].idname] = index
|
cls._tool_group_active[item[0].idname] = index
|
||||||
else:
|
else:
|
||||||
index = cls._tool_group_active.get(item[0].idname, 0)
|
index = cls._tool_group_active_get_from_item(item)
|
||||||
|
|
||||||
item = item[index]
|
item = item[index]
|
||||||
use_menu = True
|
use_menu = True
|
||||||
@@ -821,7 +833,8 @@ class ToolSelectPanelHelper:
|
|||||||
if is_active_tool:
|
if is_active_tool:
|
||||||
index_current = -1
|
index_current = -1
|
||||||
else:
|
else:
|
||||||
index_current = cls._tool_group_active.get(item_group[0].idname, 0)
|
index_current = cls._tool_group_active_get_from_item(item_group)
|
||||||
|
|
||||||
for i, sub_item in enumerate(item_group):
|
for i, sub_item in enumerate(item_group):
|
||||||
is_active = (i == index_current)
|
is_active = (i == index_current)
|
||||||
|
|
||||||
@@ -871,7 +884,7 @@ class ToolSelectPanelHelper:
|
|||||||
if is_active_tool:
|
if is_active_tool:
|
||||||
index_current = -1
|
index_current = -1
|
||||||
else:
|
else:
|
||||||
index_current = cls._tool_group_active.get(item_group[0].idname, 0)
|
index_current = cls._tool_group_active_get_from_item(item_group)
|
||||||
for i, sub_item in enumerate(item_group):
|
for i, sub_item in enumerate(item_group):
|
||||||
is_active = (i == index_current)
|
is_active = (i == index_current)
|
||||||
props = pie.operator(
|
props = pie.operator(
|
||||||
@@ -1023,7 +1036,7 @@ def activate_by_id_or_cycle(context, space_type, idname, *, offset=1, as_fallbac
|
|||||||
id_current = ""
|
id_current = ""
|
||||||
for item_group in cls.tools_from_context(context):
|
for item_group in cls.tools_from_context(context):
|
||||||
if type(item_group) is tuple:
|
if type(item_group) is tuple:
|
||||||
index_current = cls._tool_group_active.get(item_group[0].idname, 0)
|
index_current = cls._tool_group_active_get_from_item(item_group)
|
||||||
for sub_item in item_group:
|
for sub_item in item_group:
|
||||||
if sub_item.idname == idname:
|
if sub_item.idname == idname:
|
||||||
id_current = item_group[index_current].idname
|
id_current = item_group[index_current].idname
|
||||||
|
Reference in New Issue
Block a user