Skip to content

Commit

Permalink
Added "Open" function in menu bar
Browse files Browse the repository at this point in the history
  • Loading branch information
NickP0is0n committed Jul 5, 2021
1 parent 4a15e93 commit 5d668af
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/main/kotlin/me/nickp0is0n/easylocalize/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ fun main() = Window (
resizable = false,
size = IntSize(780, 455)
) {
System.setProperty("apple.laf.useScreenMenuBar", "true")
val currentView = MainWindowView()
MaterialTheme {
currentView.MainUI()
Expand Down
37 changes: 36 additions & 1 deletion src/main/kotlin/me/nickp0is0n/easylocalize/ui/MainWindowView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import androidx.compose.runtime.snapshots.SnapshotStateList
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Notifier
import androidx.compose.ui.window.*
import me.nickp0is0n.easylocalize.models.LocalizedString
import me.nickp0is0n.easylocalize.utils.LocalizeParser
import java.awt.FileDialog
Expand All @@ -25,10 +26,15 @@ class MainWindowView {
private lateinit var fieldValuesModel: FieldValuesViewModel
private var selectedID = -1
private val controller = MainWindowController()
private val waitForFile = mutableStateOf(false)

@Composable
fun MainUI() {
val window = LocalAppWindow.current
window.setMenuBar(
AppMenuBar()
)

Box(modifier = Modifier
.background(color = Color(255, 255, 255))
.fillMaxSize())
Expand Down Expand Up @@ -58,6 +64,7 @@ class MainWindowView {
Text(text ="Export translations to file...", color = Color.White)
}
}
checkIfOpenButtonClicked()
}
}

Expand Down Expand Up @@ -184,6 +191,34 @@ class MainWindowView {
val openDialog = FileDialog(window.window)
openDialog.isVisible = true
val stringFile = openDialog.files[0]
waitForFile.value = false
return parser.fromFile(stringFile)
}

@Composable
private fun checkIfOpenButtonClicked() {
if (waitForFile.value) {
val newList = retrieveStringList()
if (newList.isNotEmpty()) {
stringList.clear()
newList.forEach { stringList.add(it) }
}
//println("called")
}
}

@Composable
private fun AppMenuBar(): MenuBar =
MenuBar(
Menu(
name = "File",
MenuItem(
name = "Open...",
onClick = {
waitForFile.value = true
},
shortcut = KeyStroke(Key.O)
)
)
)
}

0 comments on commit 5d668af

Please sign in to comment.