Friday, December 10, 2010

Cut and Paste with the current #WP7Dev tools

For a lot of people the lack of native Cut & Paste support in the current (initial) version of Windows Phone 7 is a big deal.

I've heard a surprisingly large amount of people tell me that it's essential that they can copy and paste text* on a phone. Personally I hardly ever used this feature when I was using a phone which had it though.

I've pointed out to a few people that it's possible to implement the cutting, copying and pasting of text within an application quite easily. (It actually only take a handful of lines of code.) But no-one (AFAIK) has taken the initiative to do this. Before now...

The issue isn't really being able to cut and paste text though. What people really want is a way to easily share data between applications. When people say "cut and paste" they, typcially, mean they want to take (copy) some data (text) from one application and then use (paste) it in another application.

As native functionality, this isn't currently possible.
However this will be coming in an remote update early next year.

So if we want copy and paste in our apps we have to either wait or try and do it ourselves.

Surprisingly, the sandboxed nature of 3rd party applications on the phone has lead many (most?) to assume that this isn't possible.

I beg to differ!

Take a lok at this video of 3 apps I wrote. 2 accept the entry of text and support methods of multiple word selection (also not currently available natively) and cutting, copying and pasting text. The third app just shows what is in the "Shared Clipboard". Yes. These apps all have access to the same clipboard. And, no, this isn't done by sending the data to a remote web server or anything like that. It's also not using anything not publically available and only uses public, authorized API methods.



To try and prove that this is really possible I've submitted Scratch Pad to the marketplace. When it's accepted you can try it for yourself. Plus acceptance will show it's not using anything it shouldn't (or you couldn't) and that it doesn't require a data connection.

With native support for cut and paste coming in early 2011 (most people are assuming in January) I'm not planning on sharing the clipboard code as there is a small side effect to using it that it's probably best not to burden users with. But, I assume that you're smart enough to work out how I did this if you really wanted to. ;)

* It's always text that people want to copy and paste. I haven't, yet, heard anyone give a case for wanting this for any other data type on a phone.

4 comments:

  1. Licantrop012:02 am

    So? how you have done?

    ReplyDelete
  2. I know a way to do it (I found myself thinking about it because my latest app uses one certain class extensively) and can't really think of another way so, if you did that, good luck with the certification :)
    I guess they could actually not notice it but if they do they may kill your app right away or just require that you make the user aware.

    ReplyDelete
  3. Yes, as some have pointed out. This isn't true cut and paste, as some may want it, as it doesn't integrate with the standard text entry methods and so can't be used by any/every application. In reality it's showing the manipualtion of text (like cut and paste would) and the sharing of data between applications.

    ReplyDelete