UndoRedoButtonItem.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. using FastReport.Design;
  2. using FastReport.DevComponents.DotNetBar;
  3. using FastReport.Utils;
  4. using System.Drawing;
  5. using System.Windows.Forms;
  6. using System;
  7. namespace FastReport.Controls
  8. {
  9. internal class UndoButtonItem : ButtonItem
  10. {
  11. private UndoDropDown undoDropDown;
  12. public UndoButtonItem(Designer designer)
  13. {
  14. undoDropDown = new UndoDropDown(designer, this);
  15. Click += designer.cmdUndo.Invoke;
  16. }
  17. }
  18. internal class RedoButtonItem : ButtonItem
  19. {
  20. private RedoDropDown redoDropDown;
  21. public RedoButtonItem(Designer designer)
  22. {
  23. redoDropDown = new RedoDropDown(designer, this);
  24. Click += designer.cmdRedo.Invoke;
  25. }
  26. }
  27. internal class UndoRedoDropDown : ItemContainer
  28. {
  29. private bool updating;
  30. protected Designer designer;
  31. protected ListBox lbxActions;
  32. protected Label lblUndoRedo;
  33. protected ButtonItem parent;
  34. protected ControlContainerItem actionsHost;
  35. protected ControlContainerItem labelHost;
  36. private void SetSelected(int index)
  37. {
  38. if (updating)
  39. return;
  40. updating = true;
  41. int saveTop = lbxActions.TopIndex;
  42. lbxActions.BeginUpdate();
  43. lbxActions.SelectedIndices.Clear();
  44. if (lbxActions.Items.Count > 0)
  45. {
  46. for (int i = index; i >= 0; i--)
  47. lbxActions.SelectedIndices.Add(i);
  48. }
  49. lbxActions.TopIndex = saveTop;
  50. lbxActions.EndUpdate();
  51. UpdateLabel();
  52. updating = false;
  53. }
  54. public override void UpdateDpiDependencies()
  55. {
  56. base.UpdateDpiDependencies();
  57. UpdateSizes();
  58. }
  59. private void lbxActions_MouseMove(object sender, MouseEventArgs e)
  60. {
  61. int index = lbxActions.IndexFromPoint(e.X, e.Y);
  62. SetSelected(index);
  63. }
  64. private void lbxActions_MouseDown(object sender, MouseEventArgs e)
  65. {
  66. int actionsCount = lbxActions.SelectedItems.Count + 1;
  67. parent.ClosePopup();
  68. DoUndoRedo(actionsCount);
  69. }
  70. private void UpdateSizes()
  71. {
  72. lbxActions.Size = designer.LogicalToDevice(new Size(150, 200));
  73. lblUndoRedo.Size = designer.LogicalToDevice(new Size(150, 30));
  74. }
  75. protected virtual void PopulateItems()
  76. {
  77. }
  78. protected virtual void UpdateLabel()
  79. {
  80. }
  81. protected virtual void DoUndoRedo(int actionsCount)
  82. {
  83. }
  84. private void parent_PopupOpen(object sender, PopupOpenEventArgs e)
  85. {
  86. PopulateItems();
  87. UpdateSizes();
  88. SetSelected(0);
  89. }
  90. public UndoRedoDropDown(Designer designer, ButtonItem parent)
  91. {
  92. this.designer = designer;
  93. this.parent = parent;
  94. LayoutOrientation = eOrientation.Vertical;
  95. parent.PopupType = ePopupType.ToolBar;
  96. parent.SubItems.Add(this);
  97. parent.PopupOpen += new DotNetBarManager.PopupOpenEventHandler(parent_PopupOpen);
  98. lbxActions = new ListBox();
  99. lbxActions.Size = new Size(150, 200);
  100. lbxActions.BorderStyle = BorderStyle.None;
  101. lbxActions.SelectionMode = SelectionMode.MultiSimple;
  102. lbxActions.MouseMove += new MouseEventHandler(lbxActions_MouseMove);
  103. lbxActions.MouseDown += new MouseEventHandler(lbxActions_MouseDown);
  104. actionsHost = new ControlContainerItem();
  105. actionsHost.Control = lbxActions;
  106. SubItems.Add(actionsHost);
  107. lblUndoRedo = new Label();
  108. lblUndoRedo.AutoSize = false;
  109. lblUndoRedo.Size = new Size(150, 30);
  110. lblUndoRedo.TextAlign = ContentAlignment.MiddleCenter;
  111. lblUndoRedo.BackColor = Color.Transparent;
  112. labelHost = new ControlContainerItem();
  113. labelHost.Control = lblUndoRedo;
  114. SubItems.Add(labelHost);
  115. }
  116. }
  117. internal class UndoDropDown : UndoRedoDropDown
  118. {
  119. protected override void PopulateItems()
  120. {
  121. lbxActions.Items.Clear();
  122. if (designer.ActiveReport != null)
  123. {
  124. string[] undoNames = designer.ActiveReportTab.UndoRedo.UndoNames;
  125. foreach (string s in undoNames)
  126. {
  127. lbxActions.Items.Add(s);
  128. }
  129. }
  130. }
  131. protected override void UpdateLabel()
  132. {
  133. lblUndoRedo.Text = String.Format(Res.Get("Designer,UndoRedo,UndoN"), lbxActions.SelectedItems.Count);
  134. }
  135. protected override void DoUndoRedo(int actionsCount)
  136. {
  137. designer.cmdUndo.Undo(actionsCount);
  138. }
  139. public UndoDropDown(Designer designer, ButtonItem parent)
  140. : base(designer, parent)
  141. {
  142. }
  143. }
  144. internal class RedoDropDown : UndoRedoDropDown
  145. {
  146. protected override void PopulateItems()
  147. {
  148. lbxActions.Items.Clear();
  149. if (designer.ActiveReport != null)
  150. {
  151. string[] undoNames = designer.ActiveReportTab.UndoRedo.RedoNames;
  152. foreach (string s in undoNames)
  153. {
  154. lbxActions.Items.Add(s);
  155. }
  156. }
  157. }
  158. protected override void UpdateLabel()
  159. {
  160. lblUndoRedo.Text = String.Format(Res.Get("Designer,UndoRedo,RedoN"), lbxActions.SelectedItems.Count);
  161. }
  162. protected override void DoUndoRedo(int actionsCount)
  163. {
  164. designer.cmdRedo.Redo(actionsCount);
  165. }
  166. public RedoDropDown(Designer designer, ButtonItem parent)
  167. : base(designer, parent)
  168. {
  169. }
  170. }
  171. }