/// /// Copyright © 2003-2008 JetBrains s.r.o. /// You may distribute under the terms of the GNU General Public License, as published by the Free Software Foundation, version 2 (see License.txt in the repository root folder). /// using System; using System.Drawing; using System.Windows.Forms; using JetBrains.Omea.GUIControls; using JetBrains.Omea.OpenAPI; using JetBrains.DataStructures; using JetBrains.Omea.ResourceTools; namespace JetBrains.Omea.CustomProperties { /** * Dialog for editing the custom properties of a resource. */ public class CustomPropertiesDlg : DialogBase { private System.Windows.Forms.Button _btnOK; private System.Windows.Forms.Button _btnCancel; private System.Windows.Forms.Panel _contentPane; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; private IResourceList _resources; private IntHashTable _propControls = new IntHashTable(); // prop ID -> ICustomPropertyEditor public CustomPropertiesDlg() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this._btnOK = new System.Windows.Forms.Button(); this._btnCancel = new System.Windows.Forms.Button(); this._contentPane = new System.Windows.Forms.Panel(); this.SuspendLayout(); // // _btnOK // this._btnOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this._btnOK.DialogResult = System.Windows.Forms.DialogResult.OK; this._btnOK.FlatStyle = System.Windows.Forms.FlatStyle.System; this._btnOK.Location = new System.Drawing.Point(124, 240); this._btnOK.Name = "_btnOK"; this._btnOK.TabIndex = 1; this._btnOK.Text = "OK"; // // _btnCancel // this._btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this._btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; this._btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System; this._btnCancel.Location = new System.Drawing.Point(208, 240); this._btnCancel.Name = "_btnCancel"; this._btnCancel.TabIndex = 2; this._btnCancel.Text = "Cancel"; // // _contentPane // this._contentPane.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this._contentPane.AutoScroll = true; this._contentPane.Location = new System.Drawing.Point(0, 0); this._contentPane.Name = "_contentPane"; this._contentPane.Size = new System.Drawing.Size(292, 232); this._contentPane.TabIndex = 0; // // CustomPropertiesDlg // this.AcceptButton = this._btnOK; this.AutoScaleBaseSize = new System.Drawing.Size(5, 14); this.CancelButton = this._btnCancel; this.ClientSize = new System.Drawing.Size(292, 271); this.Controls.Add(this._contentPane); this.Controls.Add(this._btnCancel); this.Controls.Add(this._btnOK); this.MinimumSize = new System.Drawing.Size(300, 305); this.Name = "CustomPropertiesDlg"; this.Text = "CustomPropertiesDlg"; this.ResumeLayout(false); } #endregion public void EditCustomProperties( IResourceList resList ) { _resources = resList; if ( resList.Count == 1 ) { Text = "Custom Properties: " + resList [0].DisplayName; } else { Text = "Custom Properties: " + resList.Count + " Resources"; } int curY = 4; int maxLength = 0; string longestName = ""; foreach( IPropType propType in ResourceTypeHelper.GetCustomPropTypes() ) { string curName; if ( propType.Name.StartsWith( "Custom." ) ) { curName = propType.Name.Substring( 7 ); } else { curName = propType.Name; } if ( curName.Length > maxLength ) { longestName = curName; maxLength = curName.Length; } } int valueX; using( Graphics g = CreateGraphics() ) { valueX = (int) g.MeasureString( longestName, Font ).Width + 16; } if ( valueX < 80 ) valueX = 80; Width = valueX + 136; foreach( IPropType propType in ResourceTypeHelper.GetCustomPropTypes() ) { bool valuesDiffer; object propValue = GetCustomPropValue( resList, propType.Id, out valuesDiffer ); CreateCustomPropControl( propType, propValue, valuesDiffer, valueX, ref curY ); } curY = Math.Min( curY, Screen.PrimaryScreen.Bounds.Height / 2 ); Height = curY + (Height - _contentPane.Height); if ( ShowDialog() == DialogResult.OK ) { Core.ResourceAP.RunJob( new MethodInvoker( SaveCustomProperties ) ); } } private object GetCustomPropValue( IResourceList resList, int propId, out bool valuesDiffer ) { object propValue = resList [0].GetProp( propId ); for( int i=1; i