mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-13 12:05:21 +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;
|
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.jface.dialogs.IDialogSettings;
|
||||||
import org.eclipse.tm.terminal.ISettingsStore;
|
import org.eclipse.tm.terminal.ISettingsStore;
|
||||||
|
import org.eclipse.ui.IMemento;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link IDialogSettings} based {@link ISettingsStore}.
|
* 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
|
* @author Michael Scharf
|
||||||
*/
|
*/
|
||||||
class SettingsStore implements ISettingsStore {
|
class SettingsStore implements ISettingsStore {
|
||||||
final private IDialogSettings fDialogSettings;
|
|
||||||
final private String fPrefix;
|
private static final String KEYS = "_keys_";
|
||||||
public SettingsStore(String terminalPartName) {
|
final private Map fMap=new HashMap();
|
||||||
fDialogSettings=TerminalViewPlugin.getDefault().getDialogSettings();
|
public SettingsStore(IMemento memento) {
|
||||||
fPrefix=getClass().getName() + "." + terminalPartName + "."; //$NON-NLS-1$ //$NON-NLS-2$;
|
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) {
|
public String get(String key) {
|
||||||
return get(key,null);
|
return get(key,null);
|
||||||
}
|
}
|
||||||
public String get(String key, String defaultValue) {
|
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$
|
if ((value == null) || (value.equals(""))) //$NON-NLS-1$
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void put(String key, String strValue) {
|
public void put(String key, String value) {
|
||||||
fDialogSettings.put(fPrefix + key , strValue);
|
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.TerminalActionSelectAll;
|
||||||
import org.eclipse.tm.terminal.internal.actions.TerminalActionSettings;
|
import org.eclipse.tm.terminal.internal.actions.TerminalActionSettings;
|
||||||
import org.eclipse.ui.IActionBars;
|
import org.eclipse.ui.IActionBars;
|
||||||
|
import org.eclipse.ui.IMemento;
|
||||||
|
import org.eclipse.ui.IViewSite;
|
||||||
import org.eclipse.ui.IWorkbench;
|
import org.eclipse.ui.IWorkbench;
|
||||||
import org.eclipse.ui.IWorkbenchActionConstants;
|
import org.eclipse.ui.IWorkbenchActionConstants;
|
||||||
import org.eclipse.ui.IWorkbenchPage;
|
import org.eclipse.ui.IWorkbenchPage;
|
||||||
|
@ -66,9 +68,6 @@ import org.eclipse.ui.part.ViewPart;
|
||||||
|
|
||||||
public class TerminalView extends ViewPart implements ITerminalView, ITerminalListener {
|
public class TerminalView extends ViewPart implements ITerminalView, ITerminalListener {
|
||||||
public static final String FONT_DEFINITION = "terminal.views.view.font.definition"; //$NON-NLS-1$
|
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;
|
protected ITerminalViewControl fCtlTerminal;
|
||||||
|
|
||||||
|
@ -96,7 +95,7 @@ public class TerminalView extends ViewPart implements ITerminalView, ITerminalLi
|
||||||
|
|
||||||
protected boolean fMenuAboutToShow;
|
protected boolean fMenuAboutToShow;
|
||||||
|
|
||||||
private ISettingsStore fStore;
|
private SettingsStore fStore;
|
||||||
|
|
||||||
/** Remember the item with which we contributed the shortcut to unregister them again! */
|
/** Remember the item with which we contributed the shortcut to unregister them again! */
|
||||||
private IContextActivation fRememberedContextActivation;
|
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.
|
// When the settings dialog is closed, we persist the Terminal settings.
|
||||||
|
|
||||||
saveSettings();
|
saveSettings(dlgTerminalSettings.getConnector());
|
||||||
return dlgTerminalSettings.getConnector();
|
return dlgTerminalSettings.getConnector();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -348,9 +347,7 @@ public class TerminalView extends ViewPart implements ITerminalView, ITerminalLi
|
||||||
IContextService ctxtService = (IContextService) getSite().getService(IContextService.class);
|
IContextService ctxtService = (IContextService) getSite().getService(IContextService.class);
|
||||||
fRememberedContextActivation = ctxtService.activateContext("org.eclipse.tm.terminal.TerminalPreferencePage"); //$NON-NLS-1$
|
fRememberedContextActivation = ctxtService.activateContext("org.eclipse.tm.terminal.TerminalPreferencePage"); //$NON-NLS-1$
|
||||||
|
|
||||||
synchronized (fSecondaryTerminalCountMutex) {
|
setPartName(ViewMessages.PROP_TITLE);
|
||||||
setPartName(ViewMessages.PROP_TITLE + " " + fSecondaryTerminalCount++); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
setupControls(wndParent);
|
setupControls(wndParent);
|
||||||
setupActions();
|
setupActions();
|
||||||
|
@ -412,31 +409,34 @@ public class TerminalView extends ViewPart implements ITerminalView, ITerminalLi
|
||||||
protected void setupControls(Composite wndParent) {
|
protected void setupControls(Composite wndParent) {
|
||||||
ITerminalConnector[] connectors=TerminalConnectorExtension.getTerminalConnectors();
|
ITerminalConnector[] connectors=TerminalConnectorExtension.getTerminalConnectors();
|
||||||
fCtlTerminal = TerminalViewControlFactory.makeControl(this, wndParent, connectors);
|
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++) {
|
for (int i = 0; i < connectors.length; i++) {
|
||||||
connectors[i].load(getStore(connectors[i]));
|
connectors[i].load(getStore(connectors[i]));
|
||||||
if(connectors[i].getId().equals(connectionType))
|
if(connectors[i].getId().equals(connectionType))
|
||||||
fCtlTerminal.setConnector(connectors[i]);
|
fCtlTerminal.setConnector(connectors[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void saveSettings() {
|
private void saveSettings(ITerminalConnector connector) {
|
||||||
ITerminalConnector[] connectors=fCtlTerminal.getConnectors();
|
ITerminalConnector[] connectors=fCtlTerminal.getConnectors();
|
||||||
for (int i = 0; i < connectors.length; i++) {
|
for (int i = 0; i < connectors.length; i++) {
|
||||||
connectors[i].save(getStore(connectors[i]));
|
connectors[i].save(getStore(connectors[i]));
|
||||||
}
|
}
|
||||||
if(fCtlTerminal.getTerminalConnection()!=null) {
|
if(connector!=null) {
|
||||||
getStore().put("ConnectionType",fCtlTerminal.getTerminalConnection().getId()); //$NON-NLS-1$
|
fStore.put("ConnectionType",connector.getId()); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ISettingsStore getStore() {
|
public void init(IViewSite site, IMemento memento) throws PartInitException {
|
||||||
if(fStore==null)
|
super.init(site, memento);
|
||||||
fStore=new SettingsStore(getPartName());
|
fStore=new SettingsStore(memento);
|
||||||
return fStore;
|
}
|
||||||
|
|
||||||
|
public void saveState(IMemento memento) {
|
||||||
|
super.saveState(memento);
|
||||||
|
fStore.saveState(memento);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ISettingsStore getStore(ITerminalConnector connector) {
|
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() {
|
protected void setupActions() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue