Browse Source

Fix #1815: make all documents closeable as long as there is at least one.

pull/1820/head
Siegfried Pammer 6 years ago
parent
commit
5d98842a89
  1. 10
      ILSpy/Docking/DockWorkspace.cs
  2. 2
      ILSpy/Docking/PaneCollection.cs
  3. 2
      ILSpy/MainWindow.xaml
  4. 1
      ILSpy/MainWindow.xaml.cs
  5. 8
      ILSpy/ViewModels/PaneModel.cs

10
ILSpy/Docking/DockWorkspace.cs

@ -43,6 +43,16 @@ namespace ICSharpCode.ILSpy.Docking
private DockWorkspace() private DockWorkspace()
{ {
this.Documents.CollectionChanged += Documents_CollectionChanged;
}
private void Documents_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
var collection = (PaneCollection<DocumentModel>)sender;
bool canClose = collection.Count > 1;
foreach (var item in collection) {
item.IsCloseable = canClose;
}
} }
public PaneCollection<DocumentModel> Documents { get; } = new PaneCollection<DocumentModel>(); public PaneCollection<DocumentModel> Documents { get; } = new PaneCollection<DocumentModel>();

2
ILSpy/Docking/PaneCollection.cs

@ -49,7 +49,7 @@ namespace ICSharpCode.ILSpy.Docking
item.IsActive = true; item.IsActive = true;
} }
public int Count => observableCollection.Count(); public int Count => observableCollection.Count;
public bool IsReadOnly => false; public bool IsReadOnly => false;
public void Clear() => observableCollection.Clear(); public void Clear() => observableCollection.Clear();
public bool Contains(T item) => observableCollection.Contains(item); public bool Contains(T item) => observableCollection.Contains(item);

2
ILSpy/MainWindow.xaml

@ -211,7 +211,7 @@
<Setter Property="IsSelected" Value="{Binding Model.IsSelected, Mode=TwoWay}"/> <Setter Property="IsSelected" Value="{Binding Model.IsSelected, Mode=TwoWay}"/>
<Setter Property="IsActive" Value="{Binding Model.IsActive, Mode=TwoWay}"/> <Setter Property="IsActive" Value="{Binding Model.IsActive, Mode=TwoWay}"/>
<Setter Property="CloseCommand" Value="{Binding Model.CloseCommand}" /> <Setter Property="CloseCommand" Value="{Binding Model.CloseCommand}" />
<Setter Property="CanClose" Value="{Binding Model.IsCloseable}" /> <Setter Property="CanClose" Value="{Binding Model.IsCloseable, Mode=TwoWay}" />
</Style> </Style>
</docking:PaneStyleSelector.DocumentStyle> </docking:PaneStyleSelector.DocumentStyle>
</docking:PaneStyleSelector> </docking:PaneStyleSelector>

1
ILSpy/MainWindow.xaml.cs

@ -457,7 +457,6 @@ namespace ICSharpCode.ILSpy
void MainWindow_Loaded(object sender, RoutedEventArgs e) void MainWindow_Loaded(object sender, RoutedEventArgs e)
{ {
DockWorkspace.Instance.Documents.Add(new DecompiledDocumentModel() { DockWorkspace.Instance.Documents.Add(new DecompiledDocumentModel() {
IsCloseable = false,
Language = CurrentLanguage, Language = CurrentLanguage,
LanguageVersion = CurrentLanguageVersion LanguageVersion = CurrentLanguageVersion
}); });

8
ILSpy/ViewModels/PaneModel.cs

@ -31,6 +31,14 @@ namespace ICSharpCode.ILSpy.ViewModels
public CloseCommandImpl(PaneModel model) public CloseCommandImpl(PaneModel model)
{ {
this.model = model; this.model = model;
this.model.PropertyChanged += Model_PropertyChanged;
}
private void Model_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(model.IsCloseable)) {
CanExecuteChanged?.Invoke(this, EventArgs.Empty);
}
} }
public event EventHandler CanExecuteChanged; public event EventHandler CanExecuteChanged;

Loading…
Cancel
Save