Beispiel #1
0
 public HexCaret()
 {
     this.hexByteInfo = caretInfos[0];
     this.asciiInfo = caretInfos[1];
     UpdateInstallTimer();
     IsVisibleChanged += HexCaret_IsVisibleChanged;
     Loaded += (s, e) => UpdateInstallTimer();
     Unloaded += (s, e) => StopTimer();
 }
        /// <summary>
        /// Fill auto list with symbols when a '.' appears.
        /// This is for access to the tables or to members of Vision objects.
        /// E.g: Render.Draw
        /// </summary>
        /// <param name="sciWordBeforeOperator">The word preceding the operator.</param>
        /// <param offset>The offset/number of characters in front of the operator
        /// (e.g. is 3 for manual invocation of 'Debug.Dra'). This is always 0 for automatic
        /// invocation at the position of the operator</param>
        /// <returns>A list of symbols for the current request (maybe null).</returns>
        private SymbolCollection HandleDotOperator(string sciWordBeforeOperator, int offset)
        {
            Scintilla        SciControl = _currentDoc.ScintillaControl;
            CaretInfo        caret      = SciControl.Caret;
            SymbolCollection list       = null;

            // access to a static function or enum constant
            if (SciControl.Lexing.Keywords[LUA_PATTERN_STATIC_CLASSES_IDX].Contains(sciWordBeforeOperator) ||
                SciControl.Lexing.Keywords[LUA_PATTERN_MODULE_IDX].Contains(sciWordBeforeOperator))
            {
                //drill down the hierarchy: Application.FileSystem.blah
                int    iDepth  = 1;
                string command = sciWordBeforeOperator;
                while (SciControl.CharAt(caret.Position - 1 - command.Length - iDepth - offset) == '.')
                {
                    iDepth++;
                    command = SciControl.GetWordFromPosition(caret.Position - 1 - command.Length - iDepth - offset) + "." + command;
                }

                list = ScriptManager.GetMembersForSymbol(command);

                //add static members (for modules)
                SymbolCollection additionals = ScriptManager.GetMembersFromMetaTable(sciWordBeforeOperator);
                if (list == null)
                {
                    list = additionals;
                }
                else if (additionals != null)
                {
                    foreach (SymbolInfo symbol in additionals)
                    {
                        list.Add(symbol);
                    }
                }

                //remove unwanted duplicates of the vision module (inside other modules)
                if (sciWordBeforeOperator != "Vision" && additionals != null && list != null)
                {
                    SymbolCollection unwanted = ScriptManager.GetMembersFromMetaTable("Vision");
                    foreach (SymbolInfo symbol in unwanted)
                    {
                        if (list.Contains(symbol))
                        {
                            list.Remove(symbol);
                        }
                    }
                }
            }
            else if (SciControl.Lexing.Keywords[LUA_PATTERN_SPECIAL_VARS_IDX].Contains(sciWordBeforeOperator))
            {
                list = ScriptManager.GetMembersFromMetaTable(sciWordBeforeOperator);
            }

            return(list);
        }
        /// <summary>
        /// Fill auto list with symbols when a ':' appears.
        /// This is for "method" calls in Lua like self:DoSomething()
        /// </summary>
        /// <param name="sciWordBeforeOperator">The word preceding the operator.</param>
        /// <param offset>The offset/number of characters in front of the operator
        /// (e.g. is 6 for manual invocation of 'Debug:PrintL'). This is always 0 for automatic
        /// invocation at the position of the operator</param>
        /// <returns>A list of symbols for the current request (maybe null).</returns>
        private SymbolCollection HandleColonOperator(string sciWordBeforeOperator, int offset)
        {
            Scintilla        SciControl = _currentDoc.ScintillaControl;
            CaretInfo        caret      = SciControl.Caret;
            SymbolCollection list       = null;

            // access to a variable's members
            // for now, simply add every member function (note: no member variables) that were defined
            if (sciWordBeforeOperator == "self")
            {
                //note: we are not sure if 'self' is really a base entity
                list = ScriptManager.GetFunctionsForClass("VisBaseEntity_cl *");

                if (list == null)
                {
                    list = new SymbolCollection();
                }

                //add the callbacks defined in the file (or which could be defined)
                foreach (String callback in SciControl.Lexing.Keywords[LUA_PATTERN_CALLBACKS_CLASSES_IDX].Split(' '))
                {
                    if (SciControl.Text.Contains(callback))
                    {
                        list.Add(new SymbolInfo(callback, SymbolType.FUNCTION));
                    }
                    else
                    {
                        list.Add(new SymbolInfo(callback, SymbolType.CONSTANT));
                    }
                }
            }
            else
            {
                //dig down like this: abc.efg.hij:blah()
                int    iDepth  = 1;
                string command = sciWordBeforeOperator;
                while (SciControl.CharAt(caret.Position - 1 - command.Length - iDepth - offset) == '.')
                {
                    iDepth++;
                    command = SciControl.GetWordFromPosition(caret.Position - 1 - command.Length - iDepth - offset) + "." + command;
                }

                list = ScriptManager.GetFunctionsFromGlobal(command);
            }

            if (list == null || list.Count == 0)
            {
                //add methods of 'self'
                list = ScriptManager.GetFunctionsFromMetaTables();
            }

            return(list);
        }
Beispiel #4
0
 void Initialize(CaretInfo info, bool hasFocus)
 {
     if (info.Rect == null)
     {
         info.Geometry            = null;
         info.BlinkHiddenGeometry = null;
     }
     else
     {
         var rect = info.Rect.Value;
         if (!hasFocus)
         {
             double height = Math.Min(rect.Height, 2.0);
             rect = new Rect(rect.X, rect.Y + rect.Height - height, rect.Width, height);
         }
         info.Geometry = new RectangleGeometry(new Rect(rect.X - horizOffset, rect.Y, rect.Width, rect.Height));
         info.Geometry.Freeze();
         info.BlinkHiddenGeometry = hasFocus ? null : info.Geometry;
     }
 }
        /// <summary>
        /// Request for the autolist to be shown if possible
        /// </summary>
        /// <param name="manualOpen"></param>
        public override void RequestAutoList(bool manualOpen)
        {
            string sciWordBeforeOperator = "";

            Scintilla SciControl = _currentDoc.ScintillaControl;
            CaretInfo caret      = SciControl.Caret;

            //skip auto list if there is no carret
            if (caret == null)
            {
                return;
            }

            SymbolCollection list = null;

            char charBeforeCursor = (char)0;
            int  offset           = 0;

            if (caret.Position >= 1)
            {
                //avoid auto completion in comments, strings, etc...
                byte style = SciControl.Styles.GetStyleAt(caret.Position);
                for (int i = 0; i < LUA_AVOID_AUTO_COMPLETE_IN_STYLE_AREA.Length; i++)
                {
                    if (style == LUA_AVOID_AUTO_COMPLETE_IN_STYLE_AREA[i])
                    {
                        return;
                    }
                }

                charBeforeCursor = SciControl.CharAt(caret.Position - 1);
            }

            if (charBeforeCursor != 0)
            {
                //get the word without the current character
                sciWordBeforeOperator = SciControl.GetWordFromPosition(caret.Position - 2);

                if (sciWordBeforeOperator != null)
                {
                    // go back to last operator on manual open
                    // e.g: Debug:PritLi ->-+
                    //           ^--<--<--<-+
                    if (manualOpen)
                    {
                        char op = charBeforeCursor;

                        //also stop if the start of the current line has been reached
                        while (op != 0 && op != '.' && op != ':' && op != ' ' && op != '\n' && op != '\r' && op != '\t')
                        {
                            offset++;
                            op = SciControl.CharAt(caret.Position - 2 - offset);
                        }
                        //grab the word before the operator
                        string newWord = SciControl.GetWordFromPosition(caret.Position - 3 - offset);

                        //use it if valid
                        if (newWord != null)
                        {
                            sciWordBeforeOperator = newWord;
                            charBeforeCursor      = op;
                            offset++;
                        }
                    }

                    //handle the different operators
                    switch (charBeforeCursor)
                    {
                    case '.': list = HandleDotOperator(sciWordBeforeOperator, offset); break;

                    case ':': list = HandleColonOperator(sciWordBeforeOperator, offset); break;

                    case ' ': list = HandleBlank(sciWordBeforeOperator); break;

                    default:  break;
                    }
                }
            }

            // Ctrl-Space pressed and no '.' or ':' -> show global scope symbols, keywords and special variables
            if ((list == null || list.Count == 0) && manualOpen)
            {
                //showList = true;
                list = ScriptManager.GetGlobalSymbols();
                sciWordBeforeOperator = SciControl.GetWordFromPosition(caret.Position - 1);

                string   keywordString = SciControl.Lexing.Keywords[LUA_PATTERN_KEYWORDS_IDX];
                string[] keywords      = keywordString.Split(' ');
                // get keywords and special variables from the Lua.syn file
                foreach (string keyword in keywords)
                {
                    list.Add(new SymbolInfo(keyword, SymbolType.KEYWORD));
                }

                keywordString = SciControl.Lexing.Keywords[LUA_PATTERN_SPECIAL_VARS_IDX];
                keywords      = keywordString.Split(' ');
                foreach (string keyword in keywords)
                {
                    if (!keyword.StartsWith("_"))
                    {
                        list.Add(new SymbolInfo(keyword, SymbolType.VARIABLE));
                    }
                }
            }

            if (list != null && list.Count > 0)
            {
                SciControl.AutoComplete.List.Clear();

                if (!_imagesRegistered)
                {
                    ImageList imageList = new ImageList();

                    imageList.Images.Add(Properties.Resources.lua_function);
                    imageList.Images.Add(Properties.Resources.lua_table);
                    imageList.Images.Add(Properties.Resources.lua_userdata);
                    imageList.Images.Add(Properties.Resources.lua_local);
                    imageList.Images.Add(Properties.Resources.lua_blank);

                    SciControl.AutoComplete.RegisterImages(imageList, Color.Black);

                    _imagesRegistered = true;
                }

                foreach (SymbolInfo symbol in list)
                {
                    int icoNum = 4;
                    switch (symbol._type)
                    {
                    case SymbolType.FUNCTION: icoNum = 0; break;

                    case SymbolType.VARIABLE: icoNum = 1; break;

                    case SymbolType.CLASS:    icoNum = 2; break;

                    case SymbolType.ENUM:     icoNum = 3; break;//currently we do not use enums...

                    default: break;
                    }

                    string name = symbol._name + "?" + icoNum;

                    //avoid duplicates
                    if (!SciControl.AutoComplete.List.Contains(name))
                    {
                        SciControl.AutoComplete.List.Add(name);
                    }
                }
                //insert a dummy if required (otherwise SciControl behaves strange)
                if (SciControl.AutoComplete.List.Count == 1)
                {
                    SciControl.AutoComplete.List.Add("?4"); //insert a blank fake item
                    SciControl.AutoComplete.SelectedIndex = 0;
                }
                else
                {
                    SciControl.AutoComplete.List.Sort();

                    //highlight the best match in list
                    if (offset > 0)
                    {
                        SciControl.AutoComplete.SelectedText = SciControl.GetWordFromPosition(caret.Position - 2);
                    }
                    else
                    {
                        SciControl.AutoComplete.SelectedIndex = 0;
                    }
                }

                //show auto complete box
                SciControl.AutoComplete.AutoHide = false;
                SciControl.AutoComplete.Show();
            }
        }
Beispiel #6
0
 void Initialize(CaretInfo info, bool hasFocus)
 {
     if (info.Rect == null) {
         info.Geometry = null;
         info.BlinkHiddenGeometry = null;
     }
     else {
         var rect = info.Rect.Value;
         if (!hasFocus) {
             double height = Math.Min(rect.Height, 2.0);
             rect = new Rect(rect.X, rect.Y + rect.Height - height, rect.Width, height);
         }
         info.Geometry = new RectangleGeometry(new Rect(rect.X - horizOffset, rect.Y, rect.Width, rect.Height));
         info.Geometry.Freeze();
         info.BlinkHiddenGeometry = hasFocus ? null : info.Geometry;
     }
 }