/*
 * Copyright 2000-2015 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.vcs.log.ui.actions;

import com.intellij.icons.AllIcons;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.vcs.log.VcsLogDataKeys;
import com.intellij.vcs.log.VcsLogFilterCollection;
import com.intellij.vcs.log.VcsLogUi;
import com.intellij.vcs.log.impl.VcsLogManager;
import com.intellij.vcs.log.impl.VcsProjectLog;
import com.intellij.vcs.log.statistics.VcsLogUsageTriggerCollector;
import com.intellij.vcs.log.ui.VcsLogInternalDataKeys;
import com.intellij.vcs.log.visible.filters.VcsLogFilterObject;
import org.jetbrains.annotations.NotNull;

public class OpenAnotherLogTabAction extends DumbAwareAction {
  protected OpenAnotherLogTabAction() {
    super("Open Another Log Tab", "Open another log tab", AllIcons.Actions.OpenNewTab);
  }

  @Override
  public void update(@NotNull AnActionEvent e) {
    Project project = e.getProject();
    if (project == null) {
      e.getPresentation().setEnabledAndVisible(false);
      return;
    }
    VcsProjectLog projectLog = VcsProjectLog.getInstance(project);
    VcsLogManager logManager = e.getData(VcsLogInternalDataKeys.LOG_MANAGER);
    VcsLogUi logUi = e.getData(VcsLogDataKeys.VCS_LOG_UI);
    // only for main log (it is a question, how and where we want to open tabs for external logs)
    e.getPresentation().setEnabledAndVisible(logManager != null && projectLog.getLogManager() == logManager && logUi != null);
  }

  @Override
  public void actionPerformed(@NotNull AnActionEvent e) {
    VcsLogUsageTriggerCollector.triggerUsage(e, this);

    Project project = e.getRequiredData(CommonDataKeys.PROJECT);
    VcsLogUi logUi = e.getRequiredData(VcsLogDataKeys.VCS_LOG_UI);
    VcsLogFilterCollection filters = Registry.is("vcs.log.copy.filters.to.new.tab") ? logUi.getFilterUi().getFilters()
                                                                                    : VcsLogFilterObject.collection();
    VcsProjectLog.getInstance(project).openLogTab(filters);
  }
}

@@ -1941,67 +1941,8 @@
 R);%0A
-    VcsLogUi logUi = e.getData(VcsLogDataKeys.VCS_LOG_UI);%0A
     
@@ -2035,16 +2035,48 @@
 l logs)%0A
+    if (logManager != null) %7B%0A  
     e.ge
@@ -2116,30 +2116,8 @@
 ble(
-logManager != null && 
 proj
@@ -2156,17 +2156,101 @@
 ager
- && logUi
+);%0A    %7D%0A    else %7B%0A      e.getPresentation().setEnabledAndVisible(projectLog.getLogManager()
  != 
@@ -2256,16 +2256,22 @@
  null);%0A
+    %7D%0A
   %7D%0A%0A  @
@@ -2480,32 +2480,24 @@
 ogUi = e.get
-Required
 Data(VcsLogD
@@ -2517,16 +2517,17 @@
 OG_UI);%0A
+%0A
     VcsL
@@ -2552,19 +2552,26 @@
  filters
- = 
+;%0A    if (
 Registry
@@ -2613,9 +2613,43 @@
 b%22) 
-?
+&& logUi != null) %7B%0A      filters =
  log
@@ -2681,94 +2681,42 @@
 rs()
+;
 %0A    
+%7D%0A
     
-                                                                            :
+else %7B%0A      filters =
  Vcs
@@ -2741,24 +2741,31 @@
 llection();%0A
+    %7D%0A%0A
     VcsProje

enable open another log tab action when log is not visible