Clipboard.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. //using System;
  2. //using System.Text;
  3. //using System.Text.RegularExpressions;
  4. //using System.Timers;
  5. //using System.Windows.Forms;
  6. //using MinorShift.Emuera.GameView;
  7. //using Timer = System.Timers.Timer;
  8. //namespace MinorShift.Emuera.GameProc.Function
  9. //{
  10. // internal class ClipboardProcessor
  11. // {
  12. // private readonly bool useCB;
  13. // private readonly bool classicMode; // New Lines Only mode
  14. // private readonly MainWindow mainWin;
  15. // private bool minTimePassed; //Has enough time passed since the last Clipboard update?
  16. // private bool postWaiting; //Is there text waiting to be sent to clipboard?
  17. // private static Timer minTimer; //Minimum timer for refrehsing the clipboard to prevent spam
  18. // private readonly int MaxCB; //Max length in lines of the output to clipboard
  19. // private int ScrollPos; //Position of the clipboard output in the buffer
  20. // private readonly int ScrollCount; //Lines to scroll at a time
  21. // private int NewLineCount; //Number of new lines
  22. // private int OldNewLineCount; //Number of lines in the last update, used for Classic mode + scrolling back to bottom
  23. // private StringBuilder OldText; //Last set of lines sent to the clipboard
  24. // private readonly CircularBuffer<string> lineBuffer; //Buffer for processed strings ready for clipboard
  25. // public string GetLatestString => OldText.ToString();
  26. // internal enum CBTriggers
  27. // {
  28. // LeftClick,
  29. // MiddleClick,
  30. // DoubleLeftClick,
  31. // AnyKeyWait,
  32. // InputWait
  33. // }
  34. // private delegate void SetClipboardDelegate(string text, bool copy, int times, int delay); //Just for using the timer to set the clipboard.
  35. // public ClipboardProcessor(MainWindow parent)
  36. // {
  37. // useCB = Config.CBUseClipboard;
  38. // classicMode = Config.CBNewLinesOnly;
  39. // mainWin = parent;
  40. // minTimePassed = true;
  41. // postWaiting = false;
  42. // MaxCB = Config.CBMaxCB;
  43. // ScrollPos = 0; //FIXIT - Expand it, add a button, etc
  44. // ScrollCount = Config.CBScrollCount; //FIXIT - Actually use it
  45. // NewLineCount = 0;
  46. // OldNewLineCount = 0;
  47. // if (!useCB) return;
  48. // lineBuffer = new CircularBuffer<string>(Config.CBBufferSize);
  49. // minTimer = new Timer(Config.CBMinTimer) {AutoReset = false};
  50. // minTimer.Elapsed += MinTimerDone;
  51. // OldText = new StringBuilder();
  52. // }
  53. // public bool ScrollUp(int value)
  54. // {
  55. // if (!useCB) return false;
  56. // if (ScrollPos == 0 && classicMode && ScrollCount > OldNewLineCount) ScrollPos = OldNewLineCount;
  57. // else ScrollPos += ScrollCount * value;
  58. // if (lineBuffer.Count < ScrollPos) ScrollPos = lineBuffer.Count - ScrollCount;
  59. // SendToCB(true);
  60. // return true;
  61. // }
  62. // public bool ScrollDown(int value)
  63. // {
  64. // if (!useCB) return false;
  65. // ScrollPos -= ScrollCount;
  66. // if (ScrollPos < 0) ScrollPos = 0;
  67. // SendToCB(true);
  68. // return true;
  69. // }
  70. // private void MinTimerDone(object source, ElapsedEventArgs e)
  71. // {
  72. // minTimePassed = true;
  73. // if (postWaiting) SendToCB(true);
  74. // }
  75. // private bool MinTimeCheck()
  76. // {
  77. // if (minTimePassed)
  78. // {
  79. // minTimePassed = false;
  80. // minTimer.Start();
  81. // return true;
  82. // }
  83. // return false;
  84. // }
  85. // //FIXIT - Autoprocess old lines or just ditch?
  86. // public void AddLine(ConsoleDisplayLine inputLine, bool left)
  87. // {
  88. // if (!useCB) return;
  89. // NewLineCount++;
  90. // string processed = ProcessLine(inputLine.ToString());
  91. // lineBuffer.Enqueue(processed);
  92. // }
  93. // public void DelLine(int count)
  94. // {
  95. // if (!useCB || count <= 0) return;
  96. // NewLineCount = Math.Max(0, NewLineCount - count);
  97. // if (count >= lineBuffer.Count) lineBuffer.Clear();
  98. // else
  99. // {
  100. // while (count > 0)
  101. // {
  102. // lineBuffer.Dequeue();
  103. // count--;
  104. // }
  105. // }
  106. // }
  107. // public void ClearScreen()
  108. // {
  109. // if (!useCB) return;
  110. // if (Config.CBClearBuffer)
  111. // {
  112. // lineBuffer.Clear();
  113. // ScrollPos = 0;
  114. // NewLineCount = 0;
  115. // }
  116. // else
  117. // {
  118. // lineBuffer.Enqueue("");
  119. // }
  120. // }
  121. // public void Check(CBTriggers type)
  122. // {
  123. // if (!useCB) return;
  124. // switch (type)
  125. // {
  126. // case CBTriggers.LeftClick:
  127. // if (!Config.CBTriggerLeftClick) return;
  128. // break;
  129. // case CBTriggers.MiddleClick:
  130. // if (!Config.CBTriggerMiddleClick) return;
  131. // break;
  132. // case CBTriggers.DoubleLeftClick:
  133. // if (!Config.CBTriggerDoubleLeftClick) return;
  134. // break;
  135. // case CBTriggers.AnyKeyWait:
  136. // if (!Config.CBTriggerAnyKeyWait) return;
  137. // break;
  138. // case CBTriggers.InputWait:
  139. // if (!Config.CBTriggerInputWait) return;
  140. // break;
  141. // default:
  142. // return;
  143. // }
  144. // ScrollPos = 0;
  145. // SendToCB(false);
  146. // }
  147. // private void SendToCB(bool force)
  148. // {
  149. // if (!useCB) return;
  150. // if (NewLineCount == 0 && !force) return;
  151. // if (!MinTimeCheck())
  152. // {
  153. // postWaiting = true;
  154. // return;
  155. // }
  156. // if (NewLineCount == 0 && ScrollPos == 0) NewLineCount = OldNewLineCount;
  157. // int length;
  158. // if (classicMode && ScrollPos == 0) length = Math.Min(NewLineCount, lineBuffer.Count);
  159. // else length = Math.Min(MaxCB, lineBuffer.Count - ScrollPos);
  160. // if (length <= 0) return;
  161. // var newText = new StringBuilder();
  162. // for (int count = 0; count < length; count++)
  163. // {
  164. // newText.AppendLine(lineBuffer[lineBuffer.Count - length - ScrollPos + count]);
  165. // }
  166. // if (newText.ToString().Equals(OldText.ToString())) return;
  167. // var scpDelegate = new SetClipboardDelegate(Clipboard.SetDataObject);
  168. // try
  169. // {
  170. // mainWin.Invoke(scpDelegate, newText.ToString(), false, 3, 200);
  171. // if (ScrollPos == 0) OldNewLineCount = NewLineCount;
  172. // NewLineCount = 0;
  173. // OldText = newText;
  174. // postWaiting = false;
  175. // }
  176. // catch (Exception)
  177. // {
  178. // //FIXIT - For now it just fails silently
  179. // }
  180. // }
  181. // private const string HTML_TAG_PATTERN = "<.*?>";
  182. // public static string StripHTML(string input)
  183. // {
  184. // // still faster to use String.Contains to check if we need to do this at all first, supposedly
  185. // if (Config.CBIgnoreTags && input.Contains("<"))
  186. // {
  187. // // regex is faster and simpler than a for loop you nerds
  188. // return Regex.Replace(input, HTML_TAG_PATTERN, Config.CBReplaceTags);
  189. // }
  190. // return input;
  191. // }
  192. // private static string ProcessLine(string input)
  193. // {
  194. // return StripHTML(input);
  195. // }
  196. // }
  197. //}