Пример #1
0
        void OpenEvent(object sender, EventArgs e)
        {
            if (categoryTreeView.SelectedNode != null)
            {
                ICSharpCode.Core.PropertyService.Set("Dialogs.NewProjectDialog.LargeImages", ((RadioButton)ControlDictionary["largeIconsRadioButton"]).Checked);
                ICSharpCode.Core.PropertyService.Set("Dialogs.NewFileDialog.CategoryViewState", TreeViewHelper.GetViewStateString(categoryTreeView));
                ICSharpCode.Core.PropertyService.Set("Dialogs.NewFileDialog.LastSelectedCategory", TreeViewHelper.GetPath(categoryTreeView.SelectedNode));
            }
            if (templateListView.SelectedItems.Count == 1)
            {
                TemplateItem item = (TemplateItem)templateListView.SelectedItems[0];

                ICSharpCode.Core.PropertyService.Set("Dialogs.NewFileDialog.LastSelectedTemplate", item.Template.Name);

                string fileName;
                string standardNamespace = "DefaultNamespace";
                if (allowUntitledFiles)
                {
                    fileName = GenerateCurrentFileName();
                }
                else
                {
                    fileName = ControlDictionary["fileNameTextBox"].Text.Trim();
                    if (!FileUtility.IsValidPath(fileName) ||
                        fileName.IndexOf(Path.AltDirectorySeparatorChar) >= 0 ||
                        fileName.IndexOf(Path.DirectorySeparatorChar) >= 0)
                    {
                        MessageService.ShowError(StringParser.Parse("${res:ICSharpCode.SharpDevelop.Commands.SaveFile.InvalidFileNameError}", new StringTagPair("FileName", fileName)));
                        return;
                    }
                    if (Path.GetExtension(fileName).Length == 0)
                    {
                        fileName += Path.GetExtension(item.Template.SuggestFileName(null));
                    }
                    fileName = Path.Combine(basePath, fileName);
                    fileName = FileUtility.NormalizePath(fileName);
                    if (project != null)
                    {
                        standardNamespace = CustomToolsService.GetDefaultNamespace(project, fileName);
                    }
                }

                options                     = new FileTemplateOptions();
                options.ClassName           = GenerateValidClassOrNamespaceName(Path.GetFileNameWithoutExtension(fileName), false);
                options.FileName            = FileName.Create(fileName);
                options.IsUntitled          = allowUntitledFiles;
                options.Namespace           = standardNamespace;
                options.CustomizationObject = localizedTypeDescriptor;
                options.Project             = project;

                result       = SelectedTemplate.Create(options);
                DialogResult = DialogResult.OK;
                if (result != null)
                {
                    SelectedTemplate.RunActions(result);
                }
            }
        }