-
Notifications
You must be signed in to change notification settings - Fork 0
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 #4 from Cullen-Shannon/uiUpdates
Mostly-functional UI, still needs a few things.
- Loading branch information
Showing
6 changed files
with
135 additions
and
66 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 |
---|---|---|
@@ -1,39 +1,64 @@ | ||
package org.jetbrains.plugins.template | ||
|
||
import com.intellij.openapi.ui.DialogWrapper | ||
import com.intellij.openapi.ui.ValidationInfo | ||
import com.intellij.ui.components.JBCheckBox | ||
import com.intellij.ui.components.JBTextField | ||
import com.intellij.ui.dsl.builder.* | ||
import com.intellij.ui.layout.not | ||
import org.jetbrains.plugins.template.domain.MyMenuItem | ||
import javax.swing.JComponent | ||
|
||
class MyDialog(private val myMenuItem: MyMenuItem): DialogWrapper(true) { | ||
/** | ||
* Maintenance dialog. | ||
* currentTree needed to determine what, if anything is selected | ||
*/ | ||
class MyDialog(val model: MyMenuItem, val onSubmit: (MyMenuItem) -> Unit): DialogWrapper(true) { | ||
|
||
lateinit var checkBox: Cell<JBCheckBox> | ||
private lateinit var _title: Cell<JBTextField> | ||
private lateinit var _description: Cell<JBTextField> | ||
private lateinit var _url: Cell<JBTextField> | ||
private lateinit var _isCollection: Cell<JBCheckBox> | ||
|
||
private val panel = panel { | ||
row("Title: ") { | ||
_title = textField().bindText(model::text) | ||
} | ||
row("Description: ") { | ||
_description = textField().bindText(model::description) | ||
} | ||
row { | ||
_isCollection = checkBox("Is Collection").selected(model.children != null) | ||
} | ||
row("Url: ") { | ||
_url = textField().text(if (model.url == null) "" else model.url!!) | ||
}.enabledIf(_isCollection.selected.not()) | ||
} | ||
|
||
override fun doValidate(): ValidationInfo? { | ||
if (_title.component.text.isBlank()) return ValidationInfo("Title is required!") | ||
if (_description.component.text.isBlank()) return ValidationInfo("Description is required!") | ||
if (!_isCollection.component.isSelected && _url.component.text.isBlank()) return ValidationInfo("Url is required!") | ||
return null | ||
} | ||
|
||
init { | ||
title = "Maintain Entry" | ||
init() | ||
} | ||
|
||
override fun createCenterPanel(): JComponent? { | ||
|
||
return panel { | ||
row("Title: ") { | ||
textField().bindText(myMenuItem::text) | ||
} | ||
row("Description: ") { | ||
textField().bindText(myMenuItem::description) | ||
} | ||
row { | ||
checkBox = checkBox("Group?") | ||
} | ||
row("Url: ") { | ||
textField() | ||
}.enabledIf(checkBox.selected.not()) | ||
} | ||
} | ||
override fun createCenterPanel() = panel | ||
|
||
// todo handle okay listener | ||
override fun doOKAction() { | ||
panel.apply() // needed to set | ||
val isCollection = _isCollection.component.isSelected | ||
model.url = if (isCollection) null else _url.component.text | ||
model.children = if (isCollection) mutableListOf() else null | ||
onSubmit(model) | ||
super.doOKAction() | ||
} | ||
|
||
override fun getPreferredFocusedComponent(): JComponent? { | ||
return _title.component | ||
} | ||
} |
18 changes: 10 additions & 8 deletions
18
src/main/java/org/jetbrains/plugins/template/domain/MyMenuItem.kt
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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
package org.jetbrains.plugins.template.domain | ||
|
||
data class MyMenuItem( | ||
var text: String, | ||
var description: String, | ||
var url: String? = null, | ||
var children: List<MyMenuItem>? = null, | ||
var addSeparatorBefore: Boolean = false, | ||
var addSeparatorAfter: Boolean = false, | ||
var isTopLevel: Boolean = false | ||
) | ||
var text: String, | ||
var description: String, | ||
var url: String? = null, | ||
var children: MutableList<MyMenuItem>? = null, | ||
var addSeparatorBefore: Boolean = false, | ||
var addSeparatorAfter: Boolean = false, | ||
var isTopLevel: Boolean = false | ||
) { | ||
override fun toString() = text | ||
} |
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