Example #1
0
        /// <summary>
        /// Show the pattern UI in a dialog.
        /// If 'patn' is not null, then it is edited in the UI, otherwise a new pattern is created.
        /// Returns the created/edited pattern</summary>
        public static Pattern ShowDialog(IWin32Window owner = null, Pattern patn = null)
        {
            var p = new PatternUI();

            using (var f = p.FormWrap <Form>(title: "Edit Pattern", start_pos: FormStartPosition.CenterParent))
            {
                patn = patn ?? new Pattern();
                p.EditPattern(patn);
                p.Commit += (s, a) => f.Close();
                f.ShowDialog(owner);
                return(p.Pattern);
            }
        }
Example #2
0
        /// <summary>Set up UI elements</summary>
        private void SetupUI()
        {
            // Detail button
            m_btn_patn_detail.BackgroundImage       = Resources.pencil2;
            m_btn_patn_detail.BackgroundImageLayout = ImageLayout.Stretch;
            m_btn_patn_detail.Click += (s, a) =>
            {
                // Show a modal form with the full pattern UI
                Pattern = PatternUI.ShowDialog(this, Pattern);
            };

            // Pattern expression combo
            m_cb_pattern.ValueType     = typeof(Pattern);
            m_cb_pattern.DisplayMember = nameof(Pattern.Expr);
            m_cb_pattern.ValidateText  = t =>
            {
                var patn = ((Pattern)m_cb_pattern.Value) ?? new Pattern(Pattern);
                patn.Expr = t;
                return(patn.IsValid);
            };
            m_cb_pattern.ValueToText = v =>
            {
                return(((Pattern)v)?.Expr ?? string.Empty);
            };
            m_cb_pattern.TextToValue = t =>
            {
                var patn = ((Pattern)m_cb_pattern.Value) ?? new Pattern(Pattern);
                patn.Expr = t;
                return(patn);
            };
            m_cb_pattern.ValueCommitted += (s, a) =>
            {
                Pattern = (Pattern)a.Value;
            };
            m_cb_pattern.Value = Pattern;
        }