MOBILE-2319 contextmenu: Don't merge menus from different tabs

main
Dani Palou 2018-03-20 13:03:35 +01:00
parent d29712258a
commit d8be7efbc6
2 changed files with 8 additions and 5 deletions

View File

@ -12,12 +12,13 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { Component, Input, OnInit, OnDestroy, ElementRef } from '@angular/core'; import { Component, Input, OnInit, OnDestroy, ElementRef, Optional } from '@angular/core';
import { PopoverController } from 'ionic-angular'; import { PopoverController } from 'ionic-angular';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { CoreDomUtilsProvider } from '@providers/utils/dom'; import { CoreDomUtilsProvider } from '@providers/utils/dom';
import { CoreContextMenuItemComponent } from './context-menu-item'; import { CoreContextMenuItemComponent } from './context-menu-item';
import { CoreContextMenuPopoverComponent } from './context-menu-popover'; import { CoreContextMenuPopoverComponent } from './context-menu-popover';
import { CoreTabComponent } from '@components/tabs/tab';
import { Subject } from 'rxjs'; import { Subject } from 'rxjs';
/** /**
@ -40,7 +41,7 @@ export class CoreContextMenuComponent implements OnInit, OnDestroy {
protected parentContextMenu: CoreContextMenuComponent; protected parentContextMenu: CoreContextMenuComponent;
constructor(private translate: TranslateService, private popoverCtrl: PopoverController, elementRef: ElementRef, constructor(private translate: TranslateService, private popoverCtrl: PopoverController, elementRef: ElementRef,
private domUtils: CoreDomUtilsProvider) { private domUtils: CoreDomUtilsProvider, @Optional() public coreTab: CoreTabComponent) {
// Create the stream and subscribe to it. We ignore successive changes during 250ms. // Create the stream and subscribe to it. We ignore successive changes during 250ms.
this.itemsChangedStream = new Subject<void>(); this.itemsChangedStream = new Subject<void>();
this.itemsChangedStream.auditTime(250).subscribe(() => { this.itemsChangedStream.auditTime(250).subscribe(() => {

View File

@ -134,10 +134,12 @@ export class CoreNavBarButtonsComponent implements OnInit, OnDestroy {
} }
// Both containers have a context menu. Merge them to prevent having 2 menus at the same time. // Both containers have a context menu. Merge them to prevent having 2 menus at the same time.
const mainContextMenuInstance = this.domUtils.getInstanceByElement(mainContextMenu), const mainContextMenuInstance: CoreContextMenuComponent = this.domUtils.getInstanceByElement(mainContextMenu),
secondaryContextMenuInstance = this.domUtils.getInstanceByElement(secondaryContextMenu); secondaryContextMenuInstance: CoreContextMenuComponent = this.domUtils.getInstanceByElement(secondaryContextMenu);
if (mainContextMenuInstance && secondaryContextMenuInstance) { // Check that both context menus belong to the same core-tab. We shouldn't merge menus from different tabs.
if (mainContextMenuInstance && secondaryContextMenuInstance &&
mainContextMenuInstance.coreTab === secondaryContextMenuInstance.coreTab) {
this.mergedContextMenu = secondaryContextMenuInstance; this.mergedContextMenu = secondaryContextMenuInstance;
this.mergedContextMenu.mergeContextMenus(mainContextMenuInstance); this.mergedContextMenu.mergeContextMenus(mainContextMenuInstance);