forked from MonoGame/MonoGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Global.Linux.cs
200 lines (169 loc) · 7.21 KB
/
Global.Linux.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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Eto.Drawing;
using Eto.Forms;
using Eto.GtkSharp.Drawing;
using Gtk;
namespace MonoGame.Tools.Pipeline
{
static partial class Gtk3Wrapper
{
public const string giolibpath = "libgio-2.0.so.0";
[DllImport(giolibpath, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr g_file_query_info(IntPtr gfile, string attributes, int flag, IntPtr cancelable, IntPtr error);
[DllImport(giolibpath, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr g_file_new_for_path(string path);
[DllImport(gtklibpath, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr gtk_app_chooser_dialog_new(IntPtr parrent, int flags, IntPtr file);
[DllImport(gtklibpath, CallingConvention = CallingConvention.Cdecl)]
public static extern bool gtk_application_prefers_app_menu(IntPtr application);
}
static partial class Global
{
private static IconTheme _theme;
private static Gdk.Pixbuf _iconMissing;
private static Gtk.Application _app;
private static void PlatformInit()
{
Linux = true;
_theme = IconTheme.Default;
try
{
_iconMissing = _theme.LoadIcon("dialog-error", 16, 0);
}
catch
{
_iconMissing = new Gdk.Pixbuf(null, "TreeView.Missing.png");
}
if (Gtk.Global.MajorVersion >= 3 && Gtk.Global.MinorVersion >= 16)
{
_app = new Gtk.Application(null, GLib.ApplicationFlags.None);
_app.Register(GLib.Cancellable.Current);
UseHeaderBar = Gtk3Wrapper.gtk_application_prefers_app_menu(_app.Handle);
}
}
private static void PlatformShowOpenWithDialog(string filePath)
{
var adialoghandle = Gtk3Wrapper.gtk_app_chooser_dialog_new(((Gtk.Window)MainWindow.Instance.ControlObject).Handle,
4 + (int)DialogFlags.Modal,
Gtk3Wrapper.g_file_new_for_path(filePath));
var adialog = new AppChooserDialog(adialoghandle);
if (adialog.Run() == (int)ResponseType.Ok)
Process.Start(adialog.AppInfo.Executable, "\"" + filePath + "\"");
adialog.Destroy();
}
private static Eto.Drawing.Image PlatformGetDirectoryIcon(bool exists)
{
var icon = _theme.LoadIcon("folder", 16, 0);
if (!exists)
{
icon = icon.Copy();
_iconMissing.Composite(icon, 8, 8, 8, 8, 8, 8, 0.5, 0.5, Gdk.InterpType.Tiles, 255);
}
return new Bitmap(new BitmapHandler(icon));
}
private static Eto.Drawing.Image PlatformGetFileIcon(string path, bool exists)
{
Gdk.Pixbuf icon = null;
try
{
var info = new GLib.FileInfo(Gtk3Wrapper.g_file_query_info(Gtk3Wrapper.g_file_new_for_path(path), "standard::*", 0, new IntPtr(), new IntPtr()));
var sicon = info.Icon.ToString().Split(' ');
for (int i = sicon.Length - 1; i >= 1; i--)
{
try
{
icon = _theme.LoadIcon(sicon[i], 16, 0);
if (icon != null)
break;
}
catch { }
}
}
catch { }
if (icon == null)
icon = _theme.LoadIcon("text-x-generic", 16, 0);
if (!exists)
{
icon = icon.Copy();
_iconMissing.Composite(icon, 8, 8, 8, 8, 8, 8, 0.5, 0.5, Gdk.InterpType.Tiles, 255);
}
return new Bitmap(new BitmapHandler(icon));
}
private static bool PlatformSetIcon(Command cmd)
{
IconInfo iconInfo = null;
Gdk.Pixbuf icon = null;
try
{
switch (cmd.MenuText)
{
case "New...":
iconInfo = _theme.LookupIcon("document-new-symbolic", 16, 0);
break;
case "Open...":
iconInfo = _theme.LookupIcon("document-open-symbolic", 16, 0);
break;
case "Save...":
iconInfo = _theme.LookupIcon("document-save-symbolic", 16, 0);
break;
case "Undo":
iconInfo = _theme.LookupIcon("edit-undo-symbolic", 16, 0);
break;
case "Redo":
iconInfo = _theme.LookupIcon("edit-redo-symbolic", 16, 0);
break;
case "New Item...":
iconInfo = _theme.LookupIcon("document-new-symbolic", 16, 0);
break;
case "New Folder...":
iconInfo = _theme.LookupIcon("folder-new-symbolic", 16, 0);
break;
case "Existing Item...":
iconInfo = _theme.LookupIcon("folder-documents-symbolic", 16, 0);
break;
case "Existing Folder...":
iconInfo = _theme.LookupIcon("folder-open-symbolic", 16, 0);
break;
case "Build":
iconInfo = _theme.LookupIcon("emblem-system-symbolic", 16, 0);
break;
case "Rebuild":
iconInfo = _theme.LookupIcon("system-run-symbolic", 16, 0);
break;
case "Cancel Build":
iconInfo = _theme.LookupIcon("media-playback-stop-symbolic", 16, 0);
break;
case "Clean":
iconInfo = _theme.LookupIcon("edit-clear-symbolic", 16, 0);
break;
case "Filter Output":
iconInfo = _theme.LookupIcon("format-indent-more-symbolic", 16, 0);
break;
}
if (iconInfo != null)
{
var colText = SystemColors.ControlText;
bool ws;
var col = new Gdk.RGBA();
col.Red = colText.R;
col.Green = colText.G;
col.Blue = colText.B;
col.Alpha = colText.A;
icon = iconInfo.LoadSymbolic(col, col, col, col, out ws);
}
}
catch { }
if (icon != null)
{
cmd.Image = new Bitmap(new BitmapHandler(icon));
return true;
}
return false;
}
}
}