Author: timotei
Date: Sat Jul 30 09:58:20 2011
New Revision: 50477

URL: http://svn.gna.org/viewcvs/wesnoth?rev=50477&view=rev
Log:
eclipse plugin: Tweak the addons view to let the user
select the wesnoth install when creating a new project
for the downloaded addons

Added:
    
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/installs/SelectWesnothInstallDialog.java
Modified:
    
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/installs/WesnothInstallsUtils.java
    trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/views/AddonsView.java

Added: 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/installs/SelectWesnothInstallDialog.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/installs/SelectWesnothInstallDialog.java?rev=50477&view=auto
==============================================================================
--- 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/installs/SelectWesnothInstallDialog.java
 (added)
+++ 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/installs/SelectWesnothInstallDialog.java
 Sat Jul 30 09:58:20 2011
@@ -1,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2011 by Timotei Dolean <[email protected]>
+ *
+ * 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( );
+    }
+}

Modified: 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/installs/WesnothInstallsUtils.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/installs/WesnothInstallsUtils.java?rev=50477&r1=50476&r2=50477&view=diff
==============================================================================
--- 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/installs/WesnothInstallsUtils.java
 (original)
+++ 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/installs/WesnothInstallsUtils.java
 Sat Jul 30 09:58:20 2011
@@ -15,6 +15,7 @@
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Combo;
 import org.wesnoth.Constants;
 import org.wesnoth.Logger;
 import org.wesnoth.Messages;
@@ -109,6 +110,32 @@
     }
 
     /**
+     * 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
      * for the specified resource. If it is not, it will guide the user
      * through selecting a proper install (if any).

Modified: trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/views/AddonsView.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/views/AddonsView.java?rev=50477&r1=50476&r2=50477&view=diff
==============================================================================
--- trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/views/AddonsView.java 
(original)
+++ trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/views/AddonsView.java Sat 
Jul 30 09:58:20 2011
@@ -41,12 +41,14 @@
 import org.eclipse.swt.widgets.TableItem;
 import org.eclipse.ui.dialogs.PreferencesUtil;
 import org.eclipse.ui.part.ViewPart;
+import org.wesnoth.installs.SelectWesnothInstallDialog;
 import org.wesnoth.preferences.AddonUploadPreferencePage;
 import org.wesnoth.preferences.Preferences;
 import org.wesnoth.preferences.Preferences.Paths;
 import org.wesnoth.projects.ProjectUtils;
 import org.wesnoth.utils.ExternalToolInvoker;
 import org.wesnoth.utils.GUIUtils;
+import org.wesnoth.utils.RunnableWithResult;
 import org.wesnoth.utils.StringUtils;
 import org.wesnoth.utils.WMLTools;
 
@@ -196,7 +198,27 @@
             {
                 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 );
 
                 OutputStream console = GUIUtils
@@ -214,22 +236,13 @@
                 monitor.worked( 50 );
 
                 // ask user if he wants to create a project
-
                 if ( GUIUtils.showMessageBox(
                         "Do you want to create a new project for the 
downloaded addon?",
                         SWT.YES | SWT.NO ) == SWT.YES ) {
 
-                    Display.getDefault( ).syncExec( new Runnable( ) {
-
-                        @Override
-                        public void run()
-                        {
-                            ProjectUtils.createWesnothProject( addonName,
-                                    paths.getAddonsDir( ) + addonName, false, 
monitor );
-                        }
-                    });
+                        ProjectUtils.createWesnothProject( addonName,
+                                paths.getAddonsDir( ) + addonName, 
installName, monitor );
                 }
-
                 monitor.done( );
 
                 return Status.OK_STATUS;
@@ -268,7 +281,7 @@
                     monitor.beginTask( "Retrieving list...", 100 );
                     monitor.worked( 10 );
 
-                    String installName = "";
+                    String installName = Preferences.getDefaultInstallName( );
 
                     OutputStream stderr = GUIUtils
                         .createConsole( "Wesnoth Addon Manager", null, false )


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to