r40: Changed MIME system slightly - now uses MIME-open, MIME-icons, etc.
[rox-filer.git] / ROX-Filer / src / newdir.c
blob1721e0afc24ac75745229c687ebcb18acc19b6fd
1 /* vi: set cindent:
2 * $Id$
4 * ROX-Filer, filer for the ROX desktop project
5 * By Thomas Leonard, <tal197@ecs.soton.ac.uk>.
6 */
8 /* newdir.c - code for handling creation of new directories */
10 #include <sys/stat.h>
11 #include <sys/types.h>
12 #include <fcntl.h>
13 #include <unistd.h>
14 #include <errno.h>
16 #include <glib.h>
17 #include <gtk/gtk.h>
19 #include "gui_support.h"
20 #include "newdir.h"
21 #include "filer.h"
23 static GtkWidget *window, *pathname_entry;
24 static FilerWindow *filer_window;
26 /* Static prototypes */
27 static void create_dir(GtkWidget *widget, gpointer data);
29 void newdir_init()
31 GtkWidget *table, *label, *sep;
32 GtkWidget *button;
34 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
35 gtk_window_set_default_size(GTK_WINDOW(window), 300, 0);
36 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_MOUSE);
37 gtk_window_set_title(GTK_WINDOW(window), "Create directory");
38 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
39 GTK_SIGNAL_FUNC(hide_dialog_event), window);
40 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
42 table = gtk_table_new(4, 2, TRUE);
43 gtk_container_add(GTK_CONTAINER(window), table);
45 label = gtk_label_new("Create new directory:");
46 gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 2, 0, 1);
48 pathname_entry = gtk_entry_new();
49 gtk_table_attach_defaults(GTK_TABLE(table),
50 pathname_entry, 0, 2, 1, 2);
51 gtk_signal_connect(GTK_OBJECT(pathname_entry), "activate",
52 GTK_SIGNAL_FUNC(create_dir), NULL);
54 sep = gtk_hseparator_new();
55 gtk_table_attach_defaults(GTK_TABLE(table), sep, 0, 2, 2, 3);
57 button = gtk_button_new_with_label("Create");
58 gtk_table_attach_defaults(GTK_TABLE(table), button, 0, 1, 3, 4);
59 gtk_signal_connect(GTK_OBJECT(button), "clicked",
60 GTK_SIGNAL_FUNC(create_dir), NULL);
62 button = gtk_button_new_with_label("Cancel");
63 gtk_table_attach_defaults(GTK_TABLE(table), button, 1, 2, 3, 4);
64 gtk_signal_connect_object(GTK_OBJECT(button), "clicked",
65 GTK_SIGNAL_FUNC(gtk_widget_hide), GTK_OBJECT(window));
68 void newdir_show(FilerWindow *fw)
70 GString *path = NULL;
72 filer_window = fw;
74 if (GTK_WIDGET_MAPPED(window))
75 gtk_widget_hide(window);
77 if (!path)
78 path = g_string_new(NULL);
80 g_string_sprintf(path, "%s/", filer_window->path);
82 gtk_entry_set_text(GTK_ENTRY(pathname_entry), path->str);
84 gtk_widget_grab_focus(pathname_entry);
85 gtk_widget_show_all(window);
88 static void create_dir(GtkWidget *widget, gpointer data)
90 char *path;
92 path = gtk_entry_get_text(GTK_ENTRY(pathname_entry));
94 if (mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO))
95 report_error("mkdir", g_strerror(errno));
96 else
98 gtk_widget_hide(window);
99 scan_dir(filer_window);