[Monodevelop-patches-list] r478 - trunk/MonoDevelop/src/Main/Base/Gui/Dialogs

commit-watcher at mono-cvs.ximian.com commit-watcher at mono-cvs.ximian.com
Tue Jan 13 17:01:02 EST 2004


Author: dkor
Date: 2004-01-13 17:01:02 -0500 (Tue, 13 Jan 2004)
New Revision: 478

Modified:
   trunk/MonoDevelop/src/Main/Base/Gui/Dialogs/TipOfTheDay.cs
Log:
Initial port of the "Tip of the Day" dialog port to Gtk


Modified: trunk/MonoDevelop/src/Main/Base/Gui/Dialogs/TipOfTheDay.cs
===================================================================
--- trunk/MonoDevelop/src/Main/Base/Gui/Dialogs/TipOfTheDay.cs	2004-01-13 03:52:41 UTC (rev 477)
+++ trunk/MonoDevelop/src/Main/Base/Gui/Dialogs/TipOfTheDay.cs	2004-01-13 22:01:02 UTC (rev 478)
@@ -1,7 +1,7 @@
 // <file>
 //     <copyright see="prj:///doc/copyright.txt"/>
 //     <license see="prj:///doc/license.txt"/>
-//     <owner name="Mike Krüger" email="mike at icsharpcode.net"/>
+//     <owner name="Mike Krüger" email="mike at icsharpcode.net"/>
 //     <version value="$version"/>
 // </file>
 
@@ -9,182 +9,116 @@
 using System.Drawing;
 using System.ComponentModel;
 using System.Resources;
-using System.Windows.Forms;
 using System.Xml;
 using System.IO;
 
+using Gtk;
+using GtkSharp;
+
 using ICSharpCode.SharpDevelop.Gui;
 using ICSharpCode.Core.Properties;
 using ICSharpCode.Core.Services;
 
 namespace ICSharpCode.SharpDevelop.Gui.Dialogs
 {
-	public class TipOfTheDayView : UserControl
+	public class TipOfTheDayView : Frame
 	{
-		readonly int ICON_DISTANCE = 16;
-		Bitmap   icon      = null;
-		Font     titlefont;
-		Font     textfont;
+
+		TextBuffer buffer;
 		string[] tips;
-		int      curtip = 0;
-		
-		string didyouknowtext;
+		int curtip = 0;
 		ResourceService resourceService = (ResourceService)ServiceManager.Services.GetService(typeof(IResourceService));
 		
-		public TipOfTheDayView(XmlElement el)
+		public TipOfTheDayView(XmlElement el) : base ()
 		{
-			titlefont = resourceService.LoadFont("Times new Roman", 15, FontStyle.Bold);
-			textfont  = resourceService.LoadFont("Times new Roman", 12);
+
+ 			XmlNodeList nodes = el.ChildNodes;
+ 			StringParserService stringParserService = (StringParserService)ServiceManager.Services.GetService(typeof(StringParserService));
+ 			tips = new string[nodes.Count];
 			
-			this.didyouknowtext = resourceService.GetString("Dialog.TipOfTheDay.DidYouKnowText");
+ 			for (int i = 0; i < nodes.Count; ++i) {
+ 				tips[i] = stringParserService.Parse(nodes[i].InnerText);
+ 			}
 			
-			//icon   = resourceService.GetBitmap("Icons.TipOfTheDayIcon");
+ 			curtip = (new Random().Next()) % nodes.Count;
+
+			TextView view = new TextView ();
+			view.WrapMode = WrapMode.Word;
+			buffer = view.Buffer;
+			buffer.InsertAtCursor(tips[curtip]);
+
+			this.Add(view);
 			
-			//			XmlNodeList nodes = el.GetElementsByTagName("TIP");
-			XmlNodeList nodes = el.ChildNodes;
-			
-			StringParserService stringParserService = (StringParserService)ServiceManager.Services.GetService(typeof(StringParserService));
-			tips = new string[nodes.Count];
-			for (int i = 0; i < nodes.Count; ++i) {
-				tips[i] = stringParserService.Parse(nodes[i].InnerText);
-			}
-			
-			curtip = (new Random().Next()) % nodes.Count;
-			
 		}
 		
-		protected override void OnPaintBackground(PaintEventArgs pe)
-		{
-		}
-		
-		protected override void OnPaint(PaintEventArgs pe)
-		{
-			Graphics g = pe.Graphics;
-			
-			g.FillRectangle(Brushes.Gray, 0,
-			                0,
-			                icon.Width + ICON_DISTANCE,
-			                Height);
-			g.FillRectangle(Brushes.White, 0 + icon.Width + ICON_DISTANCE,
-			                0,
-			                Width - icon.Width - ICON_DISTANCE,
-			                Height);
-			g.DrawImage(icon, 2 + ICON_DISTANCE / 2, 4);
-			
-			g.DrawString(didyouknowtext, titlefont, Brushes.Black, icon.Width + ICON_DISTANCE + 4, 8);
-			
-			g.DrawLine(Pens.Black, new Point(icon.Width + ICON_DISTANCE, 8 + titlefont.Height + 2),
-			           new Point(Width, 8 + titlefont.Height + 2));
-			drawrect = new Rectangle(icon.Width + ICON_DISTANCE, 8 + titlefont.Height + 6,
-			                         Width - icon.Width - ICON_DISTANCE, Height - (8 + titlefont.Height + 6));
-			
-			g.DrawString(tips[curtip], textfont, Brushes.Black, drawrect);
-		}
-		Rectangle drawrect;
-		
 		public void NextTip()
 		{
-			curtip = (curtip + 1) % tips.Length;
-			Invalidate(drawrect);
-			Update();
+			buffer.Clear();
+ 			curtip = (curtip + 1) % tips.Length;
+			buffer.InsertAtCursor(tips[curtip]);
 		}
 	}
 	
-	public class TipOfTheDayDialog : Form
+	public class TipOfTheDayDialog  : MessageDialog
 	{
-		CheckBox viewTipsAtStartCheckBox;
-		Button   closeButton;
-		Button   nextTipButton;
+
+		enum UserDefinedResponseType {Next=1, Show}
+
+ 		CheckButton viewTipsAtStartCheckBox;
+ 		Button   closeButton;
+ 		Button   nextTipButton;
 		
-		Panel panel = new Panel();
-		TipOfTheDayView tipview;
-		ResourceService resourceService = (ResourceService)ServiceManager.Services.GetService(typeof(IResourceService));
-		PropertyService propertyService = (PropertyService)ServiceManager.Services.GetService(typeof(PropertyService));
-		
-		void NextTip(object sender, EventArgs e)
+ 		TipOfTheDayView tipview;
+ 		ResourceService resourceService = (ResourceService)ServiceManager.Services.GetService(typeof(IResourceService));
+ 		PropertyService propertyService = (PropertyService)ServiceManager.Services.GetService(typeof(PropertyService));
+
+		public TipOfTheDayDialog(string didyouknowtext) :  base ((Window) WorkbenchSingleton.Workbench,
+				                    DialogFlags.Modal,
+				                    MessageType.Info,
+				                    ButtonsType.None,
+				                    didyouknowtext)
 		{
-			tipview.NextTip();
-		}
-		
-		void CheckChange(object sender, EventArgs e)
-		{
-			propertyService.SetProperty("ICSharpCode.SharpDevelop.Gui.Dialog.TipOfTheDayView.ShowTipsAtStartup", viewTipsAtStartCheckBox.Checked);
-		}
-		
-		public TipOfTheDayDialog()
-		{
-			InitializeComponent();
-			StartPosition = FormStartPosition.CenterScreen;
+			this.SetDefaultSize (320, 240);
+
+			viewTipsAtStartCheckBox = new CheckButton("Show tips at startup");
+ 			viewTipsAtStartCheckBox.Active = propertyService.GetProperty(
+				"ICSharpCode.SharpDevelop.Gui.Dialog.TipOfTheDayView.ShowTipsAtStartup", true);
+			this.AddActionWidget(viewTipsAtStartCheckBox, (int) UserDefinedResponseType.Show);
+
+			nextTipButton = (Button) this.AddButton ("_Next Tip", (int) UserDefinedResponseType.Next);
+			closeButton = (Button) this.AddButton (Stock.Close, (int) ResponseType.Close);
 			
-			Icon = null;
-			FileUtilityService fileUtilityService = (FileUtilityService)ServiceManager.Services.GetService(typeof(FileUtilityService));
-			PropertyService propertyService = (PropertyService)ServiceManager.Services.GetService(typeof(PropertyService));
+ 			FileUtilityService fileUtilityService = (FileUtilityService)ServiceManager.Services.GetService(typeof(FileUtilityService));
+ 			PropertyService propertyService = (PropertyService)ServiceManager.Services.GetService(typeof(PropertyService));
 			
-			XmlDocument doc = new XmlDocument();
-			doc.Load(propertyService.DataDirectory +
-			         Path.DirectorySeparatorChar + "options" +
-			         Path.DirectorySeparatorChar + "TipsOfTheDay.xml" );
-			
-			tipview = new TipOfTheDayView(doc.DocumentElement);
-			panel.Controls.Add(tipview);
-			//			panel.FormBorderStyle = FormBorderStyle.Fixed3D;
-			Controls.Add(panel);
-			
-			panel.Width  = tipview.Width  = Width - 24;
-			panel.Height = tipview.Height = nextTipButton.Top - 15;
-			panel.Location = new Point(8, 5);
-			nextTipButton.Click += new EventHandler(NextTip);
-			
-			viewTipsAtStartCheckBox.CheckedChanged += new EventHandler(CheckChange);
-			viewTipsAtStartCheckBox.Checked = propertyService.GetProperty("ICSharpCode.SharpDevelop.Gui.Dialog.TipOfTheDayView.ShowTipsAtStartup", true);
-			
-			MaximizeBox  = MinimizeBox = false;
-			ShowInTaskbar = false;
+ 			XmlDocument doc = new XmlDocument();
+ 			doc.Load(propertyService.DataDirectory +
+ 			         System.IO.Path.DirectorySeparatorChar + "options" +
+ 			         System.IO.Path.DirectorySeparatorChar + "TipsOfTheDay.xml" );
+ 			tipview = new TipOfTheDayView(doc.DocumentElement);
+
+			this.Response += new ResponseHandler (HandleResponse);
+
+ 			this.VBox.PackStart(tipview);
+			this.ShowAll();
 		}
-		
-		void ExitDialog(object sender, EventArgs e)
+
+		public void HandleResponse (object sender, ResponseArgs e)
 		{
-			Close();
-			Dispose();
+			switch (e.ResponseId) 
+			{
+			case (int) ResponseType.Close : 
+				this.Hide ();
+				break;
+			case (int) UserDefinedResponseType.Next : 
+				tipview.NextTip();
+				break;
+			case (int) UserDefinedResponseType.Show : 
+				propertyService.SetProperty("ICSharpCode.SharpDevelop.Gui.Dialog.TipOfTheDayView.ShowTipsAtStartup", 
+						viewTipsAtStartCheckBox.Active);
+				break;
+			}
 		}
 		
-		private void InitializeComponent()
-		{
-			this.closeButton = new Button();
-			this.viewTipsAtStartCheckBox = new CheckBox();
-			this.nextTipButton = new Button();
-			
-			closeButton.Location = new System.Drawing.Point(328, 232);
-			closeButton.Click  += new EventHandler(ExitDialog);
-			closeButton.Size = new System.Drawing.Size(80, 24);
-			closeButton.TabIndex = 1;
-			closeButton.Text = resourceService.GetString("Global.CloseButtonText");
-			closeButton.FlatStyle = FlatStyle.System;
-			
-			viewTipsAtStartCheckBox.Location = new System.Drawing.Point(8, 232);
-			viewTipsAtStartCheckBox.Text = resourceService.GetString("Dialog.TipOfTheDay.checkBox1Text");
-			viewTipsAtStartCheckBox.Size = new System.Drawing.Size(210, 24);
-			//			viewTipsAtStartCheckBox.AccessibleRole = AccessibleRoles.CheckButton;
-			viewTipsAtStartCheckBox.TabIndex = 2;
-			viewTipsAtStartCheckBox.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
-			viewTipsAtStartCheckBox.FlatStyle = FlatStyle.System;
-			
-			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
-			this.Text = resourceService.GetString("Dialog.TipOfTheDay.DialogName");
-			//@design this.TrayLargeIcon = true;
-			this.FormBorderStyle = FormBorderStyle.FixedDialog;
-			//@design this.TrayHeight = 0;
-			this.ClientSize = new System.Drawing.Size(418, 263);
-			
-			nextTipButton.Location = new System.Drawing.Point(240 - 16, 232);
-			nextTipButton.Size = new System.Drawing.Size(96, 24);
-			nextTipButton.TabIndex = 0;
-			nextTipButton.Text = resourceService.GetString("Dialog.TipOfTheDay.button1Text");
-			nextTipButton.FlatStyle = FlatStyle.System;
-			
-			this.Controls.Add(viewTipsAtStartCheckBox);
-			this.Controls.Add(closeButton);
-			this.Controls.Add(nextTipButton);
-		}
 	}
 }




More information about the Monodevelop-patches-list mailing list