mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2024-11-23 12:22:35 +00:00
@ Work in progress on the Mass Undo/Redo plugin
This commit is contained in:
parent
0ac4c4ad4f
commit
7af4e711bb
2 changed files with 95 additions and 3 deletions
|
@ -50,6 +50,9 @@ namespace CodeImp.DoomBuilder.MassUndoRedo
|
|||
this.list.TabIndex = 0;
|
||||
this.list.UseCompatibleStateImageBehavior = false;
|
||||
this.list.View = System.Windows.Forms.View.Details;
|
||||
this.list.SelectedIndexChanged += new System.EventHandler(this.list_SelectedIndexChanged);
|
||||
this.list.MouseUp += new System.Windows.Forms.MouseEventHandler(this.list_MouseUp);
|
||||
this.list.KeyUp += new System.Windows.Forms.KeyEventHandler(this.list_KeyUp);
|
||||
//
|
||||
// coldescription
|
||||
//
|
||||
|
|
|
@ -34,6 +34,10 @@ namespace CodeImp.DoomBuilder.MassUndoRedo
|
|||
{
|
||||
#region ================== Variables
|
||||
|
||||
private bool ignoreevents;
|
||||
private int currentselection;
|
||||
private bool ignorefirstevent;
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Constructor
|
||||
|
@ -42,6 +46,7 @@ namespace CodeImp.DoomBuilder.MassUndoRedo
|
|||
public UndoRedoForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
ignorefirstevent = true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -53,6 +58,8 @@ namespace CodeImp.DoomBuilder.MassUndoRedo
|
|||
{
|
||||
List<UndoSnapshot> levels;
|
||||
|
||||
ignoreevents = true;
|
||||
|
||||
// Position window on the left side of the main window
|
||||
SizeF scalefactor = new SizeF(owner.CurrentAutoScaleDimensions.Width / owner.AutoScaleDimensions.Width,
|
||||
owner.CurrentAutoScaleDimensions.Height / owner.AutoScaleDimensions.Height);
|
||||
|
@ -60,29 +67,111 @@ namespace CodeImp.DoomBuilder.MassUndoRedo
|
|||
this.Location = new Point(owner.Location.X + (int)(20 * scalefactor.Width), owner.Location.Y + topoffset);
|
||||
this.Height = owner.Height - (topoffset + (int)(50 * scalefactor.Height));
|
||||
|
||||
// Fill the list
|
||||
// Reset the list
|
||||
list.Items.Clear();
|
||||
list.Items.Add("Begin");
|
||||
|
||||
// Add undo levels
|
||||
levels = General.Map.UndoRedo.GetUndoList();
|
||||
levels.Reverse();
|
||||
foreach(UndoSnapshot u in levels)
|
||||
{
|
||||
list.Items.Add(u.Description);
|
||||
ListViewItem item = list.Items.Add(u.Description);
|
||||
}
|
||||
|
||||
// Select the last undo level: that's where we currently are at.
|
||||
list.Items[list.Items.Count - 1].Selected = true;
|
||||
currentselection = list.Items.Count - 1;
|
||||
|
||||
// Add redo levels
|
||||
levels = General.Map.UndoRedo.GetRedoList();
|
||||
foreach(UndoSnapshot r in levels)
|
||||
{
|
||||
ListViewItem item = list.Items.Add(r.Description);
|
||||
item.BackColor = SystemColors.Control;
|
||||
item.ForeColor = SystemColors.GrayText;
|
||||
item.BackColor = SystemColors.Control;
|
||||
}
|
||||
|
||||
ignoreevents = false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ================== Events
|
||||
|
||||
// Item selected
|
||||
private void list_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if(ignoreevents) return;
|
||||
if(ignorefirstevent)
|
||||
{
|
||||
ignorefirstevent = false;
|
||||
return;
|
||||
}
|
||||
|
||||
ignoreevents = true;
|
||||
|
||||
// We must have something selected
|
||||
if(list.SelectedIndices.Count > 0)
|
||||
{
|
||||
// Not the same as last selected?
|
||||
int selectedindex = list.SelectedIndices[0];
|
||||
if(selectedindex != currentselection)
|
||||
{
|
||||
// Perform the undo/redos
|
||||
int delta = currentselection - selectedindex;
|
||||
if(delta < 0)
|
||||
General.Map.UndoRedo.PerformRedo(-delta);
|
||||
else
|
||||
General.Map.UndoRedo.PerformUndo(delta);
|
||||
|
||||
// Update list
|
||||
list.BeginUpdate();
|
||||
foreach(ListViewItem item in list.Items)
|
||||
{
|
||||
if(item.Index <= selectedindex)
|
||||
{
|
||||
item.ForeColor = SystemColors.WindowText;
|
||||
item.BackColor = SystemColors.Window;
|
||||
}
|
||||
else
|
||||
{
|
||||
item.ForeColor = SystemColors.GrayText;
|
||||
item.BackColor = SystemColors.Control;
|
||||
}
|
||||
}
|
||||
list.EndUpdate();
|
||||
currentselection = selectedindex;
|
||||
}
|
||||
}
|
||||
|
||||
ignoreevents = false;
|
||||
}
|
||||
|
||||
// Mouse released
|
||||
private void list_MouseUp(object sender, MouseEventArgs e)
|
||||
{
|
||||
ignoreevents = true;
|
||||
|
||||
// If selection was removed, then keep the last selected
|
||||
if(list.SelectedIndices.Count == 0)
|
||||
list.Items[currentselection].Selected = true;
|
||||
|
||||
ignoreevents = false;
|
||||
}
|
||||
|
||||
// Key released
|
||||
private void list_KeyUp(object sender, KeyEventArgs e)
|
||||
{
|
||||
ignoreevents = true;
|
||||
|
||||
// If selection was removed, then keep the last selected
|
||||
if(list.SelectedIndices.Count == 0)
|
||||
list.Items[currentselection].Selected = true;
|
||||
|
||||
ignoreevents = false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue