2005-11-22 12:26:26 +00:00
/*
* dialogs . c - this file is part of Geany , a fast and lightweight IDE
*
2009-01-04 18:30:42 +00:00
* Copyright 2005 - 2009 Enrico Tröger < enrico ( dot ) troeger ( at ) uvena ( dot ) de >
* Copyright 2006 - 2009 Nick Treleaven < nick ( dot ) treleaven ( at ) btinternet ( dot ) 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-06-08 15:12:55 +00:00
* Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
2005-11-22 12:26:26 +00:00
*
2005-12-11 02:16:02 +00:00
* $ Id $
2005-11-22 12:26:26 +00:00
*/
2007-02-24 11:41:56 +00:00
/*
2007-07-27 11:28:17 +00:00
* File related dialogs , miscellaneous dialogs , font dialog .
2007-02-24 11:41:56 +00:00
*/
2006-02-22 13:46:20 +00:00
# include "geany.h"
2005-11-22 12:26:26 +00:00
# include <gdk/gdkkeysyms.h>
2005-12-29 19:50:50 +00:00
# include <string.h>
2008-06-04 15:43:52 +00:00
# ifdef HAVE_SYS_TIME_H
2006-02-22 13:46:20 +00:00
# include <sys / time.h>
# endif
2008-06-04 15:43:52 +00:00
# include <time.h>
2006-02-22 13:46:20 +00:00
# ifdef HAVE_SYS_TYPES_H
# include <sys / types.h>
# endif
2008-06-04 15:43:52 +00:00
/* gstdio.h also includes sys/stat.h */
2007-04-16 15:58:34 +00:00
# include <glib/gstdio.h>
2005-11-22 12:26:26 +00:00
# include "dialogs.h"
# include "callbacks.h"
# include "document.h"
2007-08-15 15:37:21 +00:00
# include "filetypes.h"
2005-11-22 12:26:26 +00:00
# include "win32.h"
2005-12-29 19:50:50 +00:00
# include "sciwrappers.h"
# include "support.h"
# include "utils.h"
2006-09-15 14:25:42 +00:00
# include "ui_utils.h"
2006-06-16 19:58:26 +00:00
# include "keybindings.h"
2006-10-23 00:05:42 +00:00
# include "encodings.h"
2007-07-17 14:52:57 +00:00
# include "build.h"
2008-06-03 18:15:52 +00:00
# include "main.h"
2009-03-19 17:50:23 +00:00
# include "project.h"
2005-11-22 12:26:26 +00:00
2006-02-10 20:57:09 +00:00
2008-01-11 13:17:00 +00:00
enum
{
2008-04-02 13:26:38 +00:00
GEANY_RESPONSE_RENAME ,
GEANY_RESPONSE_VIEW
2008-01-11 13:17:00 +00:00
} ;
2006-10-24 23:50:50 +00:00
# if ! GEANY_USE_WIN32_DIALOG
2008-02-20 11:24:23 +00:00
static GtkWidget * add_file_open_extra_widget ( void ) ;
2007-07-17 14:52:57 +00:00
static void
on_file_open_dialog_response ( GtkDialog * dialog ,
gint response ,
gpointer user_data )
{
2007-08-23 11:34:06 +00:00
gtk_widget_hide ( ui_widgets . open_filesel ) ;
2007-07-17 14:52:57 +00:00
2008-04-02 13:26:38 +00:00
if ( response = = GTK_RESPONSE_ACCEPT | | response = = GEANY_RESPONSE_VIEW )
2007-07-17 14:52:57 +00:00
{
GSList * filelist ;
2009-03-31 15:07:27 +00:00
gint filetype_idx = gtk_combo_box_get_active ( GTK_COMBO_BOX (
ui_lookup_widget ( GTK_WIDGET ( dialog ) , " filetype_combo " ) ) ) ;
2007-07-17 14:52:57 +00:00
gint encoding_idx = gtk_combo_box_get_active ( GTK_COMBO_BOX (
2008-12-18 21:21:53 +00:00
ui_lookup_widget ( GTK_WIDGET ( dialog ) , " encoding_combo " ) ) ) ;
2008-05-16 14:17:54 +00:00
GeanyFiletype * ft = NULL ;
2007-07-17 14:52:57 +00:00
gchar * charset = NULL ;
2008-04-02 13:26:38 +00:00
gboolean ro = ( response = = GEANY_RESPONSE_VIEW ) ; /* View clicked */
2007-07-17 14:52:57 +00:00
2008-05-07 12:13:58 +00:00
/* ignore detect from file item */
2009-03-31 15:07:27 +00:00
if ( filetype_idx > 0 & & filetype_idx < GEANY_MAX_BUILT_IN_FILETYPES )
2009-04-02 15:00:17 +00:00
ft = g_slist_nth_data ( filetypes_by_title , filetype_idx ) ;
2007-07-17 14:52:57 +00:00
if ( encoding_idx > = 0 & & encoding_idx < GEANY_ENCODINGS_MAX )
charset = encodings [ encoding_idx ] . charset ;
2007-08-23 11:34:06 +00:00
filelist = gtk_file_chooser_get_filenames ( GTK_FILE_CHOOSER ( ui_widgets . open_filesel ) ) ;
2007-07-17 14:52:57 +00:00
if ( filelist ! = NULL )
{
document_open_files ( filelist , ro , ft , charset ) ;
2008-02-27 13:17:29 +00:00
g_slist_foreach ( filelist , ( GFunc ) g_free , NULL ) ; /* free filenames */
2007-07-17 14:52:57 +00:00
}
g_slist_free ( filelist ) ;
}
2009-03-19 17:50:23 +00:00
if ( app - > project & & NZV ( app - > project - > base_path ) )
gtk_file_chooser_remove_shortcut_folder ( GTK_FILE_CHOOSER ( ui_widgets . open_filesel ) ,
app - > project - > base_path , NULL ) ;
2007-07-17 14:52:57 +00:00
}
2009-04-19 18:14:12 +00:00
static void on_file_open_notify ( GObject * filechooser , GParamSpec * pspec , gpointer data )
2007-07-17 14:52:57 +00:00
{
2009-04-19 18:14:12 +00:00
GValue * value ;
value = g_new0 ( GValue , 1 ) ;
g_value_init ( value , pspec - > value_type ) ;
2009-05-11 15:57:02 +00:00
g_object_get_property ( filechooser , pspec - > name , value ) ;
2007-07-17 14:52:57 +00:00
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON (
2009-04-19 18:14:12 +00:00
ui_lookup_widget ( GTK_WIDGET ( filechooser ) , " check_hidden " ) ) , g_value_get_boolean ( value ) ) ;
2007-07-17 14:52:57 +00:00
}
static void
2009-04-19 18:14:12 +00:00
on_file_open_check_hidden_toggled ( GtkToggleButton * togglebutton , gpointer user_data )
2007-07-17 14:52:57 +00:00
{
gboolean is_on = gtk_toggle_button_get_active ( togglebutton ) ;
2007-08-23 11:34:06 +00:00
gtk_file_chooser_set_show_hidden ( GTK_FILE_CHOOSER ( ui_widgets . open_filesel ) , is_on ) ;
2007-07-17 14:52:57 +00:00
}
2006-09-09 14:36:15 +00:00
2006-10-19 16:26:29 +00:00
2008-02-20 11:24:23 +00:00
static void create_open_file_dialog ( void )
2005-11-22 12:26:26 +00:00
{
2007-12-21 17:25:58 +00:00
GtkWidget * filetype_combo , * encoding_combo ;
GtkWidget * viewbtn ;
2008-05-07 11:34:38 +00:00
guint i ;
2007-12-21 17:25:58 +00:00
gchar * encoding_string ;
2009-03-31 15:07:27 +00:00
GSList * node ;
2007-12-21 17:25:58 +00:00
2008-05-22 14:41:28 +00:00
ui_widgets . open_filesel = gtk_file_chooser_dialog_new ( _ ( " Open File " ) , GTK_WINDOW ( main_widgets . window ) ,
2007-12-21 17:25:58 +00:00
GTK_FILE_CHOOSER_ACTION_OPEN , NULL , NULL ) ;
gtk_widget_set_name ( ui_widgets . open_filesel , " GeanyDialog " ) ;
2008-04-02 13:26:38 +00:00
viewbtn = gtk_dialog_add_button ( GTK_DIALOG ( ui_widgets . open_filesel ) , _ ( " _View " ) ,
GEANY_RESPONSE_VIEW ) ;
2008-11-18 20:14:42 +00:00
ui_widget_set_tooltip_text ( viewbtn ,
_ ( " Opens the file in read-only mode. If you choose more than one file to open, all files will be opened read-only. " ) ) ;
2007-12-21 17:25:58 +00:00
gtk_dialog_add_buttons ( GTK_DIALOG ( ui_widgets . open_filesel ) ,
GTK_STOCK_CANCEL , GTK_RESPONSE_CANCEL ,
GTK_STOCK_OPEN , GTK_RESPONSE_ACCEPT , NULL ) ;
2008-04-02 13:26:38 +00:00
gtk_dialog_set_default_response ( GTK_DIALOG ( ui_widgets . open_filesel ) , GTK_RESPONSE_ACCEPT ) ;
2007-12-21 17:25:58 +00:00
gtk_widget_set_size_request ( ui_widgets . open_filesel , - 1 , 460 ) ;
gtk_window_set_modal ( GTK_WINDOW ( ui_widgets . open_filesel ) , TRUE ) ;
gtk_window_set_destroy_with_parent ( GTK_WINDOW ( ui_widgets . open_filesel ) , TRUE ) ;
2008-03-17 18:26:22 +00:00
gtk_window_set_skip_taskbar_hint ( GTK_WINDOW ( ui_widgets . open_filesel ) , FALSE ) ;
2007-12-21 17:25:58 +00:00
gtk_window_set_type_hint ( GTK_WINDOW ( ui_widgets . open_filesel ) , GDK_WINDOW_TYPE_HINT_DIALOG ) ;
2008-05-22 14:41:28 +00:00
gtk_window_set_transient_for ( GTK_WINDOW ( ui_widgets . open_filesel ) , GTK_WINDOW ( main_widgets . window ) ) ;
2007-12-21 17:25:58 +00:00
gtk_file_chooser_set_select_multiple ( GTK_FILE_CHOOSER ( ui_widgets . open_filesel ) , TRUE ) ;
2009-02-04 20:04:49 +00:00
if ( gtk_check_version ( 2 , 14 , 0 ) = = NULL )
gtk_file_chooser_set_local_only ( GTK_FILE_CHOOSER ( ui_widgets . open_filesel ) , FALSE ) ;
2007-12-21 17:25:58 +00:00
2008-02-27 13:17:29 +00:00
/* add checkboxes and filename entry */
2007-12-21 17:25:58 +00:00
gtk_file_chooser_set_extra_widget ( GTK_FILE_CHOOSER ( ui_widgets . open_filesel ) ,
add_file_open_extra_widget ( ) ) ;
2008-12-18 21:21:53 +00:00
filetype_combo = ui_lookup_widget ( ui_widgets . open_filesel , " filetype_combo " ) ;
2007-12-21 17:25:58 +00:00
2009-03-20 16:33:59 +00:00
gtk_combo_box_append_text ( GTK_COMBO_BOX ( filetype_combo ) , _ ( " Detect by file extension " ) ) ;
2008-02-27 13:17:29 +00:00
/* add FileFilters(start with "All Files") */
2007-12-21 17:25:58 +00:00
gtk_file_chooser_add_filter ( GTK_FILE_CHOOSER ( ui_widgets . open_filesel ) ,
2008-05-07 13:54:21 +00:00
filetypes_create_file_filter ( filetypes [ GEANY_FILETYPES_NONE ] ) ) ;
2008-02-27 13:17:29 +00:00
/* now create meta filter "All Source" */
2007-12-21 17:25:58 +00:00
gtk_file_chooser_add_filter ( GTK_FILE_CHOOSER ( ui_widgets . open_filesel ) ,
filetypes_create_file_filter_all_source ( ) ) ;
2009-06-12 15:32:35 +00:00
foreach_slist ( node , filetypes_by_title )
2009-03-31 15:07:27 +00:00
{
2009-06-12 15:32:35 +00:00
GeanyFiletype * ft = node - > data ;
2009-04-05 21:07:40 +00:00
if ( G_UNLIKELY ( ft - > id = = GEANY_FILETYPES_NONE ) )
2009-03-31 15:07:27 +00:00
continue ;
gtk_combo_box_append_text ( GTK_COMBO_BOX ( filetype_combo ) , ft - > title ) ;
gtk_file_chooser_add_filter ( GTK_FILE_CHOOSER ( ui_widgets . open_filesel ) ,
filetypes_create_file_filter ( ft ) ) ;
}
2009-03-20 16:33:59 +00:00
gtk_combo_box_set_active ( GTK_COMBO_BOX ( filetype_combo ) , 0 ) ;
2006-01-26 21:32:46 +00:00
2008-02-27 13:17:29 +00:00
/* fill encoding combo box */
2008-12-18 21:21:53 +00:00
encoding_combo = ui_lookup_widget ( ui_widgets . open_filesel , " encoding_combo " ) ;
2007-12-21 17:25:58 +00:00
for ( i = 0 ; i < GEANY_ENCODINGS_MAX ; i + + )
2006-10-09 16:08:53 +00:00
{
2007-12-21 17:25:58 +00:00
encoding_string = encodings_to_string ( & encodings [ i ] ) ;
gtk_combo_box_append_text ( GTK_COMBO_BOX ( encoding_combo ) , encoding_string ) ;
g_free ( encoding_string ) ;
}
gtk_combo_box_append_text ( GTK_COMBO_BOX ( encoding_combo ) , _ ( " Detect from file " ) ) ;
gtk_combo_box_set_active ( GTK_COMBO_BOX ( encoding_combo ) , GEANY_ENCODINGS_MAX ) ;
2009-04-19 18:14:12 +00:00
g_signal_connect ( ui_widgets . open_filesel , " notify::show-hidden " ,
G_CALLBACK ( on_file_open_notify ) , NULL ) ;
2008-07-18 13:40:48 +00:00
g_signal_connect ( ui_widgets . open_filesel , " delete-event " ,
2007-12-21 17:25:58 +00:00
G_CALLBACK ( gtk_widget_hide_on_delete ) , NULL ) ;
2008-07-18 13:40:48 +00:00
g_signal_connect ( ui_widgets . open_filesel , " response " ,
2007-12-21 17:25:58 +00:00
G_CALLBACK ( on_file_open_dialog_response ) , NULL ) ;
}
# endif
2006-05-14 16:07:30 +00:00
2007-12-21 17:25:58 +00:00
/* This shows the file selection dialog to open a file. */
void dialogs_show_open_file ( )
{
gchar * initdir ;
2006-04-27 18:06:35 +00:00
2008-02-27 13:17:29 +00:00
/* set dialog directory to the current file's directory, if present */
2007-12-21 17:25:58 +00:00
initdir = utils_get_current_file_dir_utf8 ( ) ;
2008-02-27 13:17:29 +00:00
/* use project or default startup directory (if set) if no files are open */
/** TODO should it only be used when initally open the dialog and not on every show? */
2007-12-21 17:25:58 +00:00
if ( ! initdir )
initdir = g_strdup ( utils_get_default_dir_utf8 ( ) ) ;
setptr ( initdir , utils_get_locale_from_utf8 ( initdir ) ) ;
# if GEANY_USE_WIN32_DIALOG
win32_show_file_dialog ( TRUE , initdir ) ;
# else /* X11, not win32: use GTK_FILE_CHOOSER */
2008-02-27 13:17:29 +00:00
/* We use the same file selection widget each time, so first of all we create it
* if it hasn ' t already been created . */
2009-04-15 22:47:33 +00:00
if ( ui_widgets . open_filesel = = NULL )
2007-12-21 17:25:58 +00:00
create_open_file_dialog ( ) ;
if ( initdir ! = NULL )
2007-05-23 13:44:25 +00:00
{
2007-12-21 17:25:58 +00:00
if ( g_path_is_absolute ( initdir ) )
2007-05-23 13:44:25 +00:00
gtk_file_chooser_set_current_folder (
2007-12-21 17:25:58 +00:00
GTK_FILE_CHOOSER ( ui_widgets . open_filesel ) , initdir ) ;
2007-05-23 13:44:25 +00:00
}
2006-01-26 21:32:46 +00:00
2009-03-19 17:50:23 +00:00
if ( app - > project & & NZV ( app - > project - > base_path ) )
gtk_file_chooser_add_shortcut_folder ( GTK_FILE_CHOOSER ( ui_widgets . open_filesel ) ,
app - > project - > base_path , NULL ) ;
2007-08-23 11:34:06 +00:00
gtk_file_chooser_unselect_all ( GTK_FILE_CHOOSER ( ui_widgets . open_filesel ) ) ;
2008-05-10 08:32:30 +00:00
gtk_window_present ( GTK_WINDOW ( ui_widgets . open_filesel ) ) ;
2005-11-22 12:26:26 +00:00
# endif
2007-12-21 17:25:58 +00:00
g_free ( initdir ) ;
2005-11-22 12:26:26 +00:00
}
2007-07-17 14:52:57 +00:00
# if ! GEANY_USE_WIN32_DIALOG
2006-09-09 14:36:15 +00:00
static GtkWidget * add_file_open_extra_widget ( )
{
2009-04-19 17:54:09 +00:00
GtkWidget * expander , * vbox , * table , * check_hidden ;
2006-10-23 00:05:42 +00:00
GtkWidget * filetype_ebox , * filetype_label , * filetype_combo ;
GtkWidget * encoding_ebox , * encoding_label , * encoding_combo ;
2006-09-09 14:36:15 +00:00
2009-04-19 17:54:09 +00:00
expander = gtk_expander_new_with_mnemonic ( _ ( " _More Options " ) ) ;
2006-09-09 14:36:15 +00:00
vbox = gtk_vbox_new ( FALSE , 6 ) ;
2009-04-19 17:54:09 +00:00
gtk_container_add ( GTK_CONTAINER ( expander ) , vbox ) ;
2006-09-09 14:36:15 +00:00
2006-10-23 00:05:42 +00:00
table = gtk_table_new ( 2 , 4 , FALSE ) ;
2008-02-27 13:17:29 +00:00
/* line 1 with checkbox and encoding combo */
2006-09-09 14:36:15 +00:00
check_hidden = gtk_check_button_new_with_mnemonic ( _ ( " Show _hidden files " ) ) ;
2006-10-23 00:05:42 +00:00
gtk_widget_show ( check_hidden ) ;
gtk_table_attach ( GTK_TABLE ( table ) , check_hidden , 0 , 1 , 0 , 1 ,
( GtkAttachOptions ) ( GTK_FILL | GTK_EXPAND ) ,
( GtkAttachOptions ) ( 0 ) , 0 , 5 ) ;
2008-02-27 13:17:29 +00:00
/* spacing */
2006-10-23 00:05:42 +00:00
gtk_table_attach ( GTK_TABLE ( table ) , gtk_label_new ( " " ) , 1 , 2 , 0 , 1 ,
( GtkAttachOptions ) ( GTK_FILL ) ,
( GtkAttachOptions ) ( 0 ) , 5 , 5 ) ;
encoding_label = gtk_label_new ( _ ( " Set encoding: " ) ) ;
gtk_misc_set_alignment ( GTK_MISC ( encoding_label ) , 1 , 0 ) ;
gtk_table_attach ( GTK_TABLE ( table ) , encoding_label , 2 , 3 , 0 , 1 ,
( GtkAttachOptions ) ( GTK_FILL ) ,
( GtkAttachOptions ) ( 0 ) , 4 , 5 ) ;
2008-02-27 13:17:29 +00:00
/* the ebox is for the tooltip, because gtk_combo_box can't show tooltips */
2006-10-23 00:05:42 +00:00
encoding_ebox = gtk_event_box_new ( ) ;
encoding_combo = gtk_combo_box_new_text ( ) ;
gtk_combo_box_set_wrap_width ( GTK_COMBO_BOX ( encoding_combo ) , 3 ) ;
2008-11-18 20:14:42 +00:00
ui_widget_set_tooltip_text ( encoding_ebox ,
_ ( " Explicitly defines an encoding for the file, if it would not be detected. This is useful when you know that the encoding of a file cannot be detected correctly by Geany. \n Note if you choose multiple files, they will all be opened with the chosen encoding. " ) ) ;
2006-10-23 00:05:42 +00:00
gtk_container_add ( GTK_CONTAINER ( encoding_ebox ) , encoding_combo ) ;
gtk_table_attach ( GTK_TABLE ( table ) , encoding_ebox , 3 , 4 , 0 , 1 ,
( GtkAttachOptions ) ( GTK_FILL ) ,
( GtkAttachOptions ) ( 0 ) , 0 , 5 ) ;
2009-04-19 17:54:09 +00:00
/* line 2 with filetype combo */
2006-09-09 14:36:15 +00:00
filetype_label = gtk_label_new ( _ ( " Set filetype: " ) ) ;
2006-10-23 00:05:42 +00:00
gtk_misc_set_alignment ( GTK_MISC ( filetype_label ) , 1 , 0 ) ;
gtk_table_attach ( GTK_TABLE ( table ) , filetype_label , 2 , 3 , 1 , 2 ,
( GtkAttachOptions ) ( GTK_FILL ) ,
( GtkAttachOptions ) ( 0 ) , 4 , 5 ) ;
2008-02-27 13:17:29 +00:00
/* the ebox is for the tooltip, because gtk_combo_box can't show tooltips */
2006-10-23 00:05:42 +00:00
filetype_ebox = gtk_event_box_new ( ) ;
2006-09-09 14:36:15 +00:00
filetype_combo = gtk_combo_box_new_text ( ) ;
2006-10-24 18:21:16 +00:00
gtk_combo_box_set_wrap_width ( GTK_COMBO_BOX ( filetype_combo ) , 2 ) ;
2008-11-18 20:14:42 +00:00
ui_widget_set_tooltip_text ( filetype_ebox ,
_ ( " Explicitly defines a filetype for the file, if it would not be detected by filename extension. \n Note if you choose multiple files, they will all be opened with the chosen filetype. " ) ) ;
2006-10-23 00:05:42 +00:00
gtk_container_add ( GTK_CONTAINER ( filetype_ebox ) , filetype_combo ) ;
gtk_table_attach ( GTK_TABLE ( table ) , filetype_ebox , 3 , 4 , 1 , 2 ,
( GtkAttachOptions ) ( GTK_FILL ) ,
( GtkAttachOptions ) ( 0 ) , 0 , 5 ) ;
2006-09-09 14:36:15 +00:00
2006-10-23 00:05:42 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , table , FALSE , FALSE , 0 ) ;
gtk_widget_show_all ( vbox ) ;
2006-09-09 14:36:15 +00:00
2008-07-18 13:40:48 +00:00
g_signal_connect ( check_hidden , " toggled " ,
2006-09-09 14:36:15 +00:00
G_CALLBACK ( on_file_open_check_hidden_toggled ) , NULL ) ;
2007-08-23 11:34:06 +00:00
g_object_set_data_full ( G_OBJECT ( ui_widgets . open_filesel ) , " check_hidden " ,
2008-10-22 15:36:45 +00:00
g_object_ref ( check_hidden ) , ( GDestroyNotify ) g_object_unref ) ;
2007-08-23 11:34:06 +00:00
g_object_set_data_full ( G_OBJECT ( ui_widgets . open_filesel ) , " filetype_combo " ,
2008-10-22 15:36:45 +00:00
g_object_ref ( filetype_combo ) , ( GDestroyNotify ) g_object_unref ) ;
2007-08-23 11:34:06 +00:00
g_object_set_data_full ( G_OBJECT ( ui_widgets . open_filesel ) , " encoding_combo " ,
2008-10-22 15:36:45 +00:00
g_object_ref ( encoding_combo ) , ( GDestroyNotify ) g_object_unref ) ;
2006-09-09 14:36:15 +00:00
2009-04-19 17:54:09 +00:00
return expander ;
2006-09-09 14:36:15 +00:00
}
2006-09-11 07:41:37 +00:00
# endif
2006-09-09 14:36:15 +00:00
2007-07-17 14:52:57 +00:00
# if ! GEANY_USE_WIN32_DIALOG
static void on_save_as_new_tab_toggled ( GtkToggleButton * togglebutton , gpointer user_data )
{
gtk_widget_set_sensitive ( GTK_WIDGET ( user_data ) ,
! gtk_toggle_button_get_active ( togglebutton ) ) ;
}
# endif
# if ! GEANY_USE_WIN32_DIALOG
2009-05-17 17:16:24 +00:00
static gboolean handle_save_as ( const gchar * utf8_filename , gboolean open_new_tab , gboolean rename_file )
2008-01-15 17:04:31 +00:00
{
2008-06-15 13:35:48 +00:00
GeanyDocument * doc = document_get_current ( ) ;
2009-05-17 17:16:24 +00:00
gboolean success = FALSE ;
2008-01-15 17:04:31 +00:00
2009-05-17 17:16:24 +00:00
g_return_val_if_fail ( NZV ( utf8_filename ) , FALSE ) ;
2008-01-15 17:04:31 +00:00
if ( open_new_tab )
2008-03-21 14:02:59 +00:00
{ /* "open" the saved file in a new tab and switch to it */
2008-06-15 13:35:48 +00:00
doc = document_clone ( doc , utf8_filename ) ;
2009-05-17 17:16:24 +00:00
success = document_save_file_as ( doc , NULL ) ;
2008-01-15 17:04:31 +00:00
}
else
{
2008-06-15 13:35:48 +00:00
if ( doc - > file_name ! = NULL )
2008-01-15 17:04:31 +00:00
{
if ( rename_file )
{
2009-01-18 18:19:58 +00:00
document_rename_file ( doc , utf8_filename ) ;
2008-01-15 17:04:31 +00:00
}
2008-02-27 13:17:29 +00:00
/* create a new tm_source_file object otherwise tagmanager won't work correctly */
2008-06-15 13:35:48 +00:00
tm_workspace_remove_object ( doc - > tm_file , TRUE , TRUE ) ;
doc - > tm_file = NULL ;
2008-01-15 17:04:31 +00:00
}
2009-05-17 17:16:24 +00:00
success = document_save_file_as ( doc , utf8_filename ) ;
2008-01-15 17:04:31 +00:00
2008-06-15 13:35:48 +00:00
build_menu_update ( doc ) ;
2009-01-18 18:19:58 +00:00
}
2009-05-17 17:16:24 +00:00
return success ;
2008-01-15 17:04:31 +00:00
}
2007-07-17 14:52:57 +00:00
static void
on_file_save_dialog_response ( GtkDialog * dialog ,
gint response ,
gpointer user_data )
{
gboolean rename_file = FALSE ;
2009-05-17 17:16:24 +00:00
gboolean success = FALSE ;
2009-07-20 16:12:23 +00:00
gchar * new_filename = gtk_file_chooser_get_filename ( GTK_FILE_CHOOSER ( ui_widgets . save_filesel ) ) ;
2007-07-17 14:52:57 +00:00
switch ( response )
{
2008-01-11 13:17:00 +00:00
case GEANY_RESPONSE_RENAME :
2009-07-20 16:12:23 +00:00
/* rename doesn't check for empty filename or overwriting */
if ( ! NZV ( new_filename ) )
{
utils_beep ( ) ;
break ;
}
if ( g_file_test ( new_filename , G_FILE_TEST_EXISTS ) & &
! dialogs_show_question_full ( NULL , NULL , NULL ,
_ ( " Overwrite? " ) ,
_ ( " Filename already exists! " ) ) )
break ;
2007-07-17 14:52:57 +00:00
rename_file = TRUE ;
2008-02-27 13:17:29 +00:00
/* fall through */
2007-07-17 14:52:57 +00:00
case GTK_RESPONSE_ACCEPT :
{
gboolean open_new_tab = gtk_toggle_button_get_active (
2008-12-18 21:21:53 +00:00
GTK_TOGGLE_BUTTON ( ui_lookup_widget ( ui_widgets . save_filesel , " check_open_new_tab " ) ) ) ;
2008-01-15 17:04:31 +00:00
gchar * utf8_filename ;
2007-07-17 14:52:57 +00:00
utf8_filename = utils_get_utf8_from_locale ( new_filename ) ;
2009-05-17 17:16:24 +00:00
success = handle_save_as ( utf8_filename , open_new_tab , rename_file ) ;
2007-07-17 14:52:57 +00:00
2008-01-15 17:04:31 +00:00
g_free ( utf8_filename ) ;
2009-05-21 19:19:12 +00:00
break ;
2007-07-17 14:52:57 +00:00
}
2009-05-21 19:19:12 +00:00
case GTK_RESPONSE_CANCEL :
success = TRUE ;
break ;
2007-07-17 14:52:57 +00:00
}
2009-07-20 16:12:23 +00:00
g_free ( new_filename ) ;
2009-05-17 17:16:24 +00:00
if ( success )
gtk_widget_hide ( ui_widgets . save_filesel ) ;
2007-07-17 14:52:57 +00:00
}
# endif
2007-12-21 17:25:58 +00:00
# if ! GEANY_USE_WIN32_DIALOG
2008-02-20 11:24:23 +00:00
static void create_save_file_dialog ( void )
2007-12-21 17:25:58 +00:00
{
GtkWidget * vbox , * check_open_new_tab , * rename_btn ;
2009-06-25 12:39:21 +00:00
const gchar * initdir ;
2007-12-21 17:25:58 +00:00
2008-05-22 14:41:28 +00:00
ui_widgets . save_filesel = gtk_file_chooser_dialog_new ( _ ( " Save File " ) , GTK_WINDOW ( main_widgets . window ) ,
2007-12-21 17:25:58 +00:00
GTK_FILE_CHOOSER_ACTION_SAVE , NULL , NULL ) ;
gtk_window_set_modal ( GTK_WINDOW ( ui_widgets . save_filesel ) , TRUE ) ;
gtk_window_set_destroy_with_parent ( GTK_WINDOW ( ui_widgets . save_filesel ) , TRUE ) ;
2008-03-17 18:26:22 +00:00
gtk_window_set_skip_taskbar_hint ( GTK_WINDOW ( ui_widgets . save_filesel ) , FALSE ) ;
2007-12-21 17:25:58 +00:00
gtk_window_set_type_hint ( GTK_WINDOW ( ui_widgets . save_filesel ) , GDK_WINDOW_TYPE_HINT_DIALOG ) ;
gtk_widget_set_name ( ui_widgets . save_filesel , " GeanyDialog " ) ;
2008-04-02 13:26:38 +00:00
rename_btn = gtk_dialog_add_button ( GTK_DIALOG ( ui_widgets . save_filesel ) , _ ( " R_ename " ) ,
GEANY_RESPONSE_RENAME ) ;
2009-01-15 19:15:41 +00:00
ui_widget_set_tooltip_text ( rename_btn , _ ( " Save the file and rename it " ) ) ;
2007-12-21 17:25:58 +00:00
gtk_dialog_add_buttons ( GTK_DIALOG ( ui_widgets . save_filesel ) ,
GTK_STOCK_CANCEL , GTK_RESPONSE_CANCEL ,
GTK_STOCK_SAVE , GTK_RESPONSE_ACCEPT , NULL ) ;
gtk_dialog_set_default_response ( GTK_DIALOG ( ui_widgets . save_filesel ) , GTK_RESPONSE_ACCEPT ) ;
vbox = gtk_vbox_new ( FALSE , 0 ) ;
check_open_new_tab = gtk_check_button_new_with_mnemonic ( _ ( " _Open file in a new tab " ) ) ;
2008-11-18 20:14:42 +00:00
ui_widget_set_tooltip_text ( check_open_new_tab ,
2007-12-21 17:25:58 +00:00
_ ( " Keep the current unsaved document open "
2009-01-15 19:15:41 +00:00
" and open the newly saved file in a new tab " ) ) ;
2007-12-21 17:25:58 +00:00
gtk_box_pack_start ( GTK_BOX ( vbox ) , check_open_new_tab , FALSE , FALSE , 0 ) ;
gtk_widget_show_all ( vbox ) ;
gtk_file_chooser_set_extra_widget ( GTK_FILE_CHOOSER ( ui_widgets . save_filesel ) , vbox ) ;
2009-01-24 19:39:35 +00:00
gtk_file_chooser_set_do_overwrite_confirmation ( GTK_FILE_CHOOSER ( ui_widgets . save_filesel ) , TRUE ) ;
2009-02-04 20:04:49 +00:00
if ( gtk_check_version ( 2 , 14 , 0 ) = = NULL )
gtk_file_chooser_set_local_only ( GTK_FILE_CHOOSER ( ui_widgets . save_filesel ) , FALSE ) ;
2007-12-21 17:25:58 +00:00
2009-06-16 21:25:04 +00:00
/* set the folder by default to the project base dir or the global pref for opening files */
2009-06-25 12:39:21 +00:00
initdir = utils_get_default_dir_utf8 ( ) ;
if ( initdir )
{
gchar * linitdir = utils_get_locale_from_utf8 ( initdir ) ;
gtk_file_chooser_set_current_folder ( GTK_FILE_CHOOSER ( ui_widgets . save_filesel ) , linitdir ) ;
g_free ( linitdir ) ;
}
2009-06-16 21:25:04 +00:00
2007-12-21 17:25:58 +00:00
g_signal_connect ( check_open_new_tab , " toggled " ,
G_CALLBACK ( on_save_as_new_tab_toggled ) , rename_btn ) ;
g_object_set_data_full ( G_OBJECT ( ui_widgets . save_filesel ) , " check_open_new_tab " ,
2008-10-22 15:36:45 +00:00
g_object_ref ( check_open_new_tab ) , ( GDestroyNotify ) g_object_unref ) ;
2007-12-21 17:25:58 +00:00
2008-07-18 13:40:48 +00:00
g_signal_connect ( ui_widgets . save_filesel , " delete-event " ,
2007-12-21 17:25:58 +00:00
G_CALLBACK ( gtk_widget_hide_on_delete ) , NULL ) ;
2008-07-18 13:40:48 +00:00
g_signal_connect ( ui_widgets . save_filesel , " response " ,
2007-12-21 17:25:58 +00:00
G_CALLBACK ( on_file_save_dialog_response ) , NULL ) ;
2008-05-22 14:41:28 +00:00
gtk_window_set_transient_for ( GTK_WINDOW ( ui_widgets . save_filesel ) , GTK_WINDOW ( main_widgets . window ) ) ;
2007-12-21 17:25:58 +00:00
}
# endif
# if ! GEANY_USE_WIN32_DIALOG
2009-06-16 21:25:04 +00:00
static gboolean gtk_show_save_as ( void )
2005-11-22 12:26:26 +00:00
{
2008-06-15 13:35:48 +00:00
GeanyDocument * doc = document_get_current ( ) ;
gint resp ;
2005-11-22 12:26:26 +00:00
2009-04-05 21:07:40 +00:00
if ( G_UNLIKELY ( ui_widgets . save_filesel = = NULL ) )
2007-12-21 17:25:58 +00:00
create_save_file_dialog ( ) ;
2008-02-12 15:50:22 +00:00
gtk_file_chooser_unselect_all ( GTK_FILE_CHOOSER ( ui_widgets . save_filesel ) ) ;
2005-11-22 12:26:26 +00:00
2008-06-15 13:35:48 +00:00
if ( doc - > file_name ! = NULL )
2006-04-27 18:06:35 +00:00
{
2008-06-15 13:35:48 +00:00
if ( g_path_is_absolute ( doc - > file_name ) )
2008-02-12 15:50:22 +00:00
{
2008-06-15 13:35:48 +00:00
gchar * locale_filename = utils_get_locale_from_utf8 ( doc - > file_name ) ;
2008-02-12 15:50:22 +00:00
gchar * locale_basename = g_path_get_basename ( locale_filename ) ;
gchar * locale_dirname = g_path_get_dirname ( locale_filename ) ;
gtk_file_chooser_set_current_folder ( GTK_FILE_CHOOSER ( ui_widgets . save_filesel ) ,
locale_dirname ) ;
gtk_file_chooser_set_current_name ( GTK_FILE_CHOOSER ( ui_widgets . save_filesel ) ,
locale_basename ) ;
g_free ( locale_filename ) ;
g_free ( locale_basename ) ;
g_free ( locale_dirname ) ;
}
2006-06-02 12:00:33 +00:00
else
2007-08-23 11:34:06 +00:00
gtk_file_chooser_set_current_name ( GTK_FILE_CHOOSER ( ui_widgets . save_filesel ) ,
2008-06-15 13:35:48 +00:00
doc - > file_name ) ;
2006-04-27 18:06:35 +00:00
}
2005-11-22 12:26:26 +00:00
else
{
2006-04-27 18:06:35 +00:00
gchar * fname = NULL ;
2006-05-14 16:07:30 +00:00
2008-06-15 13:35:48 +00:00
if ( doc - > file_type ! = NULL & & doc - > file_type - > id ! = GEANY_FILETYPES_NONE & &
doc - > file_type - > extension ! = NULL )
2006-04-27 18:06:35 +00:00
fname = g_strconcat ( GEANY_STRING_UNTITLED , " . " ,
2008-06-15 13:35:48 +00:00
doc - > file_type - > extension , NULL ) ;
2006-05-14 16:07:30 +00:00
else
2006-04-27 18:06:35 +00:00
fname = g_strdup ( GEANY_STRING_UNTITLED ) ;
2007-08-23 11:34:06 +00:00
gtk_file_chooser_set_current_name ( GTK_FILE_CHOOSER ( ui_widgets . save_filesel ) , fname ) ;
2007-05-23 13:44:25 +00:00
2006-04-27 18:06:35 +00:00
g_free ( fname ) ;
2005-11-22 12:26:26 +00:00
}
2009-03-19 17:50:23 +00:00
if ( app - > project & & NZV ( app - > project - > base_path ) )
gtk_file_chooser_add_shortcut_folder ( GTK_FILE_CHOOSER ( ui_widgets . save_filesel ) ,
app - > project - > base_path , NULL ) ;
2008-02-27 13:17:29 +00:00
/* Run the dialog synchronously, pausing this function call */
2007-08-23 11:34:06 +00:00
resp = gtk_dialog_run ( GTK_DIALOG ( ui_widgets . save_filesel ) ) ;
2009-03-19 17:50:23 +00:00
if ( app - > project & & NZV ( app - > project - > base_path ) )
gtk_file_chooser_remove_shortcut_folder ( GTK_FILE_CHOOSER ( ui_widgets . save_filesel ) ,
app - > project - > base_path , NULL ) ;
2006-11-07 11:24:22 +00:00
return ( resp = = GTK_RESPONSE_ACCEPT ) ;
2007-12-21 17:25:58 +00:00
}
# endif
2008-02-17 18:00:42 +00:00
/**
* Show the Save As dialog for the current notebook page .
*
* @ return @ a TRUE if the file was saved , otherwise @ a FALSE .
* */
2007-12-21 17:25:58 +00:00
gboolean dialogs_show_save_as ( )
{
gboolean result ;
# if GEANY_USE_WIN32_DIALOG
2009-06-16 21:25:04 +00:00
result = win32_show_file_dialog ( FALSE , utils_get_default_dir_utf8 ( ) ) ;
2007-12-21 17:25:58 +00:00
# else
2009-06-16 21:25:04 +00:00
result = gtk_show_save_as ( ) ;
2005-11-22 12:26:26 +00:00
# endif
2007-12-21 17:25:58 +00:00
return result ;
2005-11-22 12:26:26 +00:00
}
2009-07-19 20:19:09 +00:00
# ifndef G_OS_WIN32
static void show_msgbox_dialog ( GtkWidget * dialog , GtkMessageType type , GtkWindow * parent )
{
const gchar * title ;
switch ( type )
{
case GTK_MESSAGE_ERROR :
title = _ ( " Error " ) ;
break ;
case GTK_MESSAGE_QUESTION :
title = _ ( " Question " ) ;
break ;
case GTK_MESSAGE_WARNING :
title = _ ( " Warning " ) ;
break ;
default :
title = _ ( " Information " ) ;
break ;
}
gtk_window_set_title ( GTK_WINDOW ( dialog ) , title ) ;
if ( parent = = NULL )
{
GdkPixbuf * pb = ui_new_pixbuf_from_inline ( GEANY_IMAGE_LOGO ) ;
gtk_window_set_icon ( GTK_WINDOW ( dialog ) , pb ) ;
g_object_unref ( pb ) ;
}
gtk_widget_set_name ( dialog , " GeanyDialog " ) ;
gtk_dialog_run ( GTK_DIALOG ( dialog ) ) ;
gtk_widget_destroy ( dialog ) ;
}
# endif
2008-02-17 18:00:42 +00:00
/**
* Show a message box of the type @ c type with @ c text .
* On Unix - like systems a GTK message dialog box is shown , on Win32 systems a native Windows
* message dialog box is shown .
*
2009-07-09 13:51:37 +00:00
* @ param type A GtkMessageType , e . g . GTK_MESSAGE_INFO , GTK_MESSAGE_WARNING ,
* GTK_MESSAGE_QUESTION , GTK_MESSAGE_ERROR .
2008-02-17 18:00:42 +00:00
* @ param text Printf ( ) - style format string .
* @ param . . . Arguments for the @ c text format string .
* */
2009-07-09 13:51:37 +00:00
void dialogs_show_msgbox ( GtkMessageType type , const gchar * text , . . . )
2005-11-22 12:26:26 +00:00
{
2006-07-26 17:02:16 +00:00
# ifndef G_OS_WIN32
2005-11-22 12:26:26 +00:00
GtkWidget * dialog ;
# endif
2008-06-20 14:17:15 +00:00
gchar string [ 512 ] ;
2005-11-22 12:26:26 +00:00
va_list args ;
2009-07-19 20:19:09 +00:00
GtkWindow * parent = ( main_status . main_window_realized ) ? GTK_WINDOW ( main_widgets . window ) : NULL ;
2005-11-22 12:26:26 +00:00
va_start ( args , text ) ;
g_vsnprintf ( string , 511 , text , args ) ;
va_end ( args ) ;
2006-07-26 17:02:16 +00:00
# ifdef G_OS_WIN32
2009-07-19 20:19:09 +00:00
win32_message_dialog ( GTK_WIDGET ( parent ) , type , string ) ;
2005-11-22 12:26:26 +00:00
# else
2009-07-19 20:19:09 +00:00
dialog = gtk_message_dialog_new ( parent , GTK_DIALOG_DESTROY_WITH_PARENT ,
2006-10-25 14:38:48 +00:00
type , GTK_BUTTONS_OK , " %s " , string ) ;
2009-07-19 20:19:09 +00:00
show_msgbox_dialog ( dialog , type , parent ) ;
2005-11-22 12:26:26 +00:00
# endif
}
2009-07-09 13:51:37 +00:00
void dialogs_show_msgbox_with_secondary ( GtkMessageType type , const gchar * text , const gchar * secondary )
2007-11-29 18:08:20 +00:00
{
2009-07-19 20:19:09 +00:00
GtkWindow * parent = ( main_status . main_window_realized ) ? GTK_WINDOW ( main_widgets . window ) : NULL ;
2007-11-29 18:08:20 +00:00
# ifdef G_OS_WIN32
2008-02-27 13:17:29 +00:00
/* put the two strings together because Windows message boxes don't support secondary texts */
2007-11-29 18:08:20 +00:00
gchar * string = g_strconcat ( text , " \n " , secondary , NULL ) ;
2009-07-19 20:19:09 +00:00
win32_message_dialog ( GTK_WIDGET ( parent ) , type , string ) ;
2007-11-29 18:08:20 +00:00
g_free ( string ) ;
# else
2008-03-17 18:26:22 +00:00
GtkWidget * dialog ;
2009-07-19 20:19:09 +00:00
dialog = gtk_message_dialog_new ( parent , GTK_DIALOG_DESTROY_WITH_PARENT ,
2007-11-29 18:08:20 +00:00
type , GTK_BUTTONS_OK , " %s " , text ) ;
gtk_message_dialog_format_secondary_text ( GTK_MESSAGE_DIALOG ( dialog ) , " %s " , secondary ) ;
2009-07-19 20:19:09 +00:00
show_msgbox_dialog ( dialog , type , parent ) ;
2007-11-29 18:08:20 +00:00
# endif
}
2006-07-26 17:02:16 +00:00
# ifndef G_OS_WIN32
2008-10-13 16:00:53 +00:00
static gint run_unsaved_dialog ( const gchar * msg , const gchar * msg2 )
{
2006-12-08 16:21:52 +00:00
GtkWidget * dialog , * button ;
2008-10-13 16:00:53 +00:00
gint ret ;
dialog = gtk_message_dialog_new ( GTK_WINDOW ( main_widgets . window ) , GTK_DIALOG_DESTROY_WITH_PARENT ,
GTK_MESSAGE_QUESTION , GTK_BUTTONS_NONE , " %s " , msg ) ;
gtk_message_dialog_format_secondary_text ( GTK_MESSAGE_DIALOG ( dialog ) , " %s " , msg2 ) ;
gtk_dialog_add_button ( GTK_DIALOG ( dialog ) , GTK_STOCK_CANCEL , GTK_RESPONSE_CANCEL ) ;
button = ui_button_new_with_image ( GTK_STOCK_CLEAR , _ ( " _Don't save " ) ) ;
gtk_dialog_add_action_widget ( GTK_DIALOG ( dialog ) , button , GTK_RESPONSE_NO ) ;
gtk_widget_show ( button ) ;
gtk_dialog_add_button ( GTK_DIALOG ( dialog ) , GTK_STOCK_SAVE , GTK_RESPONSE_YES ) ;
gtk_dialog_set_default_response ( GTK_DIALOG ( dialog ) , GTK_RESPONSE_YES ) ;
ret = gtk_dialog_run ( GTK_DIALOG ( dialog ) ) ;
gtk_widget_destroy ( dialog ) ;
return ret ;
}
2005-11-22 12:26:26 +00:00
# endif
2008-10-13 16:00:53 +00:00
gboolean dialogs_show_unsaved_file ( GeanyDocument * doc )
{
gchar * msg , * short_fn = NULL ;
const gchar * msg2 ;
2005-11-22 12:26:26 +00:00
gint ret ;
2008-06-04 13:23:43 +00:00
gboolean old_quitting_state = main_status . quitting ;
2005-11-22 12:26:26 +00:00
2008-02-27 13:17:29 +00:00
/* display the file tab to remind the user of the document */
2008-06-03 18:15:52 +00:00
main_status . quitting = FALSE ;
2008-05-22 14:41:28 +00:00
gtk_notebook_set_current_page ( GTK_NOTEBOOK ( main_widgets . notebook ) ,
2008-06-15 13:35:48 +00:00
document_get_notebook_page ( doc ) ) ;
2008-06-04 13:23:43 +00:00
main_status . quitting = old_quitting_state ;
2006-12-18 12:34:29 +00:00
2009-04-21 20:52:51 +00:00
short_fn = document_get_basename_for_display ( doc , - 1 ) ;
2006-10-20 16:40:12 +00:00
msg = g_strdup_printf ( _ ( " The file '%s' is not saved. " ) ,
( short_fn ! = NULL ) ? short_fn : GEANY_STRING_UNTITLED ) ;
2007-07-08 14:55:37 +00:00
msg2 = _ ( " Do you want to save it before closing? " ) ;
2006-10-20 16:40:12 +00:00
g_free ( short_fn ) ;
2006-07-26 17:02:16 +00:00
# ifdef G_OS_WIN32
2007-07-08 14:55:37 +00:00
setptr ( msg , g_strconcat ( msg , " \n " , msg2 , NULL ) ) ;
2006-07-25 12:46:08 +00:00
ret = win32_message_dialog_unsaved ( msg ) ;
2005-11-22 12:26:26 +00:00
# else
2008-10-13 16:00:53 +00:00
ret = run_unsaved_dialog ( msg , msg2 ) ;
2005-11-22 12:26:26 +00:00
# endif
g_free ( msg ) ;
switch ( ret )
{
case GTK_RESPONSE_YES :
{
2008-06-15 13:35:48 +00:00
if ( doc - > file_name = = NULL )
2006-09-05 18:33:48 +00:00
{
2006-11-07 11:24:22 +00:00
ret = dialogs_show_save_as ( ) ;
2006-09-05 18:33:48 +00:00
}
2005-11-22 12:26:26 +00:00
else
2008-02-27 13:17:29 +00:00
/* document_save_file() returns the status if the file could be saved */
2008-06-15 13:35:48 +00:00
ret = document_save_file ( doc , FALSE ) ;
2005-11-22 12:26:26 +00:00
break ;
}
case GTK_RESPONSE_NO : ret = TRUE ; break ;
case GTK_RESPONSE_CANCEL : /* fall through to default and leave the function */
default : ret = FALSE ; break ;
}
return ( gboolean ) ret ;
}
2007-07-28 17:44:02 +00:00
# ifndef G_OS_WIN32
2007-07-17 14:52:57 +00:00
static void
on_font_apply_button_clicked ( GtkButton * button ,
gpointer user_data )
{
gchar * fontname ;
fontname = gtk_font_selection_dialog_get_font_name (
2007-08-23 11:34:06 +00:00
GTK_FONT_SELECTION_DIALOG ( ui_widgets . open_fontsel ) ) ;
2007-07-17 14:52:57 +00:00
ui_set_editor_font ( fontname ) ;
g_free ( fontname ) ;
}
static void
on_font_ok_button_clicked ( GtkButton * button ,
gpointer user_data )
{
2008-02-27 13:17:29 +00:00
/* We do the same thing as apply, but we close the dialog after. */
2007-07-17 14:52:57 +00:00
on_font_apply_button_clicked ( button , NULL ) ;
2007-08-23 11:34:06 +00:00
gtk_widget_hide ( ui_widgets . open_fontsel ) ;
2007-07-17 14:52:57 +00:00
}
static void
on_font_cancel_button_clicked ( GtkButton * button ,
gpointer user_data )
{
2007-08-23 11:34:06 +00:00
gtk_widget_hide ( ui_widgets . open_fontsel ) ;
2007-07-17 14:52:57 +00:00
}
2007-07-28 17:44:02 +00:00
# endif
2007-07-17 14:52:57 +00:00
2005-11-22 12:26:26 +00:00
/* This shows the font selection dialog to choose a font. */
2006-09-09 14:36:15 +00:00
void dialogs_show_open_font ( )
2005-11-22 12:26:26 +00:00
{
2006-07-26 17:02:16 +00:00
# ifdef G_OS_WIN32
2005-11-22 12:26:26 +00:00
win32_show_font_dialog ( ) ;
2006-02-22 13:46:20 +00:00
# else
2005-11-22 12:26:26 +00:00
2007-08-23 11:34:06 +00:00
if ( ui_widgets . open_fontsel = = NULL )
2005-11-22 12:26:26 +00:00
{
2007-08-23 11:34:06 +00:00
ui_widgets . open_fontsel = gtk_font_selection_dialog_new ( _ ( " Choose font " ) ) ; ;
gtk_container_set_border_width ( GTK_CONTAINER ( ui_widgets . open_fontsel ) , 4 ) ;
gtk_window_set_modal ( GTK_WINDOW ( ui_widgets . open_fontsel ) , TRUE ) ;
gtk_window_set_destroy_with_parent ( GTK_WINDOW ( ui_widgets . open_fontsel ) , TRUE ) ;
gtk_window_set_skip_taskbar_hint ( GTK_WINDOW ( ui_widgets . open_fontsel ) , TRUE ) ;
gtk_window_set_type_hint ( GTK_WINDOW ( ui_widgets . open_fontsel ) , GDK_WINDOW_TYPE_HINT_DIALOG ) ;
gtk_widget_set_name ( ui_widgets . open_fontsel , " GeanyDialog " ) ;
2006-02-25 22:26:43 +00:00
2007-08-23 11:34:06 +00:00
gtk_widget_show ( GTK_FONT_SELECTION_DIALOG ( ui_widgets . open_fontsel ) - > apply_button ) ;
2006-02-22 13:46:20 +00:00
2008-07-18 13:40:48 +00:00
g_signal_connect ( ui_widgets . open_fontsel ,
" delete-event " , G_CALLBACK ( gtk_widget_hide_on_delete ) , NULL ) ;
g_signal_connect ( GTK_FONT_SELECTION_DIALOG ( ui_widgets . open_fontsel ) - > ok_button ,
2006-02-22 13:46:20 +00:00
" clicked " , G_CALLBACK ( on_font_ok_button_clicked ) , NULL ) ;
2008-07-18 13:40:48 +00:00
g_signal_connect ( GTK_FONT_SELECTION_DIALOG ( ui_widgets . open_fontsel ) - > cancel_button ,
2006-02-22 13:46:20 +00:00
" clicked " , G_CALLBACK ( on_font_cancel_button_clicked ) , NULL ) ;
2008-07-18 13:40:48 +00:00
g_signal_connect ( GTK_FONT_SELECTION_DIALOG ( ui_widgets . open_fontsel ) - > apply_button ,
2006-02-22 13:46:20 +00:00
" clicked " , G_CALLBACK ( on_font_apply_button_clicked ) , NULL ) ;
2007-01-19 23:17:40 +00:00
gtk_font_selection_dialog_set_font_name (
2008-05-16 12:08:39 +00:00
GTK_FONT_SELECTION_DIALOG ( ui_widgets . open_fontsel ) , interface_prefs . editor_font ) ;
2008-05-22 14:41:28 +00:00
gtk_window_set_transient_for ( GTK_WINDOW ( ui_widgets . open_fontsel ) , GTK_WINDOW ( main_widgets . window ) ) ;
2005-11-22 12:26:26 +00:00
}
/* We make sure the dialog is visible. */
2007-08-23 11:34:06 +00:00
gtk_window_present ( GTK_WINDOW ( ui_widgets . open_fontsel ) ) ;
2005-11-22 12:26:26 +00:00
# endif
}
2007-12-21 13:09:09 +00:00
static void
on_input_dialog_show ( GtkDialog * dialog , GtkWidget * entry )
2005-11-22 12:26:26 +00:00
{
2007-12-21 13:09:09 +00:00
gtk_widget_grab_focus ( entry ) ;
}
2005-11-22 12:26:26 +00:00
2007-12-21 13:09:09 +00:00
static void
on_input_entry_activate ( GtkEntry * entry , GtkDialog * dialog )
{
gtk_dialog_response ( dialog , GTK_RESPONSE_ACCEPT ) ;
}
2008-06-19 14:31:09 +00:00
static void
on_input_numeric_activate ( GtkEntry * entry , GtkDialog * dialog )
{
gtk_dialog_response ( dialog , GTK_RESPONSE_ACCEPT ) ;
}
2007-12-21 13:09:09 +00:00
static void
on_input_dialog_response ( GtkDialog * dialog ,
gint response ,
GtkWidget * entry )
{
2008-02-20 11:24:23 +00:00
gboolean persistent = ( gboolean ) GPOINTER_TO_INT ( g_object_get_data ( G_OBJECT ( dialog ) , " has_combo " ) ) ;
2007-12-21 13:09:09 +00:00
if ( response = = GTK_RESPONSE_ACCEPT )
{
const gchar * str = gtk_entry_get_text ( GTK_ENTRY ( entry ) ) ;
InputCallback input_cb =
( InputCallback ) g_object_get_data ( G_OBJECT ( dialog ) , " input_cb " ) ;
if ( persistent )
{
GtkWidget * combo = ( GtkWidget * ) g_object_get_data ( G_OBJECT ( dialog ) , " combo " ) ;
ui_combo_box_add_to_history ( GTK_COMBO_BOX ( combo ) , str ) ;
}
input_cb ( str ) ;
}
if ( persistent )
gtk_widget_hide ( GTK_WIDGET ( dialog ) ) ;
else
gtk_widget_destroy ( GTK_WIDGET ( dialog ) ) ;
}
static void add_input_widgets ( GtkWidget * dialog , GtkWidget * vbox ,
const gchar * label_text , const gchar * default_text , gboolean persistent )
{
GtkWidget * label , * entry ;
2005-11-22 12:26:26 +00:00
2006-08-19 12:56:30 +00:00
label = gtk_label_new ( label_text ) ;
gtk_label_set_line_wrap ( GTK_LABEL ( label ) , TRUE ) ;
2006-10-19 16:26:29 +00:00
gtk_misc_set_alignment ( GTK_MISC ( label ) , 0 , 0.5 ) ;
2007-12-21 13:09:09 +00:00
gtk_container_add ( GTK_CONTAINER ( vbox ) , label ) ;
2008-02-27 13:17:29 +00:00
if ( persistent ) /* remember previous entry text in a combo box */
2007-12-21 13:09:09 +00:00
{
GtkWidget * combo = gtk_combo_box_entry_new_text ( ) ;
entry = GTK_BIN ( combo ) - > child ;
2009-02-10 21:10:50 +00:00
ui_entry_add_clear_icon ( entry ) ;
2007-12-21 13:09:09 +00:00
g_object_set_data ( G_OBJECT ( dialog ) , " combo " , combo ) ;
gtk_container_add ( GTK_CONTAINER ( vbox ) , combo ) ;
}
else
{
entry = gtk_entry_new ( ) ;
2009-02-10 21:10:50 +00:00
ui_entry_add_clear_icon ( entry ) ;
2007-12-21 13:09:09 +00:00
gtk_container_add ( GTK_CONTAINER ( vbox ) , entry ) ;
}
2006-08-19 12:56:30 +00:00
if ( default_text ! = NULL )
2005-11-22 12:26:26 +00:00
{
2006-08-19 12:56:30 +00:00
gtk_entry_set_text ( GTK_ENTRY ( entry ) , default_text ) ;
2005-11-22 12:26:26 +00:00
}
2006-08-19 12:56:30 +00:00
gtk_entry_set_max_length ( GTK_ENTRY ( entry ) , 255 ) ;
2005-11-22 12:26:26 +00:00
gtk_entry_set_width_chars ( GTK_ENTRY ( entry ) , 30 ) ;
2008-07-18 13:40:48 +00:00
g_signal_connect ( entry , " activate " , G_CALLBACK ( on_input_entry_activate ) , dialog ) ;
g_signal_connect ( dialog , " show " , G_CALLBACK ( on_input_dialog_show ) , entry ) ;
g_signal_connect ( dialog , " response " , G_CALLBACK ( on_input_dialog_response ) , entry ) ;
2007-12-21 13:09:09 +00:00
}
/* Create and display an input dialog.
* persistent : whether to remember previous entry text in a combo box ;
* in this case the dialog returned is not destroyed on a response ,
* and can be reshown .
* Returns : the dialog widget . */
GtkWidget *
dialogs_show_input ( const gchar * title , const gchar * label_text , const gchar * default_text ,
gboolean persistent , InputCallback input_cb )
{
GtkWidget * dialog , * vbox ;
2008-05-22 14:41:28 +00:00
dialog = gtk_dialog_new_with_buttons ( title , GTK_WINDOW ( main_widgets . window ) ,
2007-12-21 13:09:09 +00:00
GTK_DIALOG_DESTROY_WITH_PARENT , GTK_STOCK_CANCEL , GTK_RESPONSE_CANCEL ,
GTK_STOCK_OK , GTK_RESPONSE_ACCEPT , NULL ) ;
vbox = ui_dialog_vbox_new ( GTK_DIALOG ( dialog ) ) ;
gtk_widget_set_name ( dialog , " GeanyDialog " ) ;
gtk_box_set_spacing ( GTK_BOX ( vbox ) , 6 ) ;
2008-02-12 15:50:22 +00:00
g_object_set_data ( G_OBJECT ( dialog ) , " has_combo " , GINT_TO_POINTER ( persistent ) ) ;
2007-12-21 13:09:09 +00:00
g_object_set_data ( G_OBJECT ( dialog ) , " input_cb " , ( gpointer ) input_cb ) ;
add_input_widgets ( dialog , vbox , label_text , default_text , persistent ) ;
if ( persistent )
2008-07-18 13:40:48 +00:00
g_signal_connect ( dialog , " delete-event " , G_CALLBACK ( gtk_widget_hide_on_delete ) , NULL ) ;
2007-12-21 13:09:09 +00:00
else
2008-07-18 13:40:48 +00:00
g_signal_connect ( dialog , " delete-event " , G_CALLBACK ( gtk_widget_destroy ) , NULL ) ;
2005-11-22 12:26:26 +00:00
gtk_widget_show_all ( dialog ) ;
2007-12-21 13:09:09 +00:00
return dialog ;
2005-11-22 12:26:26 +00:00
}
2009-01-21 22:49:47 +00:00
/**
* Show an input box to enter a numerical value using a GtkSpinButton .
2009-01-21 23:19:25 +00:00
* If the dialog is aborted , @ c value remains untouched .
2009-01-21 22:49:47 +00:00
*
* @ param title The dialog title .
* @ param label_text The shown dialog label .
* @ param value The default value for the spin button and the return location of the entered value .
* Must be non - NULL .
* @ param min Minimum allowable value ( see documentation for @ a gtk_spin_button_new_with_range ( ) ) .
* @ param max Maximum allowable value ( see documentation for @ a gtk_spin_button_new_with_range ( ) ) .
* @ param step Increment added or subtracted by spinning the widget
* ( see documentation for @ a gtk_spin_button_new_with_range ( ) ) .
*
* @ return @ a TRUE if a value was entered and the dialog closed with ' OK ' . @ a FALSE otherwise .
2009-01-30 18:53:23 +00:00
*
* @ since 0.16
2009-01-21 22:49:47 +00:00
* */
2008-06-19 14:31:09 +00:00
gboolean dialogs_show_input_numeric ( const gchar * title , const gchar * label_text ,
gdouble * value , gdouble min , gdouble max , gdouble step )
{
GtkWidget * dialog , * label , * spin , * vbox ;
gboolean res = FALSE ;
2009-04-15 22:47:33 +00:00
g_return_val_if_fail ( title ! = NULL , FALSE ) ;
g_return_val_if_fail ( label_text ! = NULL , FALSE ) ;
g_return_val_if_fail ( value ! = NULL , FALSE ) ;
2009-01-21 22:49:47 +00:00
2008-06-19 14:31:09 +00:00
dialog = gtk_dialog_new_with_buttons ( title , GTK_WINDOW ( main_widgets . window ) ,
GTK_DIALOG_DESTROY_WITH_PARENT ,
GTK_STOCK_CANCEL , GTK_RESPONSE_CANCEL ,
GTK_STOCK_OK , GTK_RESPONSE_ACCEPT , NULL ) ;
gtk_dialog_set_default_response ( GTK_DIALOG ( dialog ) , GTK_RESPONSE_CANCEL ) ;
vbox = ui_dialog_vbox_new ( GTK_DIALOG ( dialog ) ) ;
gtk_widget_set_name ( dialog , " GeanyDialog " ) ;
label = gtk_label_new ( label_text ) ;
gtk_misc_set_alignment ( GTK_MISC ( label ) , 0 , 0.5 ) ;
spin = gtk_spin_button_new_with_range ( min , max , step ) ;
2009-02-10 21:10:50 +00:00
ui_entry_add_clear_icon ( spin ) ;
2008-06-19 14:31:09 +00:00
gtk_spin_button_set_value ( GTK_SPIN_BUTTON ( spin ) , * value ) ;
g_signal_connect ( spin , " activate " , G_CALLBACK ( on_input_numeric_activate ) , dialog ) ;
gtk_container_add ( GTK_CONTAINER ( vbox ) , label ) ;
gtk_container_add ( GTK_CONTAINER ( vbox ) , spin ) ;
gtk_widget_show_all ( vbox ) ;
if ( gtk_dialog_run ( GTK_DIALOG ( dialog ) ) = = GTK_RESPONSE_ACCEPT )
{
* value = gtk_spin_button_get_value ( GTK_SPIN_BUTTON ( spin ) ) ;
res = TRUE ;
}
gtk_widget_destroy ( dialog ) ;
return res ;
}
2008-06-15 13:35:48 +00:00
void dialogs_show_file_properties ( GeanyDocument * doc )
2006-02-22 13:46:20 +00:00
{
2006-10-19 16:26:29 +00:00
GtkWidget * dialog , * label , * table , * hbox , * image , * perm_table , * check , * vbox ;
2006-07-22 01:29:10 +00:00
gchar * file_size , * title , * base_name , * time_changed , * time_modified , * time_accessed , * enctext ;
2009-04-21 20:52:51 +00:00
gchar * short_name ;
2008-06-04 15:43:52 +00:00
# ifdef HAVE_SYS_TYPES_H
2006-02-22 13:46:20 +00:00
struct stat st ;
2006-02-25 22:26:43 +00:00
off_t filesize ;
2006-02-22 13:46:20 +00:00
mode_t mode ;
2006-04-27 18:06:35 +00:00
gchar * locale_filename ;
2006-02-22 13:46:20 +00:00
# else
gint filesize = 0 ;
gint mode = 0 ;
# endif
2008-02-27 13:17:29 +00:00
/* define this ones, to avoid later trouble */
2006-05-05 16:37:35 +00:00
# ifndef S_IRUSR
# define S_IRUSR 0
# define S_IWUSR 0
# define S_IXUSR 0
# endif
# ifndef S_IRGRP
# define S_IRGRP 0
# define S_IWGRP 0
# define S_IXGRP 0
# define S_IROTH 0
# define S_IWOTH 0
# define S_IXOTH 0
# endif
2009-04-15 22:47:33 +00:00
if ( doc = = NULL | | doc - > file_name = = NULL )
2006-04-27 18:06:35 +00:00
{
2006-10-25 14:38:48 +00:00
dialogs_show_msgbox ( GTK_MESSAGE_ERROR ,
_ ( " An error occurred or file information could not be retrieved (e.g. from a new file). " ) ) ;
2006-04-27 18:06:35 +00:00
return ;
}
2006-05-14 16:07:30 +00:00
2006-02-22 13:46:20 +00:00
2008-06-04 15:43:52 +00:00
# ifdef HAVE_SYS_TYPES_H
2008-06-15 13:35:48 +00:00
locale_filename = utils_get_locale_from_utf8 ( doc - > file_name ) ;
2007-04-16 15:58:34 +00:00
if ( g_stat ( locale_filename , & st ) = = 0 )
2006-02-22 13:46:20 +00:00
{
2008-02-27 13:17:29 +00:00
/* first copy the returned string and the trim it, to not modify the static glibc string
* g_strchomp ( ) is used to remove trailing EOL chars , which are there for whatever reason */
2006-04-27 18:06:35 +00:00
time_changed = g_strchomp ( g_strdup ( ctime ( & st . st_ctime ) ) ) ;
time_modified = g_strchomp ( g_strdup ( ctime ( & st . st_mtime ) ) ) ;
time_accessed = g_strchomp ( g_strdup ( ctime ( & st . st_atime ) ) ) ;
2006-02-22 13:46:20 +00:00
filesize = st . st_size ;
mode = st . st_mode ;
}
2006-02-25 22:26:43 +00:00
else
2006-02-22 13:46:20 +00:00
{
time_changed = g_strdup ( _ ( " unknown " ) ) ;
time_modified = g_strdup ( _ ( " unknown " ) ) ;
time_accessed = g_strdup ( _ ( " unknown " ) ) ;
2006-02-25 22:26:43 +00:00
filesize = ( off_t ) 0 ;
mode = ( mode_t ) 0 ;
2006-02-22 13:46:20 +00:00
}
g_free ( locale_filename ) ;
# else
time_changed = g_strdup ( _ ( " unknown " ) ) ;
time_modified = g_strdup ( _ ( " unknown " ) ) ;
time_accessed = g_strdup ( _ ( " unknown " ) ) ;
# endif
2008-06-15 13:35:48 +00:00
base_name = g_path_get_basename ( doc - > file_name ) ;
2009-04-21 20:52:51 +00:00
short_name = utils_str_middle_truncate ( base_name , 30 ) ;
title = g_strconcat ( short_name , " " , _ ( " Properties " ) , NULL ) ;
2008-05-22 14:41:28 +00:00
dialog = gtk_dialog_new_with_buttons ( title , GTK_WINDOW ( main_widgets . window ) ,
2006-02-22 13:46:20 +00:00
GTK_DIALOG_DESTROY_WITH_PARENT ,
2006-10-19 16:26:29 +00:00
GTK_STOCK_CLOSE , GTK_RESPONSE_CANCEL , NULL ) ;
2009-04-21 20:52:51 +00:00
g_free ( short_name ) ;
2006-02-22 13:46:20 +00:00
g_free ( title ) ;
2007-05-15 15:16:16 +00:00
gtk_widget_set_name ( dialog , " GeanyDialog " ) ;
2006-10-22 14:56:05 +00:00
vbox = ui_dialog_vbox_new ( GTK_DIALOG ( dialog ) ) ;
2006-02-22 13:46:20 +00:00
2006-03-02 21:12:27 +00:00
g_signal_connect ( dialog , " response " , G_CALLBACK ( gtk_widget_destroy ) , NULL ) ;
2008-07-18 13:40:48 +00:00
g_signal_connect ( dialog , " delete-event " , G_CALLBACK ( gtk_widget_destroy ) , NULL ) ;
2006-02-22 13:46:20 +00:00
2006-04-27 18:06:35 +00:00
gtk_window_set_default_size ( GTK_WINDOW ( dialog ) , 300 , - 1 ) ;
2006-10-19 16:26:29 +00:00
title = g_strdup_printf ( " <b>%s</b> " , base_name ) ;
2006-02-22 13:46:20 +00:00
label = gtk_label_new ( title ) ;
2008-10-10 16:43:40 +00:00
gtk_label_set_selectable ( GTK_LABEL ( label ) , TRUE ) ;
2006-10-19 16:26:29 +00:00
gtk_misc_set_alignment ( GTK_MISC ( label ) , 0.0 , 0.5 ) ;
2006-02-22 13:46:20 +00:00
image = gtk_image_new_from_stock ( " gtk-file " , GTK_ICON_SIZE_BUTTON ) ;
2006-10-19 16:26:29 +00:00
gtk_misc_set_alignment ( GTK_MISC ( image ) , 1.0 , 0.5 ) ;
hbox = gtk_hbox_new ( FALSE , 6 ) ;
2006-02-22 13:46:20 +00:00
gtk_label_set_use_markup ( GTK_LABEL ( label ) , TRUE ) ;
gtk_container_add ( GTK_CONTAINER ( hbox ) , image ) ;
gtk_container_add ( GTK_CONTAINER ( hbox ) , label ) ;
2006-10-19 16:26:29 +00:00
gtk_container_add ( GTK_CONTAINER ( vbox ) , hbox ) ;
2006-02-22 13:46:20 +00:00
g_free ( title ) ;
2006-04-27 18:06:35 +00:00
table = gtk_table_new ( 8 , 2 , FALSE ) ;
2006-02-22 13:46:20 +00:00
gtk_table_set_row_spacings ( GTK_TABLE ( table ) , 10 ) ;
2006-04-27 18:06:35 +00:00
gtk_table_set_col_spacings ( GTK_TABLE ( table ) , 10 ) ;
2006-02-22 13:46:20 +00:00
label = gtk_label_new ( _ ( " <b>Type:</b> " ) ) ;
gtk_table_attach ( GTK_TABLE ( table ) , label , 0 , 1 , 0 , 1 ,
( GtkAttachOptions ) ( GTK_FILL ) ,
( GtkAttachOptions ) ( 0 ) , 0 , 0 ) ;
gtk_label_set_use_markup ( GTK_LABEL ( label ) , TRUE ) ;
gtk_misc_set_alignment ( GTK_MISC ( label ) , 1 , 0 ) ;
2008-06-15 13:35:48 +00:00
label = gtk_label_new ( doc - > file_type - > title ) ;
2008-10-10 16:43:40 +00:00
gtk_label_set_selectable ( GTK_LABEL ( label ) , TRUE ) ;
2006-02-22 13:46:20 +00:00
gtk_table_attach ( GTK_TABLE ( table ) , label , 1 , 2 , 0 , 1 ,
( GtkAttachOptions ) ( GTK_FILL ) ,
( GtkAttachOptions ) ( 0 ) , 0 , 0 ) ;
gtk_misc_set_alignment ( GTK_MISC ( label ) , 0 , 0 ) ;
label = gtk_label_new ( _ ( " <b>Size:</b> " ) ) ;
gtk_table_attach ( GTK_TABLE ( table ) , label , 0 , 1 , 1 , 2 ,
( GtkAttachOptions ) ( GTK_FILL ) ,
( GtkAttachOptions ) ( 0 ) , 0 , 0 ) ;
gtk_label_set_use_markup ( GTK_LABEL ( label ) , TRUE ) ;
gtk_misc_set_alignment ( GTK_MISC ( label ) , 1 , 0 ) ;
file_size = utils_make_human_readable_str ( filesize , 1 , 0 ) ;
label = gtk_label_new ( file_size ) ;
2008-10-10 16:43:40 +00:00
gtk_label_set_selectable ( GTK_LABEL ( label ) , TRUE ) ;
2006-02-22 13:46:20 +00:00
gtk_table_attach ( GTK_TABLE ( table ) , label , 1 , 2 , 1 , 2 ,
( GtkAttachOptions ) ( GTK_FILL ) ,
( GtkAttachOptions ) ( 0 ) , 0 , 0 ) ;
g_free ( file_size ) ;
gtk_misc_set_alignment ( GTK_MISC ( label ) , 0 , 0 ) ;
label = gtk_label_new ( _ ( " <b>Location:</b> " ) ) ;
gtk_table_attach ( GTK_TABLE ( table ) , label , 0 , 1 , 2 , 3 ,
( GtkAttachOptions ) ( GTK_FILL ) ,
( GtkAttachOptions ) ( 0 ) , 0 , 0 ) ;
gtk_label_set_use_markup ( GTK_LABEL ( label ) , TRUE ) ;
gtk_misc_set_alignment ( GTK_MISC ( label ) , 1 , 0 ) ;
2008-06-15 13:35:48 +00:00
label = gtk_label_new ( doc - > file_name ) ;
2008-10-10 16:43:40 +00:00
gtk_label_set_selectable ( GTK_LABEL ( label ) , TRUE ) ;
2006-02-22 13:46:20 +00:00
gtk_table_attach ( GTK_TABLE ( table ) , label , 1 , 2 , 2 , 3 ,
( GtkAttachOptions ) ( GTK_FILL ) ,
( GtkAttachOptions ) ( 0 ) , 0 , 0 ) ;
2006-04-27 18:06:35 +00:00
gtk_misc_set_alignment ( GTK_MISC ( label ) , 0.0 , 0 ) ;
2006-02-22 13:46:20 +00:00
2006-04-27 18:06:35 +00:00
label = gtk_label_new ( _ ( " <b>Read-only:</b> " ) ) ;
2006-02-22 13:46:20 +00:00
gtk_table_attach ( GTK_TABLE ( table ) , label , 0 , 1 , 3 , 4 ,
( GtkAttachOptions ) ( GTK_FILL ) ,
( GtkAttachOptions ) ( 0 ) , 0 , 0 ) ;
gtk_label_set_use_markup ( GTK_LABEL ( label ) , TRUE ) ;
gtk_misc_set_alignment ( GTK_MISC ( label ) , 1 , 0 ) ;
2006-04-27 18:06:35 +00:00
check = gtk_check_button_new_with_label ( _ ( " (only inside Geany) " ) ) ;
gtk_widget_set_sensitive ( check , FALSE ) ;
gtk_button_set_focus_on_click ( GTK_BUTTON ( check ) , FALSE ) ;
2008-06-15 13:35:48 +00:00
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( check ) , doc - > readonly ) ;
2006-04-27 18:06:35 +00:00
gtk_table_attach ( GTK_TABLE ( table ) , check , 1 , 2 , 3 , 4 ,
( GtkAttachOptions ) ( GTK_FILL ) ,
( GtkAttachOptions ) ( 0 ) , 0 , 0 ) ;
gtk_button_set_alignment ( GTK_BUTTON ( check ) , 0.0 , 0 ) ;
label = gtk_label_new ( _ ( " <b>Encoding:</b> " ) ) ;
gtk_table_attach ( GTK_TABLE ( table ) , label , 0 , 1 , 4 , 5 ,
( GtkAttachOptions ) ( GTK_FILL ) ,
( GtkAttachOptions ) ( 0 ) , 0 , 0 ) ;
gtk_label_set_use_markup ( GTK_LABEL ( label ) , TRUE ) ;
gtk_misc_set_alignment ( GTK_MISC ( label ) , 1 , 0 ) ;
2006-07-22 01:29:10 +00:00
enctext = g_strdup_printf ( " %s %s " ,
2008-06-15 13:35:48 +00:00
doc - > encoding ,
( encodings_is_unicode_charset ( doc - > encoding ) ) ?
( ( doc - > has_bom ) ? _ ( " (with BOM) " ) : _ ( " (without BOM) " ) ) : " " ) ;
2006-07-22 01:29:10 +00:00
label = gtk_label_new ( enctext ) ;
2008-10-10 16:43:40 +00:00
gtk_label_set_selectable ( GTK_LABEL ( label ) , TRUE ) ;
2006-07-22 01:29:10 +00:00
g_free ( enctext ) ;
2006-04-27 18:06:35 +00:00
gtk_table_attach ( GTK_TABLE ( table ) , label , 1 , 2 , 4 , 5 ,
( GtkAttachOptions ) ( GTK_FILL ) ,
( GtkAttachOptions ) ( 0 ) , 0 , 0 ) ;
gtk_misc_set_alignment ( GTK_MISC ( label ) , 0.0 , 0 ) ;
label = gtk_label_new ( _ ( " <b>Modified:</b> " ) ) ;
gtk_table_attach ( GTK_TABLE ( table ) , label , 0 , 1 , 5 , 6 ,
( GtkAttachOptions ) ( GTK_FILL ) ,
( GtkAttachOptions ) ( 0 ) , 0 , 0 ) ;
gtk_label_set_use_markup ( GTK_LABEL ( label ) , TRUE ) ;
gtk_misc_set_alignment ( GTK_MISC ( label ) , 1 , 0 ) ;
2006-02-22 13:46:20 +00:00
label = gtk_label_new ( time_modified ) ;
2008-10-10 16:43:40 +00:00
gtk_label_set_selectable ( GTK_LABEL ( label ) , TRUE ) ;
2006-04-27 18:06:35 +00:00
gtk_table_attach ( GTK_TABLE ( table ) , label , 1 , 2 , 5 , 6 ,
2006-02-22 13:46:20 +00:00
( GtkAttachOptions ) ( GTK_FILL ) ,
( GtkAttachOptions ) ( 0 ) , 0 , 0 ) ;
gtk_misc_set_alignment ( GTK_MISC ( label ) , 0 , 0 ) ;
label = gtk_label_new ( _ ( " <b>Changed:</b> " ) ) ;
2006-04-27 18:06:35 +00:00
gtk_table_attach ( GTK_TABLE ( table ) , label , 0 , 1 , 6 , 7 ,
2006-02-22 13:46:20 +00:00
( GtkAttachOptions ) ( GTK_FILL ) ,
( GtkAttachOptions ) ( 0 ) , 0 , 0 ) ;
gtk_label_set_use_markup ( GTK_LABEL ( label ) , TRUE ) ;
gtk_misc_set_alignment ( GTK_MISC ( label ) , 1 , 0 ) ;
label = gtk_label_new ( time_changed ) ;
2008-10-10 16:43:40 +00:00
gtk_label_set_selectable ( GTK_LABEL ( label ) , TRUE ) ;
2006-04-27 18:06:35 +00:00
gtk_table_attach ( GTK_TABLE ( table ) , label , 1 , 2 , 6 , 7 ,
2006-02-22 13:46:20 +00:00
( GtkAttachOptions ) ( GTK_FILL ) ,
( GtkAttachOptions ) ( 0 ) , 0 , 0 ) ;
gtk_misc_set_alignment ( GTK_MISC ( label ) , 0 , 0 ) ;
label = gtk_label_new ( _ ( " <b>Accessed:</b> " ) ) ;
2006-04-27 18:06:35 +00:00
gtk_table_attach ( GTK_TABLE ( table ) , label , 0 , 1 , 7 , 8 ,
2006-02-22 13:46:20 +00:00
( GtkAttachOptions ) ( GTK_FILL ) ,
( GtkAttachOptions ) ( 0 ) , 0 , 0 ) ;
gtk_label_set_use_markup ( GTK_LABEL ( label ) , TRUE ) ;
gtk_misc_set_alignment ( GTK_MISC ( label ) , 1 , 0 ) ;
label = gtk_label_new ( time_accessed ) ;
2008-10-10 16:43:40 +00:00
gtk_label_set_selectable ( GTK_LABEL ( label ) , TRUE ) ;
2006-04-27 18:06:35 +00:00
gtk_table_attach ( GTK_TABLE ( table ) , label , 1 , 2 , 7 , 8 ,
2006-02-22 13:46:20 +00:00
( GtkAttachOptions ) ( GTK_FILL ) ,
( GtkAttachOptions ) ( 0 ) , 0 , 0 ) ;
gtk_misc_set_alignment ( GTK_MISC ( label ) , 0 , 0 ) ;
2008-02-27 13:17:29 +00:00
/* add table */
2006-10-19 16:26:29 +00:00
gtk_container_add ( GTK_CONTAINER ( vbox ) , table ) ;
2006-05-14 16:07:30 +00:00
2008-02-27 13:17:29 +00:00
/* create table with the permissions */
2006-10-19 16:26:29 +00:00
perm_table = gtk_table_new ( 5 , 4 , TRUE ) ;
gtk_table_set_row_spacings ( GTK_TABLE ( perm_table ) , 5 ) ;
gtk_table_set_col_spacings ( GTK_TABLE ( perm_table ) , 5 ) ;
2006-02-22 13:46:20 +00:00
2006-10-09 13:50:23 +00:00
label = gtk_label_new ( _ ( " <b>Permissions:</b> " ) ) ;
2006-02-22 13:46:20 +00:00
gtk_label_set_use_markup ( GTK_LABEL ( label ) , TRUE ) ;
2006-10-19 16:26:29 +00:00
gtk_misc_set_alignment ( GTK_MISC ( label ) , 0 , 0.5 ) ;
gtk_table_attach ( GTK_TABLE ( perm_table ) , label , 0 , 4 , 0 , 1 ,
( GtkAttachOptions ) ( GTK_EXPAND | GTK_FILL ) ,
( GtkAttachOptions ) ( 0 ) , 0 , 0 ) ;
2006-02-22 13:46:20 +00:00
2008-02-27 13:17:29 +00:00
/* Header */
2006-04-27 18:06:35 +00:00
label = gtk_label_new ( _ ( " Read: " ) ) ;
2006-10-19 16:26:29 +00:00
gtk_table_attach ( GTK_TABLE ( perm_table ) , label , 1 , 2 , 1 , 2 ,
2006-04-27 18:06:35 +00:00
( GtkAttachOptions ) ( GTK_EXPAND | GTK_FILL ) ,
2006-02-22 13:46:20 +00:00
( GtkAttachOptions ) ( 0 ) , 0 , 0 ) ;
gtk_label_set_use_markup ( GTK_LABEL ( label ) , TRUE ) ;
2006-04-27 18:06:35 +00:00
gtk_misc_set_alignment ( GTK_MISC ( label ) , 0.0 , 0 ) ;
2006-02-22 13:46:20 +00:00
2006-04-27 18:06:35 +00:00
label = gtk_label_new ( _ ( " Write: " ) ) ;
2006-10-19 16:26:29 +00:00
gtk_table_attach ( GTK_TABLE ( perm_table ) , label , 2 , 3 , 1 , 2 ,
2006-04-27 18:06:35 +00:00
( GtkAttachOptions ) ( GTK_EXPAND | GTK_FILL ) ,
2006-02-22 13:46:20 +00:00
( GtkAttachOptions ) ( 0 ) , 0 , 0 ) ;
gtk_label_set_use_markup ( GTK_LABEL ( label ) , TRUE ) ;
2006-04-27 18:06:35 +00:00
gtk_misc_set_alignment ( GTK_MISC ( label ) , 0.0 , 0 ) ;
2006-02-22 13:46:20 +00:00
2006-04-27 18:06:35 +00:00
label = gtk_label_new ( _ ( " Execute: " ) ) ;
2006-10-19 16:26:29 +00:00
gtk_table_attach ( GTK_TABLE ( perm_table ) , label , 3 , 4 , 1 , 2 ,
2006-04-27 18:06:35 +00:00
( GtkAttachOptions ) ( GTK_EXPAND | GTK_FILL ) ,
2006-02-22 13:46:20 +00:00
( GtkAttachOptions ) ( 0 ) , 0 , 0 ) ;
gtk_label_set_use_markup ( GTK_LABEL ( label ) , TRUE ) ;
2006-04-27 18:06:35 +00:00
gtk_misc_set_alignment ( GTK_MISC ( label ) , 0.0 , 0 ) ;
2006-02-22 13:46:20 +00:00
2008-02-27 13:17:29 +00:00
/* Owner */
2006-04-27 18:06:35 +00:00
label = gtk_label_new ( _ ( " Owner: " ) ) ;
2006-10-19 16:26:29 +00:00
gtk_table_attach ( GTK_TABLE ( perm_table ) , label , 0 , 1 , 2 , 3 ,
2006-04-27 18:06:35 +00:00
( GtkAttachOptions ) ( GTK_EXPAND | GTK_FILL ) ,
2006-02-22 13:46:20 +00:00
( GtkAttachOptions ) ( 0 ) , 0 , 0 ) ;
gtk_label_set_use_markup ( GTK_LABEL ( label ) , TRUE ) ;
gtk_misc_set_alignment ( GTK_MISC ( label ) , 0.5 , 0 ) ;
check = gtk_check_button_new ( ) ;
2006-04-27 18:06:35 +00:00
gtk_widget_set_sensitive ( check , FALSE ) ;
2006-02-22 13:46:20 +00:00
gtk_button_set_focus_on_click ( GTK_BUTTON ( check ) , FALSE ) ;
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( check ) , mode & S_IRUSR ) ;
2006-10-19 16:26:29 +00:00
gtk_table_attach ( GTK_TABLE ( perm_table ) , check , 1 , 2 , 2 , 3 ,
2006-04-27 18:06:35 +00:00
( GtkAttachOptions ) ( GTK_EXPAND | GTK_EXPAND | GTK_FILL ) ,
2006-02-22 13:46:20 +00:00
( GtkAttachOptions ) ( 0 ) , 0 , 0 ) ;
gtk_button_set_alignment ( GTK_BUTTON ( check ) , 0.5 , 0 ) ;
check = gtk_check_button_new ( ) ;
2006-04-27 18:06:35 +00:00
gtk_widget_set_sensitive ( check , FALSE ) ;
2006-02-22 13:46:20 +00:00
gtk_button_set_focus_on_click ( GTK_BUTTON ( check ) , FALSE ) ;
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( check ) , mode & S_IWUSR ) ;
2006-10-19 16:26:29 +00:00
gtk_table_attach ( GTK_TABLE ( perm_table ) , check , 2 , 3 , 2 , 3 ,
2006-04-27 18:06:35 +00:00
( GtkAttachOptions ) ( GTK_EXPAND | GTK_FILL ) ,
2006-02-22 13:46:20 +00:00
( GtkAttachOptions ) ( 0 ) , 0 , 0 ) ;
gtk_button_set_alignment ( GTK_BUTTON ( check ) , 0.5 , 0 ) ;
check = gtk_check_button_new ( ) ;
2006-04-27 18:06:35 +00:00
gtk_widget_set_sensitive ( check , FALSE ) ;
2006-02-22 13:46:20 +00:00
gtk_button_set_focus_on_click ( GTK_BUTTON ( check ) , FALSE ) ;
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( check ) , mode & S_IXUSR ) ;
2006-10-19 16:26:29 +00:00
gtk_table_attach ( GTK_TABLE ( perm_table ) , check , 3 , 4 , 2 , 3 ,
2006-04-27 18:06:35 +00:00
( GtkAttachOptions ) ( GTK_EXPAND | GTK_FILL ) ,
2006-02-22 13:46:20 +00:00
( GtkAttachOptions ) ( 0 ) , 0 , 0 ) ;
gtk_button_set_alignment ( GTK_BUTTON ( check ) , 0.5 , 0 ) ;
2008-02-27 13:17:29 +00:00
/* Group */
2006-04-27 18:06:35 +00:00
label = gtk_label_new ( _ ( " Group: " ) ) ;
2006-10-19 16:26:29 +00:00
gtk_table_attach ( GTK_TABLE ( perm_table ) , label , 0 , 1 , 3 , 4 ,
2006-04-27 18:06:35 +00:00
( GtkAttachOptions ) ( GTK_EXPAND | GTK_FILL ) ,
2006-02-22 13:46:20 +00:00
( GtkAttachOptions ) ( 0 ) , 0 , 0 ) ;
gtk_label_set_use_markup ( GTK_LABEL ( label ) , TRUE ) ;
gtk_misc_set_alignment ( GTK_MISC ( label ) , 0.5 , 0 ) ;
check = gtk_check_button_new ( ) ;
2006-04-27 18:06:35 +00:00
gtk_widget_set_sensitive ( check , FALSE ) ;
2006-02-22 13:46:20 +00:00
gtk_button_set_focus_on_click ( GTK_BUTTON ( check ) , FALSE ) ;
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( check ) , mode & S_IRGRP ) ;
2006-10-19 16:26:29 +00:00
gtk_table_attach ( GTK_TABLE ( perm_table ) , check , 1 , 2 , 3 , 4 ,
2006-04-27 18:06:35 +00:00
( GtkAttachOptions ) ( GTK_EXPAND | GTK_FILL ) ,
2006-02-22 13:46:20 +00:00
( GtkAttachOptions ) ( 0 ) , 0 , 0 ) ;
gtk_button_set_alignment ( GTK_BUTTON ( check ) , 0.5 , 0 ) ;
check = gtk_check_button_new ( ) ;
2006-04-27 18:06:35 +00:00
gtk_widget_set_sensitive ( check , FALSE ) ;
2006-02-22 13:46:20 +00:00
gtk_button_set_focus_on_click ( GTK_BUTTON ( check ) , FALSE ) ;
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( check ) , mode & S_IWGRP ) ;
2006-10-19 16:26:29 +00:00
gtk_table_attach ( GTK_TABLE ( perm_table ) , check , 2 , 3 , 3 , 4 ,
2006-04-27 18:06:35 +00:00
( GtkAttachOptions ) ( GTK_EXPAND | GTK_FILL ) ,
2006-02-22 13:46:20 +00:00
( GtkAttachOptions ) ( 0 ) , 0 , 0 ) ;
gtk_button_set_alignment ( GTK_BUTTON ( check ) , 0.5 , 0 ) ;
check = gtk_check_button_new ( ) ;
2006-04-27 18:06:35 +00:00
gtk_widget_set_sensitive ( check , FALSE ) ;
2006-02-22 13:46:20 +00:00
gtk_button_set_focus_on_click ( GTK_BUTTON ( check ) , FALSE ) ;
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( check ) , mode & S_IXGRP ) ;
2006-10-19 16:26:29 +00:00
gtk_table_attach ( GTK_TABLE ( perm_table ) , check , 3 , 4 , 3 , 4 ,
2006-04-27 18:06:35 +00:00
( GtkAttachOptions ) ( GTK_EXPAND | GTK_FILL ) ,
2006-02-22 13:46:20 +00:00
( GtkAttachOptions ) ( 0 ) , 0 , 0 ) ;
gtk_button_set_alignment ( GTK_BUTTON ( check ) , 0.5 , 0 ) ;
2008-02-27 13:17:29 +00:00
/* Other */
2006-04-27 18:06:35 +00:00
label = gtk_label_new ( _ ( " Other: " ) ) ;
2006-10-19 16:26:29 +00:00
gtk_table_attach ( GTK_TABLE ( perm_table ) , label , 0 , 1 , 4 , 5 ,
2006-04-27 18:06:35 +00:00
( GtkAttachOptions ) ( GTK_EXPAND | GTK_FILL ) ,
2006-02-22 13:46:20 +00:00
( GtkAttachOptions ) ( 0 ) , 0 , 0 ) ;
gtk_label_set_use_markup ( GTK_LABEL ( label ) , TRUE ) ;
gtk_misc_set_alignment ( GTK_MISC ( label ) , 0.5 , 0 ) ;
check = gtk_check_button_new ( ) ;
2006-04-27 18:06:35 +00:00
gtk_widget_set_sensitive ( check , FALSE ) ;
2006-02-22 13:46:20 +00:00
gtk_button_set_focus_on_click ( GTK_BUTTON ( check ) , FALSE ) ;
2006-02-25 22:26:43 +00:00
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( check ) , mode & S_IROTH ) ;
2006-10-19 16:26:29 +00:00
gtk_table_attach ( GTK_TABLE ( perm_table ) , check , 1 , 2 , 4 , 5 ,
2006-04-27 18:06:35 +00:00
( GtkAttachOptions ) ( GTK_EXPAND | GTK_FILL ) ,
2006-02-22 13:46:20 +00:00
( GtkAttachOptions ) ( 0 ) , 0 , 0 ) ;
gtk_button_set_alignment ( GTK_BUTTON ( check ) , 0.5 , 0 ) ;
check = gtk_check_button_new ( ) ;
2006-04-27 18:06:35 +00:00
gtk_widget_set_sensitive ( check , FALSE ) ;
2006-02-22 13:46:20 +00:00
gtk_button_set_focus_on_click ( GTK_BUTTON ( check ) , FALSE ) ;
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( check ) , mode & S_IWOTH ) ;
2006-10-19 16:26:29 +00:00
gtk_table_attach ( GTK_TABLE ( perm_table ) , check , 2 , 3 , 4 , 5 ,
2006-04-27 18:06:35 +00:00
( GtkAttachOptions ) ( GTK_EXPAND | GTK_FILL ) ,
2006-02-22 13:46:20 +00:00
( GtkAttachOptions ) ( 0 ) , 0 , 0 ) ;
gtk_button_set_alignment ( GTK_BUTTON ( check ) , 0.5 , 0 ) ;
check = gtk_check_button_new ( ) ;
2006-04-27 18:06:35 +00:00
gtk_widget_set_sensitive ( check , FALSE ) ;
2006-02-22 13:46:20 +00:00
gtk_button_set_focus_on_click ( GTK_BUTTON ( check ) , FALSE ) ;
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( check ) , mode & S_IXOTH ) ;
2006-10-19 16:26:29 +00:00
gtk_table_attach ( GTK_TABLE ( perm_table ) , check , 3 , 4 , 4 , 5 ,
2006-04-27 18:06:35 +00:00
( GtkAttachOptions ) ( GTK_EXPAND | GTK_FILL ) ,
2006-02-22 13:46:20 +00:00
( GtkAttachOptions ) ( 0 ) , 0 , 0 ) ;
gtk_button_set_alignment ( GTK_BUTTON ( check ) , 0.5 , 0 ) ;
2006-10-19 16:26:29 +00:00
gtk_container_add ( GTK_CONTAINER ( vbox ) , perm_table ) ;
2006-02-22 13:46:20 +00:00
g_free ( base_name ) ;
g_free ( time_changed ) ;
g_free ( time_modified ) ;
g_free ( time_accessed ) ;
gtk_widget_show_all ( dialog ) ;
}
2006-04-27 18:06:35 +00:00
2007-07-04 17:08:53 +00:00
static gboolean show_question ( GtkWidget * parent , const gchar * yes_btn , const gchar * no_btn ,
2008-02-17 18:00:42 +00:00
const gchar * question_text , const gchar * extra_text )
2006-04-27 18:06:35 +00:00
{
gboolean ret = FALSE ;
2006-07-26 17:02:16 +00:00
# ifdef G_OS_WIN32
2006-08-18 17:22:57 +00:00
gchar * string = ( extra_text = = NULL ) ? g_strdup ( question_text ) :
g_strconcat ( question_text , " \n \n " , extra_text , NULL ) ;
2007-07-04 17:08:53 +00:00
ret = win32_message_dialog ( parent , GTK_MESSAGE_QUESTION , string ) ;
2006-08-18 17:22:57 +00:00
g_free ( string ) ;
2006-04-27 18:06:35 +00:00
# else
2006-08-18 17:22:57 +00:00
GtkWidget * dialog ;
2009-07-19 20:19:09 +00:00
if ( parent = = NULL & & main_status . main_window_realized )
2008-05-22 14:41:28 +00:00
parent = main_widgets . window ;
2007-07-04 17:08:53 +00:00
dialog = gtk_message_dialog_new ( GTK_WINDOW ( parent ) ,
2006-08-18 17:22:57 +00:00
GTK_DIALOG_DESTROY_WITH_PARENT , GTK_MESSAGE_QUESTION ,
GTK_BUTTONS_NONE , " %s " , question_text ) ;
2007-05-15 15:16:16 +00:00
gtk_widget_set_name ( dialog , " GeanyDialog " ) ;
2009-07-19 20:19:09 +00:00
gtk_window_set_title ( GTK_WINDOW ( dialog ) , _ ( " Question " ) ) ;
if ( parent = = NULL )
{
GdkPixbuf * pb = ui_new_pixbuf_from_inline ( GEANY_IMAGE_LOGO ) ;
gtk_window_set_icon ( GTK_WINDOW ( dialog ) , pb ) ;
g_object_unref ( pb ) ;
}
2008-02-27 13:17:29 +00:00
/* question_text will be in bold if optional extra_text used */
2006-08-18 17:22:57 +00:00
if ( extra_text ! = NULL )
gtk_message_dialog_format_secondary_text ( GTK_MESSAGE_DIALOG ( dialog ) ,
" %s " , extra_text ) ;
2008-02-27 13:17:29 +00:00
/* For a cancel button, use cancel response so user can press escape to cancel */
2006-08-18 17:22:57 +00:00
gtk_dialog_add_button ( GTK_DIALOG ( dialog ) , no_btn ,
2006-12-07 16:12:01 +00:00
utils_str_equal ( no_btn , GTK_STOCK_CANCEL ) ? GTK_RESPONSE_CANCEL : GTK_RESPONSE_NO ) ;
2006-08-18 17:22:57 +00:00
gtk_dialog_add_button ( GTK_DIALOG ( dialog ) , yes_btn , GTK_RESPONSE_YES ) ;
2006-05-30 15:27:38 +00:00
if ( gtk_dialog_run ( GTK_DIALOG ( dialog ) ) = = GTK_RESPONSE_YES )
ret = TRUE ;
2006-04-27 18:06:35 +00:00
gtk_widget_destroy ( dialog ) ;
# endif
2006-08-18 17:22:57 +00:00
return ret ;
}
2008-02-17 18:00:42 +00:00
/**
* Show a question message box with @ c text and Yes / No buttons .
* On Unix - like systems a GTK message dialog box is shown , on Win32 systems a native Windows
* message dialog box is shown .
*
* @ param text Printf ( ) - style format string .
* @ param . . . Arguments for the @ c text format string .
*
* @ return @ a TRUE if the user answered with Yes , otherwise @ a FALSE .
* */
2006-08-18 17:22:57 +00:00
gboolean dialogs_show_question ( const gchar * text , . . . )
{
gboolean ret = FALSE ;
2008-06-20 14:17:15 +00:00
gchar string [ 512 ] ;
2006-08-18 17:22:57 +00:00
va_list args ;
2009-07-19 20:19:09 +00:00
GtkWidget * parent = ( main_status . main_window_realized ) ? main_widgets . window : NULL ;
2006-08-18 17:22:57 +00:00
va_start ( args , text ) ;
g_vsnprintf ( string , 511 , text , args ) ;
va_end ( args ) ;
2009-07-19 20:19:09 +00:00
ret = show_question ( parent , GTK_STOCK_YES , GTK_STOCK_NO , string , NULL ) ;
2006-08-18 17:22:57 +00:00
return ret ;
}
2007-07-04 17:08:53 +00:00
/* extra_text can be NULL; otherwise it is displayed below main_text.
2009-07-20 16:12:23 +00:00
* if parent is NULL , main_widgets . window will be used
* yes_btn , no_btn can be NULL . */
2007-07-04 17:08:53 +00:00
gboolean dialogs_show_question_full ( GtkWidget * parent , const gchar * yes_btn , const gchar * no_btn ,
2006-08-18 17:22:57 +00:00
const gchar * extra_text , const gchar * main_text , . . . )
{
gboolean ret = FALSE ;
2008-06-20 14:17:15 +00:00
gchar string [ 512 ] ;
2006-08-18 17:22:57 +00:00
va_list args ;
2006-05-14 16:07:30 +00:00
2009-07-20 16:12:23 +00:00
if ( ! yes_btn )
yes_btn = GTK_STOCK_YES ;
if ( ! no_btn )
no_btn = GTK_STOCK_NO ;
2006-08-18 17:22:57 +00:00
va_start ( args , main_text ) ;
g_vsnprintf ( string , 511 , main_text , args ) ;
va_end ( args ) ;
2007-07-04 17:08:53 +00:00
ret = show_question ( parent , yes_btn , no_btn , string , extra_text ) ;
2006-04-27 18:06:35 +00:00
return ret ;
}
2006-06-05 15:12:40 +00:00