-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from moacirrf/ft-converter-menu-on-toolbar
Include "Export To" to Context Menu
- Loading branch information
Showing
11 changed files
with
300 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/test/java/io/github/moacirrf/netbeans/markdown/TempDirTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright (C) 2024 Moacir da Roza Flores <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package io.github.moacirrf.netbeans.markdown; | ||
|
||
import java.io.IOException; | ||
import static java.lang.System.getProperty; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import static java.nio.file.StandardOpenOption.CREATE; | ||
import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING; | ||
import org.openide.util.Exceptions; | ||
|
||
/** | ||
* | ||
* @author Moacir da Roza Flores <[email protected]> | ||
*/ | ||
public final class TempDirTest { | ||
|
||
private static final String NB_MARKDOWN_NOT_LOAD_IMAGE = "nb_markdown_not_load_image.png"; | ||
|
||
private static Path NOT_LOADED_IMAGE; | ||
|
||
public static final String TEMP_DIR_PLUGIN = getProperty("java.io.tmpdir") + "/nb_markdown_teste"; | ||
|
||
public static Path getTempDir() { | ||
Path path = Paths.get(TEMP_DIR_PLUGIN); | ||
if (!Files.exists(path)) { | ||
try { | ||
Files.createDirectory(path); | ||
} catch (IOException ex) { | ||
Exceptions.printStackTrace(ex); | ||
} | ||
createCantLoadImage(); | ||
} | ||
return path; | ||
} | ||
|
||
public static Path getCantLoadImage() { | ||
if (Files.exists(getTempDir())) { | ||
if (NOT_LOADED_IMAGE == null) { | ||
createCantLoadImage(); | ||
} | ||
} | ||
return NOT_LOADED_IMAGE; | ||
} | ||
|
||
private static void createCantLoadImage() { | ||
try (var inputStream = Icons.class.getResourceAsStream(NB_MARKDOWN_NOT_LOAD_IMAGE)) { | ||
byte[] bytes = inputStream.readAllBytes(); | ||
NOT_LOADED_IMAGE = Path.of(TEMP_DIR_PLUGIN, NB_MARKDOWN_NOT_LOAD_IMAGE); | ||
Files.write(NOT_LOADED_IMAGE, bytes, CREATE, TRUNCATE_EXISTING); | ||
} catch (IOException ex) { | ||
Exceptions.printStackTrace(ex); | ||
} | ||
} | ||
|
||
public static void removeTempDir() { | ||
clearTempFolder(getTempDir()); | ||
} | ||
|
||
private static void clearTempFolder(Path path) { | ||
try { | ||
if (Files.isDirectory(path) && Files.list(path).count() > 0) { | ||
Files.list(path).forEach(it -> clearTempFolder(it)); | ||
} | ||
path.toFile().setWritable(true); | ||
Files.deleteIfExists(path); | ||
} catch (IOException ex) { | ||
Exceptions.printStackTrace(ex); | ||
} | ||
} | ||
|
||
private TempDirTest() { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.