home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 9866 / 9866.xpi / modules / samfind_modoptionswin.jsm < prev    next >
Encoding:
Text File  |  2009-11-16  |  6.9 KB  |  242 lines

  1. //-------------------------------------------------------------------------------------------
  2. // Option window module.
  3. //-------------------------------------------------------------------------------------------
  4.  
  5. const Cc = Components.classes;
  6. const Ci = Components.interfaces;
  7.  
  8. var EXPORTED_SYMBOLS = ["samfind_modoptionswin"];
  9.  
  10. var samfind_modoptionswin =
  11. {
  12.     _window_mediator : null,
  13.  
  14.     _init : function()
  15.     {
  16.         samfind_modoptionswin._window_mediator = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
  17.       },
  18.  
  19.     closeModals : function()
  20.     {
  21.         var enumerator = samfind_modoptionswin._window_mediator.getEnumerator(null);
  22.         while (enumerator.hasMoreElements())
  23.         {
  24.             var win = enumerator.getNext();
  25.             if (win.name == "samfind-topic-add"
  26.                 || win.name == "samfind-topic-edit"
  27.                 || win.name == "samfind-website-add"
  28.                 || win.name == "samfind-website-edit"
  29.                 || win.name == "samfind-search-accelerators")
  30.             {
  31.                 win.close();
  32.                 break;
  33.             }
  34.         }
  35.         enumerator = null;
  36.     },
  37.  
  38.     getOptionsWindow : function()
  39.     {
  40.         var enumerator = samfind_modoptionswin._window_mediator.getEnumerator(null);
  41.         var opt = null;
  42.         while (enumerator.hasMoreElements())
  43.         {
  44.               var win = enumerator.getNext();
  45.             if (win.name == "samfind-options")
  46.             {
  47.                 samfind_modoptionswin.closeModals();
  48.                 opt = win;
  49.                 break;
  50.             }
  51.         }
  52.         enumerator = null;
  53.         return opt;
  54.     },
  55.  
  56.     openOptions : function(win, event)
  57.     {
  58.         var opt = samfind_modoptionswin.getOptionsWindow();
  59.         if (opt)
  60.         {
  61.             opt.focus();
  62.         }
  63.         else
  64.         {
  65.             var branch = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService).getBranch("samfind.");
  66.             var params = {tab : branch.getIntPref("options.current.tab"),
  67.                           topicid : null,
  68.                           websiteid : null,
  69.                           websitename : null,
  70.                           websitehomeurl : null,
  71.                           websitesearchurl : null,
  72.                           websiterssurl : null,
  73.                           btitemindex : null};
  74.             win.openDialog("chrome://samfind/content/options/options.xul", "samfind-options", "chrome,resizable=no,titlebar=no", params);
  75.         }
  76.         if (event != null)
  77.         {
  78.             event.stopPropagation();
  79.         }
  80.     },
  81.  
  82.     openOptionsByRightClick : function(event, win)
  83.     {
  84.         if (event.button == 2)
  85.         {
  86.             var target = event.target;
  87.             var selected_tab = null;
  88.             var topic_id = null;
  89.             var website_id = null;
  90.             if (target.localName == "toolbarbutton")
  91.             {
  92.                 if (target.parentNode.getAttribute("id") == "samfind-social")
  93.                 {
  94.                     selected_tab = 1;
  95.                 }
  96.                 else if (target.hasAttribute("topicid"))
  97.                 {
  98.                     selected_tab = 2;
  99.                     topic_id = target.getAttribute("topicid");
  100.                 }
  101.                 else if (target.hasAttribute("websitetopicid"))
  102.                 {
  103.                     selected_tab = 2;
  104.                     topic_id = target.getAttribute("websitetopicid");
  105.                     website_id = target.getAttribute("websiteid");
  106.                 }
  107.             }
  108.             else if (target.localName == "toolbarseparator"
  109.                      || target.localName == "label"
  110.                      || target.localName == "image"
  111.                      || target.localName == "spacer"
  112.                      || target.localName == "toolbarspring")
  113.             {
  114.                 selected_tab = 0;
  115.             }
  116.             else
  117.             {
  118.                 return;    
  119.             }
  120.             //
  121.             var opt = samfind_modoptionswin.getOptionsWindow();
  122.             if (opt)
  123.             {
  124.                 opt.focus();
  125.                 var tabbox = opt.document.getElementById("tabbox");
  126.                 if (tabbox)
  127.                 {
  128.                     tabbox.setAttribute("samfindselectedtab", selected_tab);
  129.                     tabbox.setAttribute("samfindtopicid", topic_id);
  130.                     tabbox.setAttribute("samfindwebsiteid", website_id);
  131.                     tabbox.setAttribute("samfindtbrightclickts", (new Date()).getTime());
  132.                 }
  133.             }
  134.             else
  135.             {
  136.                 var params = {tab : selected_tab,
  137.                               topicid : topic_id,
  138.                               websiteid : website_id,
  139.                               websitename : null,
  140.                               websitehomeurl : null,
  141.                               websitesearchurl : null,
  142.                               websiterssurl : null,
  143.                               btitemindex : null};
  144.                 win.openDialog("chrome://samfind/content/options/options.xul", "samfind-options", "chrome,resizable=no,titlebar=no", params);
  145.             }
  146.             event.stopPropagation();
  147.         }
  148.     },
  149.  
  150.     openOptionsByDragAndDrop : function(topicId, websiteName, websiteHomeUrl, websiteSearchUrl, websiteRssUrl, win)
  151.     {
  152.         var opt = samfind_modoptionswin.getOptionsWindow();
  153.         if (opt)
  154.         {
  155.             opt.focus();
  156.             var tabbox = opt.document.getElementById("tabbox");
  157.             if (tabbox)
  158.             {
  159.                 tabbox.setAttribute("samfindtopicid", topicId);
  160.                 tabbox.setAttribute("samfindwebsitename", websiteName);
  161.                 tabbox.setAttribute("samfindwebsitehomeurl", websiteHomeUrl);
  162.                 tabbox.setAttribute("samfindwebsitesearchurl", websiteSearchUrl);
  163.                 tabbox.setAttribute("samfindwebsiterssurl", websiteRssUrl);
  164.                 tabbox.setAttribute("samfindtbdraganddropts", (new Date()).getTime());
  165.             }
  166.         }
  167.         else
  168.         {
  169.             var params = {tab : 2,
  170.                           topicid : topicId,
  171.                           websiteid : null,
  172.                           websitename : websiteName,
  173.                           websitehomeurl : websiteHomeUrl,
  174.                           websitesearchurl : websiteSearchUrl,
  175.                           websiterssurl : websiteRssUrl,
  176.                           btitemindex : null};
  177.             win.openDialog("chrome://samfind/content/options/options.xul", "samfind-options", "chrome,resizable=no,titlebar=no", params);
  178.         }
  179.     },
  180.  
  181.     openOptionsByDragAndDropOfBookmarksToolbarItem : function(topicId, index, win)
  182.     {
  183.         var opt = samfind_modoptionswin.getOptionsWindow();
  184.         if (opt)
  185.         {
  186.             opt.focus();
  187.             var tabbox = opt.document.getElementById("tabbox");
  188.             if (tabbox)
  189.             {
  190.                 tabbox.setAttribute("samfindtopicid", topicId);
  191.                 tabbox.setAttribute("samfindbtitemindex", index);
  192.                 tabbox.setAttribute("samfindtbdraganddropbtitemts", (new Date()).getTime());
  193.             }
  194.         }
  195.         else
  196.         {
  197.             var params = {tab : 2,
  198.                           topicid : topicId,
  199.                           websiteid : null,
  200.                           websitename : null,
  201.                           websitehomeurl : null,
  202.                           websitesearchurl : null,
  203.                           websiterssurl : null,
  204.                           btitemindex : index};
  205.             win.openDialog("chrome://samfind/content/options/options.xul", "samfind-options", "chrome,resizable=no,titlebar=no", params);
  206.         }
  207.     },
  208.  
  209.     openOptionsByContextMenuCommand : function(topicId, websiteId, websiteSearchUrl, win)
  210.     {
  211.         var opt = samfind_modoptionswin.getOptionsWindow();
  212.         if (opt)
  213.         {
  214.             opt.focus();
  215.             var tabbox = opt.document.getElementById("tabbox");
  216.             if (tabbox)
  217.             {
  218.                 tabbox.setAttribute("samfindtopicid", topicId);
  219.                 tabbox.setAttribute("samfindwebsiteid", websiteId);
  220.                 tabbox.setAttribute("samfindwebsitesearchurl", websiteSearchUrl);
  221.                 tabbox.setAttribute("samfindcntxtcommandts", (new Date()).getTime());
  222.             }
  223.         }
  224.         else
  225.         {
  226.             var params = {tab : 2,
  227.                           topicid : topicId,
  228.                           websiteid : websiteId,
  229.                           websitename : null,
  230.                           websitehomeurl : null,
  231.                           websitesearchurl : websiteSearchUrl,
  232.                           websiterssurl : null,
  233.                           btitemindex : null};
  234.             win.openDialog("chrome://samfind/content/options/options.xul", "samfind-options", "chrome,resizable=no,titlebar=no", params);
  235.         }
  236.     }
  237. };
  238.  
  239. /**
  240.  * Constructor.
  241.  */
  242. (function() { this._init(); }).apply(samfind_modoptionswin);