Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new page for context menus #273

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ElviraMustafina
Copy link
Collaborator

  • new page for context menus
  • new screenshots
  • minor updates to code samples: added titles for windows, updated comments
  • added info about localization


The default context menu for a text field includes the following actions, depending on the cursor's position and the
selection range: Copy, Cut, Paste, and Select All.
To enable the standard context menu in the text field, just use the `TextField` component from the Material theme.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To enable the standard context menu in the text field, just use the `TextField` component from the Material theme.
The default context menu is available by default in the material `TextField` or the foundation `BasicTextField`.

We have 3 text fields:

androidx.compose.foundation.text.BasicTextField
androidx.compose.material.TextField
androidx.compose.material3.TextField

all contain the default context menu.

The new item adjusts to the text selection:

```kotlin
import androidx.compose.foundation.ContextMenuDataProvider
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import androidx.compose.foundation.ContextMenuDataProvider
import androidx.compose.foundation.ContextMenuDataProvider
import androidx.compose.foundation.ContextMenuItem
import androidx.compose.foundation.ContextMenuState
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.text.LocalTextContextMenu
import androidx.compose.foundation.text.TextContextMenu
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.material.Text
import androidx.compose.material.TextField
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.window.singleWindowApplication
import java.net.URLEncoder
import java.nio.charset.Charset
fun main() = singleWindowApplication {
CustomTextMenuProvider {
Column {
SelectionContainer {
Text("Hello, Compose!")
}
var text by remember { mutableStateOf("") }
TextField(text, { text = it })
}
}
}
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun CustomTextMenuProvider(content: @Composable () -> Unit) {

We had an issue in the previous version - we used ComposePanel, but it isn't related to this section. We should use just standard entry point. The screenshot and behaviour don't change with the new code.

## Swing interoperability

If you are embedding Compose code into an existing Swing application and need the context menu to match the appearance and
behavior of other parts of the application, you can use the `JPopupTextMenu` class. In this class, `TextContextMenu` uses
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
behavior of other parts of the application, you can use the `JPopupTextMenu` class. In this class, `TextContextMenu` uses
behavior of other parts of the application, you can use the `JPopupTextMenu` class. In this class, `LocalTextContextMenu` uses

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants