SECI  1
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
EditTabs.cs
Go to the documentation of this file.
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 
10 namespace SeciUserInterface.Dialogs.Tabs
11 {
12  public partial class EditTabs : Form
13  {
15  private List<String> _secretTabs;
16  private List<String> _nonEditTabs;
17  private Seci.SerialisableList<Seci.Definitions.Tab> _tabs;
18  private bool _changesMade = false;
19 
20  public EditTabs(ref SeciControls.ViTabControl tab, List<String> nonEditTabs, List<String> secretTabs, Seci.SerialisableList<Seci.Definitions.Tab> tabs)
21  {
22  InitializeComponent();
23  _tabControl = tab;
24  _secretTabs = secretTabs;
25  _nonEditTabs = nonEditTabs;
26  _tabs = tabs;
27  }
28 
29  private void EditTabs_Load(object sender, EventArgs e)
30  {
31  UpdateTabList();
32  }
33 
34  private void UpdateTabList()
35  {
36  lstTabs.Items.Clear();
37 
38  //Get tabs
39  List<String> names = _tabControl.GetTabNames(true);
40 
41  //Remove secret tabs
42  foreach (String tab in _secretTabs)
43  {
44  names.Remove(tab);
45  }
46 
47  //Remove hidden tabs
48  foreach (Seci.Definitions.Tab tab in _tabs)
49  {
50  if (!tab.VisibleForUser)
51  {
52  if (names.Contains(tab.Name))
53  {
54  names.Remove(tab.Name);
55  }
56  }
57  }
58 
59  lstTabs.Items.AddRange(names.ToArray());
60  }
61 
62  private void btnAdd_Click(object sender, EventArgs e)
63  {
64  NameTab add = new NameTab();
65 
66  if (add.ShowDialog() == DialogResult.OK)
67  {
68  _tabControl.AddTab(add.TabName);
69  _tabs.Add(new Seci.Definitions.Tab(add.TabName, true));
70 
71  _tabControl.StartTimers(Seci.Definitions.Status.ViHostRefreshRate);
72  UpdateTabList();
73  _changesMade = true;
74  }
75  }
76 
77  private void btnDelete_Click(object sender, EventArgs e)
78  {
79  if (lstTabs.SelectedIndex != -1)
80  {
81  if (_nonEditTabs.Contains(lstTabs.SelectedItem.ToString()))
82  {
83  MessageBox.Show("This tab cannot be deleted.");
84  return;
85  }
86 
87  if (lstVIs.Items.Count > 0)
88  {
89  if (!canTabBeEdited(lstTabs.SelectedItem.ToString()))
90  {
91  return;
92  }
93 
94  for (int i = lstVIs.Items.Count - 1; i >= 0; --i)
95  {
96  removeVi(lstTabs.SelectedItem.ToString(), lstVIs.Items[i].ToString());
97  }
98  }
99 
100  _tabControl.RemoveTab(lstTabs.SelectedItem.ToString());
101  for(int i =0; i < _tabs.Count; ++i)
102  {
103  if (_tabs[i].Name == lstTabs.SelectedItem.ToString())
104  {
105  _tabs.RemoveAt(i);
106  break;
107  }
108  }
109 
110  UpdateTabList();
111  UpdateViList();
112  _changesMade = true;
113  }
114  }
115 
116  private Boolean canTabBeEdited(String tab)
117  {
118  Seci.SerialisableList<Seci.LabView.LabViewPanelInfo> panels = Seci.Managers.LabViewMgr.GetAllPanelsInfo();
119 
120  List<String> vis = _tabControl.GetTabVis(tab);
121 
122  foreach (Seci.LabView.LabViewPanelInfo panel in panels)
123  {
124  if (vis.Contains(panel.FilePath) && !String.IsNullOrEmpty(panel.OwningComponent))
125  {
126  MessageBox.Show("This tab cannot be modified.", "Tab cannot be modified!", MessageBoxButtons.OK, MessageBoxIcon.Error);
127  return false;
128  }
129  }
130  return true;
131  }
132 
133  private void btnRename_Click(object sender, EventArgs e)
134  {
135  if (lstTabs.SelectedIndex != -1)
136  {
137  if (_nonEditTabs.Contains(lstTabs.SelectedItem.ToString()))
138  {
139  MessageBox.Show("This tab cannot be renamed.");
140  return;
141  }
142 
143  if (!canTabBeEdited(lstTabs.SelectedItem.ToString()))
144  {
145  return;
146  }
147 
148  NameTab edit = new NameTab();
149  String oldName = lstTabs.SelectedItem.ToString();
150  edit.TabName = oldName;
151 
152  if (edit.ShowDialog() == DialogResult.OK)
153  {
154  try
155  {
156  _tabControl.RenameTab(oldName, edit.TabName);
157  for (int i = 0; i < _tabs.Count; ++i)
158  {
159  if (_tabs[i].Name == oldName)
160  {
161  _tabs[i].Name = edit.TabName;
162  break;
163  }
164  }
165  }
166  catch
167  {
168  MessageBox.Show("Name already in use; please, try another", "Duplicate Name", MessageBoxButtons.OK, MessageBoxIcon.Error);
169  }
170  UpdateTabList();
171 
172  Seci.SerialisableList<Seci.LabView.LabViewPanelInfo> panels = Seci.Managers.LabViewMgr.GetAllPanelsInfo();
173 
174  for (int i = 0; i < panels.Count; ++i)
175  {
176  if (panels[i].Group != null && panels[i].Group == oldName)
177  {
178  panels[i].Group = edit.TabName;
179  }
180  }
181  _changesMade = true;
182  }
183  }
184  }
185 
186  private void btnExit_Click(object sender, EventArgs e)
187  {
188  if (_changesMade)
189  {
190  DialogResult = DialogResult.OK;
191  Seci.Managers.ConfigurationMgr.SetTabs(_tabs);
192  }
193  else
194  {
195  DialogResult = DialogResult.Cancel;
196  }
197 
198  this.Close();
199  }
200 
201  private void lstTabs_SelectedIndexChanged(object sender, EventArgs e)
202  {
203  UpdateViList();
204  }
205 
206  private void UpdateViList()
207  {
208  lstVIs.Items.Clear();
209 
210  if (lstTabs.SelectedIndex != -1)
211  {
212  List<String> names = _tabControl.GetTabVis(lstTabs.SelectedItem.ToString());
213 
214  if (names != null)
215  {
216  lstVIs.Items.AddRange(names.ToArray());
217  }
218  }
219  }
220 
221  private void btnAddVi_Click(object sender, EventArgs e)
222  {
223  if (lstTabs.SelectedIndex != -1)
224  {
225  if (_nonEditTabs.Contains(lstTabs.SelectedItem.ToString()))
226  {
227  MessageBox.Show("This tab cannot be altered.");
228  return;
229  }
230  else if (!canTabBeEdited(lstTabs.SelectedItem.ToString()))
231  {
232  return;
233  }
234 
235  //Generate list of VIs available
236  Seci.SerialisableList<Seci.LabView.LabViewPanelInfo> vis = Seci.Managers.LabViewMgr.GetAllPanelsInfo();
237  List<String> available = new List<String>();
238  List<String> visInTabs = _tabControl.GetAllVisInTabs();
239 
240  for (int i=0; i< vis.Count; ++i)
241  {
242  if (!vis[i].ShowPanel || visInTabs.Contains(vis[i].FilePath) || !String.IsNullOrEmpty(vis[i].OwningComponent))
243  {
244  //Do nothing
245  }
246  else
247  {
248  available.Add(vis[i].FilePath);
249  }
250  }
251 
252  AddVi add = new AddVi();
253  add.AvailableVis = available;
254 
255  if (add.ShowDialog() == DialogResult.OK)
256  {
257  foreach (String viToAdd in add.VisToAdd)
258  {
259  _tabControl.AddVi(lstTabs.SelectedItem.ToString(), viToAdd);
260 
261  Seci.SerialisableList<Seci.LabView.LabViewPanelInfo> panels = Seci.Managers.LabViewMgr.GetAllPanelsInfo();
262 
263  for (int i = 0; i < panels.Count; ++i)
264  {
265  if (panels[i].FilePath.ToLower() == viToAdd.ToLower())
266  {
267  panels[i].Group = lstTabs.SelectedItem.ToString();
268  break;
269  }
270  }
271  }
272 
273  _changesMade = true;
274  }
275  }
276  UpdateViList();
277  }
278 
279  private void btnRemoveVi_Click(object sender, EventArgs e)
280  {
281  if (lstTabs.SelectedIndex != -1 && lstVIs.SelectedIndex != -1)
282  {
283  if (_nonEditTabs.Contains(lstTabs.SelectedItem.ToString()))
284  {
285  MessageBox.Show("This tab cannot be altered.");
286  return;
287  }
288  else if (!canTabBeEdited(lstTabs.SelectedItem.ToString()))
289  {
290  return;
291  }
292 
293  removeVi(lstTabs.SelectedItem.ToString(), lstVIs.SelectedItem.ToString());
294 
295  _changesMade = true;
296  }
297  UpdateViList();
298  }
299 
300  private void removeVi(String tabname, String viname)
301  {
302  _tabControl.RemoveVi(tabname,viname);
303 
304  Seci.SerialisableList<Seci.LabView.LabViewPanelInfo> panels = Seci.Managers.LabViewMgr.GetAllPanelsInfo();
305 
306  for (int i = 0; i < panels.Count; ++i)
307  {
308  if (panels[i].FilePath.ToLower() == viname.ToLower())
309  {
310  panels[i].Group = "";
311  break;
312  }
313  }
314  }
315 
316  private void btnUp_Click(object sender, EventArgs e)
317  {
318  if (lstTabs.SelectedIndex > 0)
319  {
320  int oldIndex = lstTabs.SelectedIndex;
321  _tabControl.SwapTabs(lstTabs.SelectedItem.ToString(), lstTabs.Items[lstTabs.SelectedIndex - 1].ToString());
322 
323  //Swap over the config tabs
324  Seci.Managers.ConfigurationMgr.SwapTabs(lstTabs.SelectedItem.ToString(), lstTabs.Items[lstTabs.SelectedIndex - 1].ToString());
325 
326  UpdateTabList();
327  lstTabs.SelectedIndex = --oldIndex;
328  _changesMade = true;
329  }
330  }
331 
332  private void btnDown_Click(object sender, EventArgs e)
333  {
334  if (lstTabs.SelectedIndex < lstTabs.Items.Count -1)
335  {
336  int oldIndex = lstTabs.SelectedIndex;
337  _tabControl.SwapTabs(lstTabs.SelectedItem.ToString(), lstTabs.Items[lstTabs.SelectedIndex + 1].ToString());
338 
339  //Swap over the config tabs
340  Seci.Managers.ConfigurationMgr.SwapTabs(lstTabs.SelectedItem.ToString(), lstTabs.Items[lstTabs.SelectedIndex + 1].ToString());
341 
342  UpdateTabList();
343  lstTabs.SelectedIndex = ++oldIndex;
344  _changesMade = true;
345  }
346  }
347  }
348 }
void btnRename_Click(object sender, EventArgs e)
Definition: EditTabs.cs:133
void btnAdd_Click(object sender, EventArgs e)
Definition: EditTabs.cs:62
void removeVi(String tabname, String viname)
Definition: EditTabs.cs:300
void btnDelete_Click(object sender, EventArgs e)
Definition: EditTabs.cs:77
void EditTabs_Load(object sender, EventArgs e)
Definition: EditTabs.cs:29
EditTabs(ref SeciControls.ViTabControl tab, List< String > nonEditTabs, List< String > secretTabs, Seci.SerialisableList< Seci.Definitions.Tab > tabs)
Definition: EditTabs.cs:20
void btnAddVi_Click(object sender, EventArgs e)
Definition: EditTabs.cs:221
void btnRemoveVi_Click(object sender, EventArgs e)
Definition: EditTabs.cs:279
SeciControls.ViTabControl _tabControl
Definition: EditTabs.cs:14
void lstTabs_SelectedIndexChanged(object sender, EventArgs e)
Definition: EditTabs.cs:201
Seci.SerialisableList< Seci.Definitions.Tab > _tabs
Definition: EditTabs.cs:17
This class contains all the information about a LabVIEW VI that needs to be saved in the configuratio...
void btnExit_Click(object sender, EventArgs e)
Definition: EditTabs.cs:186
Interaction logic for ViTabControl.xaml
void btnDown_Click(object sender, EventArgs e)
Definition: EditTabs.cs:332
Boolean canTabBeEdited(String tab)
Definition: EditTabs.cs:116
void btnUp_Click(object sender, EventArgs e)
Definition: EditTabs.cs:316