Skip to content

Commit

Permalink
Added ability to search file contents in tree search
Browse files Browse the repository at this point in the history
  • Loading branch information
EasyG0ing1 committed Apr 15, 2022
1 parent 46b9515 commit 399c876
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.redmondsims</groupId>
<artifactId>GistFX</artifactId>
<version>3.4.41</version>
<version>3.4.42</version>
<name>GistFX</name>
<url>https://github.com/redmondsims/gistfx</url>

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/redmondsims/gistfx/gist/GistFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ public String getLanguage() {

public ObjectProperty<Node> getGraphicNode() {return graphicNode;}

public String getFileContents() {
return liveVersion.get();
}

/**
SQL Actions
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ public void trayIconUserColor() {
prefs.remove(LABEL.TRAY_ICON_USER_COLOR.Name());
}

public void searchFileContents() {
prefs.remove(LABEL.SEARCH_FILE_CONTENTS.Name());
}

/**
* Tree Icon SMTPServerSettings
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,8 @@ public ColorOption trayIconColorOption() {
return option;
}

public boolean searchFileContents() {
return prefs.getBoolean(LABEL.SEARCH_FILE_CONTENTS.Name(), false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public enum LABEL {
DIVIDER_EXPANDED,
ICON_BASE_SIZE,
TRAY_ICON_COLOR_OPTION,
TRAY_ICON_USER_COLOR
TRAY_ICON_USER_COLOR,
SEARCH_FILE_CONTENTS
;

public String Name(LABEL this) {
Expand Down Expand Up @@ -83,6 +84,7 @@ public String Name(LABEL this) {
case ICON_BASE_SIZE -> "GFX_DEV_Icon_Base_Size";
case TRAY_ICON_COLOR_OPTION -> "GFX_DEV_Tray_Icon_Color_Option";
case TRAY_ICON_USER_COLOR -> "GFX_DEV_Tray_Icon_User_Color";
case SEARCH_FILE_CONTENTS -> "GFX_DEV_Search_File_Contents";
};
}
else {
Expand Down Expand Up @@ -123,6 +125,7 @@ public String Name(LABEL this) {
case ICON_BASE_SIZE -> "GFX_Icon_Base_Size";
case TRAY_ICON_COLOR_OPTION -> "GFX_Tray_Icon_Color_Option";
case TRAY_ICON_USER_COLOR -> "GFX_Tray_Icon_User_Color";
case SEARCH_FILE_CONTENTS -> "GFX_Search_File_Contents";
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ public void trayIconColorOption(ColorOption option) {
prefs.put(LABEL.TRAY_ICON_COLOR_OPTION.Name(), option.Name());
}

public void searchFileContents(boolean value) {
AppSettings.clear().searchFileContents();
prefs.putBoolean(LABEL.SEARCH_FILE_CONTENTS.Name(), value);
}

public void setDefaults() {
try {prefs.clear();}catch (BackingStoreException e) {e.printStackTrace();}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class SettingsWindow {
public SettingsWindow(GistWindow gistWindow) {
this.gistWindow = gistWindow;
createForm();
double height = 325;
double height = 355;
setGuiElements();
setWideMode();
setResetOptions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public GuiElements() {
private CheckBox cbxTrayIconLogin;
private CheckBox cbxProgressColorLogin;
private CheckBox cbxRandomLoginScreen;
private CheckBox cbxSearchFileContents;
private final double choiceWidth = 100;
private final double labelWidth = 215;
private final double cBoxWidth = 217.5;
Expand All @@ -65,6 +66,7 @@ private void makeControls() {
cbxTrayIconLogin = Utility.checkBoxLabelLeft("Login");
cbxProgressColorLogin = Utility.checkBoxLabelLeft("Login");
cbxRandomLoginScreen = Utility.checkBoxLabelLeft("Random");
cbxSearchFileContents = Utility.checkBoxLabelLeft("Use File Contents In Tree Search");
progressBarColorPicker = new ColorPicker();
}

Expand All @@ -79,6 +81,7 @@ private void installTooltips() {
Tooltip.install(cbxProgressColorLogin, Action.newTooltip("Match Progress Bar Color with login screen color choice"));
Tooltip.install(cbTrayIconColor, Action.newTooltip("Any color you like ... as long as it's in the list."));
Tooltip.install(cbxRandomLoginScreen, Action.newTooltip("GistFX selects from the five options, randomly at startup"));
Tooltip.install(cbxSearchFileContents, Action.newTooltip("Includes the text in Gist files when performing a search in the tree"));
}

private void setControlProperties() {
Expand All @@ -93,6 +96,7 @@ private void setControlProperties() {
cbTrayIconColor.setValue(AppSettings.get().trayIconUserColor());
cbxProgressColorLogin.setSelected(AppSettings.get().progressColorLogin());
cbxRandomLoginScreen.setSelected(AppSettings.get().loginScreenRandom());
cbxSearchFileContents.setSelected(AppSettings.get().searchFileContents());
progressBarColorPicker.visibleProperty().bind(cbxCustomProgressColor.selectedProperty());
progressBarColorPicker.disableProperty().bind(cbxProgressColorLogin.selectedProperty());
cbxProgressColorLogin.visibleProperty().bind(cbxCustomProgressColor.selectedProperty());
Expand Down Expand Up @@ -132,6 +136,9 @@ private void setControlProperties() {
cbxTrayIcon.setMinWidth(cBoxWidth);
cbxTrayIcon.setMaxWidth(cBoxWidth);
cbxTrayIcon.setPrefWidth(cBoxWidth);
cbxSearchFileContents.setMinWidth(cBoxWidth);
cbxSearchFileContents.setMaxWidth(cBoxWidth);
cbxSearchFileContents.setPrefWidth(cBoxWidth);

switch(AppSettings.get().trayIconColorOption()) {
case DEFAULT, USER_SELECTED -> {
Expand Down Expand Up @@ -190,6 +197,9 @@ private void setControlActions() {
cbxRandomLoginScreen.setOnAction(e->{
AppSettings.set().loginScreenRandom(cbxRandomLoginScreen.isSelected());
});
cbxSearchFileContents.setOnAction(e->{
AppSettings.set().searchFileContents(cbxSearchFileContents.isSelected());
});
}

public VBox controls() {
Expand All @@ -199,7 +209,8 @@ public VBox controls() {
HBox boxToolBar = new HBox(cbxToolBar);
HBox boxTrayIcon = new HBox(10, cbxTrayIcon, cbTrayIconColor, cbxTrayIconLogin);
HBox boxCustomColor = new HBox(10, cbxCustomProgressColor, progressBarColorPicker, cbxProgressColorLogin);
VBox vbox = new VBox(13,boxTheme,boxLoginScreenColor,boxToolBar,boxDisableWarning,boxTrayIcon,boxCustomColor);
HBox boxSearchFileContents = new HBox(10, cbxSearchFileContents);
VBox vbox = new VBox(13,boxTheme,boxLoginScreenColor,boxTrayIcon,boxCustomColor,boxToolBar,boxDisableWarning,boxSearchFileContents);
vbox.setPadding(new Insets(25,10,10,20));
return vbox;
}
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/com/redmondsims/gistfx/ui/gist/Search.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.redmondsims.gistfx.enums.TreeType;
import com.redmondsims.gistfx.javafx.CStringProperty;
import com.redmondsims.gistfx.preferences.AppSettings;
import com.redmondsims.gistfx.ui.gist.factory.TreeNode;
import javafx.application.Platform;
import javafx.beans.property.StringProperty;
Expand All @@ -18,6 +19,7 @@ public class Search {
private final Map<Integer, TreeItem<TreeNode>> treeMap = new HashMap<>();
private final Map<Integer, String> wordMap = new HashMap<>();
private final LinkedList<Integer> hitList = new LinkedList<>();
private String results;

public void bindTo(StringProperty searchFieldProperty) {
searchText.bind(searchFieldProperty);
Expand Down Expand Up @@ -45,6 +47,9 @@ public void startSearch(TreeItem<TreeNode> treeRoot) {
String filename = fileNode.getValue().getName();
String fileDescription = fileNode.getValue().getFile().getDescription();
finalString = filename + " " + fileDescription;
if(AppSettings.get().searchFileContents()) {
finalString = finalString + " " + fileNode.getValue().getFile().getFileContents().replaceAll("\\n"," ");
}
index++;
treeMap.put(index,fileNode);
wordMap.put(index,finalString);
Expand Down Expand Up @@ -73,8 +78,8 @@ public void startSearch(TreeItem<TreeNode> treeRoot) {
if (line.contains(value)) {
hitList.addLast(idx);
totalHits++;
final String currentCount = "Found " + totalHits + " hits";
feedbackProperty.setValue(currentCount);
results = "Found " + totalHits + " hits";
feedbackProperty.setValue(results);
hitIndex = 0;
}
}
Expand All @@ -92,6 +97,8 @@ public TreeItem<TreeNode> getNextHit() {
if(hitList.size() > 0) {
int nodeIndex = hitList.get(hitIndex);
hitIndex++;
String feedback = results + " (" + hitIndex + ")";
feedbackProperty.setValue(feedback);
node = treeMap.get(nodeIndex);
if (hitIndex > hitList.size() - 1) {
hitIndex = 0;
Expand Down

0 comments on commit 399c876

Please sign in to comment.