Skip to content

Commit e877f75

Browse files
Copilottimheuer
andauthored
Open Workflows expander by default (#42)
* Persist Expander state in GHActionsToolWindow Add properties to ExtensionOptions and event handlers in XAML/code-behind to persist and restore the expanded/collapsed state of Current Branch, Workflows, and Secrets Expander controls between sessions. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: timheuer <4821+timheuer@users.noreply.github.com> Co-authored-by: Tim Heuer <tim.heuer@gmail.com>
1 parent 5d64d63 commit e877f75

3 files changed

Lines changed: 65 additions & 6 deletions

File tree

src/Options/ExtensionOptions.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,16 @@ public class ExtensionOptions : BaseOptionModel<ExtensionOptions>, IRatingConfig
3232

3333
[Browsable(false)]
3434
public int RatingRequests { get; set; }
35+
36+
[Browsable(false)]
37+
[DefaultValue(false)]
38+
public bool CurrentBranchExpanded { get; set; } = false;
39+
40+
[Browsable(false)]
41+
[DefaultValue(true)]
42+
public bool WorkflowsExpanded { get; set; } = true;
43+
44+
[Browsable(false)]
45+
[DefaultValue(false)]
46+
public bool SecretsExpanded { get; set; } = false;
3547
}

src/ToolWindows/GHActionsToolWindow.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
<TextBlock HorizontalAlignment="Center" x:Name="MessageArea" TextWrapping="Wrap" Margin="20" />
130130
<ScrollViewer VerticalAlignment="Stretch" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Margin="5,5,0,0" x:Name="ActionsInfoPanel">
131131
<StackPanel Orientation="Vertical">
132-
<Expander Header="{x:Static resx:UIStrings.HEADER_CURRENT_BRANCH}" x:Name="CurrentBranchExpander" FontWeight="Bold" ToolTipService.ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Header}">
132+
<Expander Header="{x:Static resx:UIStrings.HEADER_CURRENT_BRANCH}" x:Name="CurrentBranchExpander" FontWeight="Bold" ToolTipService.ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Header}" Expanded="Expander_ExpandedOrCollapsed" Collapsed="Expander_ExpandedOrCollapsed">
133133
<TreeView BorderThickness="0" FontWeight="Normal" PreviewMouseWheel="HandlePreviewMouseWheel" x:Name="tvCurrentBranch" ItemTemplate="{StaticResource TreeViewRunNodeDataTemplate}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch">
134134
<TreeView.Resources>
135135
<Style TargetType="{x:Type TreeViewItem}" BasedOn="{StaticResource {x:Static shell:VsResourceKeys.ThemedDialogTreeViewItemStyleKey}}">
@@ -138,10 +138,10 @@
138138
</TreeView.Resources>
139139
</TreeView>
140140
</Expander>
141-
<Expander Header="{x:Static resx:UIStrings.HEADER_WORKFLOWS}" FontWeight="Bold" ToolTipService.ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Header}">
141+
<Expander Header="{x:Static resx:UIStrings.HEADER_WORKFLOWS}" x:Name="WorkflowsExpander" FontWeight="Bold" ToolTipService.ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Header}" Expanded="Expander_ExpandedOrCollapsed" Collapsed="Expander_ExpandedOrCollapsed">
142142
<TreeView BorderThickness="0" FontWeight="Normal" PreviewMouseWheel="HandlePreviewMouseWheel" x:Name="tvWorkflows" ItemTemplate="{StaticResource WorkflowItemTemplate}"/>
143143
</Expander>
144-
<Expander Header="{x:Static resx:UIStrings.HEADER_SECRETS}" FontWeight="Bold" ToolTipService.ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Header}">
144+
<Expander Header="{x:Static resx:UIStrings.HEADER_SECRETS}" x:Name="SecretsExpander" FontWeight="Bold" ToolTipService.ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Header}" Expanded="Expander_ExpandedOrCollapsed" Collapsed="Expander_ExpandedOrCollapsed">
145145
<TreeView BorderThickness="0" PreviewMouseWheel="HandlePreviewMouseWheel" FontWeight="Normal">
146146
<TreeViewItem ToolTipService.ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Header}" Header="{x:Static resx:UIStrings.HEADER_ENVIRONMENTS}" HeaderTemplate="{StaticResource EnvironmentHeaderTemplate}" x:Name="tvEnvironments" ItemTemplate="{StaticResource EnvironmentItemTemplate}" />
147147
<TreeViewItem ToolTipService.ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Header}" Header="{x:Static resx:UIStrings.HEADER_SECRETS}" HeaderTemplate="{StaticResource SecretsHeaderTemplate}">

src/ToolWindows/GHActionsToolWindow.xaml.cs

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public partial class GHActionsToolWindow : UserControl
2828
private int maxRuns = 10;
2929
private bool refreshPending = false;
3030
private int refreshInterval = 5;
31+
private bool _isApplyingExpanderStates = false;
3132
OutputWindowPane _pane;
3233

3334
public GHActionsToolWindow(ToolWindowMessenger toolWindowMessenger)
@@ -99,6 +100,7 @@ public async Task GetRepoInfoAsync()
99100
maxRuns = generalSettings.MaxRuns;
100101
refreshInterval = generalSettings.RefreshInterval;
101102
refreshPending = generalSettings.RefreshActiveJobs;
103+
ApplyExpanderStates(generalSettings);
102104

103105
await _pane.WriteLineAsync($"[{DateTime.UtcNow.ToString("o")}] Extension settings retrieved and applied");
104106

@@ -158,7 +160,6 @@ private void ClearTreeViews()
158160
tvEnvironments.Header = resx.HEADER_ENVIRONMENTS;
159161
tvCurrentBranch.ItemsSource = null;
160162
tvWorkflows.ItemsSource = null;
161-
CurrentBranchExpander.IsExpanded = false;
162163
}
163164

164165
private async Task LoadDataAsync()
@@ -285,11 +286,58 @@ private async Task LoadDataAsync()
285286
await ex.LogAsync();
286287
}
287288

288-
CurrentBranchExpander.IsExpanded = true;
289289
refreshProgress.Visibility = Visibility.Hidden;
290290
refreshProgress.IsIndeterminate = false;
291291
}
292292

293+
private void ApplyExpanderStates(ExtensionOptions options)
294+
{
295+
_isApplyingExpanderStates = true;
296+
try
297+
{
298+
CurrentBranchExpander.IsExpanded = options.CurrentBranchExpanded;
299+
WorkflowsExpander.IsExpanded = options.WorkflowsExpanded;
300+
SecretsExpander.IsExpanded = options.SecretsExpanded;
301+
}
302+
finally
303+
{
304+
_isApplyingExpanderStates = false;
305+
}
306+
}
307+
308+
private void Expander_ExpandedOrCollapsed(object sender, RoutedEventArgs e)
309+
{
310+
if (_isApplyingExpanderStates)
311+
{
312+
return;
313+
}
314+
315+
ThreadHelper.JoinableTaskFactory.RunAsync(SaveExpanderStatesAsync).FireAndForget();
316+
}
317+
318+
private async Task SaveExpanderStatesAsync()
319+
{
320+
try
321+
{
322+
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
323+
324+
bool currentBranchExpanded = CurrentBranchExpander.IsExpanded;
325+
bool workflowsExpanded = WorkflowsExpander.IsExpanded;
326+
bool secretsExpanded = SecretsExpander.IsExpanded;
327+
328+
ExtensionOptions options = await ExtensionOptions.GetLiveInstanceAsync();
329+
options.CurrentBranchExpanded = currentBranchExpanded;
330+
options.WorkflowsExpanded = workflowsExpanded;
331+
options.SecretsExpanded = secretsExpanded;
332+
333+
await options.SaveAsync();
334+
}
335+
catch (Exception ex)
336+
{
337+
await ex.LogAsync();
338+
}
339+
}
340+
293341
private async Task RefreshEnvironmentsAsync(GitHubClient client)
294342
{
295343
List<SimpleEnvironment> envList = new List<SimpleEnvironment>();
@@ -603,4 +651,3 @@ private void CancelRun_Click(object sender, RoutedEventArgs e)
603651
}
604652
}
605653
}
606-

0 commit comments

Comments
 (0)