mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-10-07 23:51:28 +00:00
Rework shell terminal command handling and clipboards
This commit is contained in:
1 parent
2af59af190
commit
4daa183dad
8 files changed
+57
-59
No files matched your search
@@ -28,10 +28,6 @@ import javafx.css.PseudoClass;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.Menu;
|
||||
import javafx.scene.control.MenuItem;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.input.MouseButton;
|
||||
import javafx.scene.layout.ColumnConstraints;
|
||||
@@ -39,16 +35,13 @@ import javafx.scene.layout.Region;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import org.kordamp.ikonli.javafx.FontIcon;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.Clipboard;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
public abstract class StoreEntryComp extends SimpleComp {
|
||||
|
||||
public static StoreEntryComp create(
|
||||
StoreEntryWrapper entry, boolean showIcon, Comp<?> content, boolean preferLarge) {
|
||||
StoreEntryWrapper entry, Comp<?> content, boolean preferLarge) {
|
||||
if (!preferLarge) {
|
||||
return new DenseStoreEntryComp(entry, true, content);
|
||||
} else {
|
||||
@@ -331,10 +324,8 @@ public abstract class StoreEntryComp extends SimpleComp {
|
||||
l.textProperty().bind(AppI18n.observable("base.copyShareLink"));
|
||||
l.setOnAction(event -> {
|
||||
ThreadHelper.runFailableAsync(() -> {
|
||||
var selection = new StringSelection(url);
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
AppActionLinkDetector.setLastDetectedAction(url);
|
||||
clipboard.setContents(selection, selection);
|
||||
ClipboardHelper.copyUrl(url);
|
||||
});
|
||||
});
|
||||
menu.getItems().add(l);
|
||||
|
||||
@@ -16,6 +16,7 @@ import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.VBox;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@@ -108,15 +109,17 @@ public class StoreSectionComp extends Comp<CompStructure<VBox>> {
|
||||
return;
|
||||
}
|
||||
|
||||
struc.get().getStyleClass().removeIf(s -> Arrays.stream(DataStoreColor.values())
|
||||
var newList = new ArrayList<>(struc.get().getStyleClass());
|
||||
newList.removeIf(s -> Arrays.stream(DataStoreColor.values())
|
||||
.anyMatch(dataStoreColor -> dataStoreColor.getId().equals(s)));
|
||||
struc.get().getStyleClass().remove("none");
|
||||
struc.get().getStyleClass().add("color-box");
|
||||
newList.remove("none");
|
||||
newList.add("color-box");
|
||||
if (val != null) {
|
||||
struc.get().getStyleClass().add(val.getId());
|
||||
newList.add(val.getId());
|
||||
} else {
|
||||
struc.get().getStyleClass().add("none");
|
||||
newList.add("none");
|
||||
}
|
||||
struc.get().getStyleClass().setAll(newList);
|
||||
}))
|
||||
.apply(struc -> {
|
||||
struc.get().pseudoClassStateChanged(ROOT, topLevel);
|
||||
|
||||
@@ -57,7 +57,7 @@ public interface DataStoreProvider {
|
||||
}
|
||||
|
||||
default Comp<?> customEntryComp(StoreSection s, boolean preferLarge) {
|
||||
return StoreEntryComp.create(s.getWrapper(),true, null, preferLarge);
|
||||
return StoreEntryComp.create(s.getWrapper(), null, preferLarge);
|
||||
}
|
||||
|
||||
default Comp<?> customSectionComp(StoreSection section, boolean topLevel) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import io.xpipe.app.fxcomps.Comp;
|
||||
import io.xpipe.app.fxcomps.CompStructure;
|
||||
import io.xpipe.app.fxcomps.SimpleCompStructure;
|
||||
import io.xpipe.app.fxcomps.util.PlatformThread;
|
||||
import io.xpipe.app.util.ClipboardHelper;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.scene.control.Button;
|
||||
@@ -14,10 +15,6 @@ import javafx.scene.paint.Color;
|
||||
import org.fxmisc.richtext.InlineCssTextArea;
|
||||
import org.kordamp.ikonli.javafx.FontIcon;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.Clipboard;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
|
||||
public class CodeSnippetComp extends Comp<CompStructure<?>> {
|
||||
|
||||
private final ObservableValue<Boolean> showLineNumbers;
|
||||
@@ -67,9 +64,7 @@ public class CodeSnippetComp extends Comp<CompStructure<?>> {
|
||||
var button = new Button();
|
||||
button.setGraphic(new FontIcon("mdoal-content_copy"));
|
||||
button.setOnAction(e -> {
|
||||
var string = new StringSelection(value.getValue().getRawString());
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
clipboard.setContents(string, string);
|
||||
ClipboardHelper.copyText(value.getValue().getRawString());
|
||||
});
|
||||
button.getStyleClass().add("copy");
|
||||
button.getStyleClass().add("button-comp");
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package io.xpipe.app.util;
|
||||
|
||||
import io.xpipe.app.fxcomps.util.PlatformThread;
|
||||
import javafx.scene.input.Clipboard;
|
||||
import javafx.scene.input.DataFormat;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ClipboardHelper {
|
||||
|
||||
public static void copyText(String s) {
|
||||
PlatformThread.runLaterIfNeeded(() -> {
|
||||
Clipboard clipboard = Clipboard.getSystemClipboard();
|
||||
clipboard.setContent(Map.of(DataFormat.PLAIN_TEXT, s));
|
||||
});
|
||||
}
|
||||
|
||||
public static void copyUrl(String s) {
|
||||
PlatformThread.runLaterIfNeeded(() -> {
|
||||
Clipboard clipboard = Clipboard.getSystemClipboard();
|
||||
clipboard.setContent(Map.of(DataFormat.PLAIN_TEXT, s, DataFormat.URL, s));
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user