package gitflow;

import com.intellij.dvcs.DvcsUtil;
import com.intellij.openapi.components.ProjectComponent;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
import com.intellij.openapi.vcs.VcsListener;
import com.intellij.openapi.wm.StatusBar;
import com.intellij.openapi.wm.WindowManager;
import com.intellij.util.messages.MessageBus;
import gitflow.ui.GitflowWidget;
import org.jetbrains.annotations.NotNull;

/**
 * @author Opher Vishnia / opherv.com / opherv@gmail.com
 */
public class GitflowComponent implements ProjectComponent, VcsListener {
    Project myProject;
    GitflowWidget myGitflowWidget;
    MessageBus messageBus;

    public GitflowComponent(Project project) {
        myProject = project;
    }

    public void initComponent() {
        messageBus = myProject.getMessageBus();
        messageBus.connect().subscribe(ProjectLevelVcsManager.VCS_CONFIGURATION_CHANGED, this);
    }

    public void disposeComponent() {
        // TODO: insert component disposal logic here
    }

    @NotNull
    public String getComponentName() {
        return "GitflowComponent";
    }

    public void projectOpened() {

    }

    public void projectClosed() {

    }

    @Override
    public void directoryMappingChanged() {
        //git repo present
        if (ProjectLevelVcsManager.getInstance(myProject).getAllVcsRoots().length>0){
            myGitflowWidget  = new GitflowWidget(myProject);
            StatusBar statusBar = WindowManager.getInstance().getStatusBar(myProject);
            if (statusBar != null) {
                statusBar.addWidget(myGitflowWidget, "after " + git4idea.ui.branch.GitBranchWidget.class.getName(), myProject);
            }
        }
        else{
            if (myGitflowWidget!=null){
                DvcsUtil.removeStatusBarWidget(myProject, myGitflowWidget);
            }
            myGitflowWidget = null;
        }
    }
}
@@ -298,24 +298,66 @@
 sListener;%0D%0A
+import com.intellij.openapi.vcs.VcsRoot;%0D%0A
 import com.i
@@ -481,16 +481,41 @@
 geBus;%0D%0A
+import git4idea.GitVcs;%0D%0A
 import g
@@ -1459,40 +1459,27 @@
     
-//git repo present%0D%0A        if (
+VcsRoot%5B%5D vcsRoots=
 Proj
@@ -1540,19 +1540,116 @@
 ts()
-.length%3E0)%7B
+;%0D%0A%0D%0A        //git repo present%0D%0A        if (vcsRoots.length%3E0 && vcsRoots%5B0%5D.getVcs() instanceof GitVcs)%7B%0D%0A
 %0D%0A  

Make sure to only show the widget when a git VCS is present