Beispiel #1
0
        public int GetEntryCount()
        {
            int count = 0;

            FindPosition             position = InitialPosition;
            HierarchicalRomFileTable tab      = ParentFileSystem.FileTable;

            if (Mode.HasFlag(OpenDirectoryMode.Directories))
            {
                while (tab.FindNextDirectory(ref position, out string _))
                {
                    count++;
                }
            }

            if (Mode.HasFlag(OpenDirectoryMode.Files))
            {
                while (tab.FindNextFile(ref position, out RomFileInfo _, out string _))
                {
                    count++;
                }
            }

            return(count);
        }
        private void Search()
        {
            ITextBuffer buffer = textEditorControl.TextCore.CurrentTextBuffer;

            if (match_checkbox.IsChecked == false)
            {
                textEditorControl.TextCore.FindReplace(findTextbox.Text, null, FindOptions.ReplaceOnce);
            }
            else if (match_checkbox.IsChecked == true)
            {
                textEditorControl.TextCore.FindReplace(findTextbox.Text, null, FindOptions.MatchCase);
            }

            if (buffer.SearchResult != null)
            {
                int searchIndex = buffer.CurrentSearchIndex;

                if (buffer.SearchResult.Count == 0)
                {
                    textEditorControl.TextCore.FindReplace(null, null, FindOptions.FindNext);
                    textEditorControl.UpdateScriptDisplay(Solution.Current.ActiveScript);
                }

                if (searchIndex != -1 && buffer.SearchResult.Count > 0)
                {
                    FindPosition currentPosition = buffer.SearchResult[searchIndex];
                    textEditorControl.textCanvas.TextEditorCore.SetCursorPosition(currentPosition.startPoint.X, currentPosition.startPoint.Y);
                    textEditorControl.UpdateCaretPosition();
                    textEditorControl.UpdateScriptDisplay(Solution.Current.ActiveScript);
                }

                match_label.Text = buffer.SearchResult.Count.ToString() + " Results found";
            }
        }
Beispiel #3
0
 public ArchiveDirectory(ArchiveFileSystem fs, string path, FindPosition position, OpenDirectoryMode mode)
 {
     ParentFileSystem = fs;
     InitialPosition  = position;
     FullPath         = path;
     Mode             = mode;
 }
Beispiel #4
0
        public void AddingDirectory()
        {
            var table            = new HierarchicalRomFileTable();
            var expectedPosition = new FindPosition {
                NextDirectory = -1, NextFile = -1
            };

            table.AddDirectory("/dir");
            bool success = table.TryOpenDirectory("/dir", out FindPosition position);

            Assert.True(success, "Opening directory failed");
            Assert.Equal(expectedPosition, position);
        }
        private void OnFindTextBoxKeyUp(object sender, KeyEventArgs e)
        {
            bool isAltPressed;

            if (Solution.Current.ActiveScript == null)
            {
                return;
            }

            if (e.Key == Key.LeftAlt || e.Key == Key.RightAlt)
            {
                isAltPressed = true;
            }
            else
            {
                isAltPressed = false;
            }

            if ((e.SystemKey == Key.None) && isAltPressed == false)
            {
                ITextBuffer buffer = textEditorControl.TextCore.CurrentTextBuffer;
                if (e.Key == Key.Enter)
                {
                    if (buffer.SearchResult != null && buffer.SearchResult.Count != 0)
                    {
                        textEditorControl.TextCore.FindReplace(findTextbox.Text, null, FindOptions.FindNext);
                        int searchIndex = buffer.CurrentSearchIndex;
                        if (buffer.SearchResult.Count != 0 && searchIndex != -1)
                        {
                            FindPosition currentPosition = buffer.SearchResult[searchIndex];
                            textEditorControl.textCanvas.TextEditorCore.SetCursorPosition(currentPosition.startPoint.X, currentPosition.startPoint.Y);
                            textEditorControl.UpdateCaretPosition();
                            textEditorControl.UpdateScriptDisplay(Solution.Current.ActiveScript);
                        }
                    }
                }
                else
                {
                    Search();
                }
            }
        }
Beispiel #6
0
        public IEnumerable <DirectoryEntry> Read()
        {
            FindPosition             position = InitialPosition;
            HierarchicalRomFileTable tab      = ParentFileSystem.FileTable;

            if (Mode.HasFlag(OpenDirectoryMode.Directories))
            {
                while (tab.FindNextDirectory(ref position, out string name))
                {
                    yield return(new DirectoryEntry(name, FullPath + '/' + name, DirectoryEntryType.Directory, 0));
                }
            }

            if (Mode.HasFlag(OpenDirectoryMode.Files))
            {
                while (tab.FindNextFile(ref position, out RomFileInfo info, out string name))
                {
                    yield return(new DirectoryEntry(name, FullPath + '/' + name, DirectoryEntryType.File, info.Length));
                }
            }
        }
        private void OnMatchCaseChecked(object sender, RoutedEventArgs e)
        {
            ITextBuffer buffer = textEditorControl.TextCore.CurrentTextBuffer;

            if (Solution.Current.ActiveScript == null)
            {
                return;
            }

            if (buffer.SearchResult != null)
            {
                buffer.SearchResult.Clear();
            }
            textEditorControl.UpdateScriptDisplay(Solution.Current.ActiveScript);

            if (match_checkbox.IsChecked == true)
            {
                textEditorControl.TextCore.FindReplace(findTextbox.Text, null, FindOptions.MatchCase);
            }
            else
            {
                textEditorControl.TextCore.FindReplace(findTextbox.Text, null, FindOptions.ReplaceOnce);
            }

            int searchIndex = buffer.CurrentSearchIndex;

            if (buffer.SearchResult.Count != 0 && searchIndex != -1)
            {
                FindPosition currentPosition = buffer.SearchResult[searchIndex];
                textEditorControl.textCanvas.TextEditorCore.SetCursorPosition(currentPosition.startPoint.X, currentPosition.startPoint.Y);
                textEditorControl.UpdateCaretPosition();
                textEditorControl.UpdateScriptDisplay(Solution.Current.ActiveScript);
            }

            if (buffer.SearchResult != null)
            {
                match_label.Text = buffer.SearchResult.Count.ToString() + " Results found";
            }
        }
        private void OnUpArrowClick(object sender, RoutedEventArgs e)
        {
            ITextBuffer buffer = textEditorControl.TextCore.CurrentTextBuffer;

            if (Solution.Current.ActiveScript == null)
            {
                return;
            }

            if (buffer.SearchResult != null && buffer.SearchResult.Count != 0)
            {
                textEditorControl.TextCore.FindReplace(findTextbox.Text, null, FindOptions.FindPrevious);
                int searchIndex = buffer.CurrentSearchIndex;
                if (buffer.SearchResult.Count != 0 && searchIndex != -1)
                {
                    FindPosition currentPosition = buffer.SearchResult[searchIndex];
                    textEditorControl.textCanvas.TextEditorCore.SetCursorPosition(currentPosition.startPoint.X, currentPosition.startPoint.Y);
                    textEditorControl.UpdateCaretPosition();
                    textEditorControl.UpdateScriptDisplay(Solution.Current.ActiveScript);
                }
            }
        }
        private void OnReplaceClick(object sender, RoutedEventArgs e)
        {
            if (Solution.Current.ActiveScript == null || replaceTextbox.Text.Equals(String.Empty))
            {
                return;
            }

            if (textEditorControl.TextCore.ReadOnlyState == true)
            {
                textEditorControl.DisplayStatusMessage(StatusTypes.Error, Configurations.EditingError, 3);
            }
            else
            {
                ITextBuffer buffer      = textEditorControl.TextCore.CurrentTextBuffer;
                FindOptions findOptions = FindOptions.ReplaceOnce;

                if (match_checkbox.IsChecked == true)
                {
                    findOptions |= FindOptions.MatchCase;
                    textEditorControl.TextCore.FindReplace(findTextbox.Text, replaceTextbox.Text, findOptions);
                }
                else
                {
                    textEditorControl.TextCore.FindReplace(findTextbox.Text, replaceTextbox.Text, FindOptions.ReplaceOnce);
                }

                int searchIndex = buffer.CurrentSearchIndex;
                if (buffer.SearchResult.Count != 0 && searchIndex != -1)
                {
                    FindPosition currentPosition = buffer.SearchResult[searchIndex];
                    textEditorControl.textCanvas.TextEditorCore.SetCursorPosition(currentPosition.startPoint.X, currentPosition.startPoint.Y);
                    textEditorControl.UpdateCaretPosition();
                    textEditorControl.UpdateScriptDisplay(Solution.Current.ActiveScript);
                }

                match_label.Text = buffer.SearchResult.Count.ToString() + " Results found";
            }
        }
Beispiel #10
0
        protected override DrawingVisual RenderCore(RenderParameters renderParams)
        {
            if (null == drawingVisual)
            {
                drawingVisual = new DrawingVisual();
            }

            // There's no script yet.
            if (null == currentScript)
            {
                return(drawingVisual);
            }
            if (null == textEditorCanvas.TextEditorCore.CurrentTextBuffer)
            {
                return(drawingVisual);
            }

            DrawingContext context = drawingVisual.RenderOpen();


            lineSelection.SetCharacterPosition(textEditorCanvas.TextEditorCore.CursorPosition);
            Rect cursorSelections = CalculateRectangleFullLine(lineSelection, renderParams.firstVisibleLine);

            RenderRectangle(context, cursorSelections, UIColors.CursorSelectionColor);

            List <InlineMessageItem> messageList = Solution.Current.GetInlineMessage();

            if (messageList != null)
            {
                foreach (InlineMessageItem message in messageList)
                {
                    int line   = message.Line;
                    int column = message.Column;

                    if (Solution.Current.ActiveScript == null || message.FilePath != Solution.Current.ActiveScript.GetParsedScript().GetScriptPath())
                    {
                        continue;
                    }

                    if (line >= 0)
                    {
                        System.Drawing.Point inlineSelectionStart = new System.Drawing.Point(column, line);
                        inLineSelection.SetCharacterPosition(inlineSelectionStart);
                        Rect  outputSelections = CalculateRectangleFullLine(inLineSelection, renderParams.firstVisibleLine);
                        Color inLineColor      = new Color();
                        switch (message.Type)
                        {
                        case InlineMessageItem.OutputMessageType.Error:
                            inLineColor = UIColors.InlinErrorColor;
                            break;

                        case InlineMessageItem.OutputMessageType.Warning:
                            inLineColor = UIColors.InlineWarningColor;
                            break;

                        case InlineMessageItem.OutputMessageType.PossibleError:
                            inLineColor = UIColors.InlinPossibleErrorColor;
                            break;

                        case InlineMessageItem.OutputMessageType.PossibleWarning:
                            inLineColor = UIColors.InlinPossibleWarningColor;
                            break;
                        }
                        RenderRectangle(context, outputSelections, inLineColor);
                    }
                }
            }

            if (null != breakpointsRef)
            {
                CharPosition startPoint = currentScript.CreateCharPosition();
                CharPosition endPoint   = currentScript.CreateCharPosition();

                foreach (CodeRange breakpoint in breakpointsRef)
                {
                    if (FallsWithinActiveScript(breakpoint.StartInclusive) == false)
                    {
                        continue; // This breakpoint does not belong to the script.
                    }
                    int startX = breakpoint.StartInclusive.CharNo - 1;
                    int startY = breakpoint.StartInclusive.LineNo - 1;
                    int endX   = breakpoint.EndExclusive.CharNo - 1;
                    int endY   = breakpoint.EndExclusive.LineNo - 1;

                    startPoint.SetCharacterPosition(startX, startY);
                    endPoint.SetCharacterPosition(endX, endY);
                    Rect region = CalculateRectangleFullLine(startPoint, renderParams.firstVisibleLine);
                    RenderRectangle(context, region, UIColors.BreakpointLineColor);
                }
            }

            if (FallsWithinActiveScript(executionCursor.StartInclusive))
            {
                CharPosition start = currentScript.CreateCharPosition();
                CharPosition end   = currentScript.CreateCharPosition();

                start.SetCharacterPosition(
                    executionCursor.StartInclusive.CharNo - 1,
                    executionCursor.StartInclusive.LineNo - 1);

                end.SetCharacterPosition(
                    executionCursor.EndExclusive.CharNo - 1,
                    executionCursor.EndExclusive.LineNo - 1);

                List <Rect> execCursors = CalculateRectangles(start, end, renderParams.firstVisibleLine);
                RenderRectangles(context, execCursors, UIColors.ExecutionCursorColor);
            }

            List <Rect> selections = CalculateRectangles(selectionStart, selectionEnd, renderParams.firstVisibleLine);

            RenderRectangles(context, selections, UIColors.SelectionsColor);

            List <FindPosition> searchResults = textEditorCanvas.TextEditorCore.CurrentTextBuffer.SearchResult;

            if (searchResults != null)
            {
                System.Drawing.Point start;
                System.Drawing.Point end;

                foreach (FindPosition item in searchResults)
                {
                    start  = item.startPoint;
                    end    = item.endPoint;
                    end.X += 1;
                    allOccurencesSelectionStart.SetCharacterPosition(start);
                    allOccurencesSelectionEnd.SetCharacterPosition(end);
                    List <Rect> findSelections = CalculateRectangles(allOccurencesSelectionStart, allOccurencesSelectionEnd, renderParams.firstVisibleLine);
                    RenderRectangles(context, findSelections, Colors.Yellow);
                }


                int searchIndex = textEditorCanvas.TextEditorCore.CurrentTextBuffer.CurrentSearchIndex;
                if (searchResults.Count != 0 && searchIndex != -1)
                {
                    FindPosition currentPosition = searchResults[searchIndex];

                    System.Drawing.Point startPoint = currentPosition.startPoint;
                    System.Drawing.Point endPoint   = currentPosition.endPoint;

                    endPoint.X += 1;

                    if (startPoint.X == 0 && endPoint.X == 0 &&
                        startPoint.Y == 0 && endPoint.Y == 0)
                    {
                    }
                    else
                    {
                        currentOccurenceSelectionStart.SetCharacterPosition(startPoint);
                        currentOccurenceSelectionEnd.SetCharacterPosition(endPoint);
                        List <Rect> currentOccurenceSelections = CalculateRectangles(currentOccurenceSelectionStart, currentOccurenceSelectionEnd, renderParams.firstVisibleLine);
                        RenderRectangles(context, currentOccurenceSelections, Colors.Orange);
                    }
                }
            }



            context.Close();
            return(drawingVisual);
        }
 public void BasicTests()
 {
     Assert.AreEqual("Position of alphabet: 1", FindPosition.Position('a'));
     Assert.AreEqual("Position of alphabet: 26", FindPosition.Position('z'));
     Assert.AreEqual("Position of alphabet: 5", FindPosition.Position('e'));
 }