2005-11-22 12:26:26 +00:00
/*
* main . c - this file is part of Geany , a fast and lightweight IDE
*
2007-01-14 17:36:42 +00:00
* Copyright 2005 - 2007 Enrico Tröger < enrico . troeger @ uvena . de >
* Copyright 2006 - 2007 Nick Treleaven < nick . treleaven @ btinternet . com >
2005-11-22 12:26:26 +00:00
*
* 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 2 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 , write to the Free Software
2006-05-22 00:25:19 +00:00
* Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
2005-11-22 12:26:26 +00:00
*
2005-11-30 23:33:35 +00:00
* $ Id $
2005-11-22 12:26:26 +00:00
*/
2007-02-24 11:41:56 +00:00
/*
* Program initialization and cleanup .
*/
2005-11-22 12:26:26 +00:00
# include <signal.h>
# include <time.h>
2006-02-10 21:06:41 +00:00
# include <sys/types.h>
# include <sys/stat.h>
# include <errno.h>
# include <string.h>
2006-03-18 17:35:53 +00:00
# include <stdlib.h>
2005-11-27 20:54:28 +00:00
2005-11-22 12:26:26 +00:00
# include "geany.h"
2007-06-25 17:49:45 +00:00
# if HAVE_LOCALE_H
# include <locale.h>
# endif
2006-09-04 11:16:07 +00:00
# include "main.h"
2007-08-23 11:34:06 +00:00
# include "prefs.h"
2005-11-22 12:26:26 +00:00
# include "interface.h"
# include "support.h"
# include "callbacks.h"
2006-09-05 14:24:47 +00:00
# include "ui_utils.h"
2005-11-22 12:26:26 +00:00
# include "utils.h"
# include "document.h"
2007-08-15 15:37:21 +00:00
# include "filetypes.h"
2005-11-22 12:26:26 +00:00
# include "keyfile.h"
# include "win32.h"
# include "msgwindow.h"
# include "dialogs.h"
# include "templates.h"
# include "encodings.h"
# include "treeviews.h"
2006-06-16 11:17:52 +00:00
# include "notebook.h"
2006-06-16 19:58:26 +00:00
# include "keybindings.h"
2007-05-28 16:07:30 +00:00
# include "editor.h"
2006-08-11 21:12:49 +00:00
# include "search.h"
2006-10-18 19:35:42 +00:00
# include "build.h"
2006-10-21 11:34:18 +00:00
# include "highlighting.h"
2006-12-15 17:09:05 +00:00
# include "symbols.h"
2007-01-16 15:22:24 +00:00
# include "project.h"
2007-02-25 14:26:55 +00:00
# include "tools.h"
2007-06-02 16:14:07 +00:00
# include "navqueue.h"
2007-06-26 16:17:16 +00:00
# include "plugins.h"
2007-11-17 14:04:27 +00:00
# include "printing.h"
2006-06-16 19:58:26 +00:00
2006-09-07 15:51:24 +00:00
# ifdef HAVE_SOCKET
# include "socket.h"
# endif
2006-01-03 12:47:08 +00:00
# ifdef HAVE_VTE
2005-11-27 20:54:28 +00:00
# include "vte.h"
# endif
2005-11-22 12:26:26 +00:00
2007-06-25 17:49:45 +00:00
# ifndef N_
# define N_(String) (String)
# endif
2006-08-20 12:33:09 +00:00
2006-08-30 18:36:17 +00:00
2007-08-23 11:34:06 +00:00
GeanyApp * app ;
2007-07-19 11:49:53 +00:00
2007-08-23 11:34:06 +00:00
GeanyStatus main_status ;
2006-09-04 11:16:07 +00:00
CommandLineOptions cl_options ; // fields initialised in parse_command_line_options
2007-07-19 11:49:53 +00:00
2007-08-16 15:20:38 +00:00
static gboolean want_plugins ;
// command-line options
2006-02-20 22:59:42 +00:00
static gboolean debug_mode = FALSE ;
2005-11-22 12:26:26 +00:00
static gboolean ignore_global_tags = FALSE ;
2006-03-15 23:19:45 +00:00
static gboolean no_msgwin = FALSE ;
2005-11-22 12:26:26 +00:00
static gboolean show_version = FALSE ;
static gchar * alternate_config = NULL ;
2006-01-14 22:38:06 +00:00
# ifdef HAVE_VTE
2006-05-22 00:25:19 +00:00
static gboolean no_vte = FALSE ;
2006-01-06 18:41:01 +00:00
static gchar * lib_vte = NULL ;
2006-01-14 22:38:06 +00:00
# endif
2006-09-07 15:51:24 +00:00
# ifdef HAVE_SOCKET
static gboolean ignore_socket = FALSE ;
# endif
2006-08-01 21:07:46 +00:00
static gboolean generate_datafiles = FALSE ;
2007-03-21 13:26:16 +00:00
static gboolean generate_tags = FALSE ;
2007-09-28 11:48:55 +00:00
static gboolean no_preprocessing = FALSE ;
2007-06-17 17:56:48 +00:00
static gboolean ft_names = FALSE ;
2007-11-11 09:09:47 +00:00
# ifdef HAVE_PLUGINS
2007-07-05 12:15:54 +00:00
static gboolean no_plugins = FALSE ;
2007-11-11 09:09:47 +00:00
# endif
2006-08-01 21:07:46 +00:00
2007-07-05 12:15:54 +00:00
// in alphabetical order of short options
2005-11-22 12:26:26 +00:00
static GOptionEntry entries [ ] =
{
2007-07-05 12:28:24 +00:00
{ " column " , 0 , 0 , G_OPTION_ARG_INT , & cl_options . goto_column , N_ ( " Set initial column number for the first opened file (useful in conjunction with --line) " ) , NULL } ,
{ " config " , ' c ' , 0 , G_OPTION_ARG_FILENAME , & alternate_config , N_ ( " Use an alternate configuration directory " ) , NULL } ,
{ " debug " , ' d ' , 0 , G_OPTION_ARG_NONE , & debug_mode , N_ ( " Runs in debug mode (means being verbose) " ) , NULL } ,
{ " ft-names " , 0 , 0 , G_OPTION_ARG_NONE , & ft_names , N_ ( " Print internal filetype names " ) , NULL } ,
{ " generate-tags " , ' g ' , 0 , G_OPTION_ARG_NONE , & generate_tags , N_ ( " Generate global tags file (see documentation) " ) , NULL } ,
2007-09-28 11:48:55 +00:00
{ " no-preprocessing " , ' P ' , 0 , G_OPTION_ARG_NONE , & no_preprocessing , NULL , NULL } ,
{ " generate-data-files " , 0 , G_OPTION_FLAG_HIDDEN , G_OPTION_ARG_NONE , & generate_datafiles , NULL , NULL } ,
2006-08-30 18:36:17 +00:00
# ifdef HAVE_SOCKET
2007-07-05 12:28:24 +00:00
{ " new-instance " , ' i ' , 0 , G_OPTION_ARG_NONE , & ignore_socket , N_ ( " Don't open files in a running instance, force opening a new instance " ) , NULL } ,
2006-02-20 22:59:42 +00:00
# endif
2007-07-05 12:28:24 +00:00
{ " line " , ' l ' , 0 , G_OPTION_ARG_INT , & cl_options . goto_line , N_ ( " Set initial line number for the first opened file " ) , NULL } ,
{ " no-msgwin " , ' m ' , 0 , G_OPTION_ARG_NONE , & no_msgwin , N_ ( " Don't show message window at startup " ) , NULL } ,
{ " no-ctags " , ' n ' , 0 , G_OPTION_ARG_NONE , & ignore_global_tags , N_ ( " Don't load auto completion data (see documentation) " ) , NULL } ,
2007-11-11 09:09:47 +00:00
# ifdef HAVE_PLUGINS
2007-07-05 12:28:24 +00:00
{ " no-plugins " , ' p ' , 0 , G_OPTION_ARG_NONE , & no_plugins , N_ ( " Don't load plugins " ) , NULL } ,
2007-11-11 09:09:47 +00:00
# endif
2006-10-03 13:16:42 +00:00
{ " no-session " , ' s ' , G_OPTION_FLAG_REVERSE , G_OPTION_ARG_NONE , & cl_options . load_session , N_ ( " don't load the previous session's files " ) , NULL } ,
2006-01-06 18:41:01 +00:00
# ifdef HAVE_VTE
2007-07-05 12:28:24 +00:00
{ " no-terminal " , ' t ' , 0 , G_OPTION_ARG_NONE , & no_vte , N_ ( " Don't load terminal support " ) , NULL } ,
{ " vte-lib " , 0 , 0 , G_OPTION_ARG_FILENAME , & lib_vte , N_ ( " Filename of libvte.so " ) , NULL } ,
2006-01-06 18:41:01 +00:00
# endif
2007-07-05 12:28:24 +00:00
{ " version " , ' v ' , 0 , G_OPTION_ARG_NONE , & show_version , N_ ( " Show version and exit " ) , NULL } ,
2006-04-27 18:05:57 +00:00
{ NULL , 0 , 0 , 0 , NULL , NULL , NULL }
2005-11-22 12:26:26 +00:00
} ;
2006-02-10 21:06:41 +00:00
/* Geany main debug function */
2005-11-22 12:26:26 +00:00
void geany_debug ( gchar const * format , . . . )
{
# ifndef GEANY_DEBUG
2006-04-29 23:55:50 +00:00
if ( app ! = NULL & & app - > debug_mode )
2005-11-22 12:26:26 +00:00
# endif
{
va_list args ;
va_start ( args , format ) ;
g_logv ( G_LOG_DOMAIN , G_LOG_LEVEL_INFO , format , args ) ;
va_end ( args ) ;
}
}
/* special things for the initial setup of the checkboxes and related stuff
2005-12-28 15:42:31 +00:00
* an action on a setting is only performed if the setting is not equal to the program default
2005-11-22 12:26:26 +00:00
* ( all the following code is not perfect but it works for the moment ) */
2006-02-10 21:06:41 +00:00
static void apply_settings ( void )
2005-11-22 12:26:26 +00:00
{
2006-09-05 14:24:47 +00:00
ui_update_fold_items ( ) ;
2006-02-26 18:19:28 +00:00
2006-07-21 11:41:33 +00:00
// toolbar, message window and sidebar are by default visible, so don't change it if it is true
2007-08-23 11:34:06 +00:00
if ( ! prefs . toolbar_visible )
2005-11-22 12:26:26 +00:00
{
2006-07-21 11:41:33 +00:00
app - > ignore_callback = TRUE ;
2005-11-22 12:26:26 +00:00
gtk_check_menu_item_set_active ( GTK_CHECK_MENU_ITEM ( lookup_widget ( app - > window , " menu_show_toolbar1 " ) ) , FALSE ) ;
gtk_widget_hide ( app - > toolbar ) ;
2006-07-21 11:41:33 +00:00
app - > ignore_callback = FALSE ;
2005-11-22 12:26:26 +00:00
}
2007-08-23 11:34:06 +00:00
if ( ! ui_prefs . msgwindow_visible )
2006-02-06 06:28:31 +00:00
{
2006-07-21 11:41:33 +00:00
app - > ignore_callback = TRUE ;
2006-02-06 06:28:31 +00:00
gtk_check_menu_item_set_active ( GTK_CHECK_MENU_ITEM ( lookup_widget ( app - > window , " menu_show_messages_window1 " ) ) , FALSE ) ;
2006-07-21 11:41:33 +00:00
gtk_widget_hide ( lookup_widget ( app - > window , " scrolledwindow1 " ) ) ;
app - > ignore_callback = FALSE ;
2006-02-06 06:28:31 +00:00
}
2007-08-23 11:34:06 +00:00
if ( ! ui_prefs . sidebar_visible )
2006-07-21 11:41:33 +00:00
{
app - > ignore_callback = TRUE ;
gtk_check_menu_item_set_active ( GTK_CHECK_MENU_ITEM ( lookup_widget ( app - > window , " menu_show_sidebar1 " ) ) , FALSE ) ;
app - > ignore_callback = FALSE ;
}
2006-09-05 14:24:47 +00:00
ui_treeviews_show_hide ( TRUE ) ;
2005-12-16 23:25:44 +00:00
// sets the icon style of the toolbar
2007-08-23 11:34:06 +00:00
switch ( prefs . toolbar_icon_style )
2005-11-22 12:26:26 +00:00
{
case GTK_TOOLBAR_BOTH :
{
//gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(app->window, "images_and_text1")), TRUE);
2007-08-23 11:34:06 +00:00
gtk_check_menu_item_set_active ( GTK_CHECK_MENU_ITEM ( lookup_widget ( ui_widgets . toolbar_menu , " images_and_text2 " ) ) , TRUE ) ;
2005-11-22 12:26:26 +00:00
break ;
}
case GTK_TOOLBAR_ICONS :
{
//gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(app->window, "images_only1")), TRUE);
2007-08-23 11:34:06 +00:00
gtk_check_menu_item_set_active ( GTK_CHECK_MENU_ITEM ( lookup_widget ( ui_widgets . toolbar_menu , " images_only2 " ) ) , TRUE ) ;
2005-11-22 12:26:26 +00:00
break ;
}
case GTK_TOOLBAR_TEXT :
{
//gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(app->window, "text_only1")), TRUE);
2007-08-23 11:34:06 +00:00
gtk_check_menu_item_set_active ( GTK_CHECK_MENU_ITEM ( lookup_widget ( ui_widgets . toolbar_menu , " text_only2 " ) ) , TRUE ) ;
2005-11-22 12:26:26 +00:00
break ;
}
}
2007-08-23 11:34:06 +00:00
gtk_toolbar_set_style ( GTK_TOOLBAR ( app - > toolbar ) , prefs . toolbar_icon_style ) ;
2005-11-22 12:26:26 +00:00
// sets the icon size of the toolbar, use user preferences (.gtkrc) if not set
2007-08-23 11:34:06 +00:00
if ( prefs . toolbar_icon_size = = GTK_ICON_SIZE_SMALL_TOOLBAR | |
prefs . toolbar_icon_size = = GTK_ICON_SIZE_LARGE_TOOLBAR )
2005-11-22 12:26:26 +00:00
{
2007-08-23 11:34:06 +00:00
gtk_toolbar_set_icon_size ( GTK_TOOLBAR ( app - > toolbar ) , prefs . toolbar_icon_size ) ;
2005-11-22 12:26:26 +00:00
}
2007-08-23 11:34:06 +00:00
ui_update_toolbar_icons ( prefs . toolbar_icon_size ) ;
2005-11-22 12:26:26 +00:00
2006-02-14 21:58:42 +00:00
// line number and markers margin are by default enabled
2007-08-23 11:34:06 +00:00
if ( ! editor_prefs . show_markers_margin )
2005-11-22 12:26:26 +00:00
{
gtk_check_menu_item_set_active ( GTK_CHECK_MENU_ITEM ( lookup_widget ( app - > window , " menu_markers_margin1 " ) ) , FALSE ) ;
2007-08-23 11:34:06 +00:00
editor_prefs . show_markers_margin = FALSE ;
2005-11-22 12:26:26 +00:00
}
2007-08-23 11:34:06 +00:00
if ( ! editor_prefs . show_linenumber_margin )
2005-11-22 12:26:26 +00:00
{
2006-02-14 21:58:42 +00:00
gtk_check_menu_item_set_active ( GTK_CHECK_MENU_ITEM ( lookup_widget ( app - > window , " menu_linenumber_margin1 " ) ) , FALSE ) ;
2007-08-23 11:34:06 +00:00
editor_prefs . show_linenumber_margin = FALSE ;
2005-11-22 12:26:26 +00:00
}
2006-02-14 21:58:42 +00:00
2005-11-22 12:26:26 +00:00
// interprets the saved window geometry
2007-08-23 11:34:06 +00:00
if ( prefs . save_winpos & & ui_prefs . geometry [ 0 ] ! = - 1 )
2005-11-22 12:26:26 +00:00
{
2007-08-23 11:34:06 +00:00
gtk_window_move ( GTK_WINDOW ( app - > window ) , ui_prefs . geometry [ 0 ] , ui_prefs . geometry [ 1 ] ) ;
gtk_window_set_default_size ( GTK_WINDOW ( app - > window ) , ui_prefs . geometry [ 2 ] , ui_prefs . geometry [ 3 ] ) ;
if ( ui_prefs . geometry [ 4 ] = = 1 )
2007-06-04 15:37:11 +00:00
gtk_window_maximize ( GTK_WINDOW ( app - > window ) ) ;
2005-11-22 12:26:26 +00:00
}
2007-04-10 17:06:57 +00:00
// hide statusbar if desired
2007-08-23 11:34:06 +00:00
if ( ! prefs . statusbar_visible )
2007-04-10 17:06:57 +00:00
{
gtk_widget_hide ( app - > statusbar ) ;
}
2006-07-24 20:23:56 +00:00
app - > ignore_callback = TRUE ;
gtk_check_menu_item_set_active ( GTK_CHECK_MENU_ITEM (
2007-08-24 16:20:33 +00:00
lookup_widget ( app - > window , " menu_line_breaking1 " ) ) , editor_prefs . line_wrapping ) ;
2006-07-24 20:23:56 +00:00
gtk_check_menu_item_set_active ( GTK_CHECK_MENU_ITEM (
2007-06-12 15:16:17 +00:00
lookup_widget ( app - > window , " menu_use_auto_indentation1 " ) ) ,
( editor_prefs . indent_mode ! = INDENT_NONE ) ) ;
2006-07-24 20:23:56 +00:00
app - > ignore_callback = FALSE ;
2006-02-20 22:59:42 +00:00
2007-05-25 14:42:43 +00:00
// connect the toolbar dropdown menu for the new button
2006-02-20 22:59:42 +00:00
gtk_menu_tool_button_set_menu ( GTK_MENU_TOOL_BUTTON (
2007-08-23 11:34:06 +00:00
lookup_widget ( app - > window , " menutoolbutton1 " ) ) , ui_widgets . new_file_menu ) ;
2006-07-02 16:21:35 +00:00
// set the tab placements of the notebooks
2007-08-23 11:34:06 +00:00
gtk_notebook_set_tab_pos ( GTK_NOTEBOOK ( app - > notebook ) , prefs . tab_pos_editor ) ;
gtk_notebook_set_tab_pos ( GTK_NOTEBOOK ( msgwindow . notebook ) , prefs . tab_pos_msgwin ) ;
gtk_notebook_set_tab_pos ( GTK_NOTEBOOK ( app - > treeview_notebook ) , prefs . tab_pos_sidebar ) ;
2006-07-11 14:15:56 +00:00
2006-09-05 14:24:47 +00:00
ui_update_toolbar_items ( ) ;
2006-11-11 18:51:33 +00:00
2006-10-29 01:28:58 +00:00
// whether to show notebook tabs or not
2007-08-23 11:34:06 +00:00
gtk_notebook_set_show_tabs ( GTK_NOTEBOOK ( app - > notebook ) , prefs . show_notebook_tabs ) ;
2005-11-22 12:26:26 +00:00
}
2006-02-26 18:19:28 +00:00
static void main_init ( void )
2005-11-22 12:26:26 +00:00
{
// inits
2006-02-10 21:06:41 +00:00
app - > window = NULL ;
2007-01-15 18:12:32 +00:00
app - > project = NULL ;
2007-11-20 18:15:46 +00:00
app - > active_plugins = NULL ;
2007-08-23 11:34:06 +00:00
ui_widgets . open_fontsel = NULL ;
2007-11-20 18:15:46 +00:00
ui_widgets . open_colorsel = NULL ;
2007-08-23 11:34:06 +00:00
ui_widgets . open_filesel = NULL ;
ui_widgets . save_filesel = NULL ;
ui_widgets . prefs_dialog = NULL ;
tv . default_tag_tree = NULL ;
main_status . main_window_realized = FALSE ;
prefs . tab_order_ltr = FALSE ;
main_status . quitting = FALSE ;
2006-07-24 20:23:56 +00:00
app - > ignore_callback = FALSE ;
2007-11-01 11:49:29 +00:00
app - > tm_workspace = tm_get_workspace ( app - > configdir ) ;
2007-08-23 11:34:06 +00:00
ui_prefs . recent_queue = g_queue_new ( ) ;
main_status . opening_session_files = FALSE ;
2005-11-22 12:26:26 +00:00
app - > window = create_window1 ( ) ;
2007-08-23 11:34:06 +00:00
ui_widgets . new_file_menu = gtk_menu_new ( ) ;
ui_widgets . recent_files_toolbar = gtk_menu_new ( ) ;
ui_widgets . recent_files_menuitem = lookup_widget ( app - > window , " recent_files1 " ) ;
ui_widgets . recent_files_menubar = gtk_menu_new ( ) ;
gtk_menu_item_set_submenu ( GTK_MENU_ITEM ( ui_widgets . recent_files_menuitem ) ,
ui_widgets . recent_files_menubar ) ;
2007-11-17 14:04:27 +00:00
// store important pointers for later reference
2005-11-22 12:26:26 +00:00
app - > toolbar = lookup_widget ( app - > window , " toolbar1 " ) ;
app - > treeview_notebook = lookup_widget ( app - > window , " notebook3 " ) ;
app - > notebook = lookup_widget ( app - > window , " notebook1 " ) ;
app - > statusbar = lookup_widget ( app - > window , " statusbar " ) ;
app - > popup_menu = create_edit_menu1 ( ) ;
2007-08-23 11:34:06 +00:00
ui_widgets . toolbar_menu = create_toolbar_popup_menu1 ( ) ;
2007-11-17 14:04:27 +00:00
ui_widgets . print_page_setup = lookup_widget ( app - > window , " page_setup1 " ) ;
2007-08-23 11:34:06 +00:00
ui_widgets . popup_goto_items [ 0 ] = lookup_widget ( app - > popup_menu , " goto_tag_definition1 " ) ;
ui_widgets . popup_goto_items [ 1 ] = lookup_widget ( app - > popup_menu , " goto_tag_declaration1 " ) ;
ui_widgets . popup_goto_items [ 2 ] = lookup_widget ( app - > popup_menu , " find_usage1 " ) ;
2007-09-12 16:01:23 +00:00
ui_widgets . popup_copy_items [ 0 ] = lookup_widget ( app - > popup_menu , " cut1 " ) ;
ui_widgets . popup_copy_items [ 1 ] = lookup_widget ( app - > popup_menu , " copy1 " ) ;
ui_widgets . popup_copy_items [ 2 ] = lookup_widget ( app - > popup_menu , " delete1 " ) ;
2007-08-23 11:34:06 +00:00
ui_widgets . menu_copy_items [ 0 ] = lookup_widget ( app - > window , " menu_cut1 " ) ;
ui_widgets . menu_copy_items [ 1 ] = lookup_widget ( app - > window , " menu_copy1 " ) ;
ui_widgets . menu_copy_items [ 2 ] = lookup_widget ( app - > window , " menu_delete1 " ) ;
ui_widgets . menu_insert_include_items [ 0 ] = lookup_widget ( app - > popup_menu , " insert_include1 " ) ;
ui_widgets . menu_insert_include_items [ 1 ] = lookup_widget ( app - > window , " insert_include2 " ) ;
ui_widgets . save_buttons [ 0 ] = lookup_widget ( app - > window , " menu_save1 " ) ;
ui_widgets . save_buttons [ 1 ] = lookup_widget ( app - > window , " toolbutton10 " ) ;
ui_widgets . save_buttons [ 2 ] = lookup_widget ( app - > window , " menu_save_all1 " ) ;
ui_widgets . save_buttons [ 3 ] = lookup_widget ( app - > window , " toolbutton22 " ) ;
ui_widgets . redo_items [ 0 ] = lookup_widget ( app - > popup_menu , " redo1 " ) ;
ui_widgets . redo_items [ 1 ] = lookup_widget ( app - > window , " menu_redo2 " ) ;
ui_widgets . redo_items [ 2 ] = lookup_widget ( app - > window , " toolbutton_redo " ) ;
ui_widgets . undo_items [ 0 ] = lookup_widget ( app - > popup_menu , " undo1 " ) ;
ui_widgets . undo_items [ 1 ] = lookup_widget ( app - > window , " menu_undo2 " ) ;
ui_widgets . undo_items [ 2 ] = lookup_widget ( app - > window , " toolbutton_undo " ) ;
2007-05-04 15:33:07 +00:00
2007-07-20 12:06:51 +00:00
ui_init ( ) ;
2007-05-04 15:33:07 +00:00
// set widget names for matching with .gtkrc-2.0
gtk_widget_set_name ( app - > window , " GeanyMainWindow " ) ;
2007-08-23 11:34:06 +00:00
gtk_widget_set_name ( ui_widgets . toolbar_menu , " GeanyToolbarMenu " ) ;
2007-05-04 15:33:07 +00:00
gtk_widget_set_name ( app - > popup_menu , " GeanyEditMenu " ) ;
2007-11-17 14:04:27 +00:00
# if ! GTK_CHECK_VERSION(2, 10, 0)
// hide Page setup menu item, it isn't supported with non-GTK printing
gtk_widget_hide ( ui_widgets . print_page_setup ) ;
# endif
2006-01-14 22:38:06 +00:00
}
2006-07-11 13:48:24 +00:00
/* get the full file path of a command-line argument
* N . B . the result should be freed and may contain ' / . . / ' or ' / . / ' */
gchar * get_argv_filename ( const gchar * filename )
{
gchar * result ;
if ( g_path_is_absolute ( filename ) )
result = g_strdup ( filename ) ;
else
{
2007-08-23 11:34:06 +00:00
// use current dir
2006-07-11 13:48:24 +00:00
gchar * cur_dir = g_get_current_dir ( ) ;
2007-01-13 12:42:12 +00:00
2006-07-11 13:48:24 +00:00
result = g_strjoin (
G_DIR_SEPARATOR_S , cur_dir , filename , NULL ) ;
g_free ( cur_dir ) ;
}
return result ;
}
2006-08-17 14:40:43 +00:00
static void setup_paths ( )
2006-01-14 22:38:06 +00:00
{
2006-07-26 17:02:16 +00:00
gchar * data_dir ;
gchar * doc_dir ;
// set paths
# ifdef G_OS_WIN32
// take the installation directory(the one where geany.exe is located) as the base for the
2007-03-02 09:58:03 +00:00
// documentation and data files
2006-07-26 17:02:16 +00:00
gchar * install_dir = g_win32_get_package_installation_directory ( " geany " , NULL ) ;
data_dir = g_strconcat ( install_dir , " \\ data " , NULL ) ; // e.g. C:\Program Files\geany\data
doc_dir = g_strconcat ( install_dir , " \\ doc " , NULL ) ;
g_free ( install_dir ) ;
# else
data_dir = g_strdup ( PACKAGE_DATA_DIR " / " PACKAGE " / " ) ; // e.g. /usr/share/geany
doc_dir = g_strdup ( PACKAGE_DATA_DIR " /doc/ " PACKAGE " /html/ " ) ;
2006-08-17 14:40:43 +00:00
# endif
2007-02-12 16:32:56 +00:00
// convert path names to locale encoding
app - > datadir = utils_get_locale_from_utf8 ( data_dir ) ;
app - > docdir = utils_get_locale_from_utf8 ( doc_dir ) ;
g_free ( data_dir ) ;
g_free ( doc_dir ) ;
2006-08-17 14:40:43 +00:00
}
static void locale_init ( )
{
2007-06-25 17:49:45 +00:00
# ifdef ENABLE_NLS
2006-08-17 14:40:43 +00:00
gchar * locale_dir = NULL ;
2007-06-25 17:49:45 +00:00
# if HAVE_LOCALE_H
setlocale ( LC_ALL , " " ) ;
# endif
2006-08-17 14:40:43 +00:00
# ifdef G_OS_WIN32
2007-03-02 09:58:03 +00:00
gchar * install_dir = g_win32_get_package_installation_directory ( " geany " , NULL ) ;
// e.g. C:\Program Files\geany\lib\locale
locale_dir = g_strconcat ( install_dir , " \\ lib \\ locale " , NULL ) ;
g_free ( install_dir ) ;
2006-08-17 14:40:43 +00:00
# else
2006-07-26 17:02:16 +00:00
locale_dir = g_strdup ( PACKAGE_LOCALE_DIR ) ;
# endif
2006-01-14 22:38:06 +00:00
2006-07-26 17:02:16 +00:00
bindtextdomain ( GETTEXT_PACKAGE , locale_dir ) ;
2006-06-12 13:17:11 +00:00
bind_textdomain_codeset ( GETTEXT_PACKAGE , " UTF-8 " ) ;
textdomain ( GETTEXT_PACKAGE ) ;
2006-07-26 17:02:16 +00:00
g_free ( locale_dir ) ;
2007-06-25 17:49:45 +00:00
# endif
2006-08-17 14:40:43 +00:00
}
static void parse_command_line_options ( gint * argc , gchar * * * argv )
{
GOptionContext * context ;
GError * error = NULL ;
2006-06-12 13:17:11 +00:00
2006-09-04 11:16:07 +00:00
// first initialise cl_options fields with default values
cl_options . load_session = TRUE ;
2006-10-03 13:16:42 +00:00
cl_options . goto_line = - 1 ;
2007-01-24 22:38:53 +00:00
cl_options . goto_column = - 1 ;
2006-09-04 11:16:07 +00:00
2007-06-25 17:49:45 +00:00
context = g_option_context_new ( _ ( " [FILES...] " ) ) ;
2006-01-14 22:38:06 +00:00
g_option_context_add_main_entries ( context , entries , GETTEXT_PACKAGE ) ;
2006-06-12 13:17:11 +00:00
g_option_group_set_translation_domain ( g_option_context_get_main_group ( context ) , GETTEXT_PACKAGE ) ;
2006-01-14 22:38:06 +00:00
g_option_context_add_group ( context , gtk_get_option_group ( TRUE ) ) ;
2006-08-17 14:40:43 +00:00
g_option_context_parse ( context , argc , argv , & error ) ;
2006-01-14 22:38:06 +00:00
g_option_context_free ( context ) ;
if ( show_version )
{
printf ( PACKAGE " " VERSION " " ) ;
printf ( _ ( " (built on %s with GTK %d.%d.%d, GLib %d.%d.%d) " ) ,
__DATE__ , GTK_MAJOR_VERSION , GTK_MINOR_VERSION , GTK_MICRO_VERSION ,
GLIB_MAJOR_VERSION , GLIB_MINOR_VERSION , GLIB_MICRO_VERSION ) ;
printf ( " \n " ) ;
2006-08-17 14:40:43 +00:00
exit ( 0 ) ;
2006-01-14 22:38:06 +00:00
}
2006-08-17 14:40:43 +00:00
# ifdef GEANY_DEBUG
2007-07-25 11:49:11 +00:00
app - > debug_mode = TRUE ;
2006-08-17 14:40:43 +00:00
geany_debug ( " debug mode built in (can't be disabled) " ) ;
2007-07-25 11:49:11 +00:00
# else
app - > debug_mode = debug_mode ;
2006-08-17 14:40:43 +00:00
# endif
2006-04-27 18:05:57 +00:00
2006-08-17 14:40:43 +00:00
if ( alternate_config )
{
geany_debug ( " alternate config: %s " , alternate_config ) ;
app - > configdir = alternate_config ;
}
else
app - > configdir = g_strconcat ( GEANY_HOME_DIR , G_DIR_SEPARATOR_S , " . " , PACKAGE , NULL ) ;
2007-04-25 15:01:14 +00:00
# ifdef GEANY_DEBUG
if ( generate_datafiles )
{
filetypes_init_types ( ) ;
configuration_generate_data_files ( ) ; // currently only filetype_extensions.conf
exit ( 0 ) ;
}
# endif
if ( generate_tags )
{
gboolean ret ;
2007-04-27 11:00:29 +00:00
filetypes_init_types ( ) ;
configuration_read_filetype_extensions ( ) ; // needed for *.lang.tags filetype matching
2007-09-28 11:48:55 +00:00
ret = symbols_generate_global_tags ( * argc , * argv , ! no_preprocessing ) ;
2007-04-25 15:01:14 +00:00
exit ( ret ) ;
}
2007-06-17 17:56:48 +00:00
if ( ft_names )
{
int i ;
printf ( " Geany's internal filetype names: \n " ) ;
filetypes_init_types ( ) ;
for ( i = 0 ; i < GEANY_MAX_FILE_TYPES ; i + + )
{
printf ( " %s \n " , filetypes [ i ] - > name ) ;
}
filetypes_free_types ( ) ;
exit ( 0 ) ;
}
2007-04-25 15:01:14 +00:00
2006-08-30 18:36:17 +00:00
# ifdef HAVE_SOCKET
socket_info . ignore_socket = ignore_socket ;
2007-07-13 11:07:35 +00:00
if ( ignore_socket )
cl_options . load_session = FALSE ;
2006-08-17 14:40:43 +00:00
# endif
# ifdef HAVE_VTE
2006-08-19 15:07:11 +00:00
vte_info . lib_vte = lib_vte ;
2006-06-29 17:10:17 +00:00
# endif
2007-08-23 11:34:06 +00:00
cl_options . ignore_global_tags = ignore_global_tags ;
2006-08-17 14:40:43 +00:00
}
2006-02-26 18:19:28 +00:00
2006-08-17 14:40:43 +00:00
// Returns 0 if config dir is OK.
static gint setup_config_dir ( )
{
gint mkdir_result = 0 ;
2007-02-12 16:32:56 +00:00
gchar * tmp = app - > configdir ;
// convert configdir to locale encoding to avoid troubles
app - > configdir = utils_get_locale_from_utf8 ( app - > configdir ) ;
g_free ( tmp ) ;
2006-02-26 18:19:28 +00:00
2007-11-04 15:48:14 +00:00
mkdir_result = utils_make_settings_dir ( ) ;
2006-07-25 12:46:08 +00:00
if ( mkdir_result ! = 0 )
2006-02-26 18:19:28 +00:00
{
2006-07-25 12:46:08 +00:00
if ( ! dialogs_show_question (
_ ( " Configuration directory could not be created (%s). \n There could be some problems "
2006-07-26 17:02:16 +00:00
" using Geany without a configuration directory. \n Start Geany anyway? " ) ,
g_strerror ( mkdir_result ) ) )
2006-07-25 12:46:08 +00:00
{
2006-08-17 14:40:43 +00:00
exit ( 0 ) ;
2006-07-25 12:46:08 +00:00
}
2006-02-26 18:19:28 +00:00
}
2006-08-17 14:40:43 +00:00
return mkdir_result ;
}
2006-02-10 21:06:41 +00:00
2006-08-17 14:40:43 +00:00
static void signal_cb ( gint sig )
{
if ( sig = = SIGTERM )
{
on_exit_clicked ( NULL , NULL ) ;
}
}
2007-01-13 12:42:12 +00:00
// open files from command line
2007-02-15 23:56:15 +00:00
static gboolean open_cl_files ( gint argc , gchar * * argv )
2007-01-13 12:42:12 +00:00
{
gint i ;
if ( argc < = 1 ) return FALSE ;
2007-02-23 13:26:06 +00:00
document_delay_colourise ( ) ;
2007-01-13 12:42:12 +00:00
for ( i = 1 ; i < argc ; i + + )
{
gchar * filename = get_argv_filename ( argv [ i ] ) ;
2007-02-15 23:56:15 +00:00
if ( filename ! = NULL & &
2007-01-13 12:42:12 +00:00
g_file_test ( filename , G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_SYMLINK ) )
{
gint idx ;
2007-09-11 15:21:11 +00:00
idx = document_open_file ( filename , FALSE , NULL , NULL ) ;
2007-01-13 12:42:12 +00:00
// add recent file manually because opening_session_files is set
if ( DOC_IDX_VALID ( idx ) )
ui_add_recent_file ( doc_list [ idx ] . file_name ) ;
}
2007-02-15 23:56:15 +00:00
else if ( filename ! = NULL )
{ // create new file if it doesn't exist
gint idx ;
2007-09-03 16:09:53 +00:00
idx = document_new_file ( filename , NULL , NULL ) ;
2007-02-15 23:56:15 +00:00
if ( DOC_IDX_VALID ( idx ) )
ui_add_recent_file ( doc_list [ idx ] . file_name ) ;
}
2007-01-13 12:42:12 +00:00
else
{
gchar * msg = _ ( " Could not find file '%s'. " ) ;
g_printerr ( msg , filename ) ; // also print to the terminal
g_printerr ( " \n " ) ;
2007-10-24 10:52:48 +00:00
ui_set_statusbar ( TRUE , msg , filename ) ;
2007-01-13 12:42:12 +00:00
}
g_free ( filename ) ;
}
2007-03-06 16:57:09 +00:00
document_colourise_new ( ) ;
2007-01-13 12:42:12 +00:00
return TRUE ;
}
2007-04-21 12:25:17 +00:00
static void load_project_file ( )
{
gchar * locale_filename ;
g_return_if_fail ( project_prefs . session_file ! = NULL ) ;
locale_filename = utils_get_locale_from_utf8 ( project_prefs . session_file ) ;
if ( * locale_filename )
project_load_file ( locale_filename ) ;
g_free ( locale_filename ) ;
g_free ( project_prefs . session_file ) ; // no longer needed
}
2007-08-16 15:20:38 +00:00
static void load_settings ( )
{
configuration_load ( ) ;
// let cmdline options overwrite configuration settings
# ifdef HAVE_VTE
vte_info . have_vte = ( no_vte ) ? FALSE : vte_info . load_vte ;
# endif
2007-08-23 11:34:06 +00:00
if ( no_msgwin ) ui_prefs . msgwindow_visible = FALSE ;
2007-08-16 15:20:38 +00:00
2007-11-11 09:09:47 +00:00
# ifdef HAVE_PLUGINS
2007-08-23 11:34:06 +00:00
want_plugins = prefs . load_plugins & & ! no_plugins ;
2007-11-11 09:09:47 +00:00
# endif
2007-08-16 15:20:38 +00:00
}
2006-08-17 14:40:43 +00:00
gint main ( gint argc , gchar * * argv )
{
gint idx ;
gint config_dir_result ;
2007-08-23 11:34:06 +00:00
app = g_new0 ( GeanyApp , 1 ) ;
memset ( & main_status , 0 , sizeof ( GeanyStatus ) ) ;
memset ( & prefs , 0 , sizeof ( GeanyPrefs ) ) ;
memset ( & ui_prefs , 0 , sizeof ( UIPrefs ) ) ;
memset ( & ui_widgets , 0 , sizeof ( UIWidgets ) ) ;
2006-08-17 14:40:43 +00:00
setup_paths ( ) ;
locale_init ( ) ;
parse_command_line_options ( & argc , & argv ) ;
gtk_set_locale ( ) ;
signal ( SIGTERM , signal_cb ) ;
2006-11-17 17:49:16 +00:00
# ifdef G_OS_UNIX
2006-11-11 18:51:33 +00:00
// SIGQUIT is used to kill spawned children and we get also this signal, so ignore
signal ( SIGQUIT , SIG_IGN ) ;
2006-11-17 17:49:16 +00:00
// ignore SIGPIPE signal for preventing sudden death of program
2006-08-17 14:40:43 +00:00
signal ( SIGPIPE , SIG_IGN ) ;
# endif
config_dir_result = setup_config_dir ( ) ;
2006-08-30 18:36:17 +00:00
# ifdef HAVE_SOCKET
// check and create (unix domain) socket for remote operation
if ( ! socket_info . ignore_socket )
{
socket_info . lock_socket = - 1 ;
socket_info . lock_socket_tag = 0 ;
socket_info . lock_socket = socket_init ( argc , argv ) ;
if ( socket_info . lock_socket < 0 )
{
2006-09-03 19:19:56 +00:00
// Socket exists
if ( argc > 1 ) // filenames were sent to first instance, so quit
{
g_free ( app - > configdir ) ;
g_free ( app - > datadir ) ;
g_free ( app - > docdir ) ;
g_free ( app ) ;
return 0 ;
}
// Start a new instance if no command line strings were passed
socket_info . ignore_socket = TRUE ;
2006-09-04 11:16:07 +00:00
cl_options . load_session = FALSE ;
2006-08-30 18:36:17 +00:00
}
}
2006-02-20 22:59:42 +00:00
# endif
2006-02-10 21:06:41 +00:00
2007-10-01 12:22:44 +00:00
geany_debug ( " Geany %s, GTK+ %u.%u.%u, GLib %u.%u.%u " ,
VERSION ,
2006-12-11 12:20:30 +00:00
gtk_major_version , gtk_minor_version , gtk_micro_version ,
glib_major_version , glib_minor_version , glib_micro_version ) ;
2006-01-14 22:38:06 +00:00
gtk_init ( & argc , & argv ) ;
2006-04-27 18:05:57 +00:00
// inits
2006-02-26 18:19:28 +00:00
main_init ( ) ;
2006-03-15 23:19:45 +00:00
gtk_widget_set_size_request ( app - > window , GEANY_WINDOW_MINIMAL_WIDTH , GEANY_WINDOW_MINIMAL_HEIGHT ) ;
gtk_window_set_default_size ( GTK_WINDOW ( app - > window ) , GEANY_WINDOW_DEFAULT_WIDTH , GEANY_WINDOW_DEFAULT_HEIGHT ) ;
2006-07-25 09:12:51 +00:00
encodings_init ( ) ;
2006-08-17 16:12:04 +00:00
2007-08-16 15:20:38 +00:00
load_settings ( ) ;
2006-08-17 16:12:04 +00:00
2006-12-13 16:41:25 +00:00
msgwin_init ( ) ;
2007-08-23 11:34:06 +00:00
build_init ( ) ;
2006-12-13 16:41:25 +00:00
search_init ( ) ;
2006-09-05 14:24:47 +00:00
ui_create_insert_menu_items ( ) ;
ui_create_insert_date_menu_items ( ) ;
2006-08-17 16:12:04 +00:00
keybindings_init ( ) ;
2007-02-25 14:26:55 +00:00
tools_create_insert_custom_command_menu_items ( ) ;
2006-08-17 16:12:04 +00:00
notebook_init ( ) ;
2007-04-25 15:01:14 +00:00
filetypes_init ( ) ;
2007-02-19 13:26:06 +00:00
templates_init ( ) ;
2007-08-23 11:34:06 +00:00
navqueue_init ( ) ;
2007-02-19 13:26:06 +00:00
document_init_doclist ( ) ;
2007-08-23 11:34:06 +00:00
treeviews_init ( ) ;
2006-02-25 22:26:43 +00:00
configuration_read_filetype_extensions ( ) ;
2007-11-12 09:27:43 +00:00
configuration_read_snippets ( ) ;
2006-01-14 22:38:06 +00:00
2006-12-13 15:18:49 +00:00
// set window icon
{
GdkPixbuf * pb ;
pb = ui_new_pixbuf_from_inline ( GEANY_IMAGE_LOGO , FALSE ) ;
gtk_window_set_icon ( GTK_WINDOW ( app - > window ) , pb ) ;
g_object_unref ( pb ) ; // free our reference
}
2005-11-22 12:26:26 +00:00
// registering some basic events
g_signal_connect ( G_OBJECT ( app - > window ) , " delete_event " , G_CALLBACK ( on_exit_clicked ) , NULL ) ;
2007-08-28 10:50:18 +00:00
g_signal_connect ( G_OBJECT ( app - > window ) , " key-press-event " , G_CALLBACK ( keybindings_got_event ) , NULL ) ;
2005-11-22 12:26:26 +00:00
g_signal_connect ( G_OBJECT ( app - > toolbar ) , " button-press-event " , G_CALLBACK ( toolbar_popup_menu ) , NULL ) ;
2007-06-11 08:58:37 +00:00
g_signal_connect ( G_OBJECT ( lookup_widget ( app - > window , " textview_scribble " ) ) ,
" motion-notify-event " , G_CALLBACK ( on_motion_event ) , NULL ) ;
g_signal_connect ( G_OBJECT ( lookup_widget ( app - > window , " entry1 " ) ) ,
" motion-notify-event " , G_CALLBACK ( on_motion_event ) , NULL ) ;
g_signal_connect ( G_OBJECT ( lookup_widget ( app - > window , " entry_goto_line " ) ) ,
" motion-notify-event " , G_CALLBACK ( on_motion_event ) , NULL ) ;
2005-11-22 12:26:26 +00:00
2006-01-14 22:38:06 +00:00
# ifdef HAVE_VTE
2005-11-27 20:54:28 +00:00
vte_init ( ) ;
2006-01-14 22:38:06 +00:00
# endif
2006-09-09 14:36:15 +00:00
ui_create_recent_menu ( ) ;
2005-11-22 12:26:26 +00:00
2007-10-24 10:52:48 +00:00
ui_set_statusbar ( TRUE , _ ( " This is Geany %s. " ) , VERSION ) ;
2006-08-17 14:40:43 +00:00
if ( config_dir_result ! = 0 )
2007-10-24 10:52:48 +00:00
ui_set_statusbar ( TRUE , _ ( " Configuration directory could not be created (%s). " ) ,
2006-08-17 14:40:43 +00:00
g_strerror ( config_dir_result ) ) ;
2005-11-22 12:26:26 +00:00
2005-12-18 22:20:22 +00:00
// apply all configuration options
2005-11-22 12:26:26 +00:00
apply_settings ( ) ;
2007-08-10 16:11:17 +00:00
# ifdef HAVE_PLUGINS
// load any enabled plugins before we open any documents
2007-08-16 15:20:38 +00:00
if ( want_plugins )
2007-08-10 16:11:17 +00:00
plugins_init ( ) ;
# endif
2007-01-13 12:42:12 +00:00
// load any command line files or session files
2007-08-23 11:34:06 +00:00
main_status . opening_session_files = TRUE ;
2007-01-13 12:42:12 +00:00
if ( ! open_cl_files ( argc , argv ) )
2005-11-22 12:26:26 +00:00
{
2007-08-23 11:34:06 +00:00
if ( prefs . load_session & & cl_options . load_session )
2005-11-22 12:26:26 +00:00
{
2007-04-21 12:25:17 +00:00
load_project_file ( ) ;
2007-11-11 19:06:41 +00:00
// load session files into tabs, as they are found in the session_files variable
2007-01-13 12:42:12 +00:00
if ( ! configuration_open_files ( ) )
2005-11-22 12:26:26 +00:00
{
2007-01-13 12:42:12 +00:00
ui_update_popup_copy_items ( - 1 ) ;
ui_update_popup_reundo_items ( - 1 ) ;
2005-11-22 12:26:26 +00:00
}
}
}
2007-08-23 11:34:06 +00:00
main_status . opening_session_files = FALSE ;
2005-12-18 22:20:22 +00:00
2005-12-09 01:58:46 +00:00
// open a new file if no other file was opened
2007-08-10 16:11:17 +00:00
if ( gtk_notebook_get_n_pages ( GTK_NOTEBOOK ( app - > notebook ) ) = = 0 )
2007-09-03 16:09:53 +00:00
document_new_file ( NULL , NULL , NULL ) ;
2005-12-09 01:58:46 +00:00
2007-07-20 12:06:51 +00:00
ui_document_buttons_update ( ) ;
2006-09-05 14:24:47 +00:00
ui_save_buttons_toggle ( FALSE ) ;
2006-01-14 22:38:06 +00:00
2005-12-09 01:58:46 +00:00
idx = document_get_cur_idx ( ) ;
gtk_widget_grab_focus ( GTK_WIDGET ( doc_list [ idx ] . sci ) ) ;
2007-08-23 11:34:06 +00:00
treeviews_select_openfiles_item ( idx ) ;
2006-10-18 19:35:42 +00:00
build_menu_update ( idx ) ;
2007-02-05 16:17:44 +00:00
treeviews_update_tag_list ( idx , FALSE ) ;
2006-04-27 18:05:57 +00:00
2006-01-14 22:38:06 +00:00
// finally realize the window to show the user what we have done
2005-11-22 12:26:26 +00:00
gtk_widget_show ( app - > window ) ;
2007-08-23 11:34:06 +00:00
main_status . main_window_realized = TRUE ;
2005-11-22 12:26:26 +00:00
2006-04-27 18:05:57 +00:00
configuration_apply_settings ( ) ;
2006-08-30 18:36:17 +00:00
# ifdef HAVE_SOCKET
// register the callback of socket input
if ( ! socket_info . ignore_socket & & socket_info . lock_socket > 0 )
{
socket_info . read_ioc = g_io_channel_unix_new ( socket_info . lock_socket ) ;
socket_info . lock_socket_tag = g_io_add_watch ( socket_info . read_ioc ,
G_IO_IN | G_IO_PRI | G_IO_ERR , socket_lock_input_cb , app - > window ) ;
}
# endif
2005-11-27 20:54:28 +00:00
//g_timeout_add(0, (GSourceFunc)destroyapp, NULL); // useful for start time tests
2005-11-22 12:26:26 +00:00
gtk_main ( ) ;
return 0 ;
}
2006-10-21 11:34:18 +00:00
void main_quit ( )
{
geany_debug ( " Quitting... " ) ;
# ifdef HAVE_SOCKET
socket_finalize ( ) ;
# endif
2007-11-21 18:54:12 +00:00
if ( app - > project ! = NULL )
project_close ( FALSE ) ;
2007-06-26 16:17:16 +00:00
# ifdef HAVE_PLUGINS
2007-08-16 15:20:38 +00:00
if ( want_plugins )
2007-07-05 12:15:54 +00:00
plugins_free ( ) ;
2007-06-26 16:17:16 +00:00
# endif
2007-11-12 09:27:43 +00:00
2007-06-02 16:14:07 +00:00
navqueue_free ( ) ;
2006-10-21 11:34:18 +00:00
keybindings_free ( ) ;
filetypes_save_commands ( ) ;
filetypes_free_types ( ) ;
2007-11-02 17:44:05 +00:00
highlighting_free_styles ( ) ;
2006-10-21 11:34:18 +00:00
templates_free_templates ( ) ;
msgwin_finalize ( ) ;
search_finalize ( ) ;
build_finalize ( ) ;
document_finalize ( ) ;
2006-12-15 17:09:05 +00:00
symbols_finalize ( ) ;
2007-06-17 17:56:48 +00:00
editor_finalize ( ) ;
2006-10-21 11:34:18 +00:00
tm_workspace_free ( TM_WORK_OBJECT ( app - > tm_workspace ) ) ;
g_free ( app - > configdir ) ;
g_free ( app - > datadir ) ;
g_free ( app - > docdir ) ;
2007-08-23 11:34:06 +00:00
g_free ( prefs . default_open_path ) ;
g_free ( ui_prefs . custom_date_format ) ;
g_free ( prefs . editor_font ) ;
g_free ( prefs . tagbar_font ) ;
g_free ( prefs . msgwin_font ) ;
g_free ( editor_prefs . long_line_color ) ;
g_free ( prefs . context_action_cmd ) ;
g_free ( prefs . template_developer ) ;
g_free ( prefs . template_company ) ;
g_free ( prefs . template_mail ) ;
g_free ( prefs . template_initial ) ;
g_free ( prefs . template_version ) ;
g_free ( prefs . tools_make_cmd ) ;
g_free ( prefs . tools_term_cmd ) ;
g_free ( prefs . tools_browser_cmd ) ;
g_free ( prefs . tools_grep_cmd ) ;
2007-11-17 14:04:27 +00:00
g_free ( printing_prefs . external_print_cmd ) ;
g_free ( printing_prefs . page_header_datefmt ) ;
2007-08-23 11:34:06 +00:00
g_strfreev ( ui_prefs . custom_commands ) ;
2007-11-20 18:15:46 +00:00
g_strfreev ( app - > active_plugins ) ;
2007-08-23 11:34:06 +00:00
while ( ! g_queue_is_empty ( ui_prefs . recent_queue ) )
2006-10-21 11:34:18 +00:00
{
2007-08-23 11:34:06 +00:00
g_free ( g_queue_pop_tail ( ui_prefs . recent_queue ) ) ;
2006-10-21 11:34:18 +00:00
}
2007-08-23 11:34:06 +00:00
g_queue_free ( ui_prefs . recent_queue ) ;
if ( ui_widgets . prefs_dialog & & GTK_IS_WIDGET ( ui_widgets . prefs_dialog ) ) gtk_widget_destroy ( ui_widgets . prefs_dialog ) ;
if ( ui_widgets . save_filesel & & GTK_IS_WIDGET ( ui_widgets . save_filesel ) ) gtk_widget_destroy ( ui_widgets . save_filesel ) ;
if ( ui_widgets . open_filesel & & GTK_IS_WIDGET ( ui_widgets . open_filesel ) ) gtk_widget_destroy ( ui_widgets . open_filesel ) ;
if ( ui_widgets . open_fontsel & & GTK_IS_WIDGET ( ui_widgets . open_fontsel ) ) gtk_widget_destroy ( ui_widgets . open_fontsel ) ;
if ( ui_widgets . open_colorsel & & GTK_IS_WIDGET ( ui_widgets . open_colorsel ) ) gtk_widget_destroy ( ui_widgets . open_colorsel ) ;
if ( tv . default_tag_tree & & GTK_IS_WIDGET ( tv . default_tag_tree ) )
2006-10-21 11:34:18 +00:00
{
2007-08-23 11:34:06 +00:00
g_object_unref ( tv . default_tag_tree ) ;
gtk_widget_destroy ( tv . default_tag_tree ) ;
2006-10-21 11:34:18 +00:00
}
# ifdef HAVE_VTE
if ( vte_info . have_vte ) vte_close ( ) ;
g_free ( vte_info . lib_vte ) ;
2006-11-15 18:21:46 +00:00
g_free ( vte_info . dir ) ;
2006-10-21 11:34:18 +00:00
# endif
gtk_widget_destroy ( app - > window ) ;
// destroy popup menus
if ( app - > popup_menu & & GTK_IS_WIDGET ( app - > popup_menu ) )
gtk_widget_destroy ( app - > popup_menu ) ;
2007-08-23 11:34:06 +00:00
if ( ui_widgets . toolbar_menu & & GTK_IS_WIDGET ( ui_widgets . toolbar_menu ) )
gtk_widget_destroy ( ui_widgets . toolbar_menu ) ;
2006-10-21 11:34:18 +00:00
if ( tv . popup_taglist & & GTK_IS_WIDGET ( tv . popup_taglist ) )
gtk_widget_destroy ( tv . popup_taglist ) ;
if ( tv . popup_openfiles & & GTK_IS_WIDGET ( tv . popup_openfiles ) )
gtk_widget_destroy ( tv . popup_openfiles ) ;
if ( msgwindow . popup_status_menu & & GTK_IS_WIDGET ( msgwindow . popup_status_menu ) )
gtk_widget_destroy ( msgwindow . popup_status_menu ) ;
if ( msgwindow . popup_msg_menu & & GTK_IS_WIDGET ( msgwindow . popup_msg_menu ) )
gtk_widget_destroy ( msgwindow . popup_msg_menu ) ;
if ( msgwindow . popup_compiler_menu & & GTK_IS_WIDGET ( msgwindow . popup_compiler_menu ) )
gtk_widget_destroy ( msgwindow . popup_compiler_menu ) ;
g_free ( app ) ;
gtk_main_quit ( ) ;
}
2007-06-04 13:22:43 +00:00
// malloc compatibility code
# undef malloc
void * malloc ( size_t n ) ;
// Allocate an N-byte block of memory from the heap. If N is zero, allocate a 1-byte block.
void * rpl_malloc ( size_t n )
{
if ( n = = 0 )
n = 1 ;
return malloc ( n ) ;
}