SHARE
TWEET

Clipboard Replace

tidbit Nov 22nd, 2015 (edited) 133 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Name: Mango: Clipboard Replace
  3. Version 1.8 (Mon November 18, 2013)
  4. Created: (Thu May 28, 2009)
  5. Author: tidbit (tikki01@gmail.com)
  6. Info: A plugin for my personal script Mango.
  7. */
  8. #singleinstance OFF
  9. amount:=-1
  10. mode:=""
  11. Gui, +AlwaysOnTop +Resize
  12. Gui, Add, Text, x4  y6  w80  h20, &Find what?
  13. Gui, Add, Edit, x+2 yp  w250 r2 wanttab gPreview vfind,
  14. Gui, Add, Text, x4  y+3 w80  h20, Replace &with?
  15. Gui, Add, Edit, x+2 yp  w250 r2 wanttab gPreview vrepwith,
  16.  
  17. Gui, Add, Button, xp+160 y+5 w90 h20 vbtnrep    greplace, &Replace
  18. Gui, Add, Button, xp     y+3 w90 h20 vbtnprev   gPreview Default, &Preview
  19. Gui, Add, Button, xp     y+3 w90 h20 vbtnCancel gcancel, Cancel (Esc)
  20.  
  21. Gui, Add, Checkbox, x6  yp-50 h20 gPreview vcs, &Case Sensitive
  22. Gui, Add, Checkbox, x+5 yp    h20 gPreview vwwo, &Whole Words Only
  23. Gui, Add, Checkbox, x6  y+3   h20 gPreview vra +Checked, Replace &All?
  24. Gui, Add, Checkbox, xp  y+3   h20 gPreview vrem, Rege&x Mode
  25. Gui, Add, Button,   x+5 yp    h20 gregexhelp, ?
  26.  
  27. Gui, Font, s12, Verdana
  28. Gui, Add, Edit, x6 y+5 w330 h310 +HScroll vpreviewbox,
  29.  
  30. Gui, Show,, Clipboard Replace
  31. gosub, Preview
  32. Return
  33.  
  34.  
  35. 11GuiClose:
  36.     Gui, Destroy
  37. Return
  38.  
  39.  
  40. OnClipboardChange:
  41.     gosub, Preview
  42. Return
  43.  
  44.  
  45. replace:
  46.     Gui, Submit, NoHide
  47.     gui, 1: default
  48.     Gosub, setup
  49.    
  50.     ; StringReplace, Clipboard, previewbox, `n, `r`n, All
  51.     GuiControl, , previewbox, %Clipboard%
  52. Return
  53.  
  54.  
  55. Preview:
  56.     Gui, 1: Submit, NoHide
  57.     gui, 1: default
  58.     Gosub, setup
  59.  
  60.     reg:=case find
  61.     ;stringreplace, reg, reg, %a_space%, %a_space%, all
  62.     previewChange:=RegExReplace(Clipboard, reg, repwith)
  63.    
  64.     ; StringReplace, previewChange, previewChange, `n, `r`n, All
  65.     GuiControl, , previewbox, %previewChange%
  66. Return
  67.  
  68.  
  69. Guisize:
  70.     If ErrorLevel = 1  ; The window has been Minimized.  No action needed.
  71.         Return
  72.     GuiControl, Move, btnrep,  % "x" A_GuiWidth-96
  73.     GuiControl, Move, btnprev, % "x" A_GuiWidth-96
  74.     GuiControl, Move, btnCancel, % "x" A_GuiWidth-96
  75.     GuiControl, Move, find, % "w" A_GuiWidth-91
  76.     GuiControl, Move, repwith, % "w" A_GuiWidth-91
  77.     GuiControl, Move, previewbox, % "w" A_GuiWidth-6 " h" A_GuiHeight-127
  78. Return
  79.  
  80.  
  81. setup:
  82. Gui, Submit, NoHide
  83. gui, 1: default
  84.     If (cs=1) ;case sensitive
  85.         case=
  86.     Else
  87.         case=i)
  88.  
  89.     If (rem=0) ;regex mode
  90.         find:=RegExReplace(find,  "[\\.*?+[{|()^$]", "\$0")
  91.  
  92.     ;this >>MUST<< be after Regex Mode.
  93.     If (wwo=1) ;whole words only
  94.         find=\b%find%\b
  95.  
  96.     If (ra=1) ;replace all
  97.         amount=-1
  98.     Else
  99.         amount=1
  100. Return
  101.  
  102.  
  103. regexhelp:
  104.     Gui, 11: Destroy
  105.     Gui, 11: Default
  106.     help=
  107.     (
  108. .   Matches any character.  cat. matches catT and cat2 but not catty
  109. []  Bracket expression. Matches one of any characters enclosed. gr[ae]y matches gray or grey
  110. [^] Negates a bracket expression. Matches one of any characters EXCEPT those enclosed.  1[^02] matches 13 but not 10 or 12
  111. [-] Range. Matches any characters within the range. [1-9] matches any single digit EXCEPT 0
  112. ?   Preceeding item must match one or zero times.   colou?r matches color or colour but not colouur
  113. ()  Parentheses. Creates a substring or item that metacharacters can be applied to  a(bee)?t matches at or abeet but not abet
  114. {n} Bound. Specifies exact number of times for the preceeding item to match.    [0-9]{3} matches any three digits
  115. {n,}    Bound. Specifies minimum number of times for the preceeding item to match.  [0-9]{3,} matches any three or more digits
  116. {n,m}   Bound. Specifies minimum and maximum number of times for the preceeding item to match.  [0-9]{3,5} matches any three, four, or five digits
  117. |   Alternation. One of the alternatives has to match.  July (first|1st|1) will match July 1st but not July 2
  118. [:alnum:]   alphanumeric character  [[:alnum:]]{3} matches any three letters or numbers, like 7Ds
  119. [:alpha:]   alphabetic character, any case  [[:alpha:]]{5} matches five alphabetic characters, any case, like aBcDe
  120. [:blank:]   space and tab   [[:blank:]]{3,5} matches any three, four, or five spaces and tabs
  121. [:digit:]   digits  [[:digit:]]{3,5} matches any three, four, or five digits, like 3, 05, 489
  122. [:lower:]   lowercase alphabetics   [[:lower:]] matches a but not A
  123. [:punct:]   punctuation characters  [[:punct:]] matches ! or . or , but not a or 3
  124. [:space:]   all whitespace characters, including newline and carriage return    [[:space:]] matches any space, tab, newline, or carriage return
  125. [:upper:]   uppercase alphabetics   [[:upper:]] matches A but not a
  126.     Default delimiters for pattern  colou?r matches color or colour
  127. i   Append to pattern to specify a case insensitive match   colou?ri matches COLOR or Colour
  128. \b  A word boundary, the spot between word (\w) and non-word (\W) characters    \bfred\bi matches Fred but not Alfred or Frederick
  129. \B  A non-word boundary fred\Bi matches Frederick but not Fred
  130. \d  A single digit character    a\dbi matches a2b but not acb
  131. \D  A single non-digit character    a\Dbi matches aCb but not a2b
  132. \n  The newline character. (ASCII 10)   \n matches a newline
  133. \r  The carriage return character. (ASCII 13)   \r matches a carriage return
  134. \s  A single whitespace character   a\sb matches a b but not ab
  135. \S  A single non-whitespace character   a\Sb matches a2b but not a b
  136. \t  The tab character. (ASCII 9)    \t matches a tab.
  137. \w  A single word character - alphanumeric and underscore   \w matches 1 or _ but not ?
  138. \W  A single non-word character a\Wbi matches a!b but not a2b
  139.  
  140.     )
  141.  
  142.     Gui, 11: add, text, y6 x6, Regex Help
  143.     Gui, 11:add, ListView, yp+22 xp w450 r25 vlist, Key|Description|Example
  144.  
  145.  
  146.     Loop, Parse, help, `n, `r
  147.     {
  148.         StringSplit, col, A_LoopField, %A_Tab%
  149.         LV_Add( "", col1, col2, col3)
  150.     }
  151.  
  152.     LV_ModifyCol(1, "Auto")
  153.     LV_ModifyCol(2, 200)
  154.     LV_ModifyCol(3, "Auto")
  155.  
  156.     gui, 11: show, x45 , Regex Help
  157. Return
  158.  
  159.  
  160. Esc::
  161. cancel:
  162. GuiClose:
  163.     ExitApp
  164. Return
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top