Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.AvalonEdit/5.0.1/AvalonEdit-5.0.1/CodeCompletion/OverloadViewer.cs @ 14419

Last change on this file since 14419 was 11700, checked in by jkarder, 10 years ago

#2077: created branch and added first version

File size: 3.8 KB
Line 
1// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy of this
4// software and associated documentation files (the "Software"), to deal in the Software
5// without restriction, including without limitation the rights to use, copy, modify, merge,
6// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7// to whom the Software is furnished to do so, subject to the following conditions:
8//
9// The above copyright notice and this permission notice shall be included in all copies or
10// substantial portions of the Software.
11//
12// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17// DEALINGS IN THE SOFTWARE.
18
19using System;
20using System.Collections.ObjectModel;
21using System.ComponentModel;
22using System.Globalization;
23using System.Windows;
24using System.Windows.Controls;
25using System.Windows.Data;
26
27namespace ICSharpCode.AvalonEdit.CodeCompletion
28{
29  /// <summary>
30  /// Represents a text between "Up" and "Down" buttons.
31  /// </summary>
32  public class OverloadViewer : Control
33  {
34    static OverloadViewer()
35    {
36      DefaultStyleKeyProperty.OverrideMetadata(typeof(OverloadViewer),
37                                               new FrameworkPropertyMetadata(typeof(OverloadViewer)));
38    }
39   
40    /// <summary>
41    /// The text property.
42    /// </summary>
43    public static readonly DependencyProperty TextProperty =
44      DependencyProperty.Register("Text", typeof(string), typeof(OverloadViewer));
45   
46    /// <summary>
47    /// Gets/Sets the text between the Up and Down buttons.
48    /// </summary>
49    public string Text {
50      get { return (string)GetValue(TextProperty); }
51      set { SetValue(TextProperty, value); }
52    }
53   
54    /// <inheritdoc/>
55    public override void OnApplyTemplate()
56    {
57      base.OnApplyTemplate();
58     
59      Button upButton = (Button)this.Template.FindName("PART_UP", this);
60      upButton.Click += (sender, e) => {
61        e.Handled = true;
62        ChangeIndex(-1);
63      };
64     
65      Button downButton = (Button)this.Template.FindName("PART_DOWN", this);
66      downButton.Click += (sender, e) => {
67        e.Handled = true;
68        ChangeIndex(+1);
69      };
70    }
71   
72    /// <summary>
73    /// The ItemProvider property.
74    /// </summary>
75    public static readonly DependencyProperty ProviderProperty =
76      DependencyProperty.Register("Provider", typeof(IOverloadProvider), typeof(OverloadViewer));
77   
78    /// <summary>
79    /// Gets/Sets the item provider.
80    /// </summary>
81    public IOverloadProvider Provider {
82      get { return (IOverloadProvider)GetValue(ProviderProperty); }
83      set { SetValue(ProviderProperty, value); }
84    }
85   
86    /// <summary>
87    /// Changes the selected index.
88    /// </summary>
89    /// <param name="relativeIndexChange">The relative index change - usual values are +1 or -1.</param>
90    public void ChangeIndex(int relativeIndexChange)
91    {
92      IOverloadProvider p = this.Provider;
93      if (p != null) {
94        int newIndex = p.SelectedIndex + relativeIndexChange;
95        if (newIndex < 0)
96          newIndex = p.Count - 1;
97        if (newIndex >= p.Count)
98          newIndex = 0;
99        p.SelectedIndex = newIndex;
100      }
101    }
102  }
103 
104  sealed class CollapseIfSingleOverloadConverter : IValueConverter
105  {
106    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
107    {
108      return ((int)value < 2) ? Visibility.Collapsed : Visibility.Visible;
109    }
110   
111    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
112    {
113      throw new NotImplementedException();
114    }
115  }
116}
Note: See TracBrowser for help on using the repository browser.