Oh, sorry. Wrong patch. Here is correct one.
>From e0e9ac5106e52d68c9c256a9662b2d35eb31b3e5 Mon Sep 17 00:00:00 2001
From: Alexander Varnin <[email protected]>
Date: Tue, 8 Jun 2010 21:50:23 +0400
Subject: [PATCH] Start of templates support.
---
src/main-win-ui.c | 3 +-
src/main-win.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++
src/pcmanfm.c | 25 +++++++++++++++--------
src/pcmanfm.h | 4 +-
4 files changed, 74 insertions(+), 12 deletions(-)
diff --git a/src/main-win-ui.c b/src/main-win-ui.c
index 6072af0..5606d23 100644
--- a/src/main-win-ui.c
+++ b/src/main-win-ui.c
@@ -100,6 +100,7 @@ static const char main_menu_xml[] =
"<menu action='CreateNew'>"
"<menuitem action='NewFolder'/>"
"<menuitem action='NewBlank'/>"
+ "<separator/>"
"</menu>"
"<separator/>"
"<menuitem action='Paste'/>"
@@ -170,7 +171,7 @@ static GtkActionEntry main_win_actions[]=
/* for popup menu */
{"CreateNew", GTK_STOCK_NEW, NULL, NULL, NULL, NULL},
{"NewFolder", "folder", N_("Folder"), NULL, NULL, G_CALLBACK(on_create_new)},
- {"NewBlank", "text-x-generic", N_("Blank FIle"), NULL, NULL, G_CALLBACK(on_create_new)},
+ {"NewBlank", "text-x-generic", N_("Blank File"), NULL, NULL, G_CALLBACK(on_create_new)},
{"Prop", GTK_STOCK_PROPERTIES, NULL, NULL, NULL, G_CALLBACK(on_prop)}
};
diff --git a/src/main-win.c b/src/main-win.c
index 2b627ba..8ee299c 100644
--- a/src/main-win.c
+++ b/src/main-win.c
@@ -466,6 +466,58 @@ static void on_places_chdir(FmPlacesView* view, guint button, FmPath* path, FmMa
fm_main_win_chdir(win, path);
}
+static void fm_template_add_item(FmMainWin *self, GtkActionGroup* act_grp, GList* l)
+{
+ GtkAction *act;
+ char* name = ((FmFileInfo*)l->data)->disp_name;
+ act = gtk_action_new (name, N_(name), 0,0);
+ gtk_action_group_add_action(act_grp, act);
+ g_signal_connect(act, "activate", on_create_new, &self->parent);
+ gtk_ui_manager_add_ui(self->ui, gtk_ui_manager_new_merge_id(self->ui), "/popup/CreateNew", name, name, GTK_UI_MANAGER_MENUITEM, FALSE);
+}
+
+static void fm_templates_load(FmFolder* folder, FmMainWin *self)
+{
+ GList *l;
+ GtkActionGroup *act_grp;
+
+ act_grp = gtk_action_group_new("Templates");
+
+ gtk_ui_manager_insert_action_group(self->ui, act_grp, 0);
+
+ for(l=fm_list_peek_head_link( fm_folder_get_files(folder) );l;l=l->next)
+ if(!fm_file_info_is_dir(l->data))
+ fm_template_add_item(self, act_grp, l);
+}
+/*
+static void fm_templates_add(GList *added, FmMainWin *self)
+{
+ GList * list;
+
+ for (list = gtk_ui_manager_get_action_groups(self->ui); list!=0 ; list = list->next)
+ {
+ GtkActionGroup *act_grp = (GtkActionGroup*)list->data;
+ printf("name: %s\n", gtk_action_group_get_name(act_grp));
+ if(strcmp(gtk_action_group_get_name(act_grp),"Templates")==0)
+ {
+ for(;added!=0; added=added->next)
+ fm_template_add_item(self, act_grp, added);
+ break;
+ }
+ }
+}
+*/
+static void fm_templates_init(FmMainWin *self)
+{
+ FmFolder *folder;
+
+ folder = fm_folder_get_for_path_name(g_get_user_special_dir(G_USER_DIRECTORY_TEMPLATES));
+ g_signal_connect(folder, "loaded", fm_templates_load, self);
+// g_signal_connect(folder, "files-added", fm_templates_add, self);
+// g_signal_connect(folder, "files-removed", fm_templates_update, 0);
+
+}
+
static void fm_main_win_init(FmMainWin *self)
{
GtkWidget *vbox, *menubar, *toolitem, *scroll;
@@ -583,6 +635,8 @@ static void fm_main_win_init(FmMainWin *self)
g_object_unref(act_grp);
self->ui = ui;
+ fm_templates_init(self);
+
gtk_container_add( (GtkContainer*)self, vbox );
gtk_widget_show_all(vbox);
diff --git a/src/pcmanfm.c b/src/pcmanfm.c
index 5daa97d..072e2ab 100644
--- a/src/pcmanfm.c
+++ b/src/pcmanfm.c
@@ -629,17 +629,19 @@ void pcmanfm_create_new(GtkWindow* parent, FmPath* cwd, const char* templ)
GError* err = NULL;
FmPath* dest;
char* basename;
+ GFile* gf;
_retry:
- basename = fm_get_user_input(parent, _("Create New..."), _("Enter a name for the newly created file:"), _("New"));
+ basename = fm_get_user_input(parent, _("Create New..."), _("Enter a name for the newly created file:"), _(templ));
if(!basename)
return;
dest = fm_path_new_child(cwd, basename);
g_free(basename);
+ gf = fm_path_to_gfile(dest);
+
if( templ == TEMPL_NAME_FOLDER )
{
- GFile* gf = fm_path_to_gfile(dest);
if(!g_file_make_directory(gf, NULL, &err))
{
if(err->domain == G_IO_ERROR && err->code == G_IO_ERROR_EXISTS)
@@ -663,11 +665,9 @@ _retry:
* the folder model now. */
/* fm_folder_view_select_file_path(fv, dest); */
}
- g_object_unref(gf);
}
else if( templ == TEMPL_NAME_BLANK )
{
- GFile* gf = fm_path_to_gfile(dest);
GFileOutputStream* f = g_file_create(gf, G_FILE_CREATE_NONE, NULL, &err);
if(f)
{
@@ -697,14 +697,21 @@ _retry:
* the folder model now. */
/* fm_folder_view_select_file_path(fv, dest); */
}
- g_object_unref(gf);
}
else /* templates in ~/Templates */
{
- FmPath* dir = fm_path_new(g_get_user_special_dir(G_USER_DIRECTORY_TEMPLATES));
- FmPath* template = fm_path_new_child(dir, templ);
- fm_copy_file(template, cwd);
- fm_path_unref(template);
+ FmPath *dir, *template_path;
+ GFile* src;
+
+ dir = fm_path_new(g_get_user_special_dir(G_USER_DIRECTORY_TEMPLATES));
+ template_path = fm_path_new_child(dir, templ);
+ src = fm_path_to_gfile(template_path);
+
+ if(!g_file_copy(src, gf, G_FILE_COPY_ALL_METADATA, 0,0,0,0))
+ fm_show_error(parent, _("Error creating template"));
+
+ fm_path_unref(template_path);
}
+ g_object_unref(gf);
fm_path_unref(dest);
}
diff --git a/src/pcmanfm.h b/src/pcmanfm.h
index 649b424..a7f1e40 100644
--- a/src/pcmanfm.h
+++ b/src/pcmanfm.h
@@ -41,8 +41,8 @@ void pcmanfm_save_config();
void pcmanfm_open_folder_in_terminal(GtkWindow* parent, FmPath* dir);
-#define TEMPL_NAME_FOLDER NULL
-#define TEMPL_NAME_BLANK (const char*)-1
+#define TEMPL_NAME_FOLDER "New Folder"
+#define TEMPL_NAME_BLANK "New File"
void pcmanfm_create_new(GtkWindow* parent, FmPath* cwd, const char* templ);
G_END_DECLS
--
1.7.0.4
------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
lucky parental unit. See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Pcmanfm-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pcmanfm-develop