Exemplo n.º 1
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);
        }
        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.º 3
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.º 4
0
 internal void DestroyScript()
 {
     if (null != this.parsedScript)
     {
         this.parsedScript.DestroyScript();
         this.parsedScript = null;
     }
 }
Exemplo n.º 5
0
        public void CopyParsedResults(IParsedScript other)
        {
            if (null == other)
            {
                return;
            }

            this.codeBlockNode = other.GetParsedResults();
        }
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
        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.º 8
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());
        }
        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.º 10
0
        private CodeFragmentManager CreateFromContent(string scriptContent)
        {
            MemoryStream inputStream = new MemoryStream(
                Encoding.Default.GetBytes(scriptContent));

            IParsedScript parsedScript = InterfaceFactory.CreateParsedScript();

            if (parsedScript.ParseStream(inputStream))
            {
                return(new CodeFragmentManager(parsedScript));
            }

            return(null);
        }
Exemplo n.º 11
0
        internal ScriptObject(string fileContent)
        {
            this.ScriptModifiedExternal = false;
            this.parsedScript           = InterfaceFactory.CreateParsedScript();

            if (string.IsNullOrEmpty(fileContent) == false)
            {
                MemoryStream inputStream = new MemoryStream(
                    Encoding.Default.GetBytes(fileContent));

                this.parsedScript.ParseStream(inputStream);
            }

            scriptState = new ScriptState(new TextBuffer(fileContent));
        }
Exemplo n.º 12
0
        internal ScriptObject(string fileContent)
        {
            this.ScriptModifiedExternal = false;
            this.parsedScript = InterfaceFactory.CreateParsedScript();

            if (string.IsNullOrEmpty(fileContent) == false)
            {
                MemoryStream inputStream = new MemoryStream(
                    Encoding.Default.GetBytes(fileContent));

                this.parsedScript.ParseStream(inputStream);
            }

            scriptState = new ScriptState(new TextBuffer(fileContent));
        }
Exemplo n.º 13
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.º 14
0
        internal CodeFragmentManager(IParsedScript iParsedScript)
        {
            // TODO: Complete member initialization
            this.parsedScript = iParsedScript;

            CodeBlockNode parsedResults = iParsedScript.GetParsedResults();

            if (null != parsedResults)
            {
                NodeProcessor nodeProcessor = new NodeProcessor(parsedResults.Body);
                nodeProcessor.GenerateFragments(out fragmentArray);
                Array.Sort(fragmentArray);
            }
            else
            {
                // Create a dummy fragment just for the heck of it.
                fragmentArray = new CodeFragment[] { new CodeFragment(-1, -1, -1) };
            }
        }
Exemplo n.º 15
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.º 16
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;
        }
Exemplo n.º 17
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.º 18
0
        internal IScriptObject OpenScript(string scriptPath)
        {
            solutionModified       = true; // Changes should be persisted.
            showSaveSolutionDialog = true;

            if (File.Exists(scriptPath) == false)
            {
                return(null); // The file does not exist.
            }
            // If the entire script is so messed up that it cannot even be
            // parsed in a meaningful way, then "ParseScript" call will fail.
            // When that happens, we don't return "null" from here, the file
            // open should continue (and errors be shown as red colored text).
            IParsedScript parsedScript = InterfaceFactory.CreateParsedScript();

            parsedScript.ParseScript(scriptPath);

            // Add the new script to loaded scripts.
            IScriptObject hostScript = new ScriptObject(parsedScript);

            loadedScripts.Add(hostScript);

            // Notify event subscribers that the script count has changed.
            if (null != ScriptCountChanged)
            {
                ScriptCountChangedEventArgs eventArgs = new ScriptCountChangedEventArgs();
                eventArgs.ScriptsAdded.Add(hostScript);
                ScriptCountChanged(this, eventArgs);
            }

            // Subscribe to the new text buffer event notification.
            ITextBuffer textBuffer = hostScript.GetTextBuffer();

            textBuffer.LinesUpdated += linesUpdatedHandler;
            return(hostScript);
        }
Exemplo n.º 19
0
 internal void DestroyScript()
 {
     if (null != this.parsedScript)
     {
         this.parsedScript.DestroyScript();
         this.parsedScript = null;
     }
 }
Exemplo n.º 20
0
        void OnMainWindowKeyDown(object sender, KeyEventArgs e)
        {
            IScriptObject activeScript = Solution.Current.ActiveScript;

            if (null == activeScript)
            {
                return; // No active script.
            }
            IParsedScript parsedScript = activeScript.GetParsedScript();

            if (null == parsedScript)
            {
                return; // No active script.
            }
            bool shift    = Keyboard.IsKeyDown(Key.RightShift) || Keyboard.IsKeyDown(Key.LeftShift);
            bool control  = Keyboard.IsKeyDown(Key.RightCtrl) || Keyboard.IsKeyDown(Key.LeftCtrl);
            bool capsLock = Console.CapsLock;
            bool alt      = Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt);

            textCore.ReadOnlyState = IsDebuggingOrExecuting();
            bool programRunning = textCore.ReadOnlyState;

            parseTimer.Stop();
            parseTimer.Start();
            textCanvas.PauseCaretTimer(true);
            textCanvas.PauseCaretTimer(false);

            // Allow extensions to handle key event before allowing it to go into
            // the text canvas. This way extensions can choose to filter or prevent
            // a key from being processed.
            //
            if (null != editorExtensions)
            {
                foreach (EditorExtension extension in editorExtensions)
                {
                    extension.PreKeyDownEvent(e);
                    if (e.Handled != false)
                    {
                        return;
                    }
                }
            }

            e.Handled = true;
            bool possibleLineChanges = false;
            char character           = char.MinValue;

            switch (e.Key)
            {
            case Key.Delete:
            case Key.Back:
                if (!CheckExecutionState())
                {
                    possibleLineChanges = true;
                    textCore.DoControlCharacter(e.Key);
                }
                break;
            }

            if (false == control) //control == false
            {
                switch (e.Key)
                {
                case Key.Space:
                case Key.Tab:
                    if (!CheckExecutionState())
                    {
                        character = HandleCharacterKey(e);
                    }
                    break;

                case Key.Enter:
                    if (!CheckExecutionState())
                    {
                        possibleLineChanges = true;
                        textCore.InsertText(GetKeyboardCharacter(e));
                    }
                    break;

                default:
                    if ((e.Key >= Key.D0 && e.Key <= Key.Z) ||
                        (e.Key >= Key.NumPad0 && e.Key <= Key.Divide) ||
                        (e.Key >= Key.OemSemicolon && e.Key <= Key.Oem102))
                    {
                        if (!CheckExecutionState())
                        {
                            character = HandleCharacterKey(e);
                        }
                    }
                    break;
                }
            }

            if (control == true && alt == true)
            {
                if ((e.Key >= Key.D0 && e.Key <= Key.Z) ||
                    (e.Key >= Key.NumPad0 && e.Key <= Key.Divide) ||
                    (e.Key >= Key.OemSemicolon && e.Key <= Key.Oem102))
                {
                    if (!CheckExecutionState())
                    {
                        character = HandleCharacterKey(e);
                    }
                }
            }

            if (false != possibleLineChanges)
            {
                UpdateCanvasDimension();
                UpdateCaretPosition();
                textCanvas.BreakpointsUpdated();
            }

            switch (e.Key)
            {
            case Key.Left:
            case Key.Right:
            case Key.Home:
            case Key.End:
            case Key.PageUp:
            case Key.PageDown:
                textCore.DoNavigation(e.Key);
                break;

            case Key.Up:
            case Key.Down:
                textCore.DoNavigation(e.Key);
                break;

            case Key.F9:
            {
                bool isInDebugMode = false;
                if (textCore.ToggleBreakpoint())
                {
                    textCanvas.BreakpointsUpdated();
                }
                else if (string.IsNullOrEmpty(activeScript.GetParsedScript().GetScriptPath()))
                {
                    DisplayStatusMessage(StatusTypes.Warning, Configurations.SaveFileBreakpointWarning, 3);
                }
                else if (Solution.Current.ExecutionSession.IsExecutionActive(ref isInDebugMode))
                {
                    DisplayStatusMessage(StatusTypes.Warning, Configurations.BreakpointDebugWarning, 3);
                }
            }
            break;
            }

            if (null != editorExtensions)
            {
                // Allow extensions to process the key after it is processed.
                foreach (EditorExtension extension in editorExtensions)
                {
                    extension.PostKeyDownEvent(e, character);
                }
            }

            // Some keys do not change the position of the cursor, for example
            // CTRL and SHIFT keys. In such cases, the script doesn't need update.
            if (IsCursorMovingKeyEvent(e))
            {
                UpdateCaretPosition();
                UpdateUiForModifiedScript(Solution.Current.ActiveScript);
            }
        }