📄 compilerresultview.cs
字号:
// CompilerResultView.cs
// Copyright (C) 2000 Mike Krueger
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using System;
using System.Windows.Forms;
using System.Drawing;
using System.CodeDom.Compiler;
using System.IO;
using System.Diagnostics;
using SharpDevelop.Tool.Data;
namespace SharpDevelop.Gui.Navigation {
/// <summary>
/// This class displays the errors and warnings which the compiler outputs and
/// allows the user to jump to the source of the warnig / error
/// </summary>
public class CompilerResultListItem : ListViewItem
{
Point pos;
string filename;
public CompilerResultListItem(Point pos, String filename, string[] rowItems) : base(rowItems)
{
this.pos = pos;
this.filename = filename;
}
public string FileName {
get {
return filename;
}
}
public Point Pos {
get {
return pos;
}
}
}
public class CompilerResultView : ListView
{
ColumnHeader type = new ColumnHeader();
ColumnHeader line = new ColumnHeader();
ColumnHeader description = new ColumnHeader();
ColumnHeader file = new ColumnHeader();
int errors = 0;
int warnings = 0;
/// <summary>
/// returns the number of errors in the last compilation
/// </summary>
public int Errors {
get {
return errors;
}
}
/// <summary>
/// returns the number of warnings in the last compilation
/// </summary>
public int Warnings {
get {
return warnings;
}
}
public CompilerResultView()
{
type.Text = "!";
line.Text = Resource.GetString("CompilerResultView.LineText");
description.Text = Resource.GetString("CompilerResultView.DescriptionText");
file.Text = Resource.GetString("CompilerResultView.FileText");
Columns.Add(type);
Columns.Add(line);
Columns.Add(description);
Columns.Add(file);
FullRowSelect = true;
AutoArrange = true;
Alignment = ListViewAlignment.Left;
View = View.Details;
Dock = DockStyle.Fill;
GridLines = true;
Activation = ItemActivation.OneClick;
OnResize(null);
}
public static string GetRelPath(string path1, string path2)
{
int when = 0;
for (int i = 0; i < path1.Length; ++i) {
if (i < path2.Length && path1[i] == path2[i])
when = i;
else
break;
}
return path1.Substring(when);
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
type.Width = 20;
line.Width = 50;
int w = Width - type.Width - line.Width;
file.Width = w * 20 / 100;
description.Width = w - file.Width;
}
public CompilerResults CompilerResults = null;
public void ShowResults(CompilerResults res, string projectroot)
{
Debug.Assert(res != null, "SharpDevelop.Gui.Navigation.CompilerResultView : ShowResults : parameter CompilerResults res == null");
Debug.Assert(projectroot != null, "SharpDevelop.Gui.Navigation.CompilerResultView : ShowResults : parameter CompilerResults projectroot == null");
this.CompilerResults = res;
errors = 0;
warnings = 0;
BeginUpdate();
Items.Clear();
foreach (CompilerError err in res.Errors) {
if (err.IsWarning)
++warnings;
else
++errors;
ListViewItem item = new CompilerResultListItem(
new Point(err.Column - 1, err.Line - 1),
err.FileName,
new string [] {
err.IsWarning ? "W" : "E",
err.Line.ToString(),
err.ErrorText + "(" + err.ErrorNumber + ")",
GetRelPath(err.FileName, projectroot)
}
);
Items.Add(item);
}
EndUpdate();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -