From 32114f947f0d9df880adf4ae712fa9f169f5ee63 Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 27 Apr 2016 22:51:59 +0200 Subject: [PATCH] When saving textures, update the filename if type changes and vice-versa --- .../Dialogs/TextureSaveDialog.Designer.cs | 9 +++ .../Windows/Dialogs/TextureSaveDialog.cs | 76 ++++++++++++++----- .../Windows/Dialogs/TextureSaveDialog.resx | 45 +++++++++++ 3 files changed, 112 insertions(+), 18 deletions(-) diff --git a/renderdocui/Windows/Dialogs/TextureSaveDialog.Designer.cs b/renderdocui/Windows/Dialogs/TextureSaveDialog.Designer.cs index 519ed6dd7..78cba84ee 100644 --- a/renderdocui/Windows/Dialogs/TextureSaveDialog.Designer.cs +++ b/renderdocui/Windows/Dialogs/TextureSaveDialog.Designer.cs @@ -28,6 +28,7 @@ /// private void InitializeComponent() { + this.components = new System.ComponentModel.Container(); System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; System.Windows.Forms.GroupBox groupBox1; System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1; @@ -71,6 +72,7 @@ this.filename = new System.Windows.Forms.TextBox(); this.colorDialog = new System.Windows.Forms.ColorDialog(); this.saveTexDialog = new System.Windows.Forms.SaveFileDialog(); + this.typingTimer = new System.Windows.Forms.Timer(this.components); tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); groupBox1 = new System.Windows.Forms.GroupBox(); flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); @@ -603,6 +605,7 @@ this.filename.Name = "filename"; this.filename.Size = new System.Drawing.Size(322, 20); this.filename.TabIndex = 1; + this.filename.KeyUp += new System.Windows.Forms.KeyEventHandler(this.filename_KeyUp); // // browse // @@ -625,6 +628,11 @@ this.saveTexDialog.OverwritePrompt = false; this.saveTexDialog.Title = "Save Texture As"; // + // typingTimer + // + this.typingTimer.Interval = 200; + this.typingTimer.Tick += new System.EventHandler(this.typingTimer_Tick); + // // TextureSaveDialog // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -704,5 +712,6 @@ private System.Windows.Forms.CheckBox resolveSamples; private System.Windows.Forms.TextBox filename; private System.Windows.Forms.SaveFileDialog saveTexDialog; + private System.Windows.Forms.Timer typingTimer; } } \ No newline at end of file diff --git a/renderdocui/Windows/Dialogs/TextureSaveDialog.cs b/renderdocui/Windows/Dialogs/TextureSaveDialog.cs index 78cd9e641..d046033c0 100644 --- a/renderdocui/Windows/Dialogs/TextureSaveDialog.cs +++ b/renderdocui/Windows/Dialogs/TextureSaveDialog.cs @@ -184,6 +184,7 @@ namespace renderdocui.Windows.Dialogs exportAllMips.Enabled = false; oneMip.Checked = oneSlice.Checked = true; } + SetFilenameFromFiletype(); } private void jpegCompression_ValueChanged(object sender, EventArgs e) @@ -231,6 +232,49 @@ namespace renderdocui.Windows.Dialogs } } + private void SetFiletypeFromFilename() + { + try + { + string ext = Path.GetExtension(filename.Text).ToUpperInvariant().Substring(1); // trim . from extension + + foreach (var ft in (FileType[])Enum.GetValues(typeof(FileType))) + { + if (ft.ToString().ToUpperInvariant() == ext) + { + fileFormat.SelectedIndex = (int)ft; + break; + } + } + } + catch (ArgumentException) + { + // invalid path or similar + } + } + + private void SetFilenameFromFiletype() + { + try + { + string filenameExt = Path.GetExtension(filename.Text).ToLowerInvariant().Substring(1); // trim . from extension + + FileType[] types = (FileType[])Enum.GetValues(typeof(FileType)); + + string selectedExt = types[fileFormat.SelectedIndex].ToString().ToLowerInvariant(); + + if (selectedExt != filenameExt) + { + filename.Text = filename.Text.Substring(0, filename.Text.Length - filenameExt.Length); + filename.Text += selectedExt; + } + } + catch (ArgumentException) + { + // invalid path or similar + } + } + private void browse_Click(object sender, EventArgs e) { saveTexDialog.FilterIndex = fileFormat.SelectedIndex + 1; @@ -238,24 +282,7 @@ namespace renderdocui.Windows.Dialogs if (res == DialogResult.OK || res == DialogResult.Yes) { filename.Text = saveTexDialog.FileName; - - try - { - string ext = Path.GetExtension(filename.Text).ToUpperInvariant().Substring(1); // trim . from extension - - foreach (var ft in (FileType[])Enum.GetValues(typeof(FileType))) - { - if (ft.ToString().ToUpperInvariant() == ext) - { - fileFormat.SelectedIndex = (int)ft; - break; - } - } - } - catch (ArgumentException) - { - // invalid path or similar - } + SetFiletypeFromFilename(); } } @@ -525,5 +552,18 @@ namespace renderdocui.Windows.Dialogs sliceSelect.Enabled = oneSlice.Checked; recurse = false; } + + private void filename_KeyUp(object sender, KeyEventArgs e) + { + typingTimer.Enabled = true; + typingTimer.Stop(); + typingTimer.Start(); + } + + private void typingTimer_Tick(object sender, EventArgs e) + { + SetFiletypeFromFilename(); + typingTimer.Enabled = false; + } } } diff --git a/renderdocui/Windows/Dialogs/TextureSaveDialog.resx b/renderdocui/Windows/Dialogs/TextureSaveDialog.resx index f23e5fc9a..15746d37f 100644 --- a/renderdocui/Windows/Dialogs/TextureSaveDialog.resx +++ b/renderdocui/Windows/Dialogs/TextureSaveDialog.resx @@ -123,9 +123,27 @@ False + + False + + + False + + + False + False + + False + + + False + + + False + False @@ -138,6 +156,18 @@ False + + False + + + False + + + False + + + False + False @@ -150,9 +180,18 @@ False + + False + False + + False + + + False + False @@ -162,10 +201,16 @@ False + + False + 17, 17 124, 17 + + 247, 17 + \ No newline at end of file