-
Notifications
You must be signed in to change notification settings - Fork 204
Tabs' Context Menu #659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Tabs' Context Menu #659
Conversation
Unknown = '' | ||
|
||
CopyFileName = QObject.tr('Copy File Name') | ||
CopyFilePath = QObject.tr('Copy file path') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the action.text() == TabActionTypes.Unknown.value
part ever happen? Do we need the Unknown
enum member at all?
@@ -519,6 +520,107 @@ def dropEvent(e): | |||
self.tabWidget.dropEvent = dropEvent | |||
self.tabWidget.setTabBarAutoHide(globalSettings.tabBarAutoHide) | |||
|
|||
self._init_tabs_context_menu() | |||
|
|||
def _init_tabs_context_menu(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: