Exemplo n.º 1
0
 public void SetBookmark(char c, string path, int position)
 {
     if (c >= 'A' && c <= 'Z')
     {
         PositionFile file = GetFile(path) ?? new PositionFile(path);
         for (int i = bookmarks.Count; i-- > 0;)
         {
             List <PositionChar> pcs = bookmarks[i];
             for (int j = pcs.Count; j-- > 0;)
             {
                 PositionChar pc = pcs[j];
                 if (pc.c == c)
                 {
                     pcs.RemoveAt(j);
                     break;
                 }
             }
             if (pcs.Count == 0)
             {
                 bookmarks.RemoveAt(i);
                 bookmarkFiles.RemoveAt(i);
             }
         }
         int index = bookmarkFiles.IndexOf(file);
         if (index == -1)
         {
             index = bookmarks.Count;
             bookmarkFiles.Add(file);
             bookmarks.Add(new List <PositionChar>(4));
         }
         bookmarks[index].Add(new PositionChar(c, position));
     }
 }
Exemplo n.º 2
0
 private PositionFile GetFile(string path)
 {
     if (currentFile != null && currentFile.path == path)
     {
         return(currentFile);
     }
     if (_files != null)
     {
         for (int i = 0; i < _files.Length; ++i)
         {
             PositionFile file = _files[i];
             if (file != null && file.path == path)
             {
                 return(_files[i]);
             }
         }
     }
     for (int i = bookmarkFiles.Count; i-- > 0;)
     {
         PositionFile file = bookmarkFiles[i];
         if (file.path == path)
         {
             return(file);
         }
     }
     return(null);
 }
Exemplo n.º 3
0
 public void ViRenameFile(string oldFile, string newFile)
 {
     if (_files != null)
     {
         for (int i = 0; i < _files.Length; ++i)
         {
             PositionFile file = _files[i];
             if (file != null && file.path == oldFile)
             {
                 file.path = newFile;
             }
         }
     }
 }
Exemplo n.º 4
0
 public void ViSetCurrentFile(string path)
 {
     if (currentFile != null && currentFile.path == path)
     {
         return;
     }
     currentFile = GetFile(path);
     if (currentFile == null)
     {
         currentFile = new PositionFile(path);
         if (_files == null)
         {
             _files = new PositionFile[_maxViPositions];
         }
         _files[_filesIndex] = currentFile;
         _filesIndex         = (_filesIndex + 1) % _maxViPositions;
     }
 }
Exemplo n.º 5
0
        public override void InsertText(int index, string text)
        {
            PositionFile currentFile = _controller.macrosExecutor.currentFile;

            PositionNode[] positionHistory = _controller.macrosExecutor.positionHistory;
            for (int i = 0; i < positionHistory.Length; ++i)
            {
                PositionNode node = positionHistory[i];
                if (node != null && node.file == currentFile && node.position > index)
                {
                    node.position += text.Length;
                }
            }
            int pcIndex = _controller.macrosExecutor.bookmarkFiles.IndexOf(currentFile);

            if (pcIndex != -1)
            {
                List <PositionChar> pcs = _controller.macrosExecutor.bookmarks[pcIndex];
                for (int i = pcs.Count; i-- > 0;)
                {
                    PositionChar pc = pcs[i];
                    if (pc.position > pcIndex)
                    {
                        pc.position += text.Length;
                        pcs[i]       = pc;
                    }
                }
            }
            for (int i = _controller.bookmarks.Count; i-- > 0;)
            {
                int position = _controller.bookmarks[i];
                if (position != -1 && position > index)
                {
                    _controller.bookmarks[i] = position + text.Length;
                }
            }
        }
Exemplo n.º 6
0
 public void ViPositionAdd(int position)
 {
     if (currentFile != null && (_lastFile != currentFile || _lastPosition != position))
     {
         _lastFile     = currentFile;
         _lastPosition = position;
         if (_nextCount > 0)
         {
             ++_prevCount;
             for (int i = 0; i < _nextCount - 1; ++i)
             {
                 positionHistory[(_offset + _prevCount + i) % _maxViPositions] = null;
             }
             _nextCount = 0;
         }
         positionHistory[(_offset + _prevCount) % _maxViPositions] = new PositionNode(currentFile, position);
         ++_nextCount;
         if (_prevCount + _nextCount > _maxViPositions)
         {
             _offset = (_offset + 1) % _maxViPositions;
             --_prevCount;
         }
     }
 }
Exemplo n.º 7
0
        public override void RemoveText(int index, int count)
        {
            PositionFile currentFile = _controller.macrosExecutor.currentFile;

            PositionNode[] positionHistory = _controller.macrosExecutor.positionHistory;
            for (int i = 0; i < positionHistory.Length; ++i)
            {
                PositionNode node = positionHistory[i];
                if (node != null && node.file == currentFile && node.position > index)
                {
                    node.position -= count;
                    if (node.position < index)
                    {
                        node.position = index;
                    }
                }
            }
            int pcIndex = _controller.macrosExecutor.bookmarkFiles.IndexOf(currentFile);

            if (pcIndex != -1)
            {
                List <PositionChar> pcs = _controller.macrosExecutor.bookmarks[pcIndex];
                for (int i = pcs.Count; i-- > 0;)
                {
                    PositionChar pc = pcs[i];
                    if (pc.position > pcIndex)
                    {
                        pc.position -= count;
                        if (pc.position < pcIndex)
                        {
                            pcs.RemoveAt(i);
                            if (pcs.Count == 0)
                            {
                                _controller.bookmarks.RemoveAt(pcIndex);
                                break;
                            }
                        }
                        else
                        {
                            pcs[i] = pc;
                        }
                    }
                }
            }
            for (int i = _controller.bookmarks.Count; i-- > 0;)
            {
                int position = _controller.bookmarks[i];
                if (position != -1 && position > index)
                {
                    position -= count;
                    if (position < index)
                    {
                        _controller.bookmarkNames.RemoveAt(i);
                        _controller.bookmarks.RemoveAt(i);
                    }
                    else
                    {
                        _controller.bookmarks[i] = position;
                    }
                }
            }
        }
Exemplo n.º 8
0
 public PositionNode(PositionFile file, int position)
 {
     this.file     = file;
     this.position = position;
 }