Archive for the 'Work' Category

Change vs Click in the Flex 3 DataGrid

Friday, April 18th, 2008

(related to a tip I found, but for Flex 3 and my own memory…)

In Flex3 you can be notified of changes to selections in your datagrid from using listeners to either the ‘click’ or ‘change’ events, the difference being that if you only listen for click events you won’t be notified when the user navigates or selects with the keyboard (obvious, but confused me for a bit). This seems a shame given Flex’s pretty good handling of keyboard navigation, so unless you only want mouse click events use a ‘change’ handler as standard.

Using a Click Handler:

<mx:DataGrid id="DG1" click="clickHandler(event)"/>
<mx:Script>
  public function clickHandler(event:MouseEvent):void
  {
      someControl.text = event.currentTarget.selectedItem.someDataField;
  } 
</mx:Script>

Using a Change Handler:

<mx:DataGrid id="DG2" change="changeHandler(event)"/>
<mx:Script>
  public function changeHandler(event:Event):void
  {
      someControl.text = event.target.selectedItem.someDataField;
  } 
</mx:Script>

Help, Adobe Air for Linux ate my mimetypes?

Wednesday, April 2nd, 2008

**note** - I would have posted this in the bug list, but I can’t find it, the link from the FAQ just goes to the products page?

**fixed** - Ashutosh from Adobe provided a working fix in the comments below, nice one!

After installing the new Alpha of Adobe Air for Linux yesterday on Ubuntu 7.1 the mime types for .zip files seem to be broken and I can’t figure out how to fix them. When I clicked on a standard .zip file it used to open in FileRoller, it now gives me an error that the filename indicates it’s a zip but the contents indicate it’s an Air Application. I need to use ‘Open With’ to select FileRoller. Not the end of the world but a bit of a pain. Also, the files have a zip icon but this changes to a .air icon when I click it.

Poking around a bit I found xdg-mime included in the files installed with Air (side note, why? I’ve already got these installed, isn’t that the point of using the package manager to install this stuff?) and also an accompanying AdobeAir.xml file…

<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
 
  <mime-type type="application/vnd.adobe.air-application-installer-package+zip">
    <comment>Adobe AIR Application</comment>
    <glob pattern="*.air"/>
    <magic priority="100">
      <match type="string" value="PK\003\004" offset="0"/>
    </magic>
  </mime-type>
</mime-info>

…not sure what the magic stuff does but it looks ok? Also testing with xdg-mime seems to point to the mime types being correct?

adam@ubuntu:~$ xdg-mime query filetype ~/Desktop/08_04_02.zip 
application/zip
adam@ubuntu:~$ xdg-mime query default application/zip
file-roller.desktop
adam@ubuntu:~$ xdg-mime query default application/vnd.adobe.air-application-installer-package+zip
AdobeAIR.desktop

There’s also an air.mime file that also looks ok to me..

application/vnd.adobe.air-application-installer-package+zip
        ext: air

I’ve also just spotted, the files have been simlinked incorrectly into /usr/share/mime-info/ …

ls -la /usr/share/mime-info/air.*
 
adam@ubuntu:~$ ls -la /usr/share/mime-info/
lrwxrwxrwx   1 root root      54 2008-03-31 20:26 air.keys -> /opt/Adobe AIR/Versions/1.0/xdg-utils/support/air.keys
lrwxrwxrwx   1 root root      54 2008-03-31 20:26 air.mime -> /opt/Adobe AIR/Versions/1.0/xdg-utils/support/air.mime

the links should be to /opt/Adobe AIR/Versions/1.0/support/* , no xdg-utils, so I’ve tried …

adam@ubuntu:~$ sudo unlink /usr/share/mime-info/air.keys 
adam@ubuntu:~$ sudo unlink /usr/share/mime-info/air.mime 
adam@ubuntu:~$ sudo ln -s /opt/Adobe\ AIR/Versions/1.0/support/air.keys /usr/share/mime-info/air.keys 
adam@ubuntu:~$ sudo ln -s /opt/Adobe\ AIR/Versions/1.0/support/air.mime /usr/share/mime-info/air.mime

but this doesn’t seem to fix anything. Any other ideas anyone?

———
note to self, may be time to look at a liquid layout for the blog :)

FB3A3 & Air for Linux on Labs

Monday, March 31st, 2008

check me and the power I wield… no sooner had I had a little moan about FB3A2 expiring than we get not one but 2 new toys on Labs…

Flex Builder 3 Alpha 3 for Linux and
Air for Linux Alpha

According to the FB release notes nothing much has changed except the addition of Air support, but at least I can keep on working without it expiring.

FlexBuilder on Linux… what’s happening?

Wednesday, March 12th, 2008

I’ve been using FlexBuilder on Ubuntu for several months now, it’s got it’s oddities and the design view is missing but it mostly works fine. I’m currently using Alpha2, and it’s now telling me it runs out in 18 days. The fcsh says it will expire in 3 days. The discussion group on Labs seems to have been wiped recently and there’s zero feedback from Adobe there. There is currently no option to buy FB for linux on the Adobe site.

So Adobe, what’s going on? Is there going to be an A3? B1? Are we ever gonna get design view? When can I buy the damn thing? Is anybody out there??

The joys of regex

Tuesday, December 11th, 2007

So a couple of days ago someone (forgotten who though, sorry!) put up an interesting post about using Regex (Regular Expressions) in Eclipse to save you loads of repetative typing. As a follow up I thought I’d show a real life example of using regex that just saved me a whole heap of laborious grunt work.

The problem

A client asked me to update the images on a site I’m building for them. The image details are all in a simple xml file with some details and a link to the image file, e.g…

<images>
<image file="img1.jpg"><client>Foobar</client><by>Someone</by></image>
<image file="img2.jpg"><client>Barfoo</client><by>Somebody Else</by></image>
...
</images>

The client however supplied me with a text doucument that looked something like…

1. Foobar/Someone
2. Barfoo/Somebody Else
....

…and a bunch of jpeg files that had been named to match the document, so they were actually called ‘1. Foobar_Someone.jpg’ etc and needed to be renamed for safe use on the web (I never like having mixed case and spaces in web filenames).

Now as there were around 80 of these files it could have been a long and boring ‘rename & save’ job, then a whole bunch of cutting and pasting, so instead I used Eclipse and Perl’s regex powers.

Eclipse solution

The first thing I did was load the text file in Eclipse, then hit CTRL + F for the find & replace dialogue and checked the ‘Regular Expressions’ box. In the ‘find’ box I put

^(\d*)\. (.*)/(.*)$

This is a fairly simple pattern match using the braces to capture matching ‘groups’ that we can use later. Taking it from the begining…

  • the ^ character matches the start of a line, the (\d*) matches the first numbers
  • the \. matches a litteral dot (the slash is an escape character as the dot normally means match anything)
  • It may be hard to see here, but there’s then a space which we ignore
  • the (.*)/(.*) matches the two groups of words around the slash
  • and the $ matches the end of the line

Then in the replace box I put

<image file="img$1.jpg"><client>$2</client><by>$3</by></image>

The dollar+number means use the contents of capture group n, so you can see I’m simply ‘pasting’ the captured bits in the correct places.

Then just hit ‘replace all’ and job done!
(Hint: You can also use CTRL+SPACE in the find & replace input boxes to remind you of the regex syntax)

Perl solution

Of course I still needed to rename all the files, so next I used the ‘rename’ command. I’m working on Linux, but I believe ‘rename’ comes as part of Perl, so it should be somewhere on your system and work the same no matter what platform.

The syntax for the rename command is…

rename perlexpr [ files ]

…and basically runs the regular expression ‘perlexpr’ on the filename of all files matching [files]. The expression I used here is…

rename -v 's/(d*)\..*/img$1.jpg/' *.jpg

The regular expression is the messy looking bit inside the inverted commas, and it’s matching all the .jpg’s in the folder. Again taking the regex from the top…

  • The “s” means substitute. The syntax is s/old/new/ — substitute the old with the new
  • The (d*) captures the intial number in the filename
  • The \. matches a litteral dot
  • The .* matches anything else after it
  • We then discard all the other crap apart from the captured number, and use it in the substituted filename.

(Hint: more info : http://tips.webdesign10.com/how-to-bulk-rename-files-in-linux-in-the-terminal)

Conclusion

Well it’s taken me a hell of a lot longer to write this post than it did to rename all those files, I wouldn’t like to guess how long it would have taken by hand but I’m sure it was much easier this way.

Try bit of regex yourself, you just might like it! :)