mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-26 18:35:32 +02:00
[cleanup] formating in preparation for bug fixing
This commit is contained in:
parent
0c5a08d8ce
commit
3577769f43
1 changed files with 248 additions and 311 deletions
|
@ -15,6 +15,7 @@
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.rse.ui;
|
package org.eclipse.rse.ui;
|
||||||
|
|
||||||
import org.eclipse.jface.dialogs.IDialogConstants;
|
import org.eclipse.jface.dialogs.IDialogConstants;
|
||||||
import org.eclipse.jface.resource.JFaceResources;
|
import org.eclipse.jface.resource.JFaceResources;
|
||||||
import org.eclipse.rse.ui.widgets.InheritableEntryField;
|
import org.eclipse.rse.ui.widgets.InheritableEntryField;
|
||||||
|
@ -29,14 +30,11 @@ import org.eclipse.swt.widgets.Menu;
|
||||||
import org.eclipse.swt.widgets.MenuItem;
|
import org.eclipse.swt.widgets.MenuItem;
|
||||||
import org.eclipse.swt.widgets.Text;
|
import org.eclipse.swt.widgets.Text;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class for creating unique mnemonics per control per window.
|
* A class for creating unique mnemonics per control per window.
|
||||||
*/
|
*/
|
||||||
public class Mnemonics
|
public class Mnemonics {
|
||||||
{
|
private static final String[] TransparentEndings = { // endings that should appear after a mnemonic if one is added
|
||||||
private static final String[] TransparentEndings = { // endings that should appear after a mnemonic
|
|
||||||
"...", // ellipsis //$NON-NLS-1$
|
"...", // ellipsis //$NON-NLS-1$
|
||||||
">>", // standard "more" //$NON-NLS-1$
|
">>", // standard "more" //$NON-NLS-1$
|
||||||
"<<", // standard "less" //$NON-NLS-1$
|
"<<", // standard "less" //$NON-NLS-1$
|
||||||
|
@ -55,8 +53,6 @@ public class Mnemonics
|
||||||
private static final String candidateChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; //$NON-NLS-1$
|
private static final String candidateChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; //$NON-NLS-1$
|
||||||
private String preferencePageMnemonics = null; // mnemonics used by Eclipse on preference pages
|
private String preferencePageMnemonics = null; // mnemonics used by Eclipse on preference pages
|
||||||
private String wizardPageMnemonics = null; // mnemonics used by Eclipse on wizard pages
|
private String wizardPageMnemonics = null; // mnemonics used by Eclipse on wizard pages
|
||||||
// private static String preferencePageMnemonics = "AD"; // mnemonics used by Eclipse on preference pages
|
|
||||||
// private static String wizardPageMnemonics = "FBN"; // mnemonics used by Eclipse on wizard pages
|
|
||||||
public static final char MNEMONIC_CHAR = '&';
|
public static final char MNEMONIC_CHAR = '&';
|
||||||
private boolean onPrefPage = false;
|
private boolean onPrefPage = false;
|
||||||
private boolean onWizardPage = false;
|
private boolean onWizardPage = false;
|
||||||
|
@ -65,8 +61,7 @@ public class Mnemonics
|
||||||
/**
|
/**
|
||||||
* Clear the list for re-use
|
* Clear the list for re-use
|
||||||
*/
|
*/
|
||||||
public void clear()
|
public void clear() {
|
||||||
{
|
|
||||||
mnemonics = new StringBuffer();
|
mnemonics = new StringBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,9 +107,7 @@ public class Mnemonics
|
||||||
* @param label String to which to generate and apply the mnemonic
|
* @param label String to which to generate and apply the mnemonic
|
||||||
* @return input String with '&' inserted in front of the unique character
|
* @return input String with '&' inserted in front of the unique character
|
||||||
*/
|
*/
|
||||||
public String setUniqueMnemonic(String label)
|
public String setUniqueMnemonic(String label) {
|
||||||
{
|
|
||||||
|
|
||||||
// Kludge for now
|
// Kludge for now
|
||||||
// If there is already a mnemonic, remove it
|
// If there is already a mnemonic, remove it
|
||||||
label = removeMnemonic(label);
|
label = removeMnemonic(label);
|
||||||
|
@ -123,7 +116,6 @@ public class Mnemonics
|
||||||
//mnemonics.append( label.charAt( iMnemonic + 1 ) );
|
//mnemonics.append( label.charAt( iMnemonic + 1 ) );
|
||||||
//return label;
|
//return label;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
int labelLen = label.length();
|
int labelLen = label.length();
|
||||||
if (labelLen == 0)
|
if (labelLen == 0)
|
||||||
return label;
|
return label;
|
||||||
|
@ -132,20 +124,19 @@ public class Mnemonics
|
||||||
StringBuffer newLabel = new StringBuffer(label);
|
StringBuffer newLabel = new StringBuffer(label);
|
||||||
int mcharPos = findUniqueMnemonic(label);
|
int mcharPos = findUniqueMnemonic(label);
|
||||||
if (mcharPos != -1)
|
if (mcharPos != -1)
|
||||||
newLabel.insert(mcharPos,MNEMONIC_CHAR);
|
newLabel.insert(mcharPos, MNEMONIC_CHAR);
|
||||||
// if no unique character found, then
|
// if no unique character found, then
|
||||||
// find a new arbitrary one from the alphabet...
|
// find a new arbitrary one from the alphabet...
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
mcharPos = findUniqueMnemonic(candidateChars);
|
mcharPos = findUniqueMnemonic(candidateChars);
|
||||||
if (mcharPos != -1)
|
if (mcharPos != -1) {
|
||||||
{
|
|
||||||
String addedMnemonic = "(" + MNEMONIC_CHAR + candidateChars.charAt(mcharPos) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
|
String addedMnemonic = "(" + MNEMONIC_CHAR + candidateChars.charAt(mcharPos) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
insertMnemonic(newLabel, addedMnemonic);
|
insertMnemonic(newLabel, addedMnemonic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return newLabel.toString();
|
return newLabel.toString();
|
||||||
} // end getUniqueMnemonic
|
} // end getUniqueMnemonic
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a label and mnemonic, this applies that mnemonic to the label.
|
* Given a label and mnemonic, this applies that mnemonic to the label.
|
||||||
* Not normally called from other classes, but rather by the setUniqueMnemonic
|
* Not normally called from other classes, but rather by the setUniqueMnemonic
|
||||||
|
@ -154,56 +145,49 @@ public class Mnemonics
|
||||||
* @param mnemonicChar the character that is to be the mnemonic character
|
* @param mnemonicChar the character that is to be the mnemonic character
|
||||||
* @return input String with '&' inserted in front of the given character
|
* @return input String with '&' inserted in front of the given character
|
||||||
*/
|
*/
|
||||||
public static String applyMnemonic(String label, char mnemonicChar)
|
public static String applyMnemonic(String label, char mnemonicChar) {
|
||||||
{
|
|
||||||
int labelLen = label.length();
|
int labelLen = label.length();
|
||||||
if (labelLen == 0)
|
if (labelLen == 0) return label;
|
||||||
return label;
|
|
||||||
StringBuffer newLabel = new StringBuffer(label);
|
StringBuffer newLabel = new StringBuffer(label);
|
||||||
int mcharPos = findCharPos(label, mnemonicChar);
|
int mcharPos = findCharPos(label, mnemonicChar);
|
||||||
if (mcharPos != -1)
|
if (mcharPos != -1)
|
||||||
newLabel.insert(mcharPos,MNEMONIC_CHAR);
|
newLabel.insert(mcharPos, MNEMONIC_CHAR);
|
||||||
else
|
else {
|
||||||
{
|
String addedMnemonic = new String("(" + MNEMONIC_CHAR + mnemonicChar + ")"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
String addedMnemonic = new String("("+MNEMONIC_CHAR + mnemonicChar + ")"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
insertMnemonic(newLabel, addedMnemonic);
|
insertMnemonic(newLabel, addedMnemonic);
|
||||||
}
|
}
|
||||||
return newLabel.toString();
|
return newLabel.toString();
|
||||||
} // end getUniqueMnemonic
|
} // end getUniqueMnemonic
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a char, find its position in the given string
|
* Given a char, find its position in the given string
|
||||||
*/
|
*/
|
||||||
private static int findCharPos(String label, char charToFind)
|
private static int findCharPos(String label, char charToFind) {
|
||||||
{
|
|
||||||
int pos = -1;
|
int pos = -1;
|
||||||
for (int idx=0; (pos==-1) && (idx<label.length()); idx++)
|
for (int idx = 0; (pos == -1) && (idx < label.length()); idx++)
|
||||||
if (label.charAt(idx) == charToFind)
|
if (label.charAt(idx) == charToFind) pos = idx;
|
||||||
pos = idx;
|
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if given char is a unique mnemonic
|
* Determine if given char is a unique mnemonic
|
||||||
*/
|
*/
|
||||||
public boolean isUniqueMnemonic(char currchar)
|
public boolean isUniqueMnemonic(char currchar) {
|
||||||
{
|
|
||||||
boolean isUnique = true;
|
boolean isUnique = true;
|
||||||
for (int idx=0; isUnique && (idx < mnemonics.length()); idx++)
|
for (int idx = 0; isUnique && (idx < mnemonics.length()); idx++)
|
||||||
if (mnemonics.charAt(idx) == currchar)
|
if (mnemonics.charAt(idx) == currchar) isUnique = false;
|
||||||
isUnique = false;
|
|
||||||
return isUnique;
|
return isUnique;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find a uniqe mnemonic char in given string.
|
* Find a uniqe mnemonic char in given string.
|
||||||
* Note if one is found, it is added to the list of currently used mnemonics!
|
* Note if one is found, it is added to the list of currently used mnemonics!
|
||||||
*
|
*
|
||||||
* @return index position of unique character in input string, or -1 if none found.
|
* @return index position of unique character in input string, or -1 if none found.
|
||||||
*/
|
*/
|
||||||
public int findUniqueMnemonic(String label)
|
public int findUniqueMnemonic(String label) {
|
||||||
{
|
|
||||||
int labelLen = label.length();
|
int labelLen = label.length();
|
||||||
if (labelLen == 0)
|
if (labelLen == 0) return -1;
|
||||||
return -1;
|
|
||||||
int retcharPos = -1;
|
int retcharPos = -1;
|
||||||
label = label.toUpperCase();
|
label = label.toUpperCase();
|
||||||
char currchar = label.charAt(0);
|
char currchar = label.charAt(0);
|
||||||
|
@ -227,17 +211,12 @@ public class Mnemonics
|
||||||
|
|
||||||
// attempt to find the first character in the given
|
// attempt to find the first character in the given
|
||||||
// string that has not already been used as a mnemonic
|
// string that has not already been used as a mnemonic
|
||||||
for (int idx=0; (idx<labelLen) && (retcharPos==-1); idx++)
|
for (int idx = 0; (idx < labelLen) && (retcharPos == -1); idx++) {
|
||||||
{
|
|
||||||
currchar = label.charAt(idx);
|
currchar = label.charAt(idx);
|
||||||
|
|
||||||
if ( !(onPrefPage && preferencePageMnemonics.indexOf( currchar ) != -1)
|
if (!(onPrefPage && preferencePageMnemonics.indexOf(currchar) != -1) && !(onWizardPage && wizardPageMnemonics.indexOf(currchar) != -1) && candidateChars.indexOf(currchar) != -1) {
|
||||||
&& !(onWizardPage && wizardPageMnemonics.indexOf( currchar ) != -1)
|
|
||||||
&& candidateChars.indexOf( currchar ) != -1 )
|
|
||||||
{
|
|
||||||
isUnique = isUniqueMnemonic(currchar);
|
isUnique = isUniqueMnemonic(currchar);
|
||||||
if (isUnique)
|
if (isUnique) {
|
||||||
{
|
|
||||||
mnemonics.append(currchar);
|
mnemonics.append(currchar);
|
||||||
retcharPos = idx;
|
retcharPos = idx;
|
||||||
}
|
}
|
||||||
|
@ -260,7 +239,7 @@ public class Mnemonics
|
||||||
* @return the mnemonics.
|
* @return the mnemonics.
|
||||||
*/
|
*/
|
||||||
private String getWizardPageMnemonics() {
|
private String getWizardPageMnemonics() {
|
||||||
String[] labels = new String[] {IDialogConstants.BACK_LABEL, IDialogConstants.NEXT_LABEL, IDialogConstants.FINISH_LABEL};
|
String[] labels = new String[] { IDialogConstants.BACK_LABEL, IDialogConstants.NEXT_LABEL, IDialogConstants.FINISH_LABEL };
|
||||||
return getMnemonicsFromStrings(labels).toUpperCase();
|
return getMnemonicsFromStrings(labels).toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,17 +249,13 @@ public class Mnemonics
|
||||||
* @return a string containing the mnemonics.
|
* @return a string containing the mnemonics.
|
||||||
*/
|
*/
|
||||||
private String getMnemonicsFromStrings(String[] strings) {
|
private String getMnemonicsFromStrings(String[] strings) {
|
||||||
|
|
||||||
StringBuffer result = new StringBuffer();
|
StringBuffer result = new StringBuffer();
|
||||||
|
|
||||||
for (int i = 0; i < strings.length; i++) {
|
for (int i = 0; i < strings.length; i++) {
|
||||||
int idx = strings[i].indexOf(MNEMONIC_CHAR);
|
int idx = strings[i].indexOf(MNEMONIC_CHAR);
|
||||||
|
|
||||||
if (idx != -1) {
|
if (idx != -1) {
|
||||||
result.append(strings[i].charAt(idx+1));
|
result.append(strings[i].charAt(idx + 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,32 +263,27 @@ public class Mnemonics
|
||||||
* Adds a mnemonic to an SWT Button such that the user can select it via Ctrl/Alt+mnemonic.
|
* Adds a mnemonic to an SWT Button such that the user can select it via Ctrl/Alt+mnemonic.
|
||||||
* Note a mnemonic unique to this window is chosen
|
* Note a mnemonic unique to this window is chosen
|
||||||
*/
|
*/
|
||||||
public void setMnemonic(Button button)
|
public void setMnemonic(Button button) {
|
||||||
{
|
|
||||||
removeMnemonic(button); // just in case it already has a mnemonic
|
removeMnemonic(button); // just in case it already has a mnemonic
|
||||||
String text = button.getText();
|
String text = button.getText();
|
||||||
if ((text != null) && (text.trim().length() > 0))
|
if ((text != null) && (text.trim().length() > 0)) button.setText(setUniqueMnemonic(text));
|
||||||
button.setText(setUniqueMnemonic(text));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If a button is removed from a dialog window, call this method to remove its mnemonic from the list for this dialog.
|
* If a button is removed from a dialog window, call this method to remove its mnemonic from the list for this dialog.
|
||||||
* This frees it up for another button to use.
|
* This frees it up for another button to use.
|
||||||
*/
|
*/
|
||||||
public void removeMnemonic(Button button)
|
public void removeMnemonic(Button button) {
|
||||||
{
|
|
||||||
String text = button.getText();
|
String text = button.getText();
|
||||||
if (text == null)
|
if (text == null) return;
|
||||||
return;
|
|
||||||
int idx = text.indexOf(MNEMONIC_CHAR);
|
int idx = text.indexOf(MNEMONIC_CHAR);
|
||||||
if (idx >= 0)
|
if (idx >= 0) {
|
||||||
{
|
|
||||||
StringBuffer buffer = new StringBuffer(text);
|
StringBuffer buffer = new StringBuffer(text);
|
||||||
char mchar = buffer.charAt(idx+1); // the char after the &
|
char mchar = buffer.charAt(idx + 1); // the char after the &
|
||||||
buffer.deleteCharAt(idx); // delete the &
|
buffer.deleteCharAt(idx); // delete the &
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
for (int mdx=0; !found && (mdx < mnemonics.length()); mdx++)
|
for (int mdx = 0; !found && (mdx < mnemonics.length()); mdx++)
|
||||||
if (mnemonics.charAt(mdx) == mchar)
|
if (mnemonics.charAt(mdx) == mchar) {
|
||||||
{
|
|
||||||
found = true;
|
found = true;
|
||||||
mnemonics.deleteCharAt(mdx);
|
mnemonics.deleteCharAt(mdx);
|
||||||
}
|
}
|
||||||
|
@ -321,47 +291,41 @@ public class Mnemonics
|
||||||
button.setText(buffer.toString());
|
button.setText(buffer.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to strip the mnemonic from a string.
|
* Helper method to strip the mnemonic from a string.
|
||||||
* Useful if using Eclipse supplied labels
|
* Useful if using Eclipse supplied labels
|
||||||
*/
|
*/
|
||||||
public static String removeMnemonic(String text)
|
public static String removeMnemonic(String text) {
|
||||||
{
|
|
||||||
int idx = text.indexOf(MNEMONIC_CHAR);
|
int idx = text.indexOf(MNEMONIC_CHAR);
|
||||||
if (idx >= 0)
|
if (idx >= 0) {
|
||||||
{
|
|
||||||
StringBuffer buffer = new StringBuffer(text);
|
StringBuffer buffer = new StringBuffer(text);
|
||||||
buffer.deleteCharAt(idx); // delete the &
|
buffer.deleteCharAt(idx); // delete the &
|
||||||
|
|
||||||
// in case of already appended (&X), remove the remaining (X)
|
// in case of already appended (&X), remove the remaining (X)
|
||||||
if ( buffer.length() > (1 + idx) && idx > 1 && buffer.charAt(idx+1) == ')' && buffer.charAt(idx-1) == '(' )
|
if (buffer.length() > (1 + idx) && idx > 1 && buffer.charAt(idx + 1) == ')' && buffer.charAt(idx - 1) == '(') buffer.delete(idx - 1, idx + 2);
|
||||||
buffer.delete(idx - 1, idx + 2);
|
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove and free up mnemonic
|
* Remove and free up mnemonic
|
||||||
*/
|
*/
|
||||||
public String removeAndFreeMnemonic(String text)
|
public String removeAndFreeMnemonic(String text) {
|
||||||
{
|
|
||||||
int idx = text.indexOf(MNEMONIC_CHAR);
|
int idx = text.indexOf(MNEMONIC_CHAR);
|
||||||
if (idx >= 0)
|
if (idx >= 0) {
|
||||||
{
|
|
||||||
StringBuffer buffer = new StringBuffer(text);
|
StringBuffer buffer = new StringBuffer(text);
|
||||||
char mchar = buffer.charAt(idx+1); // the char after the &
|
char mchar = buffer.charAt(idx + 1); // the char after the &
|
||||||
buffer.deleteCharAt(idx); // delete the &
|
buffer.deleteCharAt(idx); // delete the &
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
for (int mdx=0; !found && (mdx < mnemonics.length()); mdx++)
|
for (int mdx = 0; !found && (mdx < mnemonics.length()); mdx++)
|
||||||
if (mnemonics.charAt(mdx) == mchar)
|
if (mnemonics.charAt(mdx) == mchar) {
|
||||||
{
|
|
||||||
found = true;
|
found = true;
|
||||||
mnemonics.deleteCharAt(mdx);
|
mnemonics.deleteCharAt(mdx);
|
||||||
}
|
}
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -371,11 +335,10 @@ public class Mnemonics
|
||||||
* such as is necessary for buttons which toggle their text.
|
* such as is necessary for buttons which toggle their text.
|
||||||
* @return the mnemonic if assigned, else a blank character.
|
* @return the mnemonic if assigned, else a blank character.
|
||||||
*/
|
*/
|
||||||
public static char getMnemonic(String text)
|
public static char getMnemonic(String text) {
|
||||||
{
|
|
||||||
int idx = text.indexOf(MNEMONIC_CHAR);
|
int idx = text.indexOf(MNEMONIC_CHAR);
|
||||||
if (idx >= 0)
|
if (idx >= 0)
|
||||||
return text.charAt(idx+1);
|
return text.charAt(idx + 1);
|
||||||
else
|
else
|
||||||
return ' ';
|
return ' ';
|
||||||
}
|
}
|
||||||
|
@ -389,50 +352,41 @@ public class Mnemonics
|
||||||
* per Window.
|
* per Window.
|
||||||
* Call this after populating your controls.
|
* Call this after populating your controls.
|
||||||
*/
|
*/
|
||||||
public void setMnemonics(Composite parent)
|
public void setMnemonics(Composite parent) {
|
||||||
{
|
|
||||||
Control children[] = parent.getChildren();
|
Control children[] = parent.getChildren();
|
||||||
if (children != null)
|
if (children != null) {
|
||||||
{
|
|
||||||
Control currChild = null;
|
Control currChild = null;
|
||||||
boolean bSetText = false;
|
boolean bSetText = false;
|
||||||
for (int idx=0; idx < children.length; idx++)
|
for (int idx = 0; idx < children.length; idx++) {
|
||||||
{
|
|
||||||
currChild = children[idx];
|
currChild = children[idx];
|
||||||
// composite? Recurse
|
// composite? Recurse
|
||||||
// d54732: but do not recurse if it is a combo! For a combo, we want to check
|
// d54732: but do not recurse if it is a combo! For a combo, we want to check
|
||||||
// if there is a preceding label. It's meaningless for a combo to
|
// if there is a preceding label. It's meaningless for a combo to
|
||||||
// have children anyway (KM)
|
// have children anyway (KM)
|
||||||
if ((currChild instanceof Composite) &&
|
if ((currChild instanceof Composite) &&
|
||||||
(!applyMnemonicsToPrecedingLabels || (applyMnemonicsToPrecedingLabels &&
|
(!applyMnemonicsToPrecedingLabels || (applyMnemonicsToPrecedingLabels && !(currChild instanceof Combo) && !(currChild instanceof InheritableEntryField))))
|
||||||
!(currChild instanceof Combo) && !(currChild instanceof InheritableEntryField))))
|
setMnemonics((Composite) currChild);
|
||||||
setMnemonics((Composite)currChild);
|
|
||||||
// button? select and apply unique mnemonic...
|
// button? select and apply unique mnemonic...
|
||||||
else if (currChild instanceof Button)
|
else if (currChild instanceof Button) {
|
||||||
{
|
Button currButton = (Button) currChild;
|
||||||
Button currButton = (Button)currChild;
|
|
||||||
String text = currButton.getText();
|
String text = currButton.getText();
|
||||||
if ((text!=null) && (text.trim().length()>0))
|
if ((text != null) && (text.trim().length() > 0)) {
|
||||||
{
|
|
||||||
currButton.setText(setUniqueMnemonic(text));
|
currButton.setText(setUniqueMnemonic(text));
|
||||||
bSetText = true;
|
bSetText = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// entry field or combo box? select and apply unique mnemonic to preceding label...
|
// entry field or combo box? select and apply unique mnemonic to preceding label...
|
||||||
else if (applyMnemonicsToPrecedingLabels && (idx>0) && ((currChild instanceof Text) || (currChild instanceof Combo) || (currChild instanceof InheritableEntryField)) &&
|
else if (applyMnemonicsToPrecedingLabels && (idx > 0) && ((currChild instanceof Text) || (currChild instanceof Combo) || (currChild instanceof InheritableEntryField)) &&
|
||||||
(children[idx-1] instanceof Label))
|
(children[idx - 1] instanceof Label)) {
|
||||||
{
|
Label currLabel = (Label) children[idx - 1];
|
||||||
Label currLabel = (Label)children[idx-1];
|
|
||||||
String text = currLabel.getText();
|
String text = currLabel.getText();
|
||||||
if ((text!=null) && (text.trim().length()>0))
|
if ((text != null) && (text.trim().length() > 0)) {
|
||||||
{
|
|
||||||
currLabel.setText(setUniqueMnemonic(text));
|
currLabel.setText(setUniqueMnemonic(text));
|
||||||
bSetText = true;
|
bSetText = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( bSetText == true )
|
if (bSetText == true) parent.layout(true); // in case a (x) was appended, we need to layout the controls again
|
||||||
parent.layout(true); // in case a (x) was appended, we need to layout the controls again
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -441,24 +395,19 @@ public class Mnemonics
|
||||||
* memnonic. Also handles casdading submenus.
|
* memnonic. Also handles casdading submenus.
|
||||||
* Call this after populating the menu.
|
* Call this after populating the menu.
|
||||||
*/
|
*/
|
||||||
public void setMnemonics(Menu menu)
|
public void setMnemonics(Menu menu) {
|
||||||
{
|
|
||||||
MenuItem[] children = menu.getItems();
|
MenuItem[] children = menu.getItems();
|
||||||
if ((children != null) && (children.length>0))
|
if ((children != null) && (children.length > 0)) {
|
||||||
{
|
|
||||||
MenuItem currChild = null;
|
MenuItem currChild = null;
|
||||||
for (int idx=0; idx < children.length; idx++)
|
for (int idx = 0; idx < children.length; idx++) {
|
||||||
{
|
|
||||||
currChild = children[idx];
|
currChild = children[idx];
|
||||||
String text = currChild.getText();
|
String text = currChild.getText();
|
||||||
if ((text!=null)&&(text.length()>0))
|
if ((text != null) && (text.length() > 0)) {
|
||||||
{
|
|
||||||
if (text.indexOf(MNEMONIC_CHAR) < 0) // bad things happen when setting mnemonics twice!
|
if (text.indexOf(MNEMONIC_CHAR) < 0) // bad things happen when setting mnemonics twice!
|
||||||
{
|
{
|
||||||
Image image = currChild.getImage();
|
Image image = currChild.getImage();
|
||||||
currChild.setText(setUniqueMnemonic(text));
|
currChild.setText(setUniqueMnemonic(text));
|
||||||
if (image != null)
|
if (image != null) currChild.setImage(image);
|
||||||
currChild.setImage(image);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -476,28 +425,22 @@ public class Mnemonics
|
||||||
* <p>
|
* <p>
|
||||||
* Call this after populating the menu.
|
* Call this after populating the menu.
|
||||||
*/
|
*/
|
||||||
public void setMnemonicsAndArmListener(Menu menu, ArmListener listener)
|
public void setMnemonicsAndArmListener(Menu menu, ArmListener listener) {
|
||||||
{
|
|
||||||
MenuItem[] children = menu.getItems();
|
MenuItem[] children = menu.getItems();
|
||||||
if ((children != null) && (children.length>0))
|
if ((children != null) && (children.length > 0)) {
|
||||||
{
|
|
||||||
MenuItem currChild = null;
|
MenuItem currChild = null;
|
||||||
for (int idx=0; idx < children.length; idx++)
|
for (int idx = 0; idx < children.length; idx++) {
|
||||||
{
|
|
||||||
currChild = children[idx];
|
currChild = children[idx];
|
||||||
String text = currChild.getText();
|
String text = currChild.getText();
|
||||||
if ((text!=null)&&(text.length()>0))
|
if ((text != null) && (text.length() > 0)) {
|
||||||
{
|
|
||||||
int mnemonicIndex = text.indexOf(MNEMONIC_CHAR);
|
int mnemonicIndex = text.indexOf(MNEMONIC_CHAR);
|
||||||
if (mnemonicIndex < 0) // bad things happen when setting mnemonics twice!
|
if (mnemonicIndex < 0) // bad things happen when setting mnemonics twice!
|
||||||
{
|
{
|
||||||
Image image = currChild.getImage();
|
Image image = currChild.getImage();
|
||||||
currChild.setText(setUniqueMnemonic(text));
|
currChild.setText(setUniqueMnemonic(text));
|
||||||
if (image != null)
|
if (image != null) currChild.setImage(image);
|
||||||
currChild.setImage(image);
|
|
||||||
currChild.addArmListener(listener);
|
currChild.addArmListener(listener);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
// hmm, already has a mnemonic char. Either it is an Eclipse/BP-supplied action, or we have been here before.
|
// hmm, already has a mnemonic char. Either it is an Eclipse/BP-supplied action, or we have been here before.
|
||||||
// The distinction is important as want to add an Arm listener, but only once!
|
// The distinction is important as want to add an Arm listener, but only once!
|
||||||
{
|
{
|
||||||
|
@ -508,16 +451,13 @@ public class Mnemonics
|
||||||
char c = text.charAt(mnemonicIndex + 1);
|
char c = text.charAt(mnemonicIndex + 1);
|
||||||
|
|
||||||
// anything already have this?
|
// anything already have this?
|
||||||
if (!isUniqueMnemonic(c))
|
if (!isUniqueMnemonic(c)) {
|
||||||
{
|
|
||||||
// if so, we need to adjust existing action
|
// if so, we need to adjust existing action
|
||||||
for (int n = 0; n < idx; n++)
|
for (int n = 0; n < idx; n++) {
|
||||||
{
|
|
||||||
MenuItem oChild = children[n];
|
MenuItem oChild = children[n];
|
||||||
String oText = oChild.getText();
|
String oText = oChild.getText();
|
||||||
char oldN = getMnemonic(oText);
|
char oldN = getMnemonic(oText);
|
||||||
if (oldN == c)
|
if (oldN == c) {
|
||||||
{
|
|
||||||
// this one now needs to change
|
// this one now needs to change
|
||||||
String cleanText = removeMnemonic(oText);
|
String cleanText = removeMnemonic(oText);
|
||||||
oChild.setText(setUniqueMnemonic(cleanText));
|
oChild.setText(setUniqueMnemonic(cleanText));
|
||||||
|
@ -527,8 +467,7 @@ public class Mnemonics
|
||||||
|
|
||||||
text = removeAndFreeMnemonic(text);
|
text = removeAndFreeMnemonic(text);
|
||||||
currChild.setText(setUniqueMnemonic(text));
|
currChild.setText(setUniqueMnemonic(text));
|
||||||
if (image != null)
|
if (image != null) currChild.setImage(image);
|
||||||
currChild.setImage(image);
|
|
||||||
currChild.removeArmListener(listener); // just in case
|
currChild.removeArmListener(listener); // just in case
|
||||||
currChild.addArmListener(listener);
|
currChild.addArmListener(listener);
|
||||||
}
|
}
|
||||||
|
@ -542,8 +481,7 @@ public class Mnemonics
|
||||||
* Preference pages already have a few buttons with mnemonics set by Eclipse
|
* Preference pages already have a few buttons with mnemonics set by Eclipse
|
||||||
* We have to make sure we do not use the ones they use
|
* We have to make sure we do not use the ones they use
|
||||||
*/
|
*/
|
||||||
public Mnemonics setOnPreferencePage(boolean page)
|
public Mnemonics setOnPreferencePage(boolean page) {
|
||||||
{
|
|
||||||
this.onPrefPage = page;
|
this.onPrefPage = page;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -553,8 +491,7 @@ public class Mnemonics
|
||||||
* Wizard pages already have a few buttons with mnemonics set by Eclipse
|
* Wizard pages already have a few buttons with mnemonics set by Eclipse
|
||||||
* We have to make sure we do not use the ones they use
|
* We have to make sure we do not use the ones they use
|
||||||
*/
|
*/
|
||||||
public Mnemonics setOnWizardPage(boolean page)
|
public Mnemonics setOnWizardPage(boolean page) {
|
||||||
{
|
|
||||||
this.onWizardPage = page;
|
this.onWizardPage = page;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue