Esempio n. 1
0
        public void AddMacro(
            String InMacro,
            IRichTextObject InReplacement)
        {
            if ((InMacro == null) || (InReplacement == null))
                throw new ArgumentNullException();

            if (InMacro.Length < 2)
                throw new ArgumentException("At least two characters are required for a macro!");

            InMacro = InMacro.ToLower();

            for (int i = 0; i < RepList.Count; i++)
            {
                if (RepList[i].Macro.CompareTo(InMacro) == 0)
                {
                    RepList[i].Element = InReplacement;

                    return;
                }

                if (RepList[i].Macro.StartsWith(InMacro) || InMacro.StartsWith(RepList[i].Macro))
                    throw new ArgumentException("The given macro conflicts with at least one existing macro.");
            }

            RepList.Add(new Replacement()
            {
                Macro = InMacro,
                Element = InReplacement,
            });

            m_MaxMacroLen = Math.Max(m_MaxMacroLen, InMacro.Length);
        }
Esempio n. 2
0
        public void InsertObject(IRichTextObject InObject)
        {
            InternalInsertFrameworkElement(InObject.IsFocusable, InObject, null, InObject.CreateInstance());

            Update();

            Select(CursorPosition.End, SelectionStart, 0);

            if (OnContentChanged != null)
                OnContentChanged(this);
        }
Esempio n. 3
0
        void InternalInsertFrameworkElement(
            Boolean InIsFocusable,
            IRichTextObject InRTO,
            String InMacro,
            FrameworkElement InElement)
        {
            if (InRTO != null)
            {
                Boolean Exists = false;

                for (int i = 0; i < m_RTOList.Count; i++)
                {
                    if (m_RTOList[i].GetTypeID() == InRTO.GetTypeID())
                    {
                        Exists = true;

                        break;
                    }
                }

                if(!Exists)
                    throw new KeyNotFoundException("The given rich text object is not registered in this editor.");
            }
            m_LastModification = DateTime.Now.Ticks;

            InElement.VerticalAlignment = VerticalAlignment.Top;
            InElement.HorizontalAlignment = HorizontalAlignment.Left;

            RemoveRange(SelectionStart, SelectionLength);

            // insert element
            LineItem Entry = new LineItem(this);

            Entry.Item = InElement;
            Entry.IsFocusable = InIsFocusable;
            Entry.RTO = InRTO;
            Entry.Macro = InMacro;

            LineItems.Insert(SelectionStart, Entry);

            if (InIsFocusable)
                m_Overlay.Children.Add(Entry);
            else
                m_Surface.Children.Add(Entry);

            InternalSelect(CursorPosition.End, SelectionStart + 1, 0);
        }