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

Shift+A to move a bookmark entry to the front (for #85) #96

Merged
merged 3 commits into from
Feb 9, 2025
Merged
Show file tree
Hide file tree
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
30 changes: 29 additions & 1 deletion src/main/java/mezz/jei/bookmarks/BookmarkList.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,22 @@ public BookmarkList(IngredientRegistry ingredientRegistry) {
}

public <T> boolean add(T ingredient) {
return add(ingredient, false);
}

public <T> boolean add(T ingredient, boolean forceFront) {
tttsaurus marked this conversation as resolved.
Show resolved Hide resolved
Object normalized = normalize(ingredient);
if (!contains(normalized)) {
if (addToLists(normalized, Config.isAddingBookmarksToFront())) {
if (addToLists(normalized, forceFront || Config.isAddingBookmarksToFront())) {
notifyListenersOfChange();
saveBookmarks();
return true;
}
} else if (forceFront) {
// avoid boolean expression short-circuiting
boolean flag1 = remove(normalized, true);
boolean flag2 = addToLists(normalized, true);
if (flag1 || flag2) {
notifyListenersOfChange();
saveBookmarks();
return true;
Expand Down Expand Up @@ -83,8 +96,23 @@ private boolean contains(Object ingredient) {
}

public boolean remove(Object ingredient) {
return remove(ingredient, false);
}

public boolean remove(Object ingredient, boolean looseEqualCheck) {
tttsaurus marked this conversation as resolved.
Show resolved Hide resolved
int index = 0;
for (Object existing : list) {
if (looseEqualCheck) {
String id1 = ingredientRegistry.getIngredientHelper(ingredient).getUniqueId(ingredient);
String id2 = ingredientRegistry.getIngredientHelper(existing).getUniqueId(existing);
if (id1.equals(id2)) {
list.remove(index);
ingredientListElements.remove(index);
notifyListenersOfChange();
saveBookmarks();
return true;
}
}
if (ingredient == existing) {
list.remove(index);
ingredientListElements.remove(index);
Expand Down
22 changes: 18 additions & 4 deletions src/main/java/mezz/jei/input/InputHandler.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package mezz.jei.input;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.ArrayList;

import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.client.event.GuiScreenEvent;
Expand Down Expand Up @@ -60,6 +60,18 @@ public InputHandler(JeiRuntime runtime, IngredientRegistry ingredientRegistry, I
this.showsRecipeFocuses.add(new GuiContainerWrapper(guiScreenHelper));
}

private boolean handleBookmarkExtra() {
boolean forceAdd = (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) && Keyboard.isKeyDown(KeyBindings.bookmark.getKeyCode());
if (!forceAdd) return false;
IClickedIngredient<?> clicked = getIngredientUnderMouseForKey(MouseHelper.getX(), MouseHelper.getY());
if (clicked != null) {
if (!Config.isBookmarkOverlayEnabled())
Config.toggleBookmarkEnabled();
return bookmarkList.add(clicked.getValue(), true);
}
return false;
}

/**
* When we have keyboard focus, use Pre
*/
Expand All @@ -75,9 +87,11 @@ public void onGuiKeyboardEvent(GuiScreenEvent.KeyboardInputEvent.Pre event) {
*/
@SubscribeEvent
public void onGuiKeyboardEvent(GuiScreenEvent.KeyboardInputEvent.Post event) {
if (!hasKeyboardFocus() && handleKeyEvent()) {
if (hasKeyboardFocus()) return;
if (handleBookmarkExtra())
event.setCanceled(true);
else if (handleKeyEvent())
event.setCanceled(true);
}
}

@SubscribeEvent
Expand Down Expand Up @@ -214,7 +228,7 @@ private boolean handleKeyEvent() {
int eventKey = Keyboard.getEventKey();

return ((eventKey == 0 && typedChar >= 32) || Keyboard.getEventKeyState()) &&
handleKeyDown(typedChar, eventKey);
handleKeyDown(typedChar, eventKey);
}

private boolean handleKeyDown(char typedChar, int eventKey) {
Expand Down