diff --git a/WDBXEditor/Forms/LoadDefinition.Designer.cs b/WDBXEditor/Forms/LoadDefinition.Designer.cs index ef82d80..8fd5c7c 100644 --- a/WDBXEditor/Forms/LoadDefinition.Designer.cs +++ b/WDBXEditor/Forms/LoadDefinition.Designer.cs @@ -30,103 +30,116 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - this.lbDefinitions = new WDBXEditor.Common.BufferedListBox(); - this.btnClose = new System.Windows.Forms.Button(); - this.btnLoad = new System.Windows.Forms.Button(); - this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); - this.label3 = new System.Windows.Forms.Label(); - this.btnNewWindow = new System.Windows.Forms.Button(); - this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); - this.lblFiles = new System.Windows.Forms.Label(); - this.SuspendLayout(); - // - // lbDefinitions - // - this.lbDefinitions.FormattingEnabled = true; - this.lbDefinitions.Location = new System.Drawing.Point(12, 28); - this.lbDefinitions.Name = "lbDefinitions"; - this.lbDefinitions.Size = new System.Drawing.Size(260, 199); - this.lbDefinitions.TabIndex = 0; - this.lbDefinitions.SelectedValueChanged += new System.EventHandler(this.lbDefinitions_SelectedValueChanged); - this.lbDefinitions.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.lbDefinitions_MouseDoubleClick); - // - // btnClose - // - this.btnClose.Location = new System.Drawing.Point(197, 233); - this.btnClose.Name = "btnClose"; - this.btnClose.Size = new System.Drawing.Size(75, 23); - this.btnClose.TabIndex = 2; - this.btnClose.Text = "Close"; - this.btnClose.UseVisualStyleBackColor = true; - this.btnClose.Click += new System.EventHandler(this.btnClose_Click); - // - // btnLoad - // - this.btnLoad.Location = new System.Drawing.Point(116, 233); - this.btnLoad.Name = "btnLoad"; - this.btnLoad.Size = new System.Drawing.Size(75, 23); - this.btnLoad.TabIndex = 1; - this.btnLoad.Text = "Load"; - this.btnLoad.UseVisualStyleBackColor = true; - this.btnLoad.Click += new System.EventHandler(this.btnLoad_Click); - // - // openFileDialog - // - this.openFileDialog.Filter = "XML Files|*.xml"; - // - // label3 - // - this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(9, 9); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(193, 13); - this.label3.TabIndex = 11; - this.label3.Text = "Builds will be limited to available options"; - // - // btnNewWindow - // - this.btnNewWindow.Image = global::WDBXEditor.Properties.Resources.open_new; - this.btnNewWindow.Location = new System.Drawing.Point(12, 233); - this.btnNewWindow.Name = "btnNewWindow"; - this.btnNewWindow.Size = new System.Drawing.Size(29, 23); - this.btnNewWindow.TabIndex = 12; - this.toolTip1.SetToolTip(this.btnNewWindow, "Opens in a new instance of the program"); - this.btnNewWindow.UseVisualStyleBackColor = true; - this.btnNewWindow.Click += new System.EventHandler(this.btnNewWindow_Click); - // - // lblFiles - // - this.lblFiles.Location = new System.Drawing.Point(208, 9); - this.lblFiles.Name = "lblFiles"; - this.lblFiles.Size = new System.Drawing.Size(64, 13); - this.lblFiles.TabIndex = 13; - this.lblFiles.Text = "0 Files"; - this.lblFiles.TextAlign = System.Drawing.ContentAlignment.TopRight; - // - // LoadDefinition - // - this.AcceptButton = this.btnLoad; - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(284, 261); - this.Controls.Add(this.lblFiles); - this.Controls.Add(this.btnNewWindow); - this.Controls.Add(this.label3); - this.Controls.Add(this.btnLoad); - this.Controls.Add(this.btnClose); - this.Controls.Add(this.lbDefinitions); - this.MaximizeBox = false; - this.MaximumSize = new System.Drawing.Size(300, 300); - this.MinimizeBox = false; - this.MinimumSize = new System.Drawing.Size(300, 300); - this.Name = "LoadDefinition"; - this.ShowIcon = false; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; - this.Text = "Load Definition"; - this.Load += new System.EventHandler(this.LoadDefinition_Load); - this.ResumeLayout(false); - this.PerformLayout(); + this.components = new System.ComponentModel.Container(); + this.btnClose = new System.Windows.Forms.Button(); + this.btnLoad = new System.Windows.Forms.Button(); + this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); + this.label3 = new System.Windows.Forms.Label(); + this.btnNewWindow = new System.Windows.Forms.Button(); + this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); + this.lblFiles = new System.Windows.Forms.Label(); + this.chkBuildFilter = new System.Windows.Forms.CheckBox(); + this.lbDefinitions = new WDBXEditor.Common.BufferedListBox(); + this.SuspendLayout(); + // + // btnClose + // + this.btnClose.Location = new System.Drawing.Point(202, 233); + this.btnClose.Name = "btnClose"; + this.btnClose.Size = new System.Drawing.Size(75, 23); + this.btnClose.TabIndex = 2; + this.btnClose.Text = "Close"; + this.btnClose.UseVisualStyleBackColor = true; + this.btnClose.Click += new System.EventHandler(this.btnClose_Click); + // + // btnLoad + // + this.btnLoad.Location = new System.Drawing.Point(121, 233); + this.btnLoad.Name = "btnLoad"; + this.btnLoad.Size = new System.Drawing.Size(75, 23); + this.btnLoad.TabIndex = 1; + this.btnLoad.Text = "Load"; + this.btnLoad.UseVisualStyleBackColor = true; + this.btnLoad.Click += new System.EventHandler(this.btnLoad_Click); + // + // openFileDialog + // + this.openFileDialog.Filter = "XML Files|*.xml"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(9, 9); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(193, 13); + this.label3.TabIndex = 11; + this.label3.Text = "Builds will be limited to available options"; + // + // btnNewWindow + // + this.btnNewWindow.Image = global::WDBXEditor.Properties.Resources.open_new; + this.btnNewWindow.Location = new System.Drawing.Point(12, 233); + this.btnNewWindow.Name = "btnNewWindow"; + this.btnNewWindow.Size = new System.Drawing.Size(29, 23); + this.btnNewWindow.TabIndex = 12; + this.toolTip1.SetToolTip(this.btnNewWindow, "Opens in a new instance of the program"); + this.btnNewWindow.UseVisualStyleBackColor = true; + this.btnNewWindow.Click += new System.EventHandler(this.btnNewWindow_Click); + // + // lblFiles + // + this.lblFiles.Location = new System.Drawing.Point(212, 9); + this.lblFiles.Name = "lblFiles"; + this.lblFiles.Size = new System.Drawing.Size(64, 13); + this.lblFiles.TabIndex = 13; + this.lblFiles.Text = "0 Files"; + this.lblFiles.TextAlign = System.Drawing.ContentAlignment.TopRight; + // + // chkBuildFilter + // + this.chkBuildFilter.AutoSize = true; + this.chkBuildFilter.Location = new System.Drawing.Point(47, 237); + this.chkBuildFilter.Name = "chkBuildFilter"; + this.chkBuildFilter.Size = new System.Drawing.Size(68, 17); + this.chkBuildFilter.TabIndex = 14; + this.chkBuildFilter.Text = "All Builds"; + this.chkBuildFilter.UseVisualStyleBackColor = true; + this.chkBuildFilter.CheckedChanged += new System.EventHandler(this.chkBuildFilter_CheckedChanged); + // + // lbDefinitions + // + this.lbDefinitions.FormattingEnabled = true; + this.lbDefinitions.Location = new System.Drawing.Point(12, 28); + this.lbDefinitions.Name = "lbDefinitions"; + this.lbDefinitions.Size = new System.Drawing.Size(265, 199); + this.lbDefinitions.TabIndex = 0; + this.lbDefinitions.SelectedValueChanged += new System.EventHandler(this.lbDefinitions_SelectedValueChanged); + this.lbDefinitions.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.lbDefinitions_MouseDoubleClick); + // + // LoadDefinition + // + this.AcceptButton = this.btnLoad; + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(290, 261); + this.Controls.Add(this.chkBuildFilter); + this.Controls.Add(this.lblFiles); + this.Controls.Add(this.btnNewWindow); + this.Controls.Add(this.label3); + this.Controls.Add(this.btnLoad); + this.Controls.Add(this.btnClose); + this.Controls.Add(this.lbDefinitions); + this.MaximizeBox = false; + this.MaximumSize = new System.Drawing.Size(306, 300); + this.MinimizeBox = false; + this.MinimumSize = new System.Drawing.Size(306, 300); + this.Name = "LoadDefinition"; + this.ShowIcon = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Load Definition"; + this.Load += new System.EventHandler(this.LoadDefinition_Load); + this.ResumeLayout(false); + this.PerformLayout(); } @@ -140,5 +153,6 @@ private void InitializeComponent() private System.Windows.Forms.Button btnNewWindow; private System.Windows.Forms.ToolTip toolTip1; private System.Windows.Forms.Label lblFiles; - } + private System.Windows.Forms.CheckBox chkBuildFilter; + } } \ No newline at end of file diff --git a/WDBXEditor/Forms/LoadDefinition.cs b/WDBXEditor/Forms/LoadDefinition.cs index 5e619dd..fe2c5d1 100644 --- a/WDBXEditor/Forms/LoadDefinition.cs +++ b/WDBXEditor/Forms/LoadDefinition.cs @@ -75,7 +75,7 @@ private void lbDefinitions_MouseDoubleClick(object sender, MouseEventArgs e) } #endregion - private void LoadBuilds() + private void LoadBuilds(bool mostRecent = true) { if (Database.Definitions.Tables.Count == 0) { @@ -92,20 +92,24 @@ private void LoadBuilds() } //Get compatible builds only - bool db2 = Files.Any(x => Path.GetExtension(x).IndexOf("db2", IGNORECASE) >= 0); - bool adb = Files.Any(x => Path.GetExtension(x).IndexOf("adb", IGNORECASE) >= 0); + bool db2 = Files.Any(x => Path.GetExtension(x).IndexOf("db2", IGNORECASE) >= 0) || Files.Any(x => Path.GetExtension(x).IndexOf("adb", IGNORECASE) >= 0); var files = Files.Select(x => Path.GetFileNameWithoutExtension(x).ToLower()); - var datasource = Database.Definitions.Tables - .Where(x => files.Contains(x.Name.ToLower())) - .Select(x => new { Key = x.Build, Value = x.BuildText }) - .Distinct() - .OrderBy(x => x.Key); - //Filter out non DB2/ADB clients - if (db2 || adb) - datasource = datasource.Where(x => x.Key > (int)ExpansionFinalBuild.WotLK).OrderBy(x => x.Key); - - lbDefinitions.BeginUpdate(); + var datasource = Database.Definitions.Tables + .Where(x => files.Contains(x.Name.ToLower())) + .Select(x => new { Key = x.Build, Value = x.BuildText }) + .Distinct() + .Where(x => db2 ? x.Key > (int)ExpansionFinalBuild.WotLK : true); // filter out non DB2/ADB clients + + // filter to the latest build for each version + if (mostRecent) + datasource = datasource.GroupBy(x => x.Value.Split('(').First()).Select(x => x.Aggregate((a, b) => a.Key > b.Key ? a : b)); + + // order + datasource = datasource.OrderBy(x => x.Key); + + + lbDefinitions.BeginUpdate(); if (datasource.Count() == 0) { @@ -126,5 +130,10 @@ private void SetFileText() { lblFiles.Text = Files.Count() == 1 ? "1 file" : Files.Count() + " files"; } - } + + private void chkBuildFilter_CheckedChanged(object sender, EventArgs e) + { + LoadBuilds(!chkBuildFilter.Checked); + } + } }