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

Support pasting layout XML from outside of IntelliJ / Android Studio #8 #81

Merged
merged 2 commits into from
Sep 30, 2020
Merged

Support pasting layout XML from outside of IntelliJ / Android Studio #8 #81

merged 2 commits into from
Sep 30, 2020

Conversation

Foso
Copy link
Contributor

@Foso Foso commented Sep 29, 2020

Hi, maybe there's a better way to check if a string is XML but i found a similar approach in the Kotlin Project

Copy link
Owner

@pocmo pocmo left a comment

Choose a reason for hiding this comment

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

Awesome! Just a couple of questions and then I think this can land. :)

return emptyList()
return if (content.isDataFlavorSupported(DataFlavor.stringFlavor)) {
val text = content.getTransferData(DataFlavor.stringFlavor) as String
val xmlPreamble = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
Copy link
Owner

Choose a reason for hiding this comment

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

I think that is a good start. Eventually we probably want to support incomplete snippets too. But that's also #41 and #5. I guess we can just file a follow-up issue and then see what a good strategy would be. Maybe looking for the start of known elements.

)
}
text.contains(xmlPreamble, true) -> {
listOf(CopiedXMLCode(text, intArrayOf(0), intArrayOf(0)) as TextBlockTransferableData)
Copy link
Owner

Choose a reason for hiding this comment

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

Shouldn't we set the endOffset to the last index of text? Right now the offsets are not used, but eventually they will, I guess (#5).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be honest, i wasn't sure what the correct values for the offsets are. I looked at what offsets are used in collectTransferableData() when i copy the text inside Intellij and they we both 0.

Copy link
Owner

Choose a reason for hiding this comment

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

Oh, I see. Then this is something to look at when tackling #5. I was expecting the offsets to mark the selection area inside the text, since right now that always contains the whole document. But if it's always 0 right now then let's just use 0 here for now too. 👍

val xmlPreamble = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"

when {
content.isDataFlavorSupported(CopiedXMLCode.DATA_FLAVOR) -> {
Copy link
Owner

Choose a reason for hiding this comment

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

Do we ever get here if this block is wrapped in DataFlavor.stringFlavor? Is that an extension of the string flavor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we can only get here when the content has one flavour with DataFlavor.stringFlavor, see row 63.
I'm first checking if the pasted content is a string and not e.g. an image file. Then i'm checking if the content also has the dataflavor of CopiedXMLCode. If it's not, i'm checking if it looks like XML.

Copy link
Owner

Choose a reason for hiding this comment

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

Alright 👍

@pocmo pocmo merged commit 9a0c15d into pocmo:main Sep 30, 2020
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