Skip to content
Browse files

overwrite flag

  • Loading branch information...
1 parent e92cbaa commit 5bfb855a1f2aeb6ec8b9991f3d072fc716cbde62 @JPMoresmau committed
View
19 ...sf.eclipsefp.haskell.core/src/net/sf/eclipsefp/haskell/core/code/SourceFileGenerator.java
@@ -28,6 +28,11 @@
private final CodeGenerator fCodeGenerator;
+ /**
+ * should we overwrite existing files?
+ */
+ private boolean overwrite=true;
+
public SourceFileGenerator( final CodeGenerator codeGenerator ) {
fCodeGenerator = codeGenerator;
}
@@ -112,7 +117,7 @@ private IFile createFile( final ModuleCreationInfo info,
SubProgressMonitor subMon = monitor==null?null:new SubProgressMonitor( monitor, 4 );
if (!result.exists()){
result.create( isContent, true, subMon );
- } else {
+ } else if (overwrite){
result.setContents( isContent,true,true,subMon);
}
return result;
@@ -129,4 +134,16 @@ private IFile createFile( final ModuleCreationInfo info,
protected String createFileName(final EHaskellCommentStyle style, final String moduleName ) {
return moduleName + "." + style.getFileExtension(); //$NON-NLS-1$
}
+
+
+
+ public boolean isOverwrite() {
+ return overwrite;
+ }
+
+
+
+ public void setOverwrite( final boolean overwrite ) {
+ this.overwrite = overwrite;
+ }
}
View
20 ...src/net/sf/eclipsefp/haskell/ui/internal/editors/cabal/forms/stanzas/TestSuiteDialog.java
@@ -126,6 +126,10 @@ public String isValid( final String newText ) {
private final TestSuiteDef def=new TestSuiteDef();
private final PackageDescription pkgDesc;
+ /**
+ * should we overwrite existing files?
+ */
+ private boolean overwrite=true;
public TestSuiteDialog(final Shell shell,final IProject project,final PackageDescription desc, final Set<String> names){
super(shell);
@@ -219,6 +223,17 @@ public void widgetSelected( final SelectionEvent e ) {
}
}
} );
+
+ final Button bOverwrite=new Button(composite,SWT.CHECK);
+ bOverwrite.setText( UITexts.option_overwrite );
+ bOverwrite.setSelection( true );
+ bOverwrite.addSelectionListener( new SelectionAdapter() {
+ @Override
+ public void widgetSelected(final SelectionEvent e) {
+ overwrite=bOverwrite.getSelection();
+ }
+ } );
+
Label lMods=new Label(composite,SWT.WRAP);
lMods.setText( UITexts.cabalEditor_newTestSuite_modules);
@@ -416,4 +431,9 @@ public boolean equals( final Object obj ) {
}
+
+
+ public boolean isOverwrite() {
+ return overwrite;
+ }
}
View
16 .../src/net/sf/eclipsefp/haskell/ui/internal/editors/cabal/forms/stanzas/TestSuitesPage.java
@@ -79,7 +79,7 @@ public TestSuitesPage( final FormEditor editor, final IProject project ) {
super( editor, TestSuitesPage.class.getName(), UITexts.cabalEditor_testSuites, project );
}
- public void addStanza(final PackageDescription desc,final String pref,final TestSuiteDialog.TestSuiteDef def){
+ public void addStanza(final PackageDescription desc,final String pref,final TestSuiteDialog.TestSuiteDef def,final boolean overwrite){
Map<String,String> vars=new HashMap<String, String>();
vars.put( TemplateVariables.PROJECT_NAME, getPackageDescription().getPackageStanza().getName() );
vars.put( TemplateVariables.SRC, def.getSrc().getProjectRelativePath().toPortableString() );
@@ -107,7 +107,7 @@ public void addStanza(final PackageDescription desc,final String pref,final Test
/**
* create test moduke
*/
- String m=createTestModule( pd, def, md.getModule(), isHTF?ICorePreferenceNames.TEMPLATE_MODULE_HTF:ICorePreferenceNames.TEMPLATE_MODULE );
+ String m=createTestModule( pd, def, md.getModule(), isHTF?ICorePreferenceNames.TEMPLATE_MODULE_HTF:ICorePreferenceNames.TEMPLATE_MODULE,overwrite );
/**
* generate import directive
*/
@@ -155,7 +155,7 @@ public void addStanza(final PackageDescription desc,final String pref,final Test
* create main
*/
if (! ICorePreferenceNames.TEMPLATE_CABAL_DETAILED.equals( pref )){
- createMain( pd, def ,isHTF,imports.toString());
+ createMain( pd, def ,isHTF,imports.toString(),overwrite);
}
desc.addStanza( pd );
@@ -168,8 +168,9 @@ public void addStanza(final PackageDescription desc,final String pref,final Test
* @param def
* @param isHTF
* @param imports
+ * @param overwrite should we overwrite existing files?
*/
- private void createMain( final PackageDescriptionStanza pd,final TestSuiteDialog.TestSuiteDef def,final boolean isHTF,final String imports){
+ private void createMain( final PackageDescriptionStanza pd,final TestSuiteDialog.TestSuiteDef def,final boolean isHTF,final String imports,final boolean overwrite){
final String mainName=def.getName() + "." + EHaskellCommentStyle.USUAL.getFileExtension(); //$NON-NLS-1$
pd.update( CabalSyntax.FIELD_MAIN_IS, mainName );
@@ -209,6 +210,7 @@ protected String createFileName( final EHaskellCommentStyle style,
return mainName;
}
};
+ gen.setOverwrite( overwrite );
try {
IFile f=gen.createFile( new NullProgressMonitor(), mci );
f.setPersistentProperty( BuildWrapperPlugin.EDITORSTANZA_PROPERTY, def.getName() );
@@ -223,9 +225,10 @@ protected String createFileName( final EHaskellCommentStyle style,
* @param def
* @param module the module to test
* @param pref
+ * @param overwrite should we overwrite existing files?
* @return
*/
- private String createTestModule(final PackageDescriptionStanza pd,final TestSuiteDialog.TestSuiteDef def,final String module,final String pref){
+ private String createTestModule(final PackageDescriptionStanza pd,final TestSuiteDialog.TestSuiteDef def,final String module,final String pref,final boolean overwrite){
String testModule=module+"Test";
pd.addToPropertyList( CabalSyntax.FIELD_OTHER_MODULES,testModule );
@@ -257,6 +260,7 @@ protected void addVariables( final Map<String, String> vars ) {
}
};
SourceFileGenerator gen=new SourceFileGenerator(cg);
+ gen.setOverwrite( overwrite );
try {
IFile f=gen.createFile( new NullProgressMonitor(), mci );
f.setPersistentProperty( BuildWrapperPlugin.EDITORSTANZA_PROPERTY, def.getName() );
@@ -515,7 +519,7 @@ public void run() {
TestSuiteDialog.TestSuiteDef def = dialog.getDefinition();
//createNewTestFrameworkStanza( lastDescription, execName );
- addStanza( lastDescription, this.pref, def );
+ addStanza( lastDescription, this.pref, def ,dialog.isOverwrite());
nextSelected = def.getName();
formEditor.getModel().set( lastDescription.dump() );
}
View
2 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/util/UITexts.java
@@ -807,6 +807,8 @@
public static String folder_add_duplicate;
public static String folder_add_empty;
+ public static String option_overwrite;
+
private static final String BUNDLE_NAME = UITexts.class.getPackage()
.getName() + ".uitexts"; //$NON-NLS-1$
View
4 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/util/uitexts.properties
@@ -809,4 +809,6 @@ folder_empty=No folder to select.
folder_add=Add new folder...
folder_add_title=Add new folder
folder_add_duplicate=Folder already exists
-folder_add_empty=Folder name cannot be empty
+folder_add_empty=Folder name cannot be empty
+
+option_overwrite=Overwrite existing files

0 comments on commit 5bfb855

Please sign in to comment.
Something went wrong with that request. Please try again.