Browse Source

Fixed bug in InterfaceImplementorCodeGenerator.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@441 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
fba8d0505e
  1. 238
      src/Main/Base/Project/Src/TextEditor/Commands/CodeGenerators/AbstractClassImplementorCodeGenerator.cs
  2. 98
      src/Main/Base/Project/Src/TextEditor/Commands/CodeGenerators/InterfaceImplementorCodeGenerator.cs
  3. 30
      src/Main/Core/Project/Src/AddInTree/AddIn/DefaultDoozers/ToolBarItem/Gui/ToolBarCommand.cs
  4. 2
      src/Main/Core/Project/Src/Services/ToolBarService/ToolBarService.cs

238
src/Main/Base/Project/Src/TextEditor/Commands/CodeGenerators/AbstractClassImplementorCodeGenerator.cs

@ -14,9 +14,8 @@ using ICSharpCode.Core; @@ -14,9 +14,8 @@ using ICSharpCode.Core;
namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
{
public class AbstractClassImplementorCodeGenerator : CodeGenerator
public class AbstractClassImplementorCodeGenerator : InterfaceOrAbstractClassCodeGenerator
{
public override string CategoryName {
get {
return "Abstract class overridings";
@ -29,13 +28,6 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands @@ -29,13 +28,6 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
}
}
public override int ImageIndex {
get {
return ClassBrowserIconService.InterfaceIndex;
}
}
public AbstractClassImplementorCodeGenerator(IClass currentClass) : base(currentClass)
{
for (int i = 0; i < currentClass.BaseTypes.Count; i++) {
@ -46,233 +38,5 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands @@ -46,233 +38,5 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
}
}
}
protected override void StartGeneration(IList items, string fileExtension)
{
for (int i = 0; i < items.Count; ++i) {
ClassWrapper cw = (ClassWrapper)items[i];
GenerateInterface(cw.ClassType, fileExtension);
}
}
void GenerateInterface(IReturnType intf, string fileExtension)
{
Return();Return();
if (fileExtension == ".vb") {
editActionHandler.InsertString("#Region \"" + intf.FullyQualifiedName + " abstract class implementation\"\n\t\t");
} else {
editActionHandler.InsertString("#region " + intf.FullyQualifiedName + " abstract class implementation\n\t\t");
}
++numOps;
foreach (IProperty property in intf.GetProperties()) {
if (!property.IsAbstract) {
continue;
}
string returnType = (fileExtension == ".vb" ? vba : csa).Convert(property.ReturnType);
if (property.IsProtected) {
if (fileExtension == ".vb") {
editActionHandler.InsertString("Protected ");
} else {
editActionHandler.InsertString("protected ");
}
++numOps;
} else {
if (fileExtension == ".vb") {
editActionHandler.InsertString("Public ");
} else {
editActionHandler.InsertString("public ");
}
++numOps;
}
if (fileExtension == ".vb") {
editActionHandler.InsertString("override " + returnType + " " + property.Name);
if (StartCodeBlockInSameLine) {
editActionHandler.InsertString(" {");++numOps;
} else {
Return();
editActionHandler.InsertString("{");++numOps;
}
} else {
editActionHandler.InsertString("Overrides Property " + property.Name + " As " + returnType + "\n");
}
++numOps;
if (property.CanGet) {
if (fileExtension == ".vb") {
editActionHandler.InsertString("\tGet");++numOps;
Return();
editActionHandler.InsertString("\t\tReturn " + GetReturnValue(returnType));++numOps;
Return();
editActionHandler.InsertString("\tEnd Get");++numOps;
Return();
} else {
editActionHandler.InsertString("\tget");++numOps;
if (StartCodeBlockInSameLine) {
editActionHandler.InsertString(" {");++numOps;
} else {
Return();
editActionHandler.InsertString("{");++numOps;
}
Return();
editActionHandler.InsertString("\t\treturn " + GetReturnValue(returnType) +";");++numOps;
Return();
editActionHandler.InsertString("\t}");++numOps;
Return();
}
}
if (property.CanSet) {
if (fileExtension == ".vb") {
editActionHandler.InsertString("\tSet");++numOps;
Return();
editActionHandler.InsertString("\tEnd Set");++numOps;
Return();
} else {
editActionHandler.InsertString("\tset");++numOps;
if (StartCodeBlockInSameLine) {
editActionHandler.InsertString(" {");++numOps;
} else {
Return();
editActionHandler.InsertString("{");++numOps;
}
Return();
editActionHandler.InsertString("\t}");++numOps;
Return();
}
}
if (fileExtension == ".vb") {
editActionHandler.InsertString("End Property");++numOps;
} else {
editActionHandler.InsertChar('}');++numOps;
}
Return();
Return();
IndentLine();
}
foreach (IMethod method in intf.GetMethods()) {
string parameters = String.Empty;
string returnType = (fileExtension == ".vb" ? vba : csa).Convert(method.ReturnType);
if (!method.IsAbstract) {
continue;
}
for (int j = 0; j < method.Parameters.Count; ++j) {
parameters += (fileExtension == ".vb" ? vba : csa).Convert(method.Parameters[j]);
if (j + 1 < method.Parameters.Count) {
parameters += ", ";
}
}
if (method.IsProtected) {
if (fileExtension == ".vb") {
editActionHandler.InsertString("Protected ");
} else {
editActionHandler.InsertString("protected ");
}
} else {
if (fileExtension == ".vb") {
editActionHandler.InsertString("Public ");
} else {
editActionHandler.InsertString("public ");
}
}
bool isSub = returnType == "void";
if (fileExtension == ".vb") {
editActionHandler.InsertString("Overrides " + (isSub ? "Sub " : "Function ") + method.Name + "(" + parameters + ") As " + returnType);++numOps;
Return();
} else {
editActionHandler.InsertString("override " + returnType + " " + method.Name + "(" + parameters + ")");++numOps;
if (StartCodeBlockInSameLine) {
editActionHandler.InsertString(" {");++numOps;
} else {
Return();
editActionHandler.InsertString("{");++numOps;
}
Return();
}
switch (returnType) {
case "void":
break;
default:
if (fileExtension == ".vb") {
editActionHandler.InsertString("Return " + GetReturnValue(returnType));++numOps;
} else {
editActionHandler.InsertString("return " + GetReturnValue(returnType) + ";");++numOps;
}
break;
}
Return();
if (fileExtension == ".vb") {
editActionHandler.InsertString("End " + (isSub ? "Sub" : "Function"));
} else {
editActionHandler.InsertChar('}');++numOps;
}
Return();
Return();
IndentLine();
}
Return();
if (fileExtension == ".vb") {
editActionHandler.InsertString("#End Region");++numOps;
} else {
editActionHandler.InsertString("#endregion");++numOps;
}
Return();
}
string GetReturnValue(string returnType)
{
switch (returnType) {
case "string":
return "String.Empty";
case "char":
return "'\\0'";
case "bool":
return "false";
case "int":
case "long":
case "short":
case "byte":
case "uint":
case "ulong":
case "ushort":
case "double":
case "float":
case "decimal":
return "0";
default:
return "null";
}
}
class ClassWrapper
{
IReturnType c;
public IReturnType ClassType {
get {
return c;
}
}
public ClassWrapper(IReturnType c)
{
this.c = c;
}
public override string ToString()
{
IAmbience ambience = AmbienceService.CurrentAmbience;
ambience.ConversionFlags = ConversionFlags.None;
return ambience.Convert(c);
}
}
}
}

98
src/Main/Base/Project/Src/TextEditor/Commands/CodeGenerators/InterfaceImplementorCodeGenerator.cs

@ -14,37 +14,37 @@ using ICSharpCode.Core; @@ -14,37 +14,37 @@ using ICSharpCode.Core;
namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
{
public class InterfaceImplementorCodeGenerator : CodeGenerator
public abstract class InterfaceOrAbstractClassCodeGenerator : CodeGenerator
{
public override string CategoryName {
get {
return "Interface implementation";
}
}
public override string Hint {
get {
return "Choose interfaces to implement";
}
}
public override int ImageIndex {
get {
return ClassBrowserIconService.InterfaceIndex;
}
}
public InterfaceImplementorCodeGenerator(IClass currentClass) : base(currentClass)
public InterfaceOrAbstractClassCodeGenerator(IClass currentClass) : base(currentClass)
{
for (int i = 0; i < currentClass.BaseTypes.Count; i++) {
IReturnType baseType = currentClass.GetBaseType(i);
IClass baseClass = (baseType != null) ? baseType.GetUnderlyingClass() : null;
if (baseClass != null && baseClass.ClassType == ClassType.Interface) {
Content.Add(new ClassWrapper(baseType));
}
protected class ClassWrapper
{
IReturnType c;
public IReturnType ClassType {
get {
return c;
}
}
public ClassWrapper(IReturnType c)
{
this.c = c;
}
public override string ToString()
{
IAmbience ambience = AmbienceService.CurrentAmbience;
ambience.ConversionFlags = ConversionFlags.None;
return ambience.Convert(c);
}
}
protected override void StartGeneration(IList items, string fileExtension)
@ -83,6 +83,8 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands @@ -83,6 +83,8 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
}
if (fileExtension == ".vb") {
editActionHandler.InsertString("Overrides Property " + property.Name + " As " + returnType + "\n");
} else {
editActionHandler.InsertString("override " + returnType + " " + property.Name);
if (StartCodeBlockInSameLine) {
editActionHandler.InsertString(" {");++numOps;
@ -90,8 +92,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands @@ -90,8 +92,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
Return();
editActionHandler.InsertString("{");++numOps;
}
} else {
editActionHandler.InsertString("Overrides Property " + property.Name + " As " + returnType + "\n");
Return();
}
++numOps;
if (property.CanGet) {
@ -192,16 +193,10 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands @@ -192,16 +193,10 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
Return();
}
switch (returnType) {
case "void":
break;
default:
if (fileExtension == ".vb") {
editActionHandler.InsertString("Return " + GetReturnValue(returnType));++numOps;
} else {
editActionHandler.InsertString("return " + GetReturnValue(returnType) + ";");++numOps;
}
break;
if (fileExtension == ".vb") {
editActionHandler.InsertString("Throw New NotImplementedException()");++numOps;
} else {
editActionHandler.InsertString("throw new NotImplementedException();");++numOps;
}
Return();
@ -244,26 +239,31 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands @@ -244,26 +239,31 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
return "null";
}
}
}
public class InterfaceImplementorCodeGenerator : InterfaceOrAbstractClassCodeGenerator
{
public override string CategoryName {
get {
return "Interface implementation";
}
}
public override string Hint {
get {
return "Choose interfaces to implement";
}
}
class ClassWrapper
public InterfaceImplementorCodeGenerator(IClass currentClass) : base(currentClass)
{
IReturnType c;
public IReturnType ClassType {
get {
return c;
for (int i = 0; i < currentClass.BaseTypes.Count; i++) {
IReturnType baseType = currentClass.GetBaseType(i);
IClass baseClass = (baseType != null) ? baseType.GetUnderlyingClass() : null;
if (baseClass != null && baseClass.ClassType == ClassType.Interface) {
Content.Add(new ClassWrapper(baseType));
}
}
public ClassWrapper(IReturnType c)
{
this.c = c;
}
public override string ToString()
{
IAmbience ambience = AmbienceService.CurrentAmbience;
ambience.ConversionFlags = ConversionFlags.None;
return ambience.Convert(c);
}
}
}
}

30
src/Main/Core/Project/Src/AddInTree/AddIn/DefaultDoozers/ToolBarItem/Gui/ToolBarCommand.cs

@ -56,36 +56,16 @@ namespace ICSharpCode.Core @@ -56,36 +56,16 @@ namespace ICSharpCode.Core
// StatusBarService.SetMessage(description);
// }
public bool LastEnabledStatus = false;
public bool CurrentEnableStatus {
get {
ConditionFailedAction failedAction = codon.GetFailedAction(caller);
bool isEnabled = failedAction != ConditionFailedAction.Disable;
if (menuCommand != null && menuCommand is IMenuCommand) {
isEnabled &= ((IMenuCommand)menuCommand).IsEnabled;
}
return isEnabled;
}
}
public override bool Enabled {
get {
bool isEnabled = CurrentEnableStatus;
LastEnabledStatus = isEnabled;
return isEnabled;
}
}
public virtual void UpdateStatus()
{
if (codon != null) {
ConditionFailedAction failedAction = codon.GetFailedAction(caller);
bool isVisible = failedAction != ConditionFailedAction.Exclude;
if (base.Visible != isVisible) {
base.Visible = isVisible;
this.Visible = failedAction != ConditionFailedAction.Exclude;
bool isEnabled = failedAction != ConditionFailedAction.Disable;
if (isEnabled && menuCommand != null && menuCommand is IMenuCommand) {
isEnabled = ((IMenuCommand)menuCommand).IsEnabled;
}
this.Enabled = isEnabled;
}
}

2
src/Main/Core/Project/Src/Services/ToolBarService/ToolBarService.cs

@ -70,7 +70,7 @@ namespace ICSharpCode.Core @@ -70,7 +70,7 @@ namespace ICSharpCode.Core
((IStatusUpdate)item).UpdateStatus();
}
}
toolStrip.Refresh();
//toolStrip.Refresh();
}
public static void UpdateToolbarText(ToolStrip toolStrip)

Loading…
Cancel
Save