-
Notifications
You must be signed in to change notification settings - Fork 49
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ import com.intellij.psi.PsiFile | |
import org.jetbrains.kotlin.idea.KotlinFileType | ||
import recompose.composer.Composer | ||
import recompose.parser.Parser | ||
import java.awt.datatransfer.DataFlavor | ||
import java.awt.datatransfer.Transferable | ||
|
||
/** | ||
|
@@ -58,14 +59,28 @@ class RecomposeCopyPasteProcessor : CopyPastePostProcessor<TextBlockTransferable | |
override fun extractTransferableData( | ||
content: Transferable | ||
): List<TextBlockTransferableData> { | ||
if (content.isDataFlavorSupported(CopiedXMLCode.DATA_FLAVOR)) { | ||
// There's some matching data in this paste, let's return it to process it. | ||
return listOf( | ||
content.getTransferData(CopiedXMLCode.DATA_FLAVOR) as TextBlockTransferableData | ||
) | ||
} | ||
|
||
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\"?>" | ||
|
||
when { | ||
content.isDataFlavorSupported(CopiedXMLCode.DATA_FLAVOR) -> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we ever get here if this block is wrapped in There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alright 👍 |
||
// There's some matching data in this paste, let's return it to process it. | ||
listOf( | ||
content.getTransferData(CopiedXMLCode.DATA_FLAVOR) as TextBlockTransferableData | ||
) | ||
} | ||
text.contains(xmlPreamble, true) -> { | ||
listOf(CopiedXMLCode(text, intArrayOf(0), intArrayOf(0)) as TextBlockTransferableData) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we set the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. 👍 |
||
} | ||
else -> { | ||
emptyList() | ||
} | ||
} | ||
} else { | ||
emptyList() | ||
} | ||
} | ||
|
||
// Perform paste: Process transferable data | ||
|
There was a problem hiding this comment.
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.