Use Rename button instead of checkbox for Save As dialog.
Add tooltips for Save As dialog's other options. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@1703 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
parent
3ecd31d9fd
commit
a4728116bc
@ -1,3 +1,10 @@
|
||||
2007-07-16 Nick Treleaven <nick.treleaven@btinternet.com>
|
||||
|
||||
* src/dialogs.c, src/callbacks.c:
|
||||
Use Rename button instead of checkbox for Save As dialog.
|
||||
Add tooltips for Save As dialog's other options.
|
||||
|
||||
|
||||
2007-07-13 Nick Treleaven <nick.treleaven@btinternet.com>
|
||||
|
||||
* src/treeviews.c:
|
||||
|
177
src/callbacks.c
177
src/callbacks.c
@ -862,6 +862,41 @@ on_file_open_selection_changed (GtkFileChooser *filechooser,
|
||||
}
|
||||
|
||||
|
||||
static gint
|
||||
clone_document(gint old_idx, const gchar *utf8_filename)
|
||||
{
|
||||
// create a new file and copy file content and properties
|
||||
gint len, idx;
|
||||
gchar *data;
|
||||
|
||||
// use old file type (or maybe NULL for auto detect would be better?)
|
||||
idx = document_new_file(utf8_filename, doc_list[idx].file_type);
|
||||
|
||||
sci_set_undo_collection(doc_list[idx].sci, FALSE); // avoid creation of an undo action
|
||||
sci_empty_undo_buffer(doc_list[idx].sci);
|
||||
|
||||
len = sci_get_length(doc_list[old_idx].sci) + 1;
|
||||
data = (gchar*) g_malloc(len);
|
||||
sci_get_text(doc_list[old_idx].sci, len, data);
|
||||
|
||||
sci_set_text(doc_list[idx].sci, data);
|
||||
|
||||
// copy file properties
|
||||
doc_list[idx].line_breaking = doc_list[old_idx].line_breaking;
|
||||
doc_list[idx].readonly = doc_list[old_idx].readonly;
|
||||
doc_list[idx].has_bom = doc_list[old_idx].has_bom;
|
||||
document_set_encoding(idx, doc_list[old_idx].encoding);
|
||||
sci_set_lines_wrapped(doc_list[idx].sci, doc_list[idx].line_breaking);
|
||||
sci_set_readonly(doc_list[idx].sci, doc_list[idx].readonly);
|
||||
sci_set_undo_collection(doc_list[idx].sci, TRUE);
|
||||
|
||||
ui_document_show_hide(idx);
|
||||
|
||||
g_free(data);
|
||||
return idx;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* save dialog callbacks
|
||||
*/
|
||||
@ -870,96 +905,74 @@ on_file_save_dialog_response (GtkDialog *dialog,
|
||||
gint response,
|
||||
gpointer user_data)
|
||||
{
|
||||
if (response == GTK_RESPONSE_ACCEPT)
|
||||
gboolean rename_file = FALSE;
|
||||
|
||||
switch (response)
|
||||
{
|
||||
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")));
|
||||
gboolean rename_file = gtk_toggle_button_get_active(
|
||||
GTK_TOGGLE_BUTTON(lookup_widget(app->save_filesel, "check_rename")));
|
||||
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);
|
||||
utf8_filename = g_strdup(new_filename);
|
||||
#else
|
||||
utf8_filename = utils_get_utf8_from_locale(new_filename);
|
||||
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
|
||||
// (actually create a new file and copy file content and properties)
|
||||
gint len, old_idx;
|
||||
gchar *data;
|
||||
|
||||
old_idx = idx;
|
||||
|
||||
// use old file type (or maybe NULL for auto detect would be better?)
|
||||
idx = document_new_file(utf8_filename, doc_list[idx].file_type);
|
||||
|
||||
sci_set_undo_collection(doc_list[idx].sci, FALSE); // avoid creation of an undo action
|
||||
sci_empty_undo_buffer(doc_list[idx].sci);
|
||||
|
||||
len = sci_get_length(doc_list[old_idx].sci) + 1;
|
||||
data = (gchar*) g_malloc(len);
|
||||
sci_get_text(doc_list[old_idx].sci, len, data);
|
||||
|
||||
sci_set_text(doc_list[idx].sci, data);
|
||||
|
||||
// copy file properties
|
||||
doc_list[idx].line_breaking = doc_list[old_idx].line_breaking;
|
||||
doc_list[idx].readonly = doc_list[old_idx].readonly;
|
||||
doc_list[idx].has_bom = doc_list[old_idx].has_bom;
|
||||
document_set_encoding(idx, doc_list[old_idx].encoding);
|
||||
sci_set_lines_wrapped(doc_list[idx].sci, doc_list[idx].line_breaking);
|
||||
sci_set_readonly(doc_list[idx].sci, doc_list[idx].readonly);
|
||||
sci_set_undo_collection(doc_list[idx].sci, TRUE);
|
||||
|
||||
ui_document_show_hide(idx);
|
||||
|
||||
g_free(data);
|
||||
g_free(utf8_filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (doc_list[idx].file_name != NULL)
|
||||
// check if file exists and ask whether to overwrite or not
|
||||
if (g_file_test(new_filename, G_FILE_TEST_EXISTS))
|
||||
{
|
||||
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);
|
||||
if (dialogs_show_question(
|
||||
_("The file '%s' already exists. Do you want to overwrite it?"),
|
||||
utf8_filename) == FALSE)
|
||||
return;
|
||||
}
|
||||
doc_list[idx].file_name = utf8_filename;
|
||||
|
||||
if (open_new_tab)
|
||||
{ // "open" the saved file in a new tab
|
||||
idx = clone_document(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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
@ -80,18 +80,18 @@ void dialogs_show_open_file ()
|
||||
|
||||
app->open_filesel = gtk_file_chooser_dialog_new(_("Open File"), GTK_WINDOW(app->window),
|
||||
GTK_FILE_CHOOSER_ACTION_OPEN, NULL, NULL);
|
||||
gtk_widget_set_name(app->open_filesel, "GeanyDialog");
|
||||
|
||||
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_widget_set_name(app->open_filesel, "GeanyDialog");
|
||||
gtk_dialog_add_action_widget(GTK_DIALOG(app->open_filesel),
|
||||
viewbtn, GTK_RESPONSE_APPLY);
|
||||
|
||||
gtk_dialog_add_buttons(GTK_DIALOG(app->open_filesel),
|
||||
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
||||
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
|
||||
// set default Open, so pressing enter can open multiple files
|
||||
gtk_dialog_set_default_response(GTK_DIALOG(app->open_filesel),
|
||||
GTK_RESPONSE_ACCEPT);
|
||||
|
||||
@ -276,36 +276,43 @@ gboolean dialogs_show_save_as()
|
||||
|
||||
if (app->save_filesel == NULL)
|
||||
{
|
||||
GtkWidget *vbox, *check_open_new_tab, *check_rename;
|
||||
GtkWidget *vbox, *check_open_new_tab, *rename_btn;
|
||||
GtkTooltips *tooltips = GTK_TOOLTIPS(lookup_widget(app->window, "tooltips"));
|
||||
|
||||
app->save_filesel = gtk_file_chooser_dialog_new(_("Save File"), GTK_WINDOW(app->window),
|
||||
GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
||||
GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL);
|
||||
GTK_FILE_CHOOSER_ACTION_SAVE, NULL, NULL);
|
||||
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);
|
||||
gtk_dialog_set_default_response(GTK_DIALOG(app->save_filesel), GTK_RESPONSE_ACCEPT);
|
||||
gtk_widget_set_name(app->save_filesel, "GeanyDialog");
|
||||
|
||||
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);
|
||||
|
||||
vbox = gtk_vbox_new(FALSE, 0);
|
||||
check_open_new_tab = gtk_check_button_new_with_mnemonic("_Open file in a new tab");
|
||||
check_rename = gtk_check_button_new_with_mnemonic("R_ename file");
|
||||
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);
|
||||
gtk_box_pack_start(GTK_BOX(vbox), check_open_new_tab, FALSE, FALSE, 0);
|
||||
gtk_box_pack_start(GTK_BOX(vbox), check_rename, FALSE, TRUE, 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",
|
||||
G_CALLBACK(on_save_as_new_tab_toggled), check_rename);
|
||||
|
||||
g_signal_connect(check_rename, "toggled",
|
||||
G_CALLBACK(on_save_as_new_tab_toggled), check_open_new_tab);
|
||||
G_CALLBACK(on_save_as_new_tab_toggled), rename_btn);
|
||||
|
||||
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);
|
||||
g_object_set_data_full(G_OBJECT(app->save_filesel), "check_rename",
|
||||
gtk_widget_ref(check_rename), (GDestroyNotify) gtk_widget_unref);
|
||||
|
||||
g_signal_connect((gpointer) app->save_filesel, "delete_event",
|
||||
G_CALLBACK(gtk_widget_hide_on_delete), NULL);
|
||||
@ -1144,6 +1151,6 @@ gboolean dialogs_show_question_full(GtkWidget *parent, const gchar *yes_btn, con
|
||||
|
||||
static void on_save_as_new_tab_toggled(GtkToggleButton *togglebutton, gpointer user_data)
|
||||
{
|
||||
if (gtk_toggle_button_get_active(togglebutton))
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(user_data), FALSE);
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(user_data),
|
||||
! gtk_toggle_button_get_active(togglebutton));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user