eclipse plugin: Implement the project properties page
This commit is contained in:
parent
7050ec20cc
commit
2901173cda
4 changed files with 65 additions and 6 deletions
|
@ -67,6 +67,7 @@ public class Constants
|
|||
/** Install preferences */
|
||||
public static final String P_INST_DEFAULT_INSTALL = "inst_default"; //$NON-NLS-1$
|
||||
public static final String P_INST_INSTALL_LIST = "inst_list"; //$NON-NLS-1$
|
||||
public static final String P_INST_NAME_PREFIX = "inst_name"; //$NON-NLS-1$
|
||||
|
||||
/** Wizards Constants **/
|
||||
public static final int WIZ_TextBoxHeight = 21;
|
||||
|
|
|
@ -2,6 +2,8 @@ package org.wesnoth.propertypages;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.layout.FillLayout;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
|
@ -13,19 +15,33 @@ import org.eclipse.swt.widgets.Group;
|
|||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.ui.IWorkbenchPropertyPage;
|
||||
import org.eclipse.ui.dialogs.PropertyPage;
|
||||
import org.wesnoth.utils.ProjectCache;
|
||||
import org.wesnoth.utils.ProjectUtils;
|
||||
import org.wesnoth.utils.WesnothInstallsUtils;
|
||||
import org.wesnoth.utils.WesnothInstallsUtils.WesnothInstall;
|
||||
|
||||
public class WesnothProjectPage extends PropertyPage implements IWorkbenchPropertyPage
|
||||
{
|
||||
private Combo cmbInstall_;
|
||||
private ProjectCache currProjectCache_;
|
||||
|
||||
public WesnothProjectPage()
|
||||
{
|
||||
currProjectCache_ = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Control createContents( Composite parent )
|
||||
{
|
||||
IAdaptable selectedElement = getElement( );
|
||||
if ( !( selectedElement instanceof IProject ) ) {
|
||||
return new Composite( parent, 0 );
|
||||
}
|
||||
|
||||
IProject selectedProject = (IProject) selectedElement;
|
||||
|
||||
currProjectCache_ = ProjectUtils.getCacheForProject( selectedProject );
|
||||
|
||||
Composite newComposite = new Composite( parent, 0 );
|
||||
newComposite.setLayout(new FillLayout(SWT.VERTICAL));
|
||||
|
||||
|
@ -45,12 +61,27 @@ public class WesnothProjectPage extends PropertyPage implements IWorkbenchProper
|
|||
// fill the installs
|
||||
List<WesnothInstall> installs = WesnothInstallsUtils.getInstalls( );
|
||||
|
||||
boolean foundInstallInList = false;
|
||||
String installName = currProjectCache_.getInstallName( );
|
||||
|
||||
for ( WesnothInstall wesnothInstall : installs )
|
||||
{
|
||||
if ( wesnothInstall.Name.equalsIgnoreCase( "Default" ) )
|
||||
continue;
|
||||
|
||||
cmbInstall_.add( wesnothInstall.Name );
|
||||
|
||||
// current install is default?
|
||||
if ( wesnothInstall.Name.equalsIgnoreCase( installName ) )
|
||||
{
|
||||
cmbInstall_.select( cmbInstall_.getItemCount( ) - 1 );
|
||||
foundInstallInList = true;
|
||||
}
|
||||
}
|
||||
|
||||
// check if the current install name is existing
|
||||
if ( !foundInstallInList && !installName.equalsIgnoreCase( "default" ) ) {
|
||||
setErrorMessage( "The currently selected install does not exist. Please select another." );
|
||||
}
|
||||
|
||||
return newComposite;
|
||||
|
@ -60,7 +91,9 @@ public class WesnothProjectPage extends PropertyPage implements IWorkbenchProper
|
|||
public boolean performOk()
|
||||
{
|
||||
// save settings.
|
||||
|
||||
if ( currProjectCache_ != null ){
|
||||
currProjectCache_.setInstallName( cmbInstall_.getText( ) );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,9 @@ import java.util.Map;
|
|||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.jface.dialogs.DialogSettings;
|
||||
import org.eclipse.jface.dialogs.IDialogSettings;
|
||||
import org.wesnoth.Constants;
|
||||
import org.wesnoth.Logger;
|
||||
import org.wesnoth.preferences.Preferences;
|
||||
import org.wesnoth.preprocessor.Define;
|
||||
import org.wesnoth.wml.core.ConfigFile;
|
||||
import org.wesnoth.wml.core.Variable;
|
||||
|
@ -39,8 +41,12 @@ public class ProjectCache
|
|||
private Map<String, ConfigFile> configFiles_;
|
||||
private Map<String, Define> defines_;
|
||||
|
||||
private IProject project_;
|
||||
|
||||
public ProjectCache(IProject project)
|
||||
{
|
||||
project_ = project;
|
||||
|
||||
configFiles_ = new HashMap<String, ConfigFile>();
|
||||
defines_ = new HashMap<String, Define>(0);
|
||||
propertiesTimetamp_ = 0;
|
||||
|
@ -227,4 +233,23 @@ public class ProjectCache
|
|||
{
|
||||
return defines_;
|
||||
}
|
||||
|
||||
/**
|
||||
* The name of the install used in the project
|
||||
*/
|
||||
public String getInstallName()
|
||||
{
|
||||
return Preferences.getString( Constants.P_INST_NAME_PREFIX + project_.getName( ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new install used in the project
|
||||
* @param newInstallName The new install name
|
||||
*/
|
||||
public void setInstallName( String newInstallName )
|
||||
{
|
||||
Preferences.getPreferences( ).setValue(
|
||||
Constants.P_INST_NAME_PREFIX + project_.getName( ),
|
||||
newInstallName );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ import java.util.List;
|
|||
*/
|
||||
public class ConfigFile
|
||||
{
|
||||
private String filename_;
|
||||
|
||||
public String ScenarioId;
|
||||
/**
|
||||
|
@ -28,13 +27,14 @@ public class ConfigFile
|
|||
|
||||
public String CampaignId;
|
||||
/**
|
||||
* True if there was a [campaign] tag present in the file.
|
||||
*
|
||||
* However The {@link ConfigFile#CampaignId} may be null
|
||||
*/
|
||||
* True if there was a [campaign] tag present in the file.
|
||||
*
|
||||
* However The {@link ConfigFile#CampaignId} may be null
|
||||
*/
|
||||
public boolean IsCampaign;
|
||||
|
||||
private List<Variable> variables_;
|
||||
private String filename_;
|
||||
|
||||
public ConfigFile(String filename)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue