GP-2894 - Icon Cleanup - Moved icons from Generic into Gui; Deleted

shared icons not in the Help module
This commit is contained in:
dragonmacher 2022-12-12 13:39:30 -05:00
parent b22062999a
commit e3aad672ce
399 changed files with 1268 additions and 2863 deletions

View file

@ -53,7 +53,7 @@ import utilities.util.FileUtilities;
*/
public class GHelpHTMLEditorKit extends HTMLEditorKit {
private static final String G_HELP_STYLE_SHEET = "Frontpage.css";
private static final String G_HELP_STYLE_SHEET = "DefaultStyle.css";
private static final String DARK_G_HELP_STYLE_SHEET = "DarkStyle.css";
private static final Pattern EXTERNAL_URL_PATTERN = Pattern.compile("https?://.*");

View file

@ -18,14 +18,16 @@ package help;
import java.io.*;
import java.net.*;
import java.nio.file.*;
import java.text.MessageFormat;
import java.util.Collection;
import java.util.Collections;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import generic.jar.ResourceFile;
import generic.theme.GIcon;
import generic.theme.Gui;
import ghidra.framework.Application;
import ghidra.util.HelpLocation;
import help.validator.location.*;
import resources.IconProvider;
import resources.Icons;
@ -34,26 +36,25 @@ public class HelpBuildUtils {
private static final String HELP_TOPICS_ROOT_PATH = "help/topics";
// Great. You've just summoned Cthulu.
private static final Pattern HREF_PATTERN =
Pattern.compile("\"(\\.\\./[^/.]+/[^/.]+\\.html*(#[^\"]+)*)\"", Pattern.CASE_INSENSITIVE);
private static final Pattern STYLE_SHEET_PATTERN = Pattern.compile(
"<link\\s+rel.+stylesheet.+href=\"*(.+(Frontpage.css))\"*.+>", Pattern.CASE_INSENSITIVE);
private static final Pattern STYLE_CLASS_PATTERN =
Pattern.compile("class\\s*=\\s*\"(\\w+)\"", Pattern.CASE_INSENSITIVE);
private static final String STYLE_SHEET_FORMAT_STRING =
"<link rel=\"stylesheet\" type=\"text/css\" href=\"{0}{1}{2}\">";
private static final String SHARED_DIRECTORY = "shared/";
public static boolean debug = true;
private HelpBuildUtils() {
// utils class; can't create
}
public static Path getSharedHelpDirectory() {
ResourceFile appRootDir = Application.getApplicationRootDirectory();
ResourceFile sharedHelpDir =
new ResourceFile(appRootDir, "Framework/Help/src/main/resources/help/shared/");
return Paths.get(sharedHelpDir.getAbsolutePath());
}
public static HelpModuleLocation toLocation(File file) {
if (file.isDirectory()) {
return new DirectoryHelpModuleLocation(file);
@ -94,6 +95,14 @@ public class HelpBuildUtils {
return null;
}
/**
* Returns a path object using the given source file path as the source of the given relative
* path. The returned path represents a local file on the file system.
*
* @param srcFile the source file path
* @param relativePath the relative path
* @return a path or null if the resolved path is not a local file
*/
public static Path getFile(Path srcFile, String relativePath) {
if (relativePath == null || relativePath.isEmpty()) {
return null;
@ -111,6 +120,13 @@ public class HelpBuildUtils {
return null; // not sure why this is here
}
if (relativePath.startsWith(HelpLocation.HELP_SHARED)) {
// special syntax that tells the help system to look in the shared directory
String updatedRelativePath = relativePath.substring(HelpLocation.HELP_SHARED.length());
Path sharedDir = getSharedHelpDirectory();
return sharedDir.resolve(updatedRelativePath);
}
Path parent = srcFile.getParent();
return parent.resolve(relativePath);
}
@ -160,15 +176,6 @@ public class HelpBuildUtils {
fileContents = newContents;
}
String styleSheetFixupContents = fixStyleSheetLinkInFile(helpFile, fileContents);
if (styleSheetFixupContents != null) {
// a fixup has taken place
newContents = styleSheetFixupContents;
// replace the input to future processing so we don't lose changes
fileContents = newContents;
}
String styleSheetClassFixupContents = fixStyleSheetClassNames(helpFile, fileContents);
if (styleSheetClassFixupContents != null) {
newContents = styleSheetClassFixupContents;
@ -181,56 +188,6 @@ public class HelpBuildUtils {
writeFileContents(helpFile, newContents);
}
private static String fixStyleSheetLinkInFile(Path helpFile, String fileContents) {
int currentPosition = 0;
StringBuffer newContents = new StringBuffer();
Matcher matcher = STYLE_SHEET_PATTERN.matcher(fileContents);
boolean hasMatches = matcher.find();
if (!hasMatches) {
return null; // no work to do
}
// only care about the first hit, if there are multiple matches
// Groups:
// 0 - full match
// 1 - href text with relative notation "../.."
// 2 - href text without relative prefix
int matchStart = matcher.start();
String fullMatch = matcher.group(0);
String beforeMatchString = fileContents.substring(currentPosition, matchStart);
newContents.append(beforeMatchString);
currentPosition = matchStart + fullMatch.length();
String fullHREFText = matcher.group(1);
if (fullHREFText.indexOf(SHARED_DIRECTORY) != -1) {
return null; // already fixed; nothing to do
}
debug("Found stylesheet reference text: " + fullHREFText + " in file: " +
helpFile.getFileName());
// pull off the relative path structure
String filenameOnlyHREFText = matcher.group(2);
int filenameStart = fullHREFText.indexOf(filenameOnlyHREFText);
String reltativePrefix = fullHREFText.substring(0, filenameStart);
String updatedStyleSheetTag = MessageFormat.format(STYLE_SHEET_FORMAT_STRING,
reltativePrefix, SHARED_DIRECTORY, filenameOnlyHREFText);
debug("\tnew link tag: " + updatedStyleSheetTag);
newContents.append(updatedStyleSheetTag);
// grab the remaining content
if (currentPosition < fileContents.length()) {
newContents.append(fileContents.substring(currentPosition));
}
return newContents.toString();
}
private static String fixStyleSheetClassNames(Path helpFile, String fileContents) {
int currentPosition = 0;

View file

@ -22,6 +22,7 @@ import java.util.Map.Entry;
import generic.jar.ResourceFile;
import ghidra.framework.Application;
import ghidra.util.HelpLocation;
import help.HelpBuildUtils;
import help.validator.links.*;
import help.validator.location.HelpModuleCollection;
@ -176,40 +177,13 @@ public class JavaHelpValidator {
private Path findPathInModules(IMG img) {
String src = img.getSrcAttribute();
// TODO upcoming 'shared' unification
// if (src.startsWith(HelpLocation.HELP_IMAGES)) {
if (src.startsWith("../../shared/")) {
if (src.startsWith(HelpLocation.HELP_SHARED)) {
// this prefix is a signal to look for images in a special directory inside of the
// modules instead of help
String imagePath = "help/" + src.substring("../../".length());
ResourceFile myModule = Application.getMyModuleRootDirectory();
ResourceFile resourceDir = new ResourceFile(myModule, "src/main/resources");
Path toCheck = makePath(resourceDir, imagePath);
if (toCheck != null) {
return toCheck;
}
// now try removing the 'shared' portion altogether
imagePath = "images/" + src.substring("../../shared/".length());
Path path = doFindPathInModules(imagePath);
if (path != null) {
return path;
}
// TODO upcoming 'shared' unification
// Path path = doFindPathInModules(imagePath);
// if (path != null) {
// return path;
// }
}
// TODO upcoming 'shared' unification - fix the few of these that are left-over in the html
if (src.startsWith("../images/")) {
String imagePath = src.substring("../".length());
Path toCheck = doFindPathInModules(imagePath);
Path toCheck = makePath(resourceDir, src);
if (toCheck != null) {
return toCheck;
}

View file

@ -17,7 +17,8 @@ package help.validator;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import ghidra.util.exception.AssertException;
@ -29,8 +30,7 @@ import help.validator.model.IMG;
public class ReferenceTagProcessor extends TagProcessor {
private static final String EOL = System.getProperty("line.separator");
private static final String STYLESHEET_FILENAME = "Frontpage.css";
private static final String STYLESHEET_PATHNAME = "shared/" + STYLESHEET_FILENAME;
private static final String STYLESHEET_FILENAME = "DefaultStyle.css";
private Path htmlFile;
private Set<Path> styleSheets = new HashSet<>();
@ -47,17 +47,10 @@ public class ReferenceTagProcessor extends TagProcessor {
this.help = help;
this.anchorManager = anchorManager;
//
// Note: currently all help being built has the required stylesheet living under
// <help dir>/shared/<stylesheet name>
//
// If we ever need a more robust styling mechanism, then this code would need to be
// updated to know how to search for the referenced stylesheet
Path helpPath = help.getHelpLocation();
FileSystem fs = helpPath.getFileSystem();
Path relativeSSPath = fs.getPath(STYLESHEET_PATHNAME);
defaultStyleSheet = helpPath.resolve(relativeSSPath);
if (Files.notExists(helpPath)) {
Path sharedHelpDir = HelpBuildUtils.getSharedHelpDirectory();
defaultStyleSheet = sharedHelpDir.resolve(Path.of(STYLESHEET_FILENAME));
if (Files.notExists(defaultStyleSheet)) {
throw new AssertException("Cannot find expected stylesheet: " + defaultStyleSheet);
}
}

View file

@ -1,64 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
WARNING!
This file is copied to all help directories. If you change this file, you must copy it
to each src/main/help/help/shared directory.
Java Help Note: JavaHelp does not accept sizes (like in 'margin-top') in anything but
px (pixel) or with no type marking.
*/
body { margin-bottom: 50px; margin-left: 10px; margin-right: 10px; margin-top: 10px; } /* some padding to improve readability */
li { font-family:times new roman; font-size:14pt; }
h1 { color:#000080; font-family:times new roman; font-size:36pt; font-style:italic; font-weight:bold; text-align:center; }
h2 { margin: 10px; margin-top: 20px; color:#984c4c; font-family:times new roman; font-size:18pt; font-weight:bold; }
h3 { margin-left: 10px; margin-top: 20px; color:#0000ff; font-family:times new roman; font-size:14pt; font-weight:bold; }
h4 { margin-left: 10px; margin-top: 20px; font-family:times new roman; font-size:14pt; font-style:italic; }
/*
P tag code. Most of the help files nest P tags inside of blockquote tags (the was the
way it had been done in the beginning). The net effect is that the text is indented. In
modern HTML we would use CSS to do this. We need to support the Ghidra P tags, nested in
blockquote tags, as well as naked P tags. The following two lines accomplish this. Note
that the 'blockquote p' definition will inherit from the first 'p' definition.
*/
p { margin-left: 40px; font-family:times new roman; font-size:14pt; }
blockquote p { margin-left: 10px; }
p.providedbyplugin { color:#7f7f7f; margin-left: 10px; font-size:14pt; margin-top:100px }
p.ProvidedByPlugin { color:#7f7f7f; margin-left: 10px; font-size:14pt; margin-top:100px }
p.relatedtopic { color:#800080; margin-left: 10px; font-size:14pt; }
p.RelatedTopic { color:#800080; margin-left: 10px; font-size:14pt; }
/*
We wish for a tables to have space between it and the preceding element, so that text
is not too close to the top of the table. Also, nest the table a bit so that it is clear
the table relates to the preceding text.
*/
table { margin-left: 20px; margin-top: 10px; width: 80%;}
td { font-family:times new roman; font-size:14pt; vertical-align: top; }
th { font-family:times new roman; font-size:14pt; font-weight:bold; background-color: #EDF3FE; }
/*
Code-like formatting for things such as file system paths and proper names of classes,
methods, etc. To apply this to a file path, use this syntax:
<CODE CLASS="path">...</CODE>
*/
code { color: black; font-weight: bold; font-family: courier new, monospace; font-size: 14pt; white-space: nowrap; }
code.path { color: #4682B4; font-weight: bold; font-family: courier new, monospace; font-size: 14pt; white-space: nowrap; }

Binary file not shown.

After

Width:  |  Height:  |  Size: 859 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View file

@ -15,7 +15,7 @@
*/
package help;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.*;
import java.io.IOException;
import java.nio.file.*;
@ -75,16 +75,13 @@ public abstract class AbstractHelpTest extends AbstractGenericTest {
// HelpFile wants to read one of these, so put one there
createEmpty_TOC_Source_File(helpDir);
createSharedDir(helpDir);
createImageDir(helpDir);
}
protected Path createSharedDir(Path helpDir) throws IOException {
Path sharedDir = helpDir.resolve("shared");
protected Path createImageDir(Path helpDir) throws IOException {
Path sharedDir = helpDir.resolve("images");
Files.createDirectory(sharedDir);
Path css = sharedDir.resolve("Frontpage.css");
Files.createFile(css);
Path png = sharedDir.resolve("test.png");
Files.createFile(png);
@ -121,12 +118,12 @@ public abstract class AbstractHelpTest extends AbstractGenericTest {
"<HTML>\n" +
"<HEAD>\n" +
"<TITLE>Configure Tool</TITLE>\n" +
"<LINK rel=\"stylesheet\" type=\"text/css\" href=\"../../shared/Frontpage.css\">\n" +
"<LINK rel=\"stylesheet\" type=\"text/css\" href=\"help/shared/DefaultStyle.css\">\n" +
"</HEAD>\n" +
"<BODY>\n" +
" <H1><A name=\""+anchor+"\"></A>Configure Tool</H1>\n" +
" Some text with reference to shared image <IMG src=\"../../shared/test.png\">\n" +
" Some text with reference to shared image <IMG src=\"help/shared/note.png\">\n" +
" \n" +
"</BODY>\n" +
"</HTML>\n";
@ -147,7 +144,7 @@ public abstract class AbstractHelpTest extends AbstractGenericTest {
"<HTML>\n" +
"<HEAD>\n" +
"<TITLE>Configure Tool</TITLE>\n" +
"<LINK rel=\"stylesheet\" type=\"text/css\" href=\"../../shared/Frontpage.css\">\n" +
"<LINK rel=\"stylesheet\" type=\"text/css\" href=\"help/shared/DefaultStyle.css\">\n" +
"</HEAD>\n" +
"<BODY>\n" +
@ -174,7 +171,7 @@ public abstract class AbstractHelpTest extends AbstractGenericTest {
"<HTML>\n" +
"<HEAD>\n" +
"<TITLE>Configure Tool</TITLE>\n" +
"<LINK rel=\"stylesheet\" type=\"text/css\" href=\"../../shared/Frontpage.css\">\n" +
"<LINK rel=\"stylesheet\" type=\"text/css\" href=\"help/shared/DefaultStyle.css\">\n" +
"</HEAD>\n" +
"<BODY>\n" +

View file

@ -36,10 +36,6 @@ public class HelpBuildUtilsTest extends AbstractHelpTest {
private static final String TOPIC_AND_FILENAME = "FooTopic/FooFile.html";
private static final String HTML_FILE_PATH = HELP_TOPIC_PATH + '/' + TOPIC_AND_FILENAME;
public HelpBuildUtilsTest() {
super();
}
@Override
protected ApplicationLayout createApplicationLayout() throws IOException {
return new GhidraTestApplicationLayout(new File(getTestDirectoryPath()));

View file

@ -15,8 +15,7 @@
*/
package help.validator.model;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assert.*;
import java.io.IOException;
import java.nio.file.*;
@ -188,7 +187,7 @@ public class HelpFileTest extends AbstractHelpTest {
"<HTML>\n" +
"<HEAD>\n" +
"<TITLE>Configure Tool</TITLE>\n" +
"<LINK rel=\"stylesheet\" type=\"text/css\" href=\"../../shared/Frontpage.css\">\n" +
"<LINK rel=\"stylesheet\" type=\"text/css\" href=\"help/shared/DefaultStyle.css\">\n" +
"</HEAD>\n" +
"<BODY>\n" +
"<H1><A name=\"ManagePluginsDialog\"></A>Configure Tool</H1>\n" +
@ -213,7 +212,7 @@ public class HelpFileTest extends AbstractHelpTest {
"<HTML>\n" +
"<HEAD>\n" +
"<TITLE>Configure Tool</TITLE>\n" +
"<LINK rel=\"stylesheet\" type=\"text/css\" href=\"../../shared/Frontpage.css\">\n" +
"<LINK rel=\"stylesheet\" type=\"text/css\" href=\"help/shared/DefaultStyle.css\">\n" +
"</HEAD>\n" +
"<BODY>\n" +
"<H1><A name=\"ManagePluginsDialog\"></A>Configure Tool</H1>\n" +
@ -238,7 +237,7 @@ public class HelpFileTest extends AbstractHelpTest {
"<HTML>\n" +
"<HEAD>\n" +
"<TITLE>Configure Tool</TITLE>\n" +
"<LINK rel=\"stylesheet\" type=\"text/css\" href=\"../../shared/Frontpage.css\">\n" +
"<LINK rel=\"stylesheet\" type=\"text/css\" href=\"help/shared/DefaultStyle.css\">\n" +
"</HEAD>\n" +
"<BODY>\n" +
"<H1><A name=\"ManagePluginsDialog\"></A>Configure Tool</H1>\n" +
@ -267,7 +266,7 @@ public class HelpFileTest extends AbstractHelpTest {
"</HEAD>\n" +
"<BODY>\n" +
"<H1><A name=\"ManagePluginsDialog\"></A>Configure Tool</H1>\n" +
"Some text with reference to shared image <IMG src=\"../../shared/test.png\">\n" +
"Some text with reference to shared image <IMG src=\"help/shared/DefaultStyle.css\">\n" +
"\n" +
"</BODY>\n" +
"</HTML>\n";
@ -289,7 +288,7 @@ public class HelpFileTest extends AbstractHelpTest {
"<HTML>\n" +
"<HEAD>\n" +
"<TITLE>Configure Tool</TITLE>\n" +
"<LINK rel=\"stylesheet\" type=\"text/css\" href=\"../../shared/Frontpage.css\">\n" +
"<LINK rel=\"stylesheet\" type=\"text/css\" href=\"help/shared/DefaultStyle.css\">\n" +
"</HEAD>\n" +
"<BODY>\n" +
"<H1><A name=\"ManagePluginsDialog\"></A>Configure Tool</H1>\n" +