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

GtkProjectServiceExtension.cs « MonoDevelop.GtkCore.GuiBuilder « MonoDevelop.GtkCore « addins « src « main - github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 35cbbfb921d7bc8072a24e1e85f08864fadc83d9 (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

using System;
using System.Threading;
using MonoDevelop.Core;
using MonoDevelop.Projects;
using MonoDevelop.Ide;
using System.Threading.Tasks;

namespace MonoDevelop.GtkCore.GuiBuilder
{
	public class GtkProjectServiceExtension: DotNetProjectExtension
	{
		protected override bool SupportsObject (WorkspaceObject item)
		{
			if (!IdeApp.IsInitialized)
				return false;
			
			DotNetProject project = item as DotNetProject;
			return project != null && GtkDesignInfo.HasDesignedObjects (project);
		}

		protected async override Task<BuildResult> OnBuild (ProgressMonitor monitor, ConfigurationSelector configuration)
		{
			GtkDesignInfo info = GtkDesignInfo.FromProject (Project);

			Generator gen = new Generator ();
			if (!await gen.Run (monitor, Project, configuration)) {
				BuildResult gr = new BuildResult ();
				foreach (string s in gen.Messages)
					gr.AddError (info.GuiBuilderProject.File, 0, 0, null, s);
				return gr;
			}
					
			BuildResult res = await base.OnBuild (monitor, configuration);

			if (gen.Messages != null) {
				foreach (string s in gen.Messages)
					res.AddWarning (info.GuiBuilderProject.File, 0, 0, null, s);
						
				if (gen.Messages.Length > 0)
					info.ForceCodeGenerationOnBuild ();
			}
			
			if (res.Failed && !Platform.IsWindows && !Platform.IsMac) {
				// Some gtk# packages don't include the .pc file unless you install gtk-sharp-devel
				if (Project.AssemblyContext.GetPackage ("gtk-sharp-2.0") == null) {
					string msg = GettextCatalog.GetString (
						"ERROR: MonoDevelop could not find the Gtk# 2.0 development package. " +
						"Compilation of projects depending on Gtk# libraries will fail. " +
						"You may need to install development packages for gtk-sharp-2.0.");
					monitor.Log.WriteLine ();
					monitor.Log.WriteLine (BrandingService.BrandApplicationName (msg));
				}
			}
			
			return res;
		}
	}
	
	class Generator
	{
		public async Task<bool> Run (ProgressMonitor monitor, DotNetProject project, ConfigurationSelector configuration)
		{
			try {
				Stetic.CodeGenerationResult res = await GuiBuilderService.GenerateSteticCode (monitor, project, configuration);
				if (res != null) {
					Messages = res.Warnings;
					return true;
				} else {
					Messages = new [] { GettextCatalog.GetString ("Code generation failed") };
					return false;
				}
			} catch (Exception ex) {
				Error = ex;
				LoggingService.LogError (ex.ToString ());
				Messages = new  [] { Error.Message };
				return false;
			}
		}
		public string[] Messages;
		public Exception Error;
	}
}