//
// Copyright 2014 Perforce Software Inc.
//
using Perforce.Helper;
using Perforce.ViewModel;
using Microsoft.Win32;
using System.Collections.Generic;
using System.Windows;
namespace Perforce.View {
///
/// Interaction logic for HelperApplicationUtility.xaml
///
public partial class HelperApplicationUtility : Window {
private HelperApplicationUtilityViewModel _model;
public HelperApplicationUtility() {
InitializeComponent();
_model = new HelperApplicationUtilityViewModel();
this.DataContext = _model;
}
private void RemoveButton_Click(object sender, RoutedEventArgs e) {
int row = MappingsGrid.SelectedIndex;
if (row >= 0) {
_model.RemoveRow(row);
}
}
private void SaveButton_Click(object sender, RoutedEventArgs e) {
var mappingsDictionary = new Dictionary();
foreach (var m in _model.Mappings) {
if (!string.IsNullOrEmpty(m.Extension) && !string.IsNullOrEmpty(m.Application)) {
mappingsDictionary[m.Extension] = m.Application;
}
}
var helper = Utility.GetExtensionHelper();
helper.Mappings = mappingsDictionary;
helper.SaveMappings();
this.Close();
}
private void BrowseButton_Click(object sender, RoutedEventArgs e) {
int row = MappingsGrid.SelectedIndex;
OpenFileDialog ofd = new OpenFileDialog();
ofd.InitialDirectory = @"C:\Program Files";
ofd.Title = "Choose helper application...";
ofd.DefaultExt = ".exe";
ofd.Filter = "Application Files (*.exe)|*.exe";
ofd.Multiselect = false;
var result = ofd.ShowDialog();
if (result == true) {
_model.UpdateMapping(row, ofd.FileName);
MappingsGrid.CommitEdit();
MappingsGrid.Items.Refresh();
}
}
}
}