diff --git a/edit/edit.c b/edit/edit.c index bb9fc29f0..dd9f65e4e 100644 --- a/edit/edit.c +++ b/edit/edit.c @@ -2790,7 +2790,7 @@ edit_execute_cmd (WEdit *edit, int command, int char_for_insertion) edit_save_confirm_cmd (edit); break; case CK_Load: - edit_load_cmd (edit); + edit_load_cmd (edit, EDIT_FILE_COMMON); break; case CK_Save_Block: edit_save_block_cmd (edit); @@ -2806,6 +2806,13 @@ edit_execute_cmd (WEdit *edit, int command, int char_for_insertion) edit_load_forward_cmd (edit); break; + case CK_Load_Syntax_File: + edit_load_cmd (edit, EDIT_FILE_SYNTAX); + break; + case CK_Load_Menu_File: + edit_load_cmd (edit, EDIT_FILE_MENU); + break; + case CK_Toggle_Syntax: if ((option_syntax_highlighting ^= 1) == 1) edit_load_syntax (edit, NULL, option_syntax_type); diff --git a/edit/edit.h b/edit/edit.h index a4fddec33..1de657a14 100644 --- a/edit/edit.h +++ b/edit/edit.h @@ -126,6 +126,13 @@ struct WEdit; typedef struct WEdit WEdit; struct Menu; +/* type for file which is currently being edited */ +typedef enum { + EDIT_FILE_COMMON = 0, + EDIT_FILE_SYNTAX = 1, + EDIT_FILE_MENU = 2 +} edit_current_file_t; + int edit_drop_hotkey_menu (WEdit *e, int key); void edit_menu_cmd (WEdit *e); struct WMenu *edit_create_menu (void); @@ -185,7 +192,7 @@ int edit_ok_to_exit (WEdit *edit); int edit_renew (WEdit * edit); int edit_new_cmd (WEdit * edit); int edit_reload (WEdit *edit, const char *filename); -int edit_load_cmd (WEdit * edit); +int edit_load_cmd (WEdit * edit, edit_current_file_t what); void edit_mark_cmd (WEdit * edit, int unmark); void edit_set_markers (WEdit * edit, long m1, long m2, int c1, int c2); void edit_push_markers (WEdit * edit); @@ -335,4 +342,9 @@ extern int visible_tws; #define BLOCK_FILE EDIT_DIR PATH_SEP_STR "cooledit.block" #define TEMP_FILE EDIT_DIR PATH_SEP_STR "cooledit.temp" +#define CEDIT_GLOBAL_MENU "cedit.menu" +#define CEDIT_LOCAL_MENU ".cedit.menu" +#define CEDIT_HOME_MENU ".mc" PATH_SEP_STR "cedit" PATH_SEP_STR "menu" + + #endif diff --git a/edit/editcmd.c b/edit/editcmd.c index e09cd1b63..4cb44b63a 100644 --- a/edit/editcmd.c +++ b/edit/editcmd.c @@ -803,30 +803,113 @@ edit_load_file_from_filename (WEdit * edit, char *exp) return 0; } +static void +edit_load_syntax_file (WEdit * edit) +{ + char *extdir; + int dir = 0; + + if (geteuid () == 0) { + dir = query_dialog (_("Syntax file edit"), + _(" Which syntax file you want to edit? "), D_NORMAL, 2, + _("&User"), _("&System Wide")); + } + extdir = concat_dir_and_file (mc_home, "syntax" PATH_SEP_STR "Syntax"); + + if (dir == 0) { + char *buffer; + + buffer = concat_dir_and_file (home_dir, SYNTAX_FILE); + check_for_default (extdir, buffer); + edit_load_file_from_filename (edit, buffer); + g_free (buffer); + } else if (dir == 1) + edit_load_file_from_filename (edit, extdir); + + g_free (extdir); +} + +static void +edit_load_menu_file (WEdit * edit) +{ + char *buffer; + char *menufile; + int dir = 0; + + dir = query_dialog ( + _(" Menu edit "), + _(" Which menu file do you want to edit? "), D_NORMAL, + geteuid() ? 2 : 3, _("&Local"), _("&User"), _("&System Wide") + ); + + menufile = concat_dir_and_file (mc_home, CEDIT_GLOBAL_MENU); + + switch (dir) { + case 0: + buffer = g_strdup (CEDIT_LOCAL_MENU); + check_for_default (menufile, buffer); + chmod (buffer, 0600); + break; + + case 1: + buffer = concat_dir_and_file (home_dir, CEDIT_HOME_MENU); + check_for_default (menufile, buffer); + break; + + case 2: + buffer = concat_dir_and_file (mc_home, CEDIT_GLOBAL_MENU); + break; + + default: + g_free (menufile); + return; + } + + edit_load_file_from_filename (edit, buffer); + + g_free (buffer); + g_free (menufile); +} + int -edit_load_cmd (WEdit *edit) +edit_load_cmd (WEdit *edit, edit_current_file_t what) { char *exp; - if (edit->modified) { - if (edit_query_dialog2 + if (edit->modified + && (edit_query_dialog2 (_("Warning"), _(" Current text was modified without a file save. \n" - " Continue discards these changes. "), _("C&ontinue"), - _("&Cancel"))) { + " Continue discards these changes. "), + _("C&ontinue"), _("&Cancel")) == 1)) { edit->force |= REDRAW_COMPLETELY; return 0; } + + switch (what) { + case EDIT_FILE_COMMON: + exp = input_expand_dialog (_(" Load "), _(" Enter file name: "), + MC_HISTORY_EDIT_LOAD, edit->filename); + + if (exp) { + if (*exp) + edit_load_file_from_filename (edit, exp); + g_free (exp); + } + break; + + case EDIT_FILE_SYNTAX: + edit_load_syntax_file (edit); + break; + + case EDIT_FILE_MENU: + edit_load_menu_file (edit); + break; + + default: + break; } - exp = input_expand_dialog (_(" Load "), _(" Enter file name: "), - MC_HISTORY_EDIT_LOAD, edit->filename); - - if (exp) { - if (*exp) - edit_load_file_from_filename (edit, exp); - g_free (exp); - } edit->force |= REDRAW_COMPLETELY; return 0; } diff --git a/edit/editcmddef.h b/edit/editcmddef.h index ca0eb1896..0127029e3 100644 --- a/edit/editcmddef.h +++ b/edit/editcmddef.h @@ -50,6 +50,8 @@ #define CK_Save_As 104 #define CK_Load_Prev_File 111 #define CK_Load_Next_File 112 +#define CK_Load_Syntax_File 121 +#define CK_Load_Menu_File 122 /* block commands */ #define CK_Mark 201 diff --git a/edit/editmenu.c b/edit/editmenu.c index 0340d8bb6..87fe1a19b 100644 --- a/edit/editmenu.c +++ b/edit/editmenu.c @@ -45,7 +45,7 @@ #include "../src/global.h" #include "edit.h" -#include "../src/cmd.h" /* save_setup_cmd() */ +#include "../src/cmd.h" #include "../src/wtools.h" /* query_dialog() */ #include "../src/menu.h" /* menu_entry */ #include "../src/tty.h" /* KEY_F */ @@ -290,15 +290,15 @@ menu_format_paragraph (void) } static void -menu_options (void) +menu_edit_syntax_file_cmd (void) { - edit_options_dialog (); + menu_cmd (CK_Load_Syntax_File); } static void -menu_syntax (void) +menu_edit_menu_file_cmd (void) { - edit_syntax_dialog (); + menu_cmd (CK_Load_Menu_File); } static void @@ -423,12 +423,14 @@ static menu_entry CmdMenuEmacs[] = static menu_entry OptMenu[] = { - {' ', N_("&General... "), NULL_HOTKEY, menu_options}, + {' ', N_("&General... "), NULL_HOTKEY, edit_options_dialog}, {' ', N_("&Save mode..."), NULL_HOTKEY, menu_save_mode_cmd}, {' ', N_("Learn &Keys..."), NULL_HOTKEY, learn_keys}, - {' ', N_("Syntax &Highlighting..."), NULL_HOTKEY, menu_syntax}, + {' ', N_("Syntax &Highlighting..."), NULL_HOTKEY, edit_syntax_dialog}, + {' ', N_("S&yntax file"), NULL_HOTKEY, menu_edit_syntax_file_cmd}, + {' ', N_("&Menu file"), NULL_HOTKEY, menu_edit_menu_file_cmd}, {' ', "", NULL_HOTKEY, 0}, - {' ', N_("Save setu&p..."), NULL_HOTKEY, save_setup_cmd} + {' ', N_("Save setu&p"), NULL_HOTKEY, save_setup_cmd} }; #define OptMenuEmacs OptMenu diff --git a/src/cmd.c b/src/cmd.c index d9c95c43c..3d521dbc7 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -42,8 +42,8 @@ #include "global.h" #include "cmd.h" /* Our definitions */ -#include "fileopctx.h" /* file_op_context_new() */ -#include "file.h" /* file operation routines */ +#include "fileopctx.h" +#include "file.h" /* file operation routines */ #include "find.h" /* do_find() */ #include "hotlist.h" /* hotlist_cmd() */ #include "tree.h" /* tree_chdir() */ @@ -570,28 +570,6 @@ void unselect_cmd (void) select_unselect_cmd (_(" Unselect "), ":unselect_cmd: Unselect ", FALSE); } -/* Check if the file exists */ -/* If not copy the default */ -static int -check_for_default(char *default_file, char *file) -{ - struct stat s; - off_t count = 0; - double bytes = 0; - FileOpContext *ctx; - - if (mc_stat (file, &s)){ - if (mc_stat (default_file, &s)){ - return -1; - } - ctx = file_op_context_new (OP_COPY); - file_op_context_create_ui (ctx, 0); - copy_file_file (ctx, default_file, file, 1, &count, &bytes, 1); - file_op_context_destroy (ctx); - } - return 0; -} - void ext_cmd (void) { char *buffer; @@ -622,59 +600,6 @@ void ext_cmd (void) flush_extension_file (); } -/* where = 0 - do edit file menu for mc */ -/* where = 1 - do edit file menu for mcedit */ -static void -menu_edit_cmd (int where) -{ - char *buffer; - char *menufile; - int dir = 0; - - dir = query_dialog ( - _(" Menu edit "), - _(" Which menu file do you want to edit? "), - D_NORMAL, geteuid() ? 2 : 3, - _("&Local"), _("&User"), _("&System Wide") - ); - - menufile = concat_dir_and_file (mc_home, where ? CEDIT_GLOBAL_MENU : MC_GLOBAL_MENU); - - if (!exist_file(menufile)) { - g_free (menufile); - menufile = concat_dir_and_file (mc_home_alt, where ? CEDIT_GLOBAL_MENU : MC_GLOBAL_MENU); - } - - switch (dir) { - case 0: - buffer = g_strdup (where ? CEDIT_LOCAL_MENU : MC_LOCAL_MENU); - check_for_default (menufile, buffer); - break; - - case 1: - buffer = concat_dir_and_file (home_dir, where ? CEDIT_HOME_MENU : MC_HOME_MENU); - check_for_default (menufile, buffer); - break; - - case 2: - buffer = concat_dir_and_file (mc_home, where ? CEDIT_GLOBAL_MENU : MC_GLOBAL_MENU); - if (!exist_file(buffer)) { - g_free (buffer); - buffer = concat_dir_and_file (mc_home_alt, where ? CEDIT_GLOBAL_MENU : MC_GLOBAL_MENU); - } - break; - - default: - g_free (menufile); - return; - } - do_edit (buffer); - if (dir == 0) - chmod(buffer, 0600); - g_free (buffer); - g_free (menufile); -} - void quick_chdir_cmd (void) { char *target; @@ -694,45 +619,71 @@ void quick_chdir_cmd (void) /* edit file menu for mc */ void edit_mc_menu_cmd (void) -{ - menu_edit_cmd (0); -} - -#ifdef USE_INTERNAL_EDIT -/* edit file menu for mcedit */ -void -edit_user_menu_cmd (void) -{ - menu_edit_cmd (1); -} - -/* edit syntax file for mcedit */ -void -edit_syntax_cmd (void) { char *buffer; - char *extdir; + char *menufile; int dir = 0; - if (geteuid () == 0) { - dir = - query_dialog (_("Syntax file edit"), - _(" Which syntax file you want to edit? "), D_NORMAL, 2, - _("&User"), _("&System Wide")); + dir = query_dialog ( + _(" Menu edit "), + _(" Which menu file do you want to edit? "), + D_NORMAL, geteuid() ? 2 : 3, + _("&Local"), _("&User"), _("&System Wide") + ); + + menufile = concat_dir_and_file (mc_home, MC_GLOBAL_MENU); + + if (!exist_file(menufile)) { + g_free (menufile); + menufile = concat_dir_and_file (mc_home_alt, MC_GLOBAL_MENU); } - extdir = concat_dir_and_file (mc_home_alt, "syntax" PATH_SEP_STR "Syntax"); - if (dir == 0) { - buffer = concat_dir_and_file (home_dir, SYNTAX_FILE); - check_for_default (extdir, buffer); - do_edit (buffer); - g_free (buffer); - } else if (dir == 1) - do_edit (extdir); + switch (dir) { + case 0: + buffer = g_strdup (MC_LOCAL_MENU); + check_for_default (menufile, buffer); + chmod (buffer, 0600); + break; - g_free (extdir); + case 1: + buffer = concat_dir_and_file (home_dir, MC_HOME_MENU); + check_for_default (menufile, buffer); + break; + + case 2: + buffer = concat_dir_and_file (mc_home, MC_GLOBAL_MENU); + if (!exist_file(buffer)) { + g_free (buffer); + buffer = concat_dir_and_file (mc_home_alt, MC_GLOBAL_MENU); + } + break; + + default: + g_free (menufile); + return; + } + + do_edit (buffer); + + g_free (buffer); + g_free (menufile); +} + +void quick_chdir_cmd (void) +{ + char *target; + + target = hotlist_cmd (LIST_HOTLIST); + if (!target) + return; + + if (get_current_type () == view_tree) + tree_chdir (the_tree, target); + else + if (!do_cd (target, cd_exact)) + message (D_ERROR, MSG_ERROR, _("Cannot change directory") ); + g_free (target); } -#endif #ifdef USE_VFS void reselect_vfs (void) diff --git a/src/cmd.h b/src/cmd.h index 25fc25393..749d9191c 100644 --- a/src/cmd.h +++ b/src/cmd.h @@ -39,8 +39,6 @@ void filter_cmd (void); void reread_cmd (void); void ext_cmd (void); void edit_mc_menu_cmd (void); -void edit_user_menu_cmd (void); -void edit_syntax_cmd (void); void quick_chdir_cmd (void); void compare_dirs_cmd (void); void history_cmd (void); diff --git a/src/main.c b/src/main.c index 20a674894..9272b9849 100644 --- a/src/main.c +++ b/src/main.c @@ -875,7 +875,6 @@ static menu_entry RightMenu[] = { }; static menu_entry FileMenu[] = { - {' ', N_("&User menu F2"), NULL_HOTKEY, user_file_menu_cmd}, {' ', N_("&View F3"), NULL_HOTKEY, view_cmd}, {' ', N_("Vie&w file... "), NULL_HOTKEY, view_file_cmd}, {' ', N_("&Filtered view M-!"), NULL_HOTKEY, filtered_view_cmd}, @@ -900,6 +899,7 @@ static menu_entry FileMenu[] = { }; static menu_entry CmdMenu[] = { + {' ', N_("&User menu F2"), NULL_HOTKEY, user_file_menu_cmd}, /* I know, I'm lazy, but the tree widget when it's not running * as a panel still has some problems, I have not yet finished * the WTree widget port, sorry. @@ -931,11 +931,7 @@ static menu_entry CmdMenu[] = { {' ', "", NULL_HOTKEY, 0}, #endif {' ', N_("Edit &extension file"), NULL_HOTKEY, ext_cmd}, - {' ', N_("Edit &menu file"), NULL_HOTKEY, edit_mc_menu_cmd}, -#ifdef USE_INTERNAL_EDIT - {' ', N_("Edit edi&tor menu file"), NULL_HOTKEY, edit_user_menu_cmd}, - {' ', N_("Edit &syntax file"), NULL_HOTKEY, edit_syntax_cmd} -#endif /* USE_INTERNAL_EDIT */ + {' ', N_("Edit &menu file"), NULL_HOTKEY, edit_mc_menu_cmd} }; /* Must keep in sync with the constants in menu_cmd */ diff --git a/src/user.h b/src/user.h index de44b1f36..5fa63b57e 100644 --- a/src/user.h +++ b/src/user.h @@ -14,9 +14,6 @@ int check_format_view (const char *); int check_format_var (const char *, char **); int check_format_cd (const char *); -#define CEDIT_GLOBAL_MENU "cedit.menu" -#define CEDIT_LOCAL_MENU ".cedit.menu" -#define CEDIT_HOME_MENU ".mc/cedit/menu" #define MC_GLOBAL_MENU "mc.menu" #define MC_LOCAL_MENU ".mc.menu" #define MC_HOME_MENU ".mc/menu" diff --git a/src/util.c b/src/util.c index 48903b8d2..35e6622bd 100644 --- a/src/util.c +++ b/src/util.c @@ -45,6 +45,8 @@ #include "win.h" /* xterm_flag */ #include "timefmt.h" #include "strutil.h" +#include "fileopctx.h" +#include "file.h" /* copy_file_file() */ #include "../src/search/search.h" #ifdef HAVE_CHARSET @@ -501,6 +503,28 @@ exist_file (const char *name) return access (name, R_OK) == 0; } +int +check_for_default (const char *default_file, const char *file) +{ + if (!exist_file (file)) { + FileOpContext *ctx; + off_t count = 0; + double bytes = 0.0; + + if (!exist_file (default_file)) + return -1; + + ctx = file_op_context_new (OP_COPY); + file_op_context_create_ui (ctx, 0); + copy_file_file (ctx, default_file, file, 1, &count, &bytes, 1); + file_op_context_destroy (ctx); + } + + return 0; +} + + + char * load_file (const char *filename) { diff --git a/src/util.h b/src/util.h index 18f24f059..90c949cbc 100644 --- a/src/util.h +++ b/src/util.h @@ -113,6 +113,9 @@ const char *file_date (time_t); int exist_file (const char *name); +/* Check if the file exists. If not copy the default */ +int check_for_default (const char *default_file, const char *file); + /* Returns a copy of *s until a \n is found and is below top */ const char *extract_line (const char *s, const char *top);