英文:
How to prevent copy/paste/cut context menu when right click on textfield [Jetpack Compose desktop]?
问题
我正在开发一个Compose桌面应用程序。在这个平台上如何做同样的事情,即在右键单击桌面时防止复制/粘贴/剪切上下文菜单。
我尝试为LocalTextToolbar提供EmptyTextToolbar,但它不起作用。
英文:
i'm developing a compose desktop application.how to do same thing in this platform.i mean prevent copy/paste/cut context menu when right click on desktop.
i try to provide EmptyTextToolbar to LocalTextToolbar.it's doesn't work.
答案1
得分: 0
emm,我找到了一个解决方案。
当组合弹出上下文菜单时,它们从LocalTextContextMenu获取菜单项。所以,我尝试提供EmptyContextMenu给LocalTextContextMenu,它有效!
EmptyContextMenu:
@OptIn(ExperimentalFoundationApi::class)
object EmptyContextMenu: TextContextMenu {
@Composable
override fun Area(textManager: TextContextMenu.TextManager, state: ContextMenuState, content:@Composable () -> Unit) {
ContextMenuArea({
emptyList()
}, state, content = content)
}
}
显示的代码:
@OptIn(ExperimentalFoundationApi::class)
fun main() = application {
Window(
onCloseRequest = ::exitApplication
) {
var textValue by remember { mutableStateOf(TextFieldValue("")) }
CompositionLocalProvider(
LocalTextContextMenu provides EmptyContextMenu
) {
TextField(
value = textValue,
onValueChange = { newValue ->
textValue = if (newValue.selection.length > 0) {
newValue.copy(selection = textValue.selection)
} else {
newValue
}
}
)
}
}
}
这里有一些参考链接:
接口用法。
英文:
emm,i find a solution
when compose popup context menu,they get menu item from LocalTextContextMenu.
so,i try to provides EmptyContextMenu to LocalTextContextMenu.it's working!
EmptyContextMenu:
@OptIn(ExperimentalFoundationApi::class)
object EmptyContextMenu: TextContextMenu {
@Composable
override fun Area(textManager: TextContextMenu.TextManager, state: ContextMenuState, content:@Composable () -> Unit) {
ContextMenuArea({
emptyList()
}, state, content = content)
}
}
display code
@OptIn(ExperimentalFoundationApi::class)
fun main() = application {
Window(
onCloseRequest = ::exitApplication
) {
var textValue by remember { mutableStateOf(TextFieldValue("")) }
CompositionLocalProvider(
LocalTextContextMenu provides EmptyContextMenu
) {
TextField(
value = textValue,
onValueChange = { newValue ->
textValue = if (newValue.selection.length > 0) {
newValue.copy(selection = textValue.selection)
} else {
newValue
}
}
)
}
}
}
there is some reference link
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论