private void btnSet_Click(object sender, EventArgs e) { try { string errMsg = GenericQbItem.ValidateText(typeof(string), typeof(string), txtItem.Text); if (errMsg.Length != 0) { err.SetError(txtItem, errMsg); } else { try { lstItems.BeginUpdate(); int idx = getSelectedItem(); _preventUpdate = true; lstItems.Items[idx] = ""; //force item to update, if only case has changed it won't update lstItems.Items[idx] = txtItem.Text; } finally { _preventUpdate = false; lstItems.EndUpdate(); } } } catch (Exception ex) { base.ShowException("Script Set Item Error", ex); } }
private void mnu_Click(object sender, EventArgs e) { Type t; if (sender == mnuFloat) { t = typeof(float); } else if (sender == mnuInt) { t = typeof(int); } else if (sender == mnuUint) { t = typeof(uint); } else if (sender == mnuHex) { t = typeof(byte[]); } else if (sender == mnuString) { t = typeof(string); } else { return; } txtValue.Text = _gItem.ConvertTo(t); btnConvert.Text = GenericQbItem.GetTypeName(t); }
private void mnuInsertItem_Click(object sender, EventArgs e) { int idx = lstItems.SelectedIndex; try { if (idx >= 0 && idx < lstItems.Items.Count) { GenericQbItem qbi = QbFile.CreateGenericArrayItem(base.QbItem); qbi.ConvertTo(_currentEditType); _gItems.Insert(idx, qbi); lstItems.Items.Insert(idx, qbi.Value); enableItems(); lstItems.SelectedIndex = idx; txtItem.SelectAll(); txtItem.Focus(); } } catch (Exception ex) { base.ShowException("Simple Array Insert Item Error", ex); } }
private void mnu_Click(object sender, EventArgs e) { try { Type t; if (sender == mnuFloat) { t = typeof(float); } else if (sender == mnuInt) { t = typeof(int); } else if (sender == mnuUint) { t = typeof(uint); } else if (sender == mnuHex) { t = typeof(byte[]); } else if (sender == mnuString) { t = typeof(string); } else { return; } try { int idx = getSelectedItem(); lstItems.BeginUpdate(); int i = 0; foreach (GenericQbItem gi in _gItems) { lstItems.Items[i++] = gi.ConvertTo(t); } lstItems.SelectedIndex = idx; txtItem.Text = _gItems[idx].Value; _currentEditType = t; } finally { lstItems.EndUpdate(); } btnConvert.Text = GenericQbItem.GetTypeName(t); } catch (Exception ex) { base.ShowException("Simple Array Menu Item Error", ex); } }
private void btnImport_Click(object sender, EventArgs e) { try { string fname = string.Empty; // string.Format("{0}_{1}.array.txt", base.QbItem.Root.Filename.Replace('\\', '#').Replace('/', '#').Replace('.', '#'), base.QbItem.ItemQbKey.Crc.ToString("X").PadLeft(8, '0')); if (AppState.LastArrayPath.Length == 0) { fname = Path.Combine(AppState.LastArrayPath, fname); } fname = getBestFullFilename(fname); import.Filter = string.Format("{0} (*.{0})|*.{0}|All files (*.*)|*.*", _fileExt); import.Title = string.Format("Import {0} file", _fileExt); import.CheckFileExists = true; import.CheckPathExists = true; import.FileName = fname; if (import.ShowDialog(this) != DialogResult.Cancel) { fname = import.FileName; using (FileStream fs = new FileStream(fname, FileMode.Open, FileAccess.Read)) { using (TextReader tr = new StreamReader(fs)) { lstItems.Items.Clear(); _gItems.Clear(); string s; while ((s = tr.ReadLine()) != null) { GenericQbItem qbi = QbFile.CreateGenericArrayItem(base.QbItem); qbi.ConvertTo(_currentEditType); _gItems.Add(qbi); qbi.Value = s; lstItems.Items.Add(qbi.Value); } } } if (lstItems.Items.Count > 1) { lstItems.SelectedIndex = 0; } btnUpdate_Click(this, e); } } catch (Exception ex) { base.ShowException("Script Import Error", ex); } }
private void SimpleArrayEditor_Load(object sender, EventArgs e) { if (this.DesignMode) { return; } try { GenericQbItem gi; _gItems = QbFile.GetGenericItems(base.QbItem); if (_gItems.Count != 0) { gi = _gItems[0]; try { lstItems.BeginUpdate(); foreach (GenericQbItem gqi in _gItems) { lstItems.Items.Add(gqi.Value); } lstItems.SelectedIndex = 0; } finally { lstItems.EndUpdate(); } } else { gi = QbFile.CreateGenericArrayItem(base.QbItem); } _currentEditType = gi.CurrentEditType; btnConvert.Text = GenericQbItem.GetTypeName(_currentEditType); lblItems.Text = gi.Name; mnuFloat.Click += new EventHandler(mnu_Click); mnuInt.Click += new EventHandler(mnu_Click); mnuUint.Click += new EventHandler(mnu_Click); mnuHex.Click += new EventHandler(mnu_Click); mnuString.Click += new EventHandler(mnu_Click); enableItems(); } catch (Exception ex) { base.ShowException("Simple Array Load Item Error", ex); } }
private void swapItems(int from, int to) { GenericQbItem tmp = _gItems[from]; _gItems[from] = _gItems[to]; _gItems[to] = tmp; string s = (string)lstItems.Items[from]; lstItems.Items[from] = lstItems.Items[to]; lstItems.Items[to] = s; }
/// <summary> /// Convert text representations /// </summary> /// <param name="text"></param> /// <param name="toType">Type to convert to</param> /// <returns></returns> public string ConvertTo(Type toType) { if (!GenericQbItem.IsTypeSupported(toType)) { throw new ArgumentOutOfRangeException(string.Format("{0} is not supported", toType.FullName)); } string s = _gItem.ConvertTo(toType); btnConvert.Text = GenericQbItem.GetTypeName(toType); txtValue.Text = s; return(s); }
private void txtValue_Validating(object sender, CancelEventArgs e) { string errMsg = GenericQbItem.ValidateText(_gItem.Type, _gItem.CurrentEditType, txtValue.Text); err.SetError(txtValue, errMsg); if (errMsg.Length != 0) { e.Cancel = true; } else { _gItem.Value = txtValue.Text; } }
public void SetData(GenericQbItem item) { _gItem = item; txtValue.ReadOnly = item.ReadOnly; if (!GenericQbItem.IsTypeSupported(item.Type)) { throw new ArgumentOutOfRangeException(string.Format("{0} is not supported", _gItem.Type.FullName)); } btnConvert.Text = GenericQbItem.GetTypeName(_gItem.CurrentEditType); lbl.Text = _gItem.Name; txtValue.Text = _gItem.Value; }
private void txtItem_Validating(object sender, CancelEventArgs e) { try { int idx = getSelectedItem(); if (idx >= 0 && idx < _gItems.Count) { string errMsg = GenericQbItem.ValidateText(_gItems[idx].Type, _gItems[idx].CurrentEditType, txtItem.Text); //only allow this event to clear messages if (errMsg.Length == 0) { err.SetError(txtItem, errMsg); } } } catch { e.Cancel = true; } }
private void btnSet_Click(object sender, EventArgs e) { try { string errMsg = GenericQbItem.ValidateText(_gItems[lstItems.SelectedIndex].Type, _gItems[lstItems.SelectedIndex].CurrentEditType, txtItem.Text); if (errMsg.Length != 0) { err.SetError(txtItem, errMsg); } else { int idx = getSelectedItem(); _gItems[idx].Value = txtItem.Text; lstItems.Items[idx] = _gItems[idx].Value; } } catch (Exception ex) { base.ShowException("Simple Array Set Error", ex); } }
private void addEditItem(int spacing, ref int top, ref int lblWidth, ref bool hasEditable, GenericQbItem gi) { GenericQbEditItem ei; ei = new GenericQbEditItem(); ei.SetData(gi); ei.Left = 0; ei.Width = this.ClientSize.Width; ei.Top = top; top += spacing; ei.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right; if (!hasEditable && !gi.ReadOnly) { hasEditable = true; } if (gi.UseQbItemType) { ei.ConvertTo(base.QbItemDataType); } //else // ei.ConvertTo(base.EditType); this.Controls.Add(ei); if (ei.LabelWidth > lblWidth) { lblWidth = ei.LabelWidth; } }