package gitlog;

import com.intellij.openapi.components.AbstractProjectComponent;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.startup.StartupManager;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowManager;
import git4idea.GitUtil;
import git4idea.repo.GitRepository;
import git4idea.repo.GitRepositoryManager;
import git4idea.repo.GitRepositoryManagerImpl;
import org.hanuna.gitalk.swing_ui.Swing_UI;
import org.hanuna.gitalk.ui.impl.UI_ControllerImpl;

import javax.swing.*;

/**
 * @author Kirill Likhodedov
 */
public class GitLogComponent extends AbstractProjectComponent {

  private final Project myProject;
  private GitRepositoryManager myRepositoryManager;
  private GitRepository myRepository;
  private Swing_UI mySwingUi;
  private UI_ControllerImpl myUiController;

  protected GitLogComponent(Project project, GitRepositoryManager repositoryManager) {
    super(project);
    myProject = project;
  }

  @Override
  public void initComponent() {
    super.initComponent();

    myRepositoryManager = GitUtil.getRepositoryManager(myProject);
    ((GitRepositoryManagerImpl)myRepositoryManager).updateRepositoriesCollection();
    myRepository = myRepositoryManager.getRepositories().get(0);

    StartupManager.getInstance(myProject).registerPostStartupActivity(new Runnable() {
      @Override
      public void run() {
        myUiController = new UI_ControllerImpl(myProject);
        mySwingUi = new Swing_UI(myUiController);
        myUiController.addControllerListener(mySwingUi.getControllerListener());
        myUiController.setDragDropListener(mySwingUi.getDragDropListener());
        myUiController.init(false);

        final ToolWindow toolWindow = ToolWindowManager.getInstance(myProject).getToolWindow("Git Log");
        if (toolWindow != null && toolWindow.isActive()) {
          toolWindow.activate(null);
        }
      }
    });
  }

  public JPanel getMainGitAlkComponent() {
    return mySwingUi.getMainFrame().getMainComponent();
  }

  public GitRepository getRepository() {
    return myRepository;
  }

  public UI_ControllerImpl getUiController() {
    return myUiController;
  }
}

@@ -120,16 +120,71 @@
 roject;%0A
+import com.intellij.openapi.roots.impl.DirectoryIndex;%0A
 import c
@@ -893,16 +893,56 @@
 oller;%0A%0A
+  @SuppressWarnings(%22UnusedParameters%22)%0A
   protec
@@ -999,17 +999,25 @@
 Manager 
-r
+makeSureR
 epositor
@@ -1024,16 +1024,100 @@
 yManager
+IsInitialized,%0A                            DirectoryIndex makeSureIndexIsInitialized
 ) %7B%0A    
@@ -1230,24 +1230,157 @@
 mponent();%0A%0A
+    StartupManager.getInstance(myProject).registerPostStartupActivity(new Runnable() %7B%0A      @Override%0A      public void run() %7B%0A    
     myReposi
@@ -1430,24 +1430,28 @@
 myProject);%0A
+    
     ((GitRep
@@ -1522,16 +1522,20 @@
 tion();%0A
+    
     myRe
@@ -1596,137 +1596,8 @@
 );%0A%0A
-    StartupManager.getInstance(myProject).registerPostStartupActivity(new Runnable() %7B%0A      @Override%0A      public void run() %7B%0A
     

Fix DirectoryIndex exception on startup: make sure the Index is initialized before.