//
// Copyright 2014 Perforce Software Inc.
//
using Perforce.Helper;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
namespace Perforce.View {
///
/// Interaction logic for FolderHistory.xaml
///
public partial class FolderHistory : UserControl {
private string _depotPath;
public FolderHistory(string depotPath) {
InitializeComponent();
var history = new List();
var helper = Utility.GetPerforceHelper();
var changes = helper.ListChanges(depotPath);
_depotPath = depotPath;
if (changes != null) {
foreach (var c in changes) {
history.Add(new FolderHistoryItem { Path = depotPath, Id = c.Id, ModifiedDate = c.ModifiedDate, Description = c.Description, User = c.OwnerName, Client = c.ClientId });
}
}
RevisionList.ItemsSource = history;
}
private void Rollback_Button_Click(object sender, RoutedEventArgs e) {
var item = RevisionList.SelectedItem as FolderHistoryItem;
var message = string.Format("Are you sure you want to rollback\n{0}\nto changelist @{1}?", item.Path, item.Id);
var main = App.Current.MainWindow as MainWindow;
var dialog = main.DialogManager.CreateMessageDialog(message, Technewlogic.WpfDialogManagement.DialogMode.OkCancel);
dialog.VerticalDialogAlignment = VerticalAlignment.Top;
dialog.Ok = () => { DoRollback(item); };
dialog.Cancel = RollbackCancelled;
dialog.Show();
}
private void DoRollback(FolderHistoryItem item) {
Utility.StopBackgroundProcesses();
var helper = Utility.GetPerforceHelper();
var main = App.Current.MainWindow as MainWindow;
var dialog = main.DialogManager.CreateWaitDialog("Rolling back...", "Rollback complete", Technewlogic.WpfDialogManagement.DialogMode.Ok);
dialog.VerticalDialogAlignment = System.Windows.VerticalAlignment.Top;
dialog.CanOk = false;
dialog.Show(() => {
string resultsMessage = string.Empty;
try {
var results = helper.RollbackFolderToChangelist(item.Path, item.Id);
if (results != null) {
resultsMessage = string.Format("{0}\nrolled back to changelist @{1}", item.Path, item.Id);
} else {
resultsMessage = string.Format("{0}\nNOT ROLLED BACK -- NO CHANGES", item.Path);
}
} catch (ApplicationException ae) {
resultsMessage = ae.Message;
}
dialog.ReadyMessage = resultsMessage;
dialog.CanOk = true;
Utility.StartBackgroundProcesses();
});
}
private void RollbackCancelled() {
UIHelper.ShowTimedMessage("Rollback cancelled", 0.5);
}
private void ShowFiles_Button_Click(object sender, RoutedEventArgs e) {
var item = RevisionList.SelectedItem as FolderHistoryItem;
var helper = Utility.GetPerforceHelper();
var change = helper.GetChangelist(item.Id);
if (change != null) {
var details = new ChangelistDetails(change);
details.ShowDialog();
}
}
}
public class FolderHistoryItem {
public string Path { get; set; }
public int Id { get; set; }
public DateTime ModifiedDate { get; set; }
public string Description { get; set; }
public string User { get; set; }
public string Client { get; set; }
}
}