📄 exportprojecttohtmldialog.cs
字号:
colorstr = "i" + colorstr;
}
if (word.Font.Bold) {
colorstr = "b" + colorstr;
}
if (Spans[colorstr] == null) {
Spans[colorstr] = "span" + ++curSpanNumber;
}
bool newColor = c != curColor || oldItalic != word.Font.Italic || oldBold != word.Font.Bold;
if (newColor) {
if (!firstSpan) {
curFileStream.Write("</span>" );
}
curFileStream.Write("<span class=\"" + Spans[colorstr].ToString() + "\">" );
spanOpen = true;
firstSpan = false;
}
curFileStream.Write(HtmlLize(word.Word));
if (newColor) {
curColor = c;
oldItalic = word.Font.Italic;
oldBold = word.Font.Bold;
}
break;
}
}
if (spanOpen) {
curFileStream.Write("</span>" );
}
curFileStream.Write("</TD>\r\n");
curFileStream.Write("</TR>\r\n");
}
curFileStream.Write("</TABLE></div>\r\n");
curFileStream.Write("<P>\r\n");
curFileStream.Write("This page was automatically generated by \r\n");
curFileStream.Write("<A TARGET=\"_blank\" HREF=\"http://www.icsharpcode.net/OpenSource/SD\">SharpDevelop</A>.\r\n");
curFileStream.Write("</p>\r\n");
curFileStream.Write("</body>\r\n");
curFileStream.Write("</html>\r\n");
curFileStream.Close();
return targetFile;
}
string HtmlLize(string str)
{
return str.Replace("&", "&").Replace("<", "<").Replace(">", ">");
}
void WriteIndexTable(string fileName, string name, ArrayList nameList, Hashtable table)
{
curIndexStreamStack.Push(File.CreateText(fileName));
StreamWriter curIndexStream = (StreamWriter)curIndexStreamStack.Peek();
curIndexStream.Write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\r\n");
curIndexStream.Write("<html>\r\n");
curIndexStream.Write("<head>\r\n");
curIndexStream.Write("<title>" + project.Name + "</title>\r\n");
curIndexStream.Write("</head>\r\n");
curIndexStream.Write("<body>\r\n");
curIndexStream.Write("<p>Location : ");
foreach (Descriptor d in nameList) {
curIndexStream.Write("<a href=\""+ d.url + "\">" + d.title + "</a>/");
}
curIndexStream.Write(name);
curIndexStream.Write("</p>\r\n");
nameList.Add(new Descriptor(name, Path.GetFileName(fileName)));
curIndexStream.Write("<TABLE SUMMARY=\"Directory\" BORDER=0 CELLSPACING=0 CELLPADDING=2 WIDTH=\"100%\">\r\n");
curIndexStream.Write(" <TR BGCOLOR=\"#F38C00\">\r\n");
curIndexStream.Write(" <TH WIDTH=\"1%\"> </TH>\r\n");
curIndexStream.Write(" <TH WIDTH=\"1%\" NOWRAP ALIGN=LEFT>Name</TH>\r\n");
curIndexStream.Write(" <TH WIDTH=\"1%\" NOWRAP ALIGN=RIGHT>Size</TH>\r\n");
curIndexStream.Write(" <TH WIDTH=\"1%\" NOWRAP ALIGN=LEFT>Date</TH>\r\n");
curIndexStream.Write(" <TH VALIGN=TOP ALIGN=LEFT> \r\n");
curIndexStream.Write(" </TH>\r\n");
curIndexStream.Write(" </TR>\r\n");
bool coloring = false;
foreach (DictionaryEntry entry in table) {
if (entry.Value is Hashtable) {
string filename = "index" + ++indexFileIndex + ".html";
WriteIndexTable(Path.GetDirectoryName(fileName) + Path.DirectorySeparatorChar + filename, entry.Key.ToString(), nameList, (Hashtable)entry.Value);
nameList.RemoveAt(nameList.Count - 1);
curIndexStream.Write(" <TR BGCOLOR=\"" + (coloring ? "#FFFFFF" : "#EEEEEE") + "\" VALIGN=TOP>\r\n");
curIndexStream.Write(" <TD NOWRAP VALIGN=TOP ALIGN=RIGHT><a href=\"" + filename + "\"><IMG ALIGN=ABSBOTTOM BORDER=0 WIDTH=16 HEIGHT=16 SRC=\"folderbitmap.png\"></a></TD>\r\n");
curIndexStream.Write(" <TD NOWRAP VALIGN=TOP ALIGN=LEFT><a href=\""+ filename + "\">" + entry.Key.ToString() + "</a> </TD>\r\n");
curIndexStream.Write(" <TD NOWRAP VALIGN=TOP ALIGN=RIGHT>-</TD>\r\n");
curIndexStream.Write(" <TD NOWRAP VALIGN=TOP ALIGN=RIGHT>-</TD>\r\n");
curIndexStream.Write(" <TD VALIGN=TOP ALIGN=LEFT> \r\n");
curIndexStream.Write(" </TD>\r\n");
curIndexStream.Write(" </TR>\r\n");
} else if (entry.Value is ProjectFile) {
ProjectFile fInfo = (ProjectFile)entry.Value;
DateTime time = Directory.GetLastAccessTime(fInfo.Name);
FileStream reader = File.OpenRead(fInfo.Name);
long size = reader.Length;
reader.Close();
int idx = GetImageIndex(fInfo.Name);
if (bitmapTable[idx] == null) {
string filename = "fileicon" + ++bitmapIconIndex + ".png";
Bitmap bmp = (Bitmap)iconService.ImageList.Images[idx];
bmp.Save(Path.GetDirectoryName(fileName) + Path.DirectorySeparatorChar + filename);
bitmapTable[idx] = filename;
}
string outFile = ExportFile(fInfo.Name, Path.GetDirectoryName(fileName));
++FilesExported;
curIndexStream.Write(" <TR BGCOLOR=\"" + (coloring ? "#FFFFFF" : "#EEEEEE") + "\" VALIGN=TOP>\r\n");
curIndexStream.Write(" <TD NOWRAP VALIGN=TOP ALIGN=RIGHT><a href=\"" + outFile + "\"><IMG ALIGN=ABSBOTTOM BORDER=0 WIDTH=16 HEIGHT=16 SRC=\"" + bitmapTable[idx].ToString() +"\"></a></TD>\r\n");
curIndexStream.Write(" <TD NOWRAP VALIGN=TOP ALIGN=LEFT><a href=\"" + outFile + "\">" + Path.GetFileName(fInfo.Name) + "</a> </TD>\r\n");
curIndexStream.Write(" <TD NOWRAP VALIGN=TOP ALIGN=RIGHT>" + size + "</TD>\r\n");
curIndexStream.Write(" <TD NOWRAP VALIGN=TOP ALIGN=RIGHT>" + time.ToString("d") + "</TD>\r\n");
curIndexStream.Write(" <TD VALIGN=TOP ALIGN=LEFT> \r\n");
curIndexStream.Write(" </TD>\r\n");
curIndexStream.Write(" </TR>\r\n");
}
coloring = !coloring;
}
curIndexStream.Write("</TABLE>\r\n");
curIndexStream.Write("<p>\r\n");
curIndexStream.Write("This page was automatically generated by \r\n");
curIndexStream.Write("<A TARGET=\"_blank\" HREF=\"http://www.icsharpcode.net/OpenSource/SD\">SharpDevelop</A>.\r\n");
curIndexStream.Write("</p>\r\n");
curIndexStream.Write("</body>\r\n");
curIndexStream.Write("</html>\r\n");
lock (this) {
curIndexStream.Close();
curIndexStreamStack.Pop();
}
}
delegate void MyD();
void QuitDialog()
{
DialogResult = DialogResult.OK;
}
Thread exportFilesThread;
void ExportFilesThread()
{
resourceService.GetBitmap("Icons.16x16.ClosedFolderBitmap").Save(fileUtilityService.GetDirectoryNameWithSeparator(pathTextBox.Text) + "folderbitmap.png");
WriteIndexTable(fileUtilityService.GetDirectoryNameWithSeparator(pathTextBox.Text) + "index.html", "[ROOT]", new ArrayList(), projectTable);
CreateCSS(pathTextBox.Text);
Invoke(new MyD(QuitDialog));
}
void StopThread(object sender, EventArgs e)
{
lock (this) {
exportFilesThread.Abort();
curFileStream.Close();
while (curIndexStreamStack.Count > 0) {
((StreamWriter)curIndexStreamStack.Pop()).Close();
}
QuitDialog();
}
}
void CreateCSS(string targetPath)
{
lock (this) {
StreamWriter sw = File.CreateText(targetPath + Path.DirectorySeparatorChar + "sdcss.css");
sw.Write("div.code\r\n");
sw.Write("{\r\n");
sw.Write(" background-color: rgb(255,255,255);\r\n");
sw.Write(" font-family: \"Lucida Console\", \"courier new\", courier;\r\n");
sw.Write(" color: rgb(0,0,0);\r\n");
sw.Write(" font-size: x-small;\r\n");
sw.Write(" padding: 1em;\r\n");
sw.Write(" margin: 1em;\r\n");
sw.Write("}\r\n");
foreach (DictionaryEntry entry in Spans) {
string color = entry.Key.ToString();
string name = entry.Value.ToString();
bool bold = color.StartsWith("b");
if (bold) {
color = color.Substring(1);
}
bool italic = color.StartsWith("i");
if (italic) {
color = color.Substring(1);
}
sw.Write("div.code span." + name +"\r\n");
sw.Write("{\r\n");
sw.Write(" color: rgb("+ color + ");\r\n");
if (bold) {
sw.Write(" font-weight: bold;\r\n");
} else
if (italic) {
sw.Write(" font-weight: italic;\r\n");
} else {
sw.Write(" font-weight: normal;\r\n");
}
sw.Write("}\r\n");
}
sw.Close();
}
}
void ExportProject(object sender, EventArgs e)
{
if (!Directory.Exists(pathTextBox.Text)) {
MessageBox.Show("Directory doesn't exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
foreach (ProjectFile fInfo in project.ProjectFiles) {
if (fInfo.Subtype != Subtype.Directory) {
if (fInfo.BuildAction == BuildAction.Compile ||
fInfo.BuildAction == BuildAction.Nothing) {
string relativefile = fileUtilityService.AbsoluteToRelativePath(project.BaseDirectory, fInfo.Name);
Hashtable table = GetPath(relativefile, projectTable, true);
table[Path.GetFileName(fInfo.Name)] = fInfo;
}
}
}
StartExporting();
exportFilesThread = new Thread(new ThreadStart(ExportFilesThread));
exportFilesThread.IsBackground = true;
exportFilesThread.Start();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -