Bug 1456849 - Part 1: Re-arrange the tool tabs if the visibility of command tools are changed. r=jdescottes

MozReview-Commit-ID: EzUfqRUdK6I

--HG--
extra : rebase_source : c108f7f183c8030d1ef44fa385e415b0209c22ad
This commit is contained in:
Daisuke Akatsuka 2018-04-29 10:52:10 +09:00
Родитель b52948e2af
Коммит bd4daf957a
3 изменённых файлов: 13 добавлений и 2 удалений

Просмотреть файл

@ -22,6 +22,7 @@ class ToolboxController extends Component {
this.state = { this.state = {
focusedButton: ELEMENT_PICKER_ID, focusedButton: ELEMENT_PICKER_ID,
toolboxButtons: [], toolboxButtons: [],
visibleToolboxButtonCount: 0,
currentToolId: null, currentToolId: null,
highlightedTools: new Set(), highlightedTools: new Set(),
panelDefinitions: [], panelDefinitions: [],
@ -172,7 +173,10 @@ class ToolboxController extends Component {
button.on("updatechecked", this.state.checkedButtonsUpdated); button.on("updatechecked", this.state.checkedButtonsUpdated);
}); });
this.setState({ toolboxButtons }, this.updateButtonIds); const visibleToolboxButtonCount =
toolboxButtons.filter(button => button.isVisible).length;
this.setState({ toolboxButtons, visibleToolboxButtonCount }, this.updateButtonIds);
} }
render() { render() {

Просмотреть файл

@ -28,6 +28,7 @@ class ToolboxTabs extends Component {
panelDefinitions: PropTypes.array, panelDefinitions: PropTypes.array,
selectTool: PropTypes.func, selectTool: PropTypes.func,
toolbox: PropTypes.object, toolbox: PropTypes.object,
visibleToolboxButtonCount: PropTypes.number.isRequired,
L10N: PropTypes.object, L10N: PropTypes.object,
onTabsOrderUpdated: PropTypes.func.isRequired, onTabsOrderUpdated: PropTypes.func.isRequired,
}; };
@ -94,7 +95,8 @@ class ToolboxTabs extends Component {
* Return true if we should update the overflowed tabs. * Return true if we should update the overflowed tabs.
*/ */
shouldUpdateToolboxTabs(prevProps, nextProps) { shouldUpdateToolboxTabs(prevProps, nextProps) {
if (prevProps.currentToolId !== nextProps.currentToolId) { if (prevProps.currentToolId !== nextProps.currentToolId ||
prevProps.visibleToolboxButtonCount !== nextProps.visibleToolboxButtonCount) {
return true; return true;
} }

Просмотреть файл

@ -76,6 +76,11 @@ class ToolboxToolbar extends Component {
toolbox: PropTypes.object, toolbox: PropTypes.object,
// Call back function to detect tabs order updated. // Call back function to detect tabs order updated.
onTabsOrderUpdated: PropTypes.func.isRequired, onTabsOrderUpdated: PropTypes.func.isRequired,
// Count of visible toolbox buttons which is used by ToolboxTabs component to
// recognize that the visibility of toolbox buttons were changed. Because in the
// component we cannot compare the visibility since the button definition instance
// in toolboxButtons will be unchanged.
visibleToolboxButtonCount: PropTypes.number,
}; };
} }