Small reorganization of MC and Editor menus.

The 'User Menu' entry is moved from 'File' submenu to 'Command' one.
The 'Edit editor menu file' and 'Edit syntax file' entries are moved
from main MC menu ('Command' submenu) to editor main menu ('Options'
submenu) and renamed.

src/cmd.c (check_for_default): moved to util.c and maken global.
(menu_edit_cmd): rewritten to handle MC menu files only and renamed
to edit_mc_menu_cmd.
Editor relevant routines are moved to editor code.

src/cmd.h: cleanup.

src/main.c: main menu reorganization.

src/user.h: moved editor macros to edit/edit.h.

src/util.c, src/util.h: check_for_default function from src/cmd.h.
Rewritten to use exist_file() function.

edit/editcmddef.h: added new commands:
CK_Load_Syntax_File and CK_Load_Menu_File.

edit/edit.h: editor file macros from src/user.h.
New type for file which is currently being edited.
Modified edit_load_cmd function to be more advanced.

edit/edit.c (edit_execute_cmd): handle new commands:
CK_Load_Syntax_File and CK_Load_Menu_File.

edit/editmenu.c: menu reorganization: moved two entries here from main
MC menu. Added requireq handle functions. Small optimization: removed
extra layer in menu entry handlers.

edit/editcmd.c: menu and syntax files edit is implemented.
Modified edit_load_cmd function to be more advanced.
This commit is contained in:
Andrew Borodin 2009-05-21 09:13:12 +04:00
parent 9c79518b9a
commit fb48d4a295
11 changed files with 217 additions and 142 deletions

View File

@ -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);

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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

167
src/cmd.c
View File

@ -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)

View File

@ -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);

View File

@ -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 */

View File

@ -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"

View File

@ -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)
{

View File

@ -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);