Stephen on Software aka SOS

August 24, 2009

this.wrap is undefined error – Ext JS Checkbox

Filed under: extjs — sljm @ 11:11 am

I am using Ext JS 2.2 and when you are setting Ext JS checkbox.setValue(something) before the checkbox is fully rendered you will get an “this.wrap is undefined” error.

The problem and fix is documented here. For a workaround with out changing any code, just make sure that you set the value of the checkbox in the Ext.onReady() portion and you should be ok.

August 20, 2009

Getting image name from urls, using the Content-Disposition header

Filed under: Programming — Tags: , — sljm @ 1:37 pm

You know when you visit some forums and when you click on a link like this http://thecelebrityspotlight.com/attachment.php?attachmentid=64134&stc=1&thumb=1, they open up an image file and when you right click and save some how the image name appears ? There are no clues in the url that tells you what the image name is suppose to be and somehow magically the browser knows.

Well it appears that the browser is looking for the Content-Disposition header in the Http Response. Jim Ley @ jibbering.com has a page Using the XML HTTP Request Object, that describe how to get the headers using the XmlHttpRequest object.

For Firefox this code snippet should work. Read his blog post for more information.

 var xmlhttp=new XMLHttpRequest();
 xmlhttp.open("HEAD", "/faq/index.html",true);
 xmlhttp.onreadystatechange=function() {
  if (xmlhttp.readyState==4) {
   alert("Content Disposition: "+
    xmlhttp.getResponseHeader("Content-Disposition"));
  }
 }
 xmlhttp.send(null)

August 19, 2009

Implementing File/Folder select for Firefox add-ons

Filed under: Uncategorized — Tags: — sljm @ 5:39 pm

To implement File/Folder select for firefox extensions you can look at the nsIFilePicker component.

To get the object:

var fp = Components.classes["@mozilla.org/filepicker;1"]
                   .createInstance(Components.interfaces.nsIFilePicker);

The object at this point is not initialized yet, you will need to use the init method to initialized it.

The method looks like this void init(parent,title,mode).

For parent you can use the window object that should be present. title is just the title of the file dialog, mode consist of any of the following valid values.

Constant Value Description
modeOpen 0 Load a file or directory.
modeSave 1 Save a file or directory.
modeGetFolder 2 Select a folder/directory.
modeOpenMultiple 3 Load multiple files.

Next you will need to call the show() method and check its return value to see if what the user pressed.

A sample of how to use;

const nsiFilePicker=Components.interfaces.nsIFilePicker;
fp.init(window,"My File dialog",nsIFilePicker.modeGetFolder);
var result=fp.show();
if(result == nsIFilePicker.returnOK || result == nsIFilePicker.returnReplace){
//do something
}

August 18, 2009

Getting the gBrowser object in Firefox

Filed under: Programming — Tags: — sljm @ 9:33 pm

Okies finally I have succumb and decided to do a Firefox add-on or extension to save open tabs that have documents/images inside, cause I am lazy to go one by one and save them.

So first step, try and get the tab browsers elements in the browser. In Firefox, there is a gBrowser object that if you can get it will help you to get all the browser tabs and their uris.

For the documentation, the only way that you can use gBrowser directly is that if you are under the scope of browser.xul when you are doing overlays. So for other windows like dialogs and sidebars, you will need to use window.opener.getBrowser method to get to the gBrowser object. If you look at the documentation for the window object, there is no mention of the getBrowser method, seems like the docs need some updating.

Look at the Getting access to the browser in the Tabbed Browser section of the MDC, you will find the various different methods for getting a gBrowser object.

August 7, 2009

Refreshing browser window when there is a resize event

Filed under: extjs — Tags: — sljm @ 5:19 pm

When I am using an ExtJS ViewPort, when I resize my window manually by dragging the window handles everything goes out of size so I needed a way to detect the window resize then refreshed the window.

First we need to create a function to refresh the window. That can be done using window.location.reload function. In ExtJS you can look at the Ext.EventManager.onWindowResize to add a listener to the onWindowResize event. Code is below.


function resize(){
window.location.reload
}

Ext.EventManager.onWindowResize(resize);

August 6, 2009

WPF Modal Windows

Filed under: Programming — Tags: — sljm @ 5:40 pm

Found this post that does a good job of showing how to do Modal Windows in WPF. Better than what I can explain anyway!

Links

Modal Dialogs in WPF

Blog at WordPress.com.