Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
05c13a1
Added alt-shortcuts to main context menu
FransBouma Jul 3, 2023
e3660a7
Defined various shortcut keys on the node type menu items. Changed to…
FransBouma Jul 3, 2023
4d3ac22
Moved ReadFromBuffer to MemoryBuffer where it belongs, and it's now u…
FransBouma Jul 3, 2023
4d2f079
Redefined some kb shortcuts, as ctrl-shift-c/v aren't used elsewhere
FransBouma Jul 3, 2023
208454e
Added a way to name a class after RTTI information associated with th…
FransBouma Jul 3, 2023
b61edca
Changed 'Auto-name' into 'Init from RTTI' and it now also inits the v…
FransBouma Jul 3, 2023
68b44d5
Removed alt-key shortcuts from context menu as they can't be viewed a…
FransBouma Jul 3, 2023
c831f9b
Added a toolstrip button for Init class from RTTI so the shortcut wor…
FransBouma Jul 4, 2023
5931050
Initial packages update
FransBouma Jul 4, 2023
dc5225e
Marked Init class from RTTI toolbar button as 'Overflow as needed' so…
FransBouma Jul 4, 2023
7bc89c7
Merge branch 'master' into UndoRedo
FransBouma Jul 4, 2023
35afcee
Defined some node type toolbar buttons as 'As Needed' for overflow if…
FransBouma Jul 4, 2023
fb7b4d6
Initial undo/redo system in place. Class name is now undo/redo aware
FransBouma Jul 4, 2023
aa8a857
Removed 2nd empty lines when introduced, added 32bit version of ReadF…
FransBouma Jul 4, 2023
a01ba4c
Merge branch 'master' into UndoRedo
FransBouma Jul 4, 2023
528708d
Added undo/redo for Class AddressFormula. Wired up auto-exception han…
FransBouma Jul 4, 2023
69790cd
Implemented class list undo/redo, and further class node undo/redo. M…
FransBouma Jul 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Initial undo/redo system in place. Class name is now undo/redo aware
  • Loading branch information
FransBouma committed Jul 4, 2023
commit fb7b4d69ba5e3ca0427304fa592cc4d48279eebe
11 changes: 10 additions & 1 deletion ReClass.NET/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ReClassNET
namespace ReClassNET
{
public class Constants
{
Expand Down Expand Up @@ -39,5 +39,14 @@ public static class CommandLineOptions
public const string FileExtRegister = "registerfileext";
public const string FileExtUnregister = "unregisterfileext";
}

/// <summary>
/// Change type for commandified members in classes which is used to signal what change occurred exactly. As we don't use this feature of the commandified
/// class, this enum is defined to simply signal 'no specific change other than it changed' happened.
/// </summary>
public enum GeneralPurposeChangeType
{
None
}
}
}
28 changes: 27 additions & 1 deletion ReClass.NET/Forms/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions ReClass.NET/Forms/MainForm.Functions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using ReClassNET.Nodes;
using ReClassNET.Project;
using ReClassNET.UI;
using SD.Tools.Algorithmia.Commands;

namespace ReClassNET.Forms
{
Expand Down Expand Up @@ -213,6 +214,10 @@ public void LoadProjectFromPath(string path)
{
Contract.Requires(path != null);

CommandQueueManagerSingleton.GetInstance().ResetActiveCommandQueue();
CommandQueueManagerSingleton.GetInstance().BeginNonUndoablePeriod(); // we don't want to trigger undo/redo activity while loading
CommandQueueManagerSingleton.GetInstance().RaiseEvents = false;

var project = new ReClassNetProject();

LoadProjectFromPath(path, ref project);
Expand All @@ -224,6 +229,10 @@ public void LoadProjectFromPath(string path)
}

SetProject(project);

// Done loading, resume undo/redo activity
CommandQueueManagerSingleton.GetInstance().RaiseEvents = true;
CommandQueueManagerSingleton.GetInstance().EndNonUndoablePeriod();
}

/// <summary>Loads the file into the given project.</summary>
Expand Down
35 changes: 35 additions & 0 deletions ReClass.NET/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using ReClassNET.UI;
using ReClassNET.Util;
using ReClassNET.Util.Conversion;
using SD.Tools.Algorithmia.Commands;

namespace ReClassNET.Forms
{
Expand Down Expand Up @@ -95,8 +96,11 @@ public MainForm()
};

pluginManager = new PluginManager(new DefaultPluginHost(this, Program.RemoteProcess, Program.Logger));

CommandQueueManagerSingleton.GetInstance().CommandQueueActionPerformed += OnCommandQueueActionPerformed;
}


protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
Expand Down Expand Up @@ -135,6 +139,8 @@ protected override void OnLoad(EventArgs e)
{
AttachToProcess(Program.CommandLineArgs[Constants.CommandLineOptions.AttachTo]);
}

SetStateOfUndoRedoButtons();
}

protected override void OnFormClosed(FormClosedEventArgs e)
Expand Down Expand Up @@ -1063,7 +1069,36 @@ private void initClassToolStripMenuItem_Click(object sender, EventArgs e)
{
return;
}

var cmd = new UndoablePeriodCommand("InitClassFromRTTI");
CommandQueueManagerSingleton.GetInstance().BeginUndoablePeriod(cmd);
memoryViewControl.InitCurrentClassFromRTTI(node as ClassNode);
CommandQueueManagerSingleton.GetInstance().EndUndoablePeriod(cmd);
}


private void SetStateOfUndoRedoButtons()
{
undoToolbarMenuItem.Enabled = CommandQueueManagerSingleton.GetInstance().CanUndo(Program.CommandQueueID);
redoToolbarMenuItem.Enabled = CommandQueueManagerSingleton.GetInstance().CanDo(Program.CommandQueueID);
}


private void OnCommandQueueActionPerformed(object sender, CommandQueueActionPerformedEventArgs e)
{
SetStateOfUndoRedoButtons();
}


private void undoToolbarMenuItem_Click(object sender, EventArgs e)
{
CommandQueueManagerSingleton.GetInstance().UndoLastCommand();
}


private void redoToolbarMenuItem_Click(object sender, EventArgs e)
{
CommandQueueManagerSingleton.GetInstance().RedoLastCommand();
}
}
}
23 changes: 20 additions & 3 deletions ReClass.NET/Nodes/BaseNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using ReClassNET.Extensions;
using ReClassNET.UI;
using ReClassNET.Util;
using SD.Tools.Algorithmia.GeneralDataStructures;
using SD.Tools.Algorithmia.GeneralDataStructures.EventArguments;

namespace ReClassNET.Nodes
{
Expand All @@ -24,14 +26,26 @@ public abstract class BaseNode

private static int nodeIndex = 0;

private string name = string.Empty;
//private string name = string.Empty;
private CommandifiedMember<string, Constants.GeneralPurposeChangeType> name;
private string comment = string.Empty;

/// <summary>Gets or sets the offset of the node.</summary>
public int Offset { get; set; }

/// <summary>Gets or sets the name of the node. If a new name was set the property changed event gets fired.</summary>
public virtual string Name { get => name; set { if (value != null && name != value) { name = value; NameChanged?.Invoke(this); } } }
public virtual string Name
{
get => name.MemberValue;
set
{
if (value == null)
{
return;
}
name.MemberValue = value;
}
}

/// <summary>Gets or sets the comment of the node.</summary>
public string Comment { get => comment; set { if (value != null && comment != value) { comment = value; CommentChanged?.Invoke(this); } } }
Expand Down Expand Up @@ -100,12 +114,15 @@ protected BaseNode()
Contract.Ensures(name != null);
Contract.Ensures(comment != null);

Name = $"N{nodeIndex++:X08}";
name = new CommandifiedMember<string, Constants.GeneralPurposeChangeType>("Name", Constants.GeneralPurposeChangeType.None, $"N{nodeIndex++:X08}");
name.ValueChanged += Name_ValueChanged;
Comment = string.Empty;

LevelsOpen[0] = true;
}

private void Name_ValueChanged(object sender, MemberChangedEventArgs<Constants.GeneralPurposeChangeType, string> e) => NameChanged?.Invoke(this);

public abstract void GetUserInterfaceInfo(out string name, out Image icon);

public virtual bool UseMemoryPreviewToolTip(HotSpot spot, out IntPtr address)
Expand Down
9 changes: 9 additions & 0 deletions ReClass.NET/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using ReClassNET.Native;
using ReClassNET.UI;
using ReClassNET.Util;
using SD.Tools.Algorithmia.Commands;

namespace ReClassNET
{
Expand All @@ -34,10 +35,13 @@ public static class Program

public static FontEx MonoSpaceFont { get; private set; }

public static Guid CommandQueueID { get; private set; }

[STAThread]
static void Main(string[] args)
{
DesignMode = false; // The designer doesn't call Main()
CommandQueueID = Guid.NewGuid();

CommandLineArgs = new CommandLineArgs(args);

Expand All @@ -63,6 +67,11 @@ static void Main(string[] args)
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

// switch is set to false, so Do actions during Undo actions are ignored.
CommandQueueManager.ThrowExceptionOnDoDuringUndo = false;
// activate our command queue stack. We're only changing things from the main thread so we don't need multiple stacks.
CommandQueueManagerSingleton.GetInstance().ActivateCommandQueueStack(CommandQueueID);

CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;

Settings = SettingsSerializer.Load();
Expand Down