Skip to content

Commit

Permalink
Improve import action (#6)
Browse files Browse the repository at this point in the history
* Fixes virtual file refresh after update
* Add duplicated suffixes validation
  • Loading branch information
abeade authored Feb 28, 2022
1 parent c41360f commit 9a2c492
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@

### Fixed

## [1.1.1] - 2022-02-27
### Added
- Duplicated suffixes validation

### Fixed
- Fixed file system refresh after files import

## [1.1.0] - 2022-02-02
### Added
- Support for drawable folder modifiers
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
pluginGroup = com.abeade.plugin.figma
pluginName = figma-import-plugin
# SemVer format -> https://semver.org
pluginVersion = 1.1.0
pluginVersion = 1.1.1

# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/com/abeade/plugin/figma/ImportAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.intellij.openapi.ui.MessageType
import com.intellij.openapi.ui.popup.Balloon
import com.intellij.openapi.ui.popup.JBPopupFactory
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.vfs.VfsUtil
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.wm.WindowManager
import com.intellij.psi.PsiElement
Expand Down Expand Up @@ -86,7 +87,7 @@ class ImportAction : AnAction() {
if (updatedItems == 0 && createdItems == 0) {
showMessage(anActionEvent.project!!, "Figma import no resources has benn created or updated", true)
} else {
virtualFileRes.refresh(false, false)
VfsUtil.markDirtyAndRefresh(true, true, true, virtualFileRes)
when {
updatedItems == 0 -> showMessage(anActionEvent.project!!, "$createdItems resources has been created", false)
createdItems == 0 -> showMessage(anActionEvent.project!!, "$updatedItems resources has been updated", false)
Expand Down
14 changes: 13 additions & 1 deletion src/main/kotlin/com/abeade/plugin/figma/ImportDialogWrapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,30 @@ class ImportDialogWrapper(

override fun doValidate(): ValidationInfo? {
processResult()
val duplicated = dialog.findFirstDuplicatedSuffix()
return when {
dialog.fileField.text.isEmpty() -> ValidationInfo("Zip file required", dialog.fileField)
dialog.resourceField.text.isBlank() -> ValidationInfo("Resource name required", dialog.resourceField)
dialog.resourceField.text.contains('.') -> ValidationInfo("Resource name should not contain extension", dialog.resourceField)
dialog.ldpiField.text.isBlank() && dialog.mdpiField.text.isBlank() && dialog.hdpiField.text.isBlank()
&& dialog.xhdpiField.text.isBlank() && dialog.xxhdpiField.text.isBlank() && dialog.xxxhdpiField.text.isBlank() ->
ValidationInfo("At least one density prefix should be defined")
ValidationInfo("At least one density suffix should be defined")
result.isEmpty() -> ValidationInfo("No resource matches found! Review the prefixes and ensure you're using PNG or JPG")
duplicated != null -> ValidationInfo("This suffix is duplicated", duplicated)
else -> null
}
}

private fun ImportDialog.findFirstDuplicatedSuffix(): JComponent? {
val items = listOf(ldpiField, mdpiField, hdpiField, xhdpiField, xxhdpiField, xxxhdpiField).filterNot { it.text.isBlank() }
for (i in 0 until items.size - 1) {
for (j in i + 1 until items.size) {
if (items[i].text == items[j].text) return items[i]
}
}
return null
}

override fun changedUpdate(e: DocumentEvent?) {
updateLabels()
}
Expand Down

0 comments on commit 9a2c492

Please sign in to comment.