newfiledialog.cs
来自「全功能c#编译器」· CS 代码 · 共 495 行 · 第 1/2 页
CS
495 行
}
propertyGrid.ToolbarVisible = false;
propertyGrid.SelectedObject = localizedTypeDescriptor;
propertyGrid.Size = new Size(GridWidth, Height - GridMargin * 4);
Width = Width + GridWidth;
Controls.Add(propertyGrid);
this.ResumeLayout(false);
}
}
void HidePropertyGrid()
{
if (Controls.Contains(propertyGrid)) {
this.SuspendLayout();
Controls.Remove(propertyGrid);
Width = Width - GridWidth;
this.ResumeLayout(false);
}
}
FileTemplate SelectedTemplate {
get {
if (((ListView)ControlDictionary["templateListView"]).SelectedItems.Count == 1) {
return ((TemplateItem)((ListView)ControlDictionary["templateListView"]).SelectedItems[0]).Template;
}
return null;
}
}
string GenerateCurrentFileName()
{
if (SelectedTemplate.DefaultName.IndexOf("${Number}") >= 0) {
try {
int curNumber = 1;
IFileService fileService = (IFileService)ICSharpCode.Core.Services.ServiceManager.Services.GetService(typeof(IFileService));
while (true) {
StringParserService.Properties["Number"] = curNumber.ToString();
string fileName = StringParserService.Parse(SelectedTemplate.DefaultName);
if (allowUntitledFiles) {
if (!fileService.IsOpen(fileName)) {
break;
}
} else if (!File.Exists(Path.Combine(basePath, fileName))) {
break;
}
++curNumber;
}
} catch (Exception e) {
Console.WriteLine(e);
}
}
return StringParserService.Parse(SelectedTemplate.DefaultName);
}
// list view event handlers
void SelectedIndexChange(object sender, EventArgs e)
{
if (((ListView)ControlDictionary["templateListView"]).SelectedItems.Count == 1) {
ControlDictionary["descriptionLabel"].Text = StringParserService.Parse(SelectedTemplate.Description);
ControlDictionary["openButton"].Enabled = true;
if (SelectedTemplate.HasProperties) {
ShowPropertyGrid();
}
if (!this.allowUntitledFiles) {
ControlDictionary["fileNameTextBox"].Text = GenerateCurrentFileName();
}
} else {
ControlDictionary["descriptionLabel"].Text = String.Empty;
ControlDictionary["openButton"].Enabled = false;
HidePropertyGrid();
}
}
// button events
void CheckedChange(object sender, EventArgs e)
{
((ListView)ControlDictionary["templateListView"]).View = ((RadioButton)ControlDictionary["smallIconsRadioButton"]).Checked ? View.List : View.LargeIcon;
}
public bool IsFilenameAvailable(string fileName)
{
return true;
}
public void SaveFile(string filename, string content, string languageName, bool showFile)
{
IFileService fileService = (IFileService)ICSharpCode.Core.Services.ServiceManager.Services.GetService(typeof(IFileService));
string parsedFileName = StringParserService.Parse(filename);
createdFiles.Add(parsedFileName);
fileService.NewFile(parsedFileName, StringParserService.Parse(languageName), StringParserService.Parse(content));
DialogResult = DialogResult.OK;
}
void OpenEvent(object sender, EventArgs e)
{
if (((TreeView)ControlDictionary["categoryTreeView"]).SelectedNode != null) {
PropertyService propertyService = (PropertyService)ServiceManager.Services.GetService(typeof(PropertyService));
propertyService.SetProperty("Dialogs.NewProjectDialog.LargeImages", ((RadioButton)ControlDictionary["largeIconsRadioButton"]).Checked);
propertyService.SetProperty("Dialogs.NewFileDialog.LastSelectedCategory", ((TreeView)ControlDictionary["categoryTreeView"]).SelectedNode.Text);
}
createdFiles.Clear();
if (((ListView)ControlDictionary["templateListView"]).SelectedItems.Count == 1) {
if (!AllPropertiesHaveAValue) {
IMessageService messageService =(IMessageService)ServiceManager.Services.GetService(typeof(IMessageService));
messageService.ShowMessage("${res:Dialog.NewFile.FillOutFirstMessage}", "${res:Dialog.NewFile.FillOutFirstCaption}");
return;
}
TemplateItem item = (TemplateItem)((ListView)ControlDictionary["templateListView"]).SelectedItems[0];
string fileName;
StringParserService.Properties["StandardNamespace"] = "DefaultNamespace";
if (allowUntitledFiles) {
fileName = GenerateCurrentFileName();
} else {
IProjectService projectService = (IProjectService)ICSharpCode.Core.Services.ServiceManager.Services.GetService(typeof(IProjectService));
if (projectService.CurrentSelectedProject != null) {
StringParserService.Properties["StandardNamespace"] = projectService.CurrentSelectedProject.StandardNamespace;
}
fileName = ControlDictionary["fileNameTextBox"].Text;
}
StringParserService.Properties["FullName"] = fileName;
StringParserService.Properties["FileName"] = Path.GetFileName(fileName);
StringParserService.Properties["FileNameWithoutExtension"] = Path.GetFileNameWithoutExtension(fileName);
StringParserService.Properties["Extension"] = Path.GetExtension(fileName);
StringParserService.Properties["Path"] = Path.GetDirectoryName(fileName);
if (item.Template.WizardPath != null) {
IProperties customizer = new DefaultProperties();
customizer.SetProperty("Template", item.Template);
customizer.SetProperty("Creator", this);
WizardDialog wizard = new WizardDialog("File Wizard", customizer, item.Template.WizardPath);
if (wizard.ShowDialog() == DialogResult.OK) {
DialogResult = DialogResult.OK;
}
} else {
ScriptRunner scriptRunner = new ScriptRunner();
foreach (FileDescriptionTemplate newfile in item.Template.FileDescriptionTemplates) {
SaveFile(newfile.Name, scriptRunner.CompileScript(item.Template, newfile), newfile.Language, true);
}
DialogResult = DialogResult.OK;
}
}
}
/// <summary>
/// Represents a category
/// </summary>
internal class Category : TreeNode
{
ArrayList categories = new ArrayList();
ArrayList templates = new ArrayList();
string name;
public bool Selected = false;
public bool HasSelectedTemplate = false;
static StringParserService stringParserService = (StringParserService)ServiceManager.Services.GetService(typeof(StringParserService));
public Category(string name) : base(stringParserService.Parse(name))
{
this.name = name;
ImageIndex = 1;
}
public string Name {
get {
return name;
}
}
public ArrayList Categories {
get {
return categories;
}
}
public ArrayList Templates {
get {
return templates;
}
}
}
/// <summary>
/// Represents a new file template
/// </summary>
class TemplateItem : ListViewItem
{
FileTemplate template;
public TemplateItem(FileTemplate template) : base(((StringParserService)ServiceManager.Services.GetService(typeof(StringParserService))).Parse(template.Name))
{
this.template = template;
ImageIndex = 0;
}
public FileTemplate Template {
get {
return template;
}
}
}
void InitializeComponents()
{
if (allowUntitledFiles) {
base.SetupFromXml(Path.Combine(PropertyService.DataDirectory, @"resources\dialogs\NewFileDialog.xfrm"));
} else {
base.SetupFromXml(Path.Combine(PropertyService.DataDirectory, @"resources\dialogs\NewFileWithNameDialog.xfrm"));
}
ImageList imglist = new ImageList();
imglist.ColorDepth = ColorDepth.Depth32Bit;
imglist.Images.Add(IconService.GetBitmap("Icons.16x16.OpenFolderBitmap"));
imglist.Images.Add(IconService.GetBitmap("Icons.16x16.ClosedFolderBitmap"));
((TreeView)ControlDictionary["categoryTreeView"]).ImageList = imglist;
((TreeView)ControlDictionary["categoryTreeView"]).AfterSelect += new TreeViewEventHandler(CategoryChange);
((TreeView)ControlDictionary["categoryTreeView"]).BeforeSelect += new TreeViewCancelEventHandler(OnBeforeExpand);
((TreeView)ControlDictionary["categoryTreeView"]).BeforeExpand += new TreeViewCancelEventHandler(OnBeforeExpand);
((TreeView)ControlDictionary["categoryTreeView"]).BeforeCollapse += new TreeViewCancelEventHandler(OnBeforeCollapse);
((ListView)ControlDictionary["templateListView"]).SelectedIndexChanged += new EventHandler(SelectedIndexChange);
((ListView)ControlDictionary["templateListView"]).DoubleClick += new EventHandler(OpenEvent);
ControlDictionary["openButton"].Click += new EventHandler(OpenEvent);
PropertyService propertyService = (PropertyService)ServiceManager.Services.GetService(typeof(PropertyService));
((RadioButton)ControlDictionary["largeIconsRadioButton"]).Checked = propertyService.GetProperty("Dialogs.NewProjectDialog.LargeImages", true);
((RadioButton)ControlDictionary["largeIconsRadioButton"]).CheckedChanged += new EventHandler(CheckedChange);
((RadioButton)ControlDictionary["largeIconsRadioButton"]).FlatStyle = FlatStyle.Standard;
((RadioButton)ControlDictionary["largeIconsRadioButton"]).Image = IconService.GetBitmap("Icons.16x16.LargeIconsIcon");
((RadioButton)ControlDictionary["smallIconsRadioButton"]).Checked = !propertyService.GetProperty("Dialogs.NewProjectDialog.LargeImages", true);
((RadioButton)ControlDictionary["smallIconsRadioButton"]).CheckedChanged += new EventHandler(CheckedChange);
((RadioButton)ControlDictionary["smallIconsRadioButton"]).FlatStyle = FlatStyle.Standard;
((RadioButton)ControlDictionary["smallIconsRadioButton"]).Image = IconService.GetBitmap("Icons.16x16.SmallIconsIcon");
ToolTip tooltip = new ToolTip();
tooltip.SetToolTip(ControlDictionary["largeIconsRadioButton"], StringParserService.Parse("${res:Global.LargeIconToolTip}"));
tooltip.SetToolTip(ControlDictionary["smallIconsRadioButton"], StringParserService.Parse("${res:Global.SmallIconToolTip}"));
tooltip.Active = true;
Owner = (Form)WorkbenchSingleton.Workbench;
StartPosition = FormStartPosition.CenterParent;
Icon = null;
CheckedChange(this, EventArgs.Empty);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?