home *** CD-ROM | disk | FTP | other *** search
- //-------------------------------------------------------------------------------------------
- // Option window module.
- //-------------------------------------------------------------------------------------------
-
- const Cc = Components.classes;
- const Ci = Components.interfaces;
-
- var EXPORTED_SYMBOLS = ["samfind_modoptionswin"];
-
- var samfind_modoptionswin =
- {
- _window_mediator : null,
-
- _init : function()
- {
- samfind_modoptionswin._window_mediator = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
- },
-
- closeModals : function()
- {
- var enumerator = samfind_modoptionswin._window_mediator.getEnumerator(null);
- while (enumerator.hasMoreElements())
- {
- var win = enumerator.getNext();
- if (win.name == "samfind-topic-add"
- || win.name == "samfind-topic-edit"
- || win.name == "samfind-website-add"
- || win.name == "samfind-website-edit"
- || win.name == "samfind-search-accelerators")
- {
- win.close();
- break;
- }
- }
- enumerator = null;
- },
-
- getOptionsWindow : function()
- {
- var enumerator = samfind_modoptionswin._window_mediator.getEnumerator(null);
- var opt = null;
- while (enumerator.hasMoreElements())
- {
- var win = enumerator.getNext();
- if (win.name == "samfind-options")
- {
- samfind_modoptionswin.closeModals();
- opt = win;
- break;
- }
- }
- enumerator = null;
- return opt;
- },
-
- openOptions : function(win, event)
- {
- var opt = samfind_modoptionswin.getOptionsWindow();
- if (opt)
- {
- opt.focus();
- }
- else
- {
- var branch = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService).getBranch("samfind.");
- var params = {tab : branch.getIntPref("options.current.tab"),
- topicid : null,
- websiteid : null,
- websitename : null,
- websitehomeurl : null,
- websitesearchurl : null,
- websiterssurl : null,
- btitemindex : null};
- win.openDialog("chrome://samfind/content/options/options.xul", "samfind-options", "chrome,resizable=no,titlebar=no", params);
- }
- if (event != null)
- {
- event.stopPropagation();
- }
- },
-
- openOptionsByRightClick : function(event, win)
- {
- if (event.button == 2)
- {
- var target = event.target;
- var selected_tab = null;
- var topic_id = null;
- var website_id = null;
- if (target.localName == "toolbarbutton")
- {
- if (target.parentNode.getAttribute("id") == "samfind-social")
- {
- selected_tab = 1;
- }
- else if (target.hasAttribute("topicid"))
- {
- selected_tab = 2;
- topic_id = target.getAttribute("topicid");
- }
- else if (target.hasAttribute("websitetopicid"))
- {
- selected_tab = 2;
- topic_id = target.getAttribute("websitetopicid");
- website_id = target.getAttribute("websiteid");
- }
- }
- else if (target.localName == "toolbarseparator"
- || target.localName == "label"
- || target.localName == "image"
- || target.localName == "spacer"
- || target.localName == "toolbarspring")
- {
- selected_tab = 0;
- }
- else
- {
- return;
- }
- //
- var opt = samfind_modoptionswin.getOptionsWindow();
- if (opt)
- {
- opt.focus();
- var tabbox = opt.document.getElementById("tabbox");
- if (tabbox)
- {
- tabbox.setAttribute("samfindselectedtab", selected_tab);
- tabbox.setAttribute("samfindtopicid", topic_id);
- tabbox.setAttribute("samfindwebsiteid", website_id);
- tabbox.setAttribute("samfindtbrightclickts", (new Date()).getTime());
- }
- }
- else
- {
- var params = {tab : selected_tab,
- topicid : topic_id,
- websiteid : website_id,
- websitename : null,
- websitehomeurl : null,
- websitesearchurl : null,
- websiterssurl : null,
- btitemindex : null};
- win.openDialog("chrome://samfind/content/options/options.xul", "samfind-options", "chrome,resizable=no,titlebar=no", params);
- }
- event.stopPropagation();
- }
- },
-
- openOptionsByDragAndDrop : function(topicId, websiteName, websiteHomeUrl, websiteSearchUrl, websiteRssUrl, win)
- {
- var opt = samfind_modoptionswin.getOptionsWindow();
- if (opt)
- {
- opt.focus();
- var tabbox = opt.document.getElementById("tabbox");
- if (tabbox)
- {
- tabbox.setAttribute("samfindtopicid", topicId);
- tabbox.setAttribute("samfindwebsitename", websiteName);
- tabbox.setAttribute("samfindwebsitehomeurl", websiteHomeUrl);
- tabbox.setAttribute("samfindwebsitesearchurl", websiteSearchUrl);
- tabbox.setAttribute("samfindwebsiterssurl", websiteRssUrl);
- tabbox.setAttribute("samfindtbdraganddropts", (new Date()).getTime());
- }
- }
- else
- {
- var params = {tab : 2,
- topicid : topicId,
- websiteid : null,
- websitename : websiteName,
- websitehomeurl : websiteHomeUrl,
- websitesearchurl : websiteSearchUrl,
- websiterssurl : websiteRssUrl,
- btitemindex : null};
- win.openDialog("chrome://samfind/content/options/options.xul", "samfind-options", "chrome,resizable=no,titlebar=no", params);
- }
- },
-
- openOptionsByDragAndDropOfBookmarksToolbarItem : function(topicId, index, win)
- {
- var opt = samfind_modoptionswin.getOptionsWindow();
- if (opt)
- {
- opt.focus();
- var tabbox = opt.document.getElementById("tabbox");
- if (tabbox)
- {
- tabbox.setAttribute("samfindtopicid", topicId);
- tabbox.setAttribute("samfindbtitemindex", index);
- tabbox.setAttribute("samfindtbdraganddropbtitemts", (new Date()).getTime());
- }
- }
- else
- {
- var params = {tab : 2,
- topicid : topicId,
- websiteid : null,
- websitename : null,
- websitehomeurl : null,
- websitesearchurl : null,
- websiterssurl : null,
- btitemindex : index};
- win.openDialog("chrome://samfind/content/options/options.xul", "samfind-options", "chrome,resizable=no,titlebar=no", params);
- }
- },
-
- openOptionsByContextMenuCommand : function(topicId, websiteId, websiteSearchUrl, win)
- {
- var opt = samfind_modoptionswin.getOptionsWindow();
- if (opt)
- {
- opt.focus();
- var tabbox = opt.document.getElementById("tabbox");
- if (tabbox)
- {
- tabbox.setAttribute("samfindtopicid", topicId);
- tabbox.setAttribute("samfindwebsiteid", websiteId);
- tabbox.setAttribute("samfindwebsitesearchurl", websiteSearchUrl);
- tabbox.setAttribute("samfindcntxtcommandts", (new Date()).getTime());
- }
- }
- else
- {
- var params = {tab : 2,
- topicid : topicId,
- websiteid : websiteId,
- websitename : null,
- websitehomeurl : null,
- websitesearchurl : websiteSearchUrl,
- websiterssurl : null,
- btitemindex : null};
- win.openDialog("chrome://samfind/content/options/options.xul", "samfind-options", "chrome,resizable=no,titlebar=no", params);
- }
- }
- };
-
- /**
- * Constructor.
- */
- (function() { this._init(); }).apply(samfind_modoptionswin);