-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
150 additions
and
25 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
app/src/main/java/io/xpipe/app/browser/FileFilterComp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package io.xpipe.app.browser; | ||
|
||
import atlantafx.base.theme.Styles; | ||
import io.xpipe.app.fxcomps.SimpleComp; | ||
import io.xpipe.app.fxcomps.SimpleCompStructure; | ||
import io.xpipe.app.fxcomps.augment.GrowAugment; | ||
import io.xpipe.app.fxcomps.impl.TextFieldComp; | ||
import io.xpipe.app.fxcomps.util.Shortcuts; | ||
import io.xpipe.app.fxcomps.util.SimpleChangeListener; | ||
import javafx.beans.property.Property; | ||
import javafx.beans.property.SimpleBooleanProperty; | ||
import javafx.scene.control.Button; | ||
import javafx.scene.input.KeyCode; | ||
import javafx.scene.input.KeyCodeCombination; | ||
import javafx.scene.input.KeyCombination; | ||
import javafx.scene.layout.HBox; | ||
import javafx.scene.layout.Region; | ||
import org.kordamp.ikonli.javafx.FontIcon; | ||
|
||
public class FileFilterComp extends SimpleComp { | ||
|
||
private final Property<String> filterString; | ||
|
||
public FileFilterComp(Property<String> filterString) { | ||
this.filterString = filterString; | ||
} | ||
|
||
@Override | ||
protected Region createSimple() { | ||
var expanded = new SimpleBooleanProperty(); | ||
var text = new TextFieldComp(filterString, false).createRegion(); | ||
text.focusedProperty().addListener((observable, oldValue, newValue) -> { | ||
if (!newValue && filterString.getValue() == null) { | ||
expanded.set(false); | ||
return; | ||
} | ||
|
||
if (newValue) { | ||
expanded.set(true); | ||
} | ||
}); | ||
filterString.addListener((observable, oldValue, newValue) -> { | ||
if (newValue == null && !text.isFocused()) { | ||
expanded.set(false); | ||
} | ||
}); | ||
text.setMinWidth(0); | ||
Styles.toggleStyleClass(text, Styles.LEFT_PILL); | ||
|
||
SimpleChangeListener.apply(filterString, val -> { | ||
if (val == null) { | ||
text.getStyleClass().remove(Styles.SUCCESS); | ||
} else { | ||
text.getStyleClass().add(Styles.SUCCESS); | ||
} | ||
}); | ||
|
||
var fi = new FontIcon("mdi2m-magnify"); | ||
var button = new Button(); | ||
GrowAugment.create(false, true).augment(new SimpleCompStructure<>(button)); | ||
Shortcuts.addShortcut(button, new KeyCodeCombination(KeyCode.F, KeyCombination.SHORTCUT_DOWN)); | ||
button.setGraphic(fi); | ||
button.setOnAction(event -> { | ||
if (expanded.get() && filterString.getValue() == null) { | ||
expanded.set(false); | ||
return; | ||
} | ||
|
||
text.requestFocus(); | ||
event.consume(); | ||
}); | ||
|
||
SimpleChangeListener.apply(expanded, val -> { | ||
if (val) { | ||
text.setPrefWidth(250); | ||
button.getStyleClass().add(Styles.RIGHT_PILL); | ||
button.getStyleClass().remove(Styles.FLAT); | ||
} else { | ||
text.setPrefWidth(0); | ||
button.getStyleClass().remove(Styles.RIGHT_PILL); | ||
button.getStyleClass().add(Styles.FLAT); | ||
} | ||
}); | ||
|
||
var box = new HBox(text, button); | ||
box.setFillHeight(true); | ||
return box; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters