eclipse plugin: Tweak the addons view to let the user...
...select the wesnoth install when creating a new project for the downloaded addons
This commit is contained in:
parent
3859a85900
commit
6494f1a6e8
3 changed files with 124 additions and 13 deletions
|
@ -0,0 +1,71 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2011 by Timotei Dolean <timotei21@gmail.com>
|
||||||
|
*
|
||||||
|
* This program and the accompanying materials are made available
|
||||||
|
* under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.wesnoth.installs;
|
||||||
|
|
||||||
|
import org.eclipse.jface.dialogs.Dialog;
|
||||||
|
import org.eclipse.swt.SWT;
|
||||||
|
import org.eclipse.swt.graphics.Point;
|
||||||
|
import org.eclipse.swt.layout.GridData;
|
||||||
|
import org.eclipse.swt.layout.GridLayout;
|
||||||
|
import org.eclipse.swt.widgets.Combo;
|
||||||
|
import org.eclipse.swt.widgets.Composite;
|
||||||
|
import org.eclipse.swt.widgets.Control;
|
||||||
|
import org.eclipse.swt.widgets.Label;
|
||||||
|
import org.eclipse.swt.widgets.Shell;
|
||||||
|
|
||||||
|
public class SelectWesnothInstallDialog extends Dialog
|
||||||
|
{
|
||||||
|
private Combo cmbInstall_;
|
||||||
|
|
||||||
|
public SelectWesnothInstallDialog( Shell parentShell )
|
||||||
|
{
|
||||||
|
super( parentShell );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configureShell( Shell newShell )
|
||||||
|
{
|
||||||
|
super.configureShell( newShell );
|
||||||
|
|
||||||
|
newShell.setText( "Select the Wesnoth Install" );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Control createDialogArea( Composite parent )
|
||||||
|
{
|
||||||
|
Composite composite = new Composite( parent, SWT.NONE );
|
||||||
|
composite.setLayout(new GridLayout(2, false));
|
||||||
|
|
||||||
|
Label lblWesnothInstall = new Label(composite, SWT.NONE);
|
||||||
|
lblWesnothInstall.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
|
||||||
|
lblWesnothInstall.setText("Wesnoth Install:");
|
||||||
|
|
||||||
|
cmbInstall_ = new Combo(composite, SWT.NONE);
|
||||||
|
GridData gd_cmbInstall_ = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
|
||||||
|
gd_cmbInstall_.widthHint = 163;
|
||||||
|
cmbInstall_.setLayoutData(gd_cmbInstall_);
|
||||||
|
|
||||||
|
WesnothInstallsUtils.fillComboWithInstalls( cmbInstall_ );
|
||||||
|
|
||||||
|
return super.createDialogArea( parent );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Point getInitialSize() {
|
||||||
|
return new Point(291, 123);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the install selected by the user
|
||||||
|
* @return A string with the name of the install selected
|
||||||
|
*/
|
||||||
|
public String getSelectedInstallName( ){
|
||||||
|
return cmbInstall_.getText( );
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,6 +15,7 @@ import java.util.List;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.resources.ResourcesPlugin;
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
|
import org.eclipse.swt.widgets.Combo;
|
||||||
import org.wesnoth.Constants;
|
import org.wesnoth.Constants;
|
||||||
import org.wesnoth.Logger;
|
import org.wesnoth.Logger;
|
||||||
import org.wesnoth.Messages;
|
import org.wesnoth.Messages;
|
||||||
|
@ -108,6 +109,32 @@ public class WesnothInstallsUtils
|
||||||
ProjectUtils.getCacheForProject( resource.getProject( ) ).setInstallName( newInstallName );
|
ProjectUtils.getCacheForProject( resource.getProject( ) ).setInstallName( newInstallName );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fills the specified combo box with all the current installs
|
||||||
|
* and selects the default or the first ( if no default exists )
|
||||||
|
* @param comboBox The combobox to fill
|
||||||
|
*/
|
||||||
|
public static void fillComboWithInstalls( Combo comboBox )
|
||||||
|
{
|
||||||
|
comboBox.removeAll( );
|
||||||
|
comboBox.clearSelection( );
|
||||||
|
|
||||||
|
// fill the installs
|
||||||
|
String defaultInstallName = Preferences.getDefaultInstallName( );
|
||||||
|
for ( WesnothInstall install : WesnothInstallsUtils.getInstalls( ) ) {
|
||||||
|
comboBox.add( install.getName( ) );
|
||||||
|
|
||||||
|
// select the default
|
||||||
|
if ( install.getName( ).equals( defaultInstallName ) )
|
||||||
|
comboBox.select( comboBox.getItemCount( ) - 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
// select the first if there is no other selected
|
||||||
|
if ( comboBox.getSelectionIndex( ) == -1 &&
|
||||||
|
comboBox.getItemCount( ) > 0 )
|
||||||
|
comboBox.select( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the Wesnoth Installation is properly setup
|
* Checks whether the Wesnoth Installation is properly setup
|
||||||
* for the specified resource. If it is not, it will guide the user
|
* for the specified resource. If it is not, it will guide the user
|
||||||
|
|
|
@ -41,12 +41,14 @@ import org.eclipse.swt.widgets.TableColumn;
|
||||||
import org.eclipse.swt.widgets.TableItem;
|
import org.eclipse.swt.widgets.TableItem;
|
||||||
import org.eclipse.ui.dialogs.PreferencesUtil;
|
import org.eclipse.ui.dialogs.PreferencesUtil;
|
||||||
import org.eclipse.ui.part.ViewPart;
|
import org.eclipse.ui.part.ViewPart;
|
||||||
|
import org.wesnoth.installs.SelectWesnothInstallDialog;
|
||||||
import org.wesnoth.preferences.AddonUploadPreferencePage;
|
import org.wesnoth.preferences.AddonUploadPreferencePage;
|
||||||
import org.wesnoth.preferences.Preferences;
|
import org.wesnoth.preferences.Preferences;
|
||||||
import org.wesnoth.preferences.Preferences.Paths;
|
import org.wesnoth.preferences.Preferences.Paths;
|
||||||
import org.wesnoth.projects.ProjectUtils;
|
import org.wesnoth.projects.ProjectUtils;
|
||||||
import org.wesnoth.utils.ExternalToolInvoker;
|
import org.wesnoth.utils.ExternalToolInvoker;
|
||||||
import org.wesnoth.utils.GUIUtils;
|
import org.wesnoth.utils.GUIUtils;
|
||||||
|
import org.wesnoth.utils.RunnableWithResult;
|
||||||
import org.wesnoth.utils.StringUtils;
|
import org.wesnoth.utils.StringUtils;
|
||||||
import org.wesnoth.utils.WMLTools;
|
import org.wesnoth.utils.WMLTools;
|
||||||
|
|
||||||
|
@ -196,7 +198,27 @@ public class AddonsView extends ViewPart
|
||||||
{
|
{
|
||||||
monitor.beginTask( "Downloading addon " + addonName, 100 );
|
monitor.beginTask( "Downloading addon " + addonName, 100 );
|
||||||
|
|
||||||
String installName = "";
|
String installName = Preferences.getDefaultInstallName( );
|
||||||
|
|
||||||
|
RunnableWithResult<String> runnable =
|
||||||
|
new RunnableWithResult<String>() {
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
// ask the user to select the install for the project
|
||||||
|
SelectWesnothInstallDialog dialog =
|
||||||
|
new SelectWesnothInstallDialog( null );
|
||||||
|
if ( dialog.open( ) == SWT.OK ) {
|
||||||
|
setResult( dialog.getSelectedInstallName( ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Display.getDefault( ).syncExec( runnable );
|
||||||
|
if ( ! StringUtils.isNullOrEmpty( runnable.getResult( ) ) ) {
|
||||||
|
installName = runnable.getResult( );
|
||||||
|
}
|
||||||
|
|
||||||
final Paths paths = Preferences.getPaths( installName );
|
final Paths paths = Preferences.getPaths( installName );
|
||||||
|
|
||||||
OutputStream console = GUIUtils
|
OutputStream console = GUIUtils
|
||||||
|
@ -214,22 +236,13 @@ public class AddonsView extends ViewPart
|
||||||
monitor.worked( 50 );
|
monitor.worked( 50 );
|
||||||
|
|
||||||
// ask user if he wants to create a project
|
// ask user if he wants to create a project
|
||||||
|
|
||||||
if ( GUIUtils.showMessageBox(
|
if ( GUIUtils.showMessageBox(
|
||||||
"Do you want to create a new project for the downloaded addon?",
|
"Do you want to create a new project for the downloaded addon?",
|
||||||
SWT.YES | SWT.NO ) == SWT.YES ) {
|
SWT.YES | SWT.NO ) == SWT.YES ) {
|
||||||
|
|
||||||
Display.getDefault( ).syncExec( new Runnable( ) {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
ProjectUtils.createWesnothProject( addonName,
|
ProjectUtils.createWesnothProject( addonName,
|
||||||
paths.getAddonsDir( ) + addonName, false, monitor );
|
paths.getAddonsDir( ) + addonName, installName, monitor );
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
monitor.done( );
|
monitor.done( );
|
||||||
|
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
|
@ -268,7 +281,7 @@ public class AddonsView extends ViewPart
|
||||||
monitor.beginTask( "Retrieving list...", 100 );
|
monitor.beginTask( "Retrieving list...", 100 );
|
||||||
monitor.worked( 10 );
|
monitor.worked( 10 );
|
||||||
|
|
||||||
String installName = "";
|
String installName = Preferences.getDefaultInstallName( );
|
||||||
|
|
||||||
OutputStream stderr = GUIUtils
|
OutputStream stderr = GUIUtils
|
||||||
.createConsole( "Wesnoth Addon Manager", null, false )
|
.createConsole( "Wesnoth Addon Manager", null, false )
|
||||||
|
|
Loading…
Add table
Reference in a new issue