-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/ide' into develop
# Conflicts: # settings.gradle.kts
- Loading branch information
Showing
30 changed files
with
1,926 additions
and
7 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
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,87 @@ | ||
import com.github.breadmoirai.githubreleaseplugin.GithubReleaseExtension | ||
import com.github.breadmoirai.githubreleaseplugin.GithubReleaseTask | ||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
|
||
val javaVersion: String by project | ||
val ktFreeCompilerArgsJvm: String by project | ||
val githubToken: String? by project | ||
val arguments: String? by project | ||
|
||
plugins { | ||
application | ||
java | ||
kotlin("jvm") | ||
id("org.openjfx.javafxplugin") version Versions.org_openjfx_javafxplugin_gradle_plugin | ||
id("com.github.johnrengelman.shadow") version Versions.com_github_johnrengelman_shadow_gradle_plugin | ||
} | ||
|
||
javafx { | ||
version = Versions.org_openjfx | ||
modules = listOf("javafx.controls", "javafx.fxml", "javafx.graphics") | ||
} | ||
|
||
application { | ||
// mainModule.set("2p-ide") | ||
mainClassName = "it.unibo.tuprolog.ui.gui.Main" | ||
} | ||
|
||
val linuxOnly by configurations.creating { isTransitive = true } | ||
|
||
dependencies { | ||
api(project(":solve-classic")) | ||
api(project(":parser-theory")) | ||
api(kotlin("stdlib-jdk8")) | ||
api(Libs.richtextfx) | ||
|
||
runtimeOnly("${Libs.javafx_graphics}:win") | ||
runtimeOnly("${Libs.javafx_graphics}:linux") | ||
runtimeOnly("${Libs.javafx_graphics}:mac") | ||
|
||
testImplementation(kotlin("test-junit")) | ||
} | ||
|
||
configure<JavaPluginConvention> { | ||
targetCompatibility = JavaVersion.valueOf("VERSION_1_$javaVersion") | ||
sourceCompatibility = JavaVersion.valueOf("VERSION_1_$javaVersion") | ||
} | ||
|
||
tasks.withType<KotlinCompile> { | ||
kotlinOptions { | ||
jvmTarget = "1.$javaVersion" | ||
freeCompilerArgs = ktFreeCompilerArgsJvm.split(";").toList() | ||
} | ||
} | ||
|
||
val shadowJar = tasks.getByName<ShadowJar>("shadowJar") { | ||
manifest { | ||
attributes("Main-Class" to application.mainClassName) | ||
} | ||
archiveBaseName.set("${rootProject.name}-${project.name}") | ||
archiveVersion.set(project.version.toString()) | ||
archiveClassifier.set("redist") | ||
sourceSets.main { | ||
runtimeClasspath.filter { it.exists() } | ||
.map { if (it.isDirectory) it else zipTree(it) } | ||
.forEach { | ||
from(it) | ||
} | ||
} | ||
from(files("${rootProject.projectDir}/LICENSE")) | ||
|
||
dependsOn("classes") | ||
|
||
doLast { | ||
println("Generated: ${archiveFile.get()}") | ||
} | ||
} | ||
|
||
if (!githubToken.isNullOrBlank()) { | ||
rootProject.configure<GithubReleaseExtension> { | ||
releaseAssets(*(releaseAssets.toList() + shadowJar).toTypedArray()) | ||
} | ||
|
||
rootProject.tasks.withType(GithubReleaseTask::class) { | ||
dependsOn(shadowJar) | ||
} | ||
} |
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,10 @@ | ||
package it.unibo.tuprolog.ui.gui; | ||
|
||
/** | ||
* https://stackoverflow.com/questions/52569724/javafx-11-create-a-jar-file-with-gradle | ||
*/ | ||
public class Main { | ||
public static void main(String[] args) { | ||
PrologIDEApplication.main(args); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
ide/src/main/kotlin/it/unibo/tuprolog/ui/gui/AssignmentView.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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package it.unibo.tuprolog.ui.gui | ||
|
||
import it.unibo.tuprolog.core.Term | ||
import it.unibo.tuprolog.core.TermFormatter | ||
import it.unibo.tuprolog.core.Var | ||
import it.unibo.tuprolog.core.format | ||
import javafx.fxml.FXML | ||
import javafx.fxml.FXMLLoader | ||
import javafx.scene.control.Label | ||
import javafx.scene.layout.BorderPane | ||
import javafx.scene.layout.HBox | ||
import java.io.IOException | ||
|
||
class AssignmentView( | ||
variable: Var, | ||
value: Term, | ||
formatter: TermFormatter = TermFormatter.prettyExpressions() | ||
) : HBox() { | ||
|
||
companion object { | ||
private const val FXML = "AssignmentView.fxml" | ||
} | ||
|
||
init { | ||
val loader = FXMLLoader(AssignmentView::class.java.getResource(FXML)) | ||
loader.setController(this) | ||
loader.setRoot(this) | ||
|
||
try { | ||
loader.load<BorderPane>() | ||
} catch (e: IOException) { | ||
throw IllegalStateException(e) | ||
} | ||
|
||
this.variable.text = variable.format(formatter) | ||
this.value.text = value.format(formatter) | ||
} | ||
|
||
constructor(assignment: Pair<Var, Term>, formatter: TermFormatter = TermFormatter.prettyExpressions()) : | ||
this(assignment.first, assignment.second, formatter) | ||
|
||
@FXML | ||
lateinit var variable: Label | ||
|
||
@FXML | ||
lateinit var operator: Label | ||
|
||
@FXML | ||
lateinit var value: Label | ||
} |
79 changes: 79 additions & 0 deletions
79
ide/src/main/kotlin/it/unibo/tuprolog/ui/gui/FileTabView.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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package it.unibo.tuprolog.ui.gui | ||
|
||
import javafx.event.Event | ||
import javafx.fxml.FXML | ||
import javafx.fxml.FXMLLoader | ||
import javafx.scene.control.Tab | ||
import javafx.scene.input.KeyEvent | ||
import javafx.scene.input.MouseEvent | ||
import javafx.scene.layout.BorderPane | ||
import org.fxmisc.richtext.CodeArea | ||
import org.fxmisc.richtext.LineNumberFactory | ||
import java.io.File | ||
import java.io.IOException | ||
|
||
@Suppress("UNUSED_PARAMETER") | ||
class FileTabView( | ||
private val file: File, | ||
private val model: PrologIDEModel, | ||
private val ideController: PrologIDEController, | ||
initialText: String = "" | ||
) : Tab() { | ||
|
||
companion object { | ||
private const val FXML = "FileTabView.fxml" | ||
} | ||
|
||
private val syntaxColoring: SyntaxColoring | ||
|
||
init { | ||
val loader = FXMLLoader(FileTabView::class.java.getResource(FXML)) | ||
loader.setController(this) | ||
loader.setRoot(this) | ||
|
||
try { | ||
loader.load<BorderPane>() | ||
} catch (e: IOException) { | ||
throw IllegalStateException(e) | ||
} | ||
|
||
codeArea.appendText(initialText) | ||
|
||
codeArea.paragraphGraphicFactory = LineNumberFactory.get(codeArea) | ||
|
||
syntaxColoring = SyntaxColoring(codeArea) | ||
syntaxColoring.activate() | ||
|
||
text = file.name | ||
} | ||
|
||
@FXML | ||
lateinit var codeArea: CodeArea | ||
|
||
// @FXML | ||
// lateinit var btnClose: Button | ||
|
||
@FXML | ||
fun onTabSelectionChanged(e: Event) { | ||
if (isSelected) { | ||
model.selectFile(file) | ||
} | ||
} | ||
|
||
@FXML | ||
fun onMousePressedOnCodeArea(e: MouseEvent) { | ||
ideController.onMouseClickedOnCurrentFile(e) | ||
} | ||
|
||
@FXML | ||
fun onKeyTypedOnCodeArea(e: KeyEvent) { | ||
model.setFile(file, codeArea.text) | ||
ideController.onKeyTypedOnCurrentFile(e) | ||
} | ||
|
||
@FXML | ||
fun onKeyPressedOnCodeArea(e: KeyEvent) { | ||
model.setFile(file, codeArea.text) | ||
ideController.onKeyPressedOnCurrentFile(e) | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
ide/src/main/kotlin/it/unibo/tuprolog/ui/gui/LibraryView.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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package it.unibo.tuprolog.ui.gui | ||
|
||
import it.unibo.tuprolog.solve.library.AliasedLibrary | ||
import javafx.scene.control.TreeItem | ||
|
||
class LibraryView(library: AliasedLibrary) : TreeItem<String>(library.alias) { | ||
init { | ||
isExpanded = false | ||
|
||
val functionsChild = TreeItem("Functions") | ||
val predicatesChild = TreeItem("Predicates") | ||
val operatorsChild = TreeItem("Operators") | ||
|
||
children.addAll(functionsChild, predicatesChild, operatorsChild) | ||
|
||
val rules = library.theory.rules.asSequence().map { it.head.indicator } | ||
val primitives = library.primitives.keys.asSequence().map { it.toIndicator() } | ||
val predicates = (rules + primitives).distinct().map { it.toString() }.sorted() | ||
|
||
predicatesChild.children.addAll(predicates.map { TreeItem(it) }) | ||
|
||
val functions = library.functions.keys.asSequence().map { it.toIndicator() }.map { it.toString() } | ||
|
||
functionsChild.children.addAll(functions.map { TreeItem(it) }) | ||
|
||
val operators = library.operators.asSequence().map { "'${it.functor}', ${it.specifier} (${it.priority})" } | ||
|
||
operatorsChild.children.addAll(operators.map { TreeItem(it) }) | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
ide/src/main/kotlin/it/unibo/tuprolog/ui/gui/ListCellView.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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package it.unibo.tuprolog.ui.gui | ||
|
||
import javafx.scene.Node | ||
import javafx.scene.control.ListCell | ||
|
||
class ListCellView<T : Any>(private val viewGenerator: (T) -> Node) : ListCell<T>() { | ||
override fun updateItem(item: T?, empty: Boolean) { | ||
super.updateItem(item, empty) | ||
graphic = if (empty || item == null) { | ||
null | ||
} else { | ||
viewGenerator(item) | ||
} | ||
} | ||
} |
Oops, something went wrong.