1
/* $Id: winefish.c 1984 2006-02-17 13:32:56Z kyanh $ */
3
/* Winefish LaTeX Editor (based on Bluefish HTML Editor)
5
* Original File: bluefish.c - the main function
7
* Copyright (C) 1998 Olivier Sessink and Chris Mazuc
8
* Copyright (C) 1999-2004 Olivier Sessink
9
* Modified for Winefish (C) 2005 Ky Anh <kyanh@o2.pl>
11
* This program is free software; you can redistribute it and/or modify
12
* it under the terms of the GNU General Public License as published by
13
* the Free Software Foundation; either version 2 of the License, or
14
* (at your option) any later version.
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU General Public License for more details.
21
* You should have received a copy of the GNU General Public License
22
* along with this program; if not, write to the Free Software
23
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28
#include <unistd.h> /* getopt() */
29
#include <stdlib.h> /* getopt() exit() and abort() on Solaris */
30
#include <time.h> /* nanosleep */
31
#include <string.h> /* strcmp */
35
#ifdef HAVE_ATLEAST_GNOMEUI_2_6
36
#include <libgnomeui/libgnomeui.h>
43
#include "document.h" /* */
44
#include "gui.h" /* gui_create_main() */
45
#include "fref.h" /* fref_init() */
46
#include "bookmark.h" /* bmark_init() */
47
#include "rcfile.h" /* rcfile_parse_main() */
48
#include "bf_lib.h" /* create_full_path() */
49
#include "highlight.h" /* hl_init() */
50
#include "msg_queue.h" /* msg_queue_start()*/
51
#include "stringlist.h" /* put_stringlist(), get_stringlist() */
52
#include "gtk_easy.h" /* flush_queue() */
53
#include "filebrowser.h" /* filters_rebuild() */
55
/* kyanh, removed, 20050309 */
56
/*#include "authen.h" *//* set_authen_callbacks() */
57
#include "autox.h" /* kyanh, completion */
58
#include "snooper.h" /* snooper_install() */
60
/*********************************************/
61
/* this var is global for all bluefish files */
62
/*********************************************/
65
/********************************/
66
/* functions used in bluefish.c */
67
/********************************/
69
void g_none(gchar *first, ...) {
74
static gint parse_commandline(int argc, char **argv
75
, gboolean *root_override
76
, GList **load_filenames
77
, GList **load_projects
78
, gboolean *open_in_new_win
85
DEBUG_MSG("parse_commandline, started\n");
86
while ((c = getopt(argc, argv, "hsvn:l:p:?")) != -1) {
92
g_print(CURRENT_VERSION_NAME);
97
tmpname = create_full_path(optarg, NULL);
98
*load_projects = g_list_append(*load_projects, tmpname);
101
*linenumber = strtoul(optarg, NULL,10);
105
g_print(CURRENT_VERSION_NAME);
106
g_print(_("\nUsage: %s [options] [filenames ...]\n"), argv[0]);
107
g_print(_("\nCurrently accepted options are:\n"));
108
g_print(_("-s skip root check\n"));
109
g_print(_("-v current version\n"));
110
g_print(_("-n 0|1 open new window (1) or not (0)\n"));
111
g_print(_("-p filename open project\n"));
112
g_print(_("-l number set line<number>. Negative value takes no effect.\n"));
113
g_print(_("-h this help screen\n"));
117
if (strncmp(optarg,"0",1)==0) {
118
*open_in_new_win = 0;
120
*open_in_new_win = 1;
124
DEBUG_MSG("parse_commandline, abort ?!?\n");
128
DEBUG_MSG("parse_commandline, optind=%d, argc=%d\n", optind, argc);
129
while (optind < argc) {
130
/* related to BUG#93 */
131
/*if (file_exists_and_readable(argv[optind])){*/
132
tmpname = create_full_path(argv[optind], NULL);
133
DEBUG_MSG("parse_commandline, argv[%d]=%s, tmpname=%s\n", optind, argv[optind], tmpname);
134
*load_filenames = g_list_append(*load_filenames, tmpname);
136
g_print("winefish: file '%s' is unreadable\n", argv[optind]);
140
DEBUG_MSG("parse_commandline, finished, num files=%d, num projects=%d\n"
141
, g_list_length(*load_filenames), g_list_length(*load_projects));
146
/*********************/
147
/* the main function */
148
/*********************/
150
int main(int argc, char *argv[])
152
gboolean root_override=FALSE, open_in_new_window = FALSE;
153
GList *filenames = NULL, *projectfiles=NULL;
154
gint linenumber = -1;
158
GtkWidget *splash_window;
159
#endif /* #ifndef NOSPLASH */
162
setlocale(LC_ALL,"");
163
bindtextdomain(PACKAGE,LOCALEDIR);
164
DEBUG_MSG("set bindtextdomain for %s to %s\n",PACKAGE,LOCALEDIR);
165
bind_textdomain_codeset(PACKAGE, "UTF-8");
168
#ifdef HAVE_ATLEAST_GNOMEUI_2_6
169
gnome_init(PACKAGE, VERSION, argc, argv);
171
gtk_init(&argc, &argv);
172
#endif /* HAVE_ATLEAST_GNOMEUI_2_6
174
main_v = g_new0(Tmain, 1);
175
main_v->session = g_new0(Tsessionvars,1);
176
DEBUG_MSG("main, main_v is at %p\n", main_v);
178
rcfile_check_directory();
181
parse_commandline(argc, argv, &root_override, &filenames, &projectfiles, &open_in_new_window, &linenumber);
182
#ifdef WITH_MSG_QUEUE
183
if (((filenames || projectfiles) && (main_v->props.view_bars & MODE_REUSE_WINDOW)) || open_in_new_window) {
184
msg_queue_start(filenames, projectfiles, linenumber, open_in_new_window);
186
#endif /* WITH_MSG_QUEUE */
188
/* start splash screen somewhere here */
189
splash_window = start_splash_screen();
190
splash_screen_set_label(_("parsing highlighting file..."));
191
#endif /* #ifndef NOSPLASH */
194
gchar *filename = g_strconcat(g_get_home_dir(), "/.winefish/dir_history", NULL);
195
main_v->recent_directories = get_stringlist(filename, NULL);
198
rcfile_parse_global_session();
199
rcfile_parse_highlighting();
201
splash_screen_set_label(_("compiling highlighting patterns..."));
202
#endif /* #ifndef NOSPLASH */
205
splash_screen_set_label(_("initialize some other things..."));
206
#endif /* #ifndef NOSPLASH */
207
filebrowserconfig_init();
208
filebrowser_filters_rebuild();
211
splash_screen_set_label(_("parsing autotext and words file..."));
212
#endif /* #ifndef NOSPLASH */
216
splash_screen_set_label(_("parsing custom menu file..."));
217
#endif /* #ifndef NOSPLASH */
218
rcfile_parse_custom_menu(FALSE,FALSE);
219
main_v->tooltips = gtk_tooltips_new();
220
/* initialize the completion window */
221
main_v->completion.window = NULL;
224
#ifdef WITH_MSG_QUEUE
225
if (!filenames && !projectfiles && (main_v->props.view_bars & MODE_REUSE_WINDOW)) {
226
msg_queue_start(NULL, NULL, -1, open_in_new_window);
228
#endif /* WITH_MSG_QUEUE */
230
splash_screen_set_label(_("creating main gui..."));
231
#endif /* #ifndef NOSPLASH */
233
/* create the first window */
234
firstbfwin = g_new0(Tbfwin,1);
235
firstbfwin->session = main_v->session;
236
firstbfwin->bookmarkstore = main_v->bookmarkstore;
237
main_v->bfwinlist = g_list_append(NULL, firstbfwin);
238
gui_create_main(firstbfwin, filenames, linenumber);
239
bmark_reload(firstbfwin);
241
splash_screen_set_label(_("showing main gui..."));
242
#endif /* #ifndef NOSPLASH */
244
/* set GTK settings, must be AFTER the menu is created */
246
gchar *shortcutfilename;
247
GtkSettings* gtksettings = gtk_settings_get_default();
248
g_object_set(G_OBJECT(gtksettings), "gtk-can-change-accels", TRUE, NULL);
249
shortcutfilename = g_strconcat(g_get_home_dir(), "/.winefish/menudump_2", NULL);
250
gtk_accel_map_load(shortcutfilename);
251
g_free(shortcutfilename);
254
gui_show_main(firstbfwin);
256
if (main_v->props.view_html_toolbar && main_v->globses.quickbar_items == NULL) {
257
info_dialog(firstbfwin->main_window, _("Winefish tip:"), _("This message is shown since you DONOT have any items in the QuickBar.\n\nIf you right-click a button in the Standard toolbars you can add buttons to the Quickbar."));
261
GList *tmplist = g_list_first(projectfiles);
263
project_open_from_file(firstbfwin, tmplist->data, linenumber);
264
tmplist = g_list_next(tmplist);
269
DEBUG_MSG("destroy splash\n");
272
static struct timespec const req = { 0, 10000000};
273
nanosleep(&req, NULL);
275
gtk_widget_destroy(splash_window);
276
#endif /* #ifndef NOSPLASH */
278
/* snooper must be installed after the main gui has shown;
279
otherwise the program may be aborted */
282
DEBUG_MSG("main, before gtk_main()\n");
284
DEBUG_MSG("main, after gtk_main()\n");
285
#ifdef WITH_MSG_QUEUE
288
#endif /* WITH_MSG_QUEUE */
289
DEBUG_MSG("Winefish: exiting cleanly\n");
293
void bluefish_exit_request() {
298
DEBUG_MSG("winefish_exit_request, started\n");
299
/* if we have modified documents we have to do something, file_close_all_cb()
300
does exactly want we want to do */
301
tmplist = return_allwindows_documentlist();
302
tmpb = (tmplist && test_docs_modified(tmplist));
303
g_list_free(tmplist);
304
tmplist = g_list_first(main_v->bfwinlist);
306
/* if there is a project, we anyway want to save & close the project */
307
if (BFWIN(tmplist->data)->project) {
308
if (!project_save_and_close(BFWIN(tmplist->data))) {
309
/* cancelled or error! */
310
DEBUG_MSG("winefish_exit_request, project_save_and_close returned FALSE\n");
315
file_close_all_cb(NULL, BFWIN(tmplist->data));
317
tmplist = g_list_next(tmplist);
319
/* if we still have modified documents we don't do a thing,
320
if we don't have them we can quit */
322
tmplist = return_allwindows_documentlist();
323
tmpb = (tmplist && test_docs_modified(tmplist));
324
g_list_free(tmplist);
329
/* gtk_widget_hide(main_v->main_window);*/
331
tmplist = g_list_first(gtk_window_list_toplevels());
335
if (GTK_IS_WIDGET(tmplist->data)) {
336
role = g_strdup(gtk_window_get_role ((GtkWindow*)tmplist->data));
337
gtk_widget_hide(GTK_WIDGET(tmplist->data));
338
if (role && strncmp(role,"html_dialog",11) ==0) {
339
window_destroy(GTK_WIDGET(tmplist->data));
342
/* g_print("type = %s, role=%s\n", GTK_OBJECT_TYPE_NAME((GtkObject*) tmplist->data), role); */
343
tmplist = g_list_next(tmplist);
351
gchar *filename = g_strconcat(g_get_home_dir(), "/.winefish/dir_history", NULL);
352
put_stringlist_limited(filename, main_v->recent_directories, main_v->props.max_dir_history);