[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] New Class Wizard 'include guard' option
|
Hello,
The New Class Wizard is just great. I tried to add an option to create a
classic include guard around the header file.
e.g for class Foo:
#ifndef FOO_H
#define FOO_H
...
#endif // FOO_H
Maybe Hoda already thought about this, in this case sorry for the noise.
Cordialement,
Christophe
Index: src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties,v
retrieving revision 1.2
diff -u -r1.2 NewWizardMessages.properties
--- src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties 30 May 2003 15:26:37 -0000 1.2
+++ src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties 5 Jun 2003 23:25:36 -0000
@@ -146,6 +146,7 @@
NewClassWizardPage.constdest.virtualdestructor=&Virtual Destructor
NewClassWizardPage.constdest.inline=&Inline
+NewClassWizardPage.constdest.includeguard=Include &Guard
NewClassWizardPage.files.header=Header File:
NewClassWizardPage.files.body=Body File:
Index: src/org/eclipse/cdt/ui/wizards/NewClassWizardPage.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassWizardPage.java,v
retrieving revision 1.3
diff -u -r1.3 NewClassWizardPage.java
--- src/org/eclipse/cdt/ui/wizards/NewClassWizardPage.java 30 May 2003 15:26:37 -0000 1.3
+++ src/org/eclipse/cdt/ui/wizards/NewClassWizardPage.java 5 Jun 2003 23:25:39 -0000
@@ -149,9 +149,10 @@
String[] buttonNames2= new String[] {
/* 0 == INLINE_INDEX */ NewWizardMessages.getString("NewClassWizardPage.constdest.inline"),
/* 1 == VIRTUAL_DEST_INDEX */ NewWizardMessages.getString("NewClassWizardPage.constdest.virtualdestructor"),
+ /* 2 == INCLUDE_GUARD_INDEX */ NewWizardMessages.getString("NewClassWizardPage.constdest.includeguard"),
};
- fConstDestButtons= new SelectionButtonDialogFieldGroup(SWT.CHECK, buttonNames2, 4);
+ fConstDestButtons= new SelectionButtonDialogFieldGroup(SWT.CHECK, buttonNames2, 3);
fConstDestButtons.setDialogFieldListener(adapter);
linkedResourceGroupForHeader = new LinkToFileGroup(adapter, this);
@@ -456,6 +457,10 @@
return fBaseClassDialogField.getText();
}
+ public boolean isIncludeGuard(){
+ return fConstDestButtons.isSelected(2);
+ }
+
public boolean isVirtualDestructor(){
return fConstDestButtons.isSelected(1);
}
@@ -742,6 +747,18 @@
}
}
+ if(isIncludeGuard()){
+ text.append("#ifndef ");
+ text.append(getNewClassName().toUpperCase());
+ text.append("_H");
+ text.append(lineDelimiter);
+ text.append("#define ");
+ text.append(getNewClassName().toUpperCase());
+ text.append("_H");
+ text.append(lineDelimiter);
+ text.append(lineDelimiter);
+ }
+
if(extendingBase){
text.append("#include \"");
text.append(baseClassFileName);
@@ -793,7 +810,15 @@
}
text.append("};");
text.append(lineDelimiter);
-
+
+ if(isIncludeGuard()){
+ text.append(lineDelimiter);
+ text.append("#endif // ");
+ text.append(getNewClassName().toUpperCase());
+ text.append("_H");
+ text.append(lineDelimiter);
+ }
+
return text.toString();
}