Skip to content

Commit

Permalink
Add Select Tab Group context menu (#339)
Browse files Browse the repository at this point in the history
SEMVER_MAJOR
Fix #336
  • Loading branch information
asamuzaK authored Dec 28, 2024
1 parent 27b3682 commit 7b1ffa5
Show file tree
Hide file tree
Showing 10 changed files with 426 additions and 70 deletions.
29 changes: 19 additions & 10 deletions src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,20 @@
"message": "Dark Theme"
},
"detachTabFromGroup_menu": {
"message": "De&tach Tab from Group",
"message": "&Detach Tab from Group",
"placeholders": {
"key": {
"content": "$1",
"example": "(&T)"
"example": "(&D)"
}
}
},
"detachTabsFromGroup_menu": {
"message": "De&tach Tabs from Group",
"message": "&Detach Tabs from Group",
"placeholders": {
"key": {
"content": "$1",
"example": "(&T)"
"example": "(&D)"
}
}
},
Expand Down Expand Up @@ -258,29 +258,29 @@
"message": "Expand grouped tabs"
},
"groupSameContainerTabs_menu": {
"message": "Group Same Contai&ner Tabs",
"message": "Group Same Conta&iner Tabs",
"placeholders": {
"key": {
"content": "$1",
"example": "(&N)"
"example": "(&I)"
}
}
},
"groupSameDomainTabs_menu": {
"message": "Group Same &Domain Tabs",
"message": "Group Same Do&main Tabs",
"placeholders": {
"key": {
"content": "$1",
"example": "(&D)"
"example": "(&M)"
}
}
},
"groupSelectedTabs_menu": {
"message": "Group &Selected Tabs",
"message": "Group Selected &Tabs",
"placeholders": {
"key": {
"content": "$1",
"example": "(&S)"
"example": "(&T)"
}
}
},
Expand Down Expand Up @@ -771,6 +771,15 @@
}
}
},
"selectTabGroup_menu": {
"message": "&Select Tab Group",
"placeholders": {
"key": {
"content": "$1",
"example": "(&S)"
}
}
},
"showTabGroupLabel_menu": {
"message": "Show Group &Label",
"placeholders": {
Expand Down
19 changes: 14 additions & 5 deletions src/_locales/fa/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
"placeholders": {
"key": {
"content": "$1",
"example": "(&T)"
"example": "(&D)"
}
}
},
Expand All @@ -211,7 +211,7 @@
"placeholders": {
"key": {
"content": "$1",
"example": "(&T)"
"example": "(&D)"
}
}
},
Expand Down Expand Up @@ -262,7 +262,7 @@
"placeholders": {
"key": {
"content": "$1",
"example": "(&N)"
"example": "(&I)"
}
}
},
Expand All @@ -271,7 +271,7 @@
"placeholders": {
"key": {
"content": "$1",
"example": "(&D)"
"example": "(&M)"
}
}
},
Expand All @@ -280,7 +280,7 @@
"placeholders": {
"key": {
"content": "$1",
"example": "(&S)"
"example": "(&T)"
}
}
},
Expand Down Expand Up @@ -771,6 +771,15 @@
}
}
},
"selectTabGroup_menu": {
"message": "Select Tab Group $KEY$",
"placeholders": {
"key": {
"content": "$1",
"example": "(&S)"
}
}
},
"showTabGroupLabel_menu": {
"message": "نمایش نام گروه $KEY$",
"placeholders": {
Expand Down
19 changes: 14 additions & 5 deletions src/_locales/ja/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
"placeholders": {
"key": {
"content": "$1",
"example": "(&T)"
"example": "(&D)"
}
}
},
Expand All @@ -211,7 +211,7 @@
"placeholders": {
"key": {
"content": "$1",
"example": "(&T)"
"example": "(&D)"
}
}
},
Expand Down Expand Up @@ -262,7 +262,7 @@
"placeholders": {
"key": {
"content": "$1",
"example": "(&N)"
"example": "(&I)"
}
}
},
Expand All @@ -271,7 +271,7 @@
"placeholders": {
"key": {
"content": "$1",
"example": "(&D)"
"example": "(&M)"
}
}
},
Expand All @@ -280,7 +280,7 @@
"placeholders": {
"key": {
"content": "$1",
"example": "(&S)"
"example": "(&T)"
}
}
},
Expand Down Expand Up @@ -771,6 +771,15 @@
}
}
},
"selectTabGroup_menu": {
"message": "タブグループを選択$KEY$",
"placeholders": {
"key": {
"content": "$1",
"example": "(&S)"
}
}
},
"showTabGroupLabel_menu": {
"message": "グループのラベルを表示する$KEY$",
"placeholders": {
Expand Down
1 change: 1 addition & 0 deletions src/mjs/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export const TAB_GROUP_LABEL_EDIT = 'editTabGroupLabel';
export const TAB_GROUP_LABEL_HIDE = 'hideTabGroupLabel';
export const TAB_GROUP_LABEL_SHOW = 'showTabGroupLabel';
export const TAB_GROUP_NEW_TAB_AT_END = 'tabGroupPutNewTabAtTheEnd';
export const TAB_GROUP_SELECT = 'selectTabGroup';
export const TAB_GROUP_SELECTED = 'groupSelectedTabs';
export const TAB_GROUP_UNGROUP = 'ungroupTabs';
export const TAB_LIST = 'tabList';
Expand Down
12 changes: 8 additions & 4 deletions src/mjs/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
addListenersToHeadingItems, addTabContextClickListener, bookmarkTabGroup,
closeTabGroup, collapseTabGroups, detachTabsFromGroup, getTabGroupHeading,
groupSameContainerTabs, groupSameDomainTabs, groupSelectedTabs,
replaceTabContextClickListener, restoreTabContainers,
replaceTabContextClickListener, restoreTabContainers, selectTabGroup,
toggleAutoCollapsePinnedTabs, toggleTabGrouping,
toggleTabGroupCollapsedState, toggleTabGroupsCollapsedState,
toggleTabGroupHeadingState, ungroupTabs
Expand Down Expand Up @@ -71,8 +71,8 @@ import {
TAB_GROUP_COLLAPSE_OTHER, TAB_GROUP_CONTAINER, TAB_GROUP_DETACH,
TAB_GROUP_DETACH_TABS, TAB_GROUP_DOMAIN, TAB_GROUP_ENABLE,
TAB_GROUP_EXPAND_COLLAPSE_OTHER, TAB_GROUP_EXPAND_EXCLUDE_PINNED,
TAB_GROUP_LABEL_SHOW, TAB_GROUP_NEW_TAB_AT_END, TAB_GROUP_SELECTED,
TAB_GROUP_UNGROUP,
TAB_GROUP_LABEL_SHOW, TAB_GROUP_NEW_TAB_AT_END, TAB_GROUP_SELECT,
TAB_GROUP_SELECTED, TAB_GROUP_UNGROUP,
TAB_LIST, TAB_MOVE, TAB_MOVE_END, TAB_MOVE_START, TAB_MOVE_WIN, TAB_MUTE,
TAB_NEW, TAB_PIN, TAB_QUERY, TAB_RELOAD, TAB_REOPEN_CONTAINER,
TAB_REOPEN_NO_CONTAINER, TAB_SKIP_COLLAPSED, TAB_SWITCH_SCROLL,
Expand Down Expand Up @@ -1344,6 +1344,9 @@ export const handleClickedMenu = async info => {
func.push(toggleTabGroupHeadingState(heading, collapseOther));
}
break;
case TAB_GROUP_SELECT:
func.push(selectTabGroup(tab || heading));
break;
case TAB_GROUP_SELECTED:
func.push(
groupSelectedTabs(windowId).then(restoreTabContainers)
Expand Down Expand Up @@ -1667,7 +1670,7 @@ export const prepareTabGroupMenuItems = async (elm, opt) => {
TAB_GROUP_BOOKMARK, TAB_GROUP_CLOSE, TAB_GROUP_COLLAPSE,
TAB_GROUP_COLLAPSE_OTHER, TAB_GROUP_CONTAINER, TAB_GROUP_DETACH,
TAB_GROUP_DETACH_TABS, TAB_GROUP_DOMAIN, TAB_GROUP_LABEL_SHOW,
TAB_GROUP_SELECTED, TAB_GROUP_UNGROUP,
TAB_GROUP_SELECT, TAB_GROUP_SELECTED, TAB_GROUP_UNGROUP,
'sepTabGroup-1', 'sepTabGroup-2', 'sepTabGroup-3'
];
func.push(updateContextMenu(tabGroupMenu.id, {
Expand All @@ -1682,6 +1685,7 @@ export const prepareTabGroupMenuItems = async (elm, opt) => {
switch (itemKey) {
case TAB_GROUP_BOOKMARK:
case TAB_GROUP_CLOSE:
case TAB_GROUP_SELECT:
data.enabled = parentClass.contains(CLASS_TAB_GROUP);
data.title = title;
data.visible = true;
Expand Down
23 changes: 16 additions & 7 deletions src/mjs/menu-items.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
TAB_GROUP, TAB_GROUP_BOOKMARK, TAB_GROUP_CLOSE, TAB_GROUP_COLLAPSE,
TAB_GROUP_COLLAPSE_OTHER, TAB_GROUP_CONTAINER, TAB_GROUP_DETACH,
TAB_GROUP_DETACH_TABS, TAB_GROUP_DOMAIN, TAB_GROUP_EXPAND,
TAB_GROUP_LABEL_HIDE, TAB_GROUP_LABEL_SHOW, TAB_GROUP_SELECTED,
TAB_GROUP_UNGROUP,
TAB_GROUP_LABEL_HIDE, TAB_GROUP_LABEL_SHOW, TAB_GROUP_SELECT,
TAB_GROUP_SELECTED, TAB_GROUP_UNGROUP,
TAB_MOVE, TAB_MOVE_END, TAB_MOVE_START, TAB_MOVE_WIN, TAB_MUTE,
TAB_MUTE_UNMUTE, TAB_NEW, TAB_PIN, TAB_PIN_UNPIN, TAB_RELOAD,
TAB_REOPEN_CONTAINER, TAB_REOPEN_NO_CONTAINER,
Expand Down Expand Up @@ -407,9 +407,18 @@ export default {
enabled: false,
visible: true
},
[TAB_GROUP_SELECT]: {
id: TAB_GROUP_SELECT,
title: i18n.getMessage(`${TAB_GROUP_SELECT}_menu`, '(&S)'),
type: 'normal',
contexts: ['tab'],
viewTypes: ['sidebar'],
enabled: false,
visible: true
},
[TAB_GROUP_SELECTED]: {
id: TAB_GROUP_SELECTED,
title: i18n.getMessage(`${TAB_GROUP_SELECTED}_menu`, '(&S)'),
title: i18n.getMessage(`${TAB_GROUP_SELECTED}_menu`, '(&T)'),
type: 'normal',
contexts: ['tab'],
viewTypes: ['sidebar'],
Expand All @@ -418,7 +427,7 @@ export default {
},
[TAB_GROUP_CONTAINER]: {
id: TAB_GROUP_CONTAINER,
title: i18n.getMessage(`${TAB_GROUP_CONTAINER}_menu`, '(&N)'),
title: i18n.getMessage(`${TAB_GROUP_CONTAINER}_menu`, '(&I)'),
type: 'normal',
contexts: ['tab'],
viewTypes: ['sidebar'],
Expand All @@ -427,7 +436,7 @@ export default {
},
[TAB_GROUP_DOMAIN]: {
id: TAB_GROUP_DOMAIN,
title: i18n.getMessage(`${TAB_GROUP_DOMAIN}_menu`, '(&D)'),
title: i18n.getMessage(`${TAB_GROUP_DOMAIN}_menu`, '(&M)'),
type: 'normal',
contexts: ['tab'],
viewTypes: ['sidebar'],
Expand All @@ -436,7 +445,7 @@ export default {
},
[TAB_GROUP_DETACH]: {
id: TAB_GROUP_DETACH,
title: i18n.getMessage(`${TAB_GROUP_DETACH}_menu`, '(&T)'),
title: i18n.getMessage(`${TAB_GROUP_DETACH}_menu`, '(&D)'),
type: 'normal',
contexts: ['tab'],
viewTypes: ['sidebar'],
Expand All @@ -445,7 +454,7 @@ export default {
},
[TAB_GROUP_DETACH_TABS]: {
id: TAB_GROUP_DETACH_TABS,
title: i18n.getMessage(`${TAB_GROUP_DETACH_TABS}_menu`, '(&T)'),
title: i18n.getMessage(`${TAB_GROUP_DETACH_TABS}_menu`, '(&D)'),
type: 'normal',
contexts: ['tab'],
viewTypes: ['sidebar'],
Expand Down
29 changes: 28 additions & 1 deletion src/mjs/tab-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/* shared */
import { bookmarkTabs } from './bookmark.js';
import { getStorage, getTab, queryTabs } from './browser.js';
import { closeTabs, moveTabsInOrder } from './browser-tabs.js';
import { closeTabs, highlightTabs, moveTabsInOrder } from './browser-tabs.js';
import {
addElementContentEditable, getType, isObjectNotEmpty,
removeElementContentEditable, throwErr
Expand Down Expand Up @@ -540,6 +540,33 @@ export const bookmarkTabGroup = async node => {
return func || null;
};

/**
* select tab group
* @param {object} node - node
* @returns {Promise.<?Promise>} - highlightTabs()
*/
export const selectTabGroup = async node => {
const container = getSidebarTabContainer(node);
let func;
if (container) {
const items = container.querySelectorAll(TAB_QUERY);
if (items.length) {
const activeTab = document.querySelector(`${TAB_QUERY}.${ACTIVE}`);
container.classList.remove(CLASS_TAB_COLLAPSED);
if (activeTab?.parentNode === container) {
func = highlightTabs([...items]);
} else {
const [tab, ...group] = [...items];
const tabId = getSidebarTabId(tab);
func = highlightTabs(group, {
tabId
});
}
}
}
return func || null;
};

/**
* close tab group
* @param {object} node - node
Expand Down
Loading

0 comments on commit 7b1ffa5

Please sign in to comment.