private void AppendSearchPaths(ProtoCore.Options options)
        {
            string assemblyPath = Assembly.GetAssembly(typeof(ExecutionSession)).Location;

            options.IncludeDirectories.Add(Path.GetDirectoryName(assemblyPath));

            ITextEditorSettings editorSettings = TextEditorCore.Instance.TextEditorSettings;

            if (Directory.Exists(editorSettings.IncludePath))
            {
                options.IncludeDirectories.Add(editorSettings.IncludePath);
            }

            IScriptObject entryPointScript = Solution.Current.ActiveScript;

            if (null != entryPointScript)
            {
                IParsedScript parsedScript = entryPointScript.GetParsedScript();
                if (null != parsedScript)
                {
                    string scriptPath = parsedScript.GetScriptPath();
                    options.RootModulePathName = parsedScript.GetScriptPath();

                    if (string.IsNullOrEmpty(scriptPath) == false)
                    {
                        string directoryName = Path.GetDirectoryName(scriptPath);
                        options.IncludeDirectories.Add(directoryName);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static List <string> GetSearchPaths()
        {
            List <string> includeDirectories = new List <string>();
            string        assemblyPath       = Assembly.GetAssembly(typeof(ExtensionFactory)).Location;

            includeDirectories.Add(Path.GetDirectoryName(assemblyPath));

            if (Directory.Exists(textEditorCore.TextEditorSettings.IncludePath))
            {
                includeDirectories.Add(textEditorCore.TextEditorSettings.IncludePath);
            }

            IScriptObject entryPointScript = Solution.Current.ActiveScript;

            if (null != entryPointScript)
            {
                IParsedScript parsedScript = entryPointScript.GetParsedScript();
                if (null != parsedScript)
                {
                    string scriptPath = parsedScript.GetScriptPath();
                    if (string.IsNullOrEmpty(scriptPath) == false)
                    {
                        string directoryName = Path.GetDirectoryName(scriptPath);
                        includeDirectories.Add(directoryName);
                    }
                }
            }

            return(includeDirectories);
        }
Exemplo n.º 3
0
        public int GetScriptIndexFromPath(string scriptPath)
        {
            if (string.IsNullOrEmpty(scriptPath) != false)
            {
                return(-1);
            }

            int scriptIndex = 0;

            foreach (IScriptObject script in loadedScripts)
            {
                IParsedScript parsed = script.GetParsedScript();
                string        path   = (null == parsed ? null : parsed.GetScriptPath());

                if (string.IsNullOrEmpty(path) == false)
                {
                    StringComparison comparison = StringComparison.CurrentCultureIgnoreCase;
                    if (scriptPath.Equals(path, comparison))
                    {
                        return(scriptIndex); // Found the script!
                    }
                }

                scriptIndex = scriptIndex + 1;
            }

            return(-1);
        }
Exemplo n.º 4
0
        public string GetScriptPathFromIndex(int index)
        {
            if (index < 0 || (index >= loadedScripts.Count))
            {
                return(string.Empty);
            }

            IParsedScript currentScript = loadedScripts[index].GetParsedScript();

            return((null != currentScript) ? currentScript.GetScriptPath() : string.Empty);
        }
Exemplo n.º 5
0
        internal ScriptObject(IParsedScript parsedScript)
        {
            this.ScriptModifiedExternal = false;
            this.parsedScript = parsedScript;
            scriptState = new ScriptState(new TextBuffer(this));

            if (null == this.parsedScript)
                throw new InvalidOperationException("Invalid 'parsedScript'!");

            InitializeFileWatcher(parsedScript.GetScriptPath());
        }
Exemplo n.º 6
0
        internal ScriptObject(IParsedScript parsedScript)
        {
            this.ScriptModifiedExternal = false;
            this.parsedScript           = parsedScript;
            scriptState = new ScriptState(new TextBuffer(this));

            if (null == this.parsedScript)
            {
                throw new InvalidOperationException("Invalid 'parsedScript'!");
            }

            InitializeFileWatcher(parsedScript.GetScriptPath());
        }
Exemplo n.º 7
0
        internal TextBuffer(IScriptObject owningScript)
        {
            this.owningScript = owningScript;
            IParsedScript parsedScript = owningScript.GetParsedScript();

            if (parsedScript.GetScriptPath() == "")
            {
                this.lineList = new List <string>();
                this.lineList.Add(string.Empty);
            }
            else
            {
                string           scriptFilePath = parsedScript.GetScriptPath();
                ScriptFileReader scriptReader   = new ScriptFileReader(scriptFilePath, true);
                this.lineList = scriptReader.ReadInput();
            }

            undoRedoRecorder = new UndoRedoRecorder(this.lineList);

            this.parsePending   = true;
            this.scriptModified = false;
        }
        private void UpdateTabDisplayText()
        {
            IScriptObject currScript   = Solution.Current.ActiveScript;
            IParsedScript parsedScript = currScript.GetParsedScript();

            if (null != parsedScript)
            {
                string   filePath = parsedScript.GetScriptPath();
                FileInfo fileInfo = new FileInfo(filePath);
                int      tabIndex = ScriptTabControl.CurrentTab;
                ScriptTabControl.SetDisplayText(tabIndex, fileInfo.Name);
                currScript.GetTextBuffer().ScriptModified = false;
            }
        }
Exemplo n.º 9
0
        private void SerializeToScriptItems()
        {
            string directory = Path.GetDirectoryName(this.filePath);

            if (directory.EndsWith("\\") == false)
            {
                directory += "\\";
            }

            Uri solutionPath = new Uri(directory, UriKind.Absolute);

            List <ScriptItem> scripts = solutionData.Scripts;

            scripts.Clear();

            // Update each script path relative to the solution file.
            foreach (IScriptObject scriptObject in loadedScripts)
            {
                IParsedScript parsedScript = scriptObject.GetParsedScript();
                if (null != parsedScript)
                {
                    try
                    {
                        Uri scriptPath   = new Uri(parsedScript.GetScriptPath(), UriKind.Absolute);
                        Uri relativePath = solutionPath.MakeRelativeUri(scriptPath);

                        ScriptItem script = new ScriptItem();
                        script.RelativePath = relativePath.OriginalString;
                        script.EntryPoint   = (activeScript == scriptObject);
                        scripts.Add(script);
                    }
                    catch (Exception exception)
                    {
                        // Invalid file path, deal with it.
                        string message = exception.Message;
                    }
                }
            }

            // Update breakpoint path relative to the solution file.
            foreach (BreakpointItem breakpoint in solutionData.Breakpoints)
            {
                Uri absolutePath = new Uri(breakpoint.AbsolutePath, UriKind.Absolute);
                Uri relativePath = solutionPath.MakeRelativeUri(absolutePath);
                breakpoint.RelativePath = relativePath.OriginalString;
            }
        }
Exemplo n.º 10
0
        private string GetEntryScriptPath()
        {
            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            Logger.LogInfo("GetEntryScriptPath", "Init");

            IParsedScript parsedScript     = null;
            IScriptObject entryPointScript = Solution.Current.ActiveScript;

            if (null != entryPointScript)
            {
                parsedScript = entryPointScript.GetParsedScript();
            }

            string ret = (null == parsedScript ? null : parsedScript.GetScriptPath());

            Logger.LogInfo("GetEntryScriptPath", ret);

            Logger.LogPerf("GetEntryScriptPath", sw.ElapsedMilliseconds + " ms");
            return(ret);
        }
Exemplo n.º 11
0
        protected bool FallsWithinActiveScript(CodePoint codePoint)
        {
            if (null == codePoint.SourceLocation || (null == currentScript))
            {
                return(false);
            }
            if (string.IsNullOrEmpty(codePoint.SourceLocation.FilePath))
            {
                throw new InvalidOperationException("'SourceLocation' not specified!");
            }

            IParsedScript parsedScript = currentScript.GetParsedScript();

            if (null == parsedScript)
            {
                return(false);
            }

            string sourcePath = codePoint.SourceLocation.FilePath;
            string activePath = parsedScript.GetScriptPath();

            return(string.Compare(sourcePath, activePath, true) == 0);
        }
Exemplo n.º 12
0
        public bool SaveScript(bool saveAs)
        {
            if (parsedScript == null)
            {
                return(false);
            }
            string filePath = parsedScript.GetScriptPath();

            if (false == saveAs) // This is just a simple save.
            {
                if (scriptState.textBuffer.ScriptModified == false)
                {
                    return(true); // Nothing has changed, no need!
                }
            }

            if ((File.Exists(filePath) &&
                 ((File.GetAttributes(filePath) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)) || SystemFile(filePath))
            {
                if (saveAs == false)
                {
                    if (!SystemFile(filePath))
                    {
                        ReadOnlyDialogResult result = dialog.ShowReadOnlyDialog(true);

                        if (result == ReadOnlyDialogResult.OverWrite)
                        {
                            FileAttributes attributes = File.GetAttributes(filePath);
                            File.SetAttributes(filePath, attributes ^ FileAttributes.ReadOnly);
                        }
                        else if (result == ReadOnlyDialogResult.SaveAs)
                        {
                            saveAs = true;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        ReadOnlyDialogResult result = dialog.ShowReadOnlyDialog(false);
                        if (result == ReadOnlyDialogResult.SaveAs)
                        {
                            saveAs = true;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
            }

            if (filePath == "" || saveAs)
            {
                string newFilePath = null;
                while (true)
                {
                    newFilePath = PromptScriptSave();
                    if (string.IsNullOrEmpty(newFilePath))
                    {
                        return(false);
                    }

                    int newFileIndex = Solution.Current.GetScriptIndexFromPath(newFilePath);
                    if (newFileIndex != -1 && newFileIndex != Solution.Current.ActiveScriptIndex)
                    {
                        dialog.ShowFileAlreadyOpenDialog();
                    }
                    else
                    {
                        break;
                    }
                }

                // The check for the filePath is to see if the file is
                // being saved into the same file or a new file.
                if (!string.Equals(filePath, newFilePath))
                {
                    scriptState.textBuffer.ScriptModified = true;
                    filePath = newFilePath;
                    InitializeFileWatcher(newFilePath);
                }



                if (null != newFilePath)
                {
                    TextEditorCore.Instance.Data.AddToRecentFileList(newFilePath);
                }
            }

            if (fileWatcher != null)
            {
                fileWatcher.EnableRaisingEvents = false;
            }

            try
            {
                StreamWriter streamWriter = new StreamWriter(filePath);
                string       fileContent  = scriptState.textBuffer.GetContent();
                fileContent = fileContent.Replace("\n", "\r\n");
                streamWriter.Write(fileContent);
                streamWriter.Close();
            }
            catch (Exception)
            {
                IDialogProvider dialog  = TextEditorCore.DialogProvider;
                string          message = string.Format("Could not access file '{0}', please try again.", filePath);
                dialog.DisplayStatusMessage(StatusTypes.Warning, message, 5);
                return(false);
            }

            if (fileWatcher != null)
            {
                fileWatcher.EnableRaisingEvents = true;
            }

            bool parseResult = parsedScript.ParseScript(filePath);

            scriptState.textBuffer.ScriptModified = false;

            return(parseResult);
        }