コード例 #1
0
        /// <summary>
        /// Attempts to load a code file
        /// </summary>
        /// <param name="filepath"></param>
        /// <returns></returns>
        public static ProjectItemCodeDocument FromFile(string filepath, ProjectItem parent)
        {
            if(!File.Exists(filepath))
                return null;

            var language = ServiceLocator.Instance.Resolve<ICodeLanguageService>().GetByExtension(Path.GetExtension(filepath));
            ProjectItemCodeDocument newp = new ProjectItemCodeDocument(Path.GetFileName(filepath), language, parent);
            newp.OverrideFilePath = filepath;
            newp.ReloadDocument();

            return newp;
        }
コード例 #2
0
        /// <summary>
        /// Handles any given File Path
        /// </summary>
        /// <param name="fileToOpen"></param>
        protected void OpenFile(string fileToOpen)
        {
            if(_languageService.IsProjectFile(fileToOpen)) {

                OpenProject(fileToOpen);

            } else {
                if(_ide.CurrentSolution != null) {

                    var currentProject = _ide.CurrentSolution.ActiveProject;
                    if(currentProject.CanAdd(fileToOpen)) {
                        currentProject.Add(fileToOpen);
                    } else {
                        _workbenchService.MessageBox(
                            string.Format(Strings.NoPluginCanHandleExtension, Path.GetExtension(fileToOpen)),
                            Strings.FileOpenError, MessageBoxType.Error, MessageBoxWPFButton.OK);
                    }

                } else {

                    var lang = _languageService.GetByExtension(Path.GetExtension(fileToOpen));

                    if(lang == null) {
                        _workbenchService.MessageBox(Strings.NoPluginCanHandleSelectedFile, Strings.UnknownFile, MessageBoxType.Error);
                        return;
                    }

                    if(_workbenchService.MessageBox(
                        string.Format(Strings.NoActiveProjectCanHandleCreateANew, lang.Name), Strings.OpenAItem
                        , MessageBoxType.Question, MessageBoxWPFButton.YesNo) == IDDialogResult.Yes) {

                        var name = Path.GetFileNameWithoutExtension(fileToOpen);
                        var project = lang.Create(name, name, Path.GetDirectoryName(fileToOpen));

                        var doc = new ProjectItemCodeDocument(Path.GetFileName(fileToOpen), lang, project);
                        project.Add(doc);
                        doc.IsStartUpDocument = true;
                        doc.ReloadDocument();

                        _ide.CurrentSolution = new SmartSolution() { Name = "Solution" };
                        _ide.CurrentSolution.Add(project);

                        doc.ShowInWorkSpace();
                        project.SaveProject();
                    }
                }
            }
        }