| 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 System.IO;
|
|---|
| 10 | using System.Threading;
|
|---|
| 11 | using System.Text.RegularExpressions;
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 | namespace SoyText
|
|---|
| 15 | {
|
|---|
| 16 | public delegate void SyncUIAction();
|
|---|
| 17 | public partial class Form1 : Form
|
|---|
| 18 | {
|
|---|
| 19 | Workspace workspace;
|
|---|
| 20 | Document curDoc;
|
|---|
| 21 | static int inst = 0;
|
|---|
| 22 | public static Form1 defaultInstance;
|
|---|
| 23 | String _statusText = "";
|
|---|
| 24 | Queue<SyncUIAction> uiActionQueue = new Queue<SyncUIAction>();
|
|---|
| 25 | public String statusText
|
|---|
| 26 | {
|
|---|
| 27 | set
|
|---|
| 28 | {
|
|---|
| 29 | _statusText = value;
|
|---|
| 30 | }
|
|---|
| 31 | }
|
|---|
| 32 | public Form1(Workspace w)
|
|---|
| 33 | {
|
|---|
| 34 | workspace = w;
|
|---|
| 35 | InitializeComponent();
|
|---|
| 36 | //curDoc = documentSet.createDocument();
|
|---|
| 37 | inst++;
|
|---|
| 38 | defaultInstance = this;
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | private void content_TextChanged(object sender, EventArgs e)
|
|---|
| 42 | {
|
|---|
| 43 | if (curDoc == null) return;
|
|---|
| 44 | var wasNew = curDoc.isNew;
|
|---|
| 45 | curDoc.content = content.Text;
|
|---|
| 46 | curDoc.save();
|
|---|
| 47 | if (wasNew && !docListBox.Items.Contains(curDoc))
|
|---|
| 48 | {
|
|---|
| 49 | docListBox.Items.Insert(0, curDoc);
|
|---|
| 50 | }
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | private void Form1_Load(object sender, EventArgs e)
|
|---|
| 54 | {
|
|---|
| 55 | documentSet.getRecents();
|
|---|
| 56 | newDocument();
|
|---|
| 57 | refreshList();
|
|---|
| 58 | }
|
|---|
| 59 | IEnumerator<int> listings;
|
|---|
| 60 | public DocumentSet documentSet
|
|---|
| 61 | {
|
|---|
| 62 | get { return workspace.documentSet; }
|
|---|
| 63 | }
|
|---|
| 64 | public void refreshList()
|
|---|
| 65 | {
|
|---|
| 66 | refreshList(null);
|
|---|
| 67 | }
|
|---|
| 68 | TerminableThread searchThread = new TerminableThread();
|
|---|
| 69 | DocumentSercher documentSearcher;
|
|---|
| 70 | public void refreshList(String kw)
|
|---|
| 71 | {
|
|---|
| 72 | if (kw == "" || kw==null) Text = "soyText";
|
|---|
| 73 | else Text = kw + " - " + "soyText";
|
|---|
| 74 | if (documentSearcher != null) documentSearcher.terminate();
|
|---|
| 75 | searchThread.exec(delegate(TerminableThread t)
|
|---|
| 76 | {
|
|---|
| 77 | var cnt = 0;
|
|---|
| 78 | syncUI(delegate()
|
|---|
| 79 | {
|
|---|
| 80 | docListBox.Items.Clear();
|
|---|
| 81 | });
|
|---|
| 82 | documentSearcher = documentSet.createDocumentSearcher(kw,
|
|---|
| 83 | delegate(Document d)
|
|---|
| 84 | {
|
|---|
| 85 | cnt++;
|
|---|
| 86 | if (cnt < 100)
|
|---|
| 87 | {
|
|---|
| 88 | syncUI(delegate() { docListBox.Items.Add(d); });
|
|---|
| 89 | return FoundHandlerAction.Accept;
|
|---|
| 90 | }
|
|---|
| 91 | else
|
|---|
| 92 | {
|
|---|
| 93 | statusText = "CNT: " + cnt;
|
|---|
| 94 | return FoundHandlerAction.End;
|
|---|
| 95 | }
|
|---|
| 96 | });
|
|---|
| 97 | documentSearcher.search();
|
|---|
| 98 | statusText = "完了";
|
|---|
| 99 | });
|
|---|
| 100 | }
|
|---|
| 101 | public void syncUI(SyncUIAction u)
|
|---|
| 102 | {
|
|---|
| 103 | uiActionQueue.Enqueue(u);
|
|---|
| 104 | }
|
|---|
| 105 | private void newDocument()
|
|---|
| 106 | {
|
|---|
| 107 | var d = documentSet.createDocument();
|
|---|
| 108 | if (command.Text != "")
|
|---|
| 109 | {
|
|---|
| 110 | var lines = Regex.Split(d.content, "\r*\n");
|
|---|
| 111 | d.content = lines[0] + "\r\ntag: " + command.Text + "\r\n" + "\r\n";
|
|---|
| 112 | }
|
|---|
| 113 | open(d);
|
|---|
| 114 |
|
|---|
| 115 | content.Focus();
|
|---|
| 116 | content.SelectionStart = content.TextLength;
|
|---|
| 117 |
|
|---|
| 118 | }
|
|---|
| 119 | private void newButton_Click(object sender, EventArgs e)
|
|---|
| 120 | {
|
|---|
| 121 | newDocument();
|
|---|
| 122 |
|
|---|
| 123 | //content.GetFirstCharIndexFromLine
|
|---|
| 124 | }
|
|---|
| 125 | bool autoSresMove = true;
|
|---|
| 126 | private void open(Document newDoc)
|
|---|
| 127 | {
|
|---|
| 128 | curDoc = null;
|
|---|
| 129 | content.Text = newDoc.content;
|
|---|
| 130 | curDoc = newDoc;
|
|---|
| 131 | //command.Text = newDoc.lastUpdate+"";
|
|---|
| 132 | if (command.Text != "")
|
|---|
| 133 | {
|
|---|
| 134 | if (autoSresMove && splitContainerSres.SplitterDistance < 64)
|
|---|
| 135 | {
|
|---|
| 136 | splitContainerSres.SplitterDistance = 64;
|
|---|
| 137 | }
|
|---|
| 138 | var sc = SearchCondition.fromExpression(command.Text);
|
|---|
| 139 | sresListBox.Items.Clear();
|
|---|
| 140 | foreach (var l in curDoc.lines)
|
|---|
| 141 | {
|
|---|
| 142 | if (sc.matches(l))
|
|---|
| 143 | {
|
|---|
| 144 | sresListBox.Items.Add(l);
|
|---|
| 145 | }
|
|---|
| 146 | }
|
|---|
| 147 | }
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | private void command_KeyDown(object sender, KeyEventArgs e)
|
|---|
| 151 | {
|
|---|
| 152 | if (e.KeyCode.Equals(Keys.Enter))
|
|---|
| 153 | {
|
|---|
| 154 | autoSresMove = true;
|
|---|
| 155 | refreshList(command.Text);
|
|---|
| 156 |
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | int testTimer = 0;
|
|---|
| 162 | private void timer1_Tick(object sender, EventArgs e)
|
|---|
| 163 | {
|
|---|
| 164 |
|
|---|
| 165 | status.Text = _statusText;
|
|---|
| 166 | testTimer++;
|
|---|
| 167 | if (listings != null)
|
|---|
| 168 | {
|
|---|
| 169 | if (listings.MoveNext())
|
|---|
| 170 | {
|
|---|
| 171 |
|
|---|
| 172 | }
|
|---|
| 173 | else
|
|---|
| 174 | {
|
|---|
| 175 | listings = null;
|
|---|
| 176 | }
|
|---|
| 177 | }
|
|---|
| 178 | long t = System.Environment.TickCount;
|
|---|
| 179 | while (uiActionQueue.Count > 0 && System.Environment.TickCount - t < 17)
|
|---|
| 180 | {
|
|---|
| 181 | var r=uiActionQueue.Dequeue();
|
|---|
| 182 | r.Invoke();
|
|---|
| 183 | }
|
|---|
| 184 | }
|
|---|
| 185 | bool seling = false;
|
|---|
| 186 | private void docListBox_SelectedIndexChanged(object sender, EventArgs e)
|
|---|
| 187 | {
|
|---|
| 188 | if (seling) return;
|
|---|
| 189 | if (docListBox.SelectedIndex < 0) return;
|
|---|
| 190 | Document d = (Document)docListBox.Items[docListBox.SelectedIndex];
|
|---|
| 191 | seling = true;
|
|---|
| 192 | docListBox.Items[docListBox.SelectedIndex] = d;
|
|---|
| 193 | seling = false;
|
|---|
| 194 | open(d);
|
|---|
| 195 | // open(new Document(Int32.Parse(docListBox.Text + "")));
|
|---|
| 196 |
|
|---|
| 197 | }
|
|---|
| 198 |
|
|---|
| 199 | private void Form1_FormClosed(object sender, FormClosedEventArgs e)
|
|---|
| 200 | {
|
|---|
| 201 | inst--;
|
|---|
| 202 | if (inst == 0) Application.Exit();
|
|---|
| 203 | }
|
|---|
| 204 | TerminableThread tth = new TerminableThread();
|
|---|
| 205 | private void Form1_KeyDown(object sender, KeyEventArgs e)
|
|---|
| 206 | {
|
|---|
| 207 | if (e.KeyCode.Equals(Keys.F11))
|
|---|
| 208 | {
|
|---|
| 209 | new Thread(delegate()
|
|---|
| 210 | {
|
|---|
| 211 | var oldActive = documentSet.getOldestActiveDocument();
|
|---|
| 212 | workspace.indexer.make(oldActive);
|
|---|
| 213 | }).Start();
|
|---|
| 214 | }
|
|---|
| 215 | if (e.KeyCode.Equals(Keys.F9))
|
|---|
| 216 | {
|
|---|
| 217 | searchThread.exec(delegate(TerminableThread t) {
|
|---|
| 218 | statusText = "NEXT!!";
|
|---|
| 219 | Thread.Sleep(1000);
|
|---|
| 220 | });
|
|---|
| 221 | /*
|
|---|
| 222 | tth.exec(delegate(TerminableThread t)
|
|---|
| 223 | {
|
|---|
| 224 | for (var i = 0; i < 20; i++)
|
|---|
| 225 | {
|
|---|
| 226 | Debug.print("TTH " + i);
|
|---|
| 227 | Thread.Sleep(500);
|
|---|
| 228 | if (t.terminated) break;
|
|---|
| 229 | }
|
|---|
| 230 | });
|
|---|
| 231 | Text = curDoc.parsed.getValue("title");*/
|
|---|
| 232 | }
|
|---|
| 233 | }
|
|---|
| 234 |
|
|---|
| 235 | private void NewMenuItem_Click(object sender, EventArgs e)
|
|---|
| 236 | {
|
|---|
| 237 | newDocument();
|
|---|
| 238 | }
|
|---|
| 239 |
|
|---|
| 240 | private void ワークスペースWToolStripMenuItem_Click(object sender, EventArgs e)
|
|---|
| 241 | {
|
|---|
| 242 | var w = new WorkspaceSelector();
|
|---|
| 243 | w.Visible = true;
|
|---|
| 244 | }
|
|---|
| 245 |
|
|---|
| 246 | private void アーカイブAToolStripMenuItem_Click(object sender, EventArgs e)
|
|---|
| 247 | {
|
|---|
| 248 | curDoc.state = DocumentState.archived;
|
|---|
| 249 | docListBox.Items.Remove(curDoc);
|
|---|
| 250 |
|
|---|
| 251 | }
|
|---|
| 252 |
|
|---|
| 253 | private void 新規NToolStripMenuItem_Click(object sender, EventArgs e)
|
|---|
| 254 | {
|
|---|
| 255 | var f = new Form1(workspace);
|
|---|
| 256 | f.Visible = true;
|
|---|
| 257 | }
|
|---|
| 258 |
|
|---|
| 259 | private void インポートToolStripMenuItem_Click(object sender, EventArgs e)
|
|---|
| 260 | {
|
|---|
| 261 | var i = new ImportDialog(workspace);
|
|---|
| 262 | i.Visible = true;
|
|---|
| 263 | }
|
|---|
| 264 |
|
|---|
| 265 | private void command_TextChanged(object sender, EventArgs e)
|
|---|
| 266 | {
|
|---|
| 267 |
|
|---|
| 268 | }
|
|---|
| 269 |
|
|---|
| 270 | private void 最新の情報に更新RToolStripMenuItem_Click(object sender, EventArgs e)
|
|---|
| 271 | {
|
|---|
| 272 | refreshList(command.Text);
|
|---|
| 273 | }
|
|---|
| 274 |
|
|---|
| 275 | private void splitContainerSres_SplitterMoved(object sender, SplitterEventArgs e)
|
|---|
| 276 | {
|
|---|
| 277 | autoSresMove = false;
|
|---|
| 278 | }
|
|---|
| 279 |
|
|---|
| 280 | private void topPanel_MouseClick(object sender, MouseEventArgs e)
|
|---|
| 281 | {
|
|---|
| 282 | status.Text = "[" + (testTimer & 255) + "] " + _statusText;
|
|---|
| 283 | testTimer++;
|
|---|
| 284 | if (listings != null)
|
|---|
| 285 | {
|
|---|
| 286 | if (listings.MoveNext())
|
|---|
| 287 | {
|
|---|
| 288 |
|
|---|
| 289 | }
|
|---|
| 290 | else
|
|---|
| 291 | {
|
|---|
| 292 | listings = null;
|
|---|
| 293 | }
|
|---|
| 294 | }
|
|---|
| 295 | long t = System.Environment.TickCount;
|
|---|
| 296 | while (uiActionQueue.Count > 0 && System.Environment.TickCount - t < 17)
|
|---|
| 297 | {
|
|---|
| 298 | var r = uiActionQueue.Dequeue();
|
|---|
| 299 | r.Invoke();
|
|---|
| 300 | }
|
|---|
| 301 | }
|
|---|
| 302 |
|
|---|
| 303 | private void sresListBox_SelectedIndexChanged(object sender, EventArgs e)
|
|---|
| 304 | {
|
|---|
| 305 | if (sresListBox.SelectedIndex >= sresListBox.Items.Count ||
|
|---|
| 306 | sresListBox.SelectedIndex < 0) return;
|
|---|
| 307 | var line = ((DocumentLine)sresListBox.Items[sresListBox.SelectedIndex]);
|
|---|
| 308 | content.SelectionStart = line.document.GetFirstCharIndexFromLine(line.lineNo);
|
|---|
| 309 | content.ScrollToCaret();
|
|---|
| 310 | content.Focus();
|
|---|
| 311 | }
|
|---|
| 312 | }
|
|---|
| 313 | }
|
|---|