Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ScriptEditorControl.xaml.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Windows;
6 using System.Windows.Controls;
7 using System.Windows.Data;
8 using System.Windows.Documents;
9 using System.Windows.Input;
10 using System.Windows.Media;
11 using System.Windows.Media.Imaging;
12 using System.Windows.Navigation;
13 using System.Windows.Shapes;
14 using System.IO;
15 
16 namespace SiliconStudio.Paradox.DebugTools
17 {
18  /// <summary>
19  /// Interaction logic for ScriptEditorControl.xaml
20  /// </summary>
21  public partial class ScriptEditorControl : UserControl
22  {
24  {
25  InitializeComponent();
26 
27  ReplTextBox.KeyDown += new KeyEventHandler(ReplTextBox_KeyDown);
28  ReplTextBox.PreviewKeyDown += new KeyEventHandler(ReplTextBox_PreviewKeyDown);
29  }
30 
31  private EngineContext engineContext;
32 
33  public void Initialize(EngineContext engineContext)
34  {
35  this.engineContext = engineContext;
36  }
37 
38  List<string> replHistory = new List<string>();
39  private int historyIndex = -1;
40 
41  void HistoryAdd(string command)
42  {
43  if (historyIndex != -1)
44  replHistory[replHistory.Count - 1] = command;
45  else
46  replHistory.Add(command);
47  if (replHistory.Last() == string.Empty)
48  replHistory.RemoveAt(replHistory.Count - 1);
49  historyIndex = -1;
50  }
51 
52  void ReplTextBox_PreviewKeyDown(object sender, KeyEventArgs e)
53  {
54  // Handle history (up/down)
55  if (e.Key == Key.Up || e.Key == Key.Down)
56  {
57  if (historyIndex == -1)
58  {
59  historyIndex = replHistory.Count;
60  replHistory.Add(ReplTextBox.Text);
61  }
62  else
63  {
64  replHistory[historyIndex] = ReplTextBox.Text;
65  }
66 
67 
68  if (e.Key == Key.Up && historyIndex > 0)
69  {
70  historyIndex--;
71  ReplTextBox.Text = replHistory[historyIndex];
72  ReplTextBox.SelectionStart = ReplTextBox.Text.Length;
73  }
74  if (e.Key == Key.Down && historyIndex < replHistory.Count - 1)
75  {
76  historyIndex++;
77  ReplTextBox.Text = replHistory[historyIndex];
78  ReplTextBox.SelectionStart = ReplTextBox.Text.Length;
79  }
80  }
81  }
82 
83  void ReplTextBox_KeyDown(object sender, KeyEventArgs e)
84  {
85  if (e.Key == Key.Enter)
86  {
87  HistoryAdd(ReplTextBox.Text);
88 
89  try
90  {
91  // Can't be done without JIT, so we should probably drop this feature
92  throw new NotSupportedException();
93  }
94  catch (Exception ex)
95  {
96  ReplResults.AppendText(string.Format("Exception {0}: {1}", ex.GetType().FullName, ex.Message));
97  }
98  finally
99  {
100  ReplTextBox.Text = string.Empty;
101  ReplResults.ScrollToEnd();
102  }
103  }
104  }
105  }
106 }
Interaction logic for ScriptEditorControl.xaml