Save last sidebar tool

This commit is contained in:
RumovZ 2021-02-25 11:35:31 +01:00
parent fd784adc31
commit 0889972bb0

View file

@ -254,17 +254,22 @@ class SidebarToolbar(QToolBar):
self.sidebar = sidebar self.sidebar = sidebar
self._action_group = QActionGroup(self) self._action_group = QActionGroup(self)
qconnect(self._action_group.triggered, self._on_action_group_triggered) qconnect(self._action_group.triggered, self._on_action_group_triggered)
self._add_tools() self._setup_tools()
def _add_tools(self) -> None: def _setup_tools(self) -> None:
for row in self._tools: for row in self._tools:
action = self.addAction(theme_manager.icon_from_resources(row[1]), row[2]) action = self.addAction(theme_manager.icon_from_resources(row[1]), row[2])
action.setCheckable(True) action.setCheckable(True)
self._action_group.addAction(action) self._action_group.addAction(action)
saved = self.sidebar.col.get_config("sidebarTool", 0)
active = saved if saved < len(self._tools) else 0
self._action_group.actions()[active].setChecked(True)
self.sidebar.tool = self._tools[active][0]
def _on_action_group_triggered(self, action) -> None: def _on_action_group_triggered(self, action) -> None:
tool = self._tools[self._action_group.actions().index(action)][0] index = self._action_group.actions().index(action)
self.sidebar.tool = tool self.sidebar.col.set_config("sidebarTool", index)
self.sidebar.tool = self._tools[index][0]
class SidebarSearchBar(QLineEdit): class SidebarSearchBar(QLineEdit):
@ -371,8 +376,6 @@ class SidebarTreeView(QTreeView):
@tool.setter @tool.setter
def tool(self, tool: SidebarTool) -> None: def tool(self, tool: SidebarTool) -> None:
if self._tool == tool:
return
self._tool = tool self._tool = tool
if tool == SidebarTool.SELECT: if tool == SidebarTool.SELECT:
# pylint: disable=no-member # pylint: disable=no-member