home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 September / PCWorld_2008-09_cd.bin / komunikace / kmeleon / K-Meleon1.1.3en-US.exe / macros / search.kmm < prev    next >
Text File  |  2007-05-04  |  6KB  |  148 lines

  1. # K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage)
  2.  
  3. # ---------- Web Search --------------------------------------------------------------------------------------------
  4. #
  5. # Dependencies    : main.kmm ($macroPrefBranch, $kLayers, OpenURL)
  6. # Resources    : -
  7. # Preferences    : kmeleon.plugins.macros.search.kmforums
  8. #          kmeleon.plugins.macros.search.engine[0,1,...].name
  9. #          kmeleon.plugins.macros.search.engine[0,1,...].url
  10. #          kmeleon.plugins.macros.search.meta[0,1,...].url
  11. #
  12. # ------------------------------------------------------------------------------------------------------------------
  13.  
  14. # Consult default engine (default engine is also used when macros are disabled)
  15. Search{
  16. $_Search_EngineURL==""?$_Search_EngineURL=getpref(STRING,$_Search_pref_DefaultURL):0;
  17. $_Search_EngineName==""?$_Search_EngineName=getpref(STRING,$_Search_pref_DefaultName):0;
  18. $_Search_Query=$SelectedText; $_Search_Query==""?&_Search_Typed:&_Search_Selected;
  19. $_Search_EngineName="";
  20. $_Search_EngineURL="";
  21. }
  22. Search_PasteAndSearch{
  23. $URLBAR=getclipboard(); &Search;
  24. }
  25.  
  26. # Lock/unlock current engine
  27. Search_ToggleEngineLock{
  28. menuchecked=getpref(BOOL,$_Search_pref_Locked);
  29. togglepref(BOOL,$_Search_pref_Locked);
  30. statusbar(sub("%s",getpref(BOOL,$_Search_pref_Locked)?getpref(STRING,$_Search_pref_DefaultName):_("Last used engine"),_("Default search engine: %s")));
  31. }
  32.  
  33. # Consult multiple engines (Metasearch)
  34. Search_Metasearch{
  35. $_Search_Metasearch_Query=$SelectedText;
  36. $_Search_Metasearch_Query==""?&_Search_Metasearch_Typed:&_Search_Metasearch_Selected;
  37. }
  38.  
  39. # Consult a particular engine
  40. Search_KMForums{
  41. $_Search_EngineURL=getpref(STRING,$macroPrefBranch."search.kmforums");
  42. $_Search_EngineName=_("K-Meleon Forums Search"); &Search;
  43. }
  44. Search_Engine{
  45. menuchecked=(getpref(STRING,$_Search_pref_Engine.$ARG.".url")==getpref(STRING,$_Search_pref_DefaultURL));
  46. $_n=$ARG; &_Search;
  47. }
  48.  
  49. # ----- PRIVATE
  50.  
  51. # Normal websearch
  52.  
  53. $_Search_EngineURL="";
  54. $_Search_EngineName="";
  55.  
  56. $_Search_pref_DefaultName="kmeleon.general.searchEngineName";
  57. $_Search_pref_DefaultURL="kmeleon.general.searchEngine";
  58. $_Search_pref_Engine=$macroPrefBranch."search.engine";
  59. $_Search_pref_Locked=$macroPrefBranch."search.locked";
  60.  
  61. # interface for search9.kmm to hook into menu sync
  62. $_Search_SyncMenu="";
  63.  
  64. _Search{
  65. $_Search_EngineURL=getpref(STRING,$_Search_pref_Engine.$_n.".url");
  66. $_Search_EngineName=getpref(STRING,$_Search_pref_Engine.$_n.".name");
  67. &_Search_Init;
  68. }
  69. _Search_Init{
  70. $__locked=getpref(BOOL,$_Search_pref_Locked);
  71. $__locked==true?0:setpref(STRING,$_Search_pref_DefaultURL,$_Search_EngineURL);
  72. $__locked==true?0:setpref(STRING,$_Search_pref_DefaultName,$_Search_EngineName);
  73. # interface for search9.kmm to hook into menu sync
  74. $__locked==true?0:macros($_Search_SyncMenu);
  75. &Search;
  76. }
  77. _Search_Selected{
  78. $OpenURL=$_Search_EngineURL.urlencode($_Search_Query); &OpenURL_Selected;
  79. }
  80. _Search_Typed{
  81. $__query=$URLBAR;
  82. $__query==$URL?$__query=prompt(_("Enter search query:"),sub("%s",$_Search_EngineName,_("Search (%s)"))):0;
  83. $OpenURL=$__query==""?"":$_Search_EngineURL.urlencode($__query);
  84. # prevent search queries from being added to the MRU
  85. $__pref="kmeleon.MRU.behavior"; $__data=getpref(INT,$__pref); $__data==2?setpref(INT,$__pref,3):0; &OpenURL_Typed; setpref(INT,$__pref,$__data);
  86. }
  87.  
  88. # Metasearch
  89.  
  90. $_Search_pref_Meta=$macroPrefBranch."search.meta";
  91.  
  92. _Search_Metasearch_Selected{
  93. $_pref=$_OpenURL_Selected; &_Search_Metasearch_Open;
  94. }
  95. _Search_Metasearch_Typed{
  96. $_pref=$_OpenURL_Typed;
  97. $_Search_Metasearch_Query=$URLBAR; $_Search_Metasearch_Query==$URL?$_Search_Metasearch_Query=prompt(_("Enter search query:"),sub("%s",_("Multisearch"),_("Search (%s)"))):0; 
  98. $_Search_Metasearch_Query==""?0:&_Search_Metasearch_Open;
  99. }
  100. _Search_Metasearch_Open{
  101. $_how=getpref(STRING,$_pref); $_Search_Metasearch_Query=urlencode($_Search_Metasearch_Query);
  102. $_how=="ID_OPEN_LINK"?$_how=0:0; 
  103. $_how=="ID_OPEN_LINK_IN_NEW_WINDOW"?$_how=0:0; 
  104. $_how=="ID_OPEN_LINK_IN_BACKGROUND"?$_how=1:0; 
  105. $_how=="layers(OpenURL)"?$_how=0:0; 
  106. $_how=="layers(OpenURLBg)"?$_how=1:0; 
  107. $URLBAR=$URL; $_i=0; while($_i>-1) &_Search_Metasearch_OpenLoop;
  108. }
  109. _Search_Metasearch_OpenLoop{
  110. $__data=getpref(STRING,$_Search_pref_Meta.$_i.".url"); $OpenURL=$__data.$_Search_Metasearch_Query;
  111. $__data==""?0:$_how==0?&OpenURL_InNew:0;
  112. $__data==""?0:$_how==1?&OpenURL_InBg:0;
  113. $_i=$__data==""?-1:$_i+1;
  114. }
  115.  
  116. # Accels/Menus
  117.  
  118. _Search_BuildMenu{
  119. # help menu
  120. setmenu(KMForums,macro,"K-Meleon Forums &Search...",Search_KMForums);
  121. # tools menu
  122. setmenu("WebServices",popup,"&Web Search",ID_NAV_SEARCH);
  123. setmenu("WebServices",command,"",ID_NAV_SEARCH);
  124. setmenu("&Web Search",inline,_Search_Engines);
  125. setmenu(_Search_Engines,inline,_Search_Engines_Configurable);
  126. $_j=0; while($_j>-1) &_Search_BuildMenuLoop;
  127. setmenu(_Search_Engines,inline,_Search_Engines_Metasearch);
  128. getpref(STRING,$_Search_pref_Meta."0.url")==""?0:setmenu(_Search_Engines_Metasearch,macro,"&Multisearch",Search_Metasearch);
  129. setmenu("&Web Search",inline,_Search_Config);
  130. setmenu(_Search_Config,macro,"Use As &Default Engine",Search_ToggleEngineLock,0);
  131. # context menus
  132. setmenu(Selection,popup,"&Web Search");
  133. # go button
  134. setmenu(_Go_Clipboard,macro,"Paste And &Search",Search_PasteAndSearch);
  135. }
  136. _Search_BuildMenuLoop{
  137. $__data=getpref(STRING,$_Search_pref_Engine.$_j.".name");
  138. $__data==""?0:setmenu(_Search_Engines_Configurable,macro,$__data,"Search_Engine(".$_j.")");
  139. $_j=$__data==""?-1:$_j+1;
  140. }
  141. _Search_SetAccels{
  142. setaccel("CTRL G","macros(Search)");
  143. setaccel("CTRL SHIFT V","macros(Search_PasteAndSearch)");
  144. }
  145. $OnInit=$OnInit."_Search_SetAccels;_Search_BuildMenu;";
  146.  
  147. # ------------------------------------------------------------------------------------------------------------------
  148. $macroModules=$macroModules."Search;";