Skip to content

Commit 5a1d480

Browse files
committed
Merge branch 'next' into SourceControlTweaks
2 parents 20041ef + 5467480 commit 5a1d480

File tree

4 files changed

+136
-51
lines changed

4 files changed

+136
-51
lines changed

RetailCoder.VBE/App.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public App(VBE vbe, IMessageBox messageBox,
7474
_panelVM.OpenRepoStarted += DisableSinkEventHandlers;
7575
_panelVM.OpenRepoCompleted += EnableSinkEventHandlersAndUpdateCache;
7676

77-
_branchesVM.MergeStarted += DisableSinkEventHandlers;
78-
_branchesVM.MergeCompleted += EnableSinkEventHandlersAndUpdateCache;
77+
_branchesVM.LoadingComponentsStarted += DisableSinkEventHandlers;
78+
_branchesVM.LoadingComponentsCompleted += EnableSinkEventHandlersAndUpdateCache;
7979

8080
_hooks.MessageReceived += _hooks_MessageReceived;
8181
_configService.SettingsChanged += _configService_SettingsChanged;
@@ -462,8 +462,8 @@ public void Dispose()
462462

463463
if (_branchesVM != null)
464464
{
465-
_branchesVM.MergeStarted -= DisableSinkEventHandlers;
466-
_branchesVM.MergeCompleted -= EnableSinkEventHandlersAndUpdateCache;
465+
_branchesVM.LoadingComponentsStarted -= DisableSinkEventHandlers;
466+
_branchesVM.LoadingComponentsCompleted -= EnableSinkEventHandlersAndUpdateCache;
467467
}
468468

469469
if (_hooks != null)

RetailCoder.VBE/UI/SourceControl/BranchesView.xaml

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
xmlns:converters="clr-namespace:Rubberduck.UI.Settings.Converters"
88
mc:Ignorable="d"
99
Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=SourceControl_Branches}"
10+
Name="SourceControlBranchesTab"
1011
d:DesignHeight="450" d:DesignWidth="300"
1112
d:DataContext="{d:DesignInstance {x:Type sourceControl:BranchesViewViewModel}, IsDesignTimeCreatable=False}">
1213
<TabItem.Resources>
@@ -19,6 +20,46 @@
1920
<BooleanToVisibilityConverter x:Key="BoolToVisibility" />
2021
<converters:SelectedItemToBooleanConverter x:Key="HasSelectedItems"/>
2122

23+
<Style x:Key="PublishedBranchesContextMenu" TargetType="ListBox">
24+
<Setter Property="ContextMenu">
25+
<Setter.Value>
26+
<ContextMenu DataContext="{Binding DataContext, Source={x:Reference SourceControlBranchesTab}}">
27+
<MenuItem Command="{Binding UnpublishBranchToolbarButtonCommand}"
28+
CommandParameter="{Binding CurrentPublishedBranch}"
29+
Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=SourceControl_UnpublishBranchButton}">
30+
</MenuItem>
31+
<MenuItem Command="{Binding DeleteBranchToolbarButtonCommand}"
32+
CommandParameter="True"
33+
Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=SourceControl_DeleteButton}">
34+
<MenuItem.Icon>
35+
<Image Source="{StaticResource DeleteImage}" />
36+
</MenuItem.Icon>
37+
</MenuItem>
38+
</ContextMenu>
39+
</Setter.Value>
40+
</Setter>
41+
</Style>
42+
43+
<Style x:Key="UnpublishedBranchesContextMenu" TargetType="ListBox">
44+
<Setter Property="ContextMenu">
45+
<Setter.Value>
46+
<ContextMenu DataContext="{Binding DataContext, Source={x:Reference SourceControlBranchesTab}}">
47+
<MenuItem Command="{Binding PublishBranchToolbarButtonCommand}"
48+
CommandParameter="{Binding CurrentUnpublishedBranch}"
49+
Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=SourceControl_PublishBranchButton}">
50+
</MenuItem>
51+
<MenuItem Command="{Binding DeleteBranchToolbarButtonCommand}"
52+
CommandParameter="False"
53+
Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=SourceControl_DeleteButton}">
54+
<MenuItem.Icon>
55+
<Image Source="{StaticResource DeleteImage}" />
56+
</MenuItem.Icon>
57+
</MenuItem>
58+
</ContextMenu>
59+
</Setter.Value>
60+
</Setter>
61+
</Style>
62+
2263
<Style x:Key="FocusVisual">
2364
<Setter Property="Control.Template">
2465
<Setter.Value>
@@ -246,13 +287,11 @@
246287
<ToolBar Style="{DynamicResource ToolBarWithOverflowOnlyShowingWhenNeededStyle}"
247288
Background="Transparent">
248289
<Button Command="{Binding UnpublishBranchToolbarButtonCommand}"
249-
CommandParameter="{Binding ElementName=PublishedBranchList, Path=SelectedItem}"
250-
IsEnabled="{Binding ElementName=PublishedBranchList, Path=SelectedItem, Converter={StaticResource HasSelectedItems}}"
290+
CommandParameter="{Binding CurrentPublishedBranch}"
251291
Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=SourceControl_UnpublishBranchButton}"
252292
Height="22" />
253293
<Button Command="{Binding DeleteBranchToolbarButtonCommand}"
254-
CommandParameter="{Binding ElementName=PublishedBranchList, Path=SelectedItem}"
255-
IsEnabled="{Binding ElementName=PublishedBranchList, Path=SelectedItem, Converter={StaticResource HasSelectedItems}}"
294+
CommandParameter="True"
256295
Height="22">
257296
<StackPanel Orientation="Horizontal">
258297
<Image Source="{StaticResource DeleteImage}" />
@@ -263,10 +302,11 @@
263302
</Button>
264303
</ToolBar>
265304
</ToolBarTray>
266-
<ListBox Name="PublishedBranchList"
267-
Height="175"
305+
<ListBox Height="175"
268306
ItemContainerStyle="{StaticResource PrettyListBoxItem}"
269-
ItemsSource="{Binding PublishedBranches}" />
307+
ItemsSource="{Binding PublishedBranches}"
308+
SelectedItem="{Binding CurrentPublishedBranch, Mode=OneWayToSource}"
309+
Style="{StaticResource PublishedBranchesContextMenu}" />
270310
</DockPanel>
271311
</GroupBox>
272312

@@ -278,13 +318,11 @@
278318
<ToolBar Style="{DynamicResource ToolBarWithOverflowOnlyShowingWhenNeededStyle}"
279319
Background="Transparent">
280320
<Button Command="{Binding PublishBranchToolbarButtonCommand}"
281-
CommandParameter="{Binding ElementName=UnpublishedBranchList, Path=SelectedItem}"
282-
IsEnabled="{Binding ElementName=UnpublishedBranchList, Path=SelectedItem, Converter={StaticResource HasSelectedItems}}"
321+
CommandParameter="{Binding CurrentUnpublishedBranch}"
283322
Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=SourceControl_PublishBranchButton}"
284323
Height="22" />
285324
<Button Command="{Binding DeleteBranchToolbarButtonCommand}"
286-
CommandParameter="{Binding ElementName=UnpublishedBranchList, Path=SelectedItem}"
287-
IsEnabled="{Binding ElementName=UnpublishedBranchList, Path=SelectedItem, Converter={StaticResource HasSelectedItems}}"
325+
CommandParameter="False"
288326
Height="22">
289327
<StackPanel Orientation="Horizontal">
290328
<Image Source="{StaticResource DeleteImage}" />
@@ -295,10 +333,11 @@
295333
</Button>
296334
</ToolBar>
297335
</ToolBarTray>
298-
<ListBox Name="UnpublishedBranchList"
299-
Height="175"
336+
<ListBox Height="175"
300337
ItemContainerStyle="{StaticResource PrettyListBoxItem}"
301-
ItemsSource="{Binding UnpublishedBranches}" />
338+
ItemsSource="{Binding UnpublishedBranches}"
339+
SelectedItem="{Binding CurrentUnpublishedBranch, Mode=OneWayToSource}"
340+
Style="{StaticResource UnpublishedBranchesContextMenu}" />
302341
</DockPanel>
303342
</GroupBox>
304343
</StackPanel>

RetailCoder.VBE/UI/SourceControl/BranchesViewViewModel.cs

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ public BranchesViewViewModel()
2121
_mergeBranchesOkButtonCommand = new DelegateCommand(_ => MergeBranchOk(), _ => SourceBranch != DestinationBranch);
2222
_mergeBranchesCancelButtonCommand = new DelegateCommand(_ => MergeBranchCancel());
2323

24-
_deleteBranchToolbarButtonCommand = new DelegateCommand(branch => DeleteBranch((string)branch), branch => (string) branch != CurrentBranch);
25-
_publishBranchToolbarButtonCommand = new DelegateCommand(branch => PublishBranch((string) branch));
26-
_unpublishBranchToolbarButtonCommand = new DelegateCommand(branch => UnpublishBranch((string)branch));
24+
_deleteBranchToolbarButtonCommand =
25+
new DelegateCommand(isBranchPublished => DeleteBranch(bool.Parse((string) isBranchPublished)),
26+
isBranchPublished => CanDeleteBranch(bool.Parse((string)isBranchPublished)));
27+
28+
_publishBranchToolbarButtonCommand = new DelegateCommand(_ => PublishBranch(), _ => !string.IsNullOrEmpty(CurrentUnpublishedBranch));
29+
_unpublishBranchToolbarButtonCommand = new DelegateCommand(_ => UnpublishBranch(), _ => !string.IsNullOrEmpty(CurrentPublishedBranch));
2730
}
2831

2932
private ISourceControlProvider _provider;
@@ -107,16 +110,40 @@ public string CurrentBranch
107110

108111
try
109112
{
113+
OnLoadingComponentsStarted();
110114
Provider.Checkout(_currentBranch);
111115
}
112116
catch (SourceControlException ex)
113117
{
114118
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
115119
}
120+
OnLoadingComponentsCompleted();
116121
}
117122
}
118123
}
119124

125+
private string _currentPublishedBranch;
126+
public string CurrentPublishedBranch
127+
{
128+
get { return _currentPublishedBranch; }
129+
set
130+
{
131+
_currentPublishedBranch = value;
132+
OnPropertyChanged();
133+
}
134+
}
135+
136+
private string _currentUnpublishedBranch;
137+
public string CurrentUnpublishedBranch
138+
{
139+
get { return _currentUnpublishedBranch; }
140+
set
141+
{
142+
_currentUnpublishedBranch = value;
143+
OnPropertyChanged();
144+
}
145+
}
146+
120147
private bool _displayCreateBranchGrid;
121148
public bool DisplayCreateBranchGrid
122149
{
@@ -279,7 +306,7 @@ private void CreateBranchCancel()
279306

280307
private void MergeBranchOk()
281308
{
282-
OnMergeStarted();
309+
OnLoadingComponentsStarted();
283310

284311
try
285312
{
@@ -288,25 +315,25 @@ private void MergeBranchOk()
288315
catch (SourceControlException ex)
289316
{
290317
RaiseErrorEvent(ex.Message, ex.InnerException.Message, NotificationType.Error);
291-
OnMergeCompleted();
318+
OnLoadingComponentsCompleted();
292319
return;
293320
}
294321

295322
DisplayMergeBranchesGrid = false;
296323
RaiseErrorEvent(RubberduckUI.SourceControl_MergeStatus, string.Format(RubberduckUI.SourceControl_SuccessfulMerge, SourceBranch, DestinationBranch), NotificationType.Info);
297-
OnMergeCompleted();
324+
OnLoadingComponentsCompleted();
298325
}
299326

300327
private void MergeBranchCancel()
301328
{
302329
DisplayMergeBranchesGrid = false;
303330
}
304331

305-
private void DeleteBranch(string branch)
332+
private void DeleteBranch(bool isBranchPublished)
306333
{
307334
try
308335
{
309-
Provider.DeleteBranch(branch);
336+
Provider.DeleteBranch(isBranchPublished ? CurrentPublishedBranch : CurrentUnpublishedBranch);
310337
}
311338
catch (SourceControlException ex)
312339
{
@@ -316,11 +343,19 @@ private void DeleteBranch(string branch)
316343
RefreshView();
317344
}
318345

319-
private void PublishBranch(string branch)
346+
347+
private bool CanDeleteBranch(bool isBranchPublished)
348+
{
349+
return isBranchPublished
350+
? !string.IsNullOrEmpty(CurrentPublishedBranch) && CurrentPublishedBranch != CurrentBranch
351+
: !string.IsNullOrEmpty(CurrentUnpublishedBranch) && CurrentUnpublishedBranch != CurrentBranch;
352+
}
353+
354+
private void PublishBranch()
320355
{
321356
try
322357
{
323-
Provider.Publish(branch);
358+
Provider.Publish(CurrentUnpublishedBranch);
324359
}
325360
catch (SourceControlException ex)
326361
{
@@ -330,11 +365,11 @@ private void PublishBranch(string branch)
330365
RefreshView();
331366
}
332367

333-
private void UnpublishBranch(string branch)
368+
private void UnpublishBranch()
334369
{
335370
try
336371
{
337-
Provider.Unpublish(Provider.Branches.First(b => b.Name == branch).TrackingName);
372+
Provider.Unpublish(Provider.Branches.First(b => b.Name == CurrentPublishedBranch).TrackingName);
338373
}
339374
catch (SourceControlException ex)
340375
{
@@ -429,20 +464,20 @@ private void RaiseErrorEvent(string message, string innerMessage, NotificationTy
429464
}
430465
}
431466

432-
public event EventHandler<EventArgs> MergeStarted;
433-
private void OnMergeStarted()
467+
public event EventHandler<EventArgs> LoadingComponentsStarted;
468+
private void OnLoadingComponentsStarted()
434469
{
435-
var handler = MergeStarted;
470+
var handler = LoadingComponentsStarted;
436471
if (handler != null)
437472
{
438473
handler(this, EventArgs.Empty);
439474
}
440475
}
441476

442-
public event EventHandler<EventArgs> MergeCompleted;
443-
private void OnMergeCompleted()
477+
public event EventHandler<EventArgs> LoadingComponentsCompleted;
478+
private void OnLoadingComponentsCompleted()
444479
{
445-
var handler = MergeCompleted;
480+
var handler = LoadingComponentsCompleted;
446481
if (handler != null)
447482
{
448483
handler(this, EventArgs.Empty);

0 commit comments

Comments
 (0)