Yasumichi Akahoshi
yasum****@users*****
2005年 5月 16日 (月) 01:00:43 JST
Index: cxplorer/src/cxp-right-pane.c diff -u cxplorer/src/cxp-right-pane.c:1.47 cxplorer/src/cxp-right-pane.c:1.48 --- cxplorer/src/cxp-right-pane.c:1.47 Sun May 15 01:22:28 2005 +++ cxplorer/src/cxp-right-pane.c Mon May 16 01:00:43 2005 @@ -63,6 +63,7 @@ COL_FILE_TYPE, /**< string of file type. */ COL_FILE_MODE, /**< File type */ COL_UPDATE_TIME, /**< Update time of file */ + COL_EDITABLE, COL_COUNT /**< Count of columns */ }; @@ -101,10 +102,13 @@ GtkCellRenderer * cell, GtkTreeModel * tree_model, GtkTreeIter * iter, gpointer data); -void cxp_right_pane_draw_update_time (GtkTreeViewColumn * tree_column, - GtkCellRenderer * cell, - GtkTreeModel * tree_model, - GtkTreeIter * iter, gpointer data); +static void cxp_right_pane_draw_update_time (GtkTreeViewColumn * tree_column, + GtkCellRenderer * cell, + GtkTreeModel * tree_model, + GtkTreeIter * iter, gpointer data); +static void cxp_right_pane_cell_edited (GtkCellRendererText * cell, + const gchar * path_string, + const gchar * new_text, gpointer data); static gint cxp_right_pane_compare_by_default (GtkTreeModel * model, GtkTreeIter * iter_a, GtkTreeIter * iter_b, @@ -116,8 +120,13 @@ GtkTextBuffer * text_buffer, const gchar * filename); static gint cxp_right_pane_popup_handler (GtkWidget * widget, GdkEvent * event); -static void cxp_right_pane_preview_expanded (GObject *object, GParamSpec *param_spec, gpointer user_data); -static void cxp_right_pane_delete_selected_file_foreach (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer userdata); +static void cxp_right_pane_preview_expanded (GObject * object, + GParamSpec * param_spec, + gpointer user_data); +static void cxp_right_pane_delete_selected_file_foreach (GtkTreeModel * model, + GtkTreePath * path, + GtkTreeIter * iter, + gpointer userdata); GType cxp_right_pane_get_type (void) { @@ -196,7 +205,7 @@ priv->cxp_unknown = create_pixbuf ("cxp_unknown.png"); scrolled_window = gtk_scrolled_window_new (NULL, NULL); - gtk_widget_set_size_request (GTK_WIDGET(scrolled_window), 300, 200); + gtk_widget_set_size_request (GTK_WIDGET (scrolled_window), 300, 200); gtk_box_pack_start (GTK_BOX (self), scrolled_window, TRUE, TRUE, 0); gtk_widget_show (scrolled_window); priv->file_list = cxp_right_pane_file_list_new (self); @@ -204,12 +213,12 @@ gtk_widget_show (priv->file_list); priv->expander = gtk_expander_new (_("<b>Preview</b>")); - gtk_expander_set_use_markup (GTK_EXPANDER(priv->expander), TRUE); + gtk_expander_set_use_markup (GTK_EXPANDER (priv->expander), TRUE); gtk_box_pack_start (GTK_BOX (self), priv->expander, FALSE, TRUE, 0); gtk_widget_show (priv->expander); scrolled_window = gtk_scrolled_window_new (NULL, NULL); - gtk_widget_set_size_request (GTK_WIDGET(scrolled_window), -1, 200); + gtk_widget_set_size_request (GTK_WIDGET (scrolled_window), -1, 200); gtk_container_add (GTK_CONTAINER (priv->expander), scrolled_window); gtk_widget_show (scrolled_window); @@ -231,7 +240,7 @@ g_signal_connect (priv->file_list, "row_activated", G_CALLBACK (cxp_right_pane_on_row_activated), self); g_signal_connect (priv->expander, "notify::expanded", - G_CALLBACK (cxp_right_pane_preview_expanded), self); + G_CALLBACK (cxp_right_pane_preview_expanded), self); } static void cxp_right_pane_dispose (GObject * obj) @@ -317,11 +326,11 @@ file_list = gtk_tree_view_new (); store = gtk_list_store_new (COL_COUNT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_UINT, - G_TYPE_UINT); + G_TYPE_UINT, G_TYPE_BOOLEAN); gtk_tree_view_set_model (GTK_TREE_VIEW (file_list), GTK_TREE_MODEL (store)); - selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(file_list)); - gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (file_list)); + gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE); /* Sort setting */ sortable = GTK_TREE_SORTABLE (store); @@ -345,7 +354,10 @@ gtk_tree_view_column_set_sort_column_id (column, COL_DISP_NAME); gtk_tree_view_column_pack_start (column, renderer, FALSE); gtk_tree_view_column_set_attributes (column, renderer, "text", - COL_DISP_NAME, NULL); + COL_DISP_NAME, "editable", + COL_EDITABLE, NULL); + g_signal_connect (renderer, "edited", + G_CALLBACK (cxp_right_pane_cell_edited), self); /* 2nd column */ renderer = gtk_cell_renderer_text_new (); @@ -405,7 +417,7 @@ GtkTreeModel *model; gchar *fullpath; - if(gtk_expander_get_expanded (GTK_EXPANDER(priv->expander)) == FALSE) + if (gtk_expander_get_expanded (GTK_EXPANDER (priv->expander)) == FALSE) { return; } @@ -510,10 +522,10 @@ * @param iter [in] Iterator of node which want to be paint by GtkCellRender. * @param data [in] Pointer to data which is defined by user. */ -void cxp_right_pane_draw_update_time (GtkTreeViewColumn * tree_column, - GtkCellRenderer * cell, - GtkTreeModel * tree_model, - GtkTreeIter * iter, gpointer data) +static void cxp_right_pane_draw_update_time (GtkTreeViewColumn * tree_column, + GtkCellRenderer * cell, + GtkTreeModel * tree_model, + GtkTreeIter * iter, gpointer data) { gchar *time_string; time_t updated; @@ -528,6 +540,86 @@ g_free (time_string); } +static void cxp_right_pane_cell_edited (GtkCellRendererText * cell, + const gchar * path_string, + const gchar * new_text, gpointer data) +{ + CxpRightPanePrivate *priv = CXP_RIGHT_PANE_GET_PRIVATE (data); + GtkTreeModel *model = + gtk_tree_view_get_model (GTK_TREE_VIEW (priv->file_list)); + GtkTreePath *path = gtk_tree_path_new_from_string (path_string); + GtkTreeIter iter; + GtkWidget *dialog; + gchar *dirname; + gchar *srcpath; + gchar *srcbase; + gchar *destpath; + gchar *destbase_locale; + gchar *error_msg; + + gtk_tree_model_get_iter (model, &iter, path); + gtk_tree_model_get (model, &iter, COL_FILE_PATH, &srcpath, + COL_TERMINATOR); + srcbase = cxp_path_get_basename_of_utf8 (srcpath); + if (strcmp (srcbase, new_text) == 0) + { + gtk_list_store_set (GTK_LIST_STORE (model), &iter, COL_EDITABLE, + FALSE, -1); + g_free (srcbase); + g_free (srcpath); + gtk_tree_path_free (path); + return; + } + g_free (srcbase); + + dirname = g_path_get_dirname (srcpath); + destbase_locale = g_locale_from_utf8 (new_text, -1, NULL, NULL, NULL); + destpath = g_build_filename (dirname, destbase_locale, NULL); + + if (g_file_test (destpath, G_FILE_TEST_EXISTS) == FALSE) + { + errno = 0; + if (rename (srcpath, destpath) == 0) + { + gtk_list_store_set (GTK_LIST_STORE (model), &iter, + COL_FILE_PATH, destpath, + COL_DISP_NAME, g_strdup (new_text), + COL_EDITABLE, FALSE, -1); + } + else + { + dialog = gtk_message_dialog_new (NULL, + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + "%s", + g_strerror (errno)); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + } + } + else + { + error_msg = + g_strdup_printf (_("%s is already exists."), new_text); + dialog = gtk_message_dialog_new (NULL, + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + "%s", error_msg); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + g_free (error_msg); + } + + g_free (destbase_locale); + g_free (dirname); + g_free (srcpath); + /* test */ + + gtk_tree_path_free (path); +} + /** * compare function for default sort method. * @param model [in] A instance of GtkTreeModel. @@ -600,7 +692,7 @@ gchar *dispname; gchar **filetype; - if((dispname = cxp_path_get_basename_of_utf8 (fullpath)) == NULL) + if ((dispname = cxp_path_get_basename_of_utf8 (fullpath)) == NULL) { dispname = g_strdup (_("(Invalid filename)")); } @@ -651,11 +743,14 @@ if (strstr (filetype, "image") != NULL) { - if((pixbuf = gdk_pixbuf_new_from_file (filename, NULL)) != NULL) + if ((pixbuf = + gdk_pixbuf_new_from_file (filename, NULL)) != NULL) { gtk_text_buffer_set_text (text_buffer, "", -1); - gtk_text_buffer_get_iter_at_line (text_buffer, &iter, 0); - gtk_text_buffer_insert_pixbuf (text_buffer, &iter, pixbuf); + gtk_text_buffer_get_iter_at_line (text_buffer, + &iter, 0); + gtk_text_buffer_insert_pixbuf (text_buffer, + &iter, pixbuf); return; } @@ -733,17 +828,21 @@ return FALSE; } -static void cxp_right_pane_preview_expanded (GObject *object, GParamSpec *param_spec, gpointer user_data) +static void cxp_right_pane_preview_expanded (GObject * object, + GParamSpec * param_spec, + gpointer user_data) { CxpRightPane *self = CXP_RIGHT_PANE (user_data); CxpRightPanePrivate *priv = CXP_RIGHT_PANE_GET_PRIVATE (self); GtkTextBuffer *buffer; gchar *filename; - if (gtk_expander_get_expanded (GTK_EXPANDER(priv->expander))) + if (gtk_expander_get_expanded (GTK_EXPANDER (priv->expander))) { - buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->preview)); - if((filename = cxp_right_pane_get_active_file_name (self)) != NULL) + buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW + (priv->preview)); + if ((filename = + cxp_right_pane_get_active_file_name (self)) != NULL) { cxp_right_pane_show_preview (self, buffer, filename); g_free (filename); @@ -760,7 +859,10 @@ * 選択ファイルをそれぞれ削除する。 * \endif */ -static void cxp_right_pane_delete_selected_file_foreach (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer userdata) +static void cxp_right_pane_delete_selected_file_foreach (GtkTreeModel * model, + GtkTreePath * path, + GtkTreeIter * iter, + gpointer userdata) { GtkWidget *dialog; gchar *fullpath; @@ -772,47 +874,58 @@ gchar *standard_error; gint exit_status; - gtk_tree_model_get (model, iter, COL_FILE_PATH, &fullpath, COL_TERMINATOR); + gtk_tree_model_get (model, iter, COL_FILE_PATH, &fullpath, + COL_TERMINATOR); filename = cxp_path_get_basename_of_utf8 (fullpath); - if (g_file_test(fullpath, G_FILE_TEST_IS_DIR) && !g_file_test(fullpath, G_FILE_TEST_IS_SYMLINK)) + if (g_file_test (fullpath, G_FILE_TEST_IS_DIR) + && !g_file_test (fullpath, G_FILE_TEST_IS_SYMLINK)) { errno = 0; - if(rmdir(fullpath) == -1) + if (rmdir (fullpath) == -1) { - switch(errno) + switch (errno) { - case ENOTEMPTY: - dialog = gtk_message_dialog_new (NULL, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_YES_NO, - "%s:%s\nDo you really delete it?", - filename, - g_strerror (errno)); - if(gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_YES) + case ENOTEMPTY: + dialog = gtk_message_dialog_new (NULL, + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_YES_NO, + "%s:%s\nDo you really delete it?", + filename, + g_strerror + (errno)); + if (gtk_dialog_run (GTK_DIALOG (dialog)) == + GTK_RESPONSE_YES) + { + cmd = g_strdup_printf ("rm -rf '%s'", + filename); + g_spawn_command_line_sync (cmd, NULL, + &standard_error, + &exit_status, + NULL); + if (exit_status != 0) { - cmd = g_strdup_printf ("rm -rf '%s'", filename); - g_spawn_command_line_sync (cmd, NULL, &standard_error, - &exit_status, NULL); - if (exit_status != 0) - { - error_msg = g_locale_to_utf8 (standard_error, -1, NULL, NULL, NULL); - dialog = gtk_message_dialog_new (NULL, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_CLOSE, - "%s", - error_msg); - gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); - g_free (error_msg); - } + error_msg = + g_locale_to_utf8 + (standard_error, -1, + NULL, NULL, NULL); + dialog = gtk_message_dialog_new + (NULL, + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + "%s", error_msg); + gtk_dialog_run (GTK_DIALOG + (dialog)); + gtk_widget_destroy (dialog); + g_free (error_msg); } - gtk_widget_destroy (dialog); - break; - default: - cxp_error_dialog_run_about_file (filename); + } + gtk_widget_destroy (dialog); + break; + default: + cxp_error_dialog_run_about_file (filename); } } } @@ -977,13 +1090,16 @@ * 選択ファイルを削除する * \endif */ -void cxp_right_pane_delete_selected_files (CxpRightPane *right_pane) +void cxp_right_pane_delete_selected_files (CxpRightPane * right_pane) { CxpRightPanePrivate *priv = CXP_RIGHT_PANE_GET_PRIVATE (right_pane); GtkTreeSelection *selection; - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(priv->file_list)); - gtk_tree_selection_selected_foreach (selection, cxp_right_pane_delete_selected_file_foreach, NULL); + selection = + gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->file_list)); + gtk_tree_selection_selected_foreach (selection, + cxp_right_pane_delete_selected_file_foreach, + NULL); cxp_right_pane_change_directory (right_pane, priv->cur_dir); } @@ -1040,99 +1156,103 @@ void cxp_right_pane_rename_file_request (CxpRightPane * right_pane) { CxpRightPanePrivate *priv = CXP_RIGHT_PANE_GET_PRIVATE (right_pane); - gchar *dirname; - gchar *srcpath; - gchar *srcbase; - gchar *destpath; - gchar *destbase; - gchar *destbase_locale; - gchar *error_msg; GtkTreeIter iter; GtkTreeModel *model; GtkTreePath *treepath; GtkTreeSelection *selection; - GtkWidget *dialog; + GtkTreeViewColumn *column; selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->file_list)); //if (gtk_tree_selection_get_selected (selection, &model, &iter)) if (gtk_tree_selection_count_selected_rows (selection) == 1) { - gtk_tree_view_get_cursor (GTK_TREE_VIEW(priv->file_list), &treepath, NULL); - model = gtk_tree_view_get_model (GTK_TREE_VIEW(priv->file_list)); + gtk_tree_view_get_cursor (GTK_TREE_VIEW (priv->file_list), + &treepath, NULL); + column = gtk_tree_view_get_column (GTK_TREE_VIEW + (priv->file_list), + COL_DISP_NAME); + model = gtk_tree_view_get_model (GTK_TREE_VIEW + (priv->file_list)); gtk_tree_model_get_iter (model, &iter, treepath); - gtk_tree_model_get (model, &iter, COL_FILE_PATH, &srcpath, - COL_TERMINATOR); - dirname = g_path_get_dirname (srcpath); - srcbase = cxp_path_get_basename_of_utf8 (srcpath); - dialog = cxp_entry_dialog_new (_("Rename"), - _("Please, input a new name."), - srcbase); - if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) - { - destbase = - cxp_entry_dialog_get_entry_text - (CXP_ENTRY_DIALOG (dialog)); - gtk_widget_destroy (dialog); - destbase_locale = - g_locale_from_utf8 (destbase, -1, NULL, NULL, - NULL); - destpath = - g_build_filename (dirname, destbase_locale, - NULL); - - if (g_file_test (destpath, G_FILE_TEST_EXISTS) == FALSE) - { - if (rename (srcpath, destpath) == 0) - { - gtk_list_store_set (GTK_LIST_STORE - (model), &iter, - COL_FILE_PATH, - destpath, - COL_DISP_NAME, - destbase, - COL_TERMINATOR); - } - else - { - dialog = gtk_message_dialog_new (NULL, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_CLOSE, - "%s", - g_strerror - (errno)); - gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); - } - } - else - { - error_msg = - g_strdup_printf (_ - ("%s is already exists."), - destbase); - dialog = gtk_message_dialog_new (NULL, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_CLOSE, - "%s", - error_msg); - gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); - g_free (error_msg); - } - - g_free (destbase); - g_free (destbase_locale); - } - else - { - gtk_widget_destroy (dialog); - } - g_free (dirname); - g_free (srcbase); - g_free (srcpath); + gtk_list_store_set (GTK_LIST_STORE (model), &iter, COL_EDITABLE, + TRUE, -1); + gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->file_list), + treepath, column, TRUE); + /* + gtk_tree_model_get (model, &iter, COL_FILE_PATH, &srcpath, + COL_TERMINATOR); + dirname = g_path_get_dirname (srcpath); + srcbase = cxp_path_get_basename_of_utf8 (srcpath); + dialog = cxp_entry_dialog_new (_("Rename"), + _("Please, input a new name."), + srcbase); + if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) + { + destbase = + cxp_entry_dialog_get_entry_text + (CXP_ENTRY_DIALOG (dialog)); + gtk_widget_destroy (dialog); + destbase_locale = + g_locale_from_utf8 (destbase, -1, NULL, NULL, + NULL); + destpath = + g_build_filename (dirname, destbase_locale, + NULL); + + if (g_file_test (destpath, G_FILE_TEST_EXISTS) == FALSE) + { + if (rename (srcpath, destpath) == 0) + { + gtk_list_store_set (GTK_LIST_STORE + (model), &iter, + COL_FILE_PATH, + destpath, + COL_DISP_NAME, + destbase, + COL_TERMINATOR); + } + else + { + dialog = gtk_message_dialog_new (NULL, + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + "%s", + g_strerror + (errno)); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + } + } + else + { + error_msg = + g_strdup_printf (_ + ("%s is already exists."), + destbase); + dialog = gtk_message_dialog_new (NULL, + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + "%s", + error_msg); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + g_free (error_msg); + } + + g_free (destbase); + g_free (destbase_locale); + } + else + { + gtk_widget_destroy (dialog); + } + g_free (dirname); + g_free (srcbase); + g_free (srcpath); + */ gtk_tree_path_free (treepath); } } @@ -1152,7 +1272,8 @@ g_return_if_fail (cmd != NULL); - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(priv->file_list)); + selection = + gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->file_list)); list = gtk_tree_selection_get_selected_rows (selection, &model); g_return_if_fail (list != NULL); @@ -1162,10 +1283,11 @@ while (cur != NULL) { gtk_tree_model_get_iter (model, &iter, cur->data); - gtk_tree_model_get (model, &iter, COL_FILE_PATH, &fullpath, COL_TERMINATOR); + gtk_tree_model_get (model, &iter, COL_FILE_PATH, &fullpath, + COL_TERMINATOR); g_string_append_printf (fullcmd, " '%s'", fullpath); g_free (fullpath); - cur = g_list_next(cur); + cur = g_list_next (cur); } g_list_foreach (list, gtk_tree_path_free, NULL); g_list_free (list);