-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRenameProgressDialog.xaml.cs
More file actions
141 lines (122 loc) · 4.18 KB
/
RenameProgressDialog.xaml.cs
File metadata and controls
141 lines (122 loc) · 4.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;
using System.Windows.Media;
namespace CodingWithCalvin.ProjectRenamifier.Dialogs
{
public partial class RenameProgressDialog : Window
{
public ObservableCollection<ProgressStep> Steps { get; }
public RenameProgressDialog(string projectName)
{
InitializeComponent();
HeaderText.Text = $"Renaming '{projectName}'...";
Steps = new ObservableCollection<ProgressStep>
{
new ProgressStep("Analyzing project references"),
new ProgressStep("Capturing solution structure"),
new ProgressStep("Removing project from solution"),
new ProgressStep("Updating project file"),
new ProgressStep("Updating namespace declarations"),
new ProgressStep("Renaming project file"),
new ProgressStep("Renaming project directory"),
new ProgressStep("Updating project references"),
new ProgressStep("Re-adding project to solution"),
new ProgressStep("Updating using statements"),
new ProgressStep("Updating fully qualified references")
};
StepsList.ItemsSource = Steps;
}
public void StartStep(int stepIndex)
{
if (stepIndex >= 0 && stepIndex < Steps.Count)
{
Steps[stepIndex].Status = StepStatus.InProgress;
UpdateProgress(stepIndex);
}
}
public void CompleteStep(int stepIndex)
{
if (stepIndex >= 0 && stepIndex < Steps.Count)
{
Steps[stepIndex].Status = StepStatus.Completed;
UpdateProgress(stepIndex + 1);
}
}
public void FailStep(int stepIndex, string error)
{
if (stepIndex >= 0 && stepIndex < Steps.Count)
{
Steps[stepIndex].Status = StepStatus.Failed;
Steps[stepIndex].Description += $" - {error}";
}
}
public void Complete()
{
HeaderText.Text = "Rename completed successfully!";
ProgressBar.Value = 100;
}
private void UpdateProgress(int completedSteps)
{
ProgressBar.Value = (completedSteps * 100.0) / Steps.Count;
}
}
public enum StepStatus
{
Pending,
InProgress,
Completed,
Failed
}
public class ProgressStep : INotifyPropertyChanged
{
private string _description;
private StepStatus _status;
public ProgressStep(string description)
{
_description = description;
_status = StepStatus.Pending;
}
public string Description
{
get => _description;
set
{
_description = value;
OnPropertyChanged(nameof(Description));
}
}
public StepStatus Status
{
get => _status;
set
{
_status = value;
OnPropertyChanged(nameof(Status));
OnPropertyChanged(nameof(StatusIcon));
OnPropertyChanged(nameof(TextColor));
}
}
public string StatusIcon => _status switch
{
StepStatus.Pending => "\u2022", // Bullet
StepStatus.InProgress => "\u25B6", // Play arrow
StepStatus.Completed => "\u2714", // Check mark
StepStatus.Failed => "\u2716", // X mark
_ => "\u2022"
};
public Brush TextColor => _status switch
{
StepStatus.Pending => Brushes.Gray,
StepStatus.InProgress => Brushes.Black,
StepStatus.Completed => Brushes.Green,
StepStatus.Failed => Brushes.Red,
_ => Brushes.Gray
};
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}