This is an automated email from the ASF dual-hosted git repository.
hansva pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hop.git
The following commit(s) were added to refs/heads/master by this push:
new 31f51bb23e when using save as point to current file location, fixes
#3109
new fda07b1d8d Merge pull request #3151 from hansva/master
31f51bb23e is described below
commit 31f51bb23ef9500eaaf2ae63918f11b090757e2e
Author: Hans Van Akelyen <[email protected]>
AuthorDate: Wed Aug 9 11:44:07 2023 +0200
when using save as point to current file location, fixes #3109
---
.../hop/projects/xp/HopGuiFileDefaultFolder.java | 6 +++++
.../org/apache/hop/ui/core/dialog/BaseDialog.java | 28 ++++++++++++----------
.../ui/hopgui/delegates/HopGuiFileDelegate.java | 3 +++
3 files changed, 25 insertions(+), 12 deletions(-)
diff --git
a/plugins/misc/projects/src/main/java/org/apache/hop/projects/xp/HopGuiFileDefaultFolder.java
b/plugins/misc/projects/src/main/java/org/apache/hop/projects/xp/HopGuiFileDefaultFolder.java
index eaf5049e5c..024e43bebf 100644
---
a/plugins/misc/projects/src/main/java/org/apache/hop/projects/xp/HopGuiFileDefaultFolder.java
+++
b/plugins/misc/projects/src/main/java/org/apache/hop/projects/xp/HopGuiFileDefaultFolder.java
@@ -84,6 +84,12 @@ public class HopGuiFileDefaultFolder implements
IExtensionPoint<HopGuiFileDialog
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);
}
diff --git a/ui/src/main/java/org/apache/hop/ui/core/dialog/BaseDialog.java
b/ui/src/main/java/org/apache/hop/ui/core/dialog/BaseDialog.java
index e7987ac327..1da04e4e94 100644
--- a/ui/src/main/java/org/apache/hop/ui/core/dialog/BaseDialog.java
+++ b/ui/src/main/java/org/apache/hop/ui/core/dialog/BaseDialog.java
@@ -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;
@@ -63,11 +67,6 @@ import org.eclipse.swt.widgets.Listener;
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
@@ -121,7 +120,6 @@ public abstract class BaseDialog extends Dialog {
return presentFileDialog(
false, shell, null, null, null, filterExtensions, filterNames,
folderAndFile);
}
-
public static final String presentFileDialog(
boolean save,
Shell shell,
@@ -243,12 +241,6 @@ public abstract class BaseDialog extends Dialog {
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 {
@@ -261,6 +253,18 @@ public abstract class BaseDialog extends Dialog {
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) {
diff --git
a/ui/src/main/java/org/apache/hop/ui/hopgui/delegates/HopGuiFileDelegate.java
b/ui/src/main/java/org/apache/hop/ui/hopgui/delegates/HopGuiFileDelegate.java
index 95fbbefdc2..20e8410990 100644
---
a/ui/src/main/java/org/apache/hop/ui/hopgui/delegates/HopGuiFileDelegate.java
+++
b/ui/src/main/java/org/apache/hop/ui/hopgui/delegates/HopGuiFileDelegate.java
@@ -136,11 +136,14 @@ public class HopGuiFileDelegate {
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);