Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CS346
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Simon Wang
CS346
Commits
1331d412
Commit
1331d412
authored
2 years ago
by
Terence-ChanLY
Browse files
Options
Downloads
Patches
Plain Diff
Added User Config File, with color theme and default file open location
parent
ff573e11
No related branches found
No related tags found
No related merge requests found
Pipeline
#87243
failed
2 years ago
Stage: build
Stage: test
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
application/src/main/kotlin/net/codebot/application/Main.kt
+31
-6
31 additions, 6 deletions
application/src/main/kotlin/net/codebot/application/Main.kt
application/src/main/kotlin/net/codebot/application/UserConfig.kt
+99
-0
99 additions, 0 deletions
...ion/src/main/kotlin/net/codebot/application/UserConfig.kt
with
130 additions
and
6 deletions
application/src/main/kotlin/net/codebot/application/Main.kt
+
31
−
6
View file @
1331d412
...
@@ -8,7 +8,6 @@ import javafx.scene.layout.BorderPane
...
@@ -8,7 +8,6 @@ import javafx.scene.layout.BorderPane
import
javafx.scene.layout.HBox
import
javafx.scene.layout.HBox
import
javafx.scene.layout.VBox
import
javafx.scene.layout.VBox
import
javafx.scene.text.Font
import
javafx.scene.text.Font
import
javafx.scene.text.Text
import
javafx.stage.FileChooser
import
javafx.stage.FileChooser
import
javafx.stage.Stage
import
javafx.stage.Stage
import
java.io.File
import
java.io.File
...
@@ -16,15 +15,20 @@ import java.io.FileNotFoundException
...
@@ -16,15 +15,20 @@ import java.io.FileNotFoundException
import
java.io.PrintWriter
import
java.io.PrintWriter
import
java.util.*
import
java.util.*
class
Main
:
Application
()
{
class
Main
:
Application
()
{
override
fun
start
(
stage
:
Stage
)
{
override
fun
start
(
stage
:
Stage
)
{
//Config, setting up themeColor and default file location
var
userConfig
=
initConfig
()
val
bold
=
Button
(
"B"
)
val
bold
=
Button
(
"B"
)
val
italics
=
Button
(
"I"
)
val
italics
=
Button
(
"I"
)
val
heading
=
Button
(
"H"
)
val
heading
=
Button
(
"H"
)
val
strikethrough
=
Button
(
"S"
)
val
strikethrough
=
Button
(
"S"
)
val
compileMd
=
Button
(
"Compile"
)
val
compileMd
=
Button
(
"Compile"
)
val
toolbar
=
ToolBar
(
val
toolbar
=
ToolBar
(
bold
,
bold
,
...
@@ -117,10 +121,10 @@ class Main : Application() {
...
@@ -117,10 +121,10 @@ class Main : Application() {
val
file
=
Menu
(
"File"
)
val
file
=
Menu
(
"File"
)
val
openFile
=
MenuItem
(
"Open File"
)
val
openFile
=
MenuItem
(
"Open File"
)
val
new
=
MenuItem
(
"New"
)
val
new
File
=
MenuItem
(
"New"
)
val
saveFile
=
MenuItem
(
"Save"
)
val
saveFile
=
MenuItem
(
"Save"
)
val
exitApp
=
MenuItem
(
"Exit"
)
val
exitApp
=
MenuItem
(
"Exit"
)
file
.
items
.
addAll
(
openFile
,
new
,
saveFile
,
exitApp
)
file
.
items
.
addAll
(
openFile
,
new
File
,
saveFile
,
exitApp
)
val
edit
=
Menu
(
"Edit"
)
val
edit
=
Menu
(
"Edit"
)
val
cut
=
MenuItem
(
"Cut"
)
val
cut
=
MenuItem
(
"Cut"
)
...
@@ -128,6 +132,7 @@ class Main : Application() {
...
@@ -128,6 +132,7 @@ class Main : Application() {
val
paste
=
MenuItem
(
"Paste"
)
val
paste
=
MenuItem
(
"Paste"
)
edit
.
items
.
addAll
(
cut
,
copy
,
paste
)
edit
.
items
.
addAll
(
cut
,
copy
,
paste
)
//Create SubMenu Help.
//Create SubMenu Help.
//Create SubMenu Help.
//Create SubMenu Help.
val
view
=
Menu
(
"View"
)
val
view
=
Menu
(
"View"
)
...
@@ -139,11 +144,22 @@ class Main : Application() {
...
@@ -139,11 +144,22 @@ class Main : Application() {
topContainer
.
getChildren
().
add
(
mainMenu
);
topContainer
.
getChildren
().
add
(
mainMenu
);
topContainer
.
getChildren
().
add
(
toolbar
);
topContainer
.
getChildren
().
add
(
toolbar
);
//NewFile
newFile
.
onAction
=
EventHandler
{
text
.
clear
();
}
//OpenFile function
//OpenFile function
openFile
.
onAction
=
EventHandler
{
openFile
.
onAction
=
EventHandler
{
val
filechooser
=
FileChooser
();
val
filechooser
=
FileChooser
();
filechooser
.
setTitle
(
"Open my file"
);
filechooser
.
setTitle
(
"Open my file"
);
filechooser
.
setInitialDirectory
(
File
(
System
.
getProperty
(
"user.home"
)));
if
(
userConfig
.
defaultFileLocation
==
"user.home"
)
{
filechooser
.
setInitialDirectory
(
File
(
System
.
getProperty
(
userConfig
.
defaultFileLocation
)))
}
else
{
filechooser
.
setInitialDirectory
(
File
(
userConfig
.
defaultFileLocation
))
}
val
selectedFile
=
filechooser
.
showOpenDialog
(
stage
);
val
selectedFile
=
filechooser
.
showOpenDialog
(
stage
);
try
{
try
{
val
scanner
=
Scanner
(
selectedFile
);
val
scanner
=
Scanner
(
selectedFile
);
...
@@ -155,11 +171,20 @@ class Main : Application() {
...
@@ -155,11 +171,20 @@ class Main : Application() {
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
border
.
left
=
FolderView
().
build
(
selectedFile
.
parentFile
.
absolutePath
)
border
.
left
=
FolderView
().
build
(
selectedFile
.
parentFile
.
absolutePath
)
userConfig
=
updateFileLocationConfig
(
userConfig
,
selectedFile
.
parentFile
.
absolutePath
)
}
}
//SaveFile function
//SaveFile function
saveFile
.
onAction
=
EventHandler
{
saveFile
.
onAction
=
EventHandler
{
val
file
=
FileChooser
().
showSaveDialog
(
Stage
());
val
savefilechooser
=
FileChooser
();
if
(
userConfig
.
defaultFileLocation
==
"user.home"
)
{
savefilechooser
.
setInitialDirectory
(
File
(
System
.
getProperty
(
userConfig
.
defaultFileLocation
)))
}
else
{
savefilechooser
.
setInitialDirectory
(
File
(
userConfig
.
defaultFileLocation
))
}
val
file
=
savefilechooser
.
showSaveDialog
(
Stage
());
if
(
file
!=
null
)
{
if
(
file
!=
null
)
{
try
{
try
{
val
printWriter
=
PrintWriter
(
file
);
val
printWriter
=
PrintWriter
(
file
);
...
...
This diff is collapsed.
Click to expand it.
application/src/main/kotlin/net/codebot/application/UserConfig.kt
0 → 100644
+
99
−
0
View file @
1331d412
package
net.codebot.application
import
kotlinx.serialization.Serializable
import
kotlinx.serialization.decodeFromString
import
kotlinx.serialization.encodeToString
import
kotlinx.serialization.json.Json
import
java.io.File
import
java.io.IOException
import
java.io.PrintWriter
import
java.nio.file.Files
import
java.nio.file.Path
import
java.nio.file.Paths
@Serializable
data class
UserSetting
(
var
theme
:
String
,
var
defaultFileLocation
:
String
)
//Check config file -> return user setting data class
fun
initConfig
():
UserSetting
{
var
currSetting
:
UserSetting
=
UserSetting
(
""
,
""
)
val
configFile
=
File
(
getConfigPath
())
//Check if Config File exists, if not, create a new default one
if
(!
configFile
.
exists
())
{
println
(
"Config file not found"
)
val
configFolder
=
configFile
.
parentFile
if
(!
configFolder
.
exists
())
{
println
(
"Config folder not found"
)
if
(!
configFolder
.
mkdirs
())
{
throw
IllegalStateException
(
"Couldn't create dir: "
+
configFolder
)
}
else
{
println
(
"Config folder created"
);
}
}
else
{
println
(
"Config folder exists"
)
}
println
(
"Writing Default Config"
)
//Default Config
updateConfig
(
UserSetting
(
"light"
,
"user.home"
))
}
try
{
println
(
"Reading Config from"
+
configFile
.
toString
())
val
config
=
String
(
Files
.
readAllBytes
(
configFile
.
toPath
()))
println
(
"Parsing Config into Json"
)
val
json
=
Json
{
prettyPrint
=
true
}
currSetting
=
json
.
decodeFromString
<
UserSetting
>(
config
)
}
catch
(
e
:
IOException
)
{
e
.
printStackTrace
()
}
if
(
currSetting
.
theme
==
""
||
currSetting
.
defaultFileLocation
==
""
)
{
throw
IllegalStateException
(
"Couldn't load User Config"
)
}
return
currSetting
}
public
fun
updateFileLocationConfig
(
userSetting
:
UserSetting
,
newlocation
:
String
)
:
UserSetting
{
val
newUserSetting
=
UserSetting
(
userSetting
.
theme
,
newlocation
)
updateConfig
(
newUserSetting
)
return
newUserSetting
}
public
fun
updateColorThemeConfig
(
userSetting
:
UserSetting
,
newTheme
:
String
)
:
UserSetting
{
val
newUserSetting
=
UserSetting
(
newTheme
,
userSetting
.
defaultFileLocation
)
updateConfig
(
newUserSetting
)
return
newUserSetting
}
private
fun
updateConfig
(
userSetting
:
UserSetting
)
{
val
configFile
=
File
(
getConfigPath
())
println
(
"Attempting to Update Config File: "
+
configFile
.
toString
())
try
{
println
(
"Converting Properties to Json"
)
val
json
=
Json
{
prettyPrint
=
true
}
val
jsonString
=
json
.
encodeToString
(
userSetting
)
println
(
"Writing Config"
)
println
(
jsonString
)
val
file
=
File
(
getConfigPath
())
val
printWriter
=
PrintWriter
(
file
)
//Get where to write
printWriter
.
write
(
jsonString
)
printWriter
.
close
();
println
(
"Done Writing Config"
)
}
catch
(
e
:
IOException
)
{
e
.
printStackTrace
()
}
}
private
fun
getConfigPath
():
String
?
{
val
rootPath
=
Paths
.
get
(
System
.
getProperty
(
"user.home"
))
val
partialPath
=
Paths
.
get
(
".MarkDown/config.txt"
)
val
resolvedPath
:
Path
=
rootPath
.
resolve
(
partialPath
)
return
resolvedPath
.
toString
()
}
This diff is collapsed.
Click to expand it.
Terence CHAN
@t24chan
mentioned in commit
0fa250e2
·
2 years ago
mentioned in commit
0fa250e2
mentioned in commit 0fa250e2a69883ffbab2da0efeebeae09e34d578
Toggle commit list
Terence CHAN
@t24chan
mentioned in merge request
!11 (closed)
·
2 years ago
mentioned in merge request
!11 (closed)
mentioned in merge request !11
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment