Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support appending template text to existing commit message #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified commit_template.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
]]></description>

<change-notes><![CDATA[
<p>1.0.3-mkempster-20171129</p>
<ul>
<li>Option to append template text to an existing commit message instead of completely overwriting.</li>
<li>Use case: Add crucible smart-commit macros to the default message.</li>
</ul>
<p>1.0.3</p>
<ul>
<li>Added the ability to set commentChar when loading template from file.</li>
Expand Down
24 changes: 15 additions & 9 deletions src/commitmessagetemplate/CommitMessageTemplateAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.vcs.CheckinProjectPanel;
import com.intellij.openapi.vcs.CommitMessageI;
import com.intellij.openapi.vcs.VcsDataKeys;
import com.intellij.openapi.vcs.ui.Refreshable;
Expand All @@ -39,7 +40,7 @@
public class CommitMessageTemplateAction extends AnAction implements DumbAware {

public void actionPerformed(AnActionEvent e) {
final CommitMessageI checkinPanel = getCheckinPanel(e);
final CheckinProjectPanel checkinPanel = getCheckinPanel(e);
if (checkinPanel == null) {
return;
}
Expand All @@ -50,25 +51,30 @@ public void actionPerformed(AnActionEvent e) {
if (config != null) {
String commitMessage = config.getCommitMessage();
if (!commitMessage.isEmpty()) {
checkinPanel.setCommitMessage(commitMessage);
if (config.getAppendMode()) {
checkinPanel.setCommitMessage(checkinPanel.getCommitMessage() + " " + commitMessage);
} else {
checkinPanel.setCommitMessage(commitMessage);
}
}
}
}


@Nullable
private static CommitMessageI getCheckinPanel(@Nullable AnActionEvent e) {
private static CheckinProjectPanel getCheckinPanel(@Nullable AnActionEvent e) {
if (e == null) {
return null;
}
Refreshable data = Refreshable.PANEL_KEY.getData(e.getDataContext());
if (data instanceof CommitMessageI) {
return (CommitMessageI) data;
}
CommitMessageI commitMessageI = VcsDataKeys.COMMIT_MESSAGE_CONTROL.getData(e.getDataContext());
if (commitMessageI != null) {
return commitMessageI;
if (data instanceof CheckinProjectPanel) {
return (CheckinProjectPanel) data;
}
// Unsure what to do with this. Can't get the current commitMessage from a commitMessageI.
// CommitMessageI commitMessageI = VcsDataKeys.COMMIT_MESSAGE_CONTROL.getData(e.getDataContext());
// if (commitMessageI != null) {
// return commitMessageI;
// }
return null;
}
}
8 changes: 8 additions & 0 deletions src/commitmessagetemplate/CommitMessageTemplateConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ String getCommentChar() {
return cmState.commentChar;
}

boolean getAppendMode() {
return cmState.append;
}
void setCommitMessage(String commitMessage) {
cmState.manualTemplate = commitMessage;
}
Expand All @@ -64,6 +67,10 @@ void setCommentChar(String commentChar) {
cmState.commentChar = commentChar;
}

void setAppend(boolean append) {
cmState.append = append;
}

@Nullable
@Override
public CommitState getState() {
Expand All @@ -85,6 +92,7 @@ public static class CommitState {
public boolean radioState = true;
public String templateFilePath = "";
public String commentChar = "";
public boolean append = false;
}

private String OpenFile(String configFilePath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<properties/>
<border type="none"/>
<children>
<grid id="4ee46" layout-manager="GridLayoutManager" row-count="6" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="4ee46" layout-manager="GridLayoutManager" row-count="7" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
Expand Down Expand Up @@ -54,22 +54,30 @@
</component>
<component id="dd5b2" class="javax.swing.JLabel" binding="commentCharLabel">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Comment character (leave empty to disable)"/>
</properties>
</component>
<component id="7f2f8" class="javax.swing.JTextField" binding="commentChar" default-binding="true">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<text value="#"/>
</properties>
</component>
<component id="f7a70" class="javax.swing.JCheckBox" binding="append">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Append to existing message"/>
</properties>
</component>
</children>
</grid>
</children>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class CommitMessageTemplateConfigurableGUI {
private TextFieldWithBrowseButton templateFilePath;
private JTextField commentChar;
private JLabel commentCharLabel;
private JCheckBox append;
private CommitMessageTemplateConfig config;
private FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFileDescriptor("txt");

Expand Down Expand Up @@ -55,6 +56,7 @@ public void actionPerformed(ActionEvent e) {
templateFilePath.setEnabled(!config.getRadioStatus());
commentChar.setEnabled(!config.getRadioStatus());
commentChar.setText(config.getCommentChar());
append.setSelected(config.getAppendMode());
}
}

Expand All @@ -66,14 +68,16 @@ boolean isModified() {
return !commitMessageTextBox.getText().equals(config.getManualTemplate()) ||
!setTemplateRadioButton.isSelected() == config.getRadioStatus() ||
!templateFilePath.getText().equals(config.getTemplateFilePath()) ||
!commentChar.getText().equals(config.getCommentChar());
!commentChar.getText().equals(config.getCommentChar()) ||
!append.isSelected() == config.getAppendMode();
}

void apply() {
config.setCommitMessage(commitMessageTextBox.getText());
config.setRadioStatus(setTemplateRadioButton.isSelected());
config.setTemplateFilePath(templateFilePath.getText());
config.setCommentChar(commentChar.getText());
config.setAppend(append.isSelected());
}

void reset() {
Expand All @@ -84,6 +88,7 @@ void reset() {
templateFilePath.setEnabled(!config.getRadioStatus());
commentChar.setEnabled(!config.getRadioStatus());
commentChar.setText(config.getCommentChar());
append.setSelected(config.getAppendMode());
}


Expand Down