Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Components/ExtensibleTreeView.cs')
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Components/ExtensibleTreeView.cs166
1 files changed, 158 insertions, 8 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Components/ExtensibleTreeView.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Components/ExtensibleTreeView.cs
index 9e0f7e6724..6f22cda97c 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Components/ExtensibleTreeView.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Components/ExtensibleTreeView.cs
@@ -195,11 +195,20 @@ namespace MonoDevelop.Ide.Gui.Components
tree.MotionNotifyEvent += HandleMotionNotifyEvent;
tree.LeaveNotifyEvent += HandleLeaveNotifyEvent;
+ if (GtkGestures.IsSupported) {
+ tree.AddGestureMagnifyHandler ((sender, args) => {
+ Zoom += Zoom * (args.Magnification / 4d);
+ });
+ }
+
for (int n=3; n<16; n++) {
Gtk.Rc.ParseString ("style \"MonoDevelop.ExtensibleTreeView_" + n + "\" {\n GtkTreeView::expander-size = " + n + "\n }\n");
Gtk.Rc.ParseString ("widget \"*.MonoDevelop.ExtensibleTreeView_" + n + "\" style \"MonoDevelop.ExtensibleTreeView_" + n + "\"\n");
}
+ if (!string.IsNullOrEmpty (Id))
+ Zoom = PropertyService.Get<double> ("MonoDevelop.Ide.ExtensibleTreeView.Zoom." + Id, 1d);
+
this.Add (tree);
this.ShowAll ();
@@ -244,8 +253,9 @@ namespace MonoDevelop.Ide.Gui.Components
var info = (NodeInfo)model.GetValue (it, NodeInfoColumn);
var cell = (ZoomableCellRendererPixbuf)renderer;
- cell.Image = info.Icon != null && info.Icon != CellRendererImage.NullImage && info.DisabledStyle ? info.Icon.WithAlpha (0.5) : info.Icon;
- cell.ImageExpanderOpen = cell.Image;
+ var img = info.Icon != null && info.Icon != CellRendererImage.NullImage && info.DisabledStyle ? info.Icon.WithAlpha (0.5) : info.Icon;
+ cell.Image = img;
+ cell.ImageExpanderOpen = img;
cell.ImageExpanderClosed = info.ClosedIcon != null && info.ClosedIcon != CellRendererImage.NullImage && info.DisabledStyle ? info.ClosedIcon.WithAlpha (0.5) : info.ClosedIcon;
cell.OverlayBottomLeft = info.OverlayBottomLeft;
cell.OverlayBottomRight = info.OverlayBottomRight;
@@ -1019,12 +1029,92 @@ namespace MonoDevelop.Ide.Gui.Components
public event EventHandler CurrentItemActivated;
- [Obsolete ("Not supported anymore")]
+ #region Zoom
+
+ const double ZOOM_FACTOR = 1.1f;
+ const int ZOOM_MIN_POW = -4;
+ const int ZOOM_MAX_POW = 8;
+ static readonly double ZOOM_MIN = System.Math.Pow (ZOOM_FACTOR, ZOOM_MIN_POW);
+ static readonly double ZOOM_MAX = System.Math.Pow (ZOOM_FACTOR, ZOOM_MAX_POW);
+ double zoom;
+
public double Zoom {
- get { return 1d; }
- set { }
+ get {
+ return zoom;
+ }
+ set {
+ value = System.Math.Min (ZOOM_MAX, System.Math.Max (ZOOM_MIN, value));
+ if (value > ZOOM_MAX || value < ZOOM_MIN)
+ return;
+ //snap to one, if within 0.001d
+ if ((System.Math.Abs (value - 1d)) < 0.001d) {
+ value = 1d;
+ }
+ if (zoom != value) {
+ zoom = value;
+ OnZoomChanged (value);
+ }
+ }
}
+ void OnZoomChanged (double value)
+ {
+ pix_render.Zoom = value;
+ text_render.Zoom = value;
+
+ int expanderSize = (int) (12 * Zoom);
+ if (expanderSize < 3) expanderSize = 3;
+ if (expanderSize > 15) expanderSize = 15;
+ if (expanderSize != 12)
+ tree.Name = "MonoDevelop.ExtensibleTreeView_" + expanderSize;
+ else
+ tree.Name = "";
+ tree.ColumnsAutosize ();
+ if (!string.IsNullOrEmpty (Id)) {
+ PropertyService.Set ("MonoDevelop.Ide.ExtensibleTreeView.Zoom." + Id, Zoom);
+ }
+ }
+
+ [CommandHandler (ViewCommands.ZoomIn)]
+ public void ZoomIn ()
+ {
+ int oldPow = (int)System.Math.Round (System.Math.Log (zoom) / System.Math.Log (ZOOM_FACTOR));
+ Zoom = System.Math.Pow (ZOOM_FACTOR, oldPow + 1);
+ }
+
+ [CommandHandler (ViewCommands.ZoomOut)]
+ public void ZoomOut ()
+ {
+ int oldPow = (int)System.Math.Round (System.Math.Log (zoom) / System.Math.Log (ZOOM_FACTOR));
+ Zoom = System.Math.Pow (ZOOM_FACTOR, oldPow - 1);
+ }
+
+ [CommandHandler (ViewCommands.ZoomReset)]
+ public void ZoomReset ()
+ {
+ Zoom = 1d;
+ }
+
+ [CommandUpdateHandler (ViewCommands.ZoomIn)]
+ protected void UpdateZoomIn (CommandInfo cinfo)
+ {
+ cinfo.Enabled = zoom < ZOOM_MAX - 0.000001d;
+ }
+
+ [CommandUpdateHandler (ViewCommands.ZoomOut)]
+ protected void UpdateZoomOut (CommandInfo cinfo)
+ {
+ cinfo.Enabled = zoom > ZOOM_MIN + 0.000001d;
+ }
+
+ [CommandUpdateHandler (ViewCommands.ZoomReset)]
+ protected void UpdateZoomReset (CommandInfo cinfo)
+ {
+ cinfo.Enabled = zoom != 1d;
+ }
+
+ #endregion Zoom
+
[CommandHandler (EditCommands.Copy)]
public void CopyCurrentItem ()
{
@@ -1783,7 +1873,9 @@ namespace MonoDevelop.Ide.Gui.Components
void ShowPopup (Gdk.EventButton evt)
{
- var entryset = BuildEntrySet () ?? new CommandEntrySet ();
+ var entryset = BuildEntrySet ();
+ if (entryset == null)
+ return;
if (evt == null) {
var paths = tree.Selection.GetSelectedRows ();
@@ -1950,6 +2042,24 @@ namespace MonoDevelop.Ide.Gui.Components
}
}
+ protected override bool OnScrollEvent (Gdk.EventScroll evnt)
+ {
+ var modifier = !Platform.IsMac? Gdk.ModifierType.ControlMask
+ //Mac window manager already uses control-scroll, so use command
+ //Command might be either meta or mod1, depending on GTK version
+ : (Gdk.ModifierType.MetaMask | Gdk.ModifierType.Mod1Mask);
+
+ if ((evnt.State & modifier) !=0) {
+ if (evnt.Direction == Gdk.ScrollDirection.Up)
+ ZoomIn ();
+ else if (evnt.Direction == Gdk.ScrollDirection.Down)
+ ZoomOut ();
+
+ return true;
+ }
+ return base.OnScrollEvent (evnt);
+ }
+
protected virtual void OnNodeActivated (object sender, Gtk.RowActivatedArgs args)
{
ActivateCurrentItem ();
@@ -2248,6 +2358,7 @@ namespace MonoDevelop.Ide.Gui.Components
class CustomCellRendererText: Gtk.CellRendererText
{
+ double zoom;
Pango.Layout layout;
Pango.FontDescription scaledFont, customFont;
@@ -2309,7 +2420,7 @@ namespace MonoDevelop.Ide.Gui.Components
if (scaledFont != null)
scaledFont.Dispose ();
scaledFont = (customFont ?? parent.Style.FontDesc).Copy ();
- scaledFont.Size = customFont.Size;
+ scaledFont.Size = (int)(customFont.Size * Zoom);
if (layout != null)
layout.FontDescription = scaledFont;
}
@@ -2455,6 +2566,19 @@ namespace MonoDevelop.Ide.Gui.Components
width += (int) StatusIcon.Width + StatusIconSpacing;
}
+ public double Zoom {
+ get {
+ return zoom;
+ }
+ set {
+ if (scaledFont != null) {
+ scaledFont.Dispose ();
+ scaledFont = null;
+ }
+ zoom = value;
+ }
+ }
+
public bool PointerInButton (int px, int py)
{
return buttonScreenRect.Contains (px, py);
@@ -2535,6 +2659,8 @@ namespace MonoDevelop.Ide.Gui.Components
class ZoomableCellRendererPixbuf: CellRendererImage
{
+ double zoom = 1f;
+
Dictionary<Xwt.Drawing.Image,Xwt.Drawing.Image> resizedCache = new Dictionary<Xwt.Drawing.Image, Xwt.Drawing.Image> ();
Xwt.Drawing.Image overlayBottomLeft;
@@ -2542,6 +2668,17 @@ namespace MonoDevelop.Ide.Gui.Components
Xwt.Drawing.Image overlayTopLeft;
Xwt.Drawing.Image overlayTopRight;
+ public double Zoom {
+ get { return zoom; }
+ set {
+ if (zoom != value) {
+ zoom = value;
+ resizedCache.Clear ();
+ Notify ("image");
+ }
+ }
+ }
+
public override Xwt.Drawing.Image Image {
get {
return base.Image;
@@ -2616,7 +2753,20 @@ namespace MonoDevelop.Ide.Gui.Components
if (value == null || value == CellRendererImage.NullImage)
return null;
- return value;
+ if (zoom == 1)
+ return value;
+
+ Xwt.Drawing.Image resized;
+ if (resizedCache.TryGetValue (value, out resized))
+ return resized;
+
+ int w = (int) (zoom * (double) value.Width);
+ int h = (int) (zoom * (double) value.Height);
+ if (w == 0) w = 1;
+ if (h == 0) h = 1;
+ resized = value.WithSize (w, h);
+ resizedCache [value] = resized;
+ return resized;
}
public override void GetSize (Gtk.Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height)