Skip to content

Commit

Permalink
Show full paths in tooltips
Browse files Browse the repository at this point in the history
This adjusts the code so that the full paths of items are displayed in
tooltips. This removes any possible ambiguity in the Recent Items list.

Fix: #5
  • Loading branch information
io7m committed Mar 29, 2020
1 parent cfe2dc7 commit 7b3068b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 21 deletions.
Expand Up @@ -41,7 +41,6 @@
import java.util.Objects;
import java.util.ResourceBundle;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

public final class ExampleViewController implements Initializable
Expand Down Expand Up @@ -137,15 +136,30 @@ private void onSlowIOChanged()
private void onOpenSelected()
throws IOException
{
final var fileSystem =
this.filesystems.filesystems()
.get(this.filesystem.getValue());
final var imageSet =
this.imageSets.imageSets()
.get(this.imageSetSelection.getValue());

final var recents =
List.of(
fileSystem.getPath("A", "B", "C"),
fileSystem.getPath("D", "E", "F"),
fileSystem.getPath("G", "H", "I")
);

final var configuration =
JWFileChooserConfiguration.builder()
.setAllowDirectoryCreation(this.allowDirectoryCreation.isSelected())
.setFileSystem(this.filesystems.filesystems().get(this.filesystem.getValue()))
.setFileSystem(fileSystem)
.setCssStylesheet(ExampleViewController.class.getResource(this.cssSelection.getValue()))
.setFileImageSet(this.imageSets.imageSets().get(this.imageSetSelection.getValue()))
.setFileImageSet(imageSet)
.setAction(this.action.getValue())
.addFileFilters(new ExampleFilterRejectAll())
.addFileFilters(new ExampleFilterXML())
.addAllRecentFiles(recents)
.build();

final var testingBuilder = JWFileChoosersTesting.builder();
Expand Down
Expand Up @@ -586,8 +586,8 @@ private void configureTableView()
this.directoryTable.setPlaceholder(new Label(""));

final var tableColumns = this.directoryTable.getColumns();
final TableColumn<JWFileItem, JWFileKind> tableTypeColumn =
(TableColumn<JWFileItem, JWFileKind>) tableColumns.get(0);
final TableColumn<JWFileItem, JWFileItem> tableTypeColumn =
(TableColumn<JWFileItem, JWFileItem>) tableColumns.get(0);
final TableColumn<JWFileItem, JWFileItem> tableNameColumn =
(TableColumn<JWFileItem, JWFileItem>) tableColumns.get(1);
final TableColumn<JWFileItem, Long> tableSizeColumn =
Expand All @@ -598,11 +598,11 @@ private void configureTableView()
tableTypeColumn.setSortable(false);
tableTypeColumn.setReorderable(false);
tableTypeColumn.setCellFactory(column -> {
final TableCell<JWFileItem, JWFileKind> cell = new TableCell<>()
final TableCell<JWFileItem, JWFileItem> cell = new TableCell<>()
{
@Override
protected void updateItem(
final JWFileKind item,
final JWFileItem item,
final boolean empty)
{
super.updateItem(item, empty);
Expand All @@ -614,9 +614,11 @@ protected void updateItem(
return;
}

this.setGraphic(JWFileChooserViewController.this.imageOfKind(item));
this.setGraphic(
JWFileChooserViewController.this.imageOfKind(item.kind()));
this.setText(null);
this.setTooltip(JWFileChooserViewController.this.tooltipOf(item));
this.setTooltip(
JWFileChooserViewController.this.tooltipOf(item));
}
};

Expand Down Expand Up @@ -645,7 +647,7 @@ protected void updateItem(

this.setGraphic(null);
this.setText(item.name());
this.setTooltip(JWFileChooserViewController.this.tooltipOf(item.kind()));
this.setTooltip(JWFileChooserViewController.this.tooltipOf(item));
}
};
cell.setOnMouseClicked(this::onTableRowClicked);
Expand Down Expand Up @@ -705,7 +707,7 @@ protected void updateItem(
});

tableTypeColumn.setCellValueFactory(
param -> new ReadOnlyObjectWrapper<>(param.getValue().kind()));
param -> new ReadOnlyObjectWrapper<>(param.getValue()));
tableNameColumn.setCellValueFactory(
param -> new ReadOnlyObjectWrapper<>(param.getValue()));
tableSizeColumn.setCellValueFactory(
Expand All @@ -715,15 +717,21 @@ protected void updateItem(
}

private Tooltip tooltipOf(
final JWFileKind kind)
final JWFileItem item)
{
switch (kind) {
switch (item.kind()) {
case REGULAR_FILE:
case SYMBOLIC_LINK:
case UNKNOWN:
return null;
return new Tooltip(
this.choosers.strings()
.tooltipFile(item.path())
);
case DIRECTORY:
return new Tooltip(this.choosers.strings().tooltipNavigateDirectory());
return new Tooltip(
this.choosers.strings()
.tooltipDirectory(item.path())
);
}
throw new UnreachableCodeException();
}
Expand Down
Expand Up @@ -16,6 +16,8 @@

package com.io7m.jwheatsheaf.ui;

import java.nio.file.Path;
import java.text.MessageFormat;
import java.util.Locale;
import java.util.ResourceBundle;

Expand Down Expand Up @@ -74,6 +76,13 @@ public static JWStrings of(
return new JWStrings(bundle);
}

private String format(
final String idId,
final Object... inArgs)
{
return MessageFormat.format(this.resourceBundle.getString(idId), inArgs);
}

public String createDirectoryTitle()
{
return this.resourceBundle.getString("ui.directoryCreateTitle");
Expand All @@ -99,11 +108,6 @@ public String enterDirectoryName()
return this.resourceBundle.getString("ui.directoryName");
}

public String tooltipNavigateDirectory()
{
return this.resourceBundle.getString("ui.tooltip.directory");
}

public String fileSelect()
{
return this.resourceBundle.getString("ui.fileSelect");
Expand Down Expand Up @@ -133,4 +137,14 @@ public String enterPath()
{
return this.resourceBundle.getString("ui.enterPath");
}

public String tooltipDirectory(final Path path)
{
return this.format("ui.tooltip.directory", path.toAbsolutePath());
}

public String tooltipFile(final Path path)
{
return this.format("ui.tooltip.file", path.toAbsolutePath());
}
}
Expand Up @@ -32,7 +32,8 @@ ui.open=Open
ui.recentItems=Recent items
ui.save=Save
ui.search=Search…
ui.tooltip.directory=Double-click to navigate into this directory.
ui.tooltip.file=Click to select this file ({0})
ui.tooltip.directory=Double-click to navigate into this directory ({0})
ui.tooltip.directoryCreate=Create a new directory…
ui.tooltip.enterDirectly=Enter a full file path directly…
ui.tooltip.goParentDirectory=Go to parent directory
Expand Down

0 comments on commit 7b3068b

Please sign in to comment.