Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,34 @@ public class FileBrowser implements AppInstance
final DockItem tab = new DockItem(this, content);
DockPane.getActiveDockPane().addTab(tab);

if (controller != null && file != null){
if(file.isDirectory()){
controller.setRoot(file);
}
else{
controller.setRootAndHighlight(file);
}
// Initial title for the tab
if (file != null)
{
String folderName = file.getName().isEmpty() ? file.getPath() : file.getName();
tab.setLabel(app.getDisplayName() + " (" + folderName + ")");
}

tab.addClosedNotification(controller::shutdown);
// When the user navigates, update the tab name dynamically
if (controller != null)
{
controller.addRootChangeListener(newRoot -> {
if (newRoot != null)
{
String folderName = newRoot.getName().isEmpty() ? newRoot.getPath() : newRoot.getName();
tab.setLabel(app.getDisplayName() + " (" + folderName + ")");
}
});

if (file != null)
{
if (file.isDirectory())
controller.setRoot(file);
else
controller.setRootAndHighlight(file);
}

tab.addClosedNotification(controller::shutdown);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.File;
import java.net.URI;
import java.net.URL;

import org.phoebus.framework.preferences.AnnotatedPreferences;
import org.phoebus.framework.preferences.Preference;
Expand Down Expand Up @@ -45,11 +46,28 @@ public AppInstance create() {
@Override
public AppInstance create(final URI resource)
{
return createWithRoot(new File(resource));
try
{
// Remove query component since File(URI) does not accept it
URI clean = new URI(resource.getScheme(), resource.getSchemeSpecificPart(), null);
return createWithRoot(new File(clean));
}
catch (Exception ex)
{
// Fallback: try using path string
return createWithRoot(new File(resource.getPath()));
}
}


public AppInstance createWithRoot(final File directory)
{
return new FileBrowser(this, directory);
}

@Override
public URL getIconURL()
{
return FileBrowserApp.class.getResource("/icons/filebrowser.png");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import java.util.function.Consumer;

import static org.phoebus.applications.filebrowser.FileBrowser.logger;

Expand All @@ -71,6 +73,21 @@ public class FileBrowserController {
private final Menu openWith = new Menu(Messages.OpenWith, ImageCache.getImageView(PhoebusApplication.class, "/icons/fldr_obj.png"));
private final ContextMenu contextMenu = new ContextMenu();

/**
* Create a listener for changes in the selected directory
*/
private final List<Consumer<File>> root_change_listeners = new ArrayList<>();
public void addRootChangeListener(Consumer<File> listener) {
root_change_listeners.add(listener);
}

private void notifyRootChange(File newRoot) {
// Notify that the directory has changed
for (Consumer<File> listener : root_change_listeners)
listener.accept(newRoot);
}


private ExpandedCountChangeListener expandedCountChangeListener;

public FileBrowserController() {
Expand Down Expand Up @@ -461,6 +478,7 @@ public void setRoot(final File directory) {
monitor.setRoot(directory);
path.setText(directory.toString());
treeView.setRoot(new FileTreeItem(monitor, directory));
notifyRootChange(directory);
}

/**
Expand Down