Index: mousepad/src/window.c =================================================================== --- mousepad/src/window.c (revision 27277) +++ mousepad/src/window.c (working copy) @@ -21,6 +21,7 @@ */ #include "mousepad.h" +#include /*static void remove_scrollbar_spacing(GtkScrolledWindow *sw) { @@ -71,7 +72,7 @@ GtkWidget *menubar; GtkWidget *ebox; GtkWidget *label; - GtkWidget *separator; + GtkWidget *separator; GtkWidget *sw; GtkWidget *textview; GtkTextBuffer *textbuffer; @@ -92,29 +93,26 @@ menubar = create_menu_bar(window, sd); gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0); - - /* check if we need to add the root warning */ - if (G_UNLIKELY (geteuid () == 0)) - { - /* install default settings for the root warning text box */ - gtk_rc_parse_string("style\"mousepad-window-root-style\"{bg[NORMAL]=\"#b4254b\"\nfg[NORMAL]=\"#fefefe\"}\n" - "widget\"GtkWindow.*.root-warning\"style\"mousepad-window-root-style\"\n" - "widget\"GtkWindow.*.root-warning.GtkLabel\"style\"mousepad-window-root-style\"\n"); - /* add the box for the root warning */ - ebox = gtk_event_box_new(); - gtk_widget_set_name(ebox, "root-warning"); - gtk_box_pack_start(GTK_BOX(vbox), ebox, FALSE, FALSE, 0); + /* install default settings for the warning text box */ + gtk_rc_parse_string("style\"mousepad-window-warning-style\"{bg[NORMAL]=\"#b4254b\"\nfg[NORMAL]=\"#fefefe\"}\n" + "widget\"GtkWindow.*.warning\"style\"mousepad-window-warning-style\"\n" + "widget\"GtkWindow.*.warning.GtkLabel\"style\"mousepad-window-warning-style\"\n"); - /* add the label with the root warning */ - label = gtk_label_new(_("Warning, you are using the root account, you may harm your system.")); - gtk_misc_set_padding(GTK_MISC(label), 6, 3); - gtk_container_add(GTK_CONTAINER(ebox), label); + /* add the box for the warning */ + ebox = gtk_event_box_new(); + gtk_widget_set_name(ebox, "warning"); + gtk_box_pack_start(GTK_BOX(vbox), ebox, FALSE, FALSE, 0); - separator = gtk_hseparator_new(); - gtk_box_pack_start(GTK_BOX(vbox), separator, FALSE, FALSE, 0); - } + /* add the label with the warning */ + label = gtk_label_new(NULL); + gtk_misc_set_padding(GTK_MISC(label), 6, 3); + gtk_container_add(GTK_CONTAINER(ebox), label); + gtk_event_box_set_visible_window(GTK_EVENT_BOX(ebox), TRUE); + separator = gtk_hseparator_new(); + gtk_box_pack_start(GTK_BOX(vbox), separator, FALSE, FALSE, 0); + sw = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); @@ -152,10 +150,11 @@ cb_text_receive, NULL); */ mainwin->window = window; + mainwin->warning_text = label; mainwin->menubar = menubar; mainwin->textview = textview; mainwin->textbuffer = textbuffer; - + return mainwin; } @@ -191,3 +190,30 @@ g_free(title); g_free(basename); } +void main_window_update_warning(StructData *sd) +{ + gchar *text; + gchar *dir; + + text = g_malloc0(256*sizeof(gchar)); + + if (G_UNLIKELY (geteuid () == 0)) + g_strlcat(text,_("Warning, you are using the root account, you may harm your system."),128); + if (sd->fi->filename != NULL) { + dir = g_path_get_dirname (sd->fi->filename); + if ((g_access (dir, R_OK | W_OK | X_OK) < 0) || \ + g_access (sd->fi->filename, R_OK | W_OK | X_OK) < 0) { + if (G_UNLIKELY (geteuid () == 0)) + g_strlcat(text,_("\nWarning, you are editing a read-only file, you can not modify it."),256); + else + g_strlcat(text,_("Warning, you are editing a read-only file, you can not modify it."),128); + + } + g_free(dir); + } + + gtk_label_set_text(GTK_LABEL(sd->mainwin->warning_text), text); + + g_free(text); +} + Index: mousepad/src/window.h =================================================================== --- mousepad/src/window.h (revision 27277) +++ mousepad/src/window.h (working copy) @@ -25,6 +25,7 @@ MainWindow *create_main_window(StructData *sd); gchar *get_current_file_basename(gchar *filename); void set_main_window_title(StructData *sd); +void main_window_update_warning(StructData *sd); #if 0 void set_main_window_title_with_asterisk(gboolean flag); void set_main_window_title_toggle_asterisk(void); Index: mousepad/src/mousepad.h =================================================================== --- mousepad/src/mousepad.h (revision 27277) +++ mousepad/src/mousepad.h (working copy) @@ -58,6 +58,7 @@ /* Data Structure */ typedef struct { GtkWidget *window; + GtkWidget *warning_text; GtkWidget *menubar; GtkWidget *textview; GtkTextBuffer *textbuffer; Index: mousepad/src/main.c =================================================================== --- mousepad/src/main.c (revision 27277) +++ mousepad/src/main.c (working copy) @@ -210,6 +210,7 @@ sd->search.string_find = NULL; sd->search.string_replace = NULL; + main_window_update_warning(sd); gtk_main(); save_config_file(sd); Index: mousepad/src/callback.c =================================================================== --- mousepad/src/callback.c (revision 27277) +++ mousepad/src/callback.c (working copy) @@ -105,6 +105,7 @@ g_free(sd->fi); sd->fi = fi; set_main_window_title(sd); + main_window_update_warning(sd); undo_init(sd->mainwin->textview, sd->mainwin->textbuffer, sd->mainwin->menubar); } }