Skip to content

Commit

Permalink
v3.5
Browse files Browse the repository at this point in the history
- Patched a folder creation bug on being unselected.
  • Loading branch information
humblerookie committed Sep 21, 2018
1 parent f5a2b12 commit b4e0ed5
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 30 deletions.
20 changes: 10 additions & 10 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<idea-plugin>
<id>com.hr.dimenify</id>
<name>Dimenify</name>
<version>3.4</version>
<version>3.5</version>
<vendor email="[email protected]" url="https://www.anvith.in">Anvith Bhat</vendor>

<description><![CDATA[
Expand All @@ -13,6 +13,8 @@
]]></description>

<change-notes><![CDATA[
<b>v3.5</b><br/>
- Patched a folder creation bug
<b>v3.4</b><br/>
- Removed max bucket restriction,now add as many as you like.
<b>v3.3</b><br/>
Expand Down Expand Up @@ -51,7 +53,7 @@
</change-notes>

<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html for description -->
<idea-version since-build="145.0"/>
<idea-version since-build="145.0" />

<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html
on how to target different products -->
Expand All @@ -66,18 +68,16 @@
<actions>
<!-- Add your actions here -->
<action id="generateDimens" class="com.hr.dimenify.action.GenerateSingleDimenAction"
text="Generate alternate dimens.."
icon="/icons/dimenify.png"
description="This generates dimensions for other density buckets">
<add-to-group group-id="GenerateGroup" anchor="last"/>
text="Generate alternate dimens.." icon="/icons/dimenify.png"
description="This generates dimensions for other density buckets">
<add-to-group group-id="GenerateGroup" anchor="last" />
</action>

<action id="rightClickDimenFile" class="com.hr.dimenify.action.BulkGenerateAction"
text="Generate alternate dimens from file"
icon="/icons/dimenify.png"
description="This generates dimensions for other density buckets">
text="Generate alternate dimens from file" icon="/icons/dimenify.png"
description="This generates dimensions for other density buckets">
<add-to-group group-id="ProjectViewPopupMenu" anchor="before"
relative-to-action="ProjectViewPopupMenuRefactoringGroup"/>
relative-to-action="ProjectViewPopupMenuRefactoringGroup" />
</action>
</actions>

Expand Down
60 changes: 40 additions & 20 deletions src/com/hr/dimenify/action/AbstractDimenAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,22 @@
import com.intellij.psi.xml.XmlFile;
import com.intellij.psi.xml.XmlTag;

import javax.swing.*;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.MessageFormat;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;

import static com.hr.dimenify.util.Constants.*;
import javax.swing.JDialog;
import javax.swing.JOptionPane;

import static com.hr.dimenify.util.Constants.MESSAGES;
import static com.hr.dimenify.util.Constants.MIGRATION_FLAG;
import static com.hr.dimenify.util.Constants.SAVE_PREFIX_V2;

public abstract class AbstractDimenAction extends AnAction {

Expand Down Expand Up @@ -100,32 +108,44 @@ protected void showAlert(int errorIndex) {

protected void createDirectoriesAndFilesIfNeeded(PsiDirectory psiParent) {
for (Dimen datum : data) {
WriteCommandAction.runWriteCommandAction(project, () -> {
PsiDirectory subDirectory = psiParent.findSubdirectory(datum.getDirectory());
if (subDirectory == null) {
subDirectory = psiParent.createSubdirectory(datum.getDirectory());
}
PsiFile file = subDirectory.findFile(Constants.FILE_NAME);
if (file == null) {
PsiFile psiFile = subDirectory.createFile(Constants.FILE_NAME);
Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
document.setText(Constants.RESOURCES_TEXT);
fileCreationCompleteAndCheck();

} else {
fileCreationCompleteAndCheck();
}
});
if (datum.isSelected()) {
WriteCommandAction.runWriteCommandAction(project, () -> {
PsiDirectory subDirectory = psiParent.findSubdirectory(datum.getDirectory());
if (subDirectory == null) {
subDirectory = psiParent.createSubdirectory(datum.getDirectory());
}
PsiFile file = subDirectory.findFile(Constants.FILE_NAME);
if (file == null) {
PsiFile psiFile = subDirectory.createFile(Constants.FILE_NAME);
Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
document.setText(Constants.RESOURCES_TEXT);
fileCreationCompleteAndCheck();

} else {
fileCreationCompleteAndCheck();
}
});
}
}
}

protected void fileCreationCompleteAndCheck() {
int value = fileCreationCount.incrementAndGet();
if (value == data.size()) {
if (value == getSelectedCount(data)) {
calculateAndWriteScaledValueToFiles();
}
}

private int getSelectedCount(ArrayList<Dimen> data) {
int selected = 0;
for (Dimen d : data) {
if (d.isSelected()) {
selected++;
}
}
return selected;
}

@Override
public void update(AnActionEvent e) {
final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
Expand Down

0 comments on commit b4e0ed5

Please sign in to comment.