Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gui: Implement undo engine [WIP] #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//******************************************************************************
// Copyright (c) Jamie Mansfield <https://jamiemansfield.me/>
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//******************************************************************************

package me.jamiemansfield.symphony.undo;

import org.cadixdev.lorenz.model.Mapping;

public final class MappingUndoables {

public static Undoable remapMapping(final Mapping<?, ?> mapping, final String deobf) {
// Store original deobf value
final String originalDeobf = mapping.getDeobfuscatedName();
return new Undoable() {
@Override
public String getTitle() {
return "Remapping " + originalDeobf;
}

@Override
public void apply() {
mapping.setDeobfuscatedName(deobf);
}

@Override
public void unapply() {
mapping.setDeobfuscatedName(originalDeobf);
}
};
}

private MappingUndoables() {
}

}
12 changes: 12 additions & 0 deletions src/main/java/me/jamiemansfield/symphony/undo/UndoManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//******************************************************************************
// Copyright (c) Jamie Mansfield <https://jamiemansfield.me/>
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//******************************************************************************

package me.jamiemansfield.symphony.undo;

public class UndoManager {

}
35 changes: 35 additions & 0 deletions src/main/java/me/jamiemansfield/symphony/undo/Undoable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//******************************************************************************
// Copyright (c) Jamie Mansfield <https://jamiemansfield.me/>
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//******************************************************************************

package me.jamiemansfield.symphony.undo;

/**
* An action that can be undone, and redone.
*
* @author Jamie Mansfield
* @since 0.1.0
*/
public interface Undoable {

/**
* Gets the title of the undoable action.
*
* @return The title
*/
String getTitle();

/**
* Applies the action.
*/
void apply();

/**
* Un-applies the action, reverting to the original state.
*/
void unapply();

}