You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by ne...@apache.org on 2019/10/01 09:42:13 UTC
[netbeans] branch master updated: [NETBEANS-3040] Diff to feature
does not work for Remote files in C/C++
This is an automated email from the ASF dual-hosted git repository.
neilcsmith pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push:
new 4b93558 [NETBEANS-3040] Diff to feature does not work for Remote files in C/C++
new eb073e1 Merge pull request #1536 from SiddheshRane/diff-for-remote-files
4b93558 is described below
commit 4b93558e74a90e8a410c4c9ad55165fdf2fcfe60
Author: Siddhesh Rane <ki...@gmail.com>
AuthorDate: Mon Sep 23 00:45:38 2019 +0530
[NETBEANS-3040] Diff to feature does not work for Remote files in C/C++
Diff file chooser converts editor FileObjects to java.io.File for selection.
In this process files with remote sources (rfs:/) become null.
This fix checks if selected file is not a disk file, providing alternate
means to retrieve the FileObject
This bug and fix is not related to C++ module; except that it manifests there.
---
.../src/org/netbeans/modules/diff/DiffAction.java | 6 ++++-
.../modules/diff/EditorBufferSelectorPanel.java | 31 ++++++++++++++++++++--
2 files changed, 34 insertions(+), 3 deletions(-)
diff --git a/ide/diff/src/org/netbeans/modules/diff/DiffAction.java b/ide/diff/src/org/netbeans/modules/diff/DiffAction.java
index 6a62efa..7d24274 100644
--- a/ide/diff/src/org/netbeans/modules/diff/DiffAction.java
+++ b/ide/diff/src/org/netbeans/modules/diff/DiffAction.java
@@ -48,7 +48,6 @@ import org.netbeans.modules.diff.builtin.SingleDiffPanel;
import org.netbeans.modules.diff.options.AccessibleJFileChooser;
import org.openide.DialogDisplayer;
import org.openide.ErrorManager;
-import org.openide.util.lookup.ProxyLookup;
/**
* Diff Action. It gets the default diff visualizer and diff provider if needed
@@ -183,6 +182,11 @@ public class DiffAction extends NodeAction {
int result = fileChooser.showDialog(WindowManager.getDefault().getMainWindow(), NbBundle.getMessage(DiffAction.class, "DiffTo_BrowseFile_OK")); // NOI18N
if (result != JFileChooser.APPROVE_OPTION) return null;
+ FileObject userSelectedFo = editorSelector.getSelectedEditorFile();
+ if (userSelectedFo != null) {
+ return userSelectedFo;
+ }
+
File f = fileChooser.getSelectedFile();
if (f != null) {
File file = f.getAbsoluteFile();
diff --git a/ide/diff/src/org/netbeans/modules/diff/EditorBufferSelectorPanel.java b/ide/diff/src/org/netbeans/modules/diff/EditorBufferSelectorPanel.java
index 12a5231..9f13c4e 100644
--- a/ide/diff/src/org/netbeans/modules/diff/EditorBufferSelectorPanel.java
+++ b/ide/diff/src/org/netbeans/modules/diff/EditorBufferSelectorPanel.java
@@ -33,16 +33,19 @@ import javax.swing.event.ListSelectionEvent;
import java.util.*;
import java.io.File;
import java.awt.event.MouseEvent;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
/**
*
* @author Maros Sandor
*/
-class EditorBufferSelectorPanel extends JPanel implements ListSelectionListener {
+class EditorBufferSelectorPanel extends JPanel implements ListSelectionListener, PropertyChangeListener {
private final JFileChooser fileChooser;
private final FileObject peer;
private JList elementsList;
+ private FileObject selectedEditorFile;
/** Creates new form EditorBufferSelectorPanel
* @param fileChooser*/
@@ -51,6 +54,7 @@ class EditorBufferSelectorPanel extends JPanel implements ListSelectionListener
this.peer = peer;
initComponents();
initEditorDocuments();
+ fileChooser.addPropertyChangeListener(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY, this);
}
private void initEditorDocuments() {
@@ -125,12 +129,35 @@ class EditorBufferSelectorPanel extends JPanel implements ListSelectionListener
EditorListElement element = (EditorListElement) elementsList.getSelectedValue();
if (element != null) {
File file = FileUtil.toFile(element.fileObject);
- fileChooser.setSelectedFile(file);
+ if (file != null) {
+ fileChooser.setSelectedFile(file);
+ } else {
+ /*FileObject may not be disk file but a remote file. Following line serves only to
+ enable open action on JFileChooser. The URL gets prefixed with current directory
+ and cannot be used to get FileObject from File
+ */
+ fileChooser.setSelectedFile(new File(element.fileObject.toURL().toString()));
+ }
+ selectedEditorFile = element.fileObject;
} else {
File file = new File("");
fileChooser.setSelectedFile(file);
+ selectedEditorFile = null;
}
}
+
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ //user has selected a different file from file chooser
+ selectedEditorFile = null;
+ }
+
+ /**
+ * @return FileObject of the editor tab chosen by the user
+ */
+ public final FileObject getSelectedEditorFile() {
+ return selectedEditorFile;
+ }
/** This method is called from within the constructor to
* initialize the form.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists