how to associate icon with window created from window.open()

Talk about add-ons and extension development.
ericjung
Posts: 846
Joined: August 4th, 2003, 9:32 am

how to associate icon with window created from window.open()

Post by ericjung »

Hi,
Whenever I create a new window like so:

Code: Select all

window.open('http://www.yahoo.com','yahoo','centerscreen, chrome, dialog').focus();

there is a default icon associated with the window when using alt-tab to view all open windows on the PC. You can try this in extension developer/javascript environment to see what I mean. Create a window with the above code, then use alt-tab to see its icon.

Is there any way to get Firefox to use my extension's icon instead of the default one?

Thank you,
grimholtz
asqueella
Posts: 4019
Joined: November 16th, 2003, 3:05 am
Location: Russia, Moscow

Post by asqueella »

Yes, put the icon in [app folder]\icons\default\*.ico/xpm; the name of file must be the same as your <window> id. There's a bug filed against the Extension Manager to add an install.rdf arc to allow for easy installation of icons, in the meanwhile check how we do it in QuickNote.
ericjung
Posts: 846
Joined: August 4th, 2003, 9:32 am

Post by ericjung »

thanks!
ericjung
Posts: 846
Joined: August 4th, 2003, 9:32 am

Post by ericjung »

I'm looking at the QuickNotet source and don't see a folder called "icons"....I just see the .ico and .xpm files in the root folder, with references to them in install.js but not in install.rdf....
asqueella
Posts: 4019
Joined: November 16th, 2003, 3:05 am
Location: Russia, Moscow

Post by asqueella »

I said there is a bug against the EM to make it possible to install icons just by adding an arc to install.rdf, but ATM EM just copies the icons to \extensions\{quicknote-guid}\defaults\ and we copy them to application folder on startup.
ericjung
Posts: 846
Joined: August 4th, 2003, 9:32 am

Post by ericjung »

I'm having an awfully difficult time understanding this. The code you use to copy the icons seems to be this (install.js):

Code: Select all

error = addFile(author, version, 'chrome/' + jarName, folder, null);
if (error == SUCCESS) {
  var iconfolder = getFolder(getFolder("chrome", "icons"), "default");
  //addFile(name, "ce-main.xpm", iconfolder, "");
  addFile(name, "quicknote-main.ico", iconfolder, "");
  addFile(name, "quicknote-main.xpm", iconfolder, "");

Is that correct? But I'm not sure where addFile() and getFolder() are defined (in the Install object?). I'd really like to see docs on those to understand what's going on. Do you have ideas where I might find those? By the way, shouldn't you be moving the icons, not copying them?
asqueella
Posts: 4019
Joined: November 16th, 2003, 3:05 am
Location: Russia, Moscow

Post by asqueella »

Whoops. I'm very sorry. I was absolutely sure we included that copying code in 0.6, but it seems that I was wrong. See the newer version in CVS, function installIcons(), quicknote.js. Not install.js (that's not read by Firefox).

Code: Select all

function installIcons() {
  var iconFileName;
  var platform = navigator.platform.toLowerCase();

  if (platform.indexOf("win32") != -1)
    iconFileName = "quicknote-main.ico";
  else if (platform.indexOf("linux") != -1)
    iconFileName = "quicknote-main.xpm";
  else
    return false; // xxx don't know what yet to do on Mac and other platforms.

  // The target directory for icons
  // chromeIconDir = %MozDir%/chrome/icons/default/
  var chromeIconDir = QNDirIO.get("AChrom");
  chromeIconDir.append('icons');
  chromeIconDir.append('default');

  var chromeIcon = chromeIconDir.clone();
  chromeIcon.append(iconFileName);

  // Existing icon file, copied from the XPI by EM.
  // profileIcon = %Profile%/extensions/{C0CB8BA3-6C1B-47e8-A6AB-1FAB889562D9}/defaults/_icon_file_
  var profileIcon = QNDirIO.get("ProfD");
  profileIcon.append('extensions');
  profileIcon.append('{C0CB8BA3-6C1B-47e8-A6AB-1FAB889562D9}');
  profileIcon.append('defaults');
  profileIcon.append(iconFileName);

  if(!chromeIcon.exists() && profileIcon.exists()) {
    profileIcon.copyTo(chromeIconDir, null);
    if(!chromeIcon.exists()) {
      QNDebug.dump("QuickNote: You do not have the correct file permissions to install icons");
      return false;
    }
  }
  return true;
}
ericjung
Posts: 846
Joined: August 4th, 2003, 9:32 am

Post by ericjung »

Bug 242757 says it's been fixed as of 2005-04-11 09:46 PST. Anyone know if it's in FF 1.5 and/or Seamonkey?
asqueella
Posts: 4019
Joined: November 16th, 2003, 3:05 am
Location: Russia, Moscow

Post by asqueella »

Firefox 1.5 - yes. Seamonkey - I don't care, but probably not.
User avatar
mrtech
Posts: 2007
Joined: May 15th, 2003, 7:46 am
Location: New York
Contact:

Post by mrtech »

just wondering, what other formats linux support for window icons, thanks.
mel reyes • mrtech.com • BlogPlaxoLinkedInTwitter
Support mrtech.com get our toolbar
Bloodeye
Posts: 582
Joined: July 12th, 2004, 7:20 pm

Post by Bloodeye »

Just so I'm up to speed...

1) If I create a icons\default\ directory within my chrome directory.
2) Place my associative .ico files in there.
3) Package my extension within a .xpi file

The EM will install the icons when installing my extension? Is that what Bug 24757 corrected?

*BTW - by doing steps above your icons will be installed and usable, but not to [app folder]\icons\default\ instead they will be installed to [profile extension was installed into]\extensions\{extension-guid}\icons\default\
asqueella
Posts: 4019
Joined: November 16th, 2003, 3:05 am
Location: Russia, Moscow

Post by asqueella »

Yes, the idea is correct, but:
1) .ico and .xpm, I believe
2) {extension-guid}\chrome\icons\default\
ericjung
Posts: 846
Joined: August 4th, 2003, 9:32 am

Post by ericjung »

just wondering, what other formats linux support for window icons, thanks.

The existence of sites like these would suggest that PNG icons work with Gnome and KDE, but I haven't tried it. If anyone does, please post your results here...
ericjung
Posts: 846
Joined: August 4th, 2003, 9:32 am

Post by ericjung »

1) If I create a icons\default\ directory within my chrome directory.
2) Place my associative .ico files in there.
3) Package my extension within a .xpi file

The EM will install the icons when installing my extension?

I tried this and it isn't working for me--no icon is associated with the dialog whose id is the filename of the .ico file.

Help!

Is there a page at developer.mozilla.org or kb.mozillazine.org on how to do this?

thanks,
grimholtz
User avatar
Pike
Posts: 2293
Joined: August 10th, 2003, 12:12 pm
Location: UK
Contact:

Post by Pike »

Post Reply