private void itmOpen_Click(object sender, System.EventArgs e) { string path; openFile.Multiselect = false; System.Windows.Forms.DialogResult enmResult = openFile.ShowDialog(); if (enmResult == System.Windows.Forms.DialogResult.OK) { path = openFile.FileName; System.IO.StreamReader reader = new System.IO.StreamReader(path); TextForm documentForm = new TextForm(); documentForm.MdiParent = this; documentForm.textData = reader.ReadToEnd(); documentForm.Text = openFile.SafeFileName; //documentForm.saveStatus = true; documentForm.pathFile = path; documentForm.Show(); setSomethingToEnable(); } capsLockStatus(); }
private void itmNew_Click(object sender, System.EventArgs e) { TextForm documentForm = new TextForm(); documentForm.MdiParent = this; documentForm.Text = "Untitled" + (this.MdiChildren.Length - 1).ToString(); documentForm.Show(); capsLockStatus(); changeStatusComboboxesToEnable(); setSomethingToEnable(); }
public virtual void Update() // called on Unity thread { if (form != null && formLoaded) { if (!Console && form.Visible) { form.Hide(); } if (Console && !form.Visible) { form.Show(); } } if (sensing) { Sensing(); sensing = false; sensingHandle.Set(); } if (task != null) { if (Tracing) { Debug.Log("EXECUTING " + task); } execute(task); if (task is Utterance && task.isSystem()) { Say(translate(task)); } task = null; taskHandle.Set(); } if (newMenu) { UpdateMenu(menu); menu = null; newMenu = false; menuHandle.Set(); } }
void InitializeButtons(List <Tuple <string, Action> > bs) { bs.Add(new Tuple <string, Action>("Send Socket", () => { int port = int.Parse(Microsoft.VisualBasic.Interaction.InputBox("socket port?", "", "7122")); Socket client_sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); client_sock.Connect(new IPEndPoint(IPAddress.Parse("127.0.0.1"), port)); Trace.WriteLine($"Connected: {client_sock.Connected}"); List <byte> send_data = new List <byte>(); using (var stream = Open()) { if (stream == null) { return; } byte[] buf = new byte[4096]; for (int n = 0; (n = stream.Read(buf, 0, buf.Length)) != 0;) { for (int i = 0; i < n; i++) { send_data.Add(buf[i]); } } } client_sock.Send(send_data.ToArray()); var f = new TextForm($"Receive from socket: port = {port}"); f.Show(); var thread = new Thread(() => { using (var stream = new NetworkStream(client_sock)) { List <byte> data = new List <byte>(); const byte target = (byte)'\0'; while (true) { var _b = stream.ReadByte(); if (_b == -1) { Trace.WriteLine("Connection closed."); } var b = (byte)_b; if (b == target) { Trace.WriteLine($"receive_length={data.Count}"); var s = Encoding.UTF8.GetString(data.ToArray()); f.Invoke(new Action(() => f.AppendText(s + "\r\n"))); data.Clear(); } else { data.Add(b); } } } }); thread.Start(); new Thread(() => { Thread.Sleep(1000 * 60); thread.Abort(); }); })); bs.Add(new Tuple <string, Action>("Convert Encoding", async() => { Encoding encodingSource, encodingTarget; var encodingList = GetProperties(typeof(Encoding)).Select(v => v as Encoding).ToList(); if ((encodingSource = await Select(encodingList, $"Source Encoding ({encodingList.Count})")) == null || (encodingTarget = await Select(encodingList, $"Target Encoding ({encodingList.Count})")) == null) { return; } OpenSave(async(fs, ss) => { try { Trace.Indent(); Trace.WriteLine($"Converting: {encodingSource} → {encodingTarget}"); using (var reader = new StreamReader(fs, encodingSource)) { using (var writer = new StreamWriter(ss, encodingTarget)) { const int bufLen = 1 << 20; var buf = new char[bufLen]; long progress = 0, total_progress = reader.BaseStream.Length; DateTime time = DateTime.Now; for (int n; (n = await reader.ReadAsync(buf, 0, buf.Length)) > 0;) { await writer.WriteAsync(buf, 0, n); progress += n; if ((DateTime.Now - time).TotalSeconds > 0.5) { Trace.WriteLine($"Converting: {(double)progress * 100 / total_progress}% {encodingSource} → {encodingTarget}"); time = DateTime.Now; } } } } Trace.WriteLine($"Convert OK: {encodingSource} → {encodingTarget}"); } finally { Trace.Unindent(); } }); })); bs.Add(new Tuple <string, Action>("Convert Trie to WordList (file to file)", () => { OpenSave(async(fs, ss) => { try { Trace.Indent(); Trace.WriteLine($"Reading... file size: {fs.Length}"); var trie = new Trie(); await Task.Run(() => trie.Load(fs)); Trace.WriteLine("Exporting..."); await trie.ExportList(ss); Trace.WriteLine($"Done"); } finally { Trace.Unindent(); } }); })); }