Skip to content

Commit

Permalink
Merge pull request #25 from zephir-lang/code-cleanup
Browse files Browse the repository at this point in the history
Code cleanup
  • Loading branch information
sergeyklay authored May 23, 2020
2 parents 5ca94e7 + 10847a7 commit f79fc01
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 38 deletions.
29 changes: 15 additions & 14 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com)
and this project adheres to [Semantic Versioning](http://semver.org).

## [Unreleased]
## [Unreleased][Unreleased]
### Added
- Amended Color Scheme configuration
- Introduced recognition of angle brackets as paired ones
- Added ability to create an empty Zephir File

### Changed
- Migrated build to Gradle
Expand All @@ -20,36 +21,36 @@ and this project adheres to [Semantic Versioning](http://semver.org).
### Removed
- Drop support of IDE's versions below `191`

## [0.3.6] - 2020-05-18
## [0.3.6][0.3.6] - 2020-05-18
### Changed
- Updated file icons
- Corrected `change-notes` section to store changes only for the latest version of the plugin

## [0.3.5] - 2020-05-13
## [0.3.5][0.3.5] - 2020-05-13
### Removed
- Drop support of IDE's versions below `182`

## [0.3.4] - 2020-05-12
## [0.3.4][0.3.4] - 2020-05-12
### Fixed
- Replaced usage of deprecated API by new one

## [0.3.3] - 2019-09-07
## [0.3.3][0.3.3] - 2019-09-07
### Fixed
- Fixed recognizing strings with regular expressions

## [0.3.2] - 2017-12-27
## [0.3.2][0.3.2] - 2017-12-27
### Added
- Completion list now shows members of class

### Changed
- Improved syntax support

## [0.3.1] - 2017-05-18
## [0.3.1][0.3.1] - 2017-05-18
### Fixed
- Fixed many bugs with syntax recognition
- Fixed extra space in completion for method params

## [0.3.0] - 2017-05-12
## [0.3.0][0.3.0] - 2017-05-12
### Added
- Added few words to highlight

Expand All @@ -59,30 +60,30 @@ and this project adheres to [Semantic Versioning](http://semver.org).
### Fixed
- Fixed many bugs with syntax recognition

## [0.2.5] - 2017-05-06
## [0.2.5][0.2.5] - 2017-05-06
### Fixed
- Fixed `switch` keyword detection

## [0.2.4] - 2014-09-22
## [0.2.4][0.2.4] - 2014-09-22
### Added
- Added brace matching support

## [0.2.3] - 2014-09-20
## [0.2.3][0.2.3] - 2014-09-20
### Fixed
- Fixed build

## [0.2.2] - 2014-09-15
## [0.2.2][0.2.2] - 2014-09-15
### Added
- Added color settings page

### Changed
- Improve highlighter

## [0.2.1] - 2014-09-15
## [0.2.1][0.2.2] - 2014-09-15
### Changed
- Disabled "New Zephir class" dialog

## [0.2] - 2014-09-15
## [0.2][0.2] - 2014-09-15
### Added
- Added lexer and simple syntax highlighter

Expand Down
61 changes: 37 additions & 24 deletions src/main/kotlin/com/zephir/ide/actions/ZephirCreateFileAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package com.zephir.ide.actions

import com.intellij.icons.AllIcons
import com.intellij.ide.actions.CreateFileFromTemplateAction
import com.intellij.ide.actions.CreateFileFromTemplateDialog
import com.intellij.ide.fileTemplates.FileTemplate
Expand All @@ -17,46 +18,58 @@ import com.intellij.ide.fileTemplates.ui.CreateFromTemplateDialog
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.io.FileUtilRt
import com.intellij.psi.PsiDirectory
import com.intellij.psi.PsiFile
import com.intellij.util.IncorrectOperationException
import com.zephir.lang.core.ZephirFileType
import java.util.*

// TODO(serghei): Put all natural language strings into the resource bundle src/main/resources/.../zephir.properties
// TODO(serghei): Add a note about resource bundle to CONTRIBUTING.md
class ZephirCreateFileAction : CreateFileFromTemplateAction(CAPTION, DESCRIPTION, ZephirFileType.icon) {
override fun getActionName(directory: PsiDirectory?, newName: String, templateName: String?): String = CAPTION

class ZephirCreateFileAction : CreateFileFromTemplateAction(
"Zephir File/Class",
"Creates new Zephir file or class",
ZephirFileType.icon
) {
override fun buildDialog(
project: Project?,
directory: PsiDirectory?,
project: Project,
directory: PsiDirectory,
builder: CreateFileFromTemplateDialog.Builder
) {
// TODO(serghei): Use different icons for class and interface
// TODO(serghei): setValidator(ZephirNameValidator)
builder.setTitle(CAPTION)
.addKind("Class", ZephirFileType.icon, ZEPHIR_KIND_CLASS)
.addKind("Interface", ZephirFileType.icon, ZEPHIR_KIND_INTERFACE)
builder.setTitle("New Zephir File/Class")
.addKind("File", ZephirFileType.icon, "Zephir File")
.addKind("Class", AllIcons.Nodes.Class, "Zephir Class")
.addKind("Interface", AllIcons.Nodes.Interface, "Zephir Interface")
}

override fun createFileFromTemplate(name: String, template: FileTemplate, dir: PsiDirectory) = try {
val className = FileUtilRt.getNameWithoutExtension(name)
override fun getActionName(directory: PsiDirectory?, newName: String, templateName: String?): String =
"Zephir File/Class"

override fun createFileFromTemplate(name: String, template: FileTemplate, dir: PsiDirectory): PsiFile? {
val project = dir.project
val className = FileUtilRt.getNameWithoutExtension(name)
val properties = createProperties(project, className)
CreateFromTemplateDialog(project, dir, template, AttributesDefaults(className).withFixedName(true), properties)
.create()
.containingFile
} catch (e: Exception) {
LOG.error("Error while creating new file", e)
null
}

private companion object {
private const val CAPTION = "Zephir File"
private const val DESCRIPTION = "Create new Zephir file"
val element = try {
CreateFromTemplateDialog(
project,
dir,
template,
AttributesDefaults(className).withFixedName(true),
properties
).create()
} catch (e: IncorrectOperationException) {
LOG.error("Error while creating new file", e)
throw e
} catch (e: Exception) {
LOG.error("Error while creating new file", e)
null
}

// These constants must match name of internal template stored in JAR resources
private const val ZEPHIR_KIND_CLASS = "Zephir Class"
private const val ZEPHIR_KIND_INTERFACE = "Zephir Interface"
return element?.containingFile
}

private companion object {
fun createProperties(project: Project, className: String): Properties {
val properties = FileTemplateManager.getInstance(project).defaultProperties

Expand Down

0 comments on commit f79fc01

Please sign in to comment.