[mono/monodevelop] 58793fcc: Implemented 'Bug 15248 - CRNL vs NL policy setting warning is too

Mike Krüger ([email protected]) <[email protected]>
Newsgroups gmane.comp.gnome.mono.patches
Message-ID <00000141a181b773-ad552ded-5276-461a-966c-b5d2c6718431-000000@email.amazonses.com>
   Branch: refs/heads/master
     Home: https://github.com/mono/monodevelop
  Compare: https://github.com/mono/monodevelop/compare/f2fb303446cf...58793fcc7d02

   Commit: 58793fcc7d0261bc4d4a89733ed3ff2a85d6f876
   Author: Mike Krüger <[email protected]> (mkrueger)
     Date: 2013-10-10 08:34:03 GMT
      URL: https://github.com/mono/monodevelop/commit/58793fcc7d0261bc4d4a89733ed3ff2a85d6f876

Implemented 'Bug 15248 - CRNL vs NL policy setting warning is too
obtrusive'.

Changed paths:
  M main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.csproj
  M main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/OverlayMessageWindow.cs
  M main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorWidget.cs
Added paths:
  A main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/HoverCloseButton.cs

Modified: main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.csproj
===================================================================
@@ -186,6 +186,7 @@
     <Compile Include="AddinInfo.cs" />
     <Compile Include="MonoDevelop.SourceEditor.OptionPanels\CompletionCharactersPanel.cs" />
     <Compile Include="MonoDevelop.SourceEditor\OverlayMessageWindow.cs" />
+    <Compile Include="MonoDevelop.SourceEditor\HoverCloseButton.cs" />
   </ItemGroup>
   <ItemGroup>
     <EmbeddedResource Include="gtk-gui\gui.stetic">

Added: main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/HoverCloseButton.cs
===================================================================
@@ -0,0 +1,160 @@
+//
+// HoverCloseButton.cs
+//
+// Author:
+//       Mike Krüger <[email protected]>
+//
+// Copyright (c) 2013 Xamarin Inc. (http://xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+using System;
+using Gtk;
+using Gdk;
+
+namespace MonoDevelop.SourceEditor
+{
+	public class HoverCloseButton : EventBox
+	{
+		bool hovered;
+
+		public HoverCloseButton ()
+		{
+			VisibleWindow = false;
+			Events |= EventMask.LeaveNotifyMask | EventMask.EnterNotifyMask | EventMask.ButtonPressMask | EventMask.ButtonReleaseMask;
+		}
+
+		protected override void OnSizeRequested (ref Requisition requisition)
+		{
+			base.OnSizeRequested (ref requisition);
+			requisition.Width = requisition.Height = 16;
+		}
+
+		protected override bool OnEnterNotifyEvent (Gdk.EventCrossing evnt)
+		{
+			hovered = true;
+			QueueDraw ();
+			return base.OnEnterNotifyEvent (evnt);
+		}
+
+		protected override bool OnLeaveNotifyEvent (Gdk.EventCrossing evnt)
+		{
+			hovered = false;
+			QueueDraw ();
+			return base.OnLeaveNotifyEvent (evnt);
+		}
+
+		bool click;
+		protected override bool OnButtonPressEvent (EventButton evnt)
+		{
+			if (evnt.Button == 1 && hovered) 
+				click = true;
+			return base.OnButtonPressEvent (evnt);
+		}
+
+		protected override bool OnButtonReleaseEvent (EventButton evnt)
+		{
+			if (click && hovered)
+				OnClicked (EventArgs.Empty);
+			click = false;
+			return base.OnButtonReleaseEvent (evnt);
+		}
+
+		public event EventHandler Clicked;
+
+		protected virtual void OnClicked (EventArgs e)
+		{
+			var handler = Clicked;
+			if (handler != null)
+				handler (this, e);
+		}
+
+		protected override bool OnExposeEvent (Gdk.EventExpose evnt)
+		{
+			using (var cr = CairoHelper.Create (evnt.Window)) {
+				DrawCloseButton (cr, new Gdk.Point (Allocation.X + Allocation.Width / 2, Allocation.Y + Allocation.Height / 2), hovered, 1.0, 0);
+			}
+			return base.OnExposeEvent (evnt);
+		}
+
+		static void DrawCloseButton (Cairo.Context context, Gdk.Point center, bool hovered, double opacity, double animationProgress)
+		{
+			if (hovered) {
+				double radius = 6;
+				context.Arc (center.X, center.Y, radius, 0, Math.PI * 2);
+				context.SetSourceRGBA (.6, .6, .6, opacity);
+				context.Fill ();
+
+				context.SetSourceRGBA (0.95, 0.95, 0.95, opacity);
+				context.LineWidth = 2;
+
+				context.MoveTo (center.X - 3, center.Y - 3);
+				context.LineTo (center.X + 3, center.Y + 3);
+				context.MoveTo (center.X - 3, center.Y + 3);
+				context.LineTo (center.X + 3, center.Y - 3);
+				context.Stroke ();
+			} else {
+				double lineColor = .63 - .1 * animationProgress;
+				double fillColor = .74;
+
+				double heightMod = Math.Max (0, 1.0 - animationProgress * 2);
+				context.MoveTo (center.X - 3, center.Y - 3 * heightMod);
+				context.LineTo (center.X + 3, center.Y + 3 * heightMod);
+				context.MoveTo (center.X - 3, center.Y + 3 * heightMod);
+				context.LineTo (center.X + 3, center.Y - 3 * heightMod);
+
+				context.LineWidth = 2;
+				context.SetSourceRGBA (lineColor, lineColor, lineColor, opacity);
+				context.Stroke ();
+
+				if (animationProgress > 0.5) {
+					double partialProg = (animationProgress - 0.5) * 2;
+					context.MoveTo (center.X - 3, center.Y);
+					context.LineTo (center.X + 3, center.Y);
+
+					context.LineWidth = 2 - partialProg;
+					context.SetSourceRGBA (lineColor, lineColor, lineColor, opacity);
+					context.Stroke ();
+
+
+					double radius = partialProg * 3.5;
+
+					// Background
+					context.Arc (center.X, center.Y, radius, 0, Math.PI * 2);
+					context.SetSourceRGBA (fillColor, fillColor, fillColor, opacity);
+					context.Fill ();
+
+					// Inset shadow
+					using (var lg = new Cairo.LinearGradient (0, center.Y - 5, 0, center.Y)) {
+						context.Arc (center.X, center.Y + 1, radius, 0, Math.PI * 2);
+						lg.AddColorStop (0, new Cairo.Color (0, 0, 0, 0.2 * opacity));
+						lg.AddColorStop (1, new Cairo.Color (0, 0, 0, 0));
+						context.SetSource (lg);
+						context.Stroke ();
+					}
+
+					// Outline
+					context.Arc (center.X, center.Y, radius, 0, Math.PI * 2);
+					context.SetSourceRGBA (lineColor, lineColor, lineColor, opacity);
+					context.Stroke ();
+				}
+			}
+		}
+	}
+}
+

Modified: main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/OverlayMessageWindow.cs
===================================================================
@@ -33,6 +33,10 @@ namespace MonoDevelop.SourceEditor
 {
 	public class OverlayMessageWindow : Gtk.EventBox
 	{
+		const int border = 8;
+
+		public Func<int> SizeFunc;
+
 		ExtensibleTextEditor textEditor;
 
 		public OverlayMessageWindow ()
@@ -59,14 +63,36 @@ protected override void OnDestroyed ()
 			}
 		}
 
+		protected override void OnSizeRequested (ref Requisition requisition)
+		{
+			base.OnSizeRequested (ref requisition);
+
+			if (wRequest > 0) {
+				requisition.Width = wRequest;
+			}
+		}
+
 		protected override void OnSizeAllocated (Gdk.Rectangle allocation)
 		{
 			base.OnSizeAllocated (allocation);
 			Resize (allocation);
 		}
-
+		int wRequest = -1;
 		void HandleSizeAllocated (object o, Gtk.SizeAllocatedArgs args)
 		{
+			if (SizeFunc != null) {
+				var req = Math.Min (SizeFunc (), textEditor.Allocation.Width - border * 2);
+				if (req != wRequest) {
+					wRequest = req;
+					QueueResize ();
+				}
+			} else {
+				if (Allocation.Width > textEditor.Allocation.Width - border * 2) {
+					if (textEditor.Allocation.Width - border * 2 > 0) {
+						QueueResize ();
+					}
+				}
+			}
 			Resize (Allocation);
 		}
 
@@ -78,7 +104,11 @@ void Resize (Gdk.Rectangle alloc)
 		protected override bool OnExposeEvent (Gdk.EventExpose evnt)
 		{
 			using (var cr = CairoHelper.Create (evnt.Window)) {
+				cr.LineWidth = 1;
 				cr.Rectangle (0, 0, Allocation.Width, Allocation.Height);
+				cr.SetSourceColor (textEditor.ColorStyle.PlainText.Background);
+				cr.Fill ();
+				cr.RoundedRectangle (0, 0, Allocation.Width, Allocation.Height, 3);
 				cr.SetSourceColor (textEditor.ColorStyle.TooltipText.Background);
 				cr.FillPreserve ();
 

Modified: main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor/SourceEditorWidget.cs
===================================================================
@@ -915,7 +915,7 @@ internal void ConvertLineEndings ()
 					newText.Append (correctEol);
 			}
 			view.StoreSettings ();
-			TextEditor.Text = newText.ToString ();
+			view.ReplaceContent (Document.FileName, newText.ToString (), null);
 			view.LoadSettings ();
 		}
 
@@ -923,7 +923,7 @@ static string GetEolString (string detectedEol)
 		{
 			switch (detectedEol) {
 			case "\n":
-				return "Unix";
+				return "UNIX";
 			case "\r\n":
 				return "Windows";
 			case "\r":
@@ -936,33 +936,50 @@ static string GetEolString (string detectedEol)
 		void ShowIncorretEolMarkers (string fileName, bool multiple)
 		{
 			RemoveMessageBar ();
-
-			Console.WriteLine ("SHOW EOL MARKER !!!!!");
-
 			var window = new OverlayMessageWindow ();
 
 			var hbox = new HBox ();
 			hbox.Spacing = 8;
 
-			hbox.PackStart (ImageService.GetImage ("gtk-dialog-warning", IconSize.Menu));
-			hbox.PackStart (new Label (string.Format ("This file has line endings ({0}) which differ from the policy settings ({1}).", GetEolString(DetectedEolMarker), GetEolString(textEditor.Options.DefaultEolMarker))), true, true, 0);
-			var okButton = new Button (Gtk.Stock.Ok);
-			hbox.PackEnd (okButton); 
+			var image = new HoverCloseButton ();
+			hbox.PackStart (image, false, false, 0);
+			var label = new Label (string.Format ("This file has line endings ({0}) which differ from the policy settings ({1}).", GetEolString (DetectedEolMarker), GetEolString (textEditor.Options.DefaultEolMarker)));
+			int w, h;
+			label.Layout.GetPixelSize (out w, out h);
+			label.Ellipsize = Pango.EllipsizeMode.End;
 
+			hbox.PackStart (label, true, true, 0);
+			var okButton = new Button (Gtk.Stock.Ok);
+			okButton.WidthRequest = 60;
+			hbox.PackEnd (okButton, false, false, 0); 
 
 			var combo = new ComboBox(new [] {
-				string.Format ("Convert this file to {0} line endings", GetEolString(textEditor.Options.DefaultEolMarker)),
-				string.Format ("Keep {0} line endings", GetEolString(DetectedEolMarker)),
+				string.Format ("Convert to {0} line endings", GetEolString(textEditor.Options.DefaultEolMarker)),
 				string.Format ("Convert all files to {0} line endings", GetEolString(textEditor.Options.DefaultEolMarker)),
+				string.Format ("Keep {0} line endings", GetEolString(DetectedEolMarker)),
 				string.Format ("Keep {0} line endings in all files", GetEolString(DetectedEolMarker))
 			});
 			combo.Active = 0;
-			hbox.PackEnd (combo);
+			hbox.PackEnd (combo, false, false, 0);
 			var container = new HBox ();
-			container.PackStart (hbox, true, true, 8); 
+			const int containerPadding = 8;
+			container.PackStart (hbox, true, true, containerPadding); 
 			window.Child = container; 
 			window.ShowOverlay (this.TextEditor);
 
+			window.SizeFunc = () => {
+				return okButton.SizeRequest ().Width +
+					combo.SizeRequest ().Width +
+					image.SizeRequest ().Width +
+					w +
+					hbox.Spacing * 4 + 
+					containerPadding * 2;
+			};
+			image.Clicked += delegate {
+				UseIncorrectMarkers = true;
+				view.WorkbenchWindow.ShowNotification = false;
+				window.Destroy ();
+			};
 			okButton.Clicked += delegate {
 				switch (combo.Active) {
 				case 0:
@@ -971,11 +988,11 @@ void ShowIncorretEolMarkers (string fileName, bool multiple)
 					view.Save (fileName, view.SourceEncoding);
 					break;
 				case 1:
-					UseIncorrectMarkers = true;
-					view.WorkbenchWindow.ShowNotification = false;
+					FileRegistry.ConvertLineEndingsInAllFiles ();
 					break;
 				case 2:
-					FileRegistry.ConvertLineEndingsInAllFiles ();
+					UseIncorrectMarkers = true;
+					view.WorkbenchWindow.ShowNotification = false;
 					break;
 				case 3:
 					FileRegistry.IgnoreLineEndingsInAllFiles ();
@@ -983,60 +1000,6 @@ void ShowIncorretEolMarkers (string fileName, bool multiple)
 				}
 				window.Destroy ();
 			};
-
-			/*
-			 if (messageBar == null) {
-				messageBar = new InfoBar (MessageType.Warning);
-				string detectedEol = DetectedEolMarker.Replace ("\n", "NL").Replace ("\r", "CR");
-				string defaultEol = textEditor.Options.DefaultEolMarker.Replace ("\n", "NL").Replace ("\r", "CR");
-				messageBar.SetMessageLabel (GettextCatalog.GetString (
-					"<b>The file \"{0}\" has line endings (" + detectedEol + ") which differ from the policy settings(" + defaultEol + ").</b>\n" +
-					"Do you want to convert the line endings?",
-					EllipsizeMiddle (Document.FileName, 50)));
-				
-				Button b1 = new Button (GettextCatalog.GetString ("_Convert"));
-				b1.Image = ImageService.GetImage (Gtk.Stock.Refresh, IconSize.Button);
-				b1.Clicked += delegate(object sender, EventArgs e) {
-					ConvertLineEndings ();
-					view.WorkbenchWindow.ShowNotification = false;
-					RemoveMessageBar ();
-					view.Save (fileName, view.SourceEncoding);
-				};
-				messageBar.ActionArea.Add (b1);
-				
-				Button b2 = new Button (GettextCatalog.GetString ("_Keep line endings"));
-				b2.Image = ImageService.GetImage (Gtk.Stock.Cancel, IconSize.Button);
-				b2.Clicked += delegate(object sender, EventArgs e) {
-					UseIncorrectMarkers = true;
-					view.WorkbenchWindow.ShowNotification = false;
-					RemoveMessageBar ();
-					view.Save (fileName, view.SourceEncoding);
-				};
-				messageBar.ActionArea.Add (b2);
-
-				if (multiple) {
-					var b3 = new Button (GettextCatalog.GetString ("_Convert all files"));
-					b3.Image = ImageService.GetImage (Gtk.Stock.Cancel, IconSize.Button);
-					b3.Clicked += delegate {
-						FileRegistry.ConvertLineEndingsInAllFiles ();
-					};
-					messageBar.ActionArea.Add (b3);
-	
-					var b4 = new Button (GettextCatalog.GetString ("_Keep in all files"));
-					b4.Image = ImageService.GetImage (Gtk.Stock.Cancel, IconSize.Button);
-					b4.Clicked += delegate {
-						FileRegistry.IgnoreLineEndingsInAllFiles ();
-					};
-					messageBar.ActionArea.Add (b4);
-				}
-
-			}
-			
-			vbox.PackStart (messageBar, false, false, CHILD_PADDING);
-			vbox.ReorderChild (messageBar, 0);
-			messageBar.ShowAll ();
-
-			messageBar.QueueDraw ();*/
 		}
 		#endregion
 		public void ShowAutoSaveWarning (string fileName)
_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.