Skip to content

Commit

Permalink
Merge pull request ualberta-smr#2 from ualberta-smr/noFactory
Browse files Browse the repository at this point in the history
Implemented tool window and context menu action + improved instantiation
  • Loading branch information
kpatenio authored Jul 30, 2020
2 parents f6c228e + c24236b commit 2dd405e
Show file tree
Hide file tree
Showing 19 changed files with 707 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
no.conflict.show.explanations = No merge conflicts found in this file.
toolwindow.button.show.log = Show Log
toolwindow.id = Explain Merge Conflict
toolwindow.label.ours = Ours
toolwindow.label.theirs = Theirs
toolwindow.tooltip.description = Explains any existing merge conflicts.
74 changes: 74 additions & 0 deletions out/production/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<idea-plugin url="https://github.com/ualberta-smr/ExplainMergeConflict">
<id>org.ualberta.smr.explainmergeconflict</id>
<name>ExplainMergeConflict</name>
<vendor
url="https://github.com/ualberta-smr/ExplainMergeConflict">The
Software Maintenance and Reuse (SMR) Lab
</vendor>
<version>2020.1-1.1</version>

<description><![CDATA[
]]></description>

<depends>com.intellij.modules.platform</depends>
<depends>com.intellij.modules.java</depends>
<depends>com.intellij.modules.lang</depends>
<depends>Git4Idea</depends>

<extensions defaultExtensionNs="com.intellij">
<projectConfigurable parentId="tools"
instance="org.jetbrains.research.refactorinsight.services.SettingsConfigurable"
id="services.SettingsConfigurable"
displayName="RefactorInsight"/>

<diff.DiffExtension implementation="org.jetbrains.research.refactorinsight.ui.windows.DiffWindow"/>

<projectService serviceImplementation="org.jetbrains.research.refactorinsight.services.MiningService"/>
<projectService serviceImplementation="org.jetbrains.research.refactorinsight.services.WindowService"/>
<projectService serviceImplementation="org.jetbrains.research.refactorinsight.services.SettingsState"/>

<errorHandler implementation="org.jetbrains.research.refactorinsight.reporter.RefactorInsightErrorReporter"/>

<toolWindow id="Explain Merge Conflict" anchor="right"
factoryClass="org.ualberta.smr.explainmergeconflict.ui.ExplanationsToolWindowFactory"/>
</extensions>

<actions>
<action id="actions.ToggleRefactoringViewAction"
class="org.jetbrains.research.refactorinsight.actions.ToggleRefactoringViewAction"
icon="RefactorInsightIcons.toggle"
text="Show Refactorings" description="actions.ToggleRefactoringViewAction">
<add-to-group group-id="Vcs.Log.ChangesBrowser.Toolbar" anchor="first"/>
</action>

<action id="RefAction" class="org.jetbrains.research.refactorinsight.actions.RefactoringAction"
text="Mine All Refactorings"
description="Clear refactoring cache">
<add-to-group group-id="ToolsMenu" anchor="first"/>
</action>

<action id="actions.RefactoringHistoryAction"
class="org.jetbrains.research.refactorinsight.actions.RefactoringHistoryAction"
text="Check Refactoring History"
description="Retrieve refactorings history for this method">
<add-to-group group-id="EditorPopupMenu1" anchor="first"/>
<keyboard-shortcut first-keystroke="control alt R" keymap="$default"/>
</action>

<action id="ShowExplanationsToolWindowAction"
class="org.ualberta.smr.explainmergeconflict.actions.ShowExplanationsToolWindowAction"
text="Explain Merge Conflict"
description="Display merge conflict explanations for this file">
<add-to-group group-id="EditorPopupMenu" anchor="last"/>
</action>
</actions>

<projectListeners>
<listener class="org.jetbrains.research.refactorinsight.processors.CommitListener"
topic="git4idea.repo.GitRepositoryChangeListener"/>
<listener class="org.jetbrains.research.refactorinsight.processors.ProjectListener"
topic="com.intellij.openapi.project.ProjectManagerListener"/>
</projectListeners>

</idea-plugin>
8 changes: 8 additions & 0 deletions out/production/resources/META-INF/pluginIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions out/production/resources/RefactoringsBundle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version=1.1.2
name=RefactorInsight
no.ref.history=No refactorings detected for this element.
no.repo=Your project is not connected to VCS.
progress=Mining refactorings %d/%d
mining=Mining refactorings
finished=Mining done
mining.at=Mining commit %s
setting=RefactorInsight
history=Refactoring History
click.to.jump=Double click to jump at commit.
how.many.detected=%d refactoring%s detected for this %s
check.methods=Check methods in this class
check.fields=Check fields in this class
bad.file=File not supported.
label.max.commits=Max commits to mine:
label.max.history=Max commits to compute history for:
label.threads=Number of threads to use for mining:
button.clear=Clear Cache
button.mine=Mine all
button.import=Import xml
change.rename.attribute=Rename and Change Attribute Type
rename.attribute=Rename Attribute
change.attribute=Change Attribute Type
change.rename.var=Rename and Change Variable Type
change.rename.param=Rename and Change Parameter Type
5 changes: 5 additions & 0 deletions out/production/resources/icons/refactorInsightNode.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions out/production/resources/icons/refactorInsightToggle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions out/production/resources/icons/refactorInsightToggle_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions out/production/resources/icons/refactorInsightToolWindow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.ualberta.smr.explainmergeconflict.actions;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.ui.components.JBLabel;
import com.intellij.ui.components.JBPanel;
import com.sun.istack.NotNull;
import git4idea.repo.GitRepository;
import org.ualberta.smr.explainmergeconflict.services.ExplainMergeConflictBundle;
import org.ualberta.smr.explainmergeconflict.services.UIController;
import org.ualberta.smr.explainmergeconflict.utils.Utils;

import java.awt.GridLayout;

public class ShowExplanationsToolWindowAction extends AnAction {
@Override
public void update(AnActionEvent e) {
GitRepository repo = Utils.getCurrentRepository(e.getProject());
e.getPresentation().setVisible(repo != null && Utils.isInConflictState(repo));

// System.out.println(e.getDataContext());
}

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
GitRepository repo = Utils.getCurrentRepository(e.getProject());

// TODO - show popup only for files without conflicts
// Ideally, action should not be visible if no conflicts are found
if (!Utils.isInConflictState(repo)) {
showPopup(e.getDataContext());
return;
}

UIController.updateToolWindowAfterAction(repo);
}

// Reference: RefactoringHistoryToolbar.java
private void showPopup(DataContext datacontext) {
JBPanel panel = new JBPanel(new GridLayout(0, 1));
panel.add(new JBLabel(ExplainMergeConflictBundle.message("no.conflict.show.explanations")));
JBPopup popup = JBPopupFactory.getInstance()
.createComponentPopupBuilder(panel, null).createPopup();
popup.showInBestPositionFor(datacontext);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.ualberta.smr.explainmergeconflict.processors;

import git4idea.repo.GitConflictsHolder;
import git4idea.repo.GitRepository;
import org.jetbrains.annotations.NotNull;
import org.ualberta.smr.explainmergeconflict.services.ExplainMergeConflictBundle;
import org.ualberta.smr.explainmergeconflict.services.UIController;
import org.ualberta.smr.explainmergeconflict.utils.Utils;

/**
* Used by ExplainMergeConflict to listen for merge conflicts. Once a
* conflict is detected, register the Explain Merge Conflict tool window and
* set the Explain Merge Conflict action to visible in context menus.
*/
public class ConflictStateListener implements GitConflictsHolder.ConflictsListener {
@Override
public void conflictsChanged(@NotNull GitRepository repository) {
System.out.println("Conflict change listener triggered from " +
"ConflictStateListener service");

if (!Utils.isInConflictState(repository)) {
System.out.println("No conflicts detected");
UIController.updateToolWindowAfterNonConflictState(repository);
} else {
System.out.println("Conflicts detected");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.ualberta.smr.explainmergeconflict.services;

import com.intellij.AbstractBundle;
import com.intellij.reference.SoftReference;
import org.jetbrains.annotations.PropertyKey;

import java.lang.ref.Reference;
import java.util.ResourceBundle;

public class ExplainMergeConflictBundle {
private static final String BUNDLE = "ExplainMergeConflictBundle";
private static Reference<ResourceBundle> INSTANCE;

private ExplainMergeConflictBundle() {
}

public static String message(@PropertyKey(resourceBundle = BUNDLE) String key, Object... params) {
return AbstractBundle.message(getBundle(), key, params);
}

private static ResourceBundle getBundle() {
ResourceBundle bundle = SoftReference.dereference(INSTANCE);
if (bundle == null) {
bundle = ResourceBundle.getBundle(BUNDLE);
INSTANCE = new SoftReference<>(bundle);
}
return bundle;
}
}
Loading

0 comments on commit 2dd405e

Please sign in to comment.