Added Copy item to the actions drop down on the Events page. Aesthetic: made the

actions split button look more like a button.

Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
Konstantina Chremmou 2013-12-10 11:29:31 +00:00
parent d2cb9298cb
commit bae0d9ab8f
5 changed files with 188 additions and 26 deletions

View File

@ -31,12 +31,14 @@
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace XenAdmin.Controls
{
public class DataGridViewDropDownSplitButtonCell : DataGridViewTextBoxCell
{
private bool active;
private bool disposed;
private ToolStripItem _defaultItem;
@ -56,7 +58,12 @@ namespace XenAdmin.Controls
/// </summary>
public const int MIN_ROW_HEIGHT = 22;
private bool active;
private static readonly Color BUTTON_BORDER_OUTER = Color.FromArgb(112, 112, 112);
private static readonly Color BUTTON_BORDER_INNER = Color.FromArgb(252, 252, 252);
private static readonly Color BUTTON_FACE_TOP = Color.FromArgb(242, 242, 242);
private static readonly Color BUTTON_FACE_MIDDLE_TOP = Color.FromArgb(235, 235, 235);
private static readonly Color BUTTON_FACE_MIDDLE_BOTTOM = Color.FromArgb(221, 221, 221);
private static readonly Color BUTTON_FACE_BOTTOM = Color.FromArgb(207, 207, 207);
public DataGridViewDropDownSplitButtonCell()
{
@ -123,28 +130,95 @@ namespace XenAdmin.Controls
cellStyle.Alignment = DataGridViewContentAlignment.TopLeft;
base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
if (active)
using (Pen pen = new Pen(SystemColors.ControlDarkDark, 1))
{
var mode = graphics.SmoothingMode;
graphics.SmoothingMode = SmoothingMode.AntiAlias;
var rec = new Rectangle(cellBounds.Left + cellStyle.Padding.Left,
cellBounds.Top + cellStyle.Padding.Top,
cellBounds.Width - cellStyle.Padding.Left - cellStyle.Padding.Right,
CELL_HEIGHT);
var innerRec = new Rectangle(rec.Location, rec.Size);
innerRec.Inflate(-1, -1);
using (GraphicsPath path = new GraphicsPath())
{
var rec = new Rectangle(cellBounds.Left + cellStyle.Padding.Left,
cellBounds.Top + cellStyle.Padding.Top,
cellBounds.Width - cellStyle.Padding.Left - cellStyle.Padding.Right,
CELL_HEIGHT);
int diameter = 4;
var arc = new Rectangle(rec.Location, new Size(diameter, diameter));
graphics.FillRectangle(SystemBrushes.Control, rec);
graphics.DrawRectangle(pen, rec);
//top left corner
path.AddArc(arc, 180, 90);
using (var font = new Font(DataGridView.DefaultCellStyle.Font, FontStyle.Regular))
graphics.DrawString(value as string, font, SystemBrushes.ControlText, cellBounds);
// top right corner
arc.X = rec.Right - diameter;
path.AddArc(arc, 270, 90);
graphics.DrawLine(pen,
cellBounds.Right - cellStyle.Padding.Right - SPLITTER_FROM_RIGHT,
cellBounds.Top + cellStyle.Padding.Top,
cellBounds.Right - cellStyle.Padding.Right - SPLITTER_FROM_RIGHT,
cellBounds.Top + cellStyle.Padding.Top + CELL_HEIGHT);
// bottom right corner
arc.Y = rec.Bottom - diameter;
path.AddArc(arc, 0, 90);
// bottom left corner
arc.X = rec.Left;
path.AddArc(arc, 90, 90);
path.CloseFigure();
using (var brush = new LinearGradientBrush(rec, BUTTON_FACE_TOP, BUTTON_FACE_BOTTOM, LinearGradientMode.Vertical))
{
ColorBlend cb = new ColorBlend();
cb.Positions = new[] { 0, 1 / 2f, 1 / 2f, 1 };
cb.Colors = new[] { BUTTON_FACE_TOP, BUTTON_FACE_MIDDLE_TOP, BUTTON_FACE_MIDDLE_BOTTOM, BUTTON_FACE_BOTTOM };
brush.InterpolationColors = cb;
graphics.FillPath(brush, path);
}
using (Pen pen = new Pen(BUTTON_BORDER_OUTER, 1))
graphics.DrawPath(pen, path);
}
using (GraphicsPath path = new GraphicsPath())
{
int diameter = 4;
var arc = new Rectangle(innerRec.Location, new Size(diameter, diameter));
//top left corner
path.AddArc(arc, 180, 90);
// top right corner
arc.X = innerRec.Right - diameter;
path.AddArc(arc, 270, 90);
// bottom right corner
arc.Y = innerRec.Bottom - diameter;
path.AddArc(arc, 0, 90);
// bottom left corner
arc.X = innerRec.Left;
path.AddArc(arc, 90, 90);
path.CloseFigure();
using (Pen pen = new Pen(BUTTON_BORDER_INNER, 1))
graphics.DrawPath(pen, path);
}
using (var font = new Font(DataGridView.DefaultCellStyle.Font, FontStyle.Regular))
graphics.DrawString(value as string, font, SystemBrushes.ControlText, cellBounds);
using (Pen pen = new Pen(BUTTON_BORDER_OUTER, 1))
graphics.DrawLine(pen,
cellBounds.Right - cellStyle.Padding.Right - SPLITTER_FROM_RIGHT,
cellBounds.Top + cellStyle.Padding.Top + 2,
cellBounds.Right - cellStyle.Padding.Right - SPLITTER_FROM_RIGHT,
cellBounds.Top + cellStyle.Padding.Top + CELL_HEIGHT - 2);
//reset graphics mode
graphics.SmoothingMode = mode;
}
var img = Properties.Resources.expanded_triangle;
graphics.DrawImage(img,
cellBounds.Right - cellStyle.Padding.Right - img.Width - (SPLITTER_FROM_RIGHT - img.Width) / 2,

View File

@ -54,26 +54,28 @@ namespace XenAdmin.Core
? Properties.Resources.tempCancel
: Properties.Resources._000_error_h32bit_16;
if (action.PercentComplete < 10)
if (action.PercentComplete < 9)
return Properties.Resources.usagebar_0;
if (action.PercentComplete < 20)
if (action.PercentComplete < 18)
return Properties.Resources.usagebar_1;
if (action.PercentComplete < 30)
if (action.PercentComplete < 27)
return Properties.Resources.usagebar_2;
if (action.PercentComplete < 40)
if (action.PercentComplete < 36)
return Properties.Resources.usagebar_3;
if (action.PercentComplete < 50)
if (action.PercentComplete < 45)
return Properties.Resources.usagebar_4;
if (action.PercentComplete < 60)
if (action.PercentComplete < 54)
return Properties.Resources.usagebar_5;
if (action.PercentComplete < 70)
if (action.PercentComplete < 63)
return Properties.Resources.usagebar_6;
if (action.PercentComplete < 80)
if (action.PercentComplete < 72)
return Properties.Resources.usagebar_7;
if (action.PercentComplete < 90)
if (action.PercentComplete < 81)
return Properties.Resources.usagebar_8;
if (action.PercentComplete < 90)
return Properties.Resources.usagebar_9;
return Properties.Resources.usagebar_9;
return Properties.Resources.usagebar_10;
}
internal static string GetDetails(this ActionBase action)
@ -172,6 +174,18 @@ namespace XenAdmin.Core
return hostUuids;
}
internal static string GetStatusString(this ActionBase action)
{
if (action.IsCompleted)
return action.Succeeded
? Messages.ACTION_STATUS_SUCCEEDED
: action.Exception is CancelledException
? Messages.ACTION_SYSTEM_STATUS_CANCELLED
: Messages.ACTION_STATUS_FAILED;
return Messages.ACTION_STATUS_IN_PROGRESS;
}
#region Comparison (just static non-extension) methods
/// <summary>

View File

@ -34,6 +34,7 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using XenAdmin.Actions;
@ -400,6 +401,8 @@ namespace XenAdmin.TabPages
private ToolStripMenuItem cancelItem = new ToolStripMenuItem(Messages.CANCEL);
private ToolStripMenuItem dismissItem = new ToolStripMenuItem(Messages.ALERT_DISMISS);
private ToolStripMenuItem goToItem = new ToolStripMenuItem(Messages.HISTORYPAGE_GOTO);
private ToolStripSeparator separatorItem = new ToolStripSeparator();
private ToolStripMenuItem copyItem = new ToolStripMenuItem(Messages.COPY);
public event Action<DataGridViewActionRow> DismissalRequested;
public event Action<IXenObject> GoToXenObjectRequested;
@ -414,6 +417,7 @@ namespace XenAdmin.TabPages
cancelItem.Click += ToolStripMenuItemCancel_Click;
dismissItem.Click += ToolStripMenuItemDismiss_Click;
goToItem.Click += ToolStripMenuItemGoTo_Click;
copyItem.Click += ToolStripMenuItemCopy_Click;
MinimumHeight = DataGridViewDropDownSplitButtonCell.MIN_ROW_HEIGHT;
Cells.AddRange(expanderCell, statusCell, messageCell, locationCell, dateCell, actionCell);
@ -433,6 +437,11 @@ namespace XenAdmin.TabPages
if (obj != null)
actionItems.Add(goToItem);
if (actionItems.Count > 0)
actionItems.Add(separatorItem);
actionItems.Add(copyItem);
actionCell.RefreshItems(actionItems.ToArray());
statusCell.Value = Action.GetImage();
@ -467,6 +476,23 @@ namespace XenAdmin.TabPages
if (GoToXenObjectRequested != null)
GoToXenObjectRequested(Action.GetRelevantXenObject());
}
private void ToolStripMenuItemCopy_Click(object sender, EventArgs e)
{
string text = string.Format("\"{0}\",\"{1}\",\"{2}\",\"{3}\"",
Action.GetStatusString(), messageCell.Value,
locationCell.Value, dateCell.Value);
try
{
Clipboard.SetText(text);
}
catch (Exception ex)
{
log.Error("Exception while trying to set clipboard text.", ex);
log.Error(ex, ex);
}
}
}
private class CustomToolStripRenderer : ToolStripProfessionalRenderer

View File

@ -1797,6 +1797,42 @@ namespace XenAdmin {
}
}
/// <summary>
/// Looks up a localized string similar to Canceled.
/// </summary>
public static string ACTION_STATUS_CANCELLED {
get {
return ResourceManager.GetString("ACTION_STATUS_CANCELLED", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Failed.
/// </summary>
public static string ACTION_STATUS_FAILED {
get {
return ResourceManager.GetString("ACTION_STATUS_FAILED", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to In Progress.
/// </summary>
public static string ACTION_STATUS_IN_PROGRESS {
get {
return ResourceManager.GetString("ACTION_STATUS_IN_PROGRESS", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Succeeded.
/// </summary>
public static string ACTION_STATUS_SUCCEEDED {
get {
return ResourceManager.GetString("ACTION_STATUS_SUCCEEDED", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Getting system status canceled.
/// </summary>

View File

@ -696,6 +696,18 @@
<data name="ACTION_START_VMS_AND_APPLIANCES_TITLE" xml:space="preserve">
<value>Start VMs and vApps</value>
</data>
<data name="ACTION_STATUS_CANCELLED" xml:space="preserve">
<value>Canceled</value>
</data>
<data name="ACTION_STATUS_FAILED" xml:space="preserve">
<value>Failed</value>
</data>
<data name="ACTION_STATUS_IN_PROGRESS" xml:space="preserve">
<value>In Progress</value>
</data>
<data name="ACTION_STATUS_SUCCEEDED" xml:space="preserve">
<value>Succeeded</value>
</data>
<data name="ACTION_SYSTEM_STATUS_CANCELLED" xml:space="preserve">
<value>Getting system status canceled</value>
</data>