Archive for June, 2009

Xcode one ups #region in Visual Studio 2

I hate regions in Visual Studio. I don’t like the fact you can hide code from my incremental search and scanning eyes. If it is unimportant to me at the moment, give me a mechanism to jump over it.

#region "collapse me"
    // you’ll never see me if I’m collapsed.
#endregion

I don’t like that I can’t CTRL+I through them nor CTRL+F will skip them unless you tell them otherwise.

While Visual Studio gives your the ability to skip to the method directly via a dropdown.

image

The dropdown is nice and all, but the members are in alphabetical order, not the order they are in file. Alphabetical may make sense in some cases, but I usually have related members near each other in the source. When I go look for them in the dropdown, why aren’t they the same.

Xcode does things a bit differently. They line up everything with the order of the members in the file. Also, they let you give clues to the IDE to format the dropdown into sections. Brilliant.

image

Notice the following lines of source and their related markup of the dropdown.

#pragma mark -
#pragma mark Picker DataSource Methods

Pretty awesome huh? The best part is as you move the code around, the markup and members move in the dropdown. A+

Turning Off ASP.Net Validators 2

In true web forms style, what should be simple is more difficult than it should be, at least in my opinion. Today I needed the following simple UI.

image

Simple enough right? Pick something from the list or type your own text. The JavaScript to enable and disable the controls wasn’t too bad. It’s pretty un-interesting, so I’ll just skip over it. What I found surprising was the validators were still firing even though the controls were disabled. I wasn’t expecting it, but oh well. Now to turn off the control’s validators.

I found a lot of examples that looked like the following:

var myVal = document.getElementById('somevalidatorid');
ValidatorEnable(myVal, false); 

That’s nice, but I really don’t want to have to know each and every validator id for each control. It would also make the generic enable/disable code really tightly coupled to the controls we’re trying to disable.

Luckily, we can just find all the validators manually. jQuery can help us out, but isn’t really required.

function enableAllValidatorsFor(control,shouldEnable){
    var validators  = $.grep(Page_Validators,
				function(validator,i){
                                	return validator.controltovalidate == control.id;
                                });
    $.each(validators,  function(i,validator) {
                            ValidatorEnable(validator,shouldEnable);
                        });    

    // the validator callout leaves the error
    // class on the control after the validator gets
    // disabled, so we have to clean that up.
    if(!shouldEnable){
        $(control).removeClass("error");
    }
}        

The last little bit of code removes a CSS class that is set via a validator callout. It is tightly coupled with our pages, so you probably won’t need it, or will need a different class name. However, even though it is tightly coupled, it’s couple to all the pages and not the instance of the control it is disabling. We probably could find the validtor callouts used by the validator controls being disabled and remove any of the error classes they apply, but that didn’t seem necessary right now.

Something else interesting is the inconsistency of the jQuery API in this case. In the “grep” and “each” method the order of the arguments is reversed in the callback.

For grep you have:

function grepCallback(item, index){}

..and for each you have:

function eachCallback(index,item){}

Questionable Hulu Usability 0

Let me preface this with accolades for Hulu. It is an amazing site, with terrific content and amazing usability…except for this one little thing. When I want to subscribe to a new channel, I find a convenient “Subscribe” link on the channel landing page.

image

What a great show! I want to be sure and get new content in my queue, so I’ll subscribe to it.

image

Yea, that sounds good. I want full episodes to appear in my queue. Submit!

image

…uh….yea. I clicked submit. What are you asking me now? Submit again? Do I click cancel to close the dialog? Will that remove the subscription? Maybe I should click the “x”? I don’t know!

Why didn’t it just close the dialog and change the page to something like this?

image 

I’m really surprised that they missed the mark on that one.