Skip to content

Commit

Permalink
Update visibility and label of the context menu correctly for tree pa…
Browse files Browse the repository at this point in the history
…rent tab #55
  • Loading branch information
piroor committed Aug 2, 2024
1 parent 032eaa9 commit 7c1b6f2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
8 changes: 6 additions & 2 deletions background/context-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,10 @@ async function onShown(info, tab) {
await context.resolve();

const multiselected = context.multiselectedTabs.length > 1;
const chooseFromMenu = (!multiselected && context.isTreeParent ? configs.modeForNoSelectionTree : configs.modeForNoSelection) == Constants.kCOPY_CHOOSE_FROM_MENU;
const chooseFromMenu = (
!multiselected &&
context.mode == Constants.kCOPY_CHOOSE_FROM_MENU
);
log('onShown ', {
chooseFromMenu,
isTreeParent: context.isTreeParent,
Expand All @@ -372,7 +375,8 @@ async function onShown(info, tab) {
!item.hiddenForTopLevelItem &&
configs[item.config] &&
hasMultipleVisibleItems &&
(context.shouldCopyMultipleTabs || (configs.modeForNoSelection != Constants.kCOPY_NOTHING))
(context.shouldCopyMultipleTabs ||
context.mode != Constants.kCOPY_NOTHING)
);
item.title = browser.i18n.getMessage(titleKey);
if (lastVisible == item.visible &&
Expand Down
30 changes: 20 additions & 10 deletions common/Context.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,24 @@ export class Context {
}

get menuItemTitleKey() {
// detect tree parent at first
if (this.isTreeParent &&
configs.modeForNoSelectionTree != Constants.kCOPY_INHERIT) {
return this.shouldCopyOnlyDescendants ?
'context_copyTreeDescendants_label' :
'context_copyTree_label';
if (this.multiselectedTabs.length > 1)
return 'context_copyTab_label';

if (this.shouldCopyAll)
return 'context_copyAllTabs_label';

if (this.mode == Constants.kCOPY_INDIVIDUAL_TAB ||
configs.modeForNoSelectionTree == Constants.kCOPY_INHERIT)
return 'context_copyTab_label';

if (this.isTreeParent) {
if (this.shouldCopyOnlyDescendants)
return 'context_copyTreeDescendants_label';

return 'context_copyTree_label';
}

return this.shouldCopyAll ?
'context_copyAllTabs_label' :
'context_copyTab_label';
return 'context_copyTab_label';
}

get isTreeParent() {
Expand Down Expand Up @@ -193,7 +200,10 @@ export class Context {

return this.$shouldCopyMultipleTabs = (
(this.isTreeParent &&
[...(this.shouldCopyOnlyDescendants ? [] : [this.tab]), ...(this.childTabs || this.descendantIds)]) ||
(this.mode == Constants.kCOPY_TREE ||
this.mode == Constants.kCOPY_TREE_DESCENDANTS) &&
[...(this.shouldCopyOnlyDescendants ? [] : [this.tab]),
...(this.childTabs || this.descendantIds)]) ||
this.multiselectedTabs
).length > 1;
}
Expand Down

0 comments on commit 7c1b6f2

Please sign in to comment.