PageRenderTime 27ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/ScrablerShell/GUi.cs

#
C# | 446 lines | 259 code | 161 blank | 26 comment | 27 complexity | 93b48a894610682a04aa4a0010c342a2 MD5 | raw file
Possible License(s): LGPL-2.1
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using Scrabler;
  10. using System.IO;
  11. using System.Reflection;
  12. using System.Runtime.InteropServices;
  13. using FireAnt.Windows;
  14. using FireAnt.Windows.Forms.Util;
  15. namespace ScrablerShell
  16. {
  17. public partial class GUi : Form
  18. {
  19. private void keypress(object sender, EventArgs e)
  20. {
  21. try
  22. {
  23. HotKey hotKey = sender as HotKey;
  24. if (hotKey != null)
  25. {
  26. // force our window to the foreground
  27. hotKey.ActivateWindow(Handle);
  28. this.shohid();
  29. // MessageBox.Show(hotKey.Key.ToString());
  30. // TODO: WRITE COOL CODE HERE
  31. }
  32. }
  33. catch (Exception ex)
  34. {
  35. //Program.errorreporting(ex);
  36. }
  37. }
  38. public static ScriptRepo repo = new ScriptRepo();
  39. ScrablerCore scarabler = new ScrablerCore();
  40. public static bool autohide = !false;
  41. public static Keys shortcutkey;
  42. string[] defconst = {"keyshortcut","gui","securedirs" };
  43. string[] val = { "ScrablerShell.GUi.shortcutkey", "ScrablerShell.GUi", "ScrablerShell.GUi.securedirs" };
  44. const string settingsfile = "settings.cs";
  45. GlobalHotkeys hotkeys = new GlobalHotkeys();
  46. // ShortcutBox shortbox = new ShortcutBox();
  47. public static string securedirs;
  48. void ConfigureApp()
  49. {
  50. ScrablerCore.definedConstants = defconst;
  51. ScrablerCore.definedValues = val;
  52. //Keys[] ikeys = new Keys[1];
  53. scarabler.ReadScriptInLightMode(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), settingsfile));
  54. // ikeys[0] = shortcutkey;
  55. // this.tabConsoleControl1.IngoreKeys = ikeys;
  56. tabConsoleControl1.SecureDirs = GUi.securedirs;
  57. hotKey1.Key = shortcutkey;
  58. hotKey1.RegisterHotkey(FireAnt.Windows.Forms.Util.Modifiers.None, shortcutkey);
  59. hotKey1.HotKeyPressed += new EventHandler(this.keypress);
  60. }
  61. public GUi()
  62. {
  63. InitializeComponent();
  64. this.ConfigureApp();
  65. this.createScriptsDirectory(Environment.UserName);
  66. this.Autoexecutescripts(Environment.UserName);
  67. this.Text = Application.ProductName + " - " + Application.ProductVersion;
  68. // this.Text += shortcutkey.ToString();
  69. }
  70. public void createScriptsDirectory(string username)
  71. {
  72. try
  73. {
  74. if (username != null)
  75. {
  76. Program.FindScriptsFolder(username);
  77. string path;
  78. // MessageBox.Show(Program.ScriptsFolder);
  79. if (Program.ScriptsFolder != null)
  80. {
  81. if (Directory.Exists(Program.ScriptsFolder) == false)
  82. {
  83. // MessageBox.Show(Program.ScriptsFolder + "\\" + ScrablerCore.ScriptsFolder);
  84. Directory.CreateDirectory(Program.ScriptsFolder);
  85. }
  86. }
  87. }
  88. // webBrowser.ScriptsFolder = Program.ScriptsFolder + "\\" + ScrablerCore.ScriptsFolder;
  89. }
  90. catch (Exception ex)
  91. {
  92. //Program.errorreporting(ex);
  93. }
  94. }
  95. public void Autoexecutescripts(string username)
  96. {
  97. try
  98. {
  99. if (username != null)
  100. {
  101. string[] filelist = Directory.GetFiles(Program.ScriptsFolder);
  102. scarabler.GetExeCutingApplicationVersion(Assembly.LoadFile(Application.ExecutablePath));
  103. if (filelist != null)
  104. {
  105. // ScrablerCore.cp.ReferencedAssemblies.Add(Application.ExecutablePath.Substring(0, Application.ExecutablePath.LastIndexOf("\\")) + "\\AxInterop.MOZILLACONTROLLib.dll");
  106. ScrablerCore.cp.ReferencedAssemblies.Add(Application.ExecutablePath);
  107. // ScrablerCore.cp.ReferencedAssemblies.Add(Application.ExecutablePath);
  108. ScrablerCore.cp.ReferencedAssemblies.Add(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase).Replace(@"file:\", "") + "\\Scrabler.dll");
  109. //ScrablerCore.definedConstants = definedConstants;
  110. // ScrablerCore.definedValues = definedValues;
  111. //Interop.MOZILLACONTROLLib.dll
  112. foreach (string file in filelist)
  113. {
  114. if ((file != null) && (file.EndsWith("scrf") == true))
  115. {
  116. int i;
  117. // ProcessHost prohost = new ProcessHost();
  118. scarabler.ReadScriptAndInstall(file,repo.Binaryfolder);
  119. }
  120. }
  121. //autoastart.scrf
  122. }
  123. }
  124. }
  125. catch (Exception ex)
  126. {
  127. // Program.errorreporting(ex);
  128. }
  129. }
  130. private void GUi_Load(object sender, EventArgs e)
  131. {
  132. notifyIcon1.Icon = this.Icon;
  133. notifyIcon1.Visible = true;
  134. notifyIcon1.Text = Application.ProductName;
  135. }
  136. private void newTabToolStripMenuItem_Click(object sender, EventArgs e)
  137. {
  138. tabConsoleControl1.createNewTabSession();
  139. }
  140. private void GUi_KeyDown(object sender, KeyEventArgs e)
  141. {
  142. try
  143. {
  144. if(GUi.shortcutkey== e.KeyCode)
  145. {
  146. this.shohid();
  147. }
  148. }
  149. catch (Exception)
  150. {
  151. }
  152. }
  153. private void GUi_Resize(object sender, EventArgs e)
  154. {
  155. try
  156. {
  157. // this.shohid();
  158. }
  159. catch (Exception)
  160. {
  161. }
  162. }
  163. private void newWindowToolStripMenuItem_Click(object sender, EventArgs e)
  164. {
  165. try
  166. {
  167. GUi g = new GUi();
  168. g.Show();
  169. }
  170. catch (Exception)
  171. {
  172. }
  173. }
  174. void shohid()
  175. {
  176. try
  177. {
  178. if (autohide == true)
  179. {
  180. if (this.WindowState== FormWindowState.Minimized)
  181. {
  182. this.ShowInTaskbar = true;
  183. // this.MainMenuStrip.Items.Insert(this.FindToolStripMenuItem("βοήθειαToolStripMenuItem",this.MainMenuStrip), this.DefaultAdditionalCommandsMenu);
  184. //this.Activate();
  185. this.WindowState = FormWindowState.Normal;
  186. this.Show();
  187. }
  188. else if ((this.WindowState == FormWindowState.Minimized) && (this.ShowInTaskbar == false)&&(this.Visible!=true ))
  189. {
  190. this.ShowInTaskbar = !true;
  191. // this.MainMenuStrip.Items.Insert(this.FindToolStripMenuItem("βοήθειαToolStripMenuItem",this.MainMenuStrip), this.DefaultAdditionalCommandsMenu);
  192. this.WindowState = FormWindowState.Minimized;
  193. this.Hide();
  194. }
  195. }
  196. }
  197. catch (Exception)
  198. {
  199. }
  200. }
  201. private void notifyIcon1_DoubleClick(object sender, EventArgs e)
  202. {
  203. try
  204. {
  205. this.shohid();
  206. }
  207. catch (Exception)
  208. {
  209. }
  210. }
  211. private void exitToolStripMenuItem_Click(object sender, EventArgs e)
  212. {
  213. Application.Exit();
  214. }
  215. private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
  216. {
  217. try
  218. {
  219. this.shohid();
  220. }
  221. catch (Exception)
  222. {
  223. }
  224. }
  225. private void showHideToolStripMenuItem_Click(object sender, EventArgs e)
  226. {
  227. try
  228. {
  229. this.shohid();
  230. }
  231. catch (Exception)
  232. {
  233. }
  234. }
  235. private void exitToolStripMenuItem1_Click(object sender, EventArgs e)
  236. {
  237. Application.Exit();
  238. }
  239. private void notifyIcon1_Click(object sender, EventArgs e)
  240. {
  241. try
  242. {
  243. //this.shohid();
  244. }
  245. catch (Exception)
  246. {
  247. }
  248. }
  249. private void installScriptsToolStripMenuItem_Click(object sender, EventArgs e)
  250. {
  251. try
  252. {
  253. ScrablerInstaller inst = new ScrablerInstaller();
  254. if (openFileDialog1.ShowDialog() == DialogResult.OK)
  255. {
  256. inst.Install(openFileDialog1.FileName, Program.ScriptsFolder);
  257. this.Autoexecutescripts(Environment.UserName);
  258. }
  259. }
  260. catch (Exception)
  261. {
  262. }
  263. }
  264. private void GUi_FormClosed(object sender, FormClosedEventArgs e)
  265. {
  266. try
  267. {
  268. shohid();
  269. }
  270. catch (Exception)
  271. {
  272. }
  273. }
  274. private void clearTempToolStripMenuItem_Click(object sender, EventArgs e)
  275. {
  276. try
  277. {
  278. GUi.repo.ClearTempfolder();
  279. }
  280. catch (Exception)
  281. {
  282. }
  283. }
  284. }
  285. }