mirror of
https://github.com/aNNiMON/HotaruFX.git
synced 2024-09-19 14:14:21 +03:00
Add cut, copy and paste buttons to toolbar
This commit is contained in:
parent
d2e85e1b87
commit
378cc26d49
@ -11,7 +11,9 @@ import javafx.util.Pair;
|
|||||||
|
|
||||||
public enum FontAwesome {
|
public enum FontAwesome {
|
||||||
|
|
||||||
CLIPBOARD("\uf0ea", "clipboard"),
|
CLIPBOARD("\uf0ea", "clipboard", "paste"),
|
||||||
|
CLONE("\uf24d", "clone"),
|
||||||
|
COPY("\uf0c5", "copy"),
|
||||||
COPYRIGHT("\uf1f9", "copyright"),
|
COPYRIGHT("\uf1f9", "copyright"),
|
||||||
FONT_AWESOME("\uf2b4", "font-awesome"),
|
FONT_AWESOME("\uf2b4", "font-awesome"),
|
||||||
GITHUB("\uf09b", "github"),
|
GITHUB("\uf09b", "github"),
|
||||||
@ -19,6 +21,7 @@ public enum FontAwesome {
|
|||||||
PENCIL("\uf040", "pencil"),
|
PENCIL("\uf040", "pencil"),
|
||||||
PLAY("\uf04b", "play"),
|
PLAY("\uf04b", "play"),
|
||||||
REDO("\uf01e", "redo"),
|
REDO("\uf01e", "redo"),
|
||||||
|
SCISSORS("\uf0c4", "scissors", "cut"),
|
||||||
UNDO("\uf0e2", "undo");
|
UNDO("\uf0e2", "undo");
|
||||||
|
|
||||||
private final String symbol;
|
private final String symbol;
|
||||||
|
@ -155,7 +155,7 @@ public class ColorPickerBox extends VBox {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
final Button copyButton = new Button("Copy");
|
final Button copyButton = new Button("Copy");
|
||||||
copyButton.setGraphic(new FontAwesomeIcon("clipboard"));
|
copyButton.setGraphic(new FontAwesomeIcon("copy"));
|
||||||
copyButton.setOnAction(e -> {
|
copyButton.setOnAction(e -> {
|
||||||
final Clipboard clipboard = Clipboard.getSystemClipboard();
|
final Clipboard clipboard = Clipboard.getSystemClipboard();
|
||||||
final ClipboardContent content = new ClipboardContent();
|
final ClipboardContent content = new ClipboardContent();
|
||||||
|
@ -12,8 +12,8 @@ import com.annimon.hotarufx.lexer.HotaruLexer;
|
|||||||
import com.annimon.hotarufx.lib.Context;
|
import com.annimon.hotarufx.lib.Context;
|
||||||
import com.annimon.hotarufx.parser.HotaruParser;
|
import com.annimon.hotarufx.parser.HotaruParser;
|
||||||
import com.annimon.hotarufx.parser.visitors.InterpreterVisitor;
|
import com.annimon.hotarufx.parser.visitors.InterpreterVisitor;
|
||||||
import com.annimon.hotarufx.ui.control.LibraryItem;
|
|
||||||
import com.annimon.hotarufx.ui.SyntaxHighlighter;
|
import com.annimon.hotarufx.ui.SyntaxHighlighter;
|
||||||
|
import com.annimon.hotarufx.ui.control.LibraryItem;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@ -22,7 +22,9 @@ import java.util.ResourceBundle;
|
|||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.beans.binding.Bindings;
|
import javafx.beans.binding.Bindings;
|
||||||
|
import javafx.beans.binding.BooleanBinding;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
|
import javafx.event.EventHandler;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
@ -44,7 +46,7 @@ public class EditorController implements Initializable, DocumentListener {
|
|||||||
private CheckMenuItem syntaxHighlightingItem;
|
private CheckMenuItem syntaxHighlightingItem;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Button undoButton, redoButton;
|
private Button undoButton, redoButton, cutButton, copyButton, pasteButton;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private CodeArea editor;
|
private CodeArea editor;
|
||||||
@ -164,6 +166,7 @@ public class EditorController implements Initializable, DocumentListener {
|
|||||||
documentManager = new FileManager();
|
documentManager = new FileManager();
|
||||||
initSyntaxHighlighter();
|
initSyntaxHighlighter();
|
||||||
initUndoRedo();
|
initUndoRedo();
|
||||||
|
initCopyCutPaste();
|
||||||
openSample();
|
openSample();
|
||||||
editor.getUndoManager().forgetHistory();
|
editor.getUndoManager().forgetHistory();
|
||||||
initializeLibrary();
|
initializeLibrary();
|
||||||
@ -191,8 +194,31 @@ public class EditorController implements Initializable, DocumentListener {
|
|||||||
Bindings.not(editor.undoAvailableProperty()));
|
Bindings.not(editor.undoAvailableProperty()));
|
||||||
redoButton.disableProperty().bind(
|
redoButton.disableProperty().bind(
|
||||||
Bindings.not(editor.redoAvailableProperty()));
|
Bindings.not(editor.redoAvailableProperty()));
|
||||||
undoButton.setOnAction(a -> editor.undo());
|
undoButton.setOnAction(editorAction(editor::undo));
|
||||||
redoButton.setOnAction(a -> editor.redo());
|
redoButton.setOnAction(editorAction(editor::redo));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initCopyCutPaste() {
|
||||||
|
val selectionEmpty = new BooleanBinding() {
|
||||||
|
{ bind(editor.selectionProperty()); }
|
||||||
|
@Override
|
||||||
|
protected boolean computeValue() {
|
||||||
|
return editor.getSelection().getLength() == 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
cutButton.disableProperty().bind(selectionEmpty);
|
||||||
|
copyButton.disableProperty().bind(selectionEmpty);
|
||||||
|
|
||||||
|
cutButton.setOnAction(editorAction(editor::cut));
|
||||||
|
copyButton.setOnAction(editorAction(editor::copy));
|
||||||
|
pasteButton.setOnAction(editorAction(editor::paste));
|
||||||
|
}
|
||||||
|
|
||||||
|
private EventHandler<ActionEvent> editorAction(Runnable r) {
|
||||||
|
return event -> {
|
||||||
|
r.run();
|
||||||
|
editor.requestFocus();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeLibrary() {
|
private void initializeLibrary() {
|
||||||
|
@ -49,7 +49,7 @@
|
|||||||
<FontAwesomeIcon icon="undo"/>
|
<FontAwesomeIcon icon="undo"/>
|
||||||
</graphic>
|
</graphic>
|
||||||
<tooltip>
|
<tooltip>
|
||||||
<Tooltip text="Undo"/>
|
<Tooltip text="Undo action"/>
|
||||||
</tooltip>
|
</tooltip>
|
||||||
</Button>
|
</Button>
|
||||||
<Button fx:id="redoButton">
|
<Button fx:id="redoButton">
|
||||||
@ -57,7 +57,32 @@
|
|||||||
<FontAwesomeIcon icon="redo"/>
|
<FontAwesomeIcon icon="redo"/>
|
||||||
</graphic>
|
</graphic>
|
||||||
<tooltip>
|
<tooltip>
|
||||||
<Tooltip text="Redo"/>
|
<Tooltip text="Redo action"/>
|
||||||
|
</tooltip>
|
||||||
|
</Button>
|
||||||
|
<Separator/>
|
||||||
|
<Button fx:id="cutButton">
|
||||||
|
<graphic>
|
||||||
|
<FontAwesomeIcon icon="cut"/>
|
||||||
|
</graphic>
|
||||||
|
<tooltip>
|
||||||
|
<Tooltip text="Cut selection"/>
|
||||||
|
</tooltip>
|
||||||
|
</Button>
|
||||||
|
<Button fx:id="copyButton">
|
||||||
|
<graphic>
|
||||||
|
<FontAwesomeIcon icon="copy"/>
|
||||||
|
</graphic>
|
||||||
|
<tooltip>
|
||||||
|
<Tooltip text="Copy selection"/>
|
||||||
|
</tooltip>
|
||||||
|
</Button>
|
||||||
|
<Button fx:id="pasteButton">
|
||||||
|
<graphic>
|
||||||
|
<FontAwesomeIcon icon="paste"/>
|
||||||
|
</graphic>
|
||||||
|
<tooltip>
|
||||||
|
<Tooltip text="Paste from clipboard"/>
|
||||||
</tooltip>
|
</tooltip>
|
||||||
</Button>
|
</Button>
|
||||||
<Separator/>
|
<Separator/>
|
||||||
|
Loading…
Reference in New Issue
Block a user