コード例 #1
0
        public void btnPaletteCreate_Click(object sender, EventArgs e)
        {
            string name        = "";
            string description = "";
            string subTitle    = "";

            Palette.Purpose purpose = Palette.Purpose.Custom;
            bool            isFlow  = true;

            if (frmPaletteDetails.Display(ref name, ref description, ref subTitle, ref purpose, ref isFlow, false) != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }
            string display = Strings.Translate(description) + (!string.IsNullOrEmpty(subTitle) ? " (" + Strings.Translate(subTitle) + ")" : "");

            if (m_DisplayedPalettes.Any(d => d.PaletteEditingFullDescription == display))
            {
                MessageBox.Show(Strings.Item("Palette_DescriptionDuplicate"));
                return;
            }
            Document document = new Document(false)
            {
                ActivityID         = Activities.PaletteID,
                PaletteWithin      = m_Config,
                PaletteTitle       = name,
                PaletteDescription = description,
                PalettePurpose     = purpose,
                SnapMode           = Shape.SnapModes.Grid,
                SubTitle           = subTitle
            };

            document.PaletteDesignSize = new SizeF(60, 30);
            document.Page(0).SetSize(document.PaletteDesignSize, 0);
            document.Page(0).Paper = Paper.CreateNew(Paper.Papers.Graph, document.Page(0).Paper);
            document.Page(0).Paper.SetIntervals(1, 1, 10);
            if (isFlow)
            {
                Flow flow = new Flow()
                {
                    Direction = Flow.Directions.RightThenDown, ShapeSeparation = 1
                };
                flow.LineStyle.SetDefaults();
                flow.FillStyle.SetDefaults();
                flow.LineStyle.Colour = Color.Empty;
                flow.FillStyle.Colour = System.Drawing.Color.Empty;
                flow.SetBounds(document.Page(0).Bounds);
                document.Page(0).AddNew(flow, null);
            }

            m_Config.CustomPalettes.Add(document);
            Palette registration = new Palette(document);

            if (document.PalettePurpose.IsCustom)             // ensure new custom one shown
            {
                m_Config.Write(Config.ShowPaletteKey(registration), true.ToString());
            }
            WrittenToCurrent();
            Palette.Register(registration);
            Form.CloseAndEditPalette(document);
        }
コード例 #2
0
ファイル: AppliedConfig.cs プロジェクト: stuart2w/SAW
 public List <Palette> AvailablePalettesForPurpose(Palette.Purpose purpose)
 {
     // There is no index - it is probably just as efficient to do a flat search given the relatively small number
     if (m_AllPalettes == null)
     {
         CreatePaletteLists();
     }
     Debug.Assert(!purpose.IsCustom);             // This is perfectly possible, but it seems less likely that it is intended
     return(m_AllPalettes.Where(p => p.PalettePurpose.Equals(purpose)).ToList());
 }
コード例 #3
0
        /// <summary>Updates the parameters on OK</summary>
        /// <param name="purpose"></param>
        /// <param name="createFlow">Should be true on entry if creating; histrionics it if the box was ticked</param>
        /// <param name="isDuplicate">Should be true if we are duplicating an existing palette; disallows changing of the flow option, and updates the UI</param>
        /// <param name="title"></param>
        /// <param name="description"></param>
        /// <param name="subtitle"></param>
        public static DialogResult Display(ref string title, ref string description, ref string subtitle, ref Palette.Purpose purpose, ref bool createFlow, bool isDuplicate)
        {
            frmPaletteDetails form = new frmPaletteDetails();

            form.txtTitle.Text            = title;
            form.txtDescription.Text      = description;
            form.txtSubTitle.Text         = subtitle;
            form.cmbPurpose.SelectedValue = purpose.Parameter;
            Debug.Assert(!createFlow || !isDuplicate);             // partly because the 2 controls are on top of each other.  But also it makes no sense for both of these to be true
            form.chkFlow.Visible      = createFlow;
            form.lblDuplicate.Visible = isDuplicate;
            DialogResult result = form.ShowDialog();

            if (result == DialogResult.OK)
            {
                purpose     = new Palette.Purpose((int)form.cmbPurpose.SelectedValue);
                title       = form.txtTitle.Text;
                description = form.txtDescription.Text;
                subtitle    = form.txtSubTitle.Text;
                createFlow  = form.chkFlow.Checked;
            }
            return(result);
        }
コード例 #4
0
        public void btnPaletteRename_Click(object sender, EventArgs e)
        {
            Document palette = m_DisplayedPalettes[lstPalettes.SelectedIndex];

            Palette.Purpose oldPurpose  = palette.PalettePurpose;
            string          title       = palette.PaletteTitle;
            string          description = palette.PaletteDescription;
            bool            temp        = false;
            var             purpose     = palette.PalettePurpose;

            if (frmPaletteDetails.Display(ref title, ref description, ref palette.SubTitle, ref purpose, ref temp, false) == DialogResult.OK)
            {
                palette.PaletteTitle       = title;
                palette.PaletteDescription = description;
                if (!purpose.Equals(oldPurpose))
                {
                    palette.PalettePurpose       = purpose;
                    Form.m_PalettePurposeChanged = true;
                }
                OnDisplay();
                WrittenToCurrent();
            }
        }
コード例 #5
0
ファイル: AppliedConfig.cs プロジェクト: stuart2w/SAW
        /// <summary>returns the ID of the palette selected for the given purpose</summary>
        public string PaletteSelection(Palette.Purpose purpose, bool verify)
        {
            //
            // This is stored in the configuration, but we need to check for some special cases, such as if nothing is yet selected (must select something by default)
            // or if a palette has been selected and then later deleted.  Again it is essential that we return a valid palette, assuming there is one
            // But in the latter case, verification is difficult unless Palette.List matches this applied configuration.  This will be the case in the GUI
            // but not always in the editing.  Therefore the second parameter controls whether this check should be performed
            if (purpose.IsCustom)
            {
                throw new ArgumentException("AppliedConfig.PaletteSelection: purpose cannot be \'custom\'");
            }
            string key      = Config.SelectPaletteKey(purpose);
            string selected = this.ReadString(key);

            if (!string.IsNullOrEmpty(selected) && verify)
            {
                if (!Palette.List.ContainsKey(selected))
                {
                    Debug.WriteLine("Selected palette not available; selection reset for purpose: " + purpose.Name);
                    selected = "";
                }
            }
            if (String.IsNullOrEmpty(selected))
            {
                // nothing selected - find most appropriate palette
                Palette selectedPalette = null;
                foreach (Palette possible in AvailablePalettesForPurpose(purpose))
                {
                    if (string.IsNullOrEmpty(selected) || possible.UserDefined == false)
                    {
                        // Selects any palette, with built-in system ones having priority
                        selected        = possible.ID;
                        selectedPalette = possible;
                    }
                }
                if (!string.IsNullOrEmpty(selected))                 // Store the value back again; it is rather slow searching each time
                {
                    // find where it is defined
                    Config sourceConfig = null;
                    if (selectedPalette.UserDefined)
                    {
                        foreach (Config config in Configurations)
                        {
                            if (config.CustomPalettes.ContainsValue(selectedPalette.CustomDocument))
                            {
                                sourceConfig = config;
                            }
                        }
                    }
                    else
                    {
                        sourceConfig = Config.SystemConfig;                         // actually defined in S/W - can safely store in sys config
                        Config.SystemConfig.Write(key, selected);
                    }
                    if (sourceConfig != null)
                    {
                        sourceConfig.Write(key, selected);
                    }
                    else
                    {
                        Utilities.LogSubError("AppliedConfig.PaletteSelection: Failed to find place to write auto palette selection");
                    }
                }
            }
            return(selected);
        }