eclipse plugin: Add button for letting the user...
...clear all plugin's preferences
This commit is contained in:
parent
cf073f820c
commit
5c39513c85
3 changed files with 166 additions and 45 deletions
|
@ -29,40 +29,45 @@ public class Preferences extends AbstractPreferenceInitializer
|
|||
protected final static Map< String, Paths > paths_ =
|
||||
new HashMap< String, Paths > ();
|
||||
|
||||
public static void initializeToDefault()
|
||||
{
|
||||
IPreferenceStore store = WesnothPlugin.getDefault().getPreferenceStore();
|
||||
// general settings
|
||||
store.setDefault(Constants.P_WESNOTH_EXEC_PATH, ""); //$NON-NLS-1$
|
||||
store.setDefault(Constants.P_WESNOTH_WORKING_DIR, ""); //$NON-NLS-1$
|
||||
store.setDefault(Constants.P_WESNOTH_USER_DIR, ""); //$NON-NLS-1$
|
||||
store.setDefault(Constants.P_WESNOTH_WMLTOOLS_DIR, ""); //$NON-NLS-1$
|
||||
store.setDefault(Constants.P_PYTHON_PATH, ""); //$NON-NLS-1$
|
||||
|
||||
// wml tools
|
||||
store.setDefault(Constants.P_WMLINDENT_VERBOSE, true);
|
||||
store.setDefault(Constants.P_WMLINDENT_DRYRUN, true);
|
||||
|
||||
store.setDefault(Constants.P_WMLLINT_DRYRUN, true);
|
||||
store.setDefault(Constants.P_WMLLINT_SPELL_CHECK, false);
|
||||
store.setDefault(Constants.P_WMLLINT_VERBOSE_LEVEL, 0);
|
||||
|
||||
store.setDefault(Constants.P_WMLSCOPE_VERBOSE_LEVEL, 0);
|
||||
store.setDefault(Constants.P_WMLSCOPE_COLLISIONS, false);
|
||||
|
||||
// upload manager
|
||||
store.setDefault(Constants.P_WAU_PASSWORD, ""); //$NON-NLS-1$
|
||||
store.setDefault(Constants.P_WAU_VERBOSE, false);
|
||||
store.setDefault(Constants.P_WAU_ADDRESS, "add-ons.wesnoth.org"); //$NON-NLS-1$
|
||||
store.setDefault(Constants.P_WAU_PORT, 15002);
|
||||
|
||||
// advanced
|
||||
store.setDefault(Constants.P_ADV_NO_TERRAIN_GFX, true);
|
||||
|
||||
// installs
|
||||
store.setDefault(Constants.P_INST_DEFAULT_INSTALL, ""); //$NON-NLS-1$
|
||||
store.setDefault(Constants.P_INST_INSTALL_LIST, ""); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeDefaultPreferences()
|
||||
{
|
||||
IPreferenceStore store = WesnothPlugin.getDefault().getPreferenceStore();
|
||||
// general settings
|
||||
store.setDefault(Constants.P_WESNOTH_EXEC_PATH, ""); //$NON-NLS-1$
|
||||
store.setDefault(Constants.P_WESNOTH_WORKING_DIR, ""); //$NON-NLS-1$
|
||||
store.setDefault(Constants.P_WESNOTH_USER_DIR, ""); //$NON-NLS-1$
|
||||
store.setDefault(Constants.P_WESNOTH_WMLTOOLS_DIR, ""); //$NON-NLS-1$
|
||||
store.setDefault(Constants.P_PYTHON_PATH, ""); //$NON-NLS-1$
|
||||
|
||||
// wml tools
|
||||
store.setDefault(Constants.P_WMLINDENT_VERBOSE, true);
|
||||
store.setDefault(Constants.P_WMLINDENT_DRYRUN, true);
|
||||
|
||||
store.setDefault(Constants.P_WMLLINT_DRYRUN, true);
|
||||
store.setDefault(Constants.P_WMLLINT_SPELL_CHECK, false);
|
||||
store.setDefault(Constants.P_WMLLINT_VERBOSE_LEVEL, 0);
|
||||
|
||||
store.setDefault(Constants.P_WMLSCOPE_VERBOSE_LEVEL, 0);
|
||||
store.setDefault(Constants.P_WMLSCOPE_COLLISIONS, false);
|
||||
|
||||
// upload manager
|
||||
store.setDefault(Constants.P_WAU_PASSWORD, ""); //$NON-NLS-1$
|
||||
store.setDefault(Constants.P_WAU_VERBOSE, false);
|
||||
store.setDefault(Constants.P_WAU_ADDRESS, "add-ons.wesnoth.org"); //$NON-NLS-1$
|
||||
store.setDefault(Constants.P_WAU_PORT, 15002);
|
||||
|
||||
// advanced
|
||||
store.setDefault(Constants.P_ADV_NO_TERRAIN_GFX, true);
|
||||
|
||||
// installs
|
||||
store.setDefault(Constants.P_INST_DEFAULT_INSTALL, ""); //$NON-NLS-1$
|
||||
store.setDefault(Constants.P_INST_INSTALL_LIST, ""); //$NON-NLS-1$
|
||||
initializeToDefault( );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,22 +8,28 @@
|
|||
*******************************************************************************/
|
||||
package org.wesnoth.preferences;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.wesnoth.Logger;
|
||||
import org.wesnoth.Messages;
|
||||
import org.wesnoth.WesnothPlugin;
|
||||
import org.wesnoth.utils.GUIUtils;
|
||||
import org.wesnoth.utils.ResourceUtils;
|
||||
import org.wesnoth.utils.WorkspaceUtils;
|
||||
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.events.SelectionListener;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
|
||||
import org.osgi.service.prefs.BackingStoreException;
|
||||
|
||||
/**
|
||||
* This class represents a preference page that
|
||||
* is contributed to the Preferences dialog. By
|
||||
* subclassing <samp>FieldEditorPreferencePage</samp>, we
|
||||
* can use the field support built into JFace that allows
|
||||
* us to create a page that is small and knows how to
|
||||
* save, restore and apply itself.
|
||||
* <p>
|
||||
* This page is used to modify preferences only. They
|
||||
* are stored in the preference store that belongs to
|
||||
* the main plug-in class. That way, preferences can
|
||||
* be accessed directly via the preference store.
|
||||
*/
|
||||
public class WesnothPreferencesPage extends AbstractPreferencePage
|
||||
{
|
||||
public WesnothPreferencesPage() {
|
||||
|
@ -31,11 +37,91 @@ public class WesnothPreferencesPage extends AbstractPreferencePage
|
|||
|
||||
setPreferenceStore(WesnothPlugin.getDefault().getPreferenceStore());
|
||||
setDescription(Messages.WesnothPreferencesPage_0);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createFieldEditors()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Control createContents( Composite parent )
|
||||
{
|
||||
Composite composite = new Composite( parent, SWT.NONE );
|
||||
composite.setLayout(new GridLayout(2, false));
|
||||
|
||||
Label lblPlugin = new Label( composite, SWT.NONE );
|
||||
lblPlugin.setText( "Reset all plugin's preferences: " );
|
||||
|
||||
Button buttonPlugin = new Button ( composite, SWT.NONE );
|
||||
buttonPlugin.setText( "Reset" );
|
||||
buttonPlugin.addSelectionListener( new SelectionListener( ) {
|
||||
|
||||
@Override
|
||||
public void widgetSelected( SelectionEvent e )
|
||||
{
|
||||
if ( GUIUtils.showMessageBox(
|
||||
"Are you sure you want to clear the plugin preferences?",
|
||||
SWT.YES | SWT.NO ) == SWT.NO )
|
||||
return;
|
||||
|
||||
// clear the preferences
|
||||
IEclipsePreferences root = Platform.getPreferencesService( ).getRootNode( );
|
||||
try {
|
||||
for ( String rootName : root.childrenNames( ) ) {
|
||||
|
||||
org.osgi.service.prefs.Preferences childNode = root.node( rootName );
|
||||
for ( String childName : childNode.childrenNames( ) ) {
|
||||
|
||||
org.osgi.service.prefs.Preferences node = childNode.node( childName );
|
||||
|
||||
if ( childName.startsWith( "org.wesnoth" ) ) {
|
||||
try {
|
||||
node.clear( );
|
||||
node.flush( );
|
||||
node.sync( );
|
||||
}
|
||||
catch ( BackingStoreException e1 ) {
|
||||
Logger.getInstance( ).logException( e1 );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Preferences.initializeToDefault( );
|
||||
}
|
||||
catch ( BackingStoreException e1 ) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
// clear the plugin's dirs
|
||||
File pluginDir = WesnothPlugin.getDefault( ).
|
||||
getStateLocation( ).toFile( ).getParentFile( );
|
||||
ResourceUtils.deleteDirectory(
|
||||
pluginDir.getAbsolutePath( ) + "/org.wesnoth" );
|
||||
ResourceUtils.deleteDirectory(
|
||||
pluginDir.getAbsolutePath( ) + "/org.wesnoth.ui" );
|
||||
|
||||
// clear the temporary files
|
||||
File[] files =
|
||||
new File( WorkspaceUtils.getTemporaryFolder( ) ).listFiles( );
|
||||
|
||||
for ( File file : files ) {
|
||||
// don't remove the logs
|
||||
if ( file.isDirectory( ) && file.getName( ).equals( "logs" ) )
|
||||
continue;
|
||||
|
||||
ResourceUtils.deleteDirectory( file );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void widgetDefaultSelected( SelectionEvent e )
|
||||
{
|
||||
}
|
||||
} );
|
||||
|
||||
return super.createContents(parent);
|
||||
}
|
||||
}
|
|
@ -196,6 +196,36 @@ public class ResourceUtils
|
|||
createResource(folder, project, folderName, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rercursively deletes a directory
|
||||
* @param path The directory's path
|
||||
* @return True if the delete was ok, false otherwise
|
||||
*/
|
||||
public static boolean deleteDirectory( File path )
|
||||
{
|
||||
if ( path == null || ! path.exists( ) )
|
||||
return false;
|
||||
|
||||
if ( ! path.isDirectory( ) )
|
||||
return path.delete( );
|
||||
|
||||
boolean res = true;
|
||||
for ( File file : path.listFiles( ) ) {
|
||||
res = res && deleteDirectory( file );
|
||||
}
|
||||
return res && path.delete( );
|
||||
}
|
||||
|
||||
/**
|
||||
* Rercursively deletes a directory
|
||||
* @param path The directory's path
|
||||
* @return True if the delete was ok, false otherwise
|
||||
*/
|
||||
public static boolean deleteDirectory( String path )
|
||||
{
|
||||
return deleteDirectory( new File( path ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a file in the specified project with the specified details
|
||||
* @param project the project in which the file will be created
|
||||
|
|
Loading…
Add table
Reference in a new issue