mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 01:15:29 +02:00
Bug 173792: Modules view needs to catch up with 3.3M5. Added ModuleMementoProvider.
This commit is contained in:
parent
ea377723db
commit
85fa4bbdc8
3 changed files with 181 additions and 26 deletions
|
@ -15,10 +15,13 @@ import org.eclipse.cdt.debug.core.model.ICModule;
|
|||
import org.eclipse.cdt.debug.core.model.IModuleRetrieval;
|
||||
import org.eclipse.cdt.debug.internal.ui.views.modules.ModuleContentProvider;
|
||||
import org.eclipse.cdt.debug.internal.ui.views.modules.ModuleLabelProvider;
|
||||
import org.eclipse.cdt.debug.internal.ui.views.modules.ModuleMementoProvider;
|
||||
import org.eclipse.cdt.debug.internal.ui.views.modules.ModuleProxyFactory;
|
||||
import org.eclipse.core.runtime.IAdapterFactory;
|
||||
import org.eclipse.debug.core.model.IStackFrame;
|
||||
import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementContentProvider;
|
||||
import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementLabelProvider;
|
||||
import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementMementoProvider;
|
||||
import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelProxyFactoryAdapter;
|
||||
|
||||
/**
|
||||
|
@ -29,7 +32,7 @@ public class CDebugElementAdapterFactory implements IAdapterFactory {
|
|||
private static IElementLabelProvider fgModuleLabelProvider = new ModuleLabelProvider();
|
||||
private static IElementContentProvider fgModuleContentProvider = new ModuleContentProvider();
|
||||
private static IModelProxyFactoryAdapter fgModuleProxyFactory = new ModuleProxyFactory();
|
||||
|
||||
private static IElementMementoProvider fgModuleMementoProvider = new ModuleMementoProvider();
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
|
||||
|
@ -62,6 +65,11 @@ public class CDebugElementAdapterFactory implements IAdapterFactory {
|
|||
return fgModuleProxyFactory;
|
||||
}
|
||||
}
|
||||
if ( adapterType.equals( IElementMementoProvider.class ) ) {
|
||||
if ( adaptableObject instanceof IModuleRetrieval ) {
|
||||
return fgModuleMementoProvider;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -72,7 +80,8 @@ public class CDebugElementAdapterFactory implements IAdapterFactory {
|
|||
return new Class[] {
|
||||
IElementLabelProvider.class,
|
||||
IElementContentProvider.class,
|
||||
IModelProxyFactoryAdapter.class
|
||||
IModelProxyFactoryAdapter.class,
|
||||
IElementMementoProvider.class,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 ARM and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* ARM - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.debug.internal.ui.views.modules;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.debug.core.CDIDebugModel;
|
||||
import org.eclipse.cdt.debug.core.model.ICModule;
|
||||
import org.eclipse.cdt.debug.core.model.IModuleRetrieval;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.debug.internal.ui.model.elements.ElementMementoProvider;
|
||||
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
|
||||
import org.eclipse.ui.IMemento;
|
||||
|
||||
/**
|
||||
* org.eclipse.cdt.debug.internal.ui.views.modules.ModuleMementoProvider:
|
||||
* //TODO Add description.
|
||||
*/
|
||||
public class ModuleMementoProvider extends ElementMementoProvider {
|
||||
|
||||
/**
|
||||
* memento attribute
|
||||
*/
|
||||
private static final String ELEMENT_NAME = "ELEMENT_NAME"; //$NON-NLS-1$
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.debug.internal.ui.model.elements.ElementMementoProvider#encodeElement(java.lang.Object, org.eclipse.ui.IMemento, org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext)
|
||||
*/
|
||||
protected boolean encodeElement( Object element, IMemento memento, IPresentationContext context ) throws CoreException {
|
||||
if ( element instanceof IModuleRetrieval ) {
|
||||
// attempt to maintain expansion for target ????
|
||||
memento.putString( ELEMENT_NAME, CDIDebugModel.getPluginIdentifier() );
|
||||
}
|
||||
else if ( element instanceof ICModule ) {
|
||||
memento.putString( ELEMENT_NAME, ((ICModule)element).getName() );
|
||||
}
|
||||
else if ( element instanceof ICElement ) {
|
||||
memento.putString( ELEMENT_NAME, ((ICElement)element).getElementName() );
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.debug.internal.ui.model.elements.ElementMementoProvider#isEqual(java.lang.Object, org.eclipse.ui.IMemento, org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext)
|
||||
*/
|
||||
protected boolean isEqual( Object element, IMemento memento, IPresentationContext context ) throws CoreException {
|
||||
String mementoName = memento.getString( ELEMENT_NAME );
|
||||
if ( mementoName != null ) {
|
||||
String elementName = null;
|
||||
if ( element instanceof IModuleRetrieval ) {
|
||||
elementName = CDIDebugModel.getPluginIdentifier();
|
||||
}
|
||||
else if ( element instanceof ICModule ) {
|
||||
elementName = ((ICModule)element).getName();
|
||||
}
|
||||
else if ( element instanceof ICElement ) {
|
||||
elementName = ((ICElement)element).getElementName();
|
||||
}
|
||||
if ( elementName != null ) {
|
||||
return elementName.equals( mementoName );
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -10,6 +10,11 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.debug.internal.ui.views.modules;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
|
@ -92,7 +97,10 @@ import org.eclipse.ui.IPerspectiveListener;
|
|||
import org.eclipse.ui.IViewSite;
|
||||
import org.eclipse.ui.IWorkbenchActionConstants;
|
||||
import org.eclipse.ui.IWorkbenchPage;
|
||||
import org.eclipse.ui.IWorkbenchPart;
|
||||
import org.eclipse.ui.PartInitException;
|
||||
import org.eclipse.ui.WorkbenchException;
|
||||
import org.eclipse.ui.XMLMemento;
|
||||
import org.eclipse.ui.actions.ActionFactory;
|
||||
import org.eclipse.ui.console.actions.TextViewerAction;
|
||||
import org.eclipse.ui.texteditor.IUpdate;
|
||||
|
@ -124,6 +132,18 @@ public class ModulesView extends AbstractDebugView implements IDebugContextListe
|
|||
interface ICursorListener extends MouseListener, KeyListener {
|
||||
}
|
||||
|
||||
protected String PREF_STATE_MEMENTO = "pref_state_memento."; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* the preference name for the view part of the sash form
|
||||
*/
|
||||
protected static final String SASH_VIEW_PART = CDebugUIPlugin.getUniqueIdentifier() + ".SASH_VIEW_PART"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* the preference name for the details part of the sash form
|
||||
*/
|
||||
protected static final String SASH_DETAILS_PART = CDebugUIPlugin.getUniqueIdentifier() + ".SASH_DETAILS_PART"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* The UI construct that provides a sliding sash between the modules tree
|
||||
* and the detail pane.
|
||||
|
@ -630,19 +650,17 @@ public class ModulesView extends AbstractDebugView implements IDebugContextListe
|
|||
fDetailViewer.getTextWidget().setWordWrap( on );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.ui.IViewPart#saveState(org.eclipse.ui.IMemento)
|
||||
/**
|
||||
* Saves the current state of the viewer
|
||||
* @param memento the memento to write the viewer state into
|
||||
*/
|
||||
public void saveState( IMemento memento ) {
|
||||
super.saveState( memento );
|
||||
SashForm sashForm = getSashForm();
|
||||
if ( sashForm != null ) {
|
||||
int[] weights = sashForm.getWeights();
|
||||
memento.putInteger( SASH_WEIGHTS + "-Length", weights.length ); //$NON-NLS-1$
|
||||
for( int i = 0; i < weights.length; i++ ) {
|
||||
memento.putInteger( SASH_WEIGHTS + "-" + i, weights[i] ); //$NON-NLS-1$
|
||||
}
|
||||
public void saveViewerState( IMemento memento ) {
|
||||
if ( fSashForm != null && !fSashForm.isDisposed() ) {
|
||||
int[] weights = fSashForm.getWeights();
|
||||
memento.putInteger( SASH_VIEW_PART, weights[0] );
|
||||
memento.putInteger( SASH_DETAILS_PART, weights[1] );
|
||||
}
|
||||
getModulesViewer().saveState( memento );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -650,22 +668,43 @@ public class ModulesView extends AbstractDebugView implements IDebugContextListe
|
|||
*/
|
||||
public void init( IViewSite site, IMemento memento ) throws PartInitException {
|
||||
super.init( site, memento );
|
||||
if ( memento != null ) {
|
||||
Integer bigI = memento.getInteger( SASH_WEIGHTS + "-Length" ); //$NON-NLS-1$
|
||||
if ( bigI == null ) {
|
||||
return;
|
||||
|
||||
PREF_STATE_MEMENTO = PREF_STATE_MEMENTO + site.getId();
|
||||
IPreferenceStore store = CDebugUIPlugin.getDefault().getPreferenceStore();
|
||||
String string = store.getString( PREF_STATE_MEMENTO );
|
||||
if ( string.length() > 0 ) {
|
||||
ByteArrayInputStream bin = new ByteArrayInputStream( string.getBytes() );
|
||||
InputStreamReader reader = new InputStreamReader( bin );
|
||||
try {
|
||||
XMLMemento stateMemento = XMLMemento.createReadRoot( reader );
|
||||
setMemento( stateMemento );
|
||||
}
|
||||
int numWeights = bigI.intValue();
|
||||
int[] weights = new int[numWeights];
|
||||
for( int i = 0; i < numWeights; i++ ) {
|
||||
bigI = memento.getInteger( SASH_WEIGHTS + "-" + i ); //$NON-NLS-1$
|
||||
if ( bigI == null ) {
|
||||
return;
|
||||
catch( WorkbenchException e ) {
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
reader.close();
|
||||
bin.close();
|
||||
}
|
||||
catch( IOException e ) {
|
||||
}
|
||||
weights[i] = bigI.intValue();
|
||||
}
|
||||
if ( weights.length > 0 ) {
|
||||
setLastSashWeights( weights );
|
||||
}
|
||||
|
||||
IMemento mem = getMemento();
|
||||
setLastSashWeights( DEFAULT_SASH_WEIGHTS );
|
||||
setLastSashWeights( DEFAULT_SASH_WEIGHTS );
|
||||
if ( mem != null ) {
|
||||
Integer sw = mem.getInteger( SASH_VIEW_PART );
|
||||
if ( sw != null ) {
|
||||
int view = sw.intValue();
|
||||
sw = mem.getInteger( SASH_DETAILS_PART );
|
||||
if ( sw != null ) {
|
||||
int details = sw.intValue();
|
||||
if ( view > -1 & details > -1 ) {
|
||||
setLastSashWeights( new int[] { view, details } );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
site.getWorkbenchWindow().addPerspectiveListener( this );
|
||||
|
@ -946,4 +985,36 @@ public class ModulesView extends AbstractDebugView implements IDebugContextListe
|
|||
manager.setErrorMessage( null );
|
||||
manager.setMessage( null );
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.ui.part.PageBookView#partDeactivated(org.eclipse.ui.IWorkbenchPart)
|
||||
*/
|
||||
public void partDeactivated( IWorkbenchPart part ) {
|
||||
String id = part.getSite().getId();
|
||||
if ( id.equals( getSite().getId() ) ) {
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
OutputStreamWriter writer = new OutputStreamWriter( bout );
|
||||
|
||||
try {
|
||||
XMLMemento memento = XMLMemento.createWriteRoot( "ModulesViewMemento" ); //$NON-NLS-1$
|
||||
saveViewerState( memento );
|
||||
memento.save( writer );
|
||||
|
||||
IPreferenceStore store = CDebugUIPlugin.getDefault().getPreferenceStore();
|
||||
String xmlString = bout.toString();
|
||||
store.putValue( PREF_STATE_MEMENTO, xmlString );
|
||||
}
|
||||
catch( IOException e ) {
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
writer.close();
|
||||
bout.close();
|
||||
}
|
||||
catch( IOException e ) {
|
||||
}
|
||||
}
|
||||
}
|
||||
super.partDeactivated( part );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue