2005-11-22 12:26:26 +00:00
/*
* dialogs . 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-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>
2006-02-22 13:46:20 +00:00
# ifdef HAVE_SYS_STAT_H
# include <sys / stat.h>
# endif
# ifdef TIME_WITH_SYS_TIME
# include <sys / time.h>
# include <time.h>
# endif
# ifdef HAVE_SYS_TYPES_H
# include <sys / types.h>
# endif
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"
# 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"
2005-11-22 12:26:26 +00:00
2006-02-10 20:57:09 +00:00
2006-10-24 23:50:50 +00:00
# if ! GEANY_USE_WIN32_DIALOG
2006-09-09 14:36:15 +00:00
static GtkWidget * add_file_open_extra_widget ( ) ;
2007-07-17 14:52:57 +00:00
# endif
# if ! GEANY_USE_WIN32_DIALOG
static void
on_file_open_dialog_response ( GtkDialog * dialog ,
gint response ,
gpointer user_data )
{
gtk_widget_hide ( app - > open_filesel ) ;
if ( response = = GTK_RESPONSE_ACCEPT | | response = = GTK_RESPONSE_APPLY )
{
GSList * filelist ;
gint filetype_idx = gtk_combo_box_get_active ( GTK_COMBO_BOX (
lookup_widget ( GTK_WIDGET ( dialog ) , " filetype_combo " ) ) ) ;
gint encoding_idx = gtk_combo_box_get_active ( GTK_COMBO_BOX (
lookup_widget ( GTK_WIDGET ( dialog ) , " encoding_combo " ) ) ) ;
filetype * ft = NULL ;
gchar * charset = NULL ;
gboolean ro = ( response = = GTK_RESPONSE_APPLY ) ; // View clicked
if ( filetype_idx > = 0 & & filetype_idx < GEANY_FILETYPES_ALL ) ft = filetypes [ filetype_idx ] ;
if ( encoding_idx > = 0 & & encoding_idx < GEANY_ENCODINGS_MAX )
charset = encodings [ encoding_idx ] . charset ;
filelist = gtk_file_chooser_get_filenames ( GTK_FILE_CHOOSER ( app - > open_filesel ) ) ;
if ( filelist ! = NULL )
{
document_open_files ( filelist , ro , ft , charset ) ;
g_slist_foreach ( filelist , ( GFunc ) g_free , NULL ) ; // free filenames
}
g_slist_free ( filelist ) ;
}
}
# endif
# if ! GEANY_USE_WIN32_DIALOG
// callback for the text entry for typing in filename
static void
on_file_open_entry_activate ( GtkEntry * entry ,
gpointer user_data )
{
gchar * locale_filename = utils_get_locale_from_utf8 ( gtk_entry_get_text ( entry ) ) ;
if ( g_file_test ( locale_filename , G_FILE_TEST_IS_DIR ) )
{
gtk_file_chooser_set_current_folder ( GTK_FILE_CHOOSER ( app - > open_filesel ) , locale_filename ) ;
}
else if ( g_file_test ( locale_filename , G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_SYMLINK ) )
{
gtk_file_chooser_set_filename ( GTK_FILE_CHOOSER ( app - > open_filesel ) , locale_filename ) ;
on_file_open_dialog_response ( GTK_DIALOG ( app - > open_filesel ) , GTK_RESPONSE_ACCEPT , NULL ) ;
}
g_free ( locale_filename ) ;
}
# endif
# if ! GEANY_USE_WIN32_DIALOG
static void
on_file_open_selection_changed ( GtkFileChooser * filechooser ,
gpointer user_data )
{
gchar * filename = gtk_file_chooser_get_filename ( filechooser ) ;
gboolean is_on = gtk_file_chooser_get_show_hidden ( filechooser ) ;
if ( filename )
{
// try to get the UTF-8 equivalent for the filename, fallback to filename if error
gchar * utf8_filename = utils_get_utf8_from_locale ( filename ) ;
gtk_entry_set_text ( GTK_ENTRY ( lookup_widget (
GTK_WIDGET ( filechooser ) , " file_entry " ) ) , utf8_filename ) ;
g_free ( utf8_filename ) ;
g_free ( filename ) ;
}
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON (
lookup_widget ( GTK_WIDGET ( filechooser ) , " check_hidden " ) ) , is_on ) ;
}
# endif
# if ! GEANY_USE_WIN32_DIALOG
static void
on_file_open_check_hidden_toggled ( GtkToggleButton * togglebutton ,
gpointer user_data )
{
gboolean is_on = gtk_toggle_button_get_active ( togglebutton ) ;
gtk_file_chooser_set_show_hidden ( GTK_FILE_CHOOSER ( app - > open_filesel ) , is_on ) ;
}
2007-07-06 12:37:07 +00:00
# endif
2006-09-09 14:36:15 +00:00
2006-10-19 16:26:29 +00:00
2005-11-22 12:26:26 +00:00
/* This shows the file selection dialog to open a file. */
void dialogs_show_open_file ( )
{
2006-10-24 23:50:50 +00:00
# if GEANY_USE_WIN32_DIALOG
2006-10-09 16:08:53 +00:00
win32_show_file_dialog ( TRUE ) ;
2005-11-22 12:26:26 +00:00
# else /* X11, not win32: use GTK_FILE_CHOOSER */
2006-10-09 16:08:53 +00:00
gchar * initdir ;
2005-11-22 12:26:26 +00:00
2006-10-09 16:08:53 +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 . */
if ( app - > open_filesel = = NULL )
{
2006-10-23 00:05:42 +00:00
GtkWidget * filetype_combo , * encoding_combo ;
2006-10-09 16:08:53 +00:00
GtkWidget * viewbtn ;
GtkTooltips * tooltips = GTK_TOOLTIPS ( lookup_widget ( app - > window , " tooltips " ) ) ;
gint i ;
2006-10-23 00:05:42 +00:00
gchar * encoding_string ;
2006-10-09 16:08:53 +00:00
app - > open_filesel = gtk_file_chooser_dialog_new ( _ ( " Open File " ) , GTK_WINDOW ( app - > window ) ,
GTK_FILE_CHOOSER_ACTION_OPEN , NULL , NULL ) ;
2007-07-16 14:42:36 +00:00
gtk_widget_set_name ( app - > open_filesel , " GeanyDialog " ) ;
2006-10-09 16:08:53 +00:00
viewbtn = gtk_button_new_with_mnemonic ( _ ( " _View " ) ) ;
gtk_tooltips_set_tip ( tooltips , viewbtn ,
_ ( " Opens the file in read-only mode. If you choose more than one file to open, all files will be opened read-only. " ) , NULL ) ;
gtk_widget_show ( viewbtn ) ;
gtk_dialog_add_action_widget ( GTK_DIALOG ( app - > open_filesel ) ,
viewbtn , GTK_RESPONSE_APPLY ) ;
2007-07-16 14:42:36 +00:00
2006-10-09 16:08:53 +00:00
gtk_dialog_add_buttons ( GTK_DIALOG ( app - > open_filesel ) ,
GTK_STOCK_CANCEL , GTK_RESPONSE_CANCEL ,
GTK_STOCK_OPEN , GTK_RESPONSE_ACCEPT , NULL ) ;
gtk_dialog_set_default_response ( GTK_DIALOG ( app - > open_filesel ) ,
GTK_RESPONSE_ACCEPT ) ;
2006-11-07 23:32:30 +00:00
gtk_widget_set_size_request ( app - > open_filesel , - 1 , 460 ) ;
2006-10-09 16:08:53 +00:00
gtk_window_set_modal ( GTK_WINDOW ( app - > open_filesel ) , TRUE ) ;
gtk_window_set_destroy_with_parent ( GTK_WINDOW ( app - > open_filesel ) , TRUE ) ;
gtk_window_set_skip_taskbar_hint ( GTK_WINDOW ( app - > open_filesel ) , TRUE ) ;
gtk_window_set_type_hint ( GTK_WINDOW ( app - > open_filesel ) , GDK_WINDOW_TYPE_HINT_DIALOG ) ;
gtk_window_set_transient_for ( GTK_WINDOW ( app - > open_filesel ) , GTK_WINDOW ( app - > window ) ) ;
gtk_file_chooser_set_select_multiple ( GTK_FILE_CHOOSER ( app - > open_filesel ) , TRUE ) ;
// add checkboxes and filename entry
gtk_file_chooser_set_extra_widget ( GTK_FILE_CHOOSER ( app - > open_filesel ) ,
add_file_open_extra_widget ( ) ) ;
2006-10-23 00:05:42 +00:00
filetype_combo = lookup_widget ( app - > open_filesel , " filetype_combo " ) ;
2006-10-09 16:08:53 +00:00
// add FileFilters(start with "All Files")
gtk_file_chooser_add_filter ( GTK_FILE_CHOOSER ( app - > open_filesel ) ,
filetypes_create_file_filter ( filetypes [ GEANY_FILETYPES_ALL ] ) ) ;
2007-03-01 22:38:31 +00:00
// now create meta filter "All Source"
gtk_file_chooser_add_filter ( GTK_FILE_CHOOSER ( app - > open_filesel ) ,
filetypes_create_file_filter_all_source ( ) ) ;
2006-10-09 16:08:53 +00:00
for ( i = 0 ; i < GEANY_MAX_FILE_TYPES - 1 ; i + + )
2005-11-22 12:26:26 +00:00
{
2006-10-23 00:05:42 +00:00
gtk_combo_box_append_text ( GTK_COMBO_BOX ( filetype_combo ) , filetypes [ i ] - > title ) ;
gtk_file_chooser_add_filter ( GTK_FILE_CHOOSER ( app - > open_filesel ) ,
2006-10-09 16:08:53 +00:00
filetypes_create_file_filter ( filetypes [ i ] ) ) ;
}
2006-10-23 00:05:42 +00:00
gtk_combo_box_append_text ( GTK_COMBO_BOX ( filetype_combo ) , _ ( " Detect by file extension " ) ) ;
gtk_combo_box_set_active ( GTK_COMBO_BOX ( filetype_combo ) , GEANY_MAX_FILE_TYPES - 1 ) ;
// fill encoding combo box
encoding_combo = lookup_widget ( app - > open_filesel , " encoding_combo " ) ;
for ( i = 0 ; i < GEANY_ENCODINGS_MAX ; i + + )
{
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 " ) ) ;
2006-10-23 20:32:37 +00:00
gtk_combo_box_set_active ( GTK_COMBO_BOX ( encoding_combo ) , GEANY_ENCODINGS_MAX ) ;
2006-10-09 16:08:53 +00:00
g_signal_connect ( ( gpointer ) app - > open_filesel , " selection-changed " ,
G_CALLBACK ( on_file_open_selection_changed ) , NULL ) ;
g_signal_connect ( ( gpointer ) app - > open_filesel , " delete_event " ,
2007-01-19 23:17:40 +00:00
G_CALLBACK ( gtk_widget_hide_on_delete ) , NULL ) ;
2006-10-09 16:08:53 +00:00
g_signal_connect ( ( gpointer ) app - > open_filesel , " response " ,
G_CALLBACK ( on_file_open_dialog_response ) , NULL ) ;
}
2006-01-26 21:32:46 +00:00
2006-10-09 16:08:53 +00:00
// set dialog directory to the current file's directory, if present
initdir = utils_get_current_file_dir ( ) ;
if ( initdir ! = NULL )
{
gchar * locale_filename ;
2006-05-14 16:07:30 +00:00
2006-10-09 16:08:53 +00:00
locale_filename = utils_get_locale_from_utf8 ( initdir ) ;
2006-05-14 16:07:30 +00:00
2006-10-09 16:08:53 +00:00
if ( g_path_is_absolute ( locale_filename ) )
gtk_file_chooser_set_current_folder (
GTK_FILE_CHOOSER ( app - > open_filesel ) , locale_filename ) ;
2006-04-27 18:06:35 +00:00
2006-10-09 16:08:53 +00:00
g_free ( initdir ) ;
g_free ( locale_filename ) ;
}
2007-05-23 13:44:25 +00:00
// use 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?
else if ( app - > default_open_path ! = NULL & & * app - > default_open_path ! = ' \0 ' )
{
if ( g_path_is_absolute ( app - > default_open_path ) )
gtk_file_chooser_set_current_folder (
GTK_FILE_CHOOSER ( app - > open_filesel ) , app - > default_open_path ) ;
}
2006-01-26 21:32:46 +00:00
2006-10-09 16:08:53 +00:00
gtk_file_chooser_unselect_all ( GTK_FILE_CHOOSER ( app - > open_filesel ) ) ;
gtk_widget_show ( app - > open_filesel ) ;
2005-11-22 12:26:26 +00:00
# endif
}
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 ( )
{
2006-10-23 00:05:42 +00:00
GtkWidget * vbox , * table , * file_entry , * check_hidden ;
GtkWidget * filetype_ebox , * filetype_label , * filetype_combo ;
GtkWidget * encoding_ebox , * encoding_label , * encoding_combo ;
2006-09-09 14:36:15 +00:00
GtkTooltips * tooltips = GTK_TOOLTIPS ( lookup_widget ( app - > window , " tooltips " ) ) ;
vbox = gtk_vbox_new ( FALSE , 6 ) ;
2006-10-23 00:05:42 +00:00
table = gtk_table_new ( 2 , 4 , FALSE ) ;
// 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 " ) ) ;
gtk_button_set_focus_on_click ( GTK_BUTTON ( check_hidden ) , FALSE ) ;
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 ) ;
// spacing
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 ) ;
// the ebox is for the tooltip, because gtk_combo_box can't show tooltips
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 ) ;
gtk_tooltips_set_tip ( tooltips , 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. " ) , NULL ) ;
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 ) ;
// line 2 with filename entry and filetype combo
2006-09-09 14:36:15 +00:00
file_entry = gtk_entry_new ( ) ;
gtk_widget_show ( file_entry ) ;
//gtk_editable_set_editable(GTK_EDITABLE(file_entry), FALSE);
gtk_entry_set_activates_default ( GTK_ENTRY ( file_entry ) , TRUE ) ;
2006-10-23 00:05:42 +00:00
gtk_table_attach ( GTK_TABLE ( table ) , file_entry , 0 , 1 , 1 , 2 ,
( GtkAttachOptions ) ( GTK_FILL | GTK_EXPAND ) ,
( GtkAttachOptions ) ( 0 ) , 0 , 5 ) ;
// spacing
gtk_table_attach ( GTK_TABLE ( table ) , gtk_label_new ( " " ) , 1 , 2 , 1 , 2 ,
( GtkAttachOptions ) ( GTK_FILL ) ,
( GtkAttachOptions ) ( 0 ) , 5 , 5 ) ;
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 ) ;
// the ebox is for the tooltip, because gtk_combo_box can't show tooltips
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 ) ;
2006-10-23 00:05:42 +00:00
gtk_tooltips_set_tip ( tooltips , filetype_ebox ,
2006-09-09 14:36:15 +00:00
_ ( " 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. " ) , NULL ) ;
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
g_signal_connect ( ( gpointer ) file_entry , " activate " ,
G_CALLBACK ( on_file_open_entry_activate ) , NULL ) ;
g_signal_connect ( ( gpointer ) check_hidden , " toggled " ,
G_CALLBACK ( on_file_open_check_hidden_toggled ) , NULL ) ;
g_object_set_data_full ( G_OBJECT ( app - > open_filesel ) , " file_entry " ,
gtk_widget_ref ( file_entry ) , ( GDestroyNotify ) gtk_widget_unref ) ;
g_object_set_data_full ( G_OBJECT ( app - > open_filesel ) , " check_hidden " ,
gtk_widget_ref ( check_hidden ) , ( GDestroyNotify ) gtk_widget_unref ) ;
g_object_set_data_full ( G_OBJECT ( app - > open_filesel ) , " filetype_combo " ,
gtk_widget_ref ( filetype_combo ) , ( GDestroyNotify ) gtk_widget_unref ) ;
2006-10-23 00:05:42 +00:00
g_object_set_data_full ( G_OBJECT ( app - > open_filesel ) , " encoding_combo " ,
gtk_widget_ref ( encoding_combo ) , ( GDestroyNotify ) gtk_widget_unref ) ;
2006-09-09 14:36:15 +00:00
return vbox ;
}
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
static void
on_file_save_dialog_response ( GtkDialog * dialog ,
gint response ,
gpointer user_data )
{
gboolean rename_file = FALSE ;
switch ( response )
{
case GTK_RESPONSE_APPLY :
rename_file = TRUE ;
// fall through
case GTK_RESPONSE_ACCEPT :
{
gint idx = document_get_cur_idx ( ) ;
gchar * new_filename = gtk_file_chooser_get_filename ( GTK_FILE_CHOOSER ( app - > save_filesel ) ) ;
gchar * utf8_filename ;
gboolean open_new_tab = gtk_toggle_button_get_active (
GTK_TOGGLE_BUTTON ( lookup_widget ( app - > save_filesel , " check_open_new_tab " ) ) ) ;
# ifdef G_OS_WIN32
utf8_filename = g_strdup ( new_filename ) ;
# else
utf8_filename = utils_get_utf8_from_locale ( new_filename ) ;
# endif
// check if file exists and ask whether to overwrite or not
if ( g_file_test ( new_filename , G_FILE_TEST_EXISTS ) )
{
if ( dialogs_show_question (
_ ( " The file '%s' already exists. Do you want to overwrite it? " ) ,
utf8_filename ) = = FALSE )
return ;
}
if ( open_new_tab )
{ // "open" the saved file in a new tab
idx = document_clone ( idx , utf8_filename ) ;
g_free ( utf8_filename ) ;
}
else
{
if ( doc_list [ idx ] . file_name ! = NULL )
{
if ( rename_file )
{ // delete the previous file name
# ifdef G_OS_WIN32
g_unlink ( doc_list [ idx ] . file_name ) ;
# else
gchar * old_filename = utils_get_locale_from_utf8 ( doc_list [ idx ] . file_name ) ;
g_unlink ( old_filename ) ;
g_free ( old_filename ) ;
# endif
}
// create a new tm_source_file object otherwise tagmanager won't work correctly
tm_workspace_remove_object ( doc_list [ idx ] . tm_file , TRUE ) ;
doc_list [ idx ] . tm_file = NULL ;
g_free ( doc_list [ idx ] . file_name ) ;
}
doc_list [ idx ] . file_name = utf8_filename ;
}
utils_replace_filename ( idx ) ;
document_save_file ( idx , TRUE ) ;
if ( ! open_new_tab )
build_menu_update ( idx ) ;
// finally add current file to recent files menu
ui_add_recent_file ( doc_list [ idx ] . file_name ) ;
g_free ( new_filename ) ;
}
}
gtk_widget_hide ( app - > save_filesel ) ;
}
# endif
2006-11-07 11:24:22 +00:00
/* This shows the file selection dialog to save a file, returning TRUE if
* the file was saved . */
gboolean dialogs_show_save_as ( )
2005-11-22 12:26:26 +00:00
{
2007-07-06 12:37:07 +00:00
# if GEANY_USE_WIN32_DIALOG
2006-11-07 11:24:22 +00:00
return win32_show_file_dialog ( FALSE ) ;
2005-11-22 12:26:26 +00:00
# else
2006-11-07 11:24:22 +00:00
gint idx = document_get_cur_idx ( ) , resp ;
2005-11-22 12:26:26 +00:00
if ( app - > save_filesel = = NULL )
{
2007-07-16 14:42:36 +00:00
GtkWidget * vbox , * check_open_new_tab , * rename_btn ;
GtkTooltips * tooltips = GTK_TOOLTIPS ( lookup_widget ( app - > window , " tooltips " ) ) ;
2007-06-12 16:45:24 +00:00
2006-06-05 16:04:28 +00:00
app - > save_filesel = gtk_file_chooser_dialog_new ( _ ( " Save File " ) , GTK_WINDOW ( app - > window ) ,
2007-07-16 14:42:36 +00:00
GTK_FILE_CHOOSER_ACTION_SAVE , NULL , NULL ) ;
2006-02-14 22:07:55 +00:00
gtk_window_set_modal ( GTK_WINDOW ( app - > save_filesel ) , TRUE ) ;
gtk_window_set_destroy_with_parent ( GTK_WINDOW ( app - > save_filesel ) , TRUE ) ;
gtk_window_set_skip_taskbar_hint ( GTK_WINDOW ( app - > save_filesel ) , TRUE ) ;
gtk_window_set_type_hint ( GTK_WINDOW ( app - > save_filesel ) , GDK_WINDOW_TYPE_HINT_DIALOG ) ;
2007-05-15 15:16:16 +00:00
gtk_widget_set_name ( app - > save_filesel , " GeanyDialog " ) ;
2006-02-14 22:07:55 +00:00
2007-07-16 14:42:36 +00:00
rename_btn = gtk_button_new_with_mnemonic ( _ ( " R_ename " ) ) ;
gtk_tooltips_set_tip ( tooltips , rename_btn ,
_ ( " Save the file and rename it. " ) , NULL ) ;
gtk_widget_show ( rename_btn ) ;
gtk_dialog_add_action_widget ( GTK_DIALOG ( app - > save_filesel ) ,
rename_btn , GTK_RESPONSE_APPLY ) ;
gtk_dialog_add_buttons ( GTK_DIALOG ( app - > save_filesel ) ,
GTK_STOCK_CANCEL , GTK_RESPONSE_CANCEL ,
GTK_STOCK_SAVE , GTK_RESPONSE_ACCEPT , NULL ) ;
gtk_dialog_set_default_response ( GTK_DIALOG ( app - > save_filesel ) , GTK_RESPONSE_ACCEPT ) ;
2007-06-12 16:45:24 +00:00
vbox = gtk_vbox_new ( FALSE , 0 ) ;
2007-07-16 14:42:36 +00:00
check_open_new_tab = gtk_check_button_new_with_mnemonic ( _ ( " _Open file in a new tab " ) ) ;
gtk_tooltips_set_tip ( tooltips , check_open_new_tab ,
_ ( " Keep the current unsaved document open "
" and open the newly saved file in a new tab. " ) , NULL ) ;
2007-06-12 16:45:24 +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 ( app - > save_filesel ) , vbox ) ;
g_signal_connect ( check_open_new_tab , " toggled " ,
2007-07-16 14:42:36 +00:00
G_CALLBACK ( on_save_as_new_tab_toggled ) , rename_btn ) ;
2007-06-12 16:45:24 +00:00
g_object_set_data_full ( G_OBJECT ( app - > save_filesel ) , " check_open_new_tab " ,
gtk_widget_ref ( check_open_new_tab ) , ( GDestroyNotify ) gtk_widget_unref ) ;
2007-01-19 23:17:40 +00:00
g_signal_connect ( ( gpointer ) app - > save_filesel , " delete_event " ,
G_CALLBACK ( gtk_widget_hide_on_delete ) , NULL ) ;
g_signal_connect ( ( gpointer ) app - > save_filesel , " response " ,
G_CALLBACK ( on_file_save_dialog_response ) , NULL ) ;
2006-02-14 22:07:55 +00:00
2005-11-22 12:26:26 +00:00
gtk_window_set_transient_for ( GTK_WINDOW ( app - > save_filesel ) , GTK_WINDOW ( app - > window ) ) ;
}
2006-04-27 18:06:35 +00:00
// If the current document has a filename we use that as the default.
if ( doc_list [ idx ] . file_name ! = NULL )
{
2007-07-06 12:37:07 +00:00
# ifdef G_OS_WIN32
gchar * locale_filename = doc_list [ idx ] . file_name ;
# else
2006-08-13 09:07:10 +00:00
gchar * locale_filename = utils_get_locale_from_utf8 ( doc_list [ idx ] . file_name ) ;
2007-07-06 12:37:07 +00:00
# endif
2006-06-02 12:00:33 +00:00
if ( g_path_is_absolute ( locale_filename ) )
gtk_file_chooser_set_filename ( GTK_FILE_CHOOSER ( app - > save_filesel ) , locale_filename ) ;
else
gtk_file_chooser_set_current_name ( GTK_FILE_CHOOSER ( app - > save_filesel ) , locale_filename ) ;
2007-07-06 12:37:07 +00:00
# ifndef G_OS_WIN32
2006-04-27 18:06:35 +00:00
g_free ( locale_filename ) ;
2007-07-06 12:37:07 +00:00
# endif
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
2006-04-27 18:06:35 +00:00
if ( doc_list [ idx ] . file_type ! = NULL & & doc_list [ idx ] . file_type - > id ! = GEANY_FILETYPES_ALL & &
doc_list [ idx ] . file_type - > extension ! = NULL )
fname = g_strconcat ( GEANY_STRING_UNTITLED , " . " ,
doc_list [ idx ] . 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 ) ;
2005-11-22 12:26:26 +00:00
gtk_file_chooser_unselect_all ( GTK_FILE_CHOOSER ( app - > save_filesel ) ) ;
2006-04-27 18:06:35 +00:00
gtk_file_chooser_set_current_name ( GTK_FILE_CHOOSER ( app - > save_filesel ) , fname ) ;
2007-05-23 13:44:25 +00:00
// use default startup directory(if set) if no files are open
if ( app - > default_open_path ! = NULL & & * app - > default_open_path ! = ' \0 ' )
{
if ( g_path_is_absolute ( app - > default_open_path ) )
2007-07-06 12:37:07 +00:00
{
# ifdef G_OS_WIN32
2007-05-23 13:44:25 +00:00
gtk_file_chooser_set_current_folder (
GTK_FILE_CHOOSER ( app - > save_filesel ) , app - > default_open_path ) ;
2007-07-06 12:37:07 +00:00
# else
gchar * def_path = utils_get_locale_from_utf8 ( app - > default_open_path ) ;
gtk_file_chooser_set_current_folder ( GTK_FILE_CHOOSER ( app - > save_filesel ) , def_path ) ;
g_free ( def_path ) ;
# endif
}
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
}
2006-07-24 21:18:06 +00:00
// Run the dialog synchronously, pausing this function call
2006-11-07 11:24:22 +00:00
resp = gtk_dialog_run ( GTK_DIALOG ( app - > save_filesel ) ) ;
return ( resp = = GTK_RESPONSE_ACCEPT ) ;
2005-11-22 12:26:26 +00:00
# endif
}
2006-10-25 14:38:48 +00:00
void dialogs_show_msgbox ( gint 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
gchar * string = g_malloc ( 512 ) ;
va_list args ;
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
2007-07-04 17:08:53 +00:00
win32_message_dialog ( NULL , type , string ) ;
2005-11-22 12:26:26 +00:00
# else
2006-08-18 17:22:57 +00:00
dialog = gtk_message_dialog_new ( GTK_WINDOW ( app - > window ) , GTK_DIALOG_DESTROY_WITH_PARENT ,
2006-10-25 14:38:48 +00:00
type , GTK_BUTTONS_OK , " %s " , string ) ;
2007-05-15 15:16:16 +00:00
gtk_widget_set_name ( dialog , " GeanyDialog " ) ;
2006-02-22 13:46:20 +00:00
gtk_dialog_run ( GTK_DIALOG ( dialog ) ) ;
2005-11-22 12:26:26 +00:00
gtk_widget_destroy ( dialog ) ;
# endif
g_free ( string ) ;
}
gboolean dialogs_show_unsaved_file ( gint idx )
{
2006-07-26 17:02:16 +00:00
# ifndef G_OS_WIN32
2006-12-08 16:21:52 +00:00
GtkWidget * dialog , * button ;
2005-11-22 12:26:26 +00:00
# endif
2007-07-08 14:55:37 +00:00
gchar * msg , * msg2 , * short_fn = NULL ;
2005-11-22 12:26:26 +00:00
gint ret ;
2006-12-18 12:34:29 +00:00
// display the file tab to remind the user of the document
gtk_notebook_set_current_page ( GTK_NOTEBOOK ( app - > notebook ) ,
2007-02-23 15:36:21 +00:00
document_get_notebook_page ( idx ) ) ;
2006-12-18 12:34:29 +00:00
2005-11-22 12:26:26 +00:00
if ( doc_list [ idx ] . file_name ! = NULL )
{
2006-10-20 16:40:12 +00:00
short_fn = g_path_get_basename ( doc_list [ idx ] . file_name ) ;
2005-11-22 12:26:26 +00:00
}
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
dialog = gtk_message_dialog_new ( GTK_WINDOW ( app - > window ) , GTK_DIALOG_DESTROY_WITH_PARENT ,
2006-07-25 12:46:08 +00:00
GTK_MESSAGE_QUESTION , GTK_BUTTONS_NONE , " %s " , msg ) ;
2007-07-08 14:55:37 +00:00
gtk_message_dialog_format_secondary_text ( GTK_MESSAGE_DIALOG ( dialog ) , " %s " , msg2 ) ;
2005-11-22 12:26:26 +00:00
gtk_dialog_add_button ( GTK_DIALOG ( dialog ) , GTK_STOCK_CANCEL , GTK_RESPONSE_CANCEL ) ;
2006-12-08 16:21:52 +00:00
button = ui_button_new_with_image ( GTK_STOCK_CLEAR , _ ( " _Don't save " ) ) ;
2005-11-22 12:26:26 +00:00
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 ) ;
# endif
g_free ( msg ) ;
switch ( ret )
{
case GTK_RESPONSE_YES :
{
if ( doc_list [ idx ] . 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
2006-09-05 18:33:48 +00:00
// document_save_file() returns the status if the file could be saved
ret = document_save_file ( idx , 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 (
GTK_FONT_SELECTION_DIALOG ( app - > open_fontsel ) ) ;
ui_set_editor_font ( fontname ) ;
g_free ( fontname ) ;
}
static void
on_font_ok_button_clicked ( GtkButton * button ,
gpointer user_data )
{
// We do the same thing as apply, but we close the dialog after.
on_font_apply_button_clicked ( button , NULL ) ;
gtk_widget_hide ( app - > open_fontsel ) ;
}
static void
on_font_cancel_button_clicked ( GtkButton * button ,
gpointer user_data )
{
gtk_widget_hide ( app - > open_fontsel ) ;
}
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
if ( app - > open_fontsel = = NULL )
{
2006-02-22 13:46:20 +00:00
app - > open_fontsel = gtk_font_selection_dialog_new ( _ ( " Choose font " ) ) ; ;
gtk_container_set_border_width ( GTK_CONTAINER ( app - > open_fontsel ) , 4 ) ;
gtk_window_set_modal ( GTK_WINDOW ( app - > open_fontsel ) , TRUE ) ;
gtk_window_set_destroy_with_parent ( GTK_WINDOW ( app - > open_fontsel ) , TRUE ) ;
gtk_window_set_skip_taskbar_hint ( GTK_WINDOW ( app - > open_fontsel ) , TRUE ) ;
gtk_window_set_type_hint ( GTK_WINDOW ( app - > open_fontsel ) , GDK_WINDOW_TYPE_HINT_DIALOG ) ;
2007-05-15 15:16:16 +00:00
gtk_widget_set_name ( app - > open_fontsel , " GeanyDialog " ) ;
2006-02-25 22:26:43 +00:00
2006-02-22 13:46:20 +00:00
gtk_widget_show ( GTK_FONT_SELECTION_DIALOG ( app - > open_fontsel ) - > apply_button ) ;
g_signal_connect ( ( gpointer ) app - > open_fontsel ,
2007-01-19 23:17:40 +00:00
" delete_event " , G_CALLBACK ( gtk_widget_hide_on_delete ) , NULL ) ;
2006-02-22 13:46:20 +00:00
g_signal_connect ( ( gpointer ) GTK_FONT_SELECTION_DIALOG ( app - > open_fontsel ) - > ok_button ,
" clicked " , G_CALLBACK ( on_font_ok_button_clicked ) , NULL ) ;
g_signal_connect ( ( gpointer ) GTK_FONT_SELECTION_DIALOG ( app - > open_fontsel ) - > cancel_button ,
" clicked " , G_CALLBACK ( on_font_cancel_button_clicked ) , NULL ) ;
g_signal_connect ( ( gpointer ) GTK_FONT_SELECTION_DIALOG ( app - > open_fontsel ) - > apply_button ,
" clicked " , G_CALLBACK ( on_font_apply_button_clicked ) , NULL ) ;
2007-01-19 23:17:40 +00:00
gtk_font_selection_dialog_set_font_name (
GTK_FONT_SELECTION_DIALOG ( app - > open_fontsel ) , app - > editor_font ) ;
2006-08-02 10:50:53 +00:00
gtk_window_set_transient_for ( GTK_WINDOW ( app - > open_fontsel ) , GTK_WINDOW ( app - > window ) ) ;
2005-11-22 12:26:26 +00:00
}
/* We make sure the dialog is visible. */
gtk_window_present ( GTK_WINDOW ( app - > open_fontsel ) ) ;
# endif
}
2006-08-19 12:56:30 +00:00
void dialogs_show_input ( const gchar * title , const gchar * label_text , const gchar * default_text ,
GCallback cb_dialog , GCallback cb_entry )
2005-11-22 12:26:26 +00:00
{
2006-10-19 16:26:29 +00:00
GtkWidget * dialog , * label , * entry , * vbox ;
2005-11-22 12:26:26 +00:00
2006-08-19 12:56:30 +00:00
dialog = gtk_dialog_new_with_buttons ( title , GTK_WINDOW ( app - > window ) ,
2006-10-19 16:26:29 +00:00
GTK_DIALOG_DESTROY_WITH_PARENT , GTK_STOCK_CANCEL , GTK_RESPONSE_CANCEL ,
2006-08-19 12:56:30 +00:00
GTK_STOCK_OK , GTK_RESPONSE_ACCEPT , NULL ) ;
2006-10-22 14:56:05 +00:00
vbox = ui_dialog_vbox_new ( GTK_DIALOG ( dialog ) ) ;
2007-05-15 15:16:16 +00:00
gtk_widget_set_name ( dialog , " GeanyDialog " ) ;
2006-10-19 16:26:29 +00:00
gtk_box_set_spacing ( GTK_BOX ( vbox ) , 6 ) ;
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 ) ;
2005-11-22 12:26:26 +00:00
entry = gtk_entry_new ( ) ;
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 ) ;
2006-08-19 12:56:30 +00:00
if ( cb_entry ! = NULL ) g_signal_connect ( ( gpointer ) entry , " activate " , cb_entry , dialog ) ;
g_signal_connect ( ( gpointer ) dialog , " response " , cb_dialog , entry ) ;
2006-05-19 17:18:06 +00:00
g_signal_connect ( ( gpointer ) dialog , " delete_event " , G_CALLBACK ( gtk_widget_destroy ) , NULL ) ;
2005-11-22 12:26:26 +00:00
2006-10-19 16:26:29 +00:00
gtk_container_add ( GTK_CONTAINER ( vbox ) , label ) ;
gtk_container_add ( GTK_CONTAINER ( vbox ) , entry ) ;
2005-11-22 12:26:26 +00:00
gtk_widget_show_all ( dialog ) ;
}
2006-09-09 14:36:15 +00:00
void dialogs_show_goto_line ( )
2005-11-22 12:26:26 +00:00
{
2006-10-19 16:26:29 +00:00
GtkWidget * dialog , * label , * entry , * vbox ;
2005-11-22 12:26:26 +00:00
2007-07-12 11:59:13 +00:00
dialog = gtk_dialog_new_with_buttons ( _ ( " Go to Line " ) , GTK_WINDOW ( app - > window ) ,
2005-11-22 12:26:26 +00:00
GTK_DIALOG_DESTROY_WITH_PARENT ,
2006-10-19 16:26:29 +00:00
GTK_STOCK_CANCEL , GTK_RESPONSE_CANCEL ,
2005-11-22 12:26:26 +00:00
GTK_STOCK_OK , GTK_RESPONSE_ACCEPT , NULL ) ;
2006-10-22 14:56:05 +00:00
vbox = ui_dialog_vbox_new ( GTK_DIALOG ( dialog ) ) ;
2007-05-15 15:16:16 +00:00
gtk_widget_set_name ( dialog , " GeanyDialog " ) ;
2005-11-22 12:26:26 +00:00
2006-10-19 16:26:29 +00:00
label = gtk_label_new ( _ ( " Enter the line you want to go to: " ) ) ;
gtk_misc_set_alignment ( GTK_MISC ( label ) , 0 , 0.5 ) ;
2005-11-22 12:26:26 +00:00
entry = gtk_entry_new ( ) ;
gtk_entry_set_max_length ( GTK_ENTRY ( entry ) , 6 ) ;
gtk_entry_set_width_chars ( GTK_ENTRY ( entry ) , 30 ) ;
g_signal_connect ( ( gpointer ) entry , " activate " , G_CALLBACK ( on_goto_line_entry_activate ) , dialog ) ;
g_signal_connect ( ( gpointer ) dialog , " response " , G_CALLBACK ( on_goto_line_dialog_response ) , entry ) ;
2006-10-19 16:26:29 +00:00
gtk_container_add ( GTK_CONTAINER ( vbox ) , label ) ;
gtk_container_add ( GTK_CONTAINER ( vbox ) , entry ) ;
2005-11-22 12:26:26 +00:00
gtk_widget_show_all ( dialog ) ;
}
2006-02-22 13:46:20 +00:00
void dialogs_show_file_properties ( gint idx )
{
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 ;
2006-02-22 13:46:20 +00:00
# if defined(HAVE_SYS_STAT_H) && defined(HAVE_SYS_TYPES_H)
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
2006-05-05 16:37:35 +00:00
// define this ones, to avoid later trouble
# 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
2006-04-27 18:06:35 +00:00
if ( idx = = - 1 | | ! doc_list [ idx ] . is_valid | | doc_list [ idx ] . file_name = = NULL )
{
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
# if defined(HAVE_SYS_STAT_H) && defined(TIME_WITH_SYS_TIME) && defined(HAVE_SYS_TYPES_H)
2007-04-16 15:58:34 +00:00
# ifdef G_OS_WIN32
// don't try to convert the filename on Windows, it should be already in UTF8
locale_filename = g_strdup ( doc_list [ idx ] . file_name ) ;
# else
2006-08-13 09:07:10 +00:00
locale_filename = utils_get_locale_from_utf8 ( doc_list [ idx ] . file_name ) ;
2007-04-16 15:58:34 +00:00
# endif
if ( g_stat ( locale_filename , & st ) = = 0 )
2006-02-22 13:46:20 +00:00
{
2006-04-27 18:06:35 +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
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
base_name = g_path_get_basename ( doc_list [ idx ] . file_name ) ;
title = g_strconcat ( base_name , " " , _ ( " Properties " ) , NULL ) ;
dialog = gtk_dialog_new_with_buttons ( title , GTK_WINDOW ( app - > window ) ,
GTK_DIALOG_DESTROY_WITH_PARENT ,
2006-10-19 16:26:29 +00:00
GTK_STOCK_CLOSE , GTK_RESPONSE_CANCEL , NULL ) ;
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 ) ;
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 ) ;
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 ) ;
label = gtk_label_new ( doc_list [ idx ] . file_type - > title ) ;
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 ) ;
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 ) ;
label = gtk_label_new ( doc_list [ idx ] . file_name ) ;
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 ) ;
gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( check ) , doc_list [ idx ] . readonly ) ;
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 " ,
2007-01-07 16:22:41 +00:00
doc_list [ idx ] . encoding ,
( encodings_is_unicode_charset ( doc_list [ idx ] . encoding ) ) ?
( ( doc_list [ idx ] . has_bom ) ? _ ( " (with BOM) " ) : _ ( " (without BOM) " ) ) : " " ) ;
2006-07-22 01:29:10 +00:00
label = gtk_label_new ( enctext ) ;
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 ) ;
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 ) ;
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 ) ;
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 ) ;
// 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
2006-10-19 16:26:29 +00:00
// create table with the permissions
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
// 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
// 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 ) ;
// 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 ) ;
// 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 ,
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 ;
2007-07-04 17:08:53 +00:00
if ( parent = = NULL )
parent = app - > window ;
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 " ) ;
2006-08-18 17:22:57 +00:00
// question_text will be in bold if optional extra_text used
if ( extra_text ! = NULL )
gtk_message_dialog_format_secondary_text ( GTK_MESSAGE_DIALOG ( dialog ) ,
" %s " , extra_text ) ;
2007-05-15 15:16:16 +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 ;
}
gboolean dialogs_show_question ( const gchar * text , . . . )
{
gboolean ret = FALSE ;
gchar * string = g_malloc ( 512 ) ;
va_list args ;
va_start ( args , text ) ;
g_vsnprintf ( string , 511 , text , args ) ;
va_end ( args ) ;
2007-07-04 17:08:53 +00:00
ret = show_question ( app - > window , GTK_STOCK_YES , GTK_STOCK_NO , string , NULL ) ;
2006-04-27 18:06:35 +00:00
g_free ( string ) ;
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.
* if parent is NULL , app - > window will be used */
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 ;
gchar * string = g_malloc ( 512 ) ;
va_list args ;
2006-05-14 16:07:30 +00:00
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-08-18 17:22:57 +00:00
g_free ( string ) ;
2006-04-27 18:06:35 +00:00
return ret ;
}
2006-06-05 15:12:40 +00:00