This repository has been archived by the owner on Oct 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
GtkProjectServiceExtension.cs
71 lines (60 loc) · 1.91 KB
/
GtkProjectServiceExtension.cs
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
using System;
using System.Threading;
using MonoDevelop.Core;
using MonoDevelop.Projects;
using MonoDevelop.Ide;
namespace MonoDevelop.GtkCore.GuiBuilder
{
public class GtkProjectServiceExtension: ProjectServiceExtension
{
public override bool SupportsItem (IBuildTarget item)
{
if (!IdeApp.IsInitialized)
return false;
DotNetProject project = item as DotNetProject;
return project != null && GtkDesignInfo.HasDesignedObjects (project);
}
protected override BuildResult Build (IProgressMonitor monitor, SolutionEntityItem entry, ConfigurationSelector configuration)
{
DotNetProject project = (DotNetProject) entry;
GtkDesignInfo info = GtkDesignInfo.FromProject (project);
// The code generator must run in the GUI thread since it needs to
// access to Gtk classes
Generator gen = new Generator ();
lock (gen) {
Gtk.Application.Invoke (delegate { gen.Run (monitor, project, configuration); });
Monitor.Wait (gen);
}
BuildResult res = base.Build (monitor, entry, configuration);
if (gen.Messages != null) {
foreach (string s in gen.Messages)
// res.AddWarning (info.GuiBuilderProject.File, 0, 0, null, s);
// TODO: Add gtkx file name in the Generator
res.AddWarning ("", 0, 0, null, s);
if (gen.Messages.Length > 0)
info.ForceCodeGenerationOnBuild ();
}
return res;
}
}
class Generator
{
public void Run (IProgressMonitor monitor, DotNetProject project, ConfigurationSelector configuration)
{
lock (this) {
try {
Stetic.CodeGenerationResult res = GuiBuilderService.GenerateSteticCode (monitor, project, configuration);
if (res != null)
Messages = res.Warnings;
} catch (Exception ex) {
Error = ex;
LoggingService.LogError (ex.ToString ());
Messages = new string [] { Error.Message };
}
Monitor.PulseAll (this);
}
}
public string[] Messages;
public Exception Error;
}
}