|
/* ZoomSliderVSX - Visual Studio 2010 Extention
* Developed By : Abhijit Jana
* Last Modified : 8-Feb-2010
* Description : Scrollable Zooming Features For VS 2010 IDE
*/
using System;
using System.Windows.Controls;
using System.Windows.Media;
using Microsoft.VisualStudio.Text.Editor;
namespace ZoomSliderVSX
{
/// <summary>
/// A class detailing the margin's visual definition including both size and content.
/// </summary>
class ZoomSlider : Canvas, IWpfTextViewMargin
{
// The IWpfTextView that our margin will be attached to.
private IWpfTextView _textView;
// The name of the margin
public const string MarginName = "ZoomSlideBar";
// A flag stating whether this margin has been disposed
private bool _isDisposed = false;
//Slider WPF User Control
private SliderControl _slider = null;
/// <summary>
/// Creates a <see cref="ZoomSlider"/> for a given <see cref="IWpfTextView"/>.
/// </summary>
/// <param name="textView">The <see cref="IWpfTextView"/> to attach the margin to.</param>
public ZoomSlider(IWpfTextView textView)
{
// Set the IWpfTextView
_textView = textView;
// Establish the background of the margin.
this.Height = 30;
this.ClipToBounds = true;
this.Background = new SolidColorBrush(Color.FromArgb(60, 41,57, 85));
//Set Direction of Control
this.FlowDirection = System.Windows.FlowDirection.RightToLeft;
//Add Event handler for for LayoutChanges Event
_textView.LayoutChanged += this.OnLayoutChanged;
//Create New instance for WPF Slider Control
_slider = new SliderControl(_textView);
//Add Control
this.Children.Add(_slider);
}
/// <summary>
/// Layout Changed Event
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnLayoutChanged(object sender, TextViewLayoutChangedEventArgs e)
{
if (_slider != null)
_slider.UpdateSlider();
}
private void ThrowIfDisposed()
{
if (_isDisposed)
throw new ObjectDisposedException(MarginName);
}
#region IWpfTextViewMargin Members
/// <summary>
/// The <see cref="Sytem.Windows.FrameworkElement"/> that implements the visual representation
/// of the margin.
/// </summary>
public System.Windows.FrameworkElement VisualElement
{
// Since this margin implements Canvas, this is the object which renders
// the margin.
get
{
ThrowIfDisposed();
return this;
}
}
#endregion
#region ITextViewMargin Members
public double MarginSize
{
// Since this is a horizontal margin, its width will be bound to the width of the text view.
// Therefore, its size is its height.
get
{
ThrowIfDisposed();
return this.ActualHeight;
}
}
public bool Enabled
{
// The margin should always be enabled
get
{
ThrowIfDisposed();
return true;
}
}
/// <summary>
/// Returns an instance of the margin if this is the margin that has been requested.
/// </summary>
/// <param name="marginName">The name of the margin requested</param>
/// <returns>An instance of ZoomSliderVSX or null</returns>
public ITextViewMargin GetTextViewMargin(string marginName)
{
return (marginName == ZoomSlider.MarginName) ? (IWpfTextViewMargin)this : null;
}
// Dispose of the margin
public void Dispose()
{
if (!_isDisposed)
{
GC.SuppressFinalize(this);
_isDisposed = true;
}
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.