Snippets code from my daily experience

May 9, 2008

How to detect XUL trees scroll event

Filed under: DOMAttrModified, extension, nsITreeView, visualdiffer, xpcom, xul — dafi @ 7:17 pm
Tags: , ,

My extension VisualDiffer contains two nsITreeViews that must synchronize scrolling, when user scrolls one the other tree moves the selection to the corresponding row.

Apparently XUL trees don’t have any event handler to intercept scrolling operations so I run the risk to became crazy.

After days spent to find a solution (using google) without result I’ve tried to use the DOMAttrModified event and amazingly it worked.

First I add a listener to the tree (VisualDiffer adds listeners to left and right trees)

document.getElementById(“left-tree”).addEventListener(“DOMAttrModified”,
function(event) { gFolderDiffer.onLeftScroll(event);}, false);

The onScroll simply checks if event.attrName is “curpos” and if it’s true the tree has been scrolled by user

onLeftScroll : function(event) { if (event.attrName == “curpos”) {
rightTreeView.treebox.scrollToRow(leftTreeView.treebox.getFirstVisibleRow());
}
}

This solution works fine but maybe exists a better way…

May 5, 2008

GIMP doesn’t reuse running instance under Windows

Filed under: gimp, gimp-remote, gimp-win-remote, viewsourcewith — dafi @ 7:44 pm

A ViewSourceWith’s user posted an interesting question on forum: how to reuse an already running GIMP instance.

I’ve never incurred on this problem on my Linux box so I was very surprised.

Booting under Windows I’ve found this different behavior, very strange because the GIMP documentation explains how to obtain the opposite effect using command line switches, i.e. running always new instances.

IMHO the reuse technique under Windows is bugged so I found a workaround using the not so famous gimp-win-remote executable program present on bin directory.

gimp-win-remote checks (correctly) if GIMP is already running and reuse it.

I’m curious to know if Mac OS/X complains to unix world, if you have a Mac and would satisfy my curiosity I will update the ViewSourceWith FAQ page ;)

May 3, 2008

Unsuccessful is…

Filed under: mental-hangover — dafi @ 9:41 am

Today my planet.mozilla feed contains a post from ActiveState’s technical leader Shane Caraveo.

Shane’s post title is “Success is…” where incidentally speaks about my VisualDiffer, he tries to define success from different points of view.

I think his team success arrives from good (and very hard) work.

Now I try to define unsuccessful from my personal point of view.

Unsuccessful is

when you born in wrong place at right time

when you work with stupid people, in stupid companies

when you must leave a software company unable to help you to work better

when smart developers find your work interesting but you can’t work with them

have a blog with two visits per month

speak (or write) a bad english

VisualDiffer: a new Komodo extension

Filed under: extension, komodo, xul — dafi @ 9:17 am

When I migrated to Ubuntu I loose some important developer tools like UltraEdit and Beyond Compare two closed-source commercial applications representing the state-of-art like editor and file comparator.

I’ve created MoreKomodo (the original name was UltraKomodo :P ) to add to KomodoEdit the UltraEdit features I need.

Folders and files comparison tools under Gnome are poor so I’ve decided to create my own differ application based on KomodoEdit for at least three reasons

KomodoEdit is open source

KomodoEdit is XUL based so I can develop re-using my know-how

KomodoEdit is multiplatform (thanks to Mozilla Gecko Engine)

Finally I’ve finished the first stable version of VisualDiffer, it misses many features but I hope to add them.

April 7, 2008

How to get element style values from XUL (or HTML)

Filed under: css, table2clipboard, xul — dafi @ 8:15 pm

I’m working to my Extend Firefox 2 Runner Up winner Table2Clipboard.

Many users tell me to add a simple feature, exclude cells having style display: none.

The solution is so straightforward that I could not believe after initial implementation.

You can style an element using CSS selectors

.invisible {
display: none;
}

<span id=“invisibleSpan” class=“invisible”>I’m invisible man</span>

or using the attribute style attribute

<span id=“invisibleSpan” style=“display : none”>I’m invisible man</span>

These two ways can both simply handled using getComputedStyle

var spanElement = document.getElementById(“invisibleSpan”);
var style = spanElement.ownerDocument.defaultView.getComputedStyle(spanElement, null);
var displayValue = style.getPropertyValue(“display”);

That’s all folks!!

Obviously you can use any CSS attribute not only display.

Pay attention to ownerDocument.defaultView, you should use window.getComputedStyle() but under XUL this doesn’t return what you expect.

getComputedStyle can be used in normal unprivileged HTML code, too.

getComputedStyle is a W3C standard and is present on Internet Explorer, Opera and Safari, too.

Little things make developer life easier.

April 5, 2008

Houston we have a problem: ViewSourceWith under FF3b5

Filed under: firefox, viewsourcewith — dafi @ 10:46 am

Bad news for ViewSourceWith and its compatibility with FF3.0.

Due to the bug “Code running in context of hiddenDOMWindow runs unprivileged?” ViewSourceWith stopped to work when FF3.0b5 was published.

I’ve done many code modifications to adhere to FF3 requirements and now VSW 0.1b is ready.
After dozen of regression tests I’m afraid something is missed so I ask to VSW users to help me to test it deeper.

Any help is welcomed not only technical tests, for example you can share my help request in other blogs/forums.
If you would help me to test VSW 0.1 download it from here.

Tests can be done on

  • Firefox from 2.0 to 3.0b5
  • SeaMonkey
  • Songbird
  • Flock

Tests must verify

  • text box editing
  • page view source
  • css/js view
  • error console view source clicking on links
  • temp files removal at application exit

Try to

  • open more that one browser window closing the openers and verify if VSW continues to work
  • use your daily VSW usage behaviour
  • use you creativity ;)

Platforms

  • Windows
  • Linux (I use Ubuntu Feisty)
  • MacOSX

Please use this post to give me feedback or better land to “ViewSourceWith Open Discussion

March 30, 2008

XUL and textbox CSS styles

Filed under: -moz-appearance, css, xul — dafi @ 12:46 pm

If you want to change the background color for HTML input text boxes you simply set the background-color style attribute, very obvious.

.my-textbox {
background-color: red;
}

If you want to make same thing for XUL textboxes you apply the same style attribute discovering it doesn’t work… :(

Ehm.. It works but you must disable standard mozilla behaviour using -moz-appearance attribute

.my-textbox {
-moz-appearance: none;
background-color: red;
}

Little lesson learned ;)

March 27, 2008

KomodoEdit and smart tab switch

Filed under: eclipse, extension, komodo — dafi @ 9:10 pm

Today I’ve discovered again (and again) other programmers have my same needs.

I do intensive use of tab switcher during my editing sessions, Control-Tab is my preferred key sequence.

When I need to use Eclipse I love the ability to access to the buffer list using the little arrow placed at buffer tabs end.

You can type buffer title to quickly focus the buffer or use arrows keys, very cool.

KomodoEdit offers very poor ways to move between views so I wrote my TabSwitcher to mimic Eclipse feature.

Today I’ve read a post on ActiveState’s forum where another user has my same needs and I’ve decided to share my bonsai extension with the community, I hope the community appreciates my work.

Maybe I should create a website page for TabSwitcher but I’m so lazy and maybe user feedback can be very low.

March 23, 2008

Central extensions repositories

Filed under: extension, firefox, flock, komodo, songbird — dafi @ 10:21 pm

I spend my time to created extensions based on Gecko expecially for

  • Firefox, Thunderbird and SeaMonkey (all under Mozilla umbrella)
  • Songbird
  • Flock
  • KomodoEdit/KomodoIDE

Every product has its own developer website where you can upload your extensions (Komodo hasn’t a dedicated upload zone).

From a visitor/user feedback’s point of view Flock is the best.

Flock addons site is cool I love it, extension informations are very complete, you can see also the locales supported by extensions.

Songbird has a cool addons site simple and very quick, extension informations are complete.

Mozilla with AMO is the most important but is also the worst.

The outsider KomodoEdit addons site not yet really exists, registered users can’t upload their extensions.
I hope Komodo guys take a look at Flock addons site if they decide to create a similar place.

From a developer feedback’s point of view Songbird is the best.
After signup you can immediately upload and publish extension on Songbird site, the upload process is easy and publication policy very developer friendly.

AMO upload mechanism is simple but publication mechanism is awful. I don’t like its approval mechanism based on sandbox, my RichFeedButton waits approval for an year.

Flock allows to upload extensions immediately after signup but publication waits approval, after a couple of days I’m yet waiting ;)

The most mature and important addons site AMO, has IMHO the worst user/developer experience.

I don’t like so much Flock but it has a great develope/user website

March 22, 2008

Get HTML code from nsISelection in XUL

Filed under: firefox, flock, nsISelection, selection, xul — dafi @ 9:56 am

Recently after a discussion with my friend bard we realized how it is easy to obtain HTML source code associated to the current browser (eg Firefox, Flock) selection.

It’s too simple to discuss the snippet, leave the code speaks itself

function selectionToHTMLSource()  {
    var sel = document.commandDispatcher.focusedWindow.getSelection();
    if (sel.rangeCount < 1) {
        return “”;
    }

    var node = sel.getRangeAt(0).cloneContents();
    var xmlStr = new XMLSerializer().serializeToString(node);
    return xmlStr;
}

The code handles single selection, if you need to work with multiple selections like tables rows/cells take a look at Table2Clipboard


Next Page »

Blog at WordPress.com.