Skip to content

Commit

Permalink
Removed compiler option "Interactive script and resource names"
Browse files Browse the repository at this point in the history
This option was rendered redundant when script compiler/decompiler were
rewritten from scratch.
  • Loading branch information
Argent77 committed Aug 6, 2017
1 parent cf25a0c commit d014217
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 83 deletions.
14 changes: 1 addition & 13 deletions src/org/infinity/gui/BrowserMenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,6 @@ public boolean autocheckBCS()
return optionsMenu.optionAutocheckBCS.isSelected();
}

public boolean checkScriptNames()
{
return optionsMenu.optionCheckScriptNames.isSelected();
}

public boolean showMoreCompileWarnings()
{
return optionsMenu.optionMoreCompileWarnings.isSelected();
Expand Down Expand Up @@ -1546,7 +1541,6 @@ private static final class OptionsMenu extends JMenu implements ActionListener,
private static final String OPTION_SHOWUNKNOWNRESOURCES = "ShowUnknownResources";
private static final String OPTION_AUTOCHECK_BCS = "AutocheckBCS";
private static final String OPTION_CACHEOVERRIDE = "CacheOverride";
private static final String OPTION_CHECKSCRIPTNAMES = "CheckScriptNames";
private static final String OPTION_MORECOMPILERWARNINGS = "MoreCompilerWarnings";
private static final String OPTION_SHOWSTRREFS = "ShowStrrefs";
private static final String OPTION_DLG_SHOWICONS = "DlgShowIcons";
Expand Down Expand Up @@ -1612,7 +1606,7 @@ private static final class OptionsMenu extends JMenu implements ActionListener,
optionSQLEnableSyntax, optionTLKEnableSyntax,
optionGLSLEnableCodeFolding;

private JCheckBoxMenuItem optionAutocheckBCS, optionCheckScriptNames, optionMoreCompileWarnings;
private JCheckBoxMenuItem optionAutocheckBCS, optionMoreCompileWarnings;

private JCheckBoxMenuItem optionBackupOnSave, optionShowOffset, optionIgnoreOverride,
optionIgnoreReadErrors, optionCacheOverride, optionShowStrrefs,
Expand Down Expand Up @@ -1683,11 +1677,6 @@ private OptionsMenu()
new JCheckBoxMenuItem("Autocheck BCS", getPrefs().getBoolean(OPTION_AUTOCHECK_BCS, true));
optionAutocheckBCS.setToolTipText("Automatically scans scripts for compile error with this option enabled.");
compilerMenu.add(optionAutocheckBCS);
optionCheckScriptNames =
new JCheckBoxMenuItem("Interactive script and resource names", getPrefs().getBoolean(OPTION_CHECKSCRIPTNAMES, true));
optionCheckScriptNames.setToolTipText("With this option disabled, performance may be boosted, " +
"but many features involving script or resource names will be disabled.");
compilerMenu.add(optionCheckScriptNames);
optionMoreCompileWarnings =
new JCheckBoxMenuItem("Show more compiler warnings", getPrefs().getBoolean(OPTION_MORECOMPILERWARNINGS, false));
optionMoreCompileWarnings.setToolTipText("Script compiler will generate an additional set of less severe " +
Expand Down Expand Up @@ -2244,7 +2233,6 @@ private void storePreferences()
getPrefs().putBoolean(OPTION_SHOWUNKNOWNRESOURCES, optionShowUnknownResources.isSelected());
getPrefs().putBoolean(OPTION_AUTOCHECK_BCS, optionAutocheckBCS.isSelected());
getPrefs().putBoolean(OPTION_CACHEOVERRIDE, optionCacheOverride.isSelected());
getPrefs().putBoolean(OPTION_CHECKSCRIPTNAMES, optionCheckScriptNames.isSelected());
getPrefs().putBoolean(OPTION_MORECOMPILERWARNINGS, optionMoreCompileWarnings.isSelected());
getPrefs().putBoolean(OPTION_SHOWSTRREFS, optionShowStrrefs.isSelected());
getPrefs().putBoolean(OPTION_DLG_SHOWICONS, optionDlgShowIcons.isSelected());
Expand Down
80 changes: 31 additions & 49 deletions src/org/infinity/gui/ScriptTextArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ private enum IconType {
// Special popup menu for interactive resource references
private final ScriptPopupMenu menu = new ScriptPopupMenu();

private boolean isInteractive; // Whether interactive elements are enabled
private Signatures triggers;
private Signatures actions;

Expand All @@ -88,25 +87,19 @@ public ScriptTextArea()
}
applyExtendedSettings(lang, null);

this.isInteractive = BrowserMenuBar.getInstance().checkScriptNames();
triggers = Signatures.getTriggers();
actions = Signatures.getActions();

if (isInteractive()) {
triggers = Signatures.getTriggers();
actions = Signatures.getActions();
if (triggers != null && actions != null) {
getDocument().addDocumentListener(this);

if (triggers != null && actions != null) {
getDocument().addDocumentListener(this);
addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) { handlePopup(e); }

addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) { handlePopup(e); }

@Override
public void mouseReleased(MouseEvent e) { handlePopup(e); }
});
} else {
isInteractive = false;
}
@Override
public void mouseReleased(MouseEvent e) { handlePopup(e); }
});
}
}

Expand All @@ -122,10 +115,6 @@ protected void paintComponent(Graphics g)
{
super.paintComponent(g);

if (!isInteractive()) {
return;
}

// getting range of affected lines
Rectangle rect = g.getClipBounds();
int offsetMin;
Expand Down Expand Up @@ -183,30 +172,28 @@ public String getToolTipText(MouseEvent e)
{
String retVal = super.getToolTipText(e);

if (isInteractive()) {
tokenMapLock.lock();
try {
int offset = viewToModel(e.getPoint());
int line = getLineOfOffset(offset);
int ofsMin = getLineStartOffset(line);
int ofsMax = getLineEndOffset(line);
SortedMap<Integer, InteractiveToken> map =
tokenMap.subMap(Integer.valueOf(ofsMin), Integer.valueOf(ofsMax));
Iterator<InteractiveToken> iter = map.values().iterator();

while (iter.hasNext()) {
InteractiveToken itoken = iter.next();
if (itoken.isTooltip()) {
if (offset >= itoken.position && offset < itoken.position + itoken.length) {
retVal = itoken.tooltip;
break;
}
tokenMapLock.lock();
try {
int offset = viewToModel(e.getPoint());
int line = getLineOfOffset(offset);
int ofsMin = getLineStartOffset(line);
int ofsMax = getLineEndOffset(line);
SortedMap<Integer, InteractiveToken> map =
tokenMap.subMap(Integer.valueOf(ofsMin), Integer.valueOf(ofsMax));
Iterator<InteractiveToken> iter = map.values().iterator();

while (iter.hasNext()) {
InteractiveToken itoken = iter.next();
if (itoken.isTooltip()) {
if (offset >= itoken.position && offset < itoken.position + itoken.length) {
retVal = itoken.tooltip;
break;
}
}
} catch (BadLocationException ble) {
} finally {
tokenMapLock.unlock();
}
} catch (BadLocationException ble) {
} finally {
tokenMapLock.unlock();
}

return retVal;
Expand Down Expand Up @@ -244,17 +231,12 @@ public void stateChanged(ChangeEvent e)
// important: stateChanged() is registered by super class
super.stateChanged(e);

if (isInteractive()) {
updateInteractiveTokens(false);
repaint();
}
updateInteractiveTokens(false);
repaint();
}

//--------------------- End Interface ChangeListener ---------------------

/** Returns whether interactive elements are generated. */
public boolean isInteractive() { return isInteractive; }

/**
* Adds a new error notification to the gutter at the left edge.
* @param line The (one-based) line where to add the icon.
Expand Down
8 changes: 3 additions & 5 deletions src/org/infinity/resource/bcs/Decompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -1063,8 +1063,7 @@ private String generateNumberComment(long value, Signatures.Function.Parameter p
{
StringBuilder sb = new StringBuilder();

if (enable && (isGenerateComments() || isGenerateResourcesUsed()) &&
BrowserMenuBar.getInstance().checkScriptNames()) {
if (enable && (isGenerateComments() || isGenerateResourcesUsed())) {
ResourceEntry entry = null;
String[] types = param.getResourceType();
for (String type: types) {
Expand Down Expand Up @@ -1102,8 +1101,7 @@ private String generateStringComment(String value, Signatures.Function.Parameter
{
StringBuilder sb = new StringBuilder();

if (enable && (isGenerateComments() || isGenerateResourcesUsed()) &&
BrowserMenuBar.getInstance().checkScriptNames() && !value.isEmpty()) {
if (enable && (isGenerateComments() || isGenerateResourcesUsed()) && !value.isEmpty()) {
String[] types = param.getResourceType();
for (String type: types) {
if (type.equals(Signatures.Function.Parameter.RESTYPE_SCRIPT) &&
Expand Down Expand Up @@ -1173,7 +1171,7 @@ private String generateObjectComment(BcsObject object, boolean enable)
{
StringBuilder sb = new StringBuilder();

if (enable && isGenerateComments() && BrowserMenuBar.getInstance().checkScriptNames()) {
if (enable && isGenerateComments()) {
if (!object.name.isEmpty()) {
Set<ResourceEntry> set = CreMapCache.getCreForScriptName(object.name);
if (set != null && !set.isEmpty()) {
Expand Down
21 changes: 5 additions & 16 deletions src/org/infinity/util/CreMapCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.concurrent.TimeUnit;

import org.infinity.NearInfinity;
import org.infinity.gui.BrowserMenuBar;
import org.infinity.gui.StatusBar;
import org.infinity.resource.Profile;
import org.infinity.resource.ResourceFactory;
Expand All @@ -30,7 +29,6 @@ public final class CreMapCache
private static final Map<String, Set<ResourceEntry>> scriptNamesCre = new HashMap<>();
private static final Set<String> scriptNamesAre = new HashSet<>();

private static boolean enabled = false;
private static boolean initialized = false;

public static void creInvalid(ResourceEntry entry)
Expand All @@ -53,22 +51,13 @@ public static void clearCache()
scriptNamesCre.clear();
scriptNamesAre.clear();
initialized = false;
enabled = false;
}
}

public static void reset()
{
enabled = BrowserMenuBar.getInstance() != null && BrowserMenuBar.getInstance().checkScriptNames();
if (enabled) {
clearCache();
init();
}
}

public static boolean isEnabled()
{
return enabled;
clearCache();
init();
}

public static boolean isInitialized()
Expand All @@ -91,7 +80,7 @@ public static boolean hasCreScriptName(String name)
if (isInitialized() && name != null) {
return scriptNamesCre.containsKey(normalized(name));
} else {
return !isEnabled();
return false;
}
}

Expand All @@ -101,7 +90,7 @@ public static boolean hasAreScriptName(String name)
if (isInitialized() && name != null) {
return scriptNamesAre.contains(normalized(name));
} else {
return !isEnabled();
return false;
}
}

Expand All @@ -128,7 +117,7 @@ public static Set<String> getCreScriptNames()
private static boolean ensureInitialized(int timeOutMS)
{
long timeOut = (timeOutMS >= 0) ? System.nanoTime() + (timeOutMS * 1000000L) : -1L;
while (isEnabled() && !isInitialized() &&
while (!isInitialized() &&
(timeOut == -1L || System.nanoTime() < timeOut)) {
try {
Thread.sleep(1);
Expand Down

0 comments on commit d014217

Please sign in to comment.