Beispiel #1
0
        private void okbutton_Click(object sender, EventArgs e)
        {
            if (!defaultimagecheckBox.Checked && imagelistView.SelectedIndices.Count == 0)
            {
                MessageBox.Show("You must select an image in the list view, or use the cancel button.", "No image selected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if (defaultimagecheckBox.Checked)
            {
                Settings.Sate.RemoveImageMapping(mappingName);
                Settings.Save();
            }
            else
            {
                ImageMapping im = new ImageMapping(mappingName,
                                                   imagelistView.SelectedItems[0].Tag as string,
                                                   applyToChildclassescheckBox.Checked);
                Settings.Sate.AddImageMapping(im);
                Settings.Save();
            }

            isDirty      = true;
            DialogResult = DialogResult.OK;
        }
        public void AddImageMapping(ImageMapping imageMapping)
        {
            //find if mapping already exists
            for (int i = 0; i < ImageMappings.Length; i++)
            {
                if (ImageMappings[i].MapObject == imageMapping.MapObject)
                {
                    ImageMappings[i] = imageMapping;
                    return;
                }
            }

            //no previous mapping existed, append new mapping
            ImageMapping[] im = new ImageMapping[ImageMappings.Length + 1];
            for (int i = 0; i < ImageMappings.Length; i++)
            {
                im[i] = ImageMappings[i];
            }
            im[im.Length - 1] = imageMapping;
            ImageMappings     = im;
        }
        public void RemoveImageAndMappings(string imagePath)
        {
            System.Collections.Generic.List <ImageMapping> list = new System.Collections.Generic.List <ImageMapping>();

            //collect remaining mappings
            for (int i = 0; i < ImageMappings.Length; i++)
            {
                if (ImageMappings[i].ImagePath != imagePath)
                {
                    list.Add(ImageMappings[i]);
                }
            }

            //convert to plain array
            ImageMapping[] tmp = new ImageMapping[list.Count];
            for (int i = 0; i < tmp.Length; i++)
            {
                tmp[i] = list[i];
            }

            ImageMappings = tmp;
        }
        public int GetImageIndex(long typeId, ImageType imageType)
        {
            int defaultIndex = -1;

            try
            {
                if (Settings.Sate.ImageMappings.Length > 0)
                {
                    ImageMapping found = null;

                    foreach (ImageMapping mapping in Settings.Sate.ImageMappings)
                    {
                        long mapTypeId;
                        bool isClass = System.Int64.TryParse(mapping.MapObject, out mapTypeId);

                        if (isClass)
                        {
                            if (mapTypeId == typeId)
                            {
                                found = mapping;
                                break;
                            }
                            else if (mapping.Inherit && Safir.Dob.Typesystem.Operations.IsOfType(typeId, mapTypeId))
                            {
                                if (found == null)
                                {
                                    found = mapping;
                                }
                                else
                                {
                                    System.Int64 foundTypeId;
                                    if (System.Int64.TryParse(found.MapObject, out foundTypeId))
                                    {
                                        if (Safir.Dob.Typesystem.Operations.IsOfType(foundTypeId, mapTypeId))
                                        {
                                            //closer ancestor to our type
                                            found = mapping;
                                        }
                                    }
                                    //note: namespace custom images always overrides class custom images
                                }
                            }
                        }
                        else //namespace
                        {
                            string typeName      = Safir.Dob.Typesystem.Operations.GetName(typeId);
                            string typeNamespace = typeName.Substring(0, typeName.LastIndexOf('.'));
                            if (typeNamespace == mapping.MapObject)
                            {
                                found = mapping;
                                break;
                            }
                            else if (mapping.Inherit && typeNamespace.StartsWith(mapping.MapObject))
                            {
                                if (found == null)
                                {
                                    found = mapping;
                                }
                                else
                                {
                                    System.Int64 foundTypeId;
                                    if (!System.Int64.TryParse(found.MapObject, out foundTypeId))
                                    {
                                        if (mapping.MapObject.StartsWith(found.MapObject))
                                        {
                                            //closer namespace to our type
                                            found = mapping;
                                        }
                                    }
                                    else
                                    {
                                        //note: namespace custom images always overrides class custom images
                                        found = mapping;
                                    }
                                }
                            }
                        }
                    }

                    if (found != null && PathIndexHt[found.ImagePath] != null)
                    {
                        defaultIndex = (int)PathIndexHt[found.ImagePath];
                    }
                }
            }
            catch { }

            //If no custom bitmap, use standard bitmaps
            if (defaultIndex < 0)
            {
                defaultIndex = GetStandardDefaultIndex(typeId);
            }

            return(ApplyImageType(defaultIndex, imageType));
        }