Author: timotei
Date: Mon Aug 1 20:53:17 2011
New Revision: 50537
URL: http://svn.gna.org/viewcvs/wesnoth?rev=50537&view=rev
Log:
eclipse plugin: Add button for letting the user
clear all plugin's preferences
Modified:
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/preferences/Preferences.java
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/preferences/WesnothPreferencesPage.java
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/ResourceUtils.java
Modified:
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/preferences/Preferences.java
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/preferences/Preferences.java?rev=50537&r1=50536&r2=50537&view=diff
==============================================================================
---
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/preferences/Preferences.java
(original)
+++
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/preferences/Preferences.java
Mon Aug 1 20:53:17 2011
@@ -29,40 +29,45 @@
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( );
}
/**
Modified:
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/preferences/WesnothPreferencesPage.java
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/preferences/WesnothPreferencesPage.java?rev=50537&r1=50536&r2=50537&view=diff
==============================================================================
---
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/preferences/WesnothPreferencesPage.java
(original)
+++
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/preferences/WesnothPreferencesPage.java
Mon Aug 1 20:53:17 2011
@@ -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;
-/**
- * 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.
- */
+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;
+
public class WesnothPreferencesPage extends AbstractPreferencePage
{
public WesnothPreferencesPage() {
@@ -31,11 +37,91 @@
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);
+ }
}
Modified:
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/ResourceUtils.java
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/ResourceUtils.java?rev=50537&r1=50536&r2=50537&view=diff
==============================================================================
--- trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/ResourceUtils.java
(original)
+++ trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/ResourceUtils.java
Mon Aug 1 20:53:17 2011
@@ -197,6 +197,36 @@
}
/**
+ * 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
* @param fileName the filename of the file
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits