-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
171 additions
and
25 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
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
36 changes: 36 additions & 0 deletions
36
src/main/scala/de/thm/move/controllers/RecentlyFilesHandler.scala
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,36 @@ | ||
package de.thm.move.controllers | ||
|
||
import java.nio.file.{Files, Path, StandardOpenOption} | ||
import javafx.event.ActionEvent | ||
import javafx.scene.control.MenuItem | ||
|
||
import de.thm.move.Global | ||
import de.thm.move.implicits.FxHandlerImplicits._ | ||
import de.thm.move.util.JFxUtils | ||
import de.thm.recent._ | ||
import spray.json.JsonFormat | ||
|
||
class RecentlyFilesHandler(recent:Recent[Path], pathClicked: Path => Unit) { | ||
|
||
private def menuItem(path:Path): MenuItem = { | ||
val item = new MenuItem(path.toString) | ||
JFxUtils.addFontIcon(item, "\uf1c9") | ||
item.setOnAction { _:ActionEvent => | ||
incrementPriorityOf(path) | ||
println(recent.recentValuesByPriority) | ||
pathClicked(path) | ||
} | ||
item | ||
} | ||
|
||
def incrementPriorityOf(path:Path): Unit = | ||
recent.incrementPriority(path) | ||
|
||
def getMenuItems:Seq[MenuItem] = | ||
recent.recentElementsByPriority.map(menuItem) | ||
|
||
def writeTo(outputFile:Path)(implicit pathFormat:JsonFormat[Path]): Unit = { | ||
val jsonString = recent.toJson | ||
Files.write(outputFile, jsonString.getBytes(Global.encoding)) | ||
} | ||
} |
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
43 changes: 43 additions & 0 deletions
43
src/test/scala/de/thm/move/loader/parser/StringParserTest.scala
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,43 @@ | ||
/** | ||
* Copyright (C) 2016 Nicola Justus <[email protected]> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
package de.thm.move.loader.parser | ||
|
||
import java.io.{ByteArrayInputStream, InputStreamReader} | ||
import java.nio.charset.StandardCharsets | ||
|
||
import scala.util._ | ||
import de.thm.move.MoveSpec | ||
import de.thm.move.loader.parser.PropertyParser._ | ||
import de.thm.move.loader.parser.ast._ | ||
|
||
class StringParserTest extends MoveSpec { | ||
val parser = new ModelicaParser() | ||
def parseString(str:String): String = { | ||
parser.stringLiteral(str) | ||
} | ||
|
||
"The parser for Modelica strings" should "parse simple strings" in { | ||
val s = "this is a super awesome test" | ||
true shouldBe true | ||
} | ||
|
||
"PropertyParser#transformEscapeChars" should | ||
"transform literal escape characters to ansi escape characters" in { | ||
val s = "this\\t\\tis a\\n test\\rmöb\\b" | ||
parser.transformEscapeChars(s) shouldBe "this\t\tis a\n test\rmöb\b" | ||
|
||
val s2 = "\\n\\n\\t" | ||
parser.transformEscapeChars(s2) shouldBe "\n\n\t" | ||
} | ||
|
||
it should "return the same string for strings without escape characters" in { | ||
val s = "this is awesome" | ||
parser.transformEscapeChars(s) shouldBe s | ||
} | ||
} |