Merge pull request #3822 from pypeclub/bugfix/OP-3606_Skip-opening-last-work-file

Launcher: Skip opening last work file works for groups
This commit is contained in:
Ondřej Samohel 2022-09-09 17:39:49 +02:00 committed by GitHub
commit e84263524e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 23 deletions

View file

@ -281,18 +281,25 @@ class ActionModel(QtGui.QStandardItemModel):
if not action_item:
return
action = action_item.data(ACTION_ROLE)
actual_data = self._prepare_compare_data(action)
actions = action_item.data(ACTION_ROLE)
if not isinstance(actions, list):
actions = [actions]
action_actions_data = [
self._prepare_compare_data(action)
for action in actions
]
stored = self.launcher_registry.get_item("force_not_open_workfile")
if is_checked:
stored.append(actual_data)
else:
final_values = []
for config in stored:
if config != actual_data:
final_values.append(config)
stored = final_values
for actual_data in action_actions_data:
if is_checked:
stored.append(actual_data)
else:
final_values = []
for config in stored:
if config != actual_data:
final_values.append(config)
stored = final_values
self.launcher_registry.set_item("force_not_open_workfile", stored)
self.launcher_registry._get_item.cache_clear()
@ -329,21 +336,24 @@ class ActionModel(QtGui.QStandardItemModel):
item (QStandardItem)
stored (list) of dict
"""
action = item.data(ACTION_ROLE)
if not self.is_application_action(action):
actions = item.data(ACTION_ROLE)
if not isinstance(actions, list):
actions = [actions]
if not self.is_application_action(actions[0]):
return False
actual_data = self._prepare_compare_data(action)
action_actions_data = [
self._prepare_compare_data(action)
for action in actions
]
for config in stored:
if config == actual_data:
if config in action_actions_data:
return True
return False
def _prepare_compare_data(self, action):
if isinstance(action, list) and action:
action = action[0]
compare_data = {}
if action and action.label:
compare_data = {

View file

@ -312,11 +312,12 @@ class ActionBar(QtWidgets.QWidget):
is_group = index.data(GROUP_ROLE)
is_variant_group = index.data(VARIANT_GROUP_ROLE)
force_not_open_workfile = index.data(FORCE_NOT_OPEN_WORKFILE_ROLE)
if not is_group and not is_variant_group:
action = index.data(ACTION_ROLE)
# Change data of application action
if issubclass(action, ApplicationAction):
if index.data(FORCE_NOT_OPEN_WORKFILE_ROLE):
if force_not_open_workfile:
action.data["start_last_workfile"] = False
else:
action.data.pop("start_last_workfile", None)
@ -385,10 +386,18 @@ class ActionBar(QtWidgets.QWidget):
menu.addMenu(sub_menu)
result = menu.exec_(QtGui.QCursor.pos())
if result:
action = actions_mapping[result]
self._start_animation(index)
self.action_clicked.emit(action)
if not result:
return
action = actions_mapping[result]
if issubclass(action, ApplicationAction):
if force_not_open_workfile:
action.data["start_last_workfile"] = False
else:
action.data.pop("start_last_workfile", None)
self._start_animation(index)
self.action_clicked.emit(action)
class ActionHistory(QtWidgets.QPushButton):