Skip to content

Commit

Permalink
Merge branch 'feature/ide' of gitlab.com:pika-lab/tuprolog/2p-in-kotl…
Browse files Browse the repository at this point in the history
…in into feature/ide
  • Loading branch information
gciatto committed Oct 22, 2020
2 parents 1eab200 + 639ad45 commit 7fa2054
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 48 deletions.
6 changes: 3 additions & 3 deletions ide/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
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
Expand All @@ -23,7 +23,7 @@ javafx {

application {
// mainModule.set("2p-ide")
mainClassName = "it.unibo.tuprolog.ui.gui.PrologIDE"
mainClassName = "it.unibo.tuprolog.ui.gui.Main"
}

dependencies {
Expand Down Expand Up @@ -78,4 +78,4 @@ if (!githubToken.isNullOrBlank()) {
rootProject.tasks.withType(GithubReleaseTask::class) {
dependsOn(shadowJar)
}
}
}
10 changes: 10 additions & 0 deletions ide/src/main/java/it/unibo/tuprolog/ui/gui/Main.java
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);
}
}
9 changes: 9 additions & 0 deletions ide/src/main/kotlin/it/unibo/tuprolog/ui/gui/FileTabView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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
Expand All @@ -15,6 +16,7 @@ import java.io.IOException
class FileTabView(
private val file: File,
private val model: PrologIDEModel,
private val ideController: PrologIDEController,
initialText: String = ""
) : Tab() {

Expand Down Expand Up @@ -58,13 +60,20 @@ class FileTabView(
}
}

@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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import javafx.stage.WindowEvent
import java.net.URL
import kotlin.system.exitProcess

class PrologIDE : Application() {
class PrologIDEApplication : Application() {
override fun start(stage: Stage) {
try {
val loader = FXMLLoader(javaClass.getResource("PrologIDEView.fxml"))
Expand Down Expand Up @@ -50,19 +50,19 @@ class PrologIDE : Application() {

companion object {

val JAVA_KEYWORDS_LIGHT: URL = PrologIDE::class.java.getResource("java-keywords-light.css")
val JAVA_KEYWORDS_LIGHT: URL = PrologIDEApplication::class.java.getResource("java-keywords-light.css")

val JAVA_KEYWORDS_DARK: URL = PrologIDE::class.java.getResource("java-keywords-dark.css")
val JAVA_KEYWORDS_DARK: URL = PrologIDEApplication::class.java.getResource("java-keywords-dark.css")

val LIGHT_CODE_AREA: URL = PrologIDE::class.java.getResource("light-code-area.css")
val LIGHT_CODE_AREA: URL = PrologIDEApplication::class.java.getResource("light-code-area.css")

val DARK_CODE_AREA: URL = PrologIDE::class.java.getResource("dark-code-area.css")
val DARK_CODE_AREA: URL = PrologIDEApplication::class.java.getResource("dark-code-area.css")

val TUPROLOG_LOGO: URL = PrologIDE::class.java.getResource("2p-logo.png")
val TUPROLOG_LOGO: URL = PrologIDEApplication::class.java.getResource("2p-logo.png")

@JvmStatic
fun main(args: Array<String>) {
launch(PrologIDE::class.java)
launch(PrologIDEApplication::class.java)
}
}
}
36 changes: 18 additions & 18 deletions ide/src/main/kotlin/it/unibo/tuprolog/ui/gui/PrologIDEController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import javafx.scene.input.KeyEvent
import javafx.scene.input.MouseEvent
import javafx.scene.layout.Region
import javafx.stage.Stage
import org.fxmisc.richtext.CodeArea
import java.io.File
import java.net.URL
import java.util.ResourceBundle
Expand Down Expand Up @@ -221,7 +222,7 @@ class PrologIDEController : Initializable {
}

private fun onFileLoaded(e: Pair<File, String>) = onUiThread {
tabsFiles.tabs.add(FileTabView(e.first, model, e.second))
tabsFiles.tabs.add(FileTabView(e.first, model, this, e.second))
}

private fun onStdoutPrinted(output: String) = onUiThread {
Expand Down Expand Up @@ -351,9 +352,8 @@ class PrologIDEController : Initializable {

@FXML
fun onKeyTypedOnCurrentFile(e: KeyEvent) {
(e.source as? TextArea)?.let {
onCaretMovedIn(e.source as TextArea)
model.setCurrentFile(it.text)
(e.source as? CodeArea)?.let {
onCaretMovedIn(it)
}
}

Expand Down Expand Up @@ -418,30 +418,30 @@ class PrologIDEController : Initializable {
}
}

private fun onCaretMovedIn(textArea: TextArea) {
val (l, c) = textArea.text.caretLocation(textArea.caretPosition)
lblCaret.text = "Line: $l | Column: $c"
private fun onCaretMovedIn(area: CodeArea) {
// val (l, c) = area.text.caretLocation(area.caretPosition)
lblCaret.text = "Line: ${area.caretPosition + 1} | Column: ${area.caretColumn + 1}"
}

private fun String.caretLocation(position: Int): Pair<Int, Int> {
val portion = this.subSequence(0, position)
val lines = portion.count { it == '\n' } + 1
val lastLine = portion.lastIndexOf('\n')
val columns = position - lastLine
return lines to columns
}
// private fun String.caretLocation(position: Int): Pair<Int, Int> {
// val portion = this.subSequence(0, position)
// val lines = portion.count { it == '\n' } + 1
// val lastLine = portion.lastIndexOf('\n')
// val columns = position - lastLine
// return lines to columns
// }

@FXML
fun onMouseClickedOnCurrentFile(e: MouseEvent) {
(e.source as? TextArea)?.let {
onCaretMovedIn(e.source as TextArea)
(e.source as? CodeArea)?.let {
onCaretMovedIn(it)
}
}

@FXML
fun onKeyPressedOnCurrentFile(e: KeyEvent) {
(e.source as? TextArea)?.let {
onCaretMovedIn(e.source as TextArea)
(e.source as? CodeArea)?.let {
onCaretMovedIn(it)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,10 @@ class SyntaxColoring(
PAREN_PATTERN.asGroup(PAREN),
BRACE_PATTERN.asGroup(BRACE),
BRACKET_PATTERN.asGroup(BRACKET),
FUNCTOR_PATTERN.asGroup(FUNCTOR),
ATOM_PATTERN.asGroup(ATOM),
VARIABLE_PATTERN.asGroup(VARIABLE),
NUMBER_PATTERN.asGroup(NUMBER),
FUNCTOR_PATTERN.asGroup(FUNCTOR),
STRING_PATTERN.asGroup(STRING),
COMMENT_PATTERN.asGroup(COMMENT),
FULLSTOP_PATTERN.asGroup(FULLSTOP),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<fx:root type="Tab" text="Untitled Tab" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1"
onSelectionChanged="#onTabSelectionChanged" closable="true">
<content>
<CodeArea fx:id="codeArea" onKeyTyped="#onKeyTypedOnCodeArea" onKeyPressed="#onKeyPressedOnCodeArea" prefHeight="200.0" prefWidth="200.0" />
<CodeArea fx:id="codeArea" onKeyTyped="#onKeyTypedOnCodeArea" onKeyPressed="#onKeyPressedOnCodeArea" onMouseClicked="#onMousePressedOnCodeArea" prefHeight="200.0" prefWidth="200.0" />
</content>
<!-- <graphic>-->
<!-- <Button mnemonicParsing="false" text="X" fx:id="btnClose" />-->
Expand Down
54 changes: 36 additions & 18 deletions ide/src/main/resources/it/unibo/tuprolog/ui/gui/PrologIDEView.fxml
Original file line number Diff line number Diff line change
@@ -1,45 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.ProgressBar?>
<?import javafx.scene.control.SeparatorMenuItem?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.TreeView?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>

<VBox fx:id="root" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="767.0" prefWidth="1100.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="it.unibo.tuprolog.ui.gui.PrologIDEController">
<children>
<MenuBar VBox.vgrow="NEVER">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem fx:id="btnNewFile" mnemonicParsing="false" onAction="#onNewFilePressed" text="New" />
<MenuItem fx:id="btnOpenFile" mnemonicParsing="false" text="Open…" />
<Menu mnemonicParsing="false" text="Open Recent" />
<MenuItem fx:id="btnOpenFile" disable="true" mnemonicParsing="false" text="Open…" />
<Menu disable="true" mnemonicParsing="false" text="Open Recent" />
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem fx:id="btnCloseFile" mnemonicParsing="false" text="Close" />
<MenuItem fx:id="btnSaveFile" mnemonicParsing="false" text="Save" />
<MenuItem mnemonicParsing="false" text="Save As…" />
<MenuItem fx:id="btnReloadFile" mnemonicParsing="false" text="Revert" />
<MenuItem fx:id="btnCloseFile" disable="true" mnemonicParsing="false" text="Close" />
<MenuItem fx:id="btnSaveFile" disable="true" mnemonicParsing="false" text="Save" />
<MenuItem disable="true" mnemonicParsing="false" text="Save As…" />
<MenuItem fx:id="btnReloadFile" disable="true" mnemonicParsing="false" text="Revert" />
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem fx:id="btnSettings" mnemonicParsing="false" text="Settings…" />
<MenuItem fx:id="btnSettings" disable="true" mnemonicParsing="false" text="Settings…" />
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem fx:id="btnQuit" mnemonicParsing="false" onAction="#onQuitRequested" text="Quit" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Edit">
<items>
<MenuItem mnemonicParsing="false" text="Undo" />
<MenuItem mnemonicParsing="false" text="Redo" />
<MenuItem disable="true" mnemonicParsing="false" text="Undo" />
<MenuItem disable="true" mnemonicParsing="false" text="Redo" />
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem mnemonicParsing="false" text="Cut" />
<MenuItem mnemonicParsing="false" text="Copy" />
<MenuItem mnemonicParsing="false" text="Paste" />
<MenuItem mnemonicParsing="false" text="Delete" />
<MenuItem disable="true" mnemonicParsing="false" text="Cut" />
<MenuItem disable="true" mnemonicParsing="false" text="Copy" />
<MenuItem disable="true" mnemonicParsing="false" text="Paste" />
<MenuItem disable="true" mnemonicParsing="false" text="Delete" />
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem mnemonicParsing="false" text="Select All" />
<MenuItem mnemonicParsing="false" text="Unselect All" />
<MenuItem disable="true" mnemonicParsing="false" text="Select All" />
<MenuItem disable="true" mnemonicParsing="false" text="Unselect All" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem fx:id="btnAbout" mnemonicParsing="false" text="About 2P" />
<MenuItem fx:id="btnAbout" disable="true" mnemonicParsing="false" text="About 2P" />
</items>
</Menu>
</menus>
Expand Down

0 comments on commit 7fa2054

Please sign in to comment.