📄 menu-items.c
字号:
/*****************************************************************************//* menu-items.c - menu callbacks *//* Copyright (C) 1998-2003 Brian Masney <masneyb@gftp.org> *//* *//* 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 *//* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *//*****************************************************************************/#include "gftp-gtk.h"static const char cvsid[] = "$Id: menu-items.c,v 1.39 2004/10/06 02:32:41 masneyb Exp $";static voiddochange_filespec (gftp_window_data * wdata, gftp_dialog_data * ddata){ GList * templist, * filelist; gftp_file * tempfle; const char *edttext; int num; wdata->show_selected = 0; edttext = gtk_entry_get_text (GTK_ENTRY (ddata->edit)); if (*edttext == '\0') { ftp_log (gftp_logging_misc, NULL, _("Change Filespec: Operation canceled...you must enter a string\n")); return; } if (wdata->filespec) g_free (wdata->filespec); wdata->filespec = g_strdup (edttext); filelist = wdata->files; templist = gftp_gtk_get_list_selection (wdata); num = 0; while (templist != NULL) { templist = get_next_selection (templist, &filelist, &num); tempfle = filelist->data; tempfle->was_sel = 1; } gtk_clist_freeze (GTK_CLIST (wdata->listbox)); gtk_clist_clear (GTK_CLIST (wdata->listbox)); templist = wdata->files; while (templist != NULL) { tempfle = templist->data; add_file_listbox (wdata, tempfle); templist = templist->next; } gtk_clist_thaw (GTK_CLIST (wdata->listbox)); update_window (wdata);}void change_filespec (gpointer data){ gftp_window_data * wdata; wdata = data; if (!check_status (_("Change Filespec"), wdata, 0, 0, 0, 1)) return; MakeEditDialog (_("Change Filespec"), _("Enter the new file specification"), wdata->filespec, 1, NULL, gftp_dialog_button_change, dochange_filespec, wdata, NULL, NULL);}static voiddestroy_save_directory_listing (GtkWidget * widget, gftp_save_dir_struct * str){ gtk_widget_destroy (str->filew); g_free (str);}static voiddosave_directory_listing (GtkWidget * widget, gftp_save_dir_struct * str){ const char *filename; gftp_file * tempfle; GList * templist; char *tempstr; FILE * fd; filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (str->filew)); if ((fd = fopen (filename, "w")) == NULL) { ftp_log (gftp_logging_misc, NULL, _("Error: Cannot open %s for writing: %s\n"), filename, g_strerror (errno)); return; } for (templist = str->wdata->files; templist != NULL; templist = templist->next) { tempfle = templist->data; if (!tempfle->shown) continue; tempstr = gftp_gen_ls_string (tempfle, NULL, NULL); fprintf (fd, "%s\n", tempstr); g_free (tempstr); } fclose (fd);}void save_directory_listing (gpointer data){ gftp_save_dir_struct * str; GtkWidget *filew; filew = gtk_file_selection_new (_("Save Directory Listing")); str = g_malloc (sizeof (*str)); str->filew = filew; str->wdata = data; gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->ok_button), "clicked", GTK_SIGNAL_FUNC (dosave_directory_listing), str); gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->ok_button), "clicked", GTK_SIGNAL_FUNC (destroy_save_directory_listing), str); gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->cancel_button), "clicked", GTK_SIGNAL_FUNC (destroy_save_directory_listing), str); gtk_window_set_wmclass (GTK_WINDOW(filew), "Save Directory Listing", "gFTP"); gtk_widget_show (filew);}voidshow_selected (gpointer data){ GList * templist, * filelist; gftp_window_data * wdata; gftp_file * tempfle; int num; wdata = data; wdata->show_selected = 1; filelist = wdata->files; templist = gftp_gtk_get_list_selection (wdata); num = 0; while (templist != NULL) { templist = get_next_selection (templist, &filelist, &num); tempfle = filelist->data; tempfle->was_sel = 1; } gtk_clist_freeze (GTK_CLIST (wdata->listbox)); gtk_clist_clear (GTK_CLIST (wdata->listbox)); templist = wdata->files; while (templist != NULL) { tempfle = templist->data; add_file_listbox (wdata, tempfle); templist = templist->next; } gtk_clist_thaw (GTK_CLIST (wdata->listbox)); update_window (wdata);}void selectall (gpointer data){ gftp_window_data * wdata; wdata = data; wdata->show_selected = 0; gtk_clist_select_all (GTK_CLIST (wdata->listbox));}void selectallfiles (gpointer data){ gftp_window_data * wdata; gftp_file * tempfle; GList *templist; int i; wdata = data; wdata->show_selected = 0; gtk_clist_freeze (GTK_CLIST (wdata->listbox)); i = 0; templist = wdata->files; while (templist != NULL) { tempfle = (gftp_file *) templist->data; if (tempfle->shown) { if (S_ISDIR (tempfle->st_mode)) gtk_clist_unselect_row (GTK_CLIST (wdata->listbox), i, 0); else gtk_clist_select_row (GTK_CLIST (wdata->listbox), i, 0); i++; } templist = templist->next; } gtk_clist_thaw (GTK_CLIST (wdata->listbox));}void deselectall (gpointer data){ gftp_window_data * wdata; wdata = data; wdata->show_selected = 0; gtk_clist_unselect_all (GTK_CLIST (wdata->listbox));}intchdir_edit (GtkWidget * widget, gpointer data){ gftp_window_data * wdata; const char *edttxt; char *tempstr; wdata = data; if (!check_status (_("Chdir"), wdata, gftpui_common_use_threads (wdata->request), 0, 0, wdata->request->chdir != NULL)) return (0); if (check_reconnect (wdata) < 0) return (0); edttxt = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (wdata->combo)->entry)); if (!GFTP_IS_CONNECTED (wdata->request) && *edttxt != '\0') { toolbar_hostedit (NULL, NULL); return (0); } if ((tempstr = gftp_expand_path (wdata->request, edttxt)) == NULL) return (FALSE); if (gftpui_run_chdir (wdata, tempstr)) add_history (wdata->combo, wdata->history, wdata->histlen, edttxt); g_free (tempstr); return (0);}void clearlog (gpointer data){ guint len;#if GTK_MAJOR_VERSION == 1 len = gtk_text_get_length (GTK_TEXT (logwdw)); gtk_text_set_point (GTK_TEXT (logwdw), len); gtk_text_backward_delete (GTK_TEXT (logwdw), len);#else GtkTextBuffer * textbuf; GtkTextIter iter, iter2; textbuf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (logwdw)); len = gtk_text_buffer_get_char_count (textbuf); gtk_text_buffer_get_iter_at_offset (textbuf, &iter, 0); gtk_text_buffer_get_iter_at_offset (textbuf, &iter2, len); gtk_text_buffer_delete (textbuf, &iter, &iter2);#endif}void viewlog (gpointer data){ char *tempstr, *txt, *pos; guint textlen; ssize_t len; int fd;#if GTK_MAJOR_VERSION > 1 GtkTextBuffer * textbuf; GtkTextIter iter, iter2;#endif tempstr = g_strconcat (g_get_tmp_dir (), "/gftp-view.XXXXXXXXXX", NULL); if ((fd = mkstemp (tempstr)) < 0) { ftp_log (gftp_logging_misc, NULL, _("Error: Cannot open %s for writing: %s\n"), tempstr, g_strerror (errno)); g_free (tempstr); return; } chmod (tempstr, S_IRUSR | S_IWUSR); #if GTK_MAJOR_VERSION == 1 textlen = gtk_text_get_length (GTK_TEXT (logwdw)); txt = gtk_editable_get_chars (GTK_EDITABLE (logwdw), 0, -1);#else textbuf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (logwdw)); textlen = gtk_text_buffer_get_char_count (textbuf); gtk_text_buffer_get_iter_at_offset (textbuf, &iter, 0); gtk_text_buffer_get_iter_at_offset (textbuf, &iter2, textlen); txt = gtk_text_buffer_get_text (textbuf, &iter, &iter2, 0); /* gtk_text_buffer_get_char_count() returns the number of characters, not bytes. So get the number of bytes that need to be written out */ textlen = strlen (txt);#endif pos = txt; while (textlen > 0) { if ((len = write (fd, pos, textlen)) == -1) { ftp_log (gftp_logging_misc, NULL, _("Error: Error writing to %s: %s\n"), tempstr, g_strerror (errno)); break; } textlen -= len; pos += len; } fsync (fd); lseek (fd, 0, SEEK_SET); view_file (tempstr, fd, 1, 1, 0, 1, NULL, NULL); close (fd); g_free (tempstr); g_free (txt);}static voiddosavelog (GtkWidget * widget, GtkFileSelection * fs){ const char *filename; char *txt, *pos; guint textlen; ssize_t len; FILE *fd; int ok;#if GTK_MAJOR_VERSION > 1 GtkTextBuffer * textbuf;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -