Browse Source

Fixed solution saving (the order of the solution folders would reverse every time the solution is saved).

Added tool to set the file headers.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@229 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 21 years ago
parent
commit
baf2cf6305
  1. 40
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/CompletionWindow/CodeCompletionListView.cs
  2. 45
      src/Main/Base/Project/Src/Project/Solution/Solution.cs
  3. 29
      src/Tools/CheckFileHeaders/CheckFileHeaders.csproj
  4. 6
      src/Tools/CheckFileHeaders/CheckFileHeaders.sln
  5. 319
      src/Tools/CheckFileHeaders/Main.cs

40
src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/CompletionWindow/CodeCompletionListView.cs

@ -63,10 +63,6 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow @@ -63,10 +63,6 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow
public CodeCompletionListView(ICompletionData[] completionData)
{
if (this.completionData != null) {
Array.Clear(this.completionData, 0, completionData.Length);
}
Array.Sort(completionData);
this.completionData = completionData;
@ -89,16 +85,6 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow @@ -89,16 +85,6 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow
int oldSelectedItem = selectedItem;
int oldFirstItem = firstItem;
if (index < 0) {
selectedItem = -1;
if (oldSelectedItem >= 0) {
Invalidate(new Rectangle(0, (oldSelectedItem - firstItem) * ItemHeight, Width, (oldSelectedItem - firstItem + 1) * ItemHeight));
}
Update();
OnSelectedItemChanged(EventArgs.Empty);
return;
}
index = Math.Max(0, index);
selectedItem = Math.Max(0, Math.Min(completionData.Length - 1, index));
if (selectedItem < firstItem) {
@ -120,6 +106,17 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow @@ -120,6 +106,17 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow
}
}
public void ClearSelection()
{
if (selectedItem < 0)
return;
int itemNum = selectedItem - firstItem;
selectedItem = -1;
Invalidate(new Rectangle(0, itemNum * ItemHeight, Width, (itemNum + 1) * ItemHeight + 1));
Update();
OnSelectedItemChanged(EventArgs.Empty);
}
public void PageDown()
{
SelectIndex(selectedItem + MaxVisibleItem);
@ -170,14 +167,25 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow @@ -170,14 +167,25 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow
} else {
quality = 0;
}
if (bestQuality < quality || bestQuality == quality && bestPriority < priority) {
bool useThisItem;
if (bestQuality < quality) {
useThisItem = true;
} else {
useThisItem = bestQuality == quality && bestPriority < priority;
if (useThisItem && bestIndex == i)
useThisItem = false;
}
if (useThisItem) {
bestIndex = i;
bestPriority = priority;
bestQuality = quality;
}
}
}
SelectIndex(bestIndex);
if (bestIndex < 0)
ClearSelection();
else
SelectIndex(bestIndex);
}
protected override void OnPaint(PaintEventArgs pe)

45
src/Main/Base/Project/Src/Project/Solution/Solution.cs

@ -37,7 +37,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -37,7 +37,7 @@ namespace ICSharpCode.SharpDevelop.Project
while (stack.Count > 0) {
ISolutionFolder currentFolder = stack.Pop();
if (currentFolder is IProject) {
yield return ((IProject)currentFolder);
}
@ -76,7 +76,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -76,7 +76,7 @@ namespace ICSharpCode.SharpDevelop.Project
while (stack.Count > 0) {
ISolutionFolder currentFolder = stack.Pop();
if (currentFolder is ISolutionFolderContainer) {
ISolutionFolderContainer currentContainer = (ISolutionFolderContainer)currentFolder;
yield return currentContainer;
@ -113,7 +113,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -113,7 +113,7 @@ namespace ICSharpCode.SharpDevelop.Project
ISolutionFolder currentFolder = stack.Pop();
yield return currentFolder;
if (currentFolder is ISolutionFolderContainer) {
ISolutionFolderContainer currentContainer = (ISolutionFolderContainer)currentFolder;
foreach (ISolutionFolder subFolder in currentContainer.Folders) {
@ -240,10 +240,11 @@ namespace ICSharpCode.SharpDevelop.Project @@ -240,10 +240,11 @@ namespace ICSharpCode.SharpDevelop.Project
StringBuilder projectSection = new StringBuilder();
StringBuilder nestedProjectsSection = new StringBuilder();
Stack<ISolutionFolder> stack = new Stack<ISolutionFolder>();
foreach (ISolutionFolder solutionFolder in Folders) {
stack.Push(solutionFolder);
List<ISolutionFolder> folderList = Folders;
Stack<ISolutionFolder> stack = new Stack<ISolutionFolder>(folderList.Count);
// push folders in reverse order because it's a stack
for (int i = folderList.Count - 1; i >= 0; i--) {
stack.Push(folderList[i]);
}
while (stack.Count > 0) {
@ -253,7 +254,9 @@ namespace ICSharpCode.SharpDevelop.Project @@ -253,7 +254,9 @@ namespace ICSharpCode.SharpDevelop.Project
projectSection.Append(currentFolder.TypeGuid);
projectSection.Append("\")");
projectSection.Append(" = ");
projectSection.Append('"');projectSection.Append(currentFolder.Name);projectSection.Append("\", ");
projectSection.Append('"');
projectSection.Append(currentFolder.Name);
projectSection.Append("\", ");
string relativeLocation;
if (currentFolder is IProject) {
currentFolder.Location = ((IProject)currentFolder).FileName;
@ -263,12 +266,16 @@ namespace ICSharpCode.SharpDevelop.Project @@ -263,12 +266,16 @@ namespace ICSharpCode.SharpDevelop.Project
} else {
relativeLocation = currentFolder.Location;
}
projectSection.Append('"');projectSection.Append(relativeLocation);projectSection.Append("\", ");
projectSection.Append('"');projectSection.Append(currentFolder.IdGuid);projectSection.Append("\"");
projectSection.Append(Environment.NewLine);
projectSection.Append('"');
projectSection.Append(relativeLocation);
projectSection.Append("\", ");
projectSection.Append('"');
projectSection.Append(currentFolder.IdGuid);
projectSection.Append("\"");
projectSection.AppendLine();
if (currentFolder is IProject) {
// IProject project = (IProject)currentFolder;
// IProject project = (IProject)currentFolder;
// currently nothing to do. (I don't know if projects may have sections).
} else if (currentFolder is SolutionFolder) {
SolutionFolder folder = (SolutionFolder)currentFolder;
@ -318,25 +325,25 @@ namespace ICSharpCode.SharpDevelop.Project @@ -318,25 +325,25 @@ namespace ICSharpCode.SharpDevelop.Project
}
using (StreamWriter sw = new StreamWriter(fileName)) {
sw.Write("Microsoft Visual Studio Solution File, Format Version 9.00");sw.Write(Environment.NewLine);
sw.WriteLine("Microsoft Visual Studio Solution File, Format Version 9.00");
Version v = System.Reflection.Assembly.GetEntryAssembly().GetName().Version;
sw.Write("# SharpDevelop " + v.Major + "." + v.Minor + "." + v.Build + "." + v.Revision);sw.Write(Environment.NewLine);
sw.WriteLine("# SharpDevelop " + v.Major + "." + v.Minor + "." + v.Build + "." + v.Revision);
sw.Write(projectSection.ToString());
sw.Write(globalSection.ToString());
if (nestedProjectsSection.Length > 0) {
sw.Write("\tGlobalSection(NestedProjects) = preSolution");sw.Write(Environment.NewLine);
sw.WriteLine("\tGlobalSection(NestedProjects) = preSolution");
sw.Write(nestedProjectsSection.ToString());
sw.Write("\tEndGlobalSection");sw.Write(Environment.NewLine);
sw.WriteLine("\tEndGlobalSection");
}
sw.Write("EndGlobal");sw.Write(Environment.NewLine);
sw.WriteLine("EndGlobal");
}
}
static Regex versionPattern = new Regex("Microsoft Visual Studio Solution File, Format Version\\s+(?<Version>.*)", RegexOptions.Compiled);
static Regex projectLinePattern = new Regex("Project\\(\"(?<ProjectGuid>.*)\"\\)\\s+=\\s+\"(?<Title>.*)\",\\s*\"(?<Location>.*)\",\\s*\"(?<Guid>.*)\"", RegexOptions.Compiled);
static Regex globalSectionPattern = new Regex("\\s*GlobalSection\\((?<Name>.*)\\)\\s*=\\s*(?<Type>.*)", RegexOptions.Compiled);
@ -459,7 +466,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -459,7 +466,7 @@ namespace ICSharpCode.SharpDevelop.Project
}
}
#endregion
public CompilerResults Build()
{
return MSBuildProject.RunMSBuild(FileName, null);

29
src/Tools/CheckFileHeaders/CheckFileHeaders.csproj

@ -0,0 +1,29 @@ @@ -0,0 +1,29 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<OutputType>Exe</OutputType>
<RootNamespace>CheckFileHeaders</RootNamespace>
<AssemblyName>CheckFileHeaders</AssemblyName>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{1377E452-CBBA-4A41-8F06-F749DC99FE1A}</ProjectGuid>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<OutputPath>bin\Debug\</OutputPath>
<Optimize>false</Optimize>
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<OutputPath>bin\Release\</OutputPath>
<Optimize>true</Optimize>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Main.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
</Project>

6
src/Tools/CheckFileHeaders/CheckFileHeaders.sln

@ -0,0 +1,6 @@ @@ -0,0 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 9.00
# SharpDevelop 2.0.0.228
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CheckFileHeaders", "CheckFileHeaders.csproj", "{1377E452-CBBA-4A41-8F06-F749DC99FE1A}"
EndProject
Global
EndGlobal

319
src/Tools/CheckFileHeaders/Main.cs

@ -0,0 +1,319 @@ @@ -0,0 +1,319 @@
// <file>
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
// <license see="prj:///doc/license.txt">GNU General Public License</license>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
namespace CheckFileHeaders
{
class MainClass
{
static int Main(string[] args)
{
try {
MainClass m = new MainClass();
if (args.Length == 0) {
m.Run(@"D:\Corsavy\SharpDevelop\src\Main\StartUp");
} else {
m.Run(args[0]);
}
} catch (Exception ex) {
Console.WriteLine(ex);
}
Console.Write("Press any key to continue...");
Console.ReadKey(true);
return 0;
}
void Run(string dir)
{
foreach (string file in Directory.GetFiles(dir, "*.cs")) {
ProcessFile(file);
}
foreach (string subdir in Directory.GetDirectories(dir)) {
if (!subdir.EndsWith("\\.svn")) {
Run(subdir);
}
}
}
void ProcessFile(string file)
{
string content = GetFileContent(file);
string author, email;
int lastLine;
int headerType = AnalyzeHeader(content, out author, out email, out lastLine);
if (author == null)
author = "";
if (author == "") {
if (file.IndexOf("Main\\Core\\") >= 0) {
author = "Omnibrain";
} else {
Console.WriteLine(file);
Console.Write(" Mike? (Y/N): ");
if (char.ToUpper(Console.ReadKey().KeyChar) == 'Y') {
author = "Omnibrain";
}
Console.WriteLine();
}
}
bool ok = true;
switch (author) {
case "Mike Krger":
case "Mike Krüger":
case "Mike Krueger":
case "Omnibrain":
author = "Mike Krüger";
email = "mike@icsharpcode.net";
break;
case "Daniel Grunwald":
email = "daniel@danielgrunwald.de";
break;
default:
ok = false;
break;
}
if (ok) {
StringBuilder builder = new StringBuilder();
builder.AppendLine("// <file>");
builder.AppendLine("// <copyright see=\"prj:///doc/copyright.txt\">2002-2005 AlphaSierraPapa</copyright>");
builder.AppendLine("// <license see=\"prj:///doc/license.txt\">GNU General Public License</license>");
builder.Append("// <owner name=\"");
builder.Append(author);
builder.Append("\" email=\"");
builder.Append(email);
builder.AppendLine("\"/>");
builder.AppendLine("// <version>$Revision$</version>");
builder.AppendLine("// </file>");
builder.AppendLine();
int offset = FindLineOffset(content, lastLine + 1);
builder.Append(content.Substring(offset).Trim());
builder.AppendLine();
string newContent = builder.ToString();
if (newContent != content) {
Console.WriteLine("Write " + file);
using (StreamWriter w = new StreamWriter(file, false, GetOptimalEncoding(newContent))) {
w.Write(newContent);
}
}
} else {
Console.WriteLine("error, did not update " + file);
}
}
Encoding GetOptimalEncoding(string content)
{
foreach (char ch in content) {
if ((int)ch >= 128)
return Encoding.UTF8;
}
return Encoding.ASCII;
}
int FindLineOffset(string content, int lineNumber)
{
int num = 0;
for (int i = 0; i < content.Length; i++) {
if (num == lineNumber)
return i;
if (content[i] == '\n')
num++;
}
throw new ApplicationException("Cannot find line " + lineNumber);
}
#region AnalyzeHeader
Regex gplRegex = new Regex(@"// Copyright \(C\) 200\d(?:\s?-\s?200\d)?(?:\s?,\s?200\d)*\s+(\w+ \w+) \((\w+@\w+\.\w+)\)", RegexOptions.IgnoreCase);
Regex xmlRegex = new Regex(@"<owner name=""(\w+ \w+)"" email=""(\w+@\w+\.\w+)""\s?/>");
Regex sdRegex = new Regex(@"\* User: .*");
// Returns:
// 0 = no header
// 1 = XML header
// 2 = SharpDevelop header
// 3 = GPL header
// 4 = unknown header
int AnalyzeHeader(string content, out string author, out string email, out int lastLine)
{
author = null;
email = null;
int lineNumber = -1;
byte state = 0;
// state:
// 0 = start
// 1 = parse XML header
// 2 = parse SharpDevelop header
// 3 = search end of GPL header
using (StringReader r = new StringReader(content)) {
string line;
while ((line = r.ReadLine()) != null) {
lineNumber++;
line = line.Trim();
if (state == 0) {
if (line.Length == 0)
continue;
if (line.StartsWith("using ")) {
lastLine = -1;
return 0;
} else if (line == "// <file>") {
state = 1;
} else if (line == "/*") {
// ignore
} else if (line == "* Created by SharpDevelop") {
state = 2;
} else if (gplRegex.IsMatch(line)) {
Match m = gplRegex.Match(line);
author = m.Groups[1].Value;
email = m.Groups[2].Value;
state = 3;
} else if (line.StartsWith("//")) {
// ignore
} else {
break;
}
} else if (state == 1) {
if (line == "// </file>") {
lastLine = lineNumber;
return 1;
} else if (xmlRegex.IsMatch(line)) {
Match m = xmlRegex.Match(line);
author = m.Groups[1].Value;
email = m.Groups[2].Value;
}
} else if (state == 2) {
if (line == "*/") {
lastLine = lineNumber;
return 2;
} else if (sdRegex.IsMatch(line)) {
Match m = sdRegex.Match(line);
author = m.Groups[1].Value;
email = m.Groups[2].Value;
}
} else if (state == 3) {
if (line.Length == 0)
continue;
if (!line.StartsWith("//")) {
lastLine = lineNumber;
return 3;
}
} else {
throw new NotSupportedException();
}
}
}
lastLine = lineNumber - 1;
return 4;
}
#endregion
#region Reading files
string GetFileContent(string file)
{
using (StreamReader r = OpenFile(file)) {
return r.ReadToEnd();
}
}
StreamReader OpenFile(string fileName)
{
bool autodetectEncoding = true;
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
if (autodetectEncoding && fs.Length > 3) {
// the autodetection of StreamReader is not capable of detecting the difference
// between ISO-8859-1 and UTF-8 without BOM.
int firstByte = fs.ReadByte();
int secondByte = fs.ReadByte();
switch ((firstByte << 8) | secondByte) {
case 0x0000: // either UTF-32 Big Endian or a binary file; use StreamReader
case 0xfffe: // Unicode BOM (UTF-16 LE or UTF-32 LE)
case 0xfeff: // UTF-16 BE BOM
case 0xefbb: // start of UTF-8 BOM
// StreamReader autodetection works
fs.Position = 0;
return new StreamReader(fs);
default:
return AutoDetect(fs, (byte)firstByte, (byte)secondByte);
}
} else {
return new StreamReader(fs);
}
}
StreamReader AutoDetect(FileStream fs, byte firstByte, byte secondByte)
{
int max = (int)Math.Min(fs.Length, 500000); // look at max. 500 KB
const int ASCII = 0;
const int Error = 1;
const int UTF8 = 2;
const int UTF8Sequence = 3;
int state = ASCII;
int sequenceLength = 0;
byte b;
for (int i = 0; i < max; i++) {
if (i == 0) {
b = firstByte;
} else if (i == 1) {
b = secondByte;
} else {
b = (byte)fs.ReadByte();
}
if (b < 0x80) {
// normal ASCII character
if (state == UTF8Sequence) {
state = Error;
break;
}
} else if (b < 0xc0) {
// 10xxxxxx : continues UTF8 byte sequence
if (state == UTF8Sequence) {
--sequenceLength;
if (sequenceLength < 0) {
state = Error;
break;
} else if (sequenceLength == 0) {
state = UTF8;
}
} else {
state = Error;
break;
}
} else if (b > 0xc2 && b < 0xf5) {
// beginning of byte sequence
if (state == UTF8 || state == ASCII) {
state = UTF8Sequence;
if (b < 0xe0) {
sequenceLength = 1; // one more byte following
} else if (b < 0xf0) {
sequenceLength = 2; // two more bytes following
} else {
sequenceLength = 3; // three more bytes following
}
} else {
state = Error;
break;
}
} else {
// 0xc0, 0xc1, 0xf5 to 0xff are invalid in UTF-8 (see RFC 3629)
state = Error;
break;
}
}
fs.Position = 0;
switch (state) {
case Error:
return new StreamReader(fs, Encoding.Default);
default:
return new StreamReader(fs);
}
}
#endregion
}
}
Loading…
Cancel
Save