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 / groups.kmm < prev    next >
Text File  |  2007-05-04  |  13KB  |  292 lines

  1. # K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage)
  2.  
  3. # ---------- Groups ------------------------------------------------------------------------------------------------
  4. #
  5. # Dependencies    : main.kmm ($kBookmarks/$kHotlist/$kLayers, OpenURL)
  6. # Resources    : -
  7. # Preferences    : kmeleon.plugins.macros.groups.crash
  8. #          kmeleon.plugins.macros.groups.last
  9. #          kmeleon.plugins.macros.groups.startup
  10. #          kmeleon.plugins.macros.groups.temp
  11. #          kmeleon.plugins.macros.groups.user
  12. #          kmeleon.plugins.macros.groups.user.<groupname>
  13. #
  14. # ------------------------------------------------------------------------------------------------------------------
  15.  
  16. # ----- Opening Groups
  17.  
  18. Groups_OpenGroup{
  19. $_Group=$ARG; $_Group==""?$_Group=$URLBAR:0; $_Group==""?$_Group=$URL:0; &_Groups_DlgSet;
  20. $_Group==$URL?$_Group=prompt($_Groups_DlgTip,$_Groups_DlgTitOpen,""):0;
  21. $_data=$_Group==""?"":getpref(STRING,$_Groups_UserPrefBranch.$_Group);
  22. $_Group==""?0:($_data==""?&_Groups_OpenFolder:&_Groups_OpenGroup);
  23. }
  24. Groups_OpenGroupStartup{
  25. $Home=Groups_OpenGroupStartup;
  26. $__t=getpref(STRING,$_Groups_Startup);
  27. $__t=="last"?&Groups_OpenLastSession:$URLBAR=sub($_Groups_User,"",$__t);
  28. $__t=="last"?0:&Groups_OpenGroup;
  29. }
  30. Groups_OpenLastSession{
  31. $_data=getpref(STRING,$_Groups_Last);
  32. $_data==""?0:&_Groups_OpenGroup;
  33. }
  34.  
  35. # PRIVATE
  36. _Groups_OpenFolder{
  37. $kLayers==true?(((pluginmsgex(layers,NumberOfLayersInWindow,"",INT)==1)*(($URL=="about:blank")+($URL=="")))==1?&_Groups_OpenGroup_LayersReplace:&_Groups_OpenGroup_LayersAdd):($URL=="about:blank"?&_Groups_OpenGroup_WindowsReplace:&_Groups_OpenGroup_WindowsAdd);
  38. $__data=""; index($_Group,$_Groups_User)==0?$_Group=sub($_Groups_User,"",$_Group):0; $OpenURL=$_Group;
  39. $kBookmarks==true?$__data=$__data.pluginmsgex(bookmarks,FindNick,$_Group,STRING):0;
  40. $kHotlist==true?$__data=$__data.pluginmsgex(hotlist,FindNick,$_Group,STRING):0;
  41. $__data==""?alert(sub("%s",$_Group,$_Groups_DlgMsg),$_Groups_DlgTitOpen):&OpenURL_Typed;
  42. }
  43.  
  44. $_Groups_OpenCmd="";
  45. _Groups_OpenGroup{
  46. $kLayers==true?(((pluginmsgex(layers,NumberOfLayersInWindow,"",INT)==1)*(($URL=="about:blank")+($URL=="")))==1?&_Groups_OpenGroup_LayersReplace:&_Groups_OpenGroup_LayersAdd):($URL=="about:blank"?&_Groups_OpenGroup_WindowsReplace:&_Groups_OpenGroup_WindowsAdd);
  47. $_Groups_OpenGroup_data=$kLayers==true?"":$_data;
  48. $_Groups_OpenGroup_init=true;
  49. $kLayers==true?pluginmsg(layers,$_Groups_OpenCmd,$_data):&_Groups_OpenGroup_Windows;
  50. }
  51.  
  52. $_Groups_OpenGroup_init=false;
  53. $_Groups_OpenGroup_data="";
  54. _Groups_OpenGroup_Windows{
  55. $__i=$_Groups_OpenGroup_data==""?0:index($_Groups_OpenGroup_data,"\t");
  56. $__u=$_Groups_OpenGroup_data==""?"":substr($_Groups_OpenGroup_data,0,$__i);
  57. $__u==""?0:$_Groups_OpenGroup_init==true?($URL=="about:blank"?open($__u):opennew($__u)):openbg($__u);
  58. $__u==""?0:$_Groups_OpenGroup_init=false;
  59. $__u==""?0:$_Groups_OpenGroup_data=sub($__u."\t","",$_Groups_OpenGroup_data);
  60. $__u==""?0:&_Groups_OpenGroup_Windows;
  61. }
  62.  
  63. $_Groups_OpenHow="kmeleon.general.opengroup";
  64. _Groups_OpenGroup_LayersAdd{
  65. $_Groups_OpenCmd==""?&_Groups_OpenGroup_LayersReplace:$_Groups_OpenCmd="AddLayersToWindow";
  66. setpref(STRING,$_Groups_OpenHow,"layers(".$_Groups_OpenCmd.")");
  67. }
  68. _Groups_OpenGroup_LayersReplace{
  69. $_Groups_OpenCmd="ReplaceLayersInWindow";
  70. setpref(STRING,$_Groups_OpenHow,"layers(".$_Groups_OpenCmd.")");
  71. }
  72. _Groups_OpenGroup_WindowsAdd{
  73. $_Groups_OpenCmd==""?&_Groups_OpenGroup_WindowsReplace:$_Groups_OpenCmd="ID_OPEN_LINK_IN_NEW_WINDOW|ID_OPEN_LINK_IN_BACKGROUND";
  74. setpref(STRING,$_Groups_OpenHow,$_Groups_OpenCmd);
  75. }
  76. _Groups_OpenGroup_WindowsReplace{
  77. $_Groups_OpenCmd="ID_OPEN_LINK|ID_OPEN_LINK_IN_BACKGROUND";
  78. setpref(STRING,$_Groups_OpenHow,$_Groups_OpenCmd);
  79. }
  80.  
  81. # ----- Editing Groups
  82.  
  83. Groups_AddPage{
  84. $_tit=_("Add To Group");
  85. $_group=prompt(_("Enter group name to add this page to:"),$_tit,""); $__data=getpref(STRING,$_Groups_UserPrefBranch.$_group);
  86. $_group==""?0:setpref(STRING,$_Groups_UserPrefBranch.$_group,$__data.$URL."\t");
  87. &_Groups_Add;
  88. }
  89. Groups_AddLink{
  90. $_tit=_("Add To Group");
  91. $_group=prompt(_("Enter group name to add this link to:"),$_tit,""); $__data=getpref(STRING,$_Groups_UserPrefBranch.$_group);
  92. $_group==""?0:setpref(STRING,$_Groups_UserPrefBranch.$_group,$__data.$LinkURL."\t");
  93. &_Groups_Add;
  94. }
  95. Groups_AddAllToGroup{
  96. $_tit=_("Add To Group");
  97. $_group=prompt(_("Enter group name to add these layers to:"),$_tit,""); $__data=getpref(STRING,$_Groups_UserPrefBranch.$_group);
  98. $_group==""?0:setpref(STRING,$_Groups_UserPrefBranch.$_group,$__data.pluginmsgex(layers,GetLayersInWindow,"",STRING));
  99. &_Groups_Add;
  100. }
  101. Groups_Delete{
  102. menugrayed=(getpref(STRING,$_Groups_Pref)=="");
  103. $_tit=_("Delete Group"); $_groups=getpref(STRING,$_Groups_Pref);
  104. $_group=prompt(_("Enter name of group to delete:"),$_tit,"");
  105. $_group==""?0:index($_groups,"\n".$_group."\n")>-1?&_Groups_Delete:alert(sub("%s",$_group,_("No group named '%s' found.")),$_tit);
  106. }
  107.  
  108. # PRIVATE
  109. _Groups_Add{
  110. $__data=getpref(STRING,$_Groups_Pref); $__data==""?$__data="\n":0;
  111. $_group==""?0:index($__data,"\n".$_group."\n")>-1?0:setpref(STRING,$_Groups_Pref,$__data.$_group."\n");
  112. &_Groups_BuildGroupsMenu;
  113. }
  114. _Groups_SaveClosed{
  115. $_Groups_Cnt?0:&_Groups_SaveLayersClosed; $_Groups_Cnt?($_Groups_Cnt=$_Groups_Cnt==1?0:$_Groups_Cnt-1):0;
  116. }
  117. _Groups_SaveLastSession{
  118. setpref(STRING,$_Groups_Last,getpref(STRING,$_Groups_Temp));
  119. }
  120. _Groups_SaveLayers{
  121. $kLayers==true?setpref(STRING,$_Groups_Temp,pluginmsgex(layers,GetLayersInWindow,"",STRING)):0;
  122. }
  123. _Groups_SaveLayersClosed{
  124. $__data=$kLayers==true?pluginmsgex(layers,GetLayersInWindow,"",STRING):"";
  125. $__data==""?0:$__data=sub($URL."\t","",$__data); setpref(STRING,$_Groups_Temp,$__data==""?$URL:$__data);
  126. }
  127. _Groups_Delete{
  128. $_groups=sub("\n".$_group."\n","\n",$_groups); delpref($_Groups_UserPrefBranch.$_group);
  129. &_Groups_BuildGroupsMenu; length($_groups)==1?delpref($_Groups_Pref):setpref(STRING,$_Groups_Pref,$_groups);
  130. }
  131.  
  132. # ----- Startup Actions
  133.  
  134. Groups_NavHome{
  135. getpref(STRING,$_Groups_Startup)==""?id(ID_NAV_HOME):&Groups_OpenGroupStartup;
  136. }
  137.  
  138. Groups_StartBlank{
  139. menuchecked=((getpref(STRING,$_Groups_Startup)=="")*(getpref(BOOL,$KM_StartHome)==false));
  140. setpref(BOOL,$KM_StartHome,false);
  141. delpref($_Groups_Startup);
  142. }
  143. Groups_StartWithHomepage{
  144. menuchecked=((getpref(STRING,$_Groups_Startup)=="")*(getpref(BOOL,$KM_StartHome)==true));
  145. $Home=_Home;
  146. setpref(BOOL,$KM_StartHome,true); delpref($_Groups_Startup);
  147. }
  148. Groups_StartWithGroup{
  149. menuchecked=((getpref(STRING,$_Groups_Startup)!="")*(getpref(STRING,$_Groups_Startup)!="last"));
  150. $__data=getpref(STRING,$_Groups_Startup); $__data=="last"?$__data="":$__data=sub($_Groups_User,"",$__data); &_Groups_DlgSet;
  151. $_Group=prompt($_Groups_DlgTip,$_Groups_DlgTitStart,$__data);
  152. $_Group==""?0:getpref(STRING,$_Groups_UserPrefBranch.$_Group)==""?&_Groups_StartWithFolder:&_Groups_StartWithGroup;
  153. }
  154. Groups_StartWithLastSession{
  155. menuchecked=(getpref(STRING,$_Groups_Startup)=="last");
  156. setpref(BOOL,$KM_StartHome,false);
  157. setpref(STRING,$_Groups_Startup,"last");
  158. }
  159.  
  160. # PRIVATE
  161. _Groups_StartWithGroup{
  162. $Home=Groups_OpenGroupStartup;
  163. setpref(BOOL,$KM_StartHome,false); setpref(STRING,$_Groups_Startup,$_Groups_User.$_Group);
  164. }
  165. _Groups_StartWithFolder{
  166. $Home=Groups_OpenGroupStartup;
  167. $__data="";
  168. $kBookmarks==true?$__data=$__data.pluginmsgex(bookmarks,FindNick,$_Group,STRING):0;
  169. $kHotlist==true?$__data=$__data.pluginmsgex(hotlist,FindNick,$_Group,STRING):0;
  170. $__data!=""?setpref(BOOL,$KM_StartHome,false):alert(sub("%s",$_Group,$_Groups_DlgMsg),$_Groups_DlgTitStart);
  171. $__data!=""?setpref(STRING,$_Groups_Startup,$_Group):0;
  172. }
  173.  
  174. # ----- PRIVATE
  175.  
  176. $_Groups_User="user.";
  177. $_Groups_Pref=$macroPrefBranch."groups.user";
  178. $_Groups_PrefBranch=$macroPrefBranch."groups.";
  179. $_Groups_UserPrefBranch=$_Groups_PrefBranch.$_Groups_User;
  180. $_Groups_Startup=$_Groups_PrefBranch."startup";
  181. $_Groups_Crash=$_Groups_PrefBranch."crash";
  182. $_Groups_Temp=$_Groups_PrefBranch."temp";
  183. $_Groups_Last=$_Groups_PrefBranch."last";
  184. $_Groups_Cnt=0;
  185.  
  186. $_Groups_FoldersAvailable=(($kBookmarks==false)*($kHotlist==false))?false:true;
  187.  
  188. _Groups_DlgSet{
  189. $_Groups_DlgMsg=$kLayers==false?_("No folder named '%s' found."):($_Groups_FoldersAvailable==false?_("No group named '%s' found."):_("No group or folder named '%s' found."));
  190. $_Groups_DlgTip=$kLayers==false?_("Enter folder nick:"):($_Groups_FoldersAvailable==false?_("Enter group name:"):_("Enter group name or folder nick:"));
  191. $_Groups_DlgTitOpen=$kLayers==false?_("Open Folder"):($_Groups_FoldersAvailable==false?_("Open Group"):_("Open Group Or Folder"));
  192. $_Groups_DlgTitStart=$kLayers==false?_("Startup Folder"):($_Groups_FoldersAvailable==false?_("Startup Group"):_("Startup Group Or Folder"));
  193. }
  194.  
  195. _Groups_Init{
  196. $kLayers==false?delpref($_Groups_Startup):0;
  197. $kLayers==false?delpref($_Groups_Temp):0;
  198. $kLayers==false?delpref($_Groups_Last):0;
  199. $__crash=getpref(STRING,$_Groups_Last)==getpref(STRING,$_Groups_Temp)?false:true;
  200. # Avoid interference with the session plugin's session recovery
  201. $kSessions==true?$__crash=false:0;
  202. $__crash==true?(confirm(_("K-Meleon wasn't closed properly. Do you want to resume your last browsing session?"),_("Open Group"),YESNO,EXCLAIM)==YES?$__crash=true:$__crash=false):0;
  203. $__crash==true?&_Groups_Init_IsCrash:&_Groups_Init_NoCrash;
  204. }
  205. _Groups_Init_NoCrash{
  206. $kLayers==true?&_Groups_SaveLastSession:0;
  207. getpref(STRING,$_Groups_Startup)==""?$_Groups_OpenCmd="_":$OnLoadOnce="Groups_OpenGroupStartup;";
  208. delpref($_Groups_Crash);
  209. }
  210. _Groups_Init_IsCrash{
  211. getpref(STRING,$_Groups_Crash)==""?setpref(STRING,$_Groups_Crash,getpref(STRING,$_Groups_Temp)):0;
  212. setpref(STRING,$_Groups_Temp,getpref(STRING,$_Groups_Crash));
  213. &_Groups_SaveLastSession; $OnLoadOnce="_Groups_Init_Crash;";
  214. }
  215. _Groups_Init_Crash{
  216. &Groups_OpenLastSession; delpref($_Groups_Crash);
  217. }
  218.  
  219. # Menu Integration
  220. _Groups_BuildMenu{
  221. # file menu
  222. $kLayers==true?setmenu(OpenSave,macro,"Open &Last Session",Groups_OpenLastSession,ID_FILE_SAVE_AS):0;
  223. # view menu
  224. $__m="Ho&me";
  225. setmenu(_Home_Open,macro,$kLayers==true?"Open &Startup Group":$_Groups_FoldersAvailable==false?"":"Open &Startup Folder",Groups_OpenGroupStartup);
  226. $kLayers==true?setmenu(_Home_Open,macro,"Open &Last Session",Groups_OpenLastSession):0;
  227. setmenu(_Home_Start,macro,"Start With Home &Page",Groups_StartWithHomepage,KM_StartWithHomepage);
  228. setmenu(_Home_Start,macro,"",KM_StartWithHomepage);
  229. setmenu(_Home_Start,macro,"Start With &Blank Page",Groups_StartBlank,KM_StartBlank);
  230. setmenu(_Home_Start,macro,"",KM_StartBlank);
  231. setmenu(_Home_Start,macro,$kLayers==true?"Start With &Group...":$_Groups_FoldersAvailable==false?"":"Start With &Folder...",Groups_StartWithGroup);
  232. $kLayers==true?setmenu(_Home_Start,macro,"Start With Last S&ession",Groups_StartWithLastSession):0;
  233. # groups menu
  234. $_g="&Groups";
  235. setmenu(Main,popup,$_g,"&Tools");
  236. $__m="_Groups";
  237. setmenu($_g,inline,$__m);
  238. setmenu($__m,macro,"&Add Page To Group...",Groups_AddPage);
  239. $kLayers==true?setmenu($__m,macro,"Add &Layers To Group...",Groups_AddAllToGroup):0;
  240. setmenu($__m,macro,"&Delete Group...",Groups_Delete);
  241. &_Groups_BuildGroupsMenu;
  242. # context menus
  243. setmenu(DocumentSave,macro,"Add Page To &Group...",Groups_AddPage,ID_FILE_SAVE_AS);
  244. setmenu(LinkSave,macro,"Add Link To &Group...",Groups_AddLink,ID_SAVE_LINK_AS);
  245. }
  246. _Groups_BuildGroupsMenu{
  247. $_m="_Groups_List";
  248. setmenu($_g,inline,$_m);
  249. $kLayers==true?setmenu($_m,macro,"&Last Session",Groups_OpenLastSession):0;
  250. $_data=sub("\n","",getpref(STRING,$_Groups_Pref));
  251. &_Groups_BuildGroupsMenuLoop;
  252. rebuildmenu($_g);
  253. }
  254. _Groups_BuildGroupsMenuLoop{
  255. $__i=$_data==""?0:index($_data,"\n");
  256. $__g=$_data==""?"":substr($_data,0,$__i);
  257. $__g==""?0:$_data=sub($__g."\n","",$_data);
  258. $__g==""?0:setmenu($_m,macro,getpref(STRING,$_Groups_UserPrefBranch.$__g)==""?"":$__g,"Groups_OpenGroup(".$__g.")");
  259. $__g==""?0:&_Groups_BuildGroupsMenuLoop;
  260. }
  261. _Groups_SetAccels{
  262. setaccel("CTRL ALT VK_HOME","macros(Groups_NavHome)");
  263. setaccel("SHIFT VK_RETURN","macros(Groups_OpenGroup)");
  264. $kLayers==true?setaccel("CTRL ALT L","macros(Groups_OpenLastSession)"):0;
  265. }
  266. $OnInit=$OnInit."_Groups_SetAccels;_Groups_BuildMenu;";
  267.  
  268. # Event Handling
  269.  
  270. _Groups_OnCloseGroup{
  271. $_Groups_Cnt=pluginmsgex(layers,NumberOfLayersInWindow,"",INT); &_Groups_SaveLayers;
  272. }
  273. _Groups_OnQuit{
  274. delpref($_Groups_Crash);
  275. }
  276.  
  277. # BUG: OnStartup is also fired for each layer/window opened with the first window (startup folder/group)
  278. $_Groups_IsStartup=true;
  279. _Groups_OnStartup{
  280. $kLayers==true?$OnCloseGroup=$OnCloseGroup."_Groups_OnCloseGroup;":0;
  281. $kLayers==true?$OnCloseWindow=$OnCloseWindow."_Groups_SaveClosed;":0;
  282. $kLayers==true?$OnLoad=$OnLoad."_Groups_SaveLayers;":0;
  283. $OnQuit=$OnQuit."_Groups_OnQuit;";
  284. $kLayers==true?$OnQuit=$OnQuit."_Groups_SaveLastSession;":0;
  285. $kLayers==true?$OnWMAppExit=$OnWMAppExit."_Groups_SaveLayers;":0;
  286. $_Groups_IsStartup==true?&_Groups_Init:0;
  287. $_Groups_IsStartup=false;
  288. }
  289. $OnStartup=$OnStartup."_Groups_OnStartup;";
  290.  
  291. # ------------------------------------------------------------------------------------------------------------------
  292. $macroModules=$macroModules."Groups;";