eclipse plugin: Rework a bit the current setup workspace routine...

...to take in account the default install when creating the projects
This commit is contained in:
Timotei Dolean 2011-07-30 07:56:30 +00:00
parent d9289cc9ea
commit 1938c0a189
5 changed files with 57 additions and 23 deletions

View file

@ -144,7 +144,7 @@ public class Preferences extends AbstractPreferenceInitializer
Paths paths = paths_.get( installName );
if ( paths == null ) {
paths = new Paths( getInstallPrefix( installName ) );
paths = new Paths( installName, getInstallPrefix( installName ) );
paths_.put( installName, paths );
}
@ -158,10 +158,21 @@ public class Preferences extends AbstractPreferenceInitializer
public static class Paths
{
private String installPrefix_;
private String installName_;
public Paths( String installPrefix )
public Paths( String installName, String installPrefix )
{
installPrefix_ = installPrefix;
installName_ = installName;
}
/**
* Returns the install name associated with this instance
* @return A string representing the install name
*/
public String getInstallName()
{
return installName_;
}
/**

View file

@ -51,6 +51,7 @@ import org.wesnoth.Constants;
import org.wesnoth.Logger;
import org.wesnoth.Messages;
import org.wesnoth.builder.DependencyListNode;
import org.wesnoth.preferences.Preferences.Paths;
import org.wesnoth.projects.ProjectUtils;
import org.wesnoth.templates.ReplaceableParameter;
import org.wesnoth.templates.TemplateProvider;
@ -324,6 +325,34 @@ public class ResourceUtils
return valid;
}
/**
* Checks if the specified path is in the user's addons directory
* @param paths The paths to use when doing the check
* @param path The path to check
* @return True if the path is in user's addons
*/
public static boolean isUserAddonsDirPath( Paths paths, String path ) {
if ( StringUtils.isNullOrEmpty( path ) )
return false;
return StringUtils.normalizePath( path ).contains(
StringUtils.normalizePath( paths.getAddonsDir( ) ) );
}
/**
* Checks if the specified path is in the campaigns directory
* @param paths The paths to use when doing the check
* @param path The path to check
* @return True if the path is in data/campaigns directory
*/
public static boolean isCampaignDirPath( Paths paths, String path ) {
if ( StringUtils.isNullOrEmpty( path ) )
return false;
return StringUtils.normalizePath( path ).contains(
StringUtils.normalizePath( paths.getCampaignDir( ) ) );
}
/**
* Returns true if the resource is a WML config file
* @param resource The resource to check

View file

@ -178,7 +178,7 @@ public class StringUtils
}
/**
* Normalizez the path given by the string, removing repeated separators
* Normalizes the path given by the string, removing repeated separators
* and replacing them by '|'
*
* @param path the string that represents the path to be normalized

View file

@ -13,7 +13,7 @@ import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.widgets.Shell;
import org.wesnoth.WesnothPlugin;
import org.wesnoth.wizards.NewWizardTemplate;
import org.wesnoth.wizards.WizardTemplate;
public class WizardUtils
@ -25,7 +25,7 @@ public class WizardUtils
* @param selection The current selection
* @return
*/
public static int launchWizard(NewWizardTemplate wizard, Shell shell,
public static int launchWizard(WizardTemplate wizard, Shell shell,
IStructuredSelection selection)
{
if (wizard == null)

View file

@ -41,6 +41,7 @@ import org.wesnoth.WesnothPlugin;
import org.wesnoth.installs.WesnothInstallsUtils;
import org.wesnoth.navigator.WesnothProjectsExplorer;
import org.wesnoth.preferences.Preferences;
import org.wesnoth.preferences.Preferences.Paths;
import org.wesnoth.projects.ProjectUtils;
public class WorkspaceUtils
@ -347,44 +348,37 @@ public class WorkspaceUtils
try
{
// automatically import 'special' folders as projects
List<File> files = new ArrayList<File>();
String addonsDir = Preferences.getPaths( null ).getAddonsDir( );
String campaignsDir = Preferences.getPaths( null ).getCampaignDir( );
List<File> userAddonsFiles = new ArrayList<File>();
Paths paths = Preferences.getPaths( Preferences.getDefaultInstallName( ) );
if (GUIUtils.showMessageBox( Messages.WorkspaceUtils_18 ,
SWT.ICON_QUESTION | SWT.YES | SWT.NO) == SWT.YES)
{
// useraddons/add-ons/data
File[] tmp = new File(addonsDir).listFiles();
File[] tmp = new File( paths.getAddonsDir( ) ).listFiles();
if (tmp != null)
files.addAll(Arrays.asList(tmp));
userAddonsFiles.addAll(Arrays.asList(tmp));
}
if (GUIUtils.showMessageBox( Messages.WorkspaceUtils_20 ,
SWT.ICON_QUESTION | SWT.YES | SWT.NO) == SWT.YES)
{
// workingdir/data/campaigns
File[] tmp = new File(campaignsDir).listFiles();
if (tmp != null)
files.addAll(Arrays.asList(tmp));
}
monitor.beginTask( Messages.WorkspaceUtils_22,
userAddonsFiles.size() * 10 );
monitor.beginTask(Messages.WorkspaceUtils_22, files.size() * 35);
for(File file: files)
for( File file: userAddonsFiles )
{
if (file.isDirectory() == false ||
file.getName().startsWith(".")) //$NON-NLS-1$
continue;
String projectName = file.getName();
if (StringUtils.normalizePath(file.getAbsolutePath()).contains(
StringUtils.normalizePath(campaignsDir)))
if ( ResourceUtils.isCampaignDirPath( paths,
file.getAbsolutePath( ) ) )
{
projectName = "_Mainline_" + file.getName(); //$NON-NLS-1$
}
ProjectUtils.createWesnothProject( projectName,
file.getAbsolutePath( ), false, monitor );
file.getAbsolutePath( ), paths.getInstallName( ),
monitor );
}
if (guided)