Fingering->pointers
Sudheendra Hangal's randomly updated weblog
All | General | Java | Music | User interfaces

20041227 Monday December 27, 2004

Mozilla hacking mozilla hacking
One of the cool things about mozilla is the degree to which it can be customized. Suppose you want to customize mozilla so that instead of the standard browser logo in the upper right corner, it displays pictures of a cute little boy.

All you have to do is unjar and re-jar <mozilla install directory>/chrome/classic.jar or modern.jar (whatever skin is in use), dropping in your images in place of skin/<skin_name>/communicator/brand/throbber-single.jpg and throbber-anim.jpg. Paths for OS X and firefox versions are slightly different, but in all cases, you just need to replace the files throbber*gif/png or loading_16/not_loading_16.gif in one of the jar files.

Another useful Mozilla hack is to change the behaviour of the messenger searchbar. The default messenger action is to search for the searchbar term in the "subject or sender" fields of all messages -- except when viewing the Sent folder, where the term is searched for in the "Subject or To" fields. Sometimes, though, you may file all messages related to a topic together, including sent messages. Or sent messages are in a different folder, because they were filed by some other client. This makes searchbar usage problematic, because mozilla doesn't understand that the folder has some Sent messages. To work around, you can always search in all of Subject, To/cc and Sender fields. unjar <chrome>/messenger.jar, and replace the following lines in content/messenger/searchBar.js:createSearchTerms()
--
    // create, fill, and append the sender (or recipient) term
    term = gSearchSession.createTerm();
    value = term.value;
    value.str = termList[i];
    term.value = value;
    term.attrib = searchAttrib;
    term.op = nsMsgSearchOp.Contains;
    term.booleanAnd = false;
    searchTermsArray.AppendElement(term);
--
with:
--
    // create, fill, and append the Sender term
    var term = gSearchSession.createTerm();
    var value = term.value;
    value.str = termList[i];
    term.value = value;
    term.attrib = nsMsgSearchAttrib.Sender;
    term.op = nsMsgSearchOp.Contains;
    term.booleanAnd = false;
    searchTermsArray.AppendElement(term);

    // create, fill, and append the To-or-CC term
    var term = gSearchSession.createTerm();
    var value = term.value;
    value.str = termList[i];
    term.value = value;
    term.attrib = nsMsgSearchAttrib.ToOrCC;
    term.op = nsMsgSearchOp.Contains;
    term.booleanAnd = false;
    searchTermsArray.AppendElement(term);
--

The same thing can probably be done much more cleanly using XUL and XPIs or customizing userChrome.css, but this was the shortest path for me. (I'm not sure if overlaying Javascript code for the searchbar is possible though. If you know, please tell me how.)


(2004-12-27 01:39:08.0) Permalink Comments [11]

20041013 Wednesday October 13, 2004

Roses are red, and so should be warnings

I am always surprised that text-based user interfaces in computers have not fully utilized the power of colour. Ever tried to scroll through 10,000 lines of history in an xterm trying to locate that particular error message, or the command you typed ? So why don't shells emit user input and program output in different colours ? Why don't programs emit errors and warnings in colours that stand out amid a sea of text ? If only K&R had provided a colour argument to printf...

Anyway, here's one sample implementation of a "warning printf". It makes warnings stand out by printing them in red. It's pretty portable and works on every unix terminal (that I use :-)

// include stdio and stdarg
void wfprintf(FILE *fp, char *format, ...)
{
    int is_tty = isatty (fileno(fp));
    va_list ap;
    va_start(ap, format);
    // ANSI escape for the colour
    if (is_tty)
        fprintf(fp, "%c[31m", 0x1B); // 31 is colour red

    /* print out real message */
    (void) vfprintf(fp, format, ap);

    // reset terminal
    if (is_tty)
        fprintf (fp, "%c[m", 0x1B);
}

Unfortunately, though, I haven't discovered any way to check isatty() on the Java platform.

(2004-10-13 03:56:32.0) Permalink Comments [1]


archives
links