Esempio n. 1
0
        /// <summary>
        /// Adds menu items for all panels or toolbars, except the doc panel, to a menu.
        /// On menu item click will show that panel.
        /// </summary>
        public void ZAddShowPanelsToMenu(ToolStripDropDown m, bool toolbars, bool clear = false)
        {
            m.SuspendLayout();
            if (clear)
            {
                m.Items.Clear();
            }

            var a = _aPanel.FindAll(v => !v.HasDocument && (toolbars == v.HasToolbar));

            a.Sort((v1, v2) => v1.Name.CompareTo(v2.Name));
            foreach (var v in a)
            {
                var s = v.Text;
                if (!v.Visible)
                {
                    s += "  (hidden)";
                }
                m.Items.Add(s, v.Image, (unu, sed) => { v.Show(true); });
            }
            //add Reset...
            m.Items.Add(new ToolStripSeparator());
            (m.Items.Add("Reset...", null, (unu, sed) => {
                if (ZResetLayoutAfterRestart)
                {
                    ZResetLayoutAfterRestart = false;
                }
                else
                {
                    ZResetLayoutAfterRestart = ADialog.ShowOkCancel("Reset panel/toolbar layout", "After restarting this application.");
                }
            }) as ToolStripMenuItem).Checked = ZResetLayoutAfterRestart;

            m.ResumeLayout();
        }
Esempio n. 2
0
        private void UpdateDropdown()
        {
            if (m_dropDown == null)
            {
                return;
            }

            var tokens        = FindTokens().ToArray();
            var matchingToken = tokens.Where(t => t.Item1.Pos < GetCursorPosInt() && (t.Item2.Pos > GetCursorPosInt() || (Text[t.Item2.Pos - 1] != ']' && t.Item2.Pos == Text.Length))).FirstOrDefault();

            if (matchingToken != null)
            {
                if (!m_dropDownOpen)
                {
                    m_itemIndex      = -1;
                    m_dropDownWindow = 0;
                }

                m_suggestions = AutoCompleteSuggestions(Text.Substring(matchingToken.Item1.Pos + 1, GetCursorPosInt() - matchingToken.Item1.Pos - 1)).ToArray();
            }
            else
            {
                CloseDropdown();
                return;
            }

            m_dropDown.SuspendLayout();
            var width  = (int)Area.Width - 2;
            var height = m_dropDown.Font.Height + 4;

            m_dropDown.Items.Clear();
            m_dropDown.Items.Add(new UpArrowItem(width, () => { m_dropDownWindow--; UpdateDropdown(); }, true));
            if (m_dropDownWindow + WINDOW_SIZE > m_suggestions.Length)
            {
                m_dropDownWindow = m_suggestions.Length - WINDOW_SIZE;
            }
            if (m_dropDownWindow < 0)
            {
                m_dropDownWindow = 0;
            }
            var limited = m_suggestions.Skip(m_dropDownWindow).TakeUpTo(WINDOW_SIZE);

            foreach (var item in limited)
            {
                var itemitem = item;
                var element  = m_dropDown.Items.Add(item, null, (a, b) => { AutoCompleteTo(itemitem); });
                element.TextAlign = ContentAlignment.MiddleLeft;
                element.AutoSize  = false;
                element.Height    = height;
                element.Width     = width;
            }
            m_dropDown.Items.Add(new UpArrowItem(width, () => { m_dropDownWindow++; UpdateDropdown(); }, false));
            m_dropDown.AutoClose = false;

            if (m_dropDownWindow <= 0)
            {
                m_dropDown.Items[0].Visible = false;
            }
            if (m_dropDownWindow >= m_suggestions.Length - WINDOW_SIZE)
            {
                m_dropDown.Items.OfType <ToolStripItem>().Last().Visible = false;
            }

            m_dropDown.ResumeLayout();

            if (!m_dropDownOpen)
            {
                m_dropDown.Show(m_control.PointToScreen(new Point((int)Area.Left, (int)Area.Bottom)));
            }
        }