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

WelcomePageSection.cs « MonoDevelop.Ide.WelcomePage « MonoDevelop.Ide « core « src « main - github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 02401d3679046f2a92786545ea48a4e4c1346f27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//
// WelcomePageSection.cs
//
// Author:
//       lluis <${AuthorEmail}>
//
// Copyright (c) 2012 lluis
//
// 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 System.Xml.Linq;
using MonoDevelop.Core;
using MonoDevelop.Components;

namespace MonoDevelop.Ide.WelcomePage
{
	public class WelcomePageSection: EventBox
	{
		string title;

		static readonly string headerFormat;

		Alignment root = new Alignment (0, 0, 1f, 1f);
		protected Gtk.Alignment ContentAlignment { get; private set; }
		protected Gtk.Alignment TitleAlignment { get; private set; }

		static WelcomePageSection ()
		{
			var face = Platform.IsMac ? Styles.WelcomeScreen.Pad.TitleFontFamilyMac : Styles.WelcomeScreen.Pad.TitleFontFamilyWindows;
			headerFormat = Styles.GetFormatString (face, Styles.WelcomeScreen.Pad.LargeTitleFontSize, Styles.WelcomeScreen.Pad.LargeTitleFontColor);
		}

		public WelcomePageSection (string title = null)
		{
			this.title = title;
			VisibleWindow = false;
			Add (root);
			root.Show ();

			uint p = Styles.WelcomeScreen.Pad.ShadowSize * 2;
			root.SetPadding (p, p, p, p);

			TitleAlignment = new Alignment (0f, 0f, 1f, 1f);
			p = Styles.WelcomeScreen.Pad.Padding;
			TitleAlignment.SetPadding (p, Styles.WelcomeScreen.Pad.LargeTitleMarginBottom, p, p);
			ContentAlignment = new Alignment (0f, 0f, 1f, 1f);
			ContentAlignment.SetPadding (0, p, p, p);
		}

		public void SetContent (Gtk.Widget w)
		{
			ContentAlignment.Add (w);

			if (string.IsNullOrEmpty (title)) {
				ContentAlignment.TopPadding = Styles.WelcomeScreen.Pad.Padding;
				root.Add (ContentAlignment);
				return;
			}

			var box = new VBox ();
			var label = new Gtk.Label () { Markup = string.Format (headerFormat, title), Xalign = (uint) 0 };
			TitleAlignment.Add (label);
			box.PackStart (TitleAlignment, false, false, 0);
			box.PackStart (ContentAlignment, false, false, 0);
			root.Add (box);
		}

		protected override bool OnExposeEvent (Gdk.EventExpose evnt)
		{
			using (var ctx = Gdk.CairoHelper.Create (evnt.Window)) {
				ctx.LineWidth = 1;
				var rect = new Gdk.Rectangle (Allocation.X, Allocation.Y, Allocation.Width, Allocation.Height);

				var shadowColor = CairoExtensions.ParseColor (Styles.WelcomeScreen.Pad.ShadowColor);
				int inset = 2;
				var ss = Styles.WelcomeScreen.Pad.ShadowSize; 
				var r = new Cairo.Rectangle (rect.X + ss + 0.5, rect.Y + ss + 0.5, rect.Width - ss * 2 - 1, rect.Height - ss * 2 - 1);
				var sr = new Cairo.Rectangle (r.X + inset, r.Y + inset + Styles.WelcomeScreen.Pad.ShadowVerticalOffset, r.Width - inset * 2, r.Height - inset * 2);
				int size = Styles.WelcomeScreen.Pad.ShadowSize;
				double alpha = 0.2;
				double alphaDec = 0.2 / (double)size;
				for (int n=0; n<size; n++) {
					sr = new Cairo.Rectangle (sr.X - 1, sr.Y - 1, sr.Width + 2, sr.Height + 2);
					CairoExtensions.RoundedRectangle (ctx, sr.X, sr.Y, sr.Width, sr.Height, 4);
					shadowColor.A = alpha;
					ctx.SetSourceColor (shadowColor);
					ctx.Stroke ();
					alpha -= alphaDec;
				}

				CairoExtensions.RoundedRectangle (ctx, r.X, r.Y, r.Width, r.Height, 4);
				ctx.SetSourceColor (CairoExtensions.ParseColor (Styles.WelcomeScreen.Pad.BackgroundColor));
				ctx.FillPreserve ();
				ctx.SetSourceColor (CairoExtensions.ParseColor (Styles.WelcomeScreen.Pad.BorderColor));
				ctx.Stroke ();
			}

			PropagateExpose (Child, evnt);
			return true;
		}

		public static string FormatText (string fontFace, int fontSize, Pango.Weight weight, string color, string text)
		{
			var format = Styles.GetFormatString (fontFace, fontSize, color, weight);
			return string.Format (format, GLib.Markup.EscapeText (text));
		}

		public static void DispatchLink (string uri)
		{
			try {
				if (uri.StartsWith ("project://")) {
					string projectUri = uri.Substring ("project://".Length);			
					Uri fileuri = new Uri (projectUri);
					Gdk.ModifierType mtype = GtkWorkarounds.GetCurrentKeyModifiers ();
					bool inWorkspace = (mtype & Gdk.ModifierType.ControlMask) != 0;

					// Notify the RecentFiles that this item does not exist anymore.
					// Possible other solution would be to check the recent projects list on focus in
					// and update them accordingly.
					if (!System.IO.File.Exists (fileuri.LocalPath)) {
						MessageService.ShowError (GettextCatalog.GetString ("File not found {0}", fileuri.LocalPath));
						FileService.NotifyFileRemoved (fileuri.LocalPath);
						return;
					}

					IdeApp.Workspace.OpenWorkspaceItem (fileuri.LocalPath, !inWorkspace);
				} else if (uri.StartsWith ("monodevelop://")) {
					var cmdId = uri.Substring ("monodevelop://".Length);
					IdeApp.CommandService.DispatchCommand (cmdId, MonoDevelop.Components.Commands.CommandSource.WelcomePage);
				} else {
					DesktopService.ShowUrl (uri);
				}
			} catch (Exception ex) {
				LoggingService.LogInternalError (GettextCatalog.GetString ("Could not open the url '{0}'", uri), ex);
			}
		}
	}
}