Skip to content
This repository has been archived by the owner on Jun 17, 2023. It is now read-only.

Commit

Permalink
把搜索提升到全局(#68)。
Browse files Browse the repository at this point in the history
  • Loading branch information
tangshimin committed Jul 22, 2022
1 parent 6e68409 commit 4a6e43c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 22 deletions.
32 changes: 27 additions & 5 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.platform.Font
import androidx.compose.ui.unit.DpOffset
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.*
import components.TypingSubtitles
import components.TypingText
import components.TypingWord
import components.computeVideoBounds
import components.*
import components.flatlaf.UpdateFlatLaf
import data.VocabularyType
import data.getHardVocabularyFile
Expand Down Expand Up @@ -92,6 +93,16 @@ fun main() = application {
WindowMenuBar(state = state, close = {close()})
MenuDialogs(state)
val scope = rememberCoroutineScope()

/** 搜索 */
var searching by remember { mutableStateOf(false) }
/** 等宽字体*/
val monospace by remember { mutableStateOf(FontFamily(Font("font/Inconsolata-Regular.ttf", FontWeight.Normal, FontStyle.Normal))) }
/** 打开搜索 **/
val openSearch:() -> Unit = {
searching = true
}

val changeTheme:(Boolean) -> Unit = {
scope.launch {
state.global.isDarkTheme = it
Expand Down Expand Up @@ -125,6 +136,14 @@ fun main() = application {
state.loadingFileChooserVisible = true
}
}
if(searching){
Search(
state = state,
vocabulary = state.vocabulary,
onDismissRequest = {searching = false},
fontFamily = monospace
)
}
when (state.global.type) {
WORD -> {
// 显示器缩放
Expand All @@ -141,7 +160,8 @@ fun main() = application {
state = state,
audioPlayer = audioPlayerComponent,
videoBounds = videoBounds,
currentWord = currentWord
currentWord = currentWord,
openSearch = {openSearch()},
)
}
SUBTITLES -> {
Expand All @@ -162,6 +182,7 @@ fun main() = application {
futureFileChooser = state.futureFileChooser,
openLoadingDialog = { openLoadingDialog()},
closeLoadingDialog = { state.loadingFileChooserVisible = false },
openSearch = {openSearch()},
)
}

Expand All @@ -179,6 +200,7 @@ fun main() = application {
futureFileChooser = state.futureFileChooser,
openLoadingDialog = { openLoadingDialog()},
closeLoadingDialog = { state.loadingFileChooserVisible = false },
openSearch = {openSearch()},
)
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/kotlin/components/TypingSubtitles.kt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ fun TypingSubtitles(
futureFileChooser: FutureTask<JFileChooser>,
openLoadingDialog: () -> Unit,
closeLoadingDialog: () -> Unit,
openSearch: () -> Unit
) {
val scope = rememberCoroutineScope()
val focusManager = LocalFocusManager.current
Expand Down Expand Up @@ -453,6 +454,10 @@ fun TypingSubtitles(
setCurrentCaptionVisible(!subtitlesState.currentCaptionVisible)
true
}
(keyEvent.isCtrlPressed && keyEvent.key == Key.F && keyEvent.type == KeyEventType.KeyUp) -> {
scope.launch { openSearch() }
true
}
(keyEvent.isCtrlPressed && keyEvent.key == Key.G && keyEvent.type == KeyEventType.KeyUp) -> {
setNotWroteCaptionVisible(!subtitlesState.notWroteCaptionVisible)
true
Expand Down Expand Up @@ -852,6 +857,9 @@ fun TypingSubtitles(
if (it.isCtrlPressed && it.key == Key.B && it.type == KeyEventType.KeyUp) {
scope.launch { selectable = !selectable }
true
}else if (it.isCtrlPressed && it.key == Key.F && it.type == KeyEventType.KeyUp) {
scope.launch { openSearch() }
true
} else false
}
)
Expand Down
8 changes: 8 additions & 0 deletions src/main/kotlin/components/TypingText.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ fun TypingText(
futureFileChooser: FutureTask<JFileChooser>,
openLoadingDialog: () -> Unit,
closeLoadingDialog: () -> Unit,
openSearch: () -> Unit
){
val scope = rememberCoroutineScope()
val focusManager = LocalFocusManager.current
Expand Down Expand Up @@ -188,6 +189,10 @@ fun TypingText(
openFileChooser()
true
}
(keyEvent.isCtrlPressed && keyEvent.key == Key.F && keyEvent.type == KeyEventType.KeyUp) -> {
scope.launch {openSearch() }
true
}
(keyEvent.isCtrlPressed && keyEvent.key == Key.D && keyEvent.type == KeyEventType.KeyUp) -> {
setIsDarkTheme(!globalState.isDarkTheme)
true
Expand Down Expand Up @@ -551,6 +556,9 @@ fun TypingText(
if (it.isCtrlPressed && it.key == Key.B && it.type == KeyEventType.KeyUp) {
scope.launch { selectable = !selectable }
true
}else if (it.isCtrlPressed && it.key == Key.F && it.type == KeyEventType.KeyUp) {
scope.launch {openSearch() }
true
} else false
}
)
Expand Down
20 changes: 3 additions & 17 deletions src/main/kotlin/components/TypingWord.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ fun TypingWord(
currentWord: Word?,
state: AppState,
videoBounds: Rectangle,
openSearch: () -> Unit
) {

/** 协程构建器 */
Expand Down Expand Up @@ -161,9 +162,6 @@ fun TypingWord(
/** 字幕输入框焦点请求器*/
val (focusRequester1,focusRequester2,focusRequester3) = remember { FocusRequester.createRefs() }

/** 搜索 */
var searching by remember { mutableStateOf(false) }

/** 等宽字体*/
val monospace by remember { mutableStateOf(FontFamily(Font("font/Inconsolata-Regular.ttf", FontWeight.Normal, FontStyle.Normal))) }

Expand All @@ -182,11 +180,6 @@ fun TypingWord(
/** 是否正在播放单词发音 */
var isPlayingAudio by remember { mutableStateOf(false) }

/** 打开搜索 **/
val openSearch:() -> Unit = {
searching = true
}

/**
* 用快捷键播放视频时被调用的回调函数
* @param playTriple 视频播放参数,Caption 表示要播放的字幕,String 表示视频的地址,Int 表示字幕的轨道 ID。
Expand Down Expand Up @@ -281,7 +274,7 @@ fun TypingWord(
}
(it.isCtrlPressed && it.key == Key.F && it.type == KeyEventType.KeyUp) -> {
scope.launch {
searching = !searching
openSearch()
}
true
}
Expand Down Expand Up @@ -1130,14 +1123,7 @@ fun TypingWord(
)
}
}
if(searching){
Search(
state = state,
vocabulary = state.vocabulary,
onDismissRequest = {searching = false},
fontFamily = monospace
)
}

}
} else {
Surface(Modifier.fillMaxSize()) {
Expand Down

0 comments on commit 4a6e43c

Please sign in to comment.