mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-03 23:25:26 +02:00
FIXED - bug 165984: [terminal] store view data in memento and not in dialog settings
https://bugs.eclipse.org/bugs/show_bug.cgi?id=165984
This commit is contained in:
parent
a72bc9ed55
commit
f34c344f00
2 changed files with 93 additions and 27 deletions
|
@ -10,35 +10,101 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.tm.terminal.internal.view;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jface.dialogs.IDialogSettings;
|
||||
import org.eclipse.tm.terminal.ISettingsStore;
|
||||
import org.eclipse.ui.IMemento;
|
||||
|
||||
/**
|
||||
* A {@link IDialogSettings} based {@link ISettingsStore}.
|
||||
*
|
||||
* Setting Store dased on IMemento. IMemento documentations says only alpha numeric
|
||||
* values mey be used as keys. Therefore the implementation converts dots (.) into
|
||||
* child elements of the memento.
|
||||
*
|
||||
* @author Michael Scharf
|
||||
*/
|
||||
class SettingsStore implements ISettingsStore {
|
||||
final private IDialogSettings fDialogSettings;
|
||||
final private String fPrefix;
|
||||
public SettingsStore(String terminalPartName) {
|
||||
fDialogSettings=TerminalViewPlugin.getDefault().getDialogSettings();
|
||||
fPrefix=getClass().getName() + "." + terminalPartName + "."; //$NON-NLS-1$ //$NON-NLS-2$;
|
||||
|
||||
private static final String KEYS = "_keys_";
|
||||
final private Map fMap=new HashMap();
|
||||
public SettingsStore(IMemento memento) {
|
||||
if(memento==null)
|
||||
return;
|
||||
// load all keys ever used from the memento
|
||||
String keys=memento.getString(KEYS);
|
||||
if(keys!=null) {
|
||||
String[] keyNames=keys.split(",");
|
||||
for (int i = 0; i < keyNames.length; i++) {
|
||||
String key=keyNames[i];
|
||||
if(!KEYS.equals(key)) {
|
||||
// get the dot separated elements
|
||||
String[] path=key.split("\\.");
|
||||
IMemento m=memento;
|
||||
// iterate over all but the last segment and get the children...
|
||||
for(int iPath=0; m!=null && iPath+1<path.length; iPath++) {
|
||||
m=m.getChild(path[iPath]);
|
||||
}
|
||||
if(m!=null) {
|
||||
// cache the value in the map
|
||||
fMap.put(key,m.getString(path[path.length-1]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String get(String key) {
|
||||
return get(key,null);
|
||||
}
|
||||
public String get(String key, String defaultValue) {
|
||||
String value = fDialogSettings.get(fPrefix + key);
|
||||
|
||||
String value = (String) fMap.get(key);
|
||||
if ((value == null) || (value.equals(""))) //$NON-NLS-1$
|
||||
return defaultValue;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public void put(String key, String strValue) {
|
||||
fDialogSettings.put(fPrefix + key , strValue);
|
||||
public void put(String key, String value) {
|
||||
if(!key.matches("^[\\w.]+$"))
|
||||
throw new IllegalArgumentException("Key '"+key+"' is not alpha numeric or '.'!");
|
||||
// null values remove the key from the map
|
||||
if ((value == null) || (value.equals(""))) //$NON-NLS-1$
|
||||
fMap.remove(key);
|
||||
else
|
||||
fMap.put(key, value);
|
||||
}
|
||||
/**
|
||||
* Save the state into memento.
|
||||
* @param memento
|
||||
*/
|
||||
public void saveState(IMemento memento) {
|
||||
String[] keyNames=(String[]) fMap.keySet().toArray(new String[fMap.size()]);
|
||||
Arrays.sort(keyNames);
|
||||
StringBuffer buffer=new StringBuffer();
|
||||
for (int i = 0; i < keyNames.length; i++) {
|
||||
String key=keyNames[i];
|
||||
String[] path=key.split("\\.");
|
||||
IMemento m=memento;
|
||||
// iterate over all but the last segment and get the children...
|
||||
for(int iPath=0; iPath+1<path.length; iPath++) {
|
||||
IMemento child=m.getChild(path[iPath]);
|
||||
// if the child does not exist, create it
|
||||
if(child==null)
|
||||
child=m.createChild(path[iPath]);
|
||||
m=child;
|
||||
}
|
||||
// use the last element in path as key of the child memento
|
||||
m.putString(path[path.length], (String) fMap.get(key));
|
||||
// construct the string for the keys
|
||||
if(i>0)
|
||||
buffer.append(",");
|
||||
buffer.append(key);
|
||||
}
|
||||
// save the keys we have used.
|
||||
memento.putString(KEYS, buffer.toString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,6 +53,8 @@ import org.eclipse.tm.terminal.internal.actions.TerminalActionPaste;
|
|||
import org.eclipse.tm.terminal.internal.actions.TerminalActionSelectAll;
|
||||
import org.eclipse.tm.terminal.internal.actions.TerminalActionSettings;
|
||||
import org.eclipse.ui.IActionBars;
|
||||
import org.eclipse.ui.IMemento;
|
||||
import org.eclipse.ui.IViewSite;
|
||||
import org.eclipse.ui.IWorkbench;
|
||||
import org.eclipse.ui.IWorkbenchActionConstants;
|
||||
import org.eclipse.ui.IWorkbenchPage;
|
||||
|
@ -66,9 +68,6 @@ import org.eclipse.ui.part.ViewPart;
|
|||
|
||||
public class TerminalView extends ViewPart implements ITerminalView, ITerminalListener {
|
||||
public static final String FONT_DEFINITION = "terminal.views.view.font.definition"; //$NON-NLS-1$
|
||||
protected static final String fSecondaryTerminalCountMutex = ""; //$NON-NLS-1$
|
||||
|
||||
protected static int fSecondaryTerminalCount = 0;
|
||||
|
||||
protected ITerminalViewControl fCtlTerminal;
|
||||
|
||||
|
@ -96,7 +95,7 @@ public class TerminalView extends ViewPart implements ITerminalView, ITerminalLi
|
|||
|
||||
protected boolean fMenuAboutToShow;
|
||||
|
||||
private ISettingsStore fStore;
|
||||
private SettingsStore fStore;
|
||||
|
||||
/** Remember the item with which we contributed the shortcut to unregister them again! */
|
||||
private IContextActivation fRememberedContextActivation;
|
||||
|
@ -214,7 +213,7 @@ public class TerminalView extends ViewPart implements ITerminalView, ITerminalLi
|
|||
|
||||
// When the settings dialog is closed, we persist the Terminal settings.
|
||||
|
||||
saveSettings();
|
||||
saveSettings(dlgTerminalSettings.getConnector());
|
||||
return dlgTerminalSettings.getConnector();
|
||||
}
|
||||
|
||||
|
@ -348,9 +347,7 @@ public class TerminalView extends ViewPart implements ITerminalView, ITerminalLi
|
|||
IContextService ctxtService = (IContextService) getSite().getService(IContextService.class);
|
||||
fRememberedContextActivation = ctxtService.activateContext("org.eclipse.tm.terminal.TerminalPreferencePage"); //$NON-NLS-1$
|
||||
|
||||
synchronized (fSecondaryTerminalCountMutex) {
|
||||
setPartName(ViewMessages.PROP_TITLE + " " + fSecondaryTerminalCount++); //$NON-NLS-1$
|
||||
}
|
||||
setPartName(ViewMessages.PROP_TITLE);
|
||||
|
||||
setupControls(wndParent);
|
||||
setupActions();
|
||||
|
@ -412,31 +409,34 @@ public class TerminalView extends ViewPart implements ITerminalView, ITerminalLi
|
|||
protected void setupControls(Composite wndParent) {
|
||||
ITerminalConnector[] connectors=TerminalConnectorExtension.getTerminalConnectors();
|
||||
fCtlTerminal = TerminalViewControlFactory.makeControl(this, wndParent, connectors);
|
||||
String connectionType=getStore().get("ConnectionType"); //$NON-NLS-1$
|
||||
String connectionType=fStore.get("ConnectionType"); //$NON-NLS-1$
|
||||
for (int i = 0; i < connectors.length; i++) {
|
||||
connectors[i].load(getStore(connectors[i]));
|
||||
if(connectors[i].getId().equals(connectionType))
|
||||
fCtlTerminal.setConnector(connectors[i]);
|
||||
}
|
||||
}
|
||||
private void saveSettings() {
|
||||
private void saveSettings(ITerminalConnector connector) {
|
||||
ITerminalConnector[] connectors=fCtlTerminal.getConnectors();
|
||||
for (int i = 0; i < connectors.length; i++) {
|
||||
connectors[i].save(getStore(connectors[i]));
|
||||
}
|
||||
if(fCtlTerminal.getTerminalConnection()!=null) {
|
||||
getStore().put("ConnectionType",fCtlTerminal.getTerminalConnection().getId()); //$NON-NLS-1$
|
||||
if(connector!=null) {
|
||||
fStore.put("ConnectionType",connector.getId()); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
private ISettingsStore getStore() {
|
||||
if(fStore==null)
|
||||
fStore=new SettingsStore(getPartName());
|
||||
return fStore;
|
||||
public void init(IViewSite site, IMemento memento) throws PartInitException {
|
||||
super.init(site, memento);
|
||||
fStore=new SettingsStore(memento);
|
||||
}
|
||||
|
||||
public void saveState(IMemento memento) {
|
||||
super.saveState(memento);
|
||||
fStore.saveState(memento);
|
||||
}
|
||||
|
||||
private ISettingsStore getStore(ITerminalConnector connector) {
|
||||
return new SettingStorePrefixDecorator(getStore(),connector.getClass().getName()+"."); //$NON-NLS-1$
|
||||
return new SettingStorePrefixDecorator(fStore,connector.getClass().getName()+"."); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
protected void setupActions() {
|
||||
|
|
Loading…
Add table
Reference in a new issue