Snippets code from my daily experience

January 10, 2010

Sunday thought: Please don’t kill XUL

Filed under: sunday_thought,xul — dafi @ 3:33 pm

After reading the Mike Connor’s blog post and the Firebug’s post blog I realized XUL developers are closer to a revolution.

I have only a few questions in my mind and my stupid answers.

Q: Is it really so difficult to write XUL extensions?

A: For me no and I’m not a so clever person! OK there is a learning curve but every complete (non strictly complex) system requires to study, to learn and to compare itself with other people. Please don’t  confuse “rich” with “complicated“.

Q: We really need new addons ecosystem?

A: Maybe we need a lightweight ecosystem but XUL is the right way, Jetpack sounds good but today it is strongly tied to the browser, this will change when Jetpack for Thunderbird will be published.

I love Jetpack believe me 😉

Jetpack suffers from its so called “JQuery oriented syntax”.

I don’t like the sentence “JQuery oriented syntax” simply because doesn’t exists a “JQuery syntax”. JQuery uses Javascript closure syntax construct, I admit sometime it is very ugly and code tends to became naturally obfuscated

Are we sure “JQuery oriented syntax” is really so simple for newbies?

I agree with Daniel Gazman blog post, solution can be worst than the problem.

Q: Is restarting the browser after an addon installation so terrible?

A: I want my Operating System doesn’t require to me to restart after an update but I don’t care if my browser must be restarted after an addon installation/update. People are so lazy, people are so stupid? They accept OS reboots but suffer browser restarts? This is really a strange world!

Q: Is the problem related to Google Chrome success?

A: I don’t like so much Google Chrome, ok its startup time is amazing, then? What other feature is so fantastic? I’m a programmer and maybe I don’t see “commercial” related problem.

Maybe someone forgets that “Firefox is a platform”, Firefox isn’t a simple browser.

You can reuse your XUL platform know-how to create extensions for other applications; Thunderbird, Komodo, Songbird, Prism (my favorites four XUL applications)

You can create standalone applications using the XUL platform, too.

You can use extensions also on your mobile phone thanks to Fennec.

Please apologize me for my bad English and my rant

Advertisements

January 8, 2010

How to programmatically change XUL tree’s pseudo-classes

Filed under: extension,nsITreeView,xul — dafi @ 3:45 pm

I encountered the following problem: Change font and color for XUL tree based on user input. The user chooses the font and picks the color from a dialog and the tree widget is immediately redrawn with the new styles.

Changing styles for XUL trees requires the implementation of a nsITreeView, some nsIAtomService manipulation and some Mozilla CSS Extensions, definitively a bit verbose but enough simple after a dozen of attempts :P.

The Mozilla CSS tree extensions are mainly pseudo-classes that can’t be modified from code, so you need to create a CSS text snippet with new values and then “reload” it.

Reloading CSS files can be accomplished using the nsIStyleSheetService service, it only requires a nsIURI pointing to the CSS resource.

Based on the scenario described above the styles are generated at runtime so I need to create a CSS style representation and stores it for example on a temp file. The styles don’t really need to be persisted on disk so why do I need to create an unuseful file?

Well using the “data:” protocol it is possible to encode the generated CSS string and pass to nsIURI the data uri without needs to create temporary files as shown below.

function applyUserStyles(cssStyles) {
    // myTreeChildren is the CSS class name used for the tree
    // obviously can be parametrized
    var css = '.myTreeChildren::-moz-tree-cell-text {' + cssStyles + '}';
    var data = 'data:text/css;charset=utf-8,' + encodeURI(css);
    var sss = Components.classes["@mozilla.org/content/style-sheet-service;1"]
                .getService(Components.interfaces.nsIStyleSheetService);
    var ios = Components.classes["@mozilla.org/network/io-service;1"]
                .getService(Components.interfaces.nsIIOService);
    var u = ios.newURI(data, null, null);
    if (sss.sheetRegistered(u, sss.USER_SHEET)) {
        sss.unregisterSheet(u, sss.USER_SHEET);
    }
    sss.loadAndRegisterSheet(u, sss.USER_SHEET);
}
 

Maybe a simpler solution exists and my code is the worst way to proceed, if you know a better way please tell me 🙂

December 20, 2009

Contributions, now it’s my turn (Sunday Thought)

Thanks to the contribution platform available at AMO I bought one book and a couple of software licenses (not open sourced).

I can say that the AMO contribution feature is a great success for me, dozen of donors for two ‘not so famous‘ extensions like Table2Clipboard and ViewSourceWith.

Now I’ve a little budget to use to make contributions because NOW it’s my turn!

I’ll contribute to Firefox extensions without forget other open source projects especially the utilities, I love the little time saver applications 😛

I chosen low ‘Suggested Donation’ amount for my extensions but this has generated very expensive PayPal fees per transaction so I’ll make fewer contributions but all higher than 5$, I would the software authors take maximum profits from donations.

I hope in my country (Italy) PayPal made available micropayments very soon.

I would like to receive contributions also for my Komodo extensions, strangely the official dafizilla website doesn’t attract donors (I don’t like to fill it with banners and donations messages), I hope rumors about the Add-On Store will be confirmed and the store will host not only browser (i.e. Firefox) extensions and more important it will host also free/open source components.

October 18, 2009

.NET Framework Assistant, automatic plugin installation and PluginChecker

Filed under: extension,plugins,xul — dafi @ 2:21 pm

In these days the net is populated by blog posts about the .NET Framework Assistant plugin for Firefox, its disabling and the fact Firefox does not warn user when a plugin installs itself without explicit permission.

Well, this is a old problem at least for me, indeed I discovered it some time ago when my Firefox crashed (apparently) without reason, discovering after a couple of days that Microsoft Office 2003 plugin fought with Foxit Reader and Google update plugins.

The problem was that I never installed Office plugin!

plugins

Disabling Office plugin Firefox stopped to crash.

After that experience I decided to write a simple (very simple) extension that at every Firefox startup checks if there are new plugins installed.

plugincheckerNothing so cool, only a quick and dirty solution implemented in a few of hours.

Waiting Mozilla implements a better solution than mine you can install PluginChecker.

If you expect to find PluginChecker innovative or the “I-can-live-without-it” extension you are on the wrong place, if you expect a not intrusive and simple solution to unattended plugins installation than you can take a look at it.

You can download PluginChecker from SourceForge.

September 14, 2009

Table2Clipboard 1.0 now preserves styles

Filed under: excel,extension,firefox,openoffice,table2clipboard,xul — dafi @ 6:49 pm

Finally after almost a year I release a new version of Table2Clipboard, one of twelve extensions that won in 2008 the Firefox 2 Contest in the section Runners Up.

What’s new

Until now Table2Clipboard has pasted to clipboard the structure of HTML tables without the styles (colors, borders, fonts) but many users have asked me that the behavior was much more similar to that of Internet Explorer (IE) which indeed maintains many details.

Well, the version 1.0 preserves the styles and in certain cases the result is better than that obtained with IE.

IE inserts also the DOM elements declared “not visible”, for example the table shown in Figure 1  is pasted in Excel as shown in Figure 2.

ie

Figure 1

Table selection on Internet Explorer

excel-from-ie

Figure 2

Copy from Internet Explorer paste to Microsoft Excel

Table2Clipboard discards hidden DOM elements as shown in Figure 3, this makes more sense for me.

Paste from Firefox with Table2Clipboard to Microsoft Excel

Figure 3

Copy from Firefox with Table2Clipboard paste to Microsoft Excel

Other little improvements

Now web links are copied and user can choose to copy images (tag IMG), too.
All defaults settings can be modified from configuration dialog.

The copy of styles on OpenOffice doesn’t work as well as the one on Microsoft products.
The “Paste Special” feature available on OpenOffice doesn’t recognize CSS styles but only deprecated tags like FONT.

I will add support for OpenOffice soon but I prefer the “release early release often” (after a year??? :P) approach so this version has poor styles support on the popular open source office automation suite.

Compatibility issues with Thunderbird 3.x are now fixed.

Table2Clipboard can be installed from AMO or from the project site on dafizilla.

August 1, 2009

Table2Clipboard and clipboard application interoperability

Filed under: calc,clipboard,excel,extension,openoffice,table2clipboard,xul — dafi @ 10:35 am

calc_excel_t2cMany users asked to me to add to the extension Table2Clipboard (T2C for friends) the ability to preserve web links and maintain the styles during tables copy.

Preserving links and other HTML tags was a very easy task, I’ve written the code very quickly and both OpenOffice Calc and Microsoft Excel have handled correctly the pasted content.

When I started to support style preservation I discovered different and ugly results on the two popular office suites making harder to write cross platform XUL code.

Actually T2C pastes to clipboard inserting data in two different formats (flavors), unicode plain text and HTML format.
When users do “Paste Special” the HTML format is pasted and applications (Excel or Calc) render inside the data sheet.

Both Excel and Calc handle only the deprecated FONT tag and a subset of TABLE tag attributes and this represents a great limitation for style preservation from T2C.

If you try to paste from Microsoft Explorer to Microsoft Excel you discover everything is copied, the styles are totally preserved but if you paste from Explorer to OpenOffice Calc all style are lost!!!

Well, Explorer inserts to clipboard also RTF formatted text and Excel works very fine with the barely public RTF file format.

Clipboard application interoperability goes to hell, HTML is not fully supported by the “Paste Special” feature available on both suites, and as usual Microsoft uses semi proprietary data formats to exchange informations between applications.

I think at least OpenOffice should improve its “Paste” feature simply adding support for HTML style attribute.

T2C can preserve correctly styles only implementing platform specific code for OpenOffice and Microsoft Office and I really hate write specific platform.

I’m considering other alternatives but I see only the darkness of C++, OLE and core dump…

June 5, 2009

gContextMenu’s imageURL property refactored on Firefox 3.5x

Filed under: extension,firefox,xul — dafi @ 5:04 pm
Tags: , , ,

Edited on 9 June 2009 Mozilla guys decided to add a getter for imageURL so no extension will be affected by new property mediaURL replacement, you can read the full story at bug 497098.

Another time Mozilla community demonstrates its strength, why nobody considered the impact before modification is another story 😉

Today a ViewSourceWith user filed a bug about a regression on Firefox 3.5b4, causing VSW to no more open images 😯

After dressing the debug uniform I started to investigate the problem.

I’ve realized the object gContextMenu doesn’t more contain the property imageURL used by VSW and maybe many other extensions.

The imageURL property has been renamed/refactored to mediaURL.

Honestly the new name fits better its new usage and maybe the imageURL property is not intended for usage from extensions.

The poor gContextMenu documentation doesn’t describe imageURL so maybe I abused its usage.

I think gContextMenu need a better documentation because its usage is so sexy inside extensions.

The workaround

A string find/replace inside code fixed the bug, to maintain compatibility with FF 3.0.x I’ve modified the code as shown below

var imageURL = gContextMenu.imageURL || gContextMenu.mediaURL;

April 9, 2009

XUL search terms used to arrive here

Filed under: xul — dafi @ 3:12 pm

Very often I take a look at search terms used to arrive on my blog, a practice that I use to understand people needs about XUL.

Obviously it is only a funny exercise because this blog receives a ridiculous count of visits per month (~200) and the search terms are a very very very little subset of XUL related terms but I want to share with my readers (six or seven) this statistic.

Terms are sorted by views and divided in two categories: general XUL and Komodo specific

General XUL search terms

  1. nsiwebprogresslistener
  2. xul textbox css
  3. mccoy firefox
  4. xul menuitem image
  5. xul style tab
  6. mccoy command line
  7. xul synchronize scrollbars
    removing scrollbar xul, firefox 3.x (after 10th position but strictly related)
  8. xul paste clipboard as html text
  9. mdc notifyobservers example
  10. vsw thunderbird

Many people has problems with McCoy (3rd and 6th), indeed signing extensions is a very awful process.
I use an ANT build and the Massimiliamo Mirra’s StarTrek friend Mr Spock.

Styling XUL widgets and their color modifications (2nd, 4th and 5th) are mystical activities, people doesn’t read documentation and ignores the -moz-appearance existence.

Scrollbar synchronization is an hot topic, I used a simple DOM event based approach but I admit it isn’t so obvious.

People uses ViewSourceWith with Thunderbird, I’m glad to read this but honestly ViewSourceWith is a browser related extension.

Komodo specific

  1. komodo scintilla
  2. komodo snippets
  3. komodo color schemes
  4. komodo syntax checking disable
  5. komodo copy with color
  6. komodo adding colors
  7. komodo clipboard
  8. komodo macro open new browser window
  9. komodo command openkomodo
  10. dafizilla klint for komodo ide

Many people wants to style its Komodo installation like with Firefox (3rd) but many people hates the native lint checker UI (4th and 10th).

The Komodo linter UI is awful (IMHO) and my extension Klint seems to be known as a valid enhancement, well I’m very glad 😛 😛 hey guys, run to donate 😉

Using clipboard from macros is an hot topic I suppose developers don’t know version 5 contains xtk.clipboard namespace.

Snippets are a  leitmotiv, I have some ideas about a website dedicated to komodo snippets and macros but I need days with 35-39 hours before deploy it.

The masterpiece

  1. mature blonde girl

I don’t know how it is possible to arrive to a blog dedicated to XUL and other computer related materials searching porn-like terms 😛

I’m very curious and I would like to know the terms used to arrive to bigger blogs on planet.mozilla

April 1, 2009

Colored file tabs for Komodo

Filed under: extension,komodo,macro,openkomodo,xul — dafi @ 1:37 pm

A couple of months ago I wrote a Komodo macro allowing the editor view tabs to be colored based on user defined color schemes, when the macro became stable I published it on Komodo community forum.

Amazingly the macro received more feedback so I decided to ‘convert’ it to an XUL extension.

Komodo macros are fantastic but they don’t allow to create complex UIs so moving them to XPI become a necessary step.

Now ColorTab is ready and can be downloaded from here.

The original name was KolorTab, the ‘K’ letter used to remember Komodo but I’ve decided to use a more tradictional name 😛

ColorTab look&feel

ColorTab look&feel

March 1, 2009

Adding CSS Color Preview Tooltip to Komodo

Filed under: komodo,nsIDOMCSSPrimitiveValue,openkomodo,scintilla,xul — dafi @ 12:36 pm

Do you know Firebug? Uh no? Well please make a jump in twentieth century then return here 😛

Firebug has many great features but I love the color preview tooltip, from CSS Tab moving the mouse over a CSS color expression you will see a little box filled with the color found under the mouse pointer.

Every time I edit CSS (and HTML) files from Komodo subconsciously I move mouse over a color waiting to see the tooltip but nothing happens 😦

I’ve realized a macro can do this job so I’ve written ColorInfoTip that adds to Komodo the ability to show colored tooltip.

Some technical detail

This is a macro! No need to create extensions, the Komodo macro ecosystem is very cool and powerful.

The tooltip is a scintilla Call tip accessible from Komodo API.

The CSS color string can be written using many syntaxes like #RRGGBB or rgb(R,G,B) instead of reinventing the wheel and write the parser I’ve used the getRGBColorValue standard DOM method.

I discovered Scintilla uses BBGGRR color format instead of RRGGBB so the CSSRGBColor components have been converted to be Scintilla compliant.

Known problems

The macro isn’t perfect and any help is welcomed

  • Sometimes the tooltip doesn’t close especially changing editor view
  • Moving mouse quickly doesn’t update the color (fixed)
  • fill here the bug you found

ColorInfoTip.kpz

You can download the macro from ColorInfoTip.kpz then open the file from Komodo to install

Next Page »

Blog at WordPress.com.