예제 #1
0
        public bool Close()
        {
            if (this.IsDirty)
            {
                DialogResult result = MessageBox.Show("Do you want to save the changes?", StringTable.GetString("ApplicationName"), MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
                switch (result)
                {
                case DialogResult.Yes:
                    if (!this.Save())
                    {
                        return(false);
                    }
                    break;

                case DialogResult.Cancel:
                    return(false);

                case DialogResult.No:
                    return(true);
                }
            }

            return(true);
        }
예제 #2
0
        protected override void OnAfterLabelEdit(LabelEditEventArgs e)
        {
            base.OnAfterLabelEdit(e);

            ResourceItem item = (ResourceItem)this.Items[e.Item];

            bool hasChanged = true;

            if ((e.Label != null) && (this.ContainsName(e.Label)))
            {
                MessageBox.Show(this, "Resource \'" + e.Label + "\' already exists.", StringTable.GetString("ApplicationName"));
                item.BeginEdit();
                hasChanged = false;
            }

            if ((e.Label == null) && (this.ContainsName(item)))
            {
                MessageBox.Show(this, "Resource \'" + item.ResourceName + "\' already exists.", StringTable.GetString("ApplicationName"));
                item.BeginEdit();
                hasChanged = false;
            }

            if (hasChanged)
            {
                this.IsDirty = true;
            }
        }
예제 #3
0
        public bool Save(string fileName)
        {
            this.FileName = fileName;

            string fileExtension = Path.GetExtension(fileName).ToLower();

            switch (fileExtension)
            {
            case ".xml":
            case ".resx":
                try
                {
                    using (ResXResourceWriter writer = new ResXResourceWriter(fileName))
                    {
                        foreach (ResourceItem item in this.Items)
                        {
                            writer.AddResource(item.ResourceName, item.ResourceValue);
                        }
                        writer.Generate();
                    }
                }
                catch (Exception exception)
                {
                    MessageBox.Show(this, exception.Message, StringTable.GetString("ApplicationName"));
                    return(false);
                }
                break;

            case ".resources":
                try
                {
                    using (ResourceWriter writer = new ResourceWriter(fileName))
                    {
                        foreach (ResourceItem item in this.Items)
                        {
                            writer.AddResource(item.ResourceName, item.ResourceValue);
                        }
                        writer.Generate();
                    }
                }
                catch (Exception exception)
                {
                    MessageBox.Show(this, exception.Message, StringTable.GetString("ApplicationName"));
                    return(false);
                }
                break;

            case ".txt":
                try
                {
                    using (StreamWriter writer = new StreamWriter(fileName))
                    {
                        foreach (ResourceItem item in this.Items)
                        {
                            if ((item.ResourceValue != null) && (item.ResourceValue is String))
                            {
                                writer.Write(item.ResourceName);
                                writer.Write("=");
                                writer.Write(item.ResourceValue);
                                writer.WriteLine();
                            }
                            else
                            {
                                MessageBox.Show(this, "Resource \'" + item.ResourceName + "\' cannot be saved as a text resource.", StringTable.GetString("ApplicationName"));
                            }
                        }
                    }
                }
                catch (Exception exception)
                {
                    MessageBox.Show(this, exception.Message, StringTable.GetString("ApplicationName"));
                    return(false);
                }
                break;

            default:
                MessageBox.Show(this, "Unknown resource file format.", StringTable.GetString("ApplicationName"));
                return(false);
            }

            this.IsDirty = false;
            return(true);
        }
예제 #4
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"));
                    }
                }
            }
        }
예제 #5
0
        public void Load(string fileName)
        {
            this.New();

            this.FileName = fileName;
            string fileExtension = Path.GetExtension(fileName).ToLower();

            try
            {
                switch (fileExtension)
                {
                case ".xml":
                case ".resx":
                    using (ResXResourceReader reader = new ResXResourceReader(fileName))
                    {
                        this.BeginUpdate();

                        Hashtable             resources  = new Hashtable();
                        IDictionaryEnumerator enumerator = reader.GetEnumerator();
                        while (enumerator.MoveNext())
                        {
                            string name  = (string)enumerator.Key;
                            object value = enumerator.Value;
                            if (!resources.Contains(name))
                            {
                                this.AddResource(name, value);
                                resources.Add(name, value);
                            }
                        }

                        this.EndUpdate();
                    }
                    break;

                case ".resources":
                    using (FileStream stream = File.OpenRead(fileName))
                    {
                        this.BeginUpdate();

                        using (ResourceReader reader = new ResourceReader(stream))
                        {
                            Hashtable             resources  = new Hashtable();
                            IDictionaryEnumerator enumerator = reader.GetEnumerator();

                            while (enumerator.MoveNext())
                            {
                                string name  = (string)enumerator.Key;
                                object value = enumerator.Value;

                                if (!resources.Contains(name))
                                {
                                    this.AddResource(name, value);
                                    resources.Add(name, value);
                                }
                            }
                        }

                        this.EndUpdate();
                    }
                    break;

                case ".txt":
                    using (StreamReader reader = File.OpenText(fileName))
                    {
                        this.BeginUpdate();

                        Hashtable resources = new Hashtable();
                        while (reader.Peek() != -1)
                        {
                            string line = reader.ReadLine();
                            line = line.TrimStart();
                            if (!line.StartsWith(";"))
                            {
                                int index = line.IndexOf("=");
                                if (index != -1)
                                {
                                    string name  = line.Substring(0, index);
                                    string value = line.Substring(index + 1);
                                    name = name.Trim();
                                    if (!resources.Contains(name))
                                    {
                                        this.AddResource(name, value);
                                        resources.Add(name, value);
                                    }
                                }
                            }
                        }

                        this.EndUpdate();
                    }
                    break;


                default:
                    MessageBox.Show(this, "Unknown resource file format.", StringTable.GetString("ApplicationName"));
                    break;
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.ToString());
            }


            this.IsDirty = false;
        }