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
[WIP]Find/Replace #37
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
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
99 changes: 99 additions & 0 deletions
99
src/com/zestedesavoir/zestwriter/view/dialogs/FindDialog.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,99 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package com.zestedesavoir.zestwriter.view.dialogs; | ||
|
||
import com.sun.javafx.scene.control.skin.resources.ControlResources; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import javafx.application.Platform; | ||
import javafx.geometry.Pos; | ||
import javafx.scene.control.ButtonBar; | ||
import javafx.scene.control.ButtonType; | ||
import javafx.scene.control.Dialog; | ||
import javafx.scene.control.DialogPane; | ||
import javafx.scene.control.Label; | ||
import javafx.scene.control.TextField; | ||
import javafx.scene.layout.GridPane; | ||
import javafx.scene.layout.Priority; | ||
import javafx.scene.layout.Region; | ||
|
||
|
||
/** | ||
* | ||
* Get a Line of line/colon entry | ||
*/ | ||
public class FindDialog extends Dialog<List<Integer>>{ | ||
private final GridPane grid; | ||
private final Label label; | ||
private final TextField textField; | ||
private String searchedText; | ||
|
||
public FindDialog(String currentText){ | ||
super(); | ||
searchedText = currentText; | ||
final DialogPane dialogPane = getDialogPane(); | ||
this.setTitle("Terme à rechercher"); | ||
this.setHeaderText(null); | ||
this.setContentText("Recherchez"); | ||
// -- textfield | ||
this.textField = new TextField(""); | ||
this.textField.setMaxWidth(Double.MAX_VALUE); | ||
GridPane.setHgrow(textField, Priority.ALWAYS); | ||
GridPane.setFillWidth(textField, true); | ||
|
||
// -- label | ||
label = new Label(dialogPane.getContentText()); | ||
label.setPrefWidth(Region.USE_COMPUTED_SIZE); | ||
label.textProperty().bind(dialogPane.contentTextProperty()); | ||
|
||
|
||
this.grid = new GridPane(); | ||
this.grid.setHgap(10); | ||
this.grid.setMaxWidth(Double.MAX_VALUE); | ||
this.grid.setAlignment(Pos.CENTER_LEFT); | ||
|
||
dialogPane.contentTextProperty().addListener(o -> updateGrid()); | ||
|
||
setTitle(ControlResources.getString("Dialog.confirm.title")); | ||
dialogPane.setHeaderText(ControlResources.getString("Dialog.confirm.header")); | ||
dialogPane.getStyleClass().add("text-input-dialog"); | ||
dialogPane.getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL); | ||
|
||
updateGrid(); | ||
|
||
setResultConverter((dialogButton) -> { | ||
ButtonBar.ButtonData data = dialogButton == null ? null : dialogButton.getButtonData(); | ||
return data == ButtonBar.ButtonData.OK_DONE ? findWordsInFile() : null; | ||
}); | ||
|
||
} | ||
public String getPatern(){ | ||
return textField.getText(); | ||
} | ||
private List<Integer> findWordsInFile(){ | ||
int lineNumber = 1; | ||
List<Integer> results = new LinkedList<>(); | ||
String pattern = textField.getText().toLowerCase(); | ||
|
||
int col = searchedText.indexOf(pattern); | ||
while(col != -1){ | ||
results.add(col); | ||
col = searchedText.indexOf(pattern, col + 1); | ||
} | ||
|
||
return results; | ||
} | ||
private void updateGrid() { | ||
grid.getChildren().clear(); | ||
|
||
grid.add(label, 0, 0); | ||
grid.add(textField, 1, 0); | ||
getDialogPane().setContent(grid); | ||
|
||
Platform.runLater(() -> textField.requestFocus()); | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Je ne comprend pas bien pourquoi avoir commenté ça ? (Et s'il doit l'être, pourquoi n'est t'il pas supprimé ?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pas supprimé car WIP, mais commenté car théoriquement la CodeArea
possède déjà une font spéciale.
Le 30/03/2016 22:25, WinXaito a écrit :
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Je vois, merci de la précision.