diff --git a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationItemView.kt b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationItemView.kt index fc66a399599536cb4ab406590186edbd55809f0d..7340022f195a7ccd9516382b9d0d69c2aef379de 100644 --- a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationItemView.kt +++ b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/conversation/ConversationItemView.kt @@ -1,6 +1,6 @@ /* * Briar Desktop - * Copyright (C) 2021-2022 The Briar Project + * Copyright (C) 2021-2023 The Briar Project * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -19,7 +19,6 @@ package org.briarproject.briar.desktop.conversation import androidx.compose.foundation.BorderStroke -import androidx.compose.foundation.ContextMenuArea import androidx.compose.foundation.ContextMenuItem import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.layout.Arrangement @@ -55,6 +54,7 @@ import org.briarproject.briar.desktop.theme.msgOut import org.briarproject.briar.desktop.theme.msgStroke import org.briarproject.briar.desktop.theme.privateMessageDate import org.briarproject.briar.desktop.theme.textPrimary +import org.briarproject.briar.desktop.ui.ContextMenuAreaDataProvider import org.briarproject.briar.desktop.utils.InternationalizationUtils.i18n import org.briarproject.briar.desktop.utils.PreviewUtils.preview import org.briarproject.briar.desktop.utils.TimeUtils.getFormattedTimestamp @@ -175,7 +175,7 @@ fun ConversationItemView( item: ConversationItem, onDelete: (MessageId) -> Unit = {}, conversationItemDescription: String, - content: @Composable () -> Unit + content: @Composable () -> Unit, ) { val arrangement = if (item.isIncoming) Arrangement.Start else Arrangement.End val alignment = if (item.isIncoming) Alignment.CenterStart else Alignment.CenterEnd @@ -187,7 +187,7 @@ fun ConversationItemView( Row(Modifier.fillMaxWidth(), arrangement) { Box(Modifier.fillMaxWidth(0.8f), contentAlignment = alignment) { - ContextMenuArea( + ContextMenuAreaDataProvider( items = { listOf( ContextMenuItem(i18n("conversation.delete.single")) { onDelete(item.id) } diff --git a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/ui/ContextMenuAreaDataProvider.kt b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/ui/ContextMenuAreaDataProvider.kt new file mode 100644 index 0000000000000000000000000000000000000000..47211bd43ede11b899db2aa62de018ce88a8aec7 --- /dev/null +++ b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/ui/ContextMenuAreaDataProvider.kt @@ -0,0 +1,43 @@ +/* + * Briar Desktop + * Copyright (C) 2023 The Briar Project + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package org.briarproject.briar.desktop.ui + +import androidx.compose.foundation.ContextMenuArea +import androidx.compose.foundation.ContextMenuDataProvider +import androidx.compose.foundation.ContextMenuItem +import androidx.compose.foundation.LocalContextMenuRepresentation +import androidx.compose.runtime.Composable + +/** + * Defines a container where context menu is available. Menu is triggered by right mouse clicks. + * Representation of menu is defined by [LocalContextMenuRepresentation]` + * + * Different to [ContextMenuArea], this area also merges the [items] with descendant text context menus. + * + * @param items List of context menu items. Final context menu contains all items from descendant + * [ContextMenuArea] and [ContextMenuDataProvider]. + * @param content The content of the [ContextMenuAreaDataProvider]. + */ +@Composable +fun ContextMenuAreaDataProvider( + items: () -> List<ContextMenuItem>, + content: @Composable () -> Unit, +) = ContextMenuDataProvider(items) { + ContextMenuArea(items = { emptyList() }, content = content) +}