Advertisement
roryok

Surround.ashk

Jun 14th, 2013
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.58 KB | None | 0 0
  1. S_Hotkey = ^+c
  2. f_sep = ~
  3.  
  4. ; CONFIG: CHOOSE YOUR FAVORITES
  5.  
  6. /*
  7. GENERIC <-- Do not change this string.
  8. <a> ~ <a href="@@">@@</a>
  9.  
  10. $("# ")~$("#@@")
  11. $("#<`%= .ClientID `%>").val()~$("#<`%= @@.ClientID `%>").val()
  12. $(". ")~$(".@@")
  13. $(document)ready~$(document).ready(function(){`n @@`n });
  14.  
  15. <div> ~ <div>`n@@`n</div>
  16. <ul> ~ <ul>`n@@`n</ul>
  17. <li> ~ <li>@@</li>
  18. <p>~<p>`n@@`n</p>
  19. <img />~<img src="<`%= ResolveUrl("~/images/@@")`%>" alt="@@" />
  20. <span>~<span>@@</span>
  21. <span green>~<span style="color:green;">@@</span>
  22. <blockquote>~<blockquote>@@</blockquote>
  23. <table>[and all that]</table>~<table>`n<tr>`n<td>`n@@`n</td>`n</tr>`n</table>
  24.  
  25. <h1>~<h1>@@</h1>
  26. <h2>~<h2>@@</h2>
  27. <h3>~<h3>@@</h3>
  28. <h4>~<h4>@@</h4>
  29. <h5>~<h5>@@</h5>
  30.  
  31. <b>~<b>@@</b>
  32. <i>~<i>@@</i>
  33. <strong>~<strong>@@</strong>
  34. <em>~<em>@@</em>
  35.  
  36. " " ~ "@@"
  37. ' ' ~ '@@'
  38. <>~ <@@>
  39. ()~ (@@)
  40. {}~{@@}
  41. []~ [@@]
  42.  
  43. <script>~<script type="text/javascript" src="@@"></script>
  44. <link>~<link type="text/css" href="@@" rel="StyleSheet" />
  45.  
  46. /**/~ /*`n@@`n*/
  47. <!-- -->~<!--@@-->
  48. */
  49.  
  50.  
  51. /*
  52. CSHARP <-- Do not change this string.
  53. resolveURL~ResolveUrl("~/@@")
  54. " " ~ "@@"
  55. ' ' ~ '@@'
  56. <>~ <@@>
  57. ()~ (@@)
  58. {}~{@@}
  59. []~ [@@]
  60.  
  61. Convert.ToInt32()~Convert.ToInt32(@@)
  62. try catch~ try{`n@@`n}catch(Exception Err){`n`n}
  63.  
  64. foreach(...){}~foreach(@@){`n`n}
  65. foreach(){...}~foreach(){`n@@`n}
  66.  
  67. if() ... else()~if()`n@@`nelse`n
  68. if(){...}else(){}~if(){`n@@`n}else{`n`n}
  69.  
  70. #region~ #region regionName`n@@`n#endregion
  71. */
  72.  
  73.  
  74. /*
  75. ASPX <-- Do not change this string.
  76. <a> ~ <a href="@@">@@</a>
  77.  
  78. $("# ")~$("#@@")
  79. $("#<`%= .ClientID `%>").val()~$("#<`%= @@.ClientID `%>").val()
  80. $(". ")~$(".@@")
  81. $(document)ready~$(document).ready(function(){`n @@`n });
  82. resolveURL~<`%= ResolveUrl("~/@@")`%>
  83.  
  84. <div> ~ <div>`n@@`n</div>
  85. <ul> ~ <ul>`n@@`n</ul>
  86. <li> ~ <li>@@</li>
  87. <p>~<p>`n@@`n</p>
  88. <img />~<img src="<`%= ResolveUrl("~/images/@@")`%>" alt="@@" />
  89. <span>~<span>@@</span>
  90. <span green>~<span style="color:green;">@@</span>
  91. <blockquote>~<blockquote>@@</blockquote>
  92. <table>[and all that]</table>~<table>`n<tr>`n<td>`n@@`n</td>`n</tr>`n</table>
  93.  
  94. <h1>~<h1>@@</h1>
  95. <h2>~<h2>@@</h2>
  96. <h3>~<h3>@@</h3>
  97. <h4>~<h4>@@</h4>
  98. <h5>~<h5>@@</h5>
  99.  
  100. <b>~<b>@@</b>
  101. <i>~<i>@@</i>
  102. <strong>~<strong>@@</strong>
  103. <em>~<em>@@</em>
  104.  
  105. <script>~<script type="text/javascript" src="@@"></script>
  106. <link>~<link type="text/css" href="@@" rel="StyleSheet" />
  107.  
  108. " " ~ "@@"
  109. ' ' ~ '@@'
  110. <>~ <@@>
  111. ()~ (@@)
  112. {}~{@@}
  113. []~ [@@]
  114. <`%= `%>~<`%=@@`%>
  115. <`%= .ClientID `%>~<`%= @@.ClientID `%>
  116.  
  117. /**/~ /*`n@@`n*/
  118. <!-- -->~<!--@@-->
  119. <`%/* */`%>~<`%/*`n@@`n */`%>
  120. */
  121.  
  122. /*
  123. SQLSERVER <-- Do not change this string.
  124. CAST( as NVARCHAR(MAX))~CAST((@@) AS NVARCHAR(MAX))
  125. ISNULL((),'')~ISNULL((@@),'')
  126. ISNULL((),0)~ISNULL((@@),0)
  127. */
  128.  
  129.  
  130. ; END OF CONFIGURATION SECTION
  131. ; Do not make changes below this point unless you want to change
  132. ; the basic functionality of the script.
  133.  
  134. #SingleInstance ; Needed since the hotkey is dynamically created.
  135. Hotkey, %S_Hotkey%, S_DisplayMenu
  136. StringLeft, S_HotkeyFirstChar, S_Hotkey, 1
  137. S_AlwaysShowMenu = y
  138.  
  139. ; Used to reliably determine whether script is compiled:
  140. SplitPath, A_ScriptName,,, S_FileExt
  141. if S_FileExt = Exe ; Read the menu items from an external file.
  142. S_FavoritesFile = %A_ScriptDir%\Paster.ini
  143. else ; Read the menu items directly from this script file.
  144. S_FavoritesFile = %A_ScriptFullPath%
  145.  
  146. ;----Read the configuration file.
  147. S_AtStartingPos = n
  148. S_MenuItemCount = 0
  149. Loop, Read, %S_FavoritesFile%
  150. {
  151. if S_FileExt <> Exe
  152. {
  153. if S_AtStartingPos = n
  154. {
  155. IfInString, A_LoopReadLine, GENERIC
  156. S_AtStartingPos = y
  157. continue
  158. }
  159. if A_LoopReadLine = */
  160. break
  161. }
  162. S_MenuItemCount++
  163. if A_LoopReadLine = ; Blank indicates a separator line.
  164. Menu, GENERIC, Add
  165. else
  166. {
  167. StringSplit, GS_line, A_LoopReadLine, %f_sep%
  168. GS_line1 = %GS_line1%
  169. GS_line2 = %GS_line2%
  170. Transform, GS_path%S_MenuItemCount%, deref, %GS_line2%
  171. Transform, GS_line1, deref, %GS_line1%
  172. Menu, GENERIC, Add, %GS_line1%, S_OpenGENERIC
  173. }
  174. }
  175. S_AtStartingPos = n
  176. S_MenuItemCount = 0
  177. Loop, Read, %S_FavoritesFile%
  178. {
  179. if S_FileExt <> Exe
  180. {
  181. if S_AtStartingPos = n
  182. {
  183. IfInString, A_LoopReadLine, CSHARP
  184. S_AtStartingPos = y
  185. continue
  186. }
  187. if A_LoopReadLine = */
  188. break
  189. }
  190. S_MenuItemCount++
  191. if A_LoopReadLine = ; Blank indicates a separator line.
  192. Menu, CSHARP, Add
  193. else
  194. {
  195. StringSplit, CS_line, A_LoopReadLine, `•
  196. CS_line1 = %CS_line1%
  197. CS_line2 = %CS_line2%
  198. Transform, CS_path%S_MenuItemCount%, deref, %CS_line2%
  199. Transform, CS_line1, deref, %CS_line1%
  200. Menu, CSHARP, Add, %CS_line1%, S_OpenCSHARP
  201. }
  202. }
  203. S_AtStartingPos = n
  204. S_MenuItemCount = 0
  205. Loop, Read, %S_FavoritesFile%
  206. {
  207. if S_FileExt <> Exe
  208. {
  209. if S_AtStartingPos = n
  210. {
  211. IfInString, A_LoopReadLine, ASPX
  212. S_AtStartingPos = y
  213. continue
  214. }
  215. if A_LoopReadLine = */
  216. break
  217. }
  218. S_MenuItemCount++
  219. if A_LoopReadLine = ; Blank indicates a separator line.
  220. Menu, ASPX, Add
  221. else
  222. {
  223. StringSplit, AS_line, A_LoopReadLine, `•
  224. AS_line1 = %AS_line1%
  225. AS_line2 = %AS_line2%
  226. Transform, AS_path%S_MenuItemCount%, deref, %AS_line2%
  227. Transform, AS_line1, deref, %AS_line1%
  228. Menu, ASPX, Add, %AS_line1%, S_OpenASPX
  229. }
  230. }
  231. S_AtStartingPos = n
  232. S_MenuItemCount = 0
  233. Loop, Read, %S_FavoritesFile%
  234. {
  235. if S_FileExt <> Exe
  236. {
  237. if S_AtStartingPos = n
  238. {
  239. IfInString, A_LoopReadLine, SQLSERVER
  240. S_AtStartingPos = y
  241. continue
  242. }
  243. if A_LoopReadLine = */
  244. break
  245. }
  246. S_MenuItemCount++
  247. if A_LoopReadLine = ; Blank indicates a separator line.
  248. Menu, SQLSERVER, Add
  249. else
  250. {
  251. StringSplit, SS_line, A_LoopReadLine, `•
  252. SS_line1 = %SS_line1% ; Trim leading and trailing spaces.
  253. SS_line2 = %SS_line2% ; Trim leading and trailing spaces.
  254. Transform, SS_path%S_MenuItemCount%, deref, %SS_line2%
  255. Transform, SS_line1, deref, %SS_line1%
  256. Menu, SQLSERVER, Add, %SS_line1%, S_OpenSQLSERVER
  257. }
  258. }
  259. return ;----End of auto-execute section.
  260.  
  261.  
  262. ;----Open the selected favorite
  263.  
  264. S_OpenGENERIC:
  265. StringTrimLeft, GS_path, GS_path%A_ThisMenuItemPos%, 0
  266. if GS_path =
  267. return
  268. WinActivate, ahk_id %S_window_id% ; Because sometimes the mclick deactivates it.
  269. SetKeyDelay, 1 ; This will be in effect only for the duration of this thread.
  270. ClipSaved := ClipboardAll
  271. Send, ^c
  272. ClipWait, 2
  273. tempstring = %GS_path%
  274. StringReplace, tempstring, tempstring, @@, %clipboard%, All
  275. ClipBoard := tempstring
  276. Send, ^v
  277. ClipBoard := ClipSaved
  278. return
  279.  
  280. S_OpenCSHARP:
  281. StringTrimLeft, CS_path, CS_path%A_ThisMenuItemPos%, 0
  282. if CS_path =
  283. return
  284. WinActivate, ahk_id %S_window_id% ; Because sometimes the mclick deactivates it.
  285. SetKeyDelay, 1 ; This will be in effect only for the duration of this thread.
  286. ClipSaved := ClipboardAll
  287. Send, ^c
  288. ClipWait, 2
  289. tempstring = %CS_path%
  290. StringReplace, tempstring, tempstring, @@, %clipboard%, All
  291. ClipBoard := tempstring
  292. Send, ^v
  293. ClipBoard := ClipSaved
  294. return
  295.  
  296. S_OpenASPX:
  297. StringTrimLeft, AS_path, AS_path%A_ThisMenuItemPos%, 0
  298. if AS_path =
  299. return
  300. WinActivate, ahk_id %S_window_id% ; Because sometimes the mclick deactivates it.
  301. SetKeyDelay, 1 ; This will be in effect only for the duration of this thread.
  302. ClipSaved := ClipboardAll
  303. Send, ^c
  304. ClipWait, 2
  305. tempstring = %AS_path%
  306. StringReplace, tempstring, tempstring, @@, %clipboard%, All
  307. ClipBoard := tempstring
  308. Send, ^v
  309. ClipBoard := ClipSaved
  310. return
  311.  
  312. S_OpenSQLSERVER:
  313. StringTrimLeft, SS_path, SS_path%A_ThisMenuItemPos%, 0
  314. if SS_path =
  315. return
  316. WinActivate, ahk_id %S_window_id% ; Because sometimes the mclick deactivates it.
  317. SetKeyDelay, 1 ; This will be in effect only for the duration of this thread.
  318. ClipSaved := ClipboardAll
  319. Send, ^c
  320. ClipWait, 2
  321. tempstring = %SS_path%
  322. StringReplace, tempstring, tempstring, @@, %clipboard%, All
  323. ClipBoard := tempstring
  324. Send, ^v
  325. ClipBoard := ClipSaved
  326. return
  327.  
  328.  
  329.  
  330. ; Since the above didn't return, one of the following is true:
  331. ; 1) It's an unsupported window type but S_AlwaysShowMenu is y (yes).
  332. ; 2) It's a supported type but it lacks an Edit1 control to facilitate the custom
  333. ; action, so instead do the default action below.
  334. Run, Explorer %S_path% ; Might work on more systems without double quotes.
  335. return
  336.  
  337. ;----Display the menu
  338. S_DisplayMenu:
  339. ; These first few variables are set here and used by S_OpenFavorite:
  340. WinGet, S_window_id, ID, A
  341. WinGetClass, S_class, ahk_id %S_window_id%
  342. if S_class in #32770,ExploreWClass,CabinetWClass ; Dialog or Explorer.
  343. ControlGetPos, S_Edit1Pos,,,, Edit1, ahk_id %S_window_id%
  344. if S_AlwaysShowMenu = n ; The menu should be shown only selectively.
  345. {
  346. if S_class in #32770,ExploreWClass,CabinetWClass ; Dialog or Explorer.
  347. {
  348. if S_Edit1Pos = ; The control doesn't exist, so don't display the menu
  349. return
  350. }
  351. else if S_class <> ConsoleWindowClass
  352. return ; Since it's some other window type, don't display menu.
  353. }
  354. ; Otherwise, the menu should be presented for this type of window:
  355. SetTitleMatchMode 2
  356. IfWinActive, .cs - Microsoft Visual Studio
  357. {
  358. Menu, CSHARP, show
  359. }
  360. else{
  361. IfWinActive, .aspx - Microsoft Visual Studio
  362. {
  363. Menu, ASPX, show
  364. }
  365. else{
  366. IfWinActive, .master - Microsoft Visual Studio
  367. {
  368. Menu, ASPX, show
  369. }
  370. else{
  371. IfWinActive, SQL Server Management Studio
  372. {
  373. Menu, SQLSERVER, show
  374. }
  375. else{
  376. IfWinActive, Remote Desktop
  377. {
  378. Menu, SQLSERVER, show
  379. }
  380. else{
  381. Menu, GENERIC, show
  382. }
  383. }
  384. }
  385. }
  386. }
  387. return
  388.  
  389.  
  390. #SingleInstance force
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement