Skip to content

Commit 39d5665

Browse files
committed
Close #351
1 parent 7ad4a9f commit 39d5665

File tree

2 files changed

+95
-23
lines changed

2 files changed

+95
-23
lines changed

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: 42 additions & 9 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;
@@ -119,6 +122,28 @@ public string CurrentBranch
119122
}
120123
}
121124

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+
122147
private bool _displayCreateBranchGrid;
123148
public bool DisplayCreateBranchGrid
124149
{
@@ -304,11 +329,11 @@ private void MergeBranchCancel()
304329
DisplayMergeBranchesGrid = false;
305330
}
306331

307-
private void DeleteBranch(string branch)
332+
private void DeleteBranch(bool isBranchPublished)
308333
{
309334
try
310335
{
311-
Provider.DeleteBranch(branch);
336+
Provider.DeleteBranch(isBranchPublished ? CurrentPublishedBranch : CurrentUnpublishedBranch);
312337
}
313338
catch (SourceControlException ex)
314339
{
@@ -318,11 +343,19 @@ private void DeleteBranch(string branch)
318343
RefreshView();
319344
}
320345

321-
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()
322355
{
323356
try
324357
{
325-
Provider.Publish(branch);
358+
Provider.Publish(CurrentUnpublishedBranch);
326359
}
327360
catch (SourceControlException ex)
328361
{
@@ -332,11 +365,11 @@ private void PublishBranch(string branch)
332365
RefreshView();
333366
}
334367

335-
private void UnpublishBranch(string branch)
368+
private void UnpublishBranch()
336369
{
337370
try
338371
{
339-
Provider.Unpublish(Provider.Branches.First(b => b.Name == branch).TrackingName);
372+
Provider.Unpublish(Provider.Branches.First(b => b.Name == CurrentPublishedBranch).TrackingName);
340373
}
341374
catch (SourceControlException ex)
342375
{

0 commit comments

Comments
 (0)