private void ActionsList_DragDrop(object sender, DragEventArgs e) { if (MacrosView.SelectedIndices.Count != 0) { Point pt = MacrosView.PointToClient(new Point(e.X, e.Y)); ListViewItem dIt = MacrosView.GetItemAt(pt.X, pt.Y); if (dIt != null) { int index = dIt.Index; foreach (int pos in MacrosView.SelectedIndices) { if (index != pos) { GXMacro old = GetMacros()[pos]; Macros2.Remove(old); Macros2.Insert(index, old); ++index; } } MacrosView.RedrawItems(dIt.Index, index, false); dirty = true; UpdateTitle(); } } }
/// <summary> /// Add new user action. /// </summary> /// <param name="macro"></param> public void AddAction(GXMacro macro) { if (this.InvokeRequired) { BeginInvoke(new AddActionEventHandler(AddAction), macro); } else { dirty = true; macro.Timestamp = DateTime.Now; Macros2.Add(macro); AddMacro(macro, Filtered); //Serialization will remove \r and comparing result will fail... if (macro.Value != null) { macro.Value = macro.Value.Replace("\r\n", "\n"); } //Serialization will remove \r and comparing result will fail... if (macro.Data != null) { macro.Data = macro.Data.Replace("\r\n", "\n"); } if (Created) { MacrosView.VirtualListSize = GetMacros().Count; if (Properties.Settings.Default.MacroFollowLast) { MacrosView.EnsureVisible(GetMacros().Count - 1); } UpdateTitle(); } } }
/// <summary> /// Mark selected macros to enabled. /// </summary> private void EnableMnu_Click(object sender, EventArgs e) { try { foreach (int it in MacrosView.SelectedIndices) { GetMacros()[it].Disable = false; MacrosView.RedrawItems(it, it, false); } dirty = true; UpdateTitle(); } catch (Exception Ex) { GXDLMS.Common.Error.ShowError(this, Ex); } }
private void Run(System.Collections.IList items, List <GXMacro> macros) { try { if (Target == null) { throw new Exception("Failed to run macro. No device is selected."); } UpdateRunMenu(true); UpdateStatus(); GXMacro selectedMacro = null; if (MacrosView.SelectedIndices.Count == 1) { selectedMacro = GetMacros()[MacrosView.SelectedIndices[0]]; } Results.Clear(); foreach (int it in items) { GXMacro orig = macros[it]; GXMacro macro = orig.Clone(); orig.LastRunMacro = macro; Results.Add(orig, macro); if (Properties.Settings.Default.MacroFollowLast) { MacrosView.EnsureVisible(it); } if (!macro.Disable) { macro.Exception = null; try { orig.Running = true; MacrosView.RedrawItems(it, it, false); switch (macro.Type) { case UserActionType.Connect: m_OnConnect(macro); break; case UserActionType.Disconnecting: m_OnDisconnect(macro); break; case UserActionType.Get: macro.Value = macro.Data = macro.Exception = null; macro.DataType = 0; m_OnGet(macro); //Update data if it's updated. if (macro.Verify) { if (macro.Exception != orig.Exception) { macro.Exception = "Different exceptions."; } else if (macro.DataType != orig.DataType) { macro.Exception = "Different data type."; } else if (macro.Data != orig.Data) { macro.Exception = "Different data."; } } break; case UserActionType.Set: m_OnSet(macro); break; case UserActionType.Action: m_OnAction(macro); break; default: break; } } catch (Exception ex) { macro.Exception = ex.Message; if (Properties.Settings.Default.MacroBreakOnError) { throw; } } finally { orig.Running = false; MacrosView.RedrawItems(it, it, false); } if (orig == selectedMacro) { ActionsList_SelectedIndexChanged(null, null); } } } } finally { UpdateRunMenu(false); UpdateStatus(); } }
private void ActionsList_ItemDrag(object sender, ItemDragEventArgs e) { MacrosView.DoDragDrop(MacrosView.SelectedItems, DragDropEffects.Move); }