public override string ToString() { var cr = new CodeRenderText(); RenderCode(cr, null); return(cr.s); }
internal MainWin() { sel = new Selection(this); TestCase(); Title = "Restructor"; FontFamily = new FontFamily("Consolas"); dp = new DockPanel(); var tbs = new ToolBarTray(); tbs.Background = new SolidColorBrush(Color.FromRgb(0xA4, 0xB3, 0xC8)); dp.Children.Add(tbs); DockPanel.SetDock(tbs, Dock.Top); var tb = GUI.ToolBar(tbs); var res = GUI.TextBox(null, "Ready."); GUI.Button(this, tb, "New", ApplicationCommands.New, false, () => { prog.New(); TreeChanged(); }); GUI.Button(this, tb, "Open", ApplicationCommands.Open, false, () => MessageBox.Show("Not Implimented: Open")); GUI.Button(this, tb, "Save", ApplicationCommands.Save, false, () => { var cr = new CodeRenderText(); prog.RenderCode(cr); var sw = new StreamWriter("text.restruct"); sw.Write(cr.program); sw.Close(); res.Text = "Saved Restructor Code."; }); GUI.Button(this, tb, "Save As", ApplicationCommands.SaveAs, false, () => MessageBox.Show("Not Implimented: SaveAs")); tb.Items.Add(GUI.TBSep()); GUI.Button(this, tb, "Copy", ApplicationCommands.Copy, true, () => Clipboard.SetText(sel.selected.ToString())); GUI.Button(this, tb, "Paste", ApplicationCommands.Paste, true, () => { if (sel.selected is Node) { Replace(sel.selected as Node, Clipboard.GetText()); } }); GUI.Button(this, tb, "Undo", ApplicationCommands.Undo, false, () => MessageBox.Show("Not Implimented: Undo")); tb.Items.Add(GUI.TBSep()); GUI.Button(this, tb, "Restruct", new RsCommand(() => { res.Text = prog.Restructor(); TreeChanged(); })); GUI.Button(this, tb, "Run", new RsCommand( () => { res.Text = prog.GenCode(true, false); GC.Collect(); })); GUI.Button(this, tb, "Save Exe", new RsCommand( () => { res.Text = prog.GenCode(false, false); GC.Collect(); })); GUI.Button(this, tb, "DBG", new RsCommand( () => { res.Text = prog.GenCode(true, true); GC.Collect(); })); GUI.Button(this, tb, "DBGS", new RsCommand( () => { res.Text = prog.GenCode(false, true); GC.Collect(); })); var tb2 = GUI.ToolBar(tbs); FocusManager.SetIsFocusScope(tb2, false); var tbsp = GUI.StackPanel(true); GUI.TextBox(tbsp, "<input>", s => Runtime.__commandlineargs = s.Split(' ')); tbsp.Children.Add(res); tb2.Items.Add(tbsp); foreach (DependencyObject a in tb.Items) { ToolBar.SetOverflowMode(a, OverflowMode.Never); } foreach (DependencyObject a in tb2.Items) { ToolBar.SetOverflowMode(a, OverflowMode.Never); } TreeChanged(); Content = dp; MouseWheel += (s, e) => { scale *= 1.0 + e.Delta / 600.0; if (scale > 2) { scale = 2; } if (scale < 1) { scale = 1; } SetScale(); }; MouseLeftButtonDown += (s, e) => { if (e.ClickCount > 1) { sel.SetEditMode(); } else { sel.Selected(); } }; PreviewMouseLeftButtonDown += (s, e) => { sel.ReSelectEditBox(); dragstartpoint = Mouse.GetPosition(this); }; MouseMove += (s, e) => { sel.HoverMove(e.GetPosition(this)); if (e.LeftButton == MouseButtonState.Pressed && dragnode == null) { Vector diff = dragstartpoint - Mouse.GetPosition(this); if ((Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance || Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance) && sel.selected != null) { var seln = sel.selected as Node; if (seln != null && !(seln.t is Unparsed)) { dragnode = seln; DataObject data = new DataObject(DataFormats.UnicodeText, sel.selected.ToString()); DragDrop.DoDragDrop(sel.selectedui, data, DragDropEffects.Copy); dragnode = null; } } } }; DragOver += (s, e) => { sel.HoverMove(e.GetPosition(this)); if (sel.hover == dragnode) { e.Effects = DragDropEffects.None; } }; Drop += (s, e) => { if (e.Data.GetDataPresent(DataFormats.UnicodeText)) { if (sel.hover != null && sel.hover is Node) { Replace(sel.hover as Node, e.Data.GetData(DataFormats.UnicodeText) as string); } } }; KeyDown += (s, e) => { switch (e.Key) { default: sel.HandleKey(e.Key); break; } }; TextInput += (s, e) => sel.SetEditMode(e.Text); }