UltimateZoneBuilder/Source/Core/Controls/CommentEditor.cs
MaxED 0d4c2a8f32 UDMF: Added "Comment" tab to Edit Sector / Linedef / Thing forms.
Sectors, Linedefs, Things modes: comment icons for appropriate map elements with comments are now rendered in these modes. This can be disabled using either the new "Toggle Comments" action, "View -> Show Comments" menu item, or "Show Comments" button on the main toolbar.
2015-07-14 23:34:31 +00:00

135 lines
3.1 KiB
C#

#region ================== Copyright
/*
* Made by MaxED, mkay?
*/
#endregion
#region ================== Namespaces
using System;
using System.Drawing;
using System.Windows.Forms;
using CodeImp.DoomBuilder.Map;
using CodeImp.DoomBuilder.GZBuilder.Tools;
using CodeImp.DoomBuilder.Rendering;
#endregion
namespace CodeImp.DoomBuilder.Controls
{
public partial class CommentEditor : UserControl
{
#region ================== Variables
private const string DEFAULT_TEXT = "Click to enter a comment...";
private bool mixedvalues;
private int commenttype;
#endregion
#region ================== Constructor / Disposer
public CommentEditor()
{
InitializeComponent();
}
#endregion
#region ================== Methods
public void SetValues(UniFields fields, bool first)
{
if(mixedvalues) return;
string c = fields.GetValue("comment", string.Empty);
if(first)
{
textbox.Text = c;
}
else if(textbox.Text != c)
{
textbox.Clear();
mixedvalues = true;
}
}
public void FinishSetup()
{
if(mixedvalues) return;
if(string.IsNullOrEmpty(textbox.Text))
{
textbox.Text = DEFAULT_TEXT;
textbox.ForeColor = SystemColors.InactiveCaptionText;
radioButton1.Checked = true;
}
else if(textbox.Text.Length > 2)
{
string type = textbox.Text.Substring(0, 3);
int index = Array.IndexOf(CommentType.Types, type);
commenttype = (index > 0 ? index : 0);
if(commenttype > 0) textbox.Text = textbox.Text.TrimStart(type.ToCharArray());
// Isn't there a better way to do this?..
switch(commenttype)
{
case 0: radioButton1.Checked = true; break;
case 1: radioButton2.Checked = true; break;
case 2: radioButton3.Checked = true; break;
case 3: radioButton4.Checked = true; break;
case 4: radioButton5.Checked = true; break;
}
}
}
public void Apply(UniFields fields)
{
if(mixedvalues) return;
string text = (!string.IsNullOrEmpty(textbox.Text) && textbox.Text != DEFAULT_TEXT ? CommentType.Types[commenttype] + textbox.Text : String.Empty);
UDMFTools.SetString(fields, "comment", text, string.Empty);
}
#endregion
#region ================== Events
private void clear_Click(object sender, EventArgs e)
{
textbox.Text = DEFAULT_TEXT;
textbox.ForeColor = SystemColors.InactiveCaptionText;
mixedvalues = false;
}
private void textbox_Enter(object sender, EventArgs e)
{
if(textbox.Text == DEFAULT_TEXT)
{
textbox.Clear();
textbox.ForeColor = SystemColors.WindowText;
}
}
private void textbox_Leave(object sender, EventArgs e)
{
if(string.IsNullOrEmpty(textbox.Text) && !mixedvalues)
{
textbox.Text = DEFAULT_TEXT;
textbox.ForeColor = SystemColors.InactiveCaptionText;
}
}
private void textbox_TextChanged(object sender, EventArgs e)
{
mixedvalues = false;
}
private void radiobutton_CheckedChanged(object sender, EventArgs e)
{
commenttype = (int)((Control)sender).Tag;
}
#endregion
}
}