public FormsDesignerContent(FormsDesignerExtension parent, OpenedFile sourceFile) : base(parent) { _language = (NetLanguageDescriptor)LanguageDescriptor.GetLanguageByPath(sourceFile.FilePath); if (!(_language is NetLanguageDescriptor)) throw new ArgumentException("File must be a .NET source file."); _extensionHost = parent.ExtensionHost; _extensionHost.ControlManager.AppearanceChanged += ControlManager_AppearanceChanged; _propertyContainer = new PropertyContainer(); _serviceContainer = new ServiceContainer(); _surfaceManager = parent.DesignerSurfaceManager; _codeReader = new DesignerCodeReader(_extensionHost, _language); _codeWriter = new DesignerCodeWriter(_language); this.Text = sourceFile.FilePath.FileName + sourceFile.FilePath.Extension + " [Design]"; this.AssociatedFile = sourceFile; this.AssociatedFile.FilePathChanged += AssociatedFile_FilePathChanged; _errorControl = new ErrorControl() { Dock = DockStyle.Fill, }; _errorControl.ReloadRequested += _errorControl_ReloadRequested; SetupDesigner(); }
/// <summary> /// Parses a source code and creates a new design surface. /// </summary> /// <param name="serviceContainer"></param> /// <param name="surfaceManager"></param> /// <param name="file">The source file to deserialize.</param> /// <returns></returns> public DesignSurface Deserialize(DesignSurfaceManager surfaceManager, IServiceContainer serviceContainer, OpenedFile file) { DesignSurface surface = surfaceManager.CreateDesignSurface(serviceContainer); IDesignerHost designerHost = surface.GetService(typeof(IDesignerHost)) as IDesignerHost; Type componentType = CompileTypeFromFile(file); // load base type. surface.BeginLoad(componentType.BaseType); // get instance to copy components and properties from. Control instance = Activator.CreateInstance(componentType) as Control; // add components var components = CreateComponents(componentType, instance, designerHost); InitializeComponents(components, designerHost); Control rootControl = designerHost.RootComponent as Control; Control parent = rootControl.Parent; ISite site = rootControl.Site; // copy instance properties to root control. CopyProperties(instance, designerHost.RootComponent); rootControl.AllowDrop = true; rootControl.Parent = parent; rootControl.Visible = true; rootControl.Site = site; designerHost.RootComponent.Site.Name = instance.Name; return surface; }
public ViewContentContainer(LiteViewContent viewContent) { base.HideOnClose = viewContent is LiteToolWindow; _extensionHost = LiteDevelopApplication.Current.ExtensionHost; ViewContent = viewContent; ViewContent.ControlChanged += ViewContent_ControlChanged; ViewContent.TextChanged += ViewContent_TextChanged; ViewContent.IconChanged += ViewContent_IconChanged; ViewContent.Closing += ViewContent_Closing; ViewContent.Closed += ViewContent_Closed; if (DocumentContent != null) { _currentFile = DocumentContent.AssociatedFile; DocumentContent.AssociatedFileChanged += DocumentContent_AssociatedFileChanged; DocumentContent_AssociatedFileChanged(null, null); } else if (ToolWindow != null) { ToolWindow.DockStateChanged += ToolWindow_DockStateChanged; } UpdateText(); UpdateControl(); UpdateIcon(); }
public ResourceEditorControl(OpenedFile file) { InitializeComponent(); _componentMuiIdentifiers = new Dictionary<object, string>() { {columnHeader1, "ResourceEditorControl.ColumnHeaders.Name"}, {columnHeader2, "ResourceEditorControl.ColumnHeaders.Type"}, {columnHeader3, "ResourceEditorControl.ColumnHeaders.Contents"}, {addStringToolStripButton, "ResourceEditorControl.ToolBar.AddString"}, {addFileToolStripButton, "ResourceEditorControl.ToolBar.AddFile"}, {removeToolStripButton, "ResourceEditorControl.ToolBar.RemoveSelected"}, {renameToolStripMenuItem, "ResourceEditorControl.ContextMenu.Rename"}, {removeToolStripMenuItem, "ResourceEditorControl.ContextMenu.Remove"}, {label1, "ResourceEditorControl.Messages.EditorNotInstalled"}, }; _extension = ResourceEditorExtension.Instance; _extension.ExtensionHost.UILanguageChanged += ExtensionHost_UILanguageChanged; ExtensionHost_UILanguageChanged(null, null); _file = file; splitContainer1.Panel2.Controls.Remove(label1); ReadResourceFile(); }
public ResourceEditorContent(LiteExtension parent, OpenedFile file) : base(parent) { AssociatedFile = file; this.Text = file.FilePath.FileName + file.FilePath.Extension; Control = _editorControl = new ResourceEditorControl(file) { Dock = System.Windows.Forms.DockStyle.Fill, }; }
public CodeEditorContent(CodeEditorExtension extension, OpenedFile sourceFile) : base(extension) { this.AssociatedFile = sourceFile; this.AssociatedFile.FilePathChanged += AssociatedFile_FilePathChanged; _extensionHost = extension.ExtensionHost; this.Text = sourceFile.FilePath.FileName + sourceFile.FilePath.Extension; this.Control = _editorControl = new CodeEditorControl(this, sourceFile) { Dock = DockStyle.Fill, }; }
public FileMovedEventArgs(OpenedFile file, string oldPath, string newPath) : base(file) { OldPath = oldPath; NewPath = newPath; }
public FileEventArgs(OpenedFile file) { TargetFile = file; }
private void DocumentContent_AssociatedFileChanged(object sender, EventArgs e) { if (_currentFile != null) _currentFile.HasUnsavedDataChanged -= AssociatedFile_HasUnsavedDataChanged; if ((_currentFile = DocumentContent.AssociatedFile) != null) _currentFile.HasUnsavedDataChanged += AssociatedFile_HasUnsavedDataChanged; }
private Type CompileTypeFromFile(OpenedFile file) { string sourceCode = file.GetContentsAsString(); var projectFile = _extensionHost.CurrentSolution.FindProjectFile(file.FilePath); if (projectFile == null) throw new FileNotFoundException("Cannot find project file " + file.FilePath.FullPath); CompilerParameters parameters = new CompilerParameters() { GenerateInMemory = true, GenerateExecutable = false, }; // standard references. parameters.ReferencedAssemblies.AddRange(new string[] {"mscorlib.dll", "System.dll", "System.Drawing.dll", "System.Windows.Forms.dll"}); CodeDomProvider provider = Language.CodeProvider; // validate source var sourceSnapshot = Language.CreateSourceSnapshot(sourceCode) as NetSourceSnapshot; if (sourceSnapshot.Types.Length != 1) { throw new ArgumentException("Source must contain exactly one type."); } string @namespace; if (sourceSnapshot.Namespaces.Length == 0) { // TODO: add temp namespace .... throw new NotImplementedException("Cannot handle classes without a namespace yet."); } else { @namespace = sourceSnapshot.Namespaces[0].Name; } // create stub class var writer = new StringWriter(); var stubClass = new CodeTypeDeclaration(sourceSnapshot.Types[0].Name) { IsPartial = true }; stubClass.Members.Add(GenerateConstructor()); // check if snapshot class doesn't have a base type. if (string.IsNullOrEmpty(sourceSnapshot.Types[0].ValueType)) { // try to find in dependencies foreach (var dependency in file.Dependencies) if (Path.GetExtension(dependency) == file.FilePath.Extension) { var dependentFile = _extensionHost.FileService.OpenFile(projectFile.FilePath.ParentDirectory.Combine(dependency)); var dependencySnapshot = Language.CreateSourceSnapshot(dependentFile.GetContentsAsString()) as NetSourceSnapshot; if (dependencySnapshot.Types[0].Name == sourceSnapshot.Types[0].Name && !string.IsNullOrEmpty(dependencySnapshot.Types[0].ValueType)) { var baseType = dependencySnapshot.GetTypeByName(dependencySnapshot.Types[0].ValueType); if (baseType != null) { stubClass.BaseTypes.Add(baseType); break; } } } } // write stub class var stubNamespace = new CodeNamespace(@namespace); stubNamespace.Types.Add(stubClass); provider.GenerateCodeFromNamespace(stubNamespace, writer, new CodeGeneratorOptions()); // compile. CompilerResults results = provider.CompileAssemblyFromSource(parameters, sourceCode, writer.GetStringBuilder().ToString()); if (results.Errors.Count == 0) { // find target type. foreach (Type type in results.CompiledAssembly.GetTypes()) if (type.IsBasedOn(typeof(Component))) return type; throw new Exception("The type based on " + typeof(Component).FullName + " was not found."); } else { throw new BuildException("The compiler did not succeed in compiling the source.", BuildResult.FromCompilerResults(results)); } }
public void OpenFile(OpenedFile file) { CodeEditorContent documentContent; if (!_codeEditors.TryGetValue(file, out documentContent)) { documentContent = new CodeEditorContent(this, file); documentContent.Closed += content_Closed; _codeEditors.Add(file, documentContent); ExtensionHost.ControlManager.OpenDocumentContents.Add(documentContent); } ExtensionHost.ControlManager.SelectedDocumentContent = documentContent; }
public void OpenFile(OpenedFile file) { FormsDesignerContent tab; if (!_formEditors.TryGetValue(file, out tab)) { tab = new FormsDesignerContent(this, file); tab.Closed += tab_Closed; _formEditors.Add(file, tab); ExtensionHost.ControlManager.OpenDocumentContents.Add(tab); } ExtensionHost.ControlManager.SelectedDocumentContent = tab; }
public ProjectFileEntry(OpenedFile file) : this(file.FilePath) { Dependencies.AddRange(file.Dependencies); }
public CreatedFile(OpenedFile file, IFileHandler handler) { File = file; ExtensionToUse = handler; }