Exemplo n.º 1
0
        private void SaveLoad(bool save, EFlags flags)
        {
            ProgressReporter prog = ProgressReporter.GetEmpty(); // too fast to warrent dialogue

            if (flags.Has(EFlags.DoNotShowAgain))
            {
                XmlSettings.SaveLoad(save, FileId.DoNotShowAgain, ref this.DoNotShowAgain, null, prog);
            }
            if (flags.Has(EFlags.RecentSessions))
            {
                XmlSettings.SaveLoad(save, FileId.RecentSessions, ref this.RecentSessions, null, prog);
            }
            if (flags.Has(EFlags.RecentWorkspaces))
            {
                XmlSettings.SaveLoad(save, FileId.RecentWorkspaces, ref this.RecentWorkspaces, null, prog);
            }
            if (flags.Has(EFlags.General))
            {
                XmlSettings.SaveLoad(save, FileId.General, ref this.General, null, prog);
            }
            if (flags.Has(EFlags.FileLoadInfo))
            {
                XmlSettings.SaveLoad(save, FileId.FileLoadInfo, ref this.FileLoadInfo, null, prog);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Deserialises an object from <paramref name="stream"/>.
        /// The type will be constructed using <see cref="ReflectionHelper.Construct{T}"/>
        /// </summary>
        public static T Deserialise <T>(Stream stream, EFlags flags = EFlags.None)
        {
            T r = ReflectionHelper.Construct <T>();

            using (StreamReader sr = new StreamReader(stream))
            {
                while (!sr.EndOfStream)
                {
                    string l = sr.ReadLine();

                    string[] e = l.Split(new[] { '=' }, 2);

                    FieldInfo field = typeof(T).GetField(e[0]);

                    if (field == null)
                    {
                        if (flags.Has(EFlags.ErrorOnUnknownField))
                        {
                            throw new FormatException($"The INI deserialiser encountered a field {{{e[0]}}} but that field does not exist in the type {{{typeof(T).ToUiString()}}}. The file may have been saved using an older version of the software.");
                        }
                        else
                        {
                            continue;
                        }
                    }

                    object x = StringToObject(e[1], field.FieldType);

                    field.SetValue(r, x);
                }
            }

            return(r);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="box">Box to manage (mandatory)</param>
        /// <param name="editButton">Edit button (optional)</param>
        /// <param name="items">Items to populate with</param>
        /// <param name="includeNull">Whether to include an extra item for a "null" or empty selection.</param>
        public EditableComboBox([NotNull] ComboBox box, [CanBeNull] Button editButton, [NotNull] IDataSet items, EFlags flags)
        {
            this.ComboBox     = box;
            this._button      = editButton;
            this._includeNull = flags.Has(EFlags.IncludeNone) ? ENullItemName.RepresentingNone : flags.Has(EFlags.IncludeAll) ? ENullItemName.RepresentingAll : ENullItemName.NoNullItem;
            this._flags       = flags;
            this._config      = items;

            if (this._button != null)
            {
                this._button.Click += this._button_Click;
            }

            this.ComboBox.DrawMode              = DrawMode.OwnerDrawFixed;
            this.ComboBox.DrawItem             += this.ComboBox_DrawItem;
            this.ComboBox.DropDown             += this.ComboBox_DropDown; // Update on every drop-down in case something else modified the list
            this.ComboBox.SelectedIndexChanged += ComboBox_SelectedIndexChanged;
            this.UpdateItemsNoPreserve();                                 // Don't do this yet or we'll NRE if the caller has events on the combobox
        }
Exemplo n.º 4
0
        public void Bind(Control owner, CtlTitleBar titleBar, ToolTip toolTip, EFlags flags)
        {
            // DEFAULT
            _doNotShowAgainKey = owner.Name + ".context_help";

            // ICON
            this._errorProvider       = new ErrorProvider( );
            _errorProvider.Icon       = Icon.FromHandle(Resources.IconBarHelp.GetHicon());
            _errorProvider.BlinkStyle = ErrorBlinkStyle.NeverBlink;

            // SPLITTER
            this._splitter = new Splitter()
            {
                Visible   = _visible,
                Width     = 8,
                BackColor = System.Drawing.Color.Black,
                Dock      = DockStyle.Right,
            };

            _splitter.Paint += _splitter_Paint;

            owner.Controls.Add(_splitter);

            // HELP PANEL
            this._panel1 = new CtlContextHelpInner
            {
                Dock              = DockStyle.Right,
                Visible           = _visible,
                HandleFileFormats = flags.Has(EFlags.FileFormats),
                Size              = new Size(224, 0)
            };

            _panel1.CloseClicked += _panel1_CloseClicked;
            owner.Controls.Add(this._panel1);

            // TITLE BAR
            this._titleBar = titleBar;
            if (titleBar.HelpText != null)
            {
                _panel1.DefaultText = titleBar.HelpText + "\r\n\r\n" + _panel1.DefaultText;
                titleBar.HelpText   = null;
            }
            titleBar.HelpIcon     = CtlTitleBar.EHelpIcon.ShowBar;
            titleBar.HelpClicked += this.TitleBar_HelpClicked;

            // TOOL TIP
            this._toolTip = toolTip;

            if (toolTip != null)
            {
                toolTip.Active       = true;
                toolTip.InitialDelay = 2000;
                toolTip.Popup       += this.ToolTip_Popup;
            }

            // CONTROL BINDINGS
            foreach (Control control in FormHelper.EnumerateControls(owner))
            {
                if (control is CtlLabel)
                {
                    if (flags.Has(EFlags.HelpOnClick))
                    {
                        control.MouseEnter += this.Control_MouseEnter;
                        control.MouseLeave += this.Control_MouseLeave;
                        control.MouseDown  += this.Control_Click;
                        control.Cursor      = Cursors.Help;
                    }
                }
                else
                {
                    if (flags.Has(EFlags.HelpOnFocus))
                    {
                        control.GotFocus  += this.Control_Click;
                        control.MouseDown += this.Control_Click;
                    }
                }
            }

            // DEFAULT VISIBILITY
            Visible = !MainSettings.Instance.DoNotShowAgain.ContainsKey(_doNotShowAgainKey);
        }