-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from skyrylyuk/master
Custom prefix pattern and settings UI
- Loading branch information
Showing
6 changed files
with
276 additions
and
20 deletions.
There are no files selected for viewing
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
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,23 @@ | ||
package com.dd; | ||
|
||
import com.intellij.ide.projectView.PresentationData; | ||
import com.intellij.ide.projectView.ViewSettings; | ||
import com.intellij.ide.projectView.impl.nodes.PsiFileNode; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.psi.PsiFile; | ||
|
||
class FoldingNode extends PsiFileNode { | ||
private String mName; | ||
|
||
public FoldingNode(Project project, PsiFile value, ViewSettings viewSettings, String shortName) { | ||
super(project, value, viewSettings); | ||
mName = shortName; | ||
} | ||
|
||
@Override | ||
protected void updateImpl(PresentationData presentationData) { | ||
super.updateImpl(presentationData); | ||
|
||
presentationData.setPresentableText(mName); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.dd.SettingConfigurable"> | ||
<grid id="27dc6" binding="mPanel" default-binding="true" layout-manager="FormLayout"> | ||
<rowspec value="center:d:noGrow"/> | ||
<rowspec value="top:3dlu:noGrow"/> | ||
<rowspec value="center:max(d;4px):noGrow"/> | ||
<colspec value="fill:d:noGrow"/> | ||
<colspec value="left:4dlu:noGrow"/> | ||
<colspec value="fill:d:grow"/> | ||
<constraints> | ||
<xy x="20" y="20" width="500" height="400"/> | ||
</constraints> | ||
<properties/> | ||
<border type="none"/> | ||
<children> | ||
<component id="77c02" class="javax.swing.JCheckBox" binding="useCustomPatternCheckBox" default-binding="true"> | ||
<constraints> | ||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/> | ||
<forms/> | ||
</constraints> | ||
<properties> | ||
<text value="Use Custom Pattern"/> | ||
</properties> | ||
</component> | ||
<component id="e1fec" class="javax.swing.JTextField" binding="customPattern"> | ||
<constraints> | ||
<grid row="0" column="2" 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> | ||
<forms defaultalign-horz="false"/> | ||
</constraints> | ||
<properties> | ||
<enabled value="false"/> | ||
</properties> | ||
</component> | ||
<component id="5d684" class="javax.swing.JCheckBox" binding="hideFoldingPrefix"> | ||
<constraints> | ||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/> | ||
<forms/> | ||
</constraints> | ||
<properties> | ||
<selected value="false"/> | ||
<text value="Hide Folding Prefix"/> | ||
</properties> | ||
</component> | ||
</children> | ||
</grid> | ||
</form> |
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,118 @@ | ||
package com.dd; | ||
|
||
import com.intellij.ide.util.PropertiesComponent; | ||
import com.intellij.openapi.options.Configurable; | ||
import com.intellij.openapi.options.ConfigurationException; | ||
import org.jetbrains.annotations.Nls; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import javax.swing.*; | ||
import javax.swing.event.DocumentEvent; | ||
import javax.swing.event.DocumentListener; | ||
import java.awt.event.ActionEvent; | ||
import java.awt.event.ActionListener; | ||
|
||
/** | ||
* Created by skyrylyuk on 10/15/15. | ||
*/ | ||
public class SettingConfigurable implements Configurable { | ||
public static final String PREFIX_PATTERN = "folding_plugin_prefix_pattern"; | ||
public static final String PREFIX_CUSTOM_USE = "folding_plugin_prefix_custom_use"; | ||
public static final String PREFIX_HIDE = "folding_plugin_prefix_hide"; | ||
|
||
public static final String DEFAULT_PATTERN = "[^_]{1,}(?=_)"; | ||
public static final String DEFAULT_PATTERN_DOUBLE = "[^_]{1,}_[^_]{1,}(?=_)"; | ||
|
||
private JPanel mPanel; | ||
private JCheckBox useCustomPatternCheckBox; | ||
private JTextField customPattern; | ||
private JCheckBox hideFoldingPrefix; | ||
private boolean isModified = false; | ||
|
||
@Nls | ||
@Override | ||
public String getDisplayName() { | ||
return "Android Folding"; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public String getHelpTopic() { | ||
return "null:"; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public JComponent createComponent() { | ||
|
||
useCustomPatternCheckBox.addActionListener(new ActionListener() { | ||
public void actionPerformed(ActionEvent actionEvent) { | ||
boolean selected = getCheckBoxStatus(actionEvent); | ||
|
||
customPattern.setEnabled(selected); | ||
isModified = true; | ||
} | ||
}); | ||
|
||
customPattern.getDocument().addDocumentListener(new DocumentListener() { | ||
@Override | ||
public void insertUpdate(DocumentEvent e) { | ||
isModified = true; | ||
} | ||
|
||
@Override | ||
public void removeUpdate(DocumentEvent e) { | ||
isModified = true; | ||
} | ||
|
||
@Override | ||
public void changedUpdate(DocumentEvent e) { | ||
isModified = true; | ||
} | ||
}); | ||
|
||
hideFoldingPrefix.addActionListener(new ActionListener() { | ||
public void actionPerformed(ActionEvent actionEvent) { | ||
isModified = true; | ||
} | ||
}); | ||
|
||
reset(); | ||
|
||
return mPanel; | ||
} | ||
|
||
private boolean getCheckBoxStatus(ActionEvent actionEvent) { | ||
AbstractButton abstractButton = (AbstractButton) actionEvent.getSource(); | ||
return abstractButton.getModel().isSelected(); | ||
} | ||
|
||
|
||
@Override | ||
public boolean isModified() { | ||
|
||
return isModified; | ||
} | ||
|
||
@Override | ||
public void apply() throws ConfigurationException { | ||
PropertiesComponent.getInstance().setValue(PREFIX_CUSTOM_USE, Boolean.valueOf(useCustomPatternCheckBox.isSelected()).toString()); | ||
PropertiesComponent.getInstance().setValue(PREFIX_PATTERN, customPattern.getText()); | ||
PropertiesComponent.getInstance().setValue(PREFIX_HIDE, Boolean.valueOf(hideFoldingPrefix.isSelected()).toString()); | ||
|
||
isModified = false; | ||
} | ||
|
||
@Override | ||
public void reset() { | ||
final boolean customPrefix = PropertiesComponent.getInstance().getBoolean(PREFIX_CUSTOM_USE, false); | ||
useCustomPatternCheckBox.setSelected(customPrefix); | ||
customPattern.setEnabled(customPrefix); | ||
customPattern.setText(PropertiesComponent.getInstance().getValue(PREFIX_PATTERN, DEFAULT_PATTERN_DOUBLE)); | ||
hideFoldingPrefix.getModel().setSelected(PropertiesComponent.getInstance().getBoolean(PREFIX_HIDE, false)); | ||
} | ||
|
||
@Override | ||
public void disposeUIResources() { | ||
} | ||
} |