generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db151ee
commit 4f7d6fc
Showing
5 changed files
with
83 additions
and
5 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
src/main/java/com/lilittlecat/plugin/action/PanguFormatActionPromoter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.lilittlecat.plugin.action; | ||
|
||
import com.intellij.openapi.actionSystem.ActionPromoter; | ||
import com.intellij.openapi.actionSystem.AnAction; | ||
import com.intellij.openapi.actionSystem.DataContext; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @author LiLittleCat | ||
* @since 2022/8/11 | ||
*/ | ||
public class PanguFormatActionPromoter implements ActionPromoter { | ||
@Override | ||
public List<AnAction> promote(List<AnAction> actions, DataContext context) { | ||
// todo, order actions use the same key shortcut | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/java/com/lilittlecat/plugin/action/PanguFormatVCSCommitMessageAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.lilittlecat.plugin.action; | ||
|
||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
import com.intellij.openapi.project.DumbAwareAction; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.vcs.CommitMessageI; | ||
import com.intellij.openapi.vcs.VcsDataKeys; | ||
import com.intellij.openapi.vcs.ui.CommitMessage; | ||
import com.lilittlecat.plugin.pangu.Pangu; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* Pangy format commit message action. | ||
* todo, keymap won't work in commit dialog | ||
* | ||
* @author LiLittleCat | ||
* @see com.intellij.openapi.vcs.actions.ShowMessageHistoryAction | ||
* @since 2022/8/11 | ||
*/ | ||
public class PanguFormatVCSCommitMessageAction extends DumbAwareAction { | ||
|
||
public static final Integer ORDER = 1; | ||
|
||
@Override | ||
public void update(@NotNull AnActionEvent e) { | ||
Project project = e.getProject(); | ||
CommitMessage commitMessage = getCommitMessage(e); | ||
e.getPresentation().setVisible(project != null && commitMessage != null); | ||
} | ||
|
||
@Override | ||
public void actionPerformed(@NotNull AnActionEvent e) { | ||
final CommitMessage commitMessage = getCommitMessage(e); | ||
if (commitMessage != null) { | ||
commitMessage.setCommitMessage(new Pangu().formatText(commitMessage.getComment())); | ||
} | ||
} | ||
|
||
private CommitMessage getCommitMessage(AnActionEvent e) { | ||
CommitMessageI data = VcsDataKeys.COMMIT_MESSAGE_CONTROL.getData(e.getDataContext()); | ||
if (data instanceof CommitMessage) { | ||
return (CommitMessage) data; | ||
} else { | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters