Skip to content

Commit

Permalink
don't quit the FZ editor if no layout is selected when clicking on th…
Browse files Browse the repository at this point in the history
…e "Edit selected layout" (#548)

don't exit when clicking on "Apply" if no layout is selected

Credit to @alexr3 for the fix. Alex provided a more extensive fix that  disable the button when no layout  is selected, but it requires more changes to the XAML and we preferred to avoid that now.
  • Loading branch information
enricogior committed Oct 23, 2019
1 parent 8f8f450 commit 57cd5b5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Background="White"
ResizeMode="NoResize"
WindowStartupLocation="CenterScreen"
Loaded="OnLoaded"
Initialized="InitializedEventHandler"
Closed="OnClosed">
<Window.Resources>
<local:BooleanToBrushConverter x:Key="BooleanToBrushConverter" />
Expand Down Expand Up @@ -222,7 +222,7 @@

</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,12,0,16">
<Button x:Name="EditTemplateBUtton" Padding="8" Content="Edit selected layout" Style="{StaticResource secondaryButton}" Click="EditLayout_Click"/>
<Button x:Name="EditTemplateButton" Padding="8" Content="Edit selected layout" Style="{StaticResource secondaryButton}" Click="EditLayout_Click"/>
<Button x:Name="ApplyTemplateButton" Padding="8" Content="Apply" Style="{StaticResource primaryButton}" Click="Apply_Click"/>
</StackPanel>
</StackPanel>
Expand Down
22 changes: 12 additions & 10 deletions src/modules/fancyzones/editor/FancyZonesEditor/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,15 @@ private void Select(LayoutModel newSelection)

private void EditLayout_Click(object sender, RoutedEventArgs e)
{
_editing = true;
this.Close();

EditorOverlay mainEditor = EditorOverlay.Current;
LayoutModel model = mainEditor.DataContext as LayoutModel;
if (model == null)
{
mainEditor.Close();
return;
}
model.IsSelected = false;
_editing = true;
this.Close();

bool isPredefinedLayout = Settings.IsPredefinedLayout(model);

Expand Down Expand Up @@ -150,9 +148,8 @@ private void Apply_Click(object sender, RoutedEventArgs e)
{
model.Apply((model as CanvasLayoutModel).Zones.ToArray());
}
this.Close();
}

this.Close();
}

private void OnClosed(object sender, EventArgs e)
Expand All @@ -163,13 +160,18 @@ private void OnClosed(object sender, EventArgs e)
}
}

private void OnLoaded(object sender, RoutedEventArgs e)
private void InitializedEventHandler(object sender, EventArgs e)
{
SetSelectedItem();
}

private void SetSelectedItem()
{
foreach(LayoutModel model in _settings.CustomModels)
foreach (LayoutModel model in _settings.CustomModels)
{
if (model.IsSelected)
{
TemplateTab.SelectedIndex = 1;
TemplateTab.SelectedItem = model;
return;
}
}
Expand All @@ -180,7 +182,7 @@ private void OnDelete(object sender, RoutedEventArgs e)
LayoutModel model = ((FrameworkElement)sender).DataContext as LayoutModel;
if (model.IsSelected)
{
OnLoaded(null, null);
SetSelectedItem();
}
model.Delete();
}
Expand Down

0 comments on commit 57cd5b5

Please sign in to comment.