Skip to content

Commit

Permalink
more options than one should ever need for representing the files in …
Browse files Browse the repository at this point in the history
…the tree view
  • Loading branch information
seanrmilligan committed Jun 25, 2017
1 parent 3057011 commit 9697abc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
16 changes: 13 additions & 3 deletions src/main/java/com/seanrmilligan/sitebuilder/SiteBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

public class SiteBuilder extends Application {
SiteBuilderWindow gui;
File homeDir, projDir;

/**
* @param primaryStage This application's window.
Expand All @@ -38,7 +39,6 @@ public void start(Stage primaryStage) {

if (action == NEW || action == LOAD) {
DirectoryChooser chooser = new DirectoryChooser();
File homeDir, projDir;
homeDir = new File(System.getProperty("user.home"));
chooser.setInitialDirectory(homeDir);
projDir = chooser.showDialog(primaryStage);
Expand All @@ -60,13 +60,23 @@ public void start(Stage primaryStage) {
this.gui.setSiteName(site.getName());
this.gui.setSiteDomain(site.getDomain());
this.gui.setDirectoryTree(DirectoryManager.getTree(projDir));
//this.gui.setDirectoryTreePathTruncation(homeDir.getAbsolutePath(), "~");
this.gui.setDirectoryTreePathTruncation(projDir.getAbsolutePath(), projDir.getName());
this.gui.init(APPLICATION_NAME);
}
}
}

public void setPathsRelativeToHome() {
this.gui.setDirectoryTreePathTruncation(this.homeDir.getAbsolutePath(), "~");
}

public void setPathsRelativeToProject() {
this.gui.setDirectoryTreePathTruncation(projDir.getAbsolutePath(), projDir.getName());
}

public void setPathsToFileName() {

}

public static void main(String[] args) {
Locale.setDefault(Locale.US);
launch(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import java.io.File;
import java.util.HashMap;

import static com.seanrmilligan.sitebuilder.view.Strings.APPLICATION_NAME;

public class SiteBuilderWindow implements SiteView, FileView {
Stage primaryStage;
Scene scene;
Expand Down Expand Up @@ -124,6 +126,7 @@ public void init(String windowTitle) {

public void setSiteName(String name) {
this.siteName.setText(name);
this.primaryStage.setTitle(APPLICATION_NAME + " | " + name);
}

public void setSiteDomain(String domain) {
Expand All @@ -148,12 +151,24 @@ public void updateItem(File item, boolean empty) {
if (empty) {
setText(null);
} else {
if (!SiteBuilderWindow.this.pathPrefix.isEmpty() &&
getItem().getAbsolutePath().startsWith(SiteBuilderWindow.this.pathPrefix)) {
setText(getItem().getAbsolutePath().replaceFirst(
SiteBuilderWindow.this.pathPrefix,
SiteBuilderWindow.this.pathReplacement
));
if (SiteBuilderWindow.this.pathPrefix.isEmpty()) {
// default to just showing the name
setText(getItem().getName());
} else if (SiteBuilderWindow.this.pathPrefix.equals("/")) {
// show absolute path
setText(getItem().getAbsolutePath());
} else {
// do some other truncations such as
// /home/dir --> ~/
// /path/to/proj --> proj/
String absPath = getItem().getAbsolutePath();

if (absPath.startsWith(SiteBuilderWindow.this.pathPrefix)) {
setText(absPath.replaceFirst(
SiteBuilderWindow.this.pathPrefix,
SiteBuilderWindow.this.pathReplacement
));
}
}
}
}
Expand All @@ -162,6 +177,7 @@ public void updateItem(File item, boolean empty) {
cell.setOnMouseClicked(event -> {
if(event.getButton().equals(MouseButton.PRIMARY)){
if(event.getClickCount() >= 2 && !cell.isEmpty()){
System.out.println(cell.getItem().toString());
FileManager.open(SiteBuilderWindow.this, cell.getTreeItem().getValue());
}
}
Expand Down

0 comments on commit 9697abc

Please sign in to comment.