Conversation
| Unknown = '' | ||
|
|
||
| CopyFileName = QObject.tr('Copy File Name') | ||
| CopyFilePath = QObject.tr('Copy file path') |
There was a problem hiding this comment.
On line 9 you capitalized all words, and here only one.
I think other interface capitalizes only the first word, can we make everything like that?
| if action_type is TabActionTypes.Close: | ||
| indices_to_close = [curr_tab] | ||
| elif action_type is TabActionTypes.CloseAll: | ||
| indices_to_close = list(range(last_tab + 1)) |
There was a problem hiding this comment.
Instead of last_tab + 1, maybe use total_tabs (here and below)?
| CloseOther = QObject.tr('Close Other Tabs') | ||
| CloseUnmodified = QObject.tr('Close Unmodified Tabs') | ||
| CloseToLeft = QObject.tr('Close Tabs to the Left') | ||
| CloseToRight = QObject.tr('Close Tabs to the Right') |
There was a problem hiding this comment.
Do we really need so many options? Are you going to use all them yourself?
| self._tabs_ctx_menu_actions = {} | ||
|
|
||
| for action_type in TabActionTypes: | ||
| if action_type is not TabActionTypes.Unknown: |
There was a problem hiding this comment.
Is there any reason to compare enum values with is / is not instead of == / !=?
|
|
||
| clicked_tab_index = self.tabWidget.tabBar().tabAt(p) | ||
| if -1 == clicked_tab_index: | ||
| raise RuntimeWarning(f"No tab found at [{p.x()};{p.y()}].") |
There was a problem hiding this comment.
You probably wanted to use warnings.warn() function instead of raise?
| self._handle_tab_context_action(chosen_action) | ||
|
|
||
| def _handle_tab_context_action(self, action): | ||
| if not action or action.text() == TabActionTypes.Unknown.value: |
There was a problem hiding this comment.
Can the action.text() == TabActionTypes.Unknown.value part ever happen? Do we need the Unknown enum member at all?
|
|
||
| self._init_tabs_context_menu() | ||
|
|
||
| def _init_tabs_context_menu(self): |
There was a problem hiding this comment.
Similarly to the other PR, please use camelCase and no leading underscore.
|
|
||
| indices_to_close.sort(reverse=True) | ||
|
|
||
| for tab_num in indices_to_close: |
There was a problem hiding this comment.
If you use reversed(indices_to_close) here, then you won’t need to convert ranges to lists.
| @@ -0,0 +1,18 @@ | |||
| from enum import StrEnum | |||
There was a problem hiding this comment.
StrEnum was introduced in Python 3.11, so if you want to use that, we would need to bump required Python version to 3.11. Please do that in a separate PR.
Or use simple Enum.
| indices_to_close = [i for i in range(last_tab + 1) if i != curr_tab] | ||
| elif action_type is TabActionTypes.CloseUnmodified: | ||
| indices_to_close = [i for i in range(last_tab + 1) | ||
| if i != curr_tab and not self.tabWidget.widget(i).editBox.document().isModified()] |
There was a problem hiding this comment.
Just a suggestion: you can also use iterateTabs() method, maybe that will be a bit shorter.
This PR introduces a tab's RMB-click menu with dynamically available actions for copying file location info and advanced closing options: