11 changed files with 194 additions and 16 deletions
@ -0,0 +1,86 @@
@@ -0,0 +1,86 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.NRefactory; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Refactoring; |
||||
|
||||
namespace ICSharpCode.AvalonEdit.AddIn.ContextActions |
||||
{ |
||||
/// <summary>
|
||||
/// Creates IOptionPanelDescriptor objects that are used in option dialogs.
|
||||
/// </summary>
|
||||
/// <attribute name="path" use="required">
|
||||
/// AddInTree-path that contains the IContextActionProviders.
|
||||
/// </attribute>
|
||||
/// <attribute name="label" use="optional">
|
||||
/// Caption of the dialog panel.
|
||||
/// </attribute>
|
||||
/// <children childTypes="OptionPanel">
|
||||
/// In the SharpDevelop options, option pages can have subpages by specifying them
|
||||
/// as children in the AddInTree.
|
||||
/// </children>
|
||||
/// <usage>In /SharpDevelop/BackendBindings/ProjectOptions/ and /SharpDevelop/Dialogs/OptionsDialog</usage>
|
||||
/// <returns>
|
||||
/// IOptionPanelDescriptor object.
|
||||
/// </returns>
|
||||
public class ContextActionOptionPanelDoozer : IDoozer |
||||
{ |
||||
public bool HandleConditions { |
||||
get { return false; } |
||||
} |
||||
|
||||
public object BuildItem(BuildItemArgs args) |
||||
{ |
||||
return new ContextActionOptionPanelDescriptor(args.Codon); |
||||
} |
||||
|
||||
sealed class ContextActionOptionPanelDescriptor : IOptionPanelDescriptor |
||||
{ |
||||
readonly string id; |
||||
readonly string label; |
||||
readonly string path; |
||||
|
||||
public ContextActionOptionPanelDescriptor(Codon codon) |
||||
{ |
||||
this.id = codon.Id; |
||||
this.path = codon.Properties["path"]; |
||||
this.label = codon.Properties["label"]; |
||||
if (string.IsNullOrEmpty(label)) |
||||
label = "Context Actions"; // TODO: Translate
|
||||
} |
||||
|
||||
public string ID { |
||||
get { return this.id; } |
||||
} |
||||
|
||||
public string Label { |
||||
get { return this.label; } |
||||
} |
||||
|
||||
public IEnumerable<IOptionPanelDescriptor> ChildOptionPanelDescriptors { |
||||
get { return EmptyList<IOptionPanelDescriptor>.Instance; } |
||||
} |
||||
|
||||
IOptionPanel optionPanel; |
||||
|
||||
public IOptionPanel OptionPanel { |
||||
get { |
||||
if (optionPanel == null) { |
||||
var providers = AddInTree.BuildItems<IContextActionProvider>(path, null, false); |
||||
optionPanel = new ContextActionOptions(providers.Where(p => p.AllowHiding)); |
||||
} |
||||
return optionPanel; |
||||
} |
||||
} |
||||
|
||||
public bool HasOptionPanel { |
||||
get { return true; } |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,24 @@
@@ -0,0 +1,24 @@
|
||||
<gui:OptionPanel x:Class="ICSharpCode.AvalonEdit.AddIn.ContextActions.ContextActionOptions" |
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
xmlns:sd="http://icsharpcode.net/sharpdevelop/core" |
||||
xmlns:gui="clr-namespace:ICSharpCode.SharpDevelop.Gui;assembly=ICSharpCode.SharpDevelop"> |
||||
<DockPanel> |
||||
<!-- TODO: Translate --> |
||||
<CheckBox Name="featureEnabledCheckBox" DockPanel.Dock="Top" |
||||
IsChecked="True" Content="Enable context actions" /> |
||||
<sd:RestrictDesiredSize Margin="0, 4, 0, 0"> |
||||
<ListBox x:Name="listBox" SelectionMode="Multiple" |
||||
ItemContainerStyle="{x:Static sd:GlobalStyles.ListBoxItemFocusHighlightStyle}"> |
||||
<ListBox.ItemTemplate> |
||||
<DataTemplate> |
||||
<!-- The checkbox is toggling the actual IsSelected property on the container (ListBoxItem), so it'll update ListBox.SelectedItems --> |
||||
<CheckBox Content="{Binding DisplayName}" |
||||
IsEnabled="{Binding IsChecked, ElementName=featureEnabledCheckBox}" |
||||
IsChecked="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBoxItem}},Path=IsSelected}" /> |
||||
</DataTemplate> |
||||
</ListBox.ItemTemplate> |
||||
</ListBox> |
||||
</sd:RestrictDesiredSize> |
||||
</DockPanel> |
||||
</gui:OptionPanel> |
||||
@ -0,0 +1,56 @@
@@ -0,0 +1,56 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Windows; |
||||
using System.Windows.Controls; |
||||
using System.Windows.Data; |
||||
using System.Windows.Documents; |
||||
using System.Windows.Input; |
||||
using System.Windows.Media; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.SharpDevelop.Refactoring; |
||||
|
||||
namespace ICSharpCode.AvalonEdit.AddIn.ContextActions |
||||
{ |
||||
/// <summary>
|
||||
/// Interaction logic for ContextActionOptions.xaml
|
||||
/// </summary>
|
||||
public partial class ContextActionOptions : OptionPanel |
||||
{ |
||||
readonly IContextActionProvider[] providers; |
||||
|
||||
public ContextActionOptions(IEnumerable<IContextActionProvider> providers) |
||||
{ |
||||
InitializeComponent(); |
||||
this.providers = providers.ToArray(); |
||||
listBox.ItemsSource = this.providers; |
||||
} |
||||
|
||||
public override void LoadOptions() |
||||
{ |
||||
base.LoadOptions(); |
||||
EditorActionsProvider.LoadProviderVisibilities(providers); |
||||
listBox.UnselectAll(); |
||||
foreach (var provider in providers) { |
||||
if (provider.IsVisible) |
||||
listBox.SelectedItems.Add(provider); |
||||
} |
||||
} |
||||
|
||||
public override bool SaveOptions() |
||||
{ |
||||
foreach (var provider in providers) { |
||||
provider.IsVisible = false; |
||||
} |
||||
foreach (IContextActionProvider provider in listBox.SelectedItems) { |
||||
provider.IsVisible = true; |
||||
} |
||||
EditorActionsProvider.SaveProviderVisibilities(providers); |
||||
return base.SaveOptions(); |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue