Exemplo n.º 1
0
        public void Paste()
        {
            IDataObject dataObject = Clipboard.GetDataObject();

            if (dataObject.GetDataPresent(typeof(Hashtable).FullName))
            {
                Hashtable dictionary = (Hashtable)dataObject.GetData(typeof(Hashtable));

                foreach (DictionaryEntry n in dictionary)
                {
                    if (!this.ContainsName((string)n.Key))
                    {
                        ICloneable   cloneable = (ICloneable)n.Value;
                        object       value     = cloneable.Clone();
                        ResourceItem item      = this.AddResource((string)n.Key, value);
                        item.Selected = true;
                    }
                    else
                    {
                        MessageBox.Show(this, "Resource \'" + n.Key + "\' already exists.", StringTable.GetString("ApplicationName"));
                    }
                }
            }
        }
Exemplo n.º 2
0
        private bool ContainsName(ResourceItem item)
        {
            foreach (ResourceItem currentItem in this.Items)
            {
                if ((item.ResourceName == currentItem.ResourceName) && (item != currentItem))
                {
                    return true;
                }
            }

            return false;
        }
Exemplo n.º 3
0
 private ResourceItem AddResource(string name, object value)
 {
     ResourceItem item = new ResourceItem();
     this.Items.Add(item);
     item.ResourceBrowser = this;
     item.ResourceName = name;
     item.ResourceValue = value;
     return item;
 }
Exemplo n.º 4
0
        public void InsertFile(string fileName)
        {
            string fileExtension = Path.GetExtension(fileName).ToLower();

            object value = null;

            switch (fileExtension)
            {
            case "cur":
                value = new Cursor(fileName);
                break;

            case ".ico":
                value = new Icon(fileName);
                break;

            case ".bmp":
            case ".emf":
            case ".exif":
            case ".gif":
            case ".jpeg":
            case ".jpg":
            case ".png":
            case ".tif":
            case ".tiff":
            case ".wmf":
                value = new Bitmap(fileName);
                break;

            case ".txt":
            case ".xml":
            case ".xsl":
            case ".xsd":
            case ".css":
            case ".htm":
            case ".html":
            case ".asp":
            case ".aspx":
                using (StreamReader reader = File.OpenText(fileName))
                {
                    value = reader.ReadToEnd();
                }
                break;


            default:
                using (FileStream stream = File.OpenRead(fileName))
                {
                    byte[] buffer = new byte[stream.Length];
                    stream.Read(buffer, 0, buffer.Length);
                    value = buffer;
                }
                break;
            }

            if (value != null)
            {
                ResourceItem item = this.AddResource(Path.GetFileName(fileName), value);
                this.SelectedItems.Clear();
                item.Selected = true;
            }
        }