Commit fa87c6b7 authored by andrei's avatar andrei
Browse files
parent 0d4f2a2c
...@@ -53,23 +53,23 @@ public class BytecodeCompare extends CompareEditorInput { ...@@ -53,23 +53,23 @@ public class BytecodeCompare extends CompareEditorInput {
* @param left element displayed on the left. * @param left element displayed on the left.
* @param right element displayed on the right. * @param right element displayed on the right.
*/ */
public BytecodeCompare(TypedElement left, TypedElement right) { public BytecodeCompare(final TypedElement left, final TypedElement right) {
super(new CompareConfiguration()); super(new CompareConfiguration());
this.left = left; this.left = left;
this.right = right; this.right = right;
toggleAsmifierModeAction = new DefaultToggleAction( toggleAsmifierModeAction = new DefaultToggleAction(
BCOConstants.DIFF_SHOW_ASMIFIER_CODE) { BCOConstants.DIFF_SHOW_ASMIFIER_CODE, false) {
public void run(boolean newState) { public void run(final boolean newState) {
toggleMode( toggleMode(
BCOConstants.F_SHOW_ASMIFIER_CODE, newState, newState); BCOConstants.F_SHOW_ASMIFIER_CODE, newState, newState);
} }
}; };
hideLineInfoAction = new DefaultToggleAction( hideLineInfoAction = new DefaultToggleAction(
BCOConstants.DIFF_SHOW_LINE_INFO) { BCOConstants.DIFF_SHOW_LINE_INFO, false) {
public void run(boolean newState) { public void run(final boolean newState) {
toggleMode( toggleMode(
BCOConstants.F_SHOW_LINE_INFO, newState, BCOConstants.F_SHOW_LINE_INFO, newState,
toggleAsmifierModeAction.isChecked()); toggleAsmifierModeAction.isChecked());
...@@ -77,9 +77,9 @@ public class BytecodeCompare extends CompareEditorInput { ...@@ -77,9 +77,9 @@ public class BytecodeCompare extends CompareEditorInput {
}; };
hideLocalsAction = new DefaultToggleAction( hideLocalsAction = new DefaultToggleAction(
BCOConstants.DIFF_SHOW_VARIABLES) { BCOConstants.DIFF_SHOW_VARIABLES, false) {
public void run(boolean newState) { public void run(final boolean newState) {
toggleMode( toggleMode(
BCOConstants.F_SHOW_VARIABLES, newState, BCOConstants.F_SHOW_VARIABLES, newState,
toggleAsmifierModeAction.isChecked()); toggleAsmifierModeAction.isChecked());
...@@ -87,9 +87,9 @@ public class BytecodeCompare extends CompareEditorInput { ...@@ -87,9 +87,9 @@ public class BytecodeCompare extends CompareEditorInput {
}; };
hideStackMapAction = new DefaultToggleAction( hideStackMapAction = new DefaultToggleAction(
BCOConstants.DIFF_SHOW_STACKMAP) { BCOConstants.DIFF_SHOW_STACKMAP, false) {
public void run(boolean newState) { public void run(final boolean newState) {
toggleMode( toggleMode(
BCOConstants.F_SHOW_STACKMAP, newState, BCOConstants.F_SHOW_STACKMAP, newState,
toggleAsmifierModeAction.isChecked()); toggleAsmifierModeAction.isChecked());
...@@ -97,9 +97,9 @@ public class BytecodeCompare extends CompareEditorInput { ...@@ -97,9 +97,9 @@ public class BytecodeCompare extends CompareEditorInput {
}; };
expandStackMapAction = new DefaultToggleAction( expandStackMapAction = new DefaultToggleAction(
BCOConstants.DIFF_EXPAND_STACKMAP) { BCOConstants.DIFF_EXPAND_STACKMAP, false) {
public void run(boolean newState) { public void run(final boolean newState) {
toggleMode( toggleMode(
BCOConstants.F_EXPAND_STACKMAP, newState, BCOConstants.F_EXPAND_STACKMAP, newState,
toggleAsmifierModeAction.isChecked()); toggleAsmifierModeAction.isChecked());
...@@ -108,7 +108,7 @@ public class BytecodeCompare extends CompareEditorInput { ...@@ -108,7 +108,7 @@ public class BytecodeCompare extends CompareEditorInput {
} }
/** @see CompareEditorInput#prepareInput(IProgressMonitor) */ /** @see CompareEditorInput#prepareInput(IProgressMonitor) */
protected Object prepareInput(IProgressMonitor monitor) protected Object prepareInput(final IProgressMonitor monitor)
throws InterruptedException { throws InterruptedException {
if (right == null || left == null) { if (right == null || left == null) {
return null; return null;
...@@ -190,7 +190,7 @@ public class BytecodeCompare extends CompareEditorInput { ...@@ -190,7 +190,7 @@ public class BytecodeCompare extends CompareEditorInput {
/** /**
* @see org.eclipse.compare.CompareEditorInput#createContents(org.eclipse.swt.widgets.Composite) * @see org.eclipse.compare.CompareEditorInput#createContents(org.eclipse.swt.widgets.Composite)
*/ */
public Control createContents(Composite parent) { public Control createContents(final Composite parent) {
Object obj = parent.getData(); Object obj = parent.getData();
if(obj == null) { if(obj == null) {
obj = parent.getParent().getData(); obj = parent.getParent().getData();
...@@ -265,7 +265,7 @@ public class BytecodeCompare extends CompareEditorInput { ...@@ -265,7 +265,7 @@ public class BytecodeCompare extends CompareEditorInput {
return control; return control;
} }
protected void toggleMode(int mode, boolean value, boolean isASMifierMode) { protected void toggleMode(final int mode, final boolean value, final boolean isASMifierMode) {
String contentType = isASMifierMode String contentType = isASMifierMode
? TypedElement.TYPE_ASM_IFIER ? TypedElement.TYPE_ASM_IFIER
: TypedElement.TYPE_BYTECODE; : TypedElement.TYPE_BYTECODE;
......
...@@ -27,33 +27,52 @@ import de.loskutov.bco.BytecodeOutlinePlugin; ...@@ -27,33 +27,52 @@ import de.loskutov.bco.BytecodeOutlinePlugin;
public abstract class DefaultToggleAction extends Action implements IPropertyChangeListener { public abstract class DefaultToggleAction extends Action implements IPropertyChangeListener {
private static final String ACTION = "action"; private static final String ACTION = "action";
boolean avoidUpdate;
private final IPreferenceStore store;
public DefaultToggleAction(String id) { public DefaultToggleAction(final String id) {
this(id, false);
}
public DefaultToggleAction(final String id, final boolean addPreferenceListener) {
super(); super();
setId(id); setId(id);
init(); init();
IPreferenceStore store = BytecodeOutlinePlugin.getDefault().getPreferenceStore(); IPreferenceStore prefStore = BytecodeOutlinePlugin.getDefault().getPreferenceStore();
boolean isChecked = store.getBoolean(id); boolean isChecked = prefStore.getBoolean(id);
setChecked(isChecked); setChecked(isChecked);
store.addPropertyChangeListener(this); if(addPreferenceListener) {
this.store = prefStore;
prefStore.addPropertyChangeListener(this);
} else {
this.store = null;
}
} }
public void propertyChange(PropertyChangeEvent event){ public void propertyChange(final PropertyChangeEvent event){
if(store == null){
return;
}
String id = getId(); String id = getId();
if(!id.equals(event.getProperty())){ if(!id.equals(event.getProperty())){
return; return;
} }
IPreferenceStore store = BytecodeOutlinePlugin.getDefault().getPreferenceStore();
boolean isChecked = store.getBoolean(id); boolean isChecked = store.getBoolean(id);
setChecked(isChecked); setChecked(isChecked);
run(isChecked); // The action state can be changed from preference page (therefore run()), but...
// see http://forge.objectweb.org/tracker/?func=detail&atid=100023&aid=311888&group_id=23
// this causes multiple unneeded re-syncs of the compare editor
if(!avoidUpdate) {
run(isChecked);
}
} }
public void dispose(){ public void dispose(){
IPreferenceStore store = BytecodeOutlinePlugin.getDefault().getPreferenceStore(); if(store != null) {
store.removePropertyChangeListener(this); store.removePropertyChangeListener(this);
}
} }
private void init(){ private void init(){
...@@ -79,8 +98,10 @@ public abstract class DefaultToggleAction extends Action implements IPropertyCha ...@@ -79,8 +98,10 @@ public abstract class DefaultToggleAction extends Action implements IPropertyCha
*/ */
public final void run() { public final void run() {
boolean isChecked = isChecked(); boolean isChecked = isChecked();
IPreferenceStore store = BytecodeOutlinePlugin.getDefault().getPreferenceStore(); avoidUpdate = true;
store.setValue(getId(), isChecked); // compare dialog: we use store as global variables to remember the state
BytecodeOutlinePlugin.getDefault().getPreferenceStore().setValue(getId(), isChecked);
avoidUpdate = false;
run(isChecked); run(isChecked);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment