mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-04 13:47:56 +00:00
eclipse plugin: computer the working directory directly...
...from the preferences page
This commit is contained in:
parent
991f3efd5f
commit
283d0801de
@ -18,6 +18,8 @@ import org.eclipse.jface.preference.FieldEditor;
|
||||
import org.eclipse.jface.preference.FieldEditorPreferencePage;
|
||||
import org.eclipse.jface.preference.FileFieldEditor;
|
||||
import org.eclipse.jface.util.PropertyChangeEvent;
|
||||
import org.eclipse.swt.events.ModifyEvent;
|
||||
import org.eclipse.swt.events.ModifyListener;
|
||||
import org.eclipse.ui.IWorkbench;
|
||||
import org.eclipse.ui.IWorkbenchPreferencePage;
|
||||
|
||||
@ -41,6 +43,9 @@ public class WesnothEditorPreferencesPage extends FieldEditorPreferencePage
|
||||
implements IWorkbenchPreferencePage
|
||||
{
|
||||
private DirectoryFieldEditor wmlToolsField_;
|
||||
private DirectoryFieldEditor wesnothWorkingDirField_;
|
||||
private DirectoryFieldEditor wesnothUserDirField_;
|
||||
private FileFieldEditor wesnothExecutableField_;
|
||||
private List<String> wmlToolsList_;
|
||||
|
||||
public WesnothEditorPreferencesPage() {
|
||||
@ -65,15 +70,49 @@ public class WesnothEditorPreferencesPage extends FieldEditorPreferencePage
|
||||
@Override
|
||||
public void createFieldEditors()
|
||||
{
|
||||
addField(new FileFieldEditor(Constants.P_WESNOTH_EXEC_PATH,
|
||||
"Wesnoth executable path:", getFieldEditorParent()));
|
||||
addField(new DirectoryFieldEditor(Constants.P_WESNOTH_WORKING_DIR,
|
||||
"Working directory:", getFieldEditorParent()));
|
||||
addField(new DirectoryFieldEditor(Constants.P_WESNOTH_USER_DIR,
|
||||
"User data directory:", getFieldEditorParent()));
|
||||
wesnothExecutableField_ = new FileFieldEditor(Constants.P_WESNOTH_EXEC_PATH,
|
||||
"Wesnoth executable path:", getFieldEditorParent());
|
||||
wesnothExecutableField_.getTextControl(getFieldEditorParent()).addModifyListener(new ModifyListener() {
|
||||
@Override
|
||||
public void modifyText(ModifyEvent e)
|
||||
{
|
||||
checkState();
|
||||
if (wesnothWorkingDirField_.getTextControl(
|
||||
getFieldEditorParent()).getText().isEmpty())
|
||||
{
|
||||
String wesnothExec = wesnothExecutableField_.getTextControl(getFieldEditorParent()).getText();
|
||||
if (!wesnothExec.isEmpty())
|
||||
{
|
||||
wesnothWorkingDirField_.getTextControl(getFieldEditorParent()).
|
||||
setText(wesnothExec.substring(0,
|
||||
wesnothExec.lastIndexOf(new File(wesnothExec).getName()))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
addField(wesnothExecutableField_);
|
||||
|
||||
ModifyListener stateChecker = new ModifyListener() {
|
||||
@Override
|
||||
public void modifyText(ModifyEvent e)
|
||||
{
|
||||
checkState();
|
||||
}
|
||||
};
|
||||
|
||||
wesnothWorkingDirField_ = new DirectoryFieldEditor(Constants.P_WESNOTH_WORKING_DIR,
|
||||
"Working directory:", getFieldEditorParent());
|
||||
addField(wesnothWorkingDirField_);
|
||||
|
||||
wesnothUserDirField_ = new DirectoryFieldEditor(Constants.P_WESNOTH_USER_DIR,
|
||||
"User data directory:", getFieldEditorParent());
|
||||
addField(wesnothUserDirField_);
|
||||
|
||||
wmlToolsField_ = new DirectoryFieldEditor(Constants.P_WESNOTH_WMLTOOLS_DIR,
|
||||
"WML* tools directory:", getFieldEditorParent());
|
||||
wmlToolsField_.getTextControl(getFieldEditorParent()).
|
||||
addModifyListener(stateChecker);
|
||||
addField(wmlToolsField_);
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,6 @@
|
||||
*******************************************************************************/
|
||||
package wesnoth_eclipse_plugin.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -107,13 +106,13 @@ public class GameUtils
|
||||
{
|
||||
List<String> args = new ArrayList<String>();
|
||||
String wesnothExec = Preferences.getString(Constants.P_WESNOTH_EXEC_PATH);
|
||||
if (wesnothExec.isEmpty())
|
||||
String workingDir = Preferences.getString(Constants.P_WESNOTH_WORKING_DIR);
|
||||
if (wesnothExec.isEmpty() || workingDir.isEmpty())
|
||||
{
|
||||
GUIUtils.showErrorMessageBox("Please set the wesnoth's executable path first.");
|
||||
return;
|
||||
}
|
||||
|
||||
String workingDir = Preferences.getString(Constants.P_WESNOTH_WORKING_DIR);
|
||||
|
||||
if (extraArgs != null)
|
||||
args.addAll(extraArgs);
|
||||
@ -122,10 +121,6 @@ public class GameUtils
|
||||
args.add("--config-dir");
|
||||
args.add(Preferences.getString(Constants.P_WESNOTH_USER_DIR));
|
||||
|
||||
if (workingDir.isEmpty())
|
||||
workingDir = wesnothExec.substring(0,
|
||||
wesnothExec.lastIndexOf(new File(wesnothExec).getName()));
|
||||
|
||||
// we need to add the working dir (backward compatibility)
|
||||
args.add(workingDir);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user