Skip to content
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

when using save as point to current file location, fixes #3109 #3151

Merged
merged 1 commit into from
Aug 9, 2023
Merged
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 @@ -84,6 +84,12 @@ public void callExtensionPoint(
filterPath = projectConfig.getProjectHome();
}

//maybe we should clean this up and in the audit split folder and filename
//check if path ends with slash else remove filename
int dotFound = filterPath.lastIndexOf(".");
int slashFound = filterPath.lastIndexOf("/");
filterPath = dotFound > slashFound && slashFound > 0 ? filterPath.substring(0,slashFound) : filterPath;

IFileDialog dialog = ext.getFileDialog();
dialog.setFilterPath(filterPath);
}
Expand Down
28 changes: 16 additions & 12 deletions ui/src/main/java/org/apache/hop/ui/core/dialog/BaseDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

package org.apache.hop.ui.core.dialog;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.vfs2.FileObject;
Expand Down Expand Up @@ -63,11 +67,6 @@
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;

/** A base dialog class containing a body and a configurable button panel. */
public abstract class BaseDialog extends Dialog {
private static final Class<?> PKG = BaseDialog.class; // For Translator
Expand Down Expand Up @@ -121,7 +120,6 @@ public static final String presentFileDialog(
return presentFileDialog(
false, shell, null, null, null, filterExtensions, filterNames, folderAndFile);
}

public static final String presentFileDialog(
boolean save,
Shell shell,
Expand Down Expand Up @@ -243,12 +241,6 @@ public static final String presentFileDialog(
dialog.setFilterExtensions(filterExtensions);
dialog.setFilterNames(filterNames);
}
if (fileObject != null) {
dialog.setFileName(HopVfs.getFilename(fileObject));
}
if (variables != null && textVar != null && textVar.getText() != null) {
dialog.setFileName(variables.resolve(textVar.getText()));
}

AtomicBoolean doIt = new AtomicBoolean(true);
try {
Expand All @@ -261,6 +253,18 @@ public static final String presentFileDialog(
LogChannel.UI.logError("Error handling extension point 'HopGuiFileOpenDialog'", xe);
}

if (fileObject != null) {
dialog.setFileName(HopVfs.getFilename(fileObject));
try {
dialog.setFilterPath(HopVfs.getFilename(fileObject.getParent()));
} catch (FileSystemException fse) {
// This wasn't a valid filename, ignore the error to reduce spamming
}
}
if (variables != null && textVar != null && textVar.getText() != null) {
dialog.setFileName(variables.resolve(textVar.getText()));
}

String filename = null;
if (!doIt.get() || dialog.open() != null) {
if (folderAndFile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,14 @@ public String fileSaveAs() {
if (!fileType.hasCapability(IHopFileType.CAPABILITY_SAVE_AS)) {
return null;
}
FileObject file = HopVfs.getFileObject(typeHandler.getFilename());

String filename =
BaseDialog.presentFileDialog(
true,
hopGui.getShell(),
null,
file,
fileType.getFilterExtensions(),
fileType.getFilterNames(),
true);
Expand Down
Loading