diff --git a/mind-map/mind-map-model/src/main/java/com/igormaznitsa/mindmap/model/MMapURI.java b/mind-map/mind-map-model/src/main/java/com/igormaznitsa/mindmap/model/MMapURI.java index 7e147a791..f1b598805 100644 --- a/mind-map/mind-map-model/src/main/java/com/igormaznitsa/mindmap/model/MMapURI.java +++ b/mind-map/mind-map-model/src/main/java/com/igormaznitsa/mindmap/model/MMapURI.java @@ -63,7 +63,9 @@ public MMapURI(final URI uri) { this.parameters = ModelUtils.extractQueryPropertiesFromURI(uri); if (this.fileUriFlag) { try { - preparedURI = new URI(uri.getScheme(), null, extractHost(uri), -1, uri.getPath(), null, null); + final String uriAsString = uri.toString(); + final int queryStart = uriAsString.lastIndexOf('?'); + preparedURI = new URI(queryStart >= 0 ? uriAsString.substring(0,queryStart) : uriAsString); } catch (URISyntaxException ex) { throw new Error("Unexpected error", ex); diff --git a/mind-map/mind-map-model/src/test/java/com/igormaznitsa/mindmap/model/MMapURITest.java b/mind-map/mind-map-model/src/test/java/com/igormaznitsa/mindmap/model/MMapURITest.java index 81e0832cd..db709ad22 100644 --- a/mind-map/mind-map-model/src/test/java/com/igormaznitsa/mindmap/model/MMapURITest.java +++ b/mind-map/mind-map-model/src/test/java/com/igormaznitsa/mindmap/model/MMapURITest.java @@ -74,7 +74,7 @@ public void testCreate_Str() throws Exception { } @Test - public void testCreate_Linux_Uri() throws Exception { + public void testCreate_Linux_Uri_NoProps() throws Exception { if (SystemUtils.IS_OS_LINUX) { MMapURI uri = new MMapURI(new URI("file:///K%C3%B5ik/v%C3%B5i/mitte/midagi.txt")); assertEquals("file:///K%C3%B5ik/v%C3%B5i/mitte/midagi.txt", uri.asString(false, false)); @@ -95,7 +95,29 @@ public void testCreate_Linux_Uri() throws Exception { } @Test - public void testCreate_Windows_Uri() throws Exception { + public void testCreate_Linux_Uri_Props() throws Exception { + if (SystemUtils.IS_OS_LINUX) { + MMapURI uri = new MMapURI(new URI("file:///K%C3%B5ik/v%C3%B5i/mitte/midagi.txt?one=two")); + assertEquals("two",uri.getParameters().getProperty("one")); + assertEquals("file:///K%C3%B5ik/v%C3%B5i/mitte/midagi.txt?one=two", uri.asString(false, true)); + assertEquals(new File("/Kõik/või/mitte/midagi.txt"), uri.asFile(null)); + assertTrue(uri.isAbsolute()); + assertFalse(uri.getParameters().isEmpty()); + + uri = new MMapURI(new URI("/some/test")); + assertEquals("/some/test", uri.asString(false, false)); + assertFalse(uri.isAbsolute()); + assertTrue(uri.getParameters().isEmpty()); + + uri = new MMapURI(new URI("/some/test?hello=1234")); + assertEquals("/some/test?hello=1234", uri.asString(false, true)); + assertFalse(uri.isAbsolute()); + assertEquals(1, uri.getParameters().size()); + } + } + + @Test + public void testCreate_Windows_Uri_NoProps() throws Exception { if (SystemUtils.IS_OS_WINDOWS) { MMapURI uri = new MMapURI(new URI("file://C:/K%C3%B5ik/v%C3%B5i/mitte/midagi.txt")); assertEquals("file://C:/K%C3%B5ik/v%C3%B5i/mitte/midagi.txt", uri.asString(false, false)); @@ -115,6 +137,28 @@ public void testCreate_Windows_Uri() throws Exception { } } + @Test + public void testCreate_Windows_Uri_Props() throws Exception { + if (SystemUtils.IS_OS_WINDOWS) { + MMapURI uri = new MMapURI(new URI("file://C:/K%C3%B5ik/v%C3%B5i/mitte/midagi.txt?one=two")); + assertEquals("file://C:/K%C3%B5ik/v%C3%B5i/mitte/midagi.txt?one=two", uri.asString(false, true)); + assertEquals(new File("C:\\Kõik\\või\\mitte\\midagi.txt"), uri.asFile(null)); + assertTrue(uri.isAbsolute()); + assertFalse(uri.getParameters().isEmpty()); + assertEquals("two",uri.getParameters().getProperty("one")); + + uri = new MMapURI(new URI("/some/test")); + assertEquals("/some/test", uri.asString(false, false)); + assertFalse(uri.isAbsolute()); + assertTrue(uri.getParameters().isEmpty()); + + uri = new MMapURI(new URI("/some/test?hello=1234")); + assertEquals("/some/test?hello=1234", uri.asString(false, true)); + assertFalse(uri.isAbsolute()); + assertEquals(1, uri.getParameters().size()); + } + } + @Test public void testCreate_AbsFile_Linux_NoBase_NoProps() throws Exception { if (SystemUtils.IS_OS_LINUX) { diff --git a/mind-map/nb-mind-map/src/main/java/com/igormaznitsa/nbmindmap/nb/editor/MMDGraphEditor.java b/mind-map/nb-mind-map/src/main/java/com/igormaznitsa/nbmindmap/nb/editor/MMDGraphEditor.java index 052a44c4c..e10f5ece6 100644 --- a/mind-map/nb-mind-map/src/main/java/com/igormaznitsa/nbmindmap/nb/editor/MMDGraphEditor.java +++ b/mind-map/nb-mind-map/src/main/java/com/igormaznitsa/nbmindmap/nb/editor/MMDGraphEditor.java @@ -380,7 +380,7 @@ public void onClickOnExtra(final MindMapPanel source, final int clicks, final To if (fileObj == null) { logger.warn("Can't find FileObject for " + theFile); if (theFile.exists()) { - NbUtils.openInExternalEditor(theFile); + NbUtils.openInSystemViewer(theFile); } else { NbUtils.msgError(String.format(BUNDLE.getString("MMDGraphEditor.onClickExtra.errorCanfFindFile"), theFile.getAbsolutePath())); @@ -396,11 +396,13 @@ public void onClickOnExtra(final MindMapPanel source, final int clicks, final To try { if (Boolean.parseBoolean(uri.getParameters().getProperty(FILELINK_ATTR_OPEN_IN_SYSTEM, "false"))) { //NOI18N - NbUtils.openInExternalEditor(theFile); + NbUtils.openInSystemViewer(theFile); } else { + Project projectOwner = null; if (fileObj.isFolder()) { - if (FileOwnerQuery.getOwner(fileObj) != null) { + projectOwner = FileOwnerQuery.getOwner(fileObj); + if (projectOwner != null) { final DataObject dataObj = DataObject.find(fileObj); if (dataObj instanceof DataFolder) { final ProjectManager manager = ProjectManager.getDefault(); @@ -420,23 +422,29 @@ public void onClickOnExtra(final MindMapPanel source, final int clicks, final To } final ProjectManager manager = ProjectManager.getDefault(); + final OpenProjects openManager = OpenProjects.getDefault(); if (manager.isProject(fileObj)) { final Project project = manager.findProject(fileObj); if (project == null) { if (!NbUtils.SelectIn.FAVORITES.select(this, fileObj)) { - NbUtils.openInExternalEditor(theFile); + NbUtils.openInSystemViewer(theFile); } } else { - final OpenProjects openManager = OpenProjects.getDefault(); if (!openManager.isProjectOpen(project)) { openManager.open(new Project[]{project}, false, true); } } } else { + if (projectOwner!=null){ + openManager.open(new Project[]{projectOwner}, false); + if (!NbUtils.SelectIn.PROJECTS.select(this, fileObj)) { + NbUtils.openInSystemViewer(theFile); + } + }else if (!NbUtils.SelectIn.FAVORITES.select(this, fileObj)) { - NbUtils.openInExternalEditor(theFile); + NbUtils.openInSystemViewer(theFile); } } } @@ -446,6 +454,7 @@ public void onClickOnExtra(final MindMapPanel source, final int clicks, final To if (openable != null) { openable.open(); } + NbUtils.SelectIn.PROJECTS.select(this, fileObj); } } } @@ -598,7 +607,7 @@ else if (Project.class.isAssignableFrom(representation)) { } } - DataObject dataObject = null; + DataObject dataObject; if (nodeObjectFlavor != null) { try { diff --git a/mind-map/nb-mind-map/src/main/java/com/igormaznitsa/nbmindmap/nb/swing/FileEditPanel.java b/mind-map/nb-mind-map/src/main/java/com/igormaznitsa/nbmindmap/nb/swing/FileEditPanel.java index 1a996e621..a8202bb31 100644 --- a/mind-map/nb-mind-map/src/main/java/com/igormaznitsa/nbmindmap/nb/swing/FileEditPanel.java +++ b/mind-map/nb-mind-map/src/main/java/com/igormaznitsa/nbmindmap/nb/swing/FileEditPanel.java @@ -139,7 +139,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { private void labelBrowseCurrentLinkMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_labelBrowseCurrentLinkMouseClicked if (evt.getClickCount() > 1) { final File file = new File(this.textFieldFilePath.getText().trim()); - NbUtils.openInExternalEditor(file); + NbUtils.openInSystemViewer(file); } }//GEN-LAST:event_labelBrowseCurrentLinkMouseClicked diff --git a/mind-map/nb-mind-map/src/main/java/com/igormaznitsa/nbmindmap/utils/NbUtils.java b/mind-map/nb-mind-map/src/main/java/com/igormaznitsa/nbmindmap/utils/NbUtils.java index a3595f63b..45b4ec3fc 100644 --- a/mind-map/nb-mind-map/src/main/java/com/igormaznitsa/nbmindmap/utils/NbUtils.java +++ b/mind-map/nb-mind-map/src/main/java/com/igormaznitsa/nbmindmap/utils/NbUtils.java @@ -343,29 +343,20 @@ public static boolean browseURI(final URI uri, final boolean preferInsideBrowser } } - public static void openInExternalEditor(final File file) { + public static void openInSystemViewer(final File file) { final Runnable startEdit = new Runnable() { @Override public void run() { boolean ok = false; if (Desktop.isDesktopSupported()) { final Desktop dsk = Desktop.getDesktop(); - if (dsk.isSupported(Desktop.Action.EDIT)) { - try { - dsk.edit(file); - ok = true; - } - catch (Throwable ex) { - logger.error("Can't start file edit: " + file, ex); - } - } - if (!ok && dsk.isSupported(Desktop.Action.OPEN)) { + if (dsk.isSupported(Desktop.Action.OPEN)) { try { dsk.open(file); ok = true; } catch (Throwable ex) { - logger.error("Can't start file open: " + file, ex); + logger.error("Can't open file in system viewer : " + file, ex);//NOI18N } } } @@ -373,14 +364,21 @@ public void run() { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - NbUtils.msgError("Can't open file to edit! See the log!"); + NbUtils.msgError("Can't open file in system viewer! See the log!");//NOI18N Toolkit.getDefaultToolkit().beep(); } }); } } }; - final Thread thr = new Thread(startEdit, " MMDStartFileEdit"); + final Thread thr = new Thread(startEdit, " MMDStartFileEdit");//NOI18N + thr.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(final Thread t, final Throwable e) { + logger.error("Detected uncaught exception in openInSystemViewer() for file " + file, e); + } + }); + thr.setDaemon(true); thr.start(); }