198 lines
8 KiB
C#
198 lines
8 KiB
C#
// Copyright (c) Ivan Bondarev, Stanislav Mihalkovich (for details please see \doc\copyright.txt)
|
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using System.Runtime.InteropServices;
|
|
using ICSharpCode.FormsDesigner;
|
|
using PascalABCCompiler;
|
|
|
|
namespace VisualPascalABC
|
|
{
|
|
public class ProjectTask
|
|
{
|
|
public static void AddReferencesToProject(ProjectExplorerForm ProjectExplorerWindow)
|
|
{
|
|
ReferenceForm.Instance.Clear();
|
|
ReferenceForm.Instance.LoadAssemblies();
|
|
if (ReferenceForm.Instance.ShowDialog() == DialogResult.OK)
|
|
{
|
|
if (ReferenceForm.Instance.AssemblyType == AssemblyType.GAC)
|
|
{
|
|
string[] assemblies = ReferenceForm.Instance.GetSelectedGACAssemblies();
|
|
foreach (string s in assemblies)
|
|
{
|
|
PascalABCCompiler.IReferenceInfo ri = ProjectFactory.Instance.AddReference(s);
|
|
ProjectExplorerWindow.AddReferenceNode(ri);
|
|
try
|
|
{
|
|
ToolboxProvider.AddComponentsFromAssembly(PascalABCCompiler.NetHelper.NetHelper.LoadAssembly(Compiler.get_assembly_path(ri.FullAssemblyName, false)));
|
|
}
|
|
catch
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
else if (ReferenceForm.Instance.AssemblyType == AssemblyType.COM)
|
|
{
|
|
string[] assemblies = ReferenceForm.Instance.GetSelectedCOMObjects();
|
|
foreach (string s in assemblies)
|
|
{
|
|
PascalABCCompiler.IReferenceInfo ri = ProjectFactory.Instance.AddReference(s);
|
|
ProjectExplorerWindow.AddReferenceNode(ri);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
string[] assemblies = ReferenceForm.Instance.GetSelectedFileAssemblies();
|
|
List<string> assm_lst = new List<string>();
|
|
foreach (string s in assemblies)
|
|
{
|
|
if (string.Compare(s, Path.Combine(ProjectFactory.Instance.ProjectDirectory, Path.GetFileName(s)), true) != 0)
|
|
File.Copy(s, Path.Combine(ProjectFactory.Instance.ProjectDirectory, Path.GetFileName(s)), true);
|
|
//assm_lst.Add(Path.GetFileNameWithoutExtension(s));
|
|
//ProjectExplorerWindow.AddReferenceNode(Path.GetFileNameWithoutExtension(s));
|
|
PascalABCCompiler.IReferenceInfo ri = ProjectFactory.Instance.AddReference(Path.GetFileNameWithoutExtension(s));
|
|
ProjectExplorerWindow.AddReferenceNode(ri);
|
|
try
|
|
{
|
|
ToolboxProvider.AddComponentsFromAssembly(PascalABCCompiler.NetHelper.NetHelper.LoadAssembly(Compiler.get_assembly_path(Path.Combine(ProjectFactory.Instance.ProjectDirectory, ri.FullAssemblyName), false)));
|
|
}
|
|
catch
|
|
{
|
|
|
|
}
|
|
}
|
|
//ProjectFactory.Instance.AddReferences(assm_lst.ToArray());
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void NewFile(ProjectExplorerForm ProjectExplorerWindow)
|
|
{
|
|
NewFileForm frm = new NewFileForm();
|
|
Form1StringResources.SetTextForAllControls(frm);
|
|
frm.FileName = ProjectFactory.Instance.GetUnitFileName();
|
|
frm.SetUnitFilter();
|
|
if (frm.ShowDialog() == DialogResult.OK)
|
|
{
|
|
PascalABCCompiler.IFileInfo fi = ProjectFactory.Instance.AddSourceFile(frm.FileName);
|
|
ProjectExplorerWindow.AddSourceFile(fi,false);
|
|
string full_file_name = Path.Combine(Path.GetDirectoryName(ProjectFactory.Instance.CurrentProject.Path),frm.FileName);
|
|
StreamWriter sw = File.CreateText(full_file_name);
|
|
sw.WriteLine("unit "+Path.GetFileNameWithoutExtension(frm.FileName)+";");
|
|
sw.WriteLine();
|
|
sw.WriteLine("interface");
|
|
sw.WriteLine();
|
|
sw.WriteLine("implementation");
|
|
sw.WriteLine();
|
|
sw.WriteLine("end.");
|
|
sw.Close();
|
|
WorkbenchServiceFactory.FileService.OpenFile(full_file_name, null);
|
|
}
|
|
}
|
|
|
|
public static void NewForm(ProjectExplorerForm ProjectExplorerWindow, bool prompt) //roman//
|
|
{
|
|
NewFileForm frm = new NewFileForm();
|
|
frm.SetWinFormsFilter();
|
|
Form1StringResources.SetTextForAllControls(frm);
|
|
frm.FileName = ProjectFactory.Instance.GetUnitFileName();
|
|
if (prompt && frm.ShowDialog() != DialogResult.OK) //roman//
|
|
return;
|
|
PascalABCCompiler.IFileInfo fi = ProjectFactory.Instance.AddSourceFile(frm.FileName);
|
|
string full_file_name = Path.Combine(Path.GetDirectoryName(ProjectFactory.Instance.CurrentProject.Path), frm.FileName);
|
|
StreamWriter sw = File.CreateText(full_file_name);
|
|
sw.Close();
|
|
|
|
WorkbenchServiceFactory.FileService.OpenFile(full_file_name, null);
|
|
VisualPABCSingleton.MainForm.CurrentCodeFileDocument.AddDesigner(null);
|
|
ProjectExplorerWindow.AddSourceFile(fi, true);
|
|
VisualPABCSingleton.MainForm.SaveFileAs(VisualPABCSingleton.MainForm.CurrentCodeFileDocument, full_file_name);
|
|
}
|
|
|
|
public static void ProjectProperties()
|
|
{
|
|
ProjectProperties pf = new ProjectProperties();
|
|
Form1StringResources.SetTextForAllControls(pf);
|
|
pf.LoadOptions(ProjectFactory.Instance.CurrentProject);
|
|
//pf.SetProperties();
|
|
if (pf.ShowDialog() == DialogResult.OK)
|
|
{
|
|
pf.SetOptions(ProjectFactory.Instance.CurrentProject);
|
|
ProjectFactory.Instance.Dirty = true;
|
|
}
|
|
}
|
|
|
|
public static void AddFile(ProjectExplorerForm ProjectExplorerWindow, string file_name)
|
|
{
|
|
PascalABCCompiler.IFileInfo fi = ProjectFactory.Instance.AddSourceFile(file_name);
|
|
ProjectExplorerWindow.AddSourceFile(fi,false);
|
|
}
|
|
|
|
private static OpenFileDialog open_dlg = null;
|
|
|
|
private static void openFileDialog_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
|
|
{
|
|
foreach (string FileName in open_dlg.FileNames)
|
|
{
|
|
if (Path.GetDirectoryName(FileName) != ProjectFactory.Instance.CurrentProject.ProjectDirectory)
|
|
{
|
|
File.Copy(FileName, Path.Combine(ProjectFactory.Instance.CurrentProject.ProjectDirectory, Path.GetFileName(FileName)), true);
|
|
AddFile(VisualPABCSingleton.MainForm.ProjectExplorerWindow, Path.GetFileName(FileName));
|
|
}
|
|
else
|
|
AddFile(VisualPABCSingleton.MainForm.ProjectExplorerWindow, Path.GetFileName(FileName));
|
|
}
|
|
}
|
|
|
|
public static void AddFile(ProjectExplorerForm ProjectExplorerWindow)
|
|
{
|
|
if (open_dlg == null)
|
|
{
|
|
open_dlg = new OpenFileDialog();
|
|
open_dlg.Multiselect = true;
|
|
open_dlg.FileOk += new System.ComponentModel.CancelEventHandler(openFileDialog_FileOk);
|
|
}
|
|
open_dlg.FileName = "";
|
|
open_dlg.InitialDirectory = ProjectFactory.Instance.ProjectDirectory;
|
|
open_dlg.Filter = VisualPABCSingleton.MainForm.VisualEnvironmentCompiler.GetFilterForDialogs();
|
|
open_dlg.ShowDialog();
|
|
}
|
|
|
|
public static void RemoveReference(PascalABCCompiler.IReferenceInfo ri)
|
|
{
|
|
ProjectFactory.Instance.RemoveReference(ri);
|
|
ToolboxProvider.RemoveComponentsFromAssembly(GetReflectionAssembly(ri));
|
|
}
|
|
|
|
private static System.Reflection.Assembly GetReflectionAssembly(IReferenceInfo ri)
|
|
{
|
|
var path = Compiler.get_assembly_path(Path.Combine(ProjectFactory.Instance.ProjectDirectory, ri.FullAssemblyName), false);
|
|
if (path == null)
|
|
path = Compiler.get_assembly_path(ri.FullAssemblyName, false);
|
|
if (path != null)
|
|
return PascalABCCompiler.NetHelper.NetHelper.LoadAssembly(path);
|
|
return null;
|
|
}
|
|
|
|
public static void ExcludeFile(PascalABCCompiler.IFileInfo fi)
|
|
{
|
|
ProjectFactory.Instance.ExcludeFile(fi);
|
|
}
|
|
|
|
private static TypeLibConverter type_conv = new TypeLibConverter();
|
|
|
|
public static string GenerateStubForCOM(string com_obj)
|
|
{
|
|
return TypeLibrary.GetManagedWrapperForCOM(com_obj);
|
|
}
|
|
}
|
|
}
|
|
|