SECI  1
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
EditTabs.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.Shapes;
13 
14 namespace SeciUserInterface.Dialogs.SubConfigs
15 {
19  public partial class EditTabs : Window
20  {
21  String _beamlogger = "Beam-Logger";
22  Seci.SerialisableList<Seci.Definitions.Tab> _tabs;
24 
25  public EditTabs(Seci.Definitions.Configuration config)
26  {
27  InitializeComponent();
28  _conf = config;
29  }
30 
31  private void Window_Loaded(object sender, RoutedEventArgs e)
32  {
33  setupTree();
34  }
35 
36  private void setupTree()
37  {
38  treeTabs.Items.Clear();
39 
40  _tabs = _conf.Tabs;
41 
42  for (int i = 0; i < _tabs.Count; ++i)
43  {
44  TreeViewItem item = new TreeViewItem();
45  item.Header = _tabs[i].Name;
46  treeTabs.Items.Add(item);
47  }
48 
49  var vis = _conf.LVPanels;
50 
51  for (int i = 0; i < vis.Count; ++i)
52  {
53  foreach (TreeViewItem t in treeTabs.Items)
54  {
55  if (vis[i].Group != null)
56  {
57  if (vis[i].Group.ToLower() == t.Header.ToString().ToLower())
58  {
59  TreeViewItem item = new TreeViewItem();
60  item.Header = vis[i].FilePath;
61  t.Items.Add(item);
62  }
63  }
64  }
65  }
66  }
67 
68  private void swapTree(int index1, bool up)
69  {
70  TreeViewItem item = treeTabs.Items[index1] as TreeViewItem;
71 
72  if (up)
73  {
74  treeTabs.Items.RemoveAt(index1);
75  treeTabs.Items.Insert(index1 - 1, item);
76  item.IsSelected = true;
77  }
78  else
79  {
80  treeTabs.Items.RemoveAt(index1);
81  treeTabs.Items.Insert(index1 + 1, item);
82  item.IsSelected = true;
83  }
84  }
85 
86  private void swapTabs(int index1, int index2)
87  {
88  if (index1 > index2)
89  {
90  int t = index1;
91  index1 = index2;
92  index2 = t;
93  }
94 
95  var temp = _tabs[index2];
96  _tabs.RemoveAt(index2);
97  _tabs.Insert(index1, temp);
98  }
99 
100  private void btnUp_Click(object sender, RoutedEventArgs e)
101  {
102  if (treeTabs.SelectedItem != null)
103  {
104  TreeViewItem item = treeTabs.SelectedItem as TreeViewItem;
105  //Check a tab is selected not a vi
106  for (int i = 0; i < _tabs.Count; ++i)
107  {
108  if (item.Header.ToString().ToLower() == _tabs[i].Name.ToLower())
109  {
110  if (i > 0)
111  {
112  swapTabs(i, i - 1);
113  swapTree(i, true);
114  }
115 
116  break;
117  }
118  }
119  }
120  }
121 
122  private void btnDown_Click(object sender, RoutedEventArgs e)
123  {
124  if (treeTabs.SelectedItem != null)
125  {
126  TreeViewItem item = treeTabs.SelectedItem as TreeViewItem;
127  //Check a tab is selected not a vi
128  for (int i = 0; i < _tabs.Count; ++i)
129  {
130  if (item.Header.ToString().ToLower() == _tabs[i].Name.ToLower())
131  {
132  if (i < _tabs.Count - 1)
133  {
134  swapTabs(i, i + 1);
135  swapTree(i, false);
136  }
137 
138  break;
139  }
140  }
141  }
142  }
143 
144  private void btnAddTab_Click(object sender, RoutedEventArgs e)
145  {
146  Tabs.NameTab add = new Tabs.NameTab();
147 
148  if (add.ShowDialog() == System.Windows.Forms.DialogResult.OK)
149  {
150  _tabs.Add(new Seci.Definitions.Tab(add.TabName, true));
151  setupTree();
152  }
153  }
154 
155  private void btnRemoveTab_Click(object sender, RoutedEventArgs e)
156  {
157  if (treeTabs.SelectedItem != null)
158  {
159  TreeViewItem item = treeTabs.SelectedItem as TreeViewItem;
160 
161  if (item.Header.ToString().ToLower() == _beamlogger.ToLower())
162  {
163  MessageBox.Show("This tab cannot be deleted as it is a default tab", "Cannot Delete - SECI", MessageBoxButton.OK, MessageBoxImage.Error);
164  return;
165  }
166 
167  //Check a tab is selected not a vi
168  for (int i = 0; i < _tabs.Count; ++i)
169  {
170  if (item.Header.ToString().ToLower() == _tabs[i].Name.ToLower())
171  {
172  if (item.Items.Count > 0)
173  {
174  var vis = _conf.LVPanels;
175  for (int j = 0; j < vis.Count; ++j)
176  {
177  if (vis[j].Group != null && vis[j].Group.ToLower() == _tabs[i].Name.ToLower())
178  {
179  vis[j].Group = null;
180  }
181  }
182  }
183 
184  treeTabs.Items.Remove(treeTabs.SelectedItem);
185  _tabs.RemoveAt(i);
186  setupTree();
187 
188  break;
189  }
190  }
191  }
192  }
193 
194  private void btnRenameTab_Click(object sender, RoutedEventArgs e)
195  {
196  if (treeTabs.SelectedItem != null)
197  {
198  TreeViewItem item = treeTabs.SelectedItem as TreeViewItem;
199 
200  if (item.Header.ToString().ToLower() == _beamlogger.ToLower())
201  {
202  MessageBox.Show("This tab cannot be renamed as it is a default tab", "Cannot Delete - SECI", MessageBoxButton.OK, MessageBoxImage.Error);
203  return;
204  }
205 
206  Tabs.NameTab edit = new Tabs.NameTab();
207  String oldName = item.Header.ToString();
208  edit.TabName = oldName;
209 
210  if (edit.ShowDialog() == System.Windows.Forms.DialogResult.OK)
211  {
212  //rename the tab
213  for (int i = 0; i < _tabs.Count; ++i)
214  {
215  if (item.Header.ToString().ToLower() == _tabs[i].Name.ToLower())
216  {
217  _tabs[i].Name = edit.TabName;
218  }
219  }
220 
221  //Sort out any VIs
222  var vis = _conf.LVPanels;
223  for (int j = 0; j < vis.Count; ++j)
224  {
225  if (vis[j].Group != null && vis[j].Group == oldName)
226  {
227  vis[j].Group = edit.TabName;
228  }
229  }
230 
231  setupTree();
232  }
233  }
234  }
235 
236  private void btnAddVi_Click(object sender, RoutedEventArgs e)
237  {
238  if (treeTabs.SelectedItem != null)
239  {
240  TreeViewItem item = treeTabs.SelectedItem as TreeViewItem;
241 
242  if (item.Header.ToString().ToLower() == _beamlogger.ToLower())
243  {
244  MessageBox.Show("This tab cannot be modified as it is a default tab", "Cannot Delete - SECI", MessageBoxButton.OK, MessageBoxImage.Error);
245  return;
246  }
247 
248  var vis = _conf.LVPanels;
249  List<String> available = new List<String>();
250  for (int i = 0; i < vis.Count; ++i)
251  {
252  if (vis[i].Group == null)
253  {
254  available.Add(vis[i].FilePath);
255  }
256  }
257 
258  Tabs.AddVi add = new Tabs.AddVi();
259  add.AvailableVis = available;
260 
261  if (add.ShowDialog() == System.Windows.Forms.DialogResult.OK)
262  {
263  foreach (String viToAdd in add.VisToAdd)
264  {
265  vis = _conf.LVPanels;
266 
267  for (int i = 0; i < vis.Count; ++i)
268  {
269  if (vis[i].FilePath.ToLower() == viToAdd.ToLower())
270  {
271  vis[i].Group = item.Header.ToString();
272  break;
273  }
274  }
275  }
276  setupTree();
277  }
278  }
279  }
280 
281  private void btnRemoveVi_Click(object sender, RoutedEventArgs e)
282  {
283  if (treeTabs.SelectedItem != null)
284  {
285  TreeViewItem item = treeTabs.SelectedItem as TreeViewItem;
286 
287  var vis = _conf.LVPanels;
288  for (int i = 0; i < vis.Count; ++i)
289  {
290  if (item.Header.ToString().ToLower() == vis[i].FilePath.ToLower())
291  {
292  vis[i].Group = null;
293  setupTree();
294  break;
295  }
296  }
297  }
298  }
299 
300  private void btnOk_Click(object sender, RoutedEventArgs e)
301  {
302  DialogResult = true;
303  Close();
304  }
305 
306  }
307 }
Interaction logic for EditTabs.xaml
void swapTabs(int index1, int index2)
Seci.SerialisableList< Seci.Definitions.Tab > _tabs
void btnRemoveVi_Click(object sender, RoutedEventArgs e)
void btnOk_Click(object sender, RoutedEventArgs e)
void btnRenameTab_Click(object sender, RoutedEventArgs e)
void btnRemoveTab_Click(object sender, RoutedEventArgs e)
This class contains all the information that defines the configuration at the SECI level and contains...
void btnAddVi_Click(object sender, RoutedEventArgs e)
void btnUp_Click(object sender, RoutedEventArgs e)
Seci.Definitions.Configuration _conf
void Window_Loaded(object sender, RoutedEventArgs e)
void btnDown_Click(object sender, RoutedEventArgs e)
EditTabs(Seci.Definitions.Configuration config)
void btnAddTab_Click(object sender, RoutedEventArgs e)