Skip to content

Commit

Permalink
added "L" short cut to insert last inserted component again.
Browse files Browse the repository at this point in the history
  • Loading branch information
hneemann committed Jun 5, 2017
1 parent 9781bed commit 65abe0c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/main/java/de/neemann/digital/gui/InsertHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class InsertHistory implements LibraryListener {
private final ElementLibrary library;
private final ArrayList<WrapperAction> wrappers;
private int mainTime;
private InsertAction lastInsertAction;

/**
* Creates a new instance
Expand All @@ -42,6 +43,7 @@ public InsertHistory(JToolBar bar, ElementLibrary library) {
* @param action the action
*/
public void add(InsertAction action) {
lastInsertAction = action;
if (!contains(action)) {
WrapperAction wrapper = new WrapperAction(action, bar.getComponentCount());
wrappers.add(wrapper);
Expand Down Expand Up @@ -82,6 +84,12 @@ private boolean contains(InsertAction action) {
return false;
}

/**
* @return the last insert action
*/
public InsertAction getLastInsertAction() {
return lastInsertAction;
}

@Override
public void libraryChanged(LibraryNode node) {
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/de/neemann/digital/gui/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,15 @@ public void actionPerformed(ActionEvent actionEvent) {
}
}.setToolTip(Lang.get("menu_help_elements_tt")).createJMenuItem());

new ToolTipAction("insertLast") {
@Override
public void actionPerformed(ActionEvent actionEvent) {
InsertAction lastInsertAction = insertHistory.getLastInsertAction();
if (lastInsertAction != null)
lastInsertAction.actionPerformed(actionEvent);
}
}.setAccelerator("L").enableAcceleratorIn(circuitComponent);

enableClockShortcut();

setPreferredSize(Screen.getInstance().scale(new Dimension(1024, 768)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,9 @@ else if (point.y > getHeight() - MOUSE_BORDER_SMALL)
} catch (AWTException e) {
e.printStackTrace();
}
} else {
mouseInsertElement.updateMousePos(getPosVector(point.x, point.y));
repaintNeeded();
}
}

Expand Down Expand Up @@ -1173,11 +1176,15 @@ private void activate(VisualElement element) {

@Override
void moved(MouseEvent e) {
updateMousePos(getPosVector(e));
}

void updateMousePos(Vector pos) {
if (delta == null) {
GraphicMinMax minMax = element.getMinMax(false);
delta = element.getPos().sub(minMax.getMax());
}
element.setPos(raster(getPosVector(e).add(delta)));
element.setPos(raster(pos.add(delta)));
repaint();
}

Expand Down Expand Up @@ -1210,6 +1217,7 @@ public void rotate() {
public void escapePressed() {
mouseNormal.activate();
}

}

private final class MouseControllerMoveElement extends MouseController {
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/docu/static_de.xml
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@
<shortcut key="STRG-C">Kopieren der selektierten Elemente in die Zwischenablage.</shortcut>
<shortcut key="STRG-V">Einfügen der Elemente aus der Zwischenablage.</shortcut>
<shortcut key="R">Beim Einfügen rotieren der Elemente.</shortcut>
<shortcut key="L">Letztes eingefügtes Element noch einmal einfügen.</shortcut>
<shortcut key="STRG-S">Speichern der Schaltung.</shortcut>
<shortcut key="STRG-Z">Letzte Änderung zurücknehmen.</shortcut>
<shortcut key="STRG-Y">Zurückgenommene Änderung erneut anwenden.</shortcut>
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/docu/static_en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@
<shortcut key="CTRL-C">Copys the selected components to the clipboard.</shortcut>
<shortcut key="CTRL-V">Inserts the comonents from the clipboard.</shortcut>
<shortcut key="R">While inserting this rotates the components.</shortcut>
<shortcut key="L">Inserts the last inserted component again.</shortcut>
<shortcut key="CTRL-S">Save the circuit.</shortcut>
<shortcut key="CTRL-Z">Undo last modification.</shortcut>
<shortcut key="CTRL-Y">Redo the last undone modification.</shortcut>
Expand Down

0 comments on commit 65abe0c

Please sign in to comment.