File: ProjectManagerMain.cpp

package info (click to toggle)
sludge 2.2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 6,908 kB
  • sloc: cpp: 32,441; sh: 1,237; xml: 874; makefile: 681
file content (300 lines) | stat: -rw-r--r-- 7,791 bytes parent folder | download | duplicates (2)
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
/* -*- Mode: C++; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
 * ProjectManagerMain.cpp - Part of the SLUDGE Project Manager (GTK+ version)
 *
 * Copyright (C) 2010 Tobias Hansen <tobias.han@gmx.de>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <gdk/gdkkeysyms.h>
#include <glib-object.h>
#include <glib.h>

#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#include <GL/glu.h>

#include <errno.h>
#include <sys/types.h>

#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

#include <getopt.h>

#include "ProjectManagerMain.h"
#include "SludgeProjectManager.h"
#include "Common.h"

SludgeProjectManager *projectManager;

#ifdef __cplusplus
extern "C" {
#endif

// SludgeApplication callbacks:

G_MODULE_EXPORT gboolean on_window1_delete_event(GtkWidget *theWidget, GdkEvent *theEvent, gpointer theUser_data)
{
	return projectManager->on_window1_delete_event();
}

G_MODULE_EXPORT void on_new(GtkMenuItem *theItem, gpointer theUser_data)
{
	projectManager->on_new();
}

G_MODULE_EXPORT void on_open(GtkMenuItem *theItem, gpointer theUser_data)
{
	projectManager->on_open();
}

G_MODULE_EXPORT void on_save(GtkMenuItem *theItem, gpointer theUser_data)
{
	projectManager->on_save();
}

G_MODULE_EXPORT void on_save_as(GtkMenuItem *theItem, gpointer theUser_data)
{
	projectManager->on_save_as();
}

G_MODULE_EXPORT void
on_about(GtkMenuItem *theItem, gpointer theUser_data)
{
	projectManager->on_about();
}

// SludgeProjectManager callbacks:

G_MODULE_EXPORT void on_files_treeview_realize(GtkTreeView *theTreeView, gpointer theUser_data)
{
	projectManager->on_treeview_realize(theTreeView, FILE_TREEVIEW);
}

G_MODULE_EXPORT void on_resources_treeview_realize(GtkTreeView *theTreeView, gpointer theUser_data)
{
	projectManager->on_treeview_realize(theTreeView, RESOURCE_TREEVIEW);
}

G_MODULE_EXPORT void on_errors_treeview_realize(GtkTreeView *theTreeView, gpointer theUser_data)
{
	projectManager->on_treeview_realize(theTreeView, ERROR_TREEVIEW);
}

G_MODULE_EXPORT void
on_files_tree_selection_changed_cb(GtkTreeSelection *theSelection, gpointer theUser_data)
{
	projectManager->on_files_tree_selection_changed(theSelection);
}

G_MODULE_EXPORT void
on_files_treeview_row_activated(GtkTreeView *theTreeView, GtkTreePath *thePath, GtkTreeViewColumn *theColumn, gpointer theUser_data)
{
	projectManager->on_treeview_row_activated(theTreeView, thePath, theColumn, FILE_TREEVIEW);
}

G_MODULE_EXPORT void
on_resources_treeview_row_activated(GtkTreeView *theTreeView, GtkTreePath *thePath, GtkTreeViewColumn *theColumn, gpointer theUser_data)
{
	projectManager->on_treeview_row_activated(theTreeView, thePath, theColumn, RESOURCE_TREEVIEW);
}

G_MODULE_EXPORT void
on_errors_treeview_row_activated(GtkTreeView *theTreeView, GtkTreePath *thePath, GtkTreeViewColumn *theColumn, gpointer theUser_data)
{
	projectManager->on_treeview_row_activated(theTreeView, thePath, theColumn, ERROR_TREEVIEW);
}

G_MODULE_EXPORT void on_add_file_clicked(GtkButton *theButton, gpointer theUser_data)
{
	projectManager->on_add_file_clicked();
}

G_MODULE_EXPORT void on_remove_file_clicked(GtkButton *theButton, gpointer theUser_data)
{
	projectManager->on_remove_file_clicked();
}

G_MODULE_EXPORT void on_compile(GtkMenuItem *theItem, gpointer theUser_data)
{
	projectManager->on_compile();
}

G_MODULE_EXPORT void on_comp_okbutton_clicked(GtkButton *theButton, gpointer theUser_data)
{
	projectManager->on_comp_okbutton_clicked(theButton);
}

G_MODULE_EXPORT void on_comp_gamebutton_clicked(GtkButton *theButton, gpointer theUser_data)
{
	projectManager->on_comp_gamebutton_clicked();
}

G_MODULE_EXPORT void on_project_settings(GtkMenuItem *theItem, gpointer theUser_data)
{
	projectManager->on_project_settings();
}

G_MODULE_EXPORT void on_preferences(GtkMenuItem *theItem, gpointer theUser_data)
{
	projectManager->on_preferences();
}

G_MODULE_EXPORT void on_floormaker_activate(GtkMenuItem *theItem, gpointer theUser_data)
{
	projectManager->on_program_activate(FLOORMAKER);
}

G_MODULE_EXPORT void on_spritebankeditor_activate(GtkMenuItem *theItem, gpointer theUser_data)
{
	projectManager->on_program_activate(SPRITEBANKEDITOR);
}

G_MODULE_EXPORT void on_zbuffermaker_activate(GtkMenuItem *theItem, gpointer theUser_data)
{
	projectManager->on_program_activate(ZBUFFERMAKER);
}

G_MODULE_EXPORT void on_translationeditor_activate(GtkMenuItem *theItem, gpointer theUser_data)
{
	projectManager->on_program_activate(TRANSLATIONEDITOR);
}

G_MODULE_EXPORT void *compile_hook(gpointer nothing)
{
	projectManager->compile();
}

G_MODULE_EXPORT gboolean update_compile_window_hook(gpointer nothing)
{
	projectManager->update_compile_window();
	return FALSE;
}

void receiveCompilerInfo(compilerInfo *info)
{
	g_async_queue_push(projectManager->compilerInfoQueue, info);
	g_idle_add(update_compile_window_hook, NULL);
}

G_MODULE_EXPORT gboolean on_project_settings_dialog_delete_event(GtkWidget *theWidget, GdkEvent  *theEvent, gpointer theUser_data)
{
	return gtk_widget_hide_on_delete(theWidget);
}

G_MODULE_EXPORT gboolean on_preferences_dialog_delete_event(GtkWidget *theWidget, GdkEvent  *theEvent, gpointer theUser_data)
{
	return gtk_widget_hide_on_delete(theWidget);
}

G_MODULE_EXPORT gboolean on_compiler_dialog_delete_event(GtkWidget *theWidget, GdkEvent  *theEvent, gpointer theUser_data)
{
	return gtk_widget_hide_on_delete(theWidget);
}
#ifdef __cplusplus
}
#endif

void printCmdlineUsage() {
	fprintf(stdout, "SLUDGE Project Manager, usage: sludge-projectmanager <project file>\n");
}

bool parseCmdlineParameters(int argc, char *argv[]) {
	int retval = true;
	while (1)
	{
		static struct option long_options[] =
		{
			{"help",	no_argument,	   0, 'h' },
			{0,0,0,0} /* This is a filler for -1 */
		};
		int option_index = 0;
		int c = getopt_long(argc, argv, "h", long_options, &option_index);
		if (c == -1) break;
			switch (c) {
		case 'h':
		default:
			retval = false;
			break;
		}
	}
	return retval;
}


/*
 * The main function.
 */
int
main(int argc, char *argv[])
{
	char *openThisFile = argv[argc - 1];

	if (! parseCmdlineParameters(argc, argv) ) {
		printCmdlineUsage();
		return 0;
	}

	if (argc < 2) {
		openThisFile = NULL;
	} else if (! fileExists(openThisFile) ) {
		errorBox("Project file not found!", joinTwoStrings("File not found:\n", openThisFile));
		printCmdlineUsage();
		return -1;
	}

	// On Windows, change to the program directory to
	// make sure the necessary resource files are found:
	winChangeToProgramDir(argv[0]);

	if (!g_thread_supported ()){ g_thread_init (NULL); }
	gdk_threads_init ();
	gdk_threads_enter ();

	/*
	 * Init GTK+.
	 */
	gtk_init(&argc, &argv);

	projectManager = new SludgeProjectManager();

	/*
	 * Get the window manager to connect any assigned signals in the loaded Glade file to our coded functions.
	 */
	gtk_builder_connect_signals(projectManager->theXml, NULL);

	/*
	 * Show the window.
	 */
	gtk_widget_show(projectManager->theWindow);

	if (openThisFile != NULL) {
		projectManager->open(openThisFile);
	}

	// Run the window manager loop.
	if (projectManager->initSuccess)
		gtk_main ();

	delete projectManager;

	gdk_threads_leave ();

	return 0;
}