using System.Collections.Generic;
using System.Reflection;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using System.Windows;
using System.Windows.Shapes;
using System.Windows.Media;
using System.Windows.Input;
using System.Linq;
using System.Diagnostics;
using System;
using System.Collections.ObjectModel;
using System.Collections;
using System.ComponentModel;
using System.Windows.Data;
using Microsoft.Research.DynamicDataDisplay.Charts.Navigation;
namespace Microsoft.Research.DynamicDataDisplay.Navigation
{
///
/// Is responsible for displaying and populating default context menu of ChartPlotter
///
public class DefaultContextMenu : IPlotterElement
{
private static readonly BitmapImage helpIcon;
private static readonly BitmapImage copyScreenshotIcon;
private static readonly BitmapImage saveScreenshotIcon;
private static readonly BitmapImage fitToViewIcon;
static DefaultContextMenu()
{
helpIcon = LoadIcon("HelpIcon");
saveScreenshotIcon = LoadIcon("SaveIcon");
copyScreenshotIcon = LoadIcon("CopyScreenshotIcon");
fitToViewIcon = LoadIcon("FitToViewIcon");
}
private static BitmapImage LoadIcon(string name)
{
Assembly currentAssembly = typeof(DefaultContextMenu).Assembly;
BitmapImage icon = new BitmapImage();
icon.BeginInit();
icon.StreamSource = currentAssembly.GetManifestResourceStream("Microsoft.Research.DynamicDataDisplay.Resources." + name + ".png");
icon.EndInit();
icon.Freeze();
return icon;
}
///
/// Initializes a new instance of the class.
///
public DefaultContextMenu() { }
protected ContextMenu PopulateContextMenu(Plotter target)
{
ContextMenu menu = new ContextMenu();
MenuItem fitToViewMenuItem = new MenuItem
{
Header = Strings.UIResources.ContextMenuFitToView,
ToolTip = Strings.UIResources.ContextMenuFitToViewTooltip,
Icon = new Image { Source = fitToViewIcon },
Command = ChartCommands.FitToView,
CommandTarget = target
};
MenuItem savePictureMenuItem = new MenuItem
{
Header = Strings.UIResources.ContextMenuSaveScreenshot,
ToolTip = Strings.UIResources.ContextMenuSaveScreenshotTooltip,
Icon = new Image { Source = saveScreenshotIcon },
Command = ChartCommands.SaveScreenshot,
CommandTarget = target
};
MenuItem copyPictureMenuItem = new MenuItem
{
Header = Strings.UIResources.ContextMenuCopyScreenshot,
ToolTip = Strings.UIResources.ContextMenuCopyScreenshotTooltip,
Icon = new Image { Source = copyScreenshotIcon },
Command = ChartCommands.CopyScreenshot,
CommandTarget = target
};
MenuItem quickHelpMenuItem = new MenuItem
{
Header = Strings.UIResources.ContextMenuQuickHelp,
ToolTip = Strings.UIResources.ContextMenuQuickHelpTooltip,
Command = ChartCommands.ShowHelp,
Icon = new Image { Source = helpIcon },
CommandTarget = target
};
MenuItem reportFeedback = new MenuItem
{
Header = Strings.UIResources.ContextMenuReportFeedback,
ToolTip = Strings.UIResources.ContextMenuReportFeedbackTooltip,
Icon = (Image)plotter.Resources["SendFeedbackIcon"]
};
reportFeedback.Click += reportFeedback_Click;
staticMenuItems.Add(fitToViewMenuItem);
staticMenuItems.Add(copyPictureMenuItem);
staticMenuItems.Add(savePictureMenuItem);
staticMenuItems.Add(quickHelpMenuItem);
//staticMenuItems.Add(reportFeedback);
menu.ItemsSource = staticMenuItems;
return menu;
}
private void reportFeedback_Click(object sender, RoutedEventArgs e)
{
try
{
using (Process.Start("mailto:" + Strings.UIResources.SendFeedbackEmail + "?Subject=[D3]%20" + typeof(DefaultContextMenu).Assembly.GetName().Version)) { }
}
catch (Exception)
{
MessageBox.Show(Strings.UIResources.SendFeedbackError + Strings.UIResources.SendFeedbackEmail, "Error while sending feedback", MessageBoxButton.OK, MessageBoxImage.Information);
}
}
private readonly ObservableCollection