[c#]代码库
// Decompiled with JetBrains decompiler
// Type: sliver.SnippetCompiler.Forms.MainForm
// Assembly: SnippetCompiler, Version=3.0.2.0, Culture=neutral, PublicKeyToken=null
// MVID: A445EC8B-5D19-44A9-B371-2BA0FA6B0564
// Assembly location: C:\Users\Seraphim\Desktop\SnippetCompiler\SnippetCompiler.exe
using sliver.SnippetCompiler.Commands;
using sliver.SnippetCompiler.Configuration;
using sliver.SnippetCompiler.Controls;
using sliver.SnippetCompiler.Languages;
using sliver.SnippetCompiler.Properties;
using sliver.SnippetCompiler.Services;
using System;
using System.CodeDom.Compiler;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
namespace sliver.SnippetCompiler.Forms
{
internal sealed class MainForm : Form, IApplication
{
private bool _firstActivation = true;
private IEditor _lastEditor;
private Process _runningProcess;
private ClipboardChangeNotifier _clipboardChangeNotifier;
private readonly ToolStripRenderer _toolStripRenderer;
private IContainer components;
private StatusStrip statusBar1;
private SplitContainer splitContainer;
private CodeTabControl tabControl;
private TabControl bottomTabControl;
private TabPage tabPage1;
private TabPage tabPage2;
private NotifyIcon notifyIcon;
private ListView lvErrors;
private ColumnHeader columnHeader1;
private ColumnHeader columnHeader2;
private ColumnHeader columnHeader3;
private ColumnHeader columnHeader4;
private TextBox txtOutput;
private ToolStripStatusLabel toolStripStatusLabel;
private ToolStripStatusLabel lineStatusStripLabel;
private ToolStripStatusLabel colStatusStripLabel;
private ContextMenuStrip errorsContextMenu;
private ScContextMenuStrip editorContextMenu;
private Panel panel1;
private CodeTabPageContextMenu tabControlContextMenu;
private MenuItem menuItem1;
private MenuItem menuItem2;
private MenuItem menuItem3;
private ToolStripMenuItem saveToolStripMenuItem;
private ToolStripMenuItem saveAsToolStripMenuItem;
private ToolStripMenuItem closeToolStripMenuItem;
internal ScToolStripContainer toolStripContainer;
private ScMenuStrip mainMenuStrip;
private ImageList errorsImageList;
private ContextMenuStrip notifyIconContextMenu;
private ToolStripMenuItem openNotifyIconMenuItem;
private ToolStripMenuItem exitNotifyIconMenuItem;
private ToolStripMenuItem copyToolStripMenuItem;
public bool OutputVisible
{
get
{
return !this.splitContainer.Panel2Collapsed;
}
set
{
this.splitContainer.Panel2Collapsed = !value;
}
}
string IApplication.StatusText
{
get
{
return this.toolStripStatusLabel.Text;
}
set
{
this.toolStripStatusLabel.Text = value;
}
}
IToolBarCollection IApplication.ToolBars
{
get
{
return (IToolBarCollection)this.toolStripContainer;
}
}
Font IApplication.Font
{
get
{
return this.Font;
}
}
IMenu IApplication.EditorContextMenu
{
get
{
return (IMenu)this.editorContextMenu;
}
}
Form IApplication.MainForm
{
get
{
return (Form)this;
}
}
IMenu IApplication.MainMenu
{
get
{
return (IMenu)this.mainMenuStrip;
}
}
ToolStripRenderer IApplication.ToolStripRenderer
{
get
{
return this._toolStripRenderer;
}
}
public MainForm()
{
this.InitializeComponent();
this._toolStripRenderer = (ToolStripRenderer)new ToolStripProfessionalRenderer();
this.Font = SystemFonts.DialogFont;
this.mainMenuStrip.Font = SystemFonts.MenuFont;
((IApplication)this).ToolBars.ToolBarAdded += new ToolBarEventHandler(this.ToolBars_ToolBarAdded);
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
ToolStripRenderer toolStripRenderer = ServiceManager.Application.ToolStripRenderer;
this.toolStripContainer.TopToolStripPanel.Renderer = toolStripRenderer;
this.mainMenuStrip.Renderer = toolStripRenderer;
this.editorContextMenu.Renderer = toolStripRenderer;
this.notifyIconContextMenu.Renderer = toolStripRenderer;
this.tabControlContextMenu.Renderer = toolStripRenderer;
this.errorsContextMenu.Renderer = toolStripRenderer;
this._clipboardChangeNotifier = new ClipboardChangeNotifier((Form)this);
this._clipboardChangeNotifier.ClipboardChanged += new EventHandler(this.ClipboardChanged);
IEditorContainer editorContainer = ServiceManager.EditorContainer;
editorContainer.SelectedEditorChanged += new EventHandler(this.EditorContainer_SelectedEditorChanged);
editorContainer.EditorClosed += new EditorEventHandler(this.EditorContainer_EditorClosed);
editorContainer.EditorClosing += new EditorEventHandler(this.EditorContainer_EditorClosing);
editorContainer.FileLoaded += new EditorEventHandler(this.EditorContainer_FileLoaded);
MainForm.CreateTemplateFiles();
MenuBuilder.CreateTemplateMenuItems();
MenuBuilder.CreateOpenMenuItems();
this.SetFontInfo();
// ISSUE: variable of a compiler-generated type
sliver.SnippetCompiler.Configuration.Settings settings = ServiceManager.Settings;
if (!this.DesignMode)
{
this.notifyIcon.Icon = this.Icon;
this.notifyIcon.Text = Application.ProductName;
}
this.Text = Application.ProductName;
this.tabControl.Multiline = settings.MultiRowTabs;
int num = settings.ShowMethodInformation ? 1 : 0;
if (settings.FormSize != Size.Empty)
this.Size = settings.FormSize;
if (settings.SaveWindowLocation)
{
if (settings.WindowIsMaximized)
this.WindowState = FormWindowState.Maximized;
else
this.Location = settings.WindowLocation;
}
this.notifyIcon.Visible = settings.MinimizeToTray;
if (settings.StartMinimized)
{
this.ShowInTaskbar = false;
this.WindowState = FormWindowState.Minimized;
}
this.SetUpSimpleEventHandlers();
}
internal void LoadToolStripSettings()
{
ToolStripManager.LoadSettings((Form)this);
}
private void SetUpSimpleEventHandlers()
{
this.openNotifyIconMenuItem.Click += (EventHandler)delegate
{
this.ShowForm();
};
this.exitNotifyIconMenuItem.Click += (EventHandler)delegate
{
this.Close();
};
ServiceManager.Settings.PropertyChanged += (PropertyChangedEventHandler)((sender, propChangedEventArgs) => this.HandleChangedSetting(propChangedEventArgs.PropertyName));
}
public void RegisterEditorService()
{
ServiceManager.Instance.AddService(typeof(IEditorContainer), this.tabControl);
}
private void ClipboardChanged(object sender, EventArgs e)
{
IEditor editor = ServiceManager.Editor;
if (editor == null)
return;
ServiceManager.CommandManager[typeof(PasteCommand)].Enabled = editor.CanPaste;
}
private static void CreateTemplateFiles()
{
string templatesPath = ServiceManager.Settings.TemplatesPath;
foreach (ILanguage language in ServiceManager.LanguageManager.Languages)
{
string path = Path.Combine(templatesPath, "Default." + language.FileExtension);
if (!File.Exists(path))
{
string defaultTemplate = language.GetDefaultTemplate();
if (defaultTemplate != null)
{
if (!Directory.Exists(templatesPath))
Directory.CreateDirectory(templatesPath);
File.WriteAllText(path, defaultTemplate);
}
}
}
}
public void CreateMenusAndToolBars()
{
CommandManager commandManager = ServiceManager.CommandManager;
IMenu mainMenu = ((IApplication)this).MainMenu;
IMenu menu1 = mainMenu.AddMenu("文件");
IMenu menu2 = mainMenu.AddMenu("编辑");
IMenu menu3 = mainMenu.AddMenu("视图");
IMenu menu4 = mainMenu.AddMenu("构建");
IMenu menu5 = mainMenu.AddMenu("调试");
ICommand command1 = ServiceManager.CommandManager[typeof(ViewOutputCommand)];
menu3.AddToggleMenu(command1);
menu3.AddMenu("工具栏");
IToolBar toolBar = ServiceManager.Application.ToolBars.AddToolBar("标准", true);
ICommand command2 = commandManager[typeof(SaveCommand)];
ICommand command3 = commandManager[typeof(SaveAllCommand)];
toolBar.AddMenuButton("新建", (ICommand)new NewDefaultCommand()).Popup += new EventHandler(MenuBuilder.NewMenuButton_Popup);
toolBar.AddMenuButton("打开", commandManager[typeof(OpenFileCommand)]).Popup += new EventHandler(MenuBuilder.OpenMenuButton_Popup);
toolBar.AddButton(command2);
toolBar.AddButton(command3);
toolBar.AddSeparator();
ICommand command4 = commandManager[typeof(CutCommand)];
ICommand command5 = commandManager[typeof(CopyCommand)];
ICommand command6 = commandManager[typeof(PasteCommand)];
ICommand command7 = commandManager[typeof(DeleteCommand)];
toolBar.AddButton(command4);
toolBar.AddButton(command5);
toolBar.AddButton(command6);
toolBar.AddSeparator();
ICommand command8 = commandManager[typeof(UndoCommand)];
ICommand command9 = commandManager[typeof(RedoCommand)];
toolBar.AddButton(command8);
toolBar.AddButton(command9);
toolBar.AddSeparator();
ICommand command10 = commandManager[typeof(CloseEditorCommand)];
ICommand command11 = commandManager[typeof(SaveAsCommand)];
ICommand command12 = commandManager[typeof(CloseAllCommand)];
ICommand command13 = commandManager[typeof(OpenProjectCommand)];
ICommand command14 = commandManager[typeof(SaveProjectCommand)];
ICommand command15 = commandManager[typeof(ImportVisualStudioProjectCommand)];
menu1.AddMenu("新建", (Image)Resources.NewFile).Popup += new EventHandler(MenuBuilder.NewMenuButton_Popup);
menu1.AddMenu("打开", (Image)Resources.Open).Popup += new EventHandler(MenuBuilder.OpenMenuButton_Popup);
menu1.AddMenuItem(command10, Keys.F4 | Keys.Control);
menu1.AddSeparator();
menu1.AddMenuItem(command2, Keys.S | Keys.Control);
menu1.AddMenuItem(command11);
menu1.AddMenuItem(command3);
menu1.AddSeparator();
menu1.AddMenuItem(command12);
menu1.AddSeparator();
IMenu menu6 = menu1.AddMenu("工程");
menu6.AddMenuItem(command13);
menu6.AddMenuItem(command14);
menu1.AddSeparator();
menu1.AddMenuItem(command15);
ICommand command16 = commandManager[typeof(ExportHtmlToFileCommand)];
ICommand command17 = commandManager[typeof(ExportHtmlToClipboardCommand)];
ICommand command18 = commandManager[typeof(ExportRtfToFileCommand)];
ICommand command19 = commandManager[typeof(ExportRtfToClipboardCommand)];
IMenu menu7 = menu1.AddMenu("导出");
menu7.AddMenuItem(command16);
menu7.AddMenuItem(command17);
menu7.AddMenuItem(command18);
menu7.AddMenuItem(command19);
menu1.AddSeparator();
ICommand command20 = commandManager[typeof(PrintCommand)];
ICommand command21 = commandManager[typeof(PrintPreviewCommand)];
ICommand command22 = commandManager.Add((ICommand)new ExitCommand((Form)this));
ICommand command23 = commandManager[typeof(SelectAllCommand)];
menu1.AddMenuItem(command20, Keys.P | Keys.Control);
menu1.AddMenuItem(command21);
menu1.AddSeparator();
menu1.AddMenuItem(command22);
menu2.AddMenuItem(command8, Keys.Z | Keys.Control);
menu2.AddMenuItem(command9, Keys.Y | Keys.Control);
menu2.AddSeparator();
menu2.AddMenuItem(command4, Keys.X | Keys.Control);
menu2.AddMenuItem(command5, Keys.C | Keys.Control);
menu2.AddMenuItem(command6, Keys.V | Keys.Control);
menu2.AddMenuItem(command7);
menu2.AddSeparator();
menu2.AddMenuItem(command23, Keys.A | Keys.Control);
menu2.AddSeparator();
IMenu menu8 = menu2.AddMenu("查找与替换");
ICommand command24 = commandManager[typeof(FindCommand)];
ICommand command25 = commandManager[typeof(FindNextCommand)];
ICommand command26 = commandManager[typeof(ReplaceCommand)];
ICommand command27 = commandManager[typeof(IncrementalSearchCommand)];
menu8.AddMenuItem(command24, Keys.F | Keys.Control);
menu8.AddMenuItem(command25, Keys.F3);
menu8.AddMenuItem(command26, Keys.H | Keys.Control);
menu8.AddMenuItem(command27, Keys.I | Keys.Control);
menu2.AddMenu("Go To").AddMenuItem((ICommand)new GoToLineCommand());
IMenu menu9 = menu2.AddMenu("高级");
menu9.AddMenuItem(commandManager[typeof(ViewWhiteSpaceCommand)]);
menu9.AddMenuItem(commandManager[typeof(MakeUppercaseCommand)], Keys.U | Keys.Shift | Keys.Control);
menu9.AddMenuItem(commandManager[typeof(MakeLowercaseCommand)], Keys.U | Keys.Control);
menu9.AddMenuItem(commandManager[typeof(DeleteHorizontalWhiteSpaceCommand)]);
menu9.AddMenuItem(commandManager[typeof(CommentSelectionCommand)]);
menu9.AddMenuItem(commandManager[typeof(UncommentSelectionCommand)]);
menu9.AddMenuItem(commandManager[typeof(DecreaseIndentCommand)]);
menu9.AddMenuItem(commandManager[typeof(IncreaseIndentCommand)]);
menu9.AddMenuItem(commandManager[typeof(DuplicateLineCommand)], Keys.D | Keys.Control);
IMenu menu10 = menu2.AddMenu("书签");
ICommand command28 = commandManager[typeof(ToggleBookmarkCommand)];
ICommand command29 = commandManager[typeof(NextBookmarkInDocumentCommand)];
ICommand command30 = commandManager[typeof(PreviousBookmarkInDocumentCommand)];
ICommand command31 = commandManager[typeof(ClearBookmarksCommand)];
menu10.AddMenuItem(command28);
menu10.AddMenuItem(command29);
menu10.AddMenuItem(command30);
menu10.AddMenuItem(command31);
menu4.AddMenuItem(commandManager[typeof(BuildCurrentCommand)], Keys.B | Keys.Shift | Keys.Control);
menu4.AddMenuItem(commandManager[typeof(BuildAllCommand)]);
menu4.AddMenuItem(commandManager[typeof(BuildCurrentToFileCommand)]);
menu4.AddMenuItem(commandManager[typeof(BuildAllToFileCommand)]);
ICommand command32 = commandManager[typeof(StartCommand)];
ICommand command33 = commandManager[typeof(StartAllCommand)];
ICommand command34 = commandManager[typeof(KillProcessCommand)];
menu5.AddMenuItem(command32, Keys.F5);
menu5.AddMenuItem(command33, Keys.F5 | Keys.Control);
menu5.AddMenuItem(commandManager[typeof(StartAsWinFormCommand)], Keys.F6);
menu5.AddMenuItem(commandManager[typeof(StartAllAsWinFormCommand)], Keys.F6 | Keys.Control);
menu5.AddSeparator();
menu5.AddMenuItem(command34, Keys.None);
IMenu menu11 = mainMenu.AddMenu("工具");
menu11.AddMenuItem(ServiceManager.CommandManager[typeof(ShowReferencesCommand)]);
menu11.AddMenuItem(ServiceManager.CommandManager[typeof(AddInsCommand)]);
menu11.AddSeparator();
menu11.AddMenuItem(ServiceManager.CommandManager[typeof(OrganizeTemplatesCommand)]);
menu11.AddSeparator();
menu11.AddMenuItem(ServiceManager.CommandManager[typeof(ShowOptionsCommand)]);
IMenu menu12 = mainMenu.AddMenu("帮助");
menu12.AddMenuItem(ServiceManager.CommandManager[typeof(StartHelpCommand)], Keys.F1);
menu12.AddMenuItem(ServiceManager.CommandManager[typeof(YourFeedbackCommand)]);
menu12.AddMenuItem(ServiceManager.CommandManager[typeof(GoToWebsiteCommand)]);
menu12.AddSeparator();
menu12.AddMenuItem(ServiceManager.CommandManager[typeof(AboutCommand)]);
toolBar.AddButton(command24);
toolBar.AddSeparator();
toolBar.AddToggleButton(command1);
toolBar.AddSeparator();
toolBar.AddButton(command32);
toolBar.AddButton(command33);
toolBar.AddSeparator();
toolBar.AddButton(command34);
}
private void NotificationAreaContextMenu_Click(object sender, EventArgs e)
{
switch (((MenuItem)sender).Text.Replace("&", ""))
{
case "打开":
this.ShowForm();
break;
case "退出":
this.Close();
break;
}
}
private void SetFontInfo()
{
// ISSUE: variable of a compiler-generated type
sliver.SnippetCompiler.Configuration.Settings settings = ServiceManager.Settings;
this.txtOutput.Font = new Font(settings.OutputFontName, settings.OutputFontSize);
this.lvErrors.Font = new Font(settings.ErrorFontName, settings.ErrorFontSize);
}
private void SetDocumentMenus()
{
bool flag1 = ServiceManager.EditorContainer.Count > 0;
CommandManager commandManager = ServiceManager.CommandManager;
((IApplication)this).MainMenu.MenuItems["文件"].MenuItems["导出"].Enabled = flag1;
if (!flag1)
{
this.colStatusStripLabel.Text = "";
this.lineStatusStripLabel.Text = "";
ServiceManager.FindReplace.Visible = false;
}
if (ServiceManager.Editor != null)
{
bool flag2 = false;
commandManager[typeof(BuildCurrentCommand)].Enabled = !flag2;
commandManager[typeof(BuildCurrentToFileCommand)].Enabled = !flag2;
commandManager[typeof(StartAsWinFormCommand)].Enabled = !flag2;
commandManager[typeof(StartAllAsWinFormCommand)].Enabled = !flag2;
}
this.SetDocumentStateMenus();
}
private void SetDocumentStateMenus()
{
CommandManager commandManager = ServiceManager.CommandManager;
if (ServiceManager.Editor == null)
{
commandManager[typeof(UndoCommand)].Enabled = false;
commandManager[typeof(RedoCommand)].Enabled = false;
commandManager[typeof(PasteCommand)].Enabled = false;
commandManager[typeof(CutCommand)].Enabled = false;
commandManager[typeof(CopyCommand)].Enabled = false;
}
else
{
commandManager[typeof(UndoCommand)].Enabled = ServiceManager.Editor.CanUndo;
commandManager[typeof(RedoCommand)].Enabled = ServiceManager.Editor.CanRedo;
commandManager[typeof(PasteCommand)].Enabled = ServiceManager.Editor.CanPaste;
commandManager[typeof(CutCommand)].Enabled = true;
commandManager[typeof(CopyCommand)].Enabled = true;
}
}
protected override void OnActivated(EventArgs e)
{
base.OnActivated(e);
if (!this.ShowInTaskbar)
this.ShowInTaskbar = true;
if (!this._firstActivation)
return;
this._firstActivation = false;
this.ResizeErrorTextColumnInListView();
ServiceManager.CommandManager[typeof(KillProcessCommand)].Enabled = false;
}
internal void CompileAndRun(bool allFiles, string outputFilename, CompileType compileType, bool run)
{
ServiceManager.Application.StatusText = "Starting build";
if (allFiles)
{
foreach (IEditor editor in ServiceManager.EditorContainer)
editor.ClearErrors();
}
else
ServiceManager.Editor.ClearErrors();
ILanguage language1 = (ILanguage)null;
if (allFiles)
{
ILanguage language2 = (ILanguage)null;
foreach (IEditor editor1 in ServiceManager.EditorContainer)
{
if (language2 == null)
language2 = editor1.Language;
else if (language2.GetType() != editor1.Language.GetType())
{
string str = "";
foreach (IEditor editor2 in ServiceManager.EditorContainer)
str += string.Format("{0}: {1}\n", editor2.FileInfo.Name, editor2.Language.Name);
sliver.SnippetCompiler.Util.ShowErrorMessageBox("When you Start All, all non-aspx snippets must be of the same language. The snippets and their types follow:\n\n{0}", str);
return;
}
}
if (language2 == null)
allFiles = false;
else
language1 = language2;
}
else
language1 = ServiceManager.Editor.Language;
this.lvErrors.Items.Clear();
this.txtOutput.Text = "";
string assemblyName = Path.ChangeExtension(!run || !ServiceManager.Settings.UseCustomAssemblyName ? (outputFilename != null ? outputFilename : Path.Combine(CompilerUtil.GetNewCompileFolder(), "output")) : ServiceManager.Settings.CustomAssemblyName, compileType == CompileType.Dll ? "dll" : "exe");
string newCompileFolder = CompilerUtil.GetNewCompileFolder();
if (newCompileFolder == null)
{
DialogResult dr = MessageBox.Show("A temporary folder required for compilation could not be created. Aborting.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
else
{
string[] strArray;
if (!allFiles)
strArray = new string[1]
{
CompilerUtil.CreateCodeFile(ServiceManager.Editor, newCompileFolder)
};
else
strArray = CompilerUtil.CreateCodeFiles(newCompileFolder);
string[] files = strArray;
CompileResults compileResults = language1.Compile(compileType, assemblyName, ServiceManager.Settings.References.ToStringArray(), files, ServiceManager.Settings.GenerateDebugSymbols);
ServiceManager.Application.StatusText = "Build " + (compileResults.Errors.HasErrors ? "failed" : "succeeded");
if (compileResults.Errors.HasErrors || compileResults.Errors.HasWarnings)
{
this.DisplayCompileErrors(compileResults.Errors);
if (compileResults.Errors.HasErrors)
{
ServiceManager.CommandManager[typeof(ViewOutputCommand)].Selected = true;
return;
}
}
if (!run)
return;
if (compileResults.Output.Count > 0)
{
StringBuilder stringBuilder = new StringBuilder();
foreach (string str in compileResults.Output)
stringBuilder.Append(str).Append("\r\n");
this.txtOutput.Text = stringBuilder.ToString();
}
if (ServiceManager.Settings.ForceRuntime)
{
if (ServiceManager.Settings.ForcedRuntimeVersion != string.Format("v{0}.{1}.{2}", Environment.Version.Major, Environment.Version.Minor, Environment.Version.Build))
{
string str = Path.Combine(Path.Combine(Application.StartupPath, "ConfigFiles"), ServiceManager.Settings.ForcedRuntimeVersion + ".config");
string destFileName = assemblyName + ".config";
if (!File.Exists(str))
{
sliver.SnippetCompiler.Util.ShowErrorMessageBox("Cannot force the runtime version '{0}' since the file '{1}' does not exist.", ServiceManager.Settings.ForcedRuntimeVersion, str);
}
else
{
try
{
File.Copy(str, destFileName);
}
catch (Exception ex)
{
sliver.SnippetCompiler.Util.ShowErrorMessageBox("An error occured while copying the config file '{0}'. Please ensure this config file exists.\n\n{1}", str, ex.Message);
}
}
}
}
try
{
string str1 = ServiceManager.Settings.RunFromCommandPrompt ? Environment.GetEnvironmentVariable("comspec") : assemblyName;
string str2;
if (!ServiceManager.Settings.RunFromCommandPrompt)
str2 = "";
else
str2 = string.Concat(new object[4]
{
"/k ",
'"',
assemblyName,
'"'
});
string str3 = str2;
CompilerUtil.CopyReferences(new FileInfo(str1).Directory);
ProcessStartInfo startInfo = new ProcessStartInfo(str1);
startInfo.WorkingDirectory = Path.GetDirectoryName(str1);
startInfo.Arguments = str3;
if (ServiceManager.Settings.RedirectOutput)
{
startInfo.RedirectStandardOutput = true;
startInfo.UseShellExecute = false;
}
this._runningProcess = Process.Start(startInfo);
if (ServiceManager.Settings.RedirectOutput)
{
this.txtOutput.AppendText(this._runningProcess.StandardOutput.ReadToEnd());
this._runningProcess.WaitForExit();
this.bottomTabControl.SelectedTab = this.bottomTabControl.TabPages[1];
ServiceManager.CommandManager[typeof(ViewOutputCommand)].Selected = true;
}
else
{
this._runningProcess.EnableRaisingEvents = true;
this._runningProcess.Exited += new EventHandler(this.RunningProcess_Exited);
ServiceManager.CommandManager[typeof(KillProcessCommand)].Enabled = true;
}
}
catch (Exception ex)
{
sliver.SnippetCompiler.Util.ShowErrorMessageBox("Error while trying to start '{0}':\n\n{1} ", assemblyName, ex.Message);
}
}
}
public void SetStatusBarText(string text, params object[] args)
{
this.toolStripStatusLabel.Text = string.Format(text, args);
}
private void DisplayCompileErrors(CompilerErrorCollection errors)
{
CodeTabPage selectedTab = this.tabControl.SelectedTab;
foreach (CompilerError error in (CollectionBase)errors)
{
string fileName = Path.GetFileName(error.FileName);
string snippetFileName = selectedTab.Text;
int snippetIndex = this.tabControl.TabPages.IndexOf((TabPage)selectedTab);
if (fileName != null)
{
try
{
snippetIndex = int.Parse(fileName);
IEditor editor = ServiceManager.EditorContainer[snippetIndex];
if (editor != null)
{
snippetFileName = editor.FileInfo.Name;
editor.AddError(error.Line, error.Column, error.ErrorText, error.IsWarning);
}
}
catch
{
}
}
ListViewItem listViewItem = (ListViewItem)new ErrorListViewItem(snippetIndex, snippetFileName, error);
listViewItem.ImageIndex = error.IsWarning ? 1 : 0;
this.lvErrors.Items.Add(listViewItem);
}
}
private void lvErrors_MouseUp(object sender, MouseEventArgs e)
{
if (this.lvErrors.SelectedItems.Count == 0)
return;
if (e.Button == MouseButtons.Right)
{
this.errorsContextMenu.Show((Control)this.lvErrors, this.lvErrors.PointToClient(Control.MousePosition));
}
else
{
try
{
ErrorListViewItem errorListViewItem = (ErrorListViewItem)this.lvErrors.SelectedItems[0];
this.tabControl.SelectedIndex = errorListViewItem.SnippetIndex;
CompilerError compilerError = errorListViewItem.CompilerError;
if (compilerError.Line <= 0)
return;
IEditor editor = ServiceManager.Editor;
int offset = editor.GetOffset(compilerError.Line, compilerError.Column);
editor.TemporarilyHighlightWord(SystemColors.HighlightText, SystemColors.Highlight, TimeSpan.FromMilliseconds(500.0), offset);
editor.Select(offset, 0, true);
this.tabControl.SelectedTab.Focus();
}
catch
{
}
}
}
private void ConnectEditor(IEditor editor)
{
if (editor == null)
return;
editor.SelectionChanged += new EventHandler(this.Editor_SelectionChanged);
this.SetLineColPanels();
this.SetDocumentStateMenus();
}
private void DisconnectEditor(IEditor editor)
{
if (editor == null)
return;
editor.SelectionChanged -= new EventHandler(this.Editor_SelectionChanged);
}
protected override void OnFormClosing(FormClosingEventArgs e)
{
// ISSUE: variable of a compiler-generated type
sliver.SnippetCompiler.Configuration.Settings settings = ServiceManager.Settings;
if (e.CloseReason == CloseReason.UserClosing && settings.MinimizeToTrayOnClose && this.WindowState != FormWindowState.Minimized)
{
e.Cancel = true;
this.SaveSettings();
this.WindowState = FormWindowState.Minimized;
}
else if (ServiceManager.EditorContainer.CloseAll())
{
switch (this.WindowState)
{
case FormWindowState.Normal:
settings.FormSize = this.Size;
settings.OutputPanelHeight = this.bottomTabControl.Height;
break;
case FormWindowState.Maximized:
settings.OutputPanelHeight = this.bottomTabControl.Height;
break;
}
settings.WindowIsMaximized = this.WindowState == FormWindowState.Maximized;
settings.ShowErrorsOutput = this.bottomTabControl.Visible;
settings.WindowLocation = this.Location;
sliver.SnippetCompiler.Util.DeleteTempCompileFolder();
ToolStripManager.SaveSettings((Form)this);
if (e.CloseReason == CloseReason.UserClosing)
this.SaveSettings();
}
else
e.Cancel = true;
base.OnFormClosing(e);
}
private void SaveSettings()
{
ServiceManager.Settings.Save();
sliver.SnippetCompiler.Properties.Settings.Default.Save();
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
if (this.WindowState == FormWindowState.Minimized && ServiceManager.Settings.MinimizeToTray)
this.Visible = false;
else
this.ResizeErrorTextColumnInListView();
}
private void ResizeErrorTextColumnInListView()
{
this.lvErrors.Columns[0].Width = this.lvErrors.Width - this.lvErrors.Columns[1].Width - this.lvErrors.Columns[2].Width - this.lvErrors.Columns[3].Width - 5;
}
private void notifyIcon_DoubleClick(object sender, EventArgs e)
{
this.ShowForm();
}
private void SetLineColPanels()
{
DocumentSelection selection = ServiceManager.Editor.Selection;
this.lineStatusStripLabel.Text = "Ln " + (selection.StartPosition.Line + 1);
this.colStatusStripLabel.Text = "Col " + (selection.StartPosition.Character + 1);
}
private void ContextMenuHandler(object sender, EventArgs e)
{
IEditor editor = (IEditor)((CodeTabPageContextMenu)((ToolStripItem)sender).Owner).TabPage;
if (editor == null)
return;
switch (((ToolStripItem)sender).Text)
{
case "保存":
editor.Save();
break;
case "另存为":
editor.SaveAs();
break;
case "关闭":
editor.Close();
break;
}
}
private void tabControl_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Right)
return;
this.tabControlContextMenu.TabPage = this.tabControl.GetTabPageAtPoint(e.X, e.Y);
this.tabControlContextMenu.Show((Control)this.tabControl, new Point(e.X, e.Y));
}
void IApplication.KillSnippetProcess()
{
if (this._runningProcess != null && !this._runningProcess.HasExited)
{
this._runningProcess.Kill();
this._runningProcess.Close();
}
ServiceManager.CommandManager[typeof(KillProcessCommand)].Enabled = false;
}
private void RunningProcess_Exited(object sender, EventArgs e)
{
ServiceManager.CommandManager[typeof(KillProcessCommand)].Enabled = false;
}
private void ShowForm()
{
if (this.WindowState == FormWindowState.Minimized)
{
this.Visible = true;
this.WindowState = FormWindowState.Normal;
}
else
this.Activate();
}
private void HandleChangedSetting(string settingName)
{
switch ((SettingName)Enum.Parse(typeof(SettingName), settingName))
{
case SettingName.ErrorFontName:
case SettingName.ErrorFontSize:
case SettingName.OutputFontName:
case SettingName.OutputFontSize:
this.SetFontInfo();
break;
}
}
private void UserSettings_ValueChanged(object sender, SettingValueChangedEventArgs e)
{
switch ((SettingName)Enum.Parse(typeof(SettingName), e.SettingName))
{
case SettingName.MinimizeToTray:
this.notifyIcon.Visible = ServiceManager.Settings.MinimizeToTray;
break;
case SettingName.MultiRowTabs:
this.tabControl.Multiline = ServiceManager.Settings.MultiRowTabs;
break;
}
}
private void EditorContainer_SelectedEditorChanged(object sender, EventArgs e)
{
this.DisconnectEditor(this._lastEditor);
this.ConnectEditor(ServiceManager.Editor);
this._lastEditor = ServiceManager.Editor;
if (this.tabControl.SelectedTab != null)
this.tabControl.SelectedTab.Focus();
this.SetDocumentMenus();
}
private void EditorContainer_EditorClosing(object sender, EditorEventArgs e)
{
this.lvErrors.Focus();
}
private void EditorContainer_EditorClosed(object sender, EditorEventArgs e)
{
if (ServiceManager.EditorContainer.Count != 0)
return;
this.SetDocumentMenus();
}
private void Editor_SelectionChanged(object sender, EventArgs e)
{
this.SetDocumentStateMenus();
this.SetLineColPanels();
}
void IApplication.ShowOptions()
{
DialogResult dr = new OptionsForm().ShowDialog();
}
void IApplication.ShowOptions(string pageName)
{
new OptionsForm().ShowDialog(pageName);
}
private void EditorContainer_FileLoaded(object sender, EditorEventArgs e)
{
this.ConnectEditor(e.Editor);
this.SetDocumentMenus();
}
private void ContexMenuHandler(object sender, EventArgs e)
{
switch (((MenuItem)sender).Text)
{
case "Copy":
this.txtOutput.Copy();
break;
case "全部选择":
this.txtOutput.SelectAll();
break;
}
}
private void outputContextMenu_Popup(object sender, EventArgs e)
{
}
private void ToolBars_ToolBarAdded(object sender, ToolBarEventArgs e)
{
((IApplication)this).MainMenu.MenuItems["视图"].MenuItems["工具栏"].AddMenuItem((ICommand)new ToolBarMenuCommand(e.ToolBar));
}
private void copyToolStripMenuItem_Click(object sender, EventArgs e)
{
if (this.lvErrors.SelectedItems.Count <= 0)
return;
Clipboard.SetDataObject(this.lvErrors.SelectedItems[0].Text);
}
protected override void Dispose(bool disposing)
{
if (disposing && this.components != null)
this.components.Dispose();
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.components = (IContainer)new Container();
ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(MainForm));
this.toolStripContainer = new ScToolStripContainer();
this.statusBar1 = new StatusStrip();
this.toolStripStatusLabel = new ToolStripStatusLabel();
this.lineStatusStripLabel = new ToolStripStatusLabel();
this.colStatusStripLabel = new ToolStripStatusLabel();
this.splitContainer = new SplitContainer();
this.tabControl = new CodeTabControl();
this.tabControlContextMenu = new CodeTabPageContextMenu();
this.saveToolStripMenuItem = new ToolStripMenuItem();
this.saveAsToolStripMenuItem = new ToolStripMenuItem();
this.closeToolStripMenuItem = new ToolStripMenuItem();
this.bottomTabControl = new TabControl();
this.tabPage1 = new TabPage();
this.lvErrors = new ListView();
this.columnHeader1 = new ColumnHeader();
this.columnHeader2 = new ColumnHeader();
this.columnHeader3 = new ColumnHeader();
this.columnHeader4 = new ColumnHeader();
this.errorsImageList = new ImageList(this.components);
this.tabPage2 = new TabPage();
this.txtOutput = new TextBox();
this.errorsContextMenu = new ContextMenuStrip(this.components);
this.copyToolStripMenuItem = new ToolStripMenuItem();
this.editorContextMenu = new ScContextMenuStrip();
this.mainMenuStrip = new ScMenuStrip();
this.notifyIcon = new NotifyIcon(this.components);
this.notifyIconContextMenu = new ContextMenuStrip(this.components);
this.openNotifyIconMenuItem = new ToolStripMenuItem();
this.exitNotifyIconMenuItem = new ToolStripMenuItem();
this.panel1 = new Panel();
this.menuItem1 = new MenuItem();
this.menuItem2 = new MenuItem();
this.menuItem3 = new MenuItem();
this.toolStripContainer.BottomToolStripPanel.SuspendLayout();
this.toolStripContainer.ContentPanel.SuspendLayout();
this.toolStripContainer.SuspendLayout();
this.statusBar1.SuspendLayout();
this.splitContainer.Panel1.SuspendLayout();
this.splitContainer.Panel2.SuspendLayout();
this.splitContainer.SuspendLayout();
this.tabControlContextMenu.SuspendLayout();
this.bottomTabControl.SuspendLayout();
this.tabPage1.SuspendLayout();
this.tabPage2.SuspendLayout();
this.errorsContextMenu.SuspendLayout();
this.notifyIconContextMenu.SuspendLayout();
this.panel1.SuspendLayout();
this.SuspendLayout();
this.toolStripContainer.BottomToolStripPanel.Controls.Add((Control)this.statusBar1);
this.toolStripContainer.ContentPanel.AutoScroll = true;
this.toolStripContainer.ContentPanel.Controls.Add((Control)this.splitContainer);
this.toolStripContainer.ContentPanel.Size = new Size(563, 532);
this.toolStripContainer.Dock = DockStyle.Fill;
this.toolStripContainer.LeftToolStripPanelVisible = false;
this.toolStripContainer.Location = new Point(0, 0);
this.toolStripContainer.Name = "toolStripContainer";
this.toolStripContainer.RightToolStripPanelVisible = false;
this.toolStripContainer.Size = new Size(563, 580);
this.toolStripContainer.TabIndex = 0;
this.toolStripContainer.Text = "toolStripContainer1";
this.statusBar1.Dock = DockStyle.None;
this.statusBar1.Items.AddRange(new ToolStripItem[3]
{
(ToolStripItem) this.toolStripStatusLabel,
(ToolStripItem) this.lineStatusStripLabel,
(ToolStripItem) this.colStatusStripLabel
});
this.statusBar1.Location = new Point(0, 0);
this.statusBar1.Name = "statusBar1";
this.statusBar1.Size = new Size(563, 23);
this.statusBar1.TabIndex = 0;
this.statusBar1.Text = "statusStrip1";
this.toolStripStatusLabel.Name = "toolStripStatusLabel";
this.toolStripStatusLabel.Size = new Size(448, 18);
this.toolStripStatusLabel.Spring = true;
this.toolStripStatusLabel.TextAlign = ContentAlignment.MiddleLeft;
this.lineStatusStripLabel.AutoSize = false;
this.lineStatusStripLabel.Name = "lineStatusStripLabel";
this.lineStatusStripLabel.Size = new Size(50, 18);
this.colStatusStripLabel.AutoSize = false;
this.colStatusStripLabel.Name = "colStatusStripLabel";
this.colStatusStripLabel.Size = new Size(50, 18);
this.splitContainer.Dock = DockStyle.Fill;
this.splitContainer.FixedPanel = FixedPanel.Panel2;
this.splitContainer.Location = new Point(0, 0);
this.splitContainer.Name = "splitContainer";
this.splitContainer.Orientation = Orientation.Horizontal;
this.splitContainer.Panel1.Controls.Add((Control)this.tabControl);
this.splitContainer.Panel2.Controls.Add((Control)this.bottomTabControl);
this.splitContainer.Size = new Size(563, 532);
this.splitContainer.SplitterDistance = 355;
this.splitContainer.SplitterWidth = 5;
this.splitContainer.TabIndex = 0;
this.splitContainer.Text = "splitContainer1";
this.tabControl.AllowDrop = true;
this.tabControl.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
this.tabControl.ContextMenuStrip = (ContextMenuStrip)this.tabControlContextMenu;
this.tabControl.Location = new Point(8, 8);
this.tabControl.Name = "tabControl";
this.tabControl.SelectedIndex = 0;
this.tabControl.Size = new Size(548, 344);
this.tabControl.TabIndex = 0;
this.tabControl.MouseDown += new MouseEventHandler(this.tabControl_MouseDown);
this.tabControlContextMenu.Items.AddRange(new ToolStripItem[3]
{
(ToolStripItem) this.saveToolStripMenuItem,
(ToolStripItem) this.saveAsToolStripMenuItem,
(ToolStripItem) this.closeToolStripMenuItem
});
this.tabControlContextMenu.Name = "tabControlContextMenu";
this.tabControlContextMenu.Size = new Size(124, 70);
this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
this.saveToolStripMenuItem.Size = new Size(123, 22);
this.saveToolStripMenuItem.Text = "保存";
this.saveToolStripMenuItem.Click += new EventHandler(this.ContextMenuHandler);
this.saveAsToolStripMenuItem.Name = "saveAsToolStripMenuItem";
this.saveAsToolStripMenuItem.Size = new Size(123, 22);
this.saveAsToolStripMenuItem.Text = "另存为";
this.saveAsToolStripMenuItem.Click += new EventHandler(this.ContextMenuHandler);
this.closeToolStripMenuItem.Name = "closeToolStripMenuItem";
this.closeToolStripMenuItem.Size = new Size(123, 22);
this.closeToolStripMenuItem.Text = "关闭";
this.closeToolStripMenuItem.Click += new EventHandler(this.ContextMenuHandler);
this.bottomTabControl.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
this.bottomTabControl.Controls.Add((Control)this.tabPage1);
this.bottomTabControl.Controls.Add((Control)this.tabPage2);
this.bottomTabControl.Location = new Point(8, 4);
this.bottomTabControl.Name = "bottomTabControl";
this.bottomTabControl.SelectedIndex = 0;
this.bottomTabControl.Size = new Size(548, 159);
this.bottomTabControl.TabIndex = 0;
this.tabPage1.Controls.Add((Control)this.lvErrors);
this.tabPage1.Location = new Point(4, 22);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Padding = new Padding(3);
this.tabPage1.Size = new Size(540, 133);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "错误列表";
this.tabPage1.UseVisualStyleBackColor = true;
this.lvErrors.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
this.lvErrors.Columns.AddRange(new ColumnHeader[4]
{
this.columnHeader1,
this.columnHeader2,
this.columnHeader3,
this.columnHeader4
});
this.lvErrors.FullRowSelect = true;
this.lvErrors.HideSelection = false;
this.lvErrors.Location = new Point(6, 7);
this.lvErrors.Name = "lvErrors";
this.lvErrors.Size = new Size(526, 118);
this.lvErrors.SmallImageList = this.errorsImageList;
this.lvErrors.TabIndex = 1;
this.lvErrors.UseCompatibleStateImageBehavior = false;
this.lvErrors.View = View.Details;
this.lvErrors.MouseUp += new MouseEventHandler(this.lvErrors_MouseUp);
this.columnHeader1.Text = "描述";
this.columnHeader1.Width = 290;
this.columnHeader2.Text = "代码行号";
this.columnHeader2.Width = 60;
this.columnHeader3.Text = "所在列";
this.columnHeader3.Width = 60;
this.columnHeader4.Text = "代码片段";
this.columnHeader4.Width = 75;
this.errorsImageList.ImageStream = (ImageListStreamer)componentResourceManager.GetObject("errorsImageList.ImageStream");
this.errorsImageList.TransparentColor = Color.Transparent;
this.errorsImageList.Images.SetKeyName(0, "Error.bmp");
this.errorsImageList.Images.SetKeyName(1, "Information16x16.bmp");
this.tabPage2.Controls.Add((Control)this.txtOutput);
this.tabPage2.Location = new Point(4, 22);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Padding = new Padding(3);
this.tabPage2.Size = new Size(540, 133);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "输出";
this.tabPage2.UseVisualStyleBackColor = true;
this.txtOutput.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
this.txtOutput.Location = new Point(6, 8);
this.txtOutput.Multiline = true;
this.txtOutput.Name = "txtOutput";
this.txtOutput.ReadOnly = true;
this.txtOutput.ScrollBars = ScrollBars.Both;
this.txtOutput.Size = new Size(526, 113);
this.txtOutput.TabIndex = 1;
this.txtOutput.WordWrap = false;
this.errorsContextMenu.Items.AddRange(new ToolStripItem[1]
{
(ToolStripItem) this.copyToolStripMenuItem
});
this.errorsContextMenu.Name = "errorsContextMenu";
this.errorsContextMenu.Size = new Size(103, 26);
this.copyToolStripMenuItem.Name = "copyToolStripMenuItem";
this.copyToolStripMenuItem.Size = new Size(102, 22);
this.copyToolStripMenuItem.Text = "Copy";
this.copyToolStripMenuItem.Click += new EventHandler(this.copyToolStripMenuItem_Click);
this.editorContextMenu.Name = "xxx";
this.editorContextMenu.Size = new Size(61, 4);
this.mainMenuStrip.Location = new Point(0, 0);
this.mainMenuStrip.Name = "mainMenuStrip";
this.mainMenuStrip.Size = new Size(563, 24);
this.mainMenuStrip.TabIndex = 0;
this.mainMenuStrip.Text = "menuStrip1";
this.notifyIcon.ContextMenuStrip = this.notifyIconContextMenu;
this.notifyIcon.Visible = true;
this.notifyIcon.DoubleClick += new EventHandler(this.notifyIcon_DoubleClick);
this.notifyIconContextMenu.Items.AddRange(new ToolStripItem[2]
{
(ToolStripItem) this.openNotifyIconMenuItem,
(ToolStripItem) this.exitNotifyIconMenuItem
});
this.notifyIconContextMenu.Name = "notifyIconContextMenu";
this.notifyIconContextMenu.Size = new Size(104, 48);
this.openNotifyIconMenuItem.Name = "openNotifyIconMenuItem";
this.openNotifyIconMenuItem.Size = new Size(103, 22);
this.openNotifyIconMenuItem.Text = "打开";
this.exitNotifyIconMenuItem.Name = "exitNotifyIconMenuItem";
this.exitNotifyIconMenuItem.Size = new Size(103, 22);
this.exitNotifyIconMenuItem.Text = "退出";
this.panel1.Controls.Add((Control)this.toolStripContainer);
this.panel1.Dock = DockStyle.Fill;
this.panel1.Location = new Point(0, 24);
this.panel1.Name = "panel1";
this.panel1.Size = new Size(563, 580);
this.panel1.TabIndex = 2;
this.menuItem1.Index = -1;
this.menuItem1.Text = "";
this.menuItem2.Index = -1;
this.menuItem2.Text = "";
this.menuItem3.Index = -1;
this.menuItem3.Text = "";
this.AutoScaleDimensions = new SizeF(6f, 13f);
this.AutoScaleMode = AutoScaleMode.Font;
this.ClientSize = new Size(563, 604);
this.Controls.Add((Control)this.panel1);
this.Controls.Add((Control)this.mainMenuStrip);
this.Icon = (Icon)componentResourceManager.GetObject("$this.Icon");
this.MainMenuStrip = (MenuStrip)this.mainMenuStrip;
this.Name = "MainForm";
this.Text = "Snippet Compiler";
this.toolStripContainer.BottomToolStripPanel.ResumeLayout(false);
this.toolStripContainer.BottomToolStripPanel.PerformLayout();
this.toolStripContainer.ContentPanel.ResumeLayout(false);
this.toolStripContainer.ResumeLayout(false);
this.toolStripContainer.PerformLayout();
this.statusBar1.ResumeLayout(false);
this.statusBar1.PerformLayout();
this.splitContainer.Panel1.ResumeLayout(false);
this.splitContainer.Panel2.ResumeLayout(false);
this.splitContainer.ResumeLayout(false);
this.tabControlContextMenu.ResumeLayout(false);
this.bottomTabControl.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.tabPage2.ResumeLayout(false);
this.tabPage2.PerformLayout();
this.errorsContextMenu.ResumeLayout(false);
this.notifyIconContextMenu.ResumeLayout(false);
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
}
}
}
[代码运行效果截图]
[源代码打包下载]
by: 发表于:2017-12-18 09:38:05 顶(0) | 踩(0) 回复
??
回复评论