Exemplo n.º 1
0
 public static void InitializeHistory(TokenEdit tokenEdit)
 {
     foreach (Contact contact in DataHelper.Contacts)
     {
         TokenEditToken item = new TokenEditToken(contact.Email, contact);
         tokenEdit.Properties.Tokens.Add(item);
     }
 }
Exemplo n.º 2
0
 public TokenEditBinder(IPropertyBinderNotifier <TObjectType, IEnumerable <TValue> > propertyBinder, TokenEdit tokenEdit)
     : base(propertyBinder)
 {
     _tokenEdit                          = tokenEdit;
     _displayFor                         = x => x.ToString();
     _onSelectedItemChanged              = delegate { };
     _tokenEdit.SelectedItemsChanged    += selectedItemsChanged;
     _tokenEdit.Properties.EditValueType = TokenEditValueType.List;
 }
Exemplo n.º 3
0
 void DoUpdateTaskEmployees(TokenEdit edit, Task task)
 {
     task.ClearEmployees();
     foreach (int id in (IList)edit.EditValue)
     {
         Employee emp = EmployeesRegistry.GetEmployee(id);
         task.AddEmployee(emp);
     }
 }
Exemplo n.º 4
0
        private void FormatByDaxEditor()
        {
            int lineCont = _source.GetLineCount();

            for (int line = 0; line < lineCont; line++)
            {
                int         lineEnd   = 0;
                TokenInfo[] lineInfos = _source.GetColorizer().GetLineInfo(_source.GetTextLines(), line, _colorState);
                if (lineInfos != null)
                {
                    for (int i = 0; i < lineInfos.Length; i++)
                    {
                        // Store it for future usage
                        TokenInfo tokenInfo = lineInfos[i];
                        var       te        = new TokenEdit()
                        {
                            TokenInfo = tokenInfo
                        };
                        te.TextSpan = new TextSpan()
                        {
                            iStartLine = line, iStartIndex = tokenInfo.StartIndex, iEndLine = line, iEndIndex = tokenInfo.EndIndex + 1
                        };
                        lineEnd         = tokenInfo.EndIndex + 1;
                        te.OriginalText = _source.GetText(te.TextSpan);
                        if (te.TokenInfo.Token == (int)Tokens.LEX_ERROR)
                        {
                            te = ReplaceInvalidChars(te);
                        }
                        _tokenEdits.AddLast(te);
                    }
                }

                // Insert token for EOL
                var tokenInfoEOL = new TokenInfo()
                {
                    Type = TokenType.WhiteSpace
                };
                var teEOL = new TokenEdit()
                {
                    TokenInfo = tokenInfoEOL
                };
                teEOL.TextSpan = new TextSpan()
                {
                    iStartLine = line, iStartIndex = lineEnd, iEndLine = line + 1, iEndIndex = 0
                };
                teEOL.OriginalText = Environment.NewLine;
                _tokenEdits.AddLast(teEOL);
            }

            NormilizeWhitespaces();
            InsertEol();
            CheckHeadAndTail();

            ApplyEdits();
        }
Exemplo n.º 5
0
 void UpdateTaskEmployees(TokenEdit edit, Task task)
 {
     if (update)
     {
         return;
     }
     this.update = true;
     try {
         DoUpdateTaskEmployees(edit, task);
         gridView.UpdateCurrentRow();
     }
     finally {
         this.update = false;
     }
 }
Exemplo n.º 6
0
        void OnSelectedItemsChanged(object sender, ListChangedEventArgs e)
        {
            if (update)
            {
                return;
            }
            TokenEdit edit = sender as TokenEdit;

            if (edit == null)
            {
                return;
            }
            Employee emp = (Employee)gridView1.GetFocusedRow();

            UpdateTokens(edit, emp);
        }
Exemplo n.º 7
0
        void OnTokenEditSelectedItemsChanged(object sender, ListChangedEventArgs e)
        {
            if (update)
            {
                return;
            }
            TokenEdit edit = sender as TokenEdit;

            if (edit == null)
            {
                return;
            }
            Task task = (Task)gridView.GetFocusedRow();

            UpdateTaskEmployees(edit, task);
        }
Exemplo n.º 8
0
 void UpdateTokens(TokenEdit edit, Employee emp)
 {
     if (update)
     {
         return;
     }
     this.update = true;
     try {
         emp.Tokens.Clear();
         foreach (ObjectWrapper wr in (IList)edit.EditValue)
         {
             string tok = TokenRegistry.GetToken(wr.Obj);
             emp.Tokens.Add(tok);
         }
         gridView1.UpdateCurrentRow();
     }
     finally {
         this.update = false;
     }
 }
Exemplo n.º 9
0
        /// <summary>
        /// Replace invalid chars in DAX with valid.  Example '&npsp' with a space
        /// </summary>
        /// <param name="te">input token edit</param>
        /// <returns></returns>
        private TokenEdit ReplaceInvalidChars(TokenEdit te)
        {
            Debug.Assert(te.TokenInfo.Token == (int)Tokens.LEX_ERROR);
            switch (te.OriginalText)
            {
            case "–":     // dash
                te.TokenInfo.Token = (int)'-';
                te.TokenInfo.Type  = TokenType.Operator;
                te.EditSpan        = new EditSpan(te.TextSpan, "-");
                break;

            case " ":     // &nbsp
                te.TokenInfo.Token = (int)Tokens.LEX_WHITE;
                te.TokenInfo.Type  = TokenType.WhiteSpace;
                te.EditSpan        = new EditSpan(te.TextSpan, " ");
                break;
            }

            return(te);
        }
 public CustomTokenEdithandler(TokenEdit tokenEdit) : base(tokenEdit)
 {
 }
Exemplo n.º 11
0
 public TokenEditTokenListPopupControllerV2(TokenEdit edit)
     : base(edit)
 {
 }
Exemplo n.º 12
0
 public TokenEditHandlerV2(TokenEdit tokenEdit) : base(tokenEdit)
 {
 }
 public MyTokenEditPopupForm(TokenEdit tokenEdit)
     : base(tokenEdit)
 {
 }
Exemplo n.º 14
0
        /// <summary>
        /// Replaces any whitespace with ' '(=space) and insert a whitespace after every token (except comment)
        /// Also expand change token type for multi line comment.  It is required because Lexer does analyzis
        /// line by line and it does not have information that the current token might be a comment token.
        /// </summary>
        private void NormilizeWhitespaces()
        {
            var currentNode = _tokenEdits.First;

            while (currentNode != null)
            {
                var previous = currentNode.Previous;

                // Expand multi line comments
                // Lexer used in the callee function works line by line
                // So if it scans 2 lines /*\nabc\n the first line is a comment
                // but 'abc' on the second line is not a comment.
                // Fix it with this check
                if (previous != null && currentNode.Value.TokenInfo.Type != TokenType.Comment && previous.Value.TokenInfo.Type == TokenType.Comment && !string.Equals(previous.Value.OriginalText, @"*/"))
                {
                    currentNode.Value.TokenInfo.Type = TokenType.Comment;
                }

                switch (currentNode.Value.TokenInfo.Type)
                {
                case TokenType.LineComment:
                case TokenType.Comment:
                    break;

                case TokenType.Delimiter:
                case TokenType.Identifier:
                case TokenType.Keyword:
                case TokenType.Literal:
                case TokenType.Operator:
                case TokenType.String:
                case TokenType.Text:
                    // Insert whitespace before these tokens.  There are some exceptions - like there must be no whitespace between function and opening Parenthesis
                    if (previous != null)
                    {
                        if (previous.Value.TokenInfo.Type != TokenType.WhiteSpace)
                        {
                            // No whitespace between 2 identifiers
                            if (previous.Value.TokenInfo.Type == TokenType.Identifier && currentNode.Value.TokenInfo.Type == TokenType.Identifier)
                            {
                                break;
                            }
                            // No whitespaces before ';'
                            if (currentNode.Value.TokenInfo.Type == TokenType.Delimiter && string.Equals(currentNode.Value.OriginalText, ";"))
                            {
                                break;
                            }

                            var te = new TokenEdit();
                            te.TokenInfo = new TokenInfo()
                            {
                                Type = TokenType.WhiteSpace
                            };
                            te.TextSpan = new TextSpan()
                            {
                                iStartLine  = currentNode.Value.TextSpan.iStartLine,
                                iStartIndex = currentNode.Value.TextSpan.iStartIndex,
                                iEndLine    = currentNode.Value.TextSpan.iStartLine,
                                iEndIndex   = currentNode.Value.TextSpan.iStartIndex
                            };

                            te.EditSpan = new EditSpan(
                                te.TextSpan,
                                " ");

                            _tokenEdits.AddAfter(previous, te);
                            currentNode = previous;     // Need to walk at the currently added node.  Side effect - this block might be executed 2 times
                        }
                    }
                    break;

                case TokenType.Unknown:
                    Debug.Assert(false);
                    break;

                case TokenType.WhiteSpace:
                    TextSpan span;
                    string   newWhitespace = " ";
                    // Do not insert whitespace after comments
                    if (previous != null && (previous.Value.TokenInfo.Type == TokenType.LineComment || previous.Value.TokenInfo.Type == TokenType.Comment))
                    {
                        break;
                    }
                    // If previous token is a whitespace as well - merge their spans and remove the previos token
                    if (previous != null && previous.Value.TokenInfo.Type == TokenType.WhiteSpace)
                    {
                        if (previous.Previous != null && (previous.Previous.Value.TokenInfo.Type == TokenType.LineComment || previous.Previous.Value.TokenInfo.Type == TokenType.Comment))
                        {
                            break;
                        }
                        span.iStartLine  = previous.Value.TextSpan.iStartLine;
                        span.iStartIndex = previous.Value.TextSpan.iStartIndex;
                        span.iEndLine    = currentNode.Value.TextSpan.iEndLine;
                        span.iEndIndex   = currentNode.Value.TextSpan.iEndIndex;
                        _tokenEdits.Remove(previous);
                        previous = currentNode.Previous;
                    }
                    else
                    {
                        span = currentNode.Value.TextSpan;
                    }
                    // In serven cases whitespace needs to be removed or replaced with EOL
                    if (previous != null && currentNode.Next != null)
                    {
                        if (
                            // [cube].
                            (currentNode.Next.Value.TokenInfo.Type == TokenType.Delimiter && string.Equals(currentNode.Next.Value.OriginalText, "."))
                            // .[cube]
                            || (previous.Value.TokenInfo.Type == TokenType.Delimiter && string.Equals(previous.Value.OriginalText, "."))
                            // TableRef[ColRef]
                            || (previous.Value.TokenInfo.Type == TokenType.Identifier && currentNode.Next.Value.TokenInfo.Type == TokenType.Identifier)
                            // just before comma
                            || (currentNode.Next.Value.TokenInfo.Type == TokenType.Delimiter && string.Equals(currentNode.Next.Value.OriginalText, ","))
                            )
                        {
                            newWhitespace = "";
                        }
                        else if (previous.Value.TokenInfo.Type == TokenType.Keyword && string.Equals("evaluate", previous.Value.OriginalText, StringComparison.CurrentCultureIgnoreCase))
                        {
                            currentNode.Value.EolType = EolType.Eol;
                        }
                        else if (currentNode.Next.Value.TokenInfo.Type == TokenType.Keyword)
                        {
                            // Measure starts with a new line, 1 indent, only if the previous token is not CREATE
                            if (string.Equals("measure", currentNode.Next.Value.OriginalText, StringComparison.CurrentCultureIgnoreCase) &&
                                previous != null && !string.Equals("create", previous.Value.OriginalText, StringComparison.CurrentCultureIgnoreCase))
                            {
                                currentNode.Value.EolType = EolType.EolHardIndent1;
                                newWhitespace             = _eolText;
                            }
                            // EVALUATE, ORDER and CREATE always starts with a new line, 0 indent
                            else if (string.Equals("evaluate", currentNode.Next.Value.OriginalText, StringComparison.CurrentCultureIgnoreCase) ||
                                     string.Equals("order", currentNode.Next.Value.OriginalText, StringComparison.CurrentCultureIgnoreCase) ||
                                     string.Equals("create", currentNode.Next.Value.OriginalText, StringComparison.CurrentCultureIgnoreCase)
                                     )
                            {
                                newWhitespace             = _eolText;
                                currentNode.Value.EolType = EolType.Eol;
                            }
                        }
                    }


                    currentNode.Value.EditSpan = new EditSpan(span, newWhitespace);
                    currentNode.Value.TextSpan = span;
                    break;

                default:
                    break;
                }

                currentNode = currentNode.Next;
            }
        }
Exemplo n.º 15
0
        public static TokenEditBinder <TObjectType, TValue> To <TObjectType, TValue>(this IScreenToElementBinder <TObjectType, IEnumerable <TValue> > screenToElementBinder, TokenEdit tokenEditControl)
        {
            var element = new TokenEditBinder <TObjectType, TValue>(screenToElementBinder.PropertyBinder, tokenEditControl);

            screenToElementBinder.ScreenBinder.AddElement(element);
            return(element);
        }
Exemplo n.º 16
0
 public MyTokenEditTokenListPopupController(TokenEdit tokenEdit)
     : base(tokenEdit)
 {
 }
Exemplo n.º 17
0
 protected override object CreateControlCore()
 {
     control              = new TokenEdit();
     control.DoubleClick += Control_DoubleClick;
     return(control);
 }
Exemplo n.º 18
0
 public override void Initialize(TokenEdit ownerEdit, TokenEditPopupForm ownerPopup)
 {
     base.Initialize(ownerEdit, ownerPopup);
 }
Exemplo n.º 19
0
 public TokenEditPopupFormV2(TokenEdit edit)
     : base(edit)
 {
 }
 public MyTokenEditPopupForm(TokenEdit edit)
     : base(edit)
 {
 }
Exemplo n.º 21
0
 public static void InitializeSeparator(this TokenEdit tokenEdit, params string[] separators)
 {
     tokenEdit.Properties.Separators.Clear();
     tokenEdit.Properties.Separators.AddRange(separators);
 }
Exemplo n.º 22
0
 public static void Initialize(this TokenEdit tokenEdit)
 {
     tokenEdit.Properties.EditMode     = TokenEditMode.Manual;
     tokenEdit.Properties.ShowDropDown = true;
 }