Add menu entry for editing filehighlight.ini (Rules for filenames highlighting)

Signed-off-by: Ilia Maslakov <il.smind@google.com>

Some fixies after patch of Ilia Maslakov.
* Fixed pathes to rules-highlight files.
* Added on-fly refresh of rules after editing.

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
Ilia Maslakov 2009-09-03 09:09:56 +00:00 committed by Slava Zanko
parent 4afc04eedc
commit 86d8c89f6a
5 changed files with 47 additions and 7 deletions

View File

@ -80,6 +80,7 @@
#include "strutil.h" #include "strutil.h"
#include "dir.h" #include "dir.h"
#include "../src/viewer/mcviewer.h" #include "../src/viewer/mcviewer.h"
#include "../src/filehighlight/fhl.h" /* MC_FHL_INI_FILE */
#ifndef MAP_FILE #ifndef MAP_FILE
# define MAP_FILE 0 # define MAP_FILE 0
@ -668,6 +669,43 @@ edit_mc_menu_cmd (void)
g_free (menufile); g_free (menufile);
} }
void edit_fhl_cmd (void)
{
char *buffer = NULL;
char *fhlfile = NULL;
char *user_mc_dir;
int dir;
dir = 0;
if (geteuid () == 0){
dir = query_dialog (_("Highlighting groups file edit"),
_(" Which highlighting file you want to edit? "), D_NORMAL, 2,
_("&User"), _("&System Wide"));
}
fhlfile = concat_dir_and_file (mc_home, MC_FHL_INI_FILE);
if (dir == 0){
user_mc_dir = concat_dir_and_file (home_dir, MC_BASE);
buffer = concat_dir_and_file (user_mc_dir, MC_FHL_INI_FILE);
g_free(user_mc_dir);
check_for_default (fhlfile, buffer);
do_edit (buffer);
g_free (buffer);
} else if (dir == 1) {
if (!exist_file(fhlfile)) {
g_free (fhlfile);
fhlfile = concat_dir_and_file (mc_home, MC_FHL_INI_FILE);
}
do_edit (fhlfile);
}
g_free (fhlfile);
/* refresh highlighting rules */
mc_fhl_free (&mc_filehighlight);
mc_filehighlight = mc_fhl_new (TRUE);
}
void quick_chdir_cmd (void) void quick_chdir_cmd (void)
{ {
char *target; char *target;

View File

@ -40,6 +40,7 @@ void filter_cmd (void);
void reread_cmd (void); void reread_cmd (void);
void ext_cmd (void); void ext_cmd (void);
void edit_mc_menu_cmd (void); void edit_mc_menu_cmd (void);
void edit_fhl_cmd (void);
void quick_chdir_cmd (void); void quick_chdir_cmd (void);
void compare_dirs_cmd (void); void compare_dirs_cmd (void);
void history_cmd (void); void history_cmd (void);

View File

@ -5,6 +5,8 @@
#include "../../src/search/search.h" #include "../../src/search/search.h"
#include "../src/dir.h" #include "../src/dir.h"
#define MC_FHL_INI_FILE "filehighlight.ini"
/*** typedefs(not structures) and defined constants **********************************************/ /*** typedefs(not structures) and defined constants **********************************************/
/*** enums ***************************************************************************************/ /*** enums ***************************************************************************************/

View File

@ -32,15 +32,13 @@
#include "../src/main.h" #include "../src/main.h"
#include "../src/strescape.h" #include "../src/strescape.h"
#include "../src/tty/color.h" #include "../src/tty/color.h"
#include "../src/filehighlight/fhl.h" #include "fhl.h"
#include "internal.h" #include "internal.h"
/*** global variables ****************************************************************************/ /*** global variables ****************************************************************************/
/*** file scope macro definitions ****************************************************************/ /*** file scope macro definitions ****************************************************************/
#define mc_fhl_INI_FILE "filehighlight.ini"
/*** file scope type declarations ****************************************************************/ /*** file scope type declarations ****************************************************************/
/*** file scope variables ************************************************************************/ /*** file scope variables ************************************************************************/
@ -229,7 +227,7 @@ mc_fhl_init_from_standart_files (mc_fhl_t * fhl)
gchar *user_mc_dir; gchar *user_mc_dir;
/* ${datadir}/mc/filehighlight.ini */ /* ${datadir}/mc/filehighlight.ini */
name = concat_dir_and_file (mc_home_alt, mc_fhl_INI_FILE); name = concat_dir_and_file (mc_home_alt, MC_FHL_INI_FILE);
if (exist_file (name) && (!mc_fhl_read_ini_file (fhl, name))) { if (exist_file (name) && (!mc_fhl_read_ini_file (fhl, name))) {
g_free (name); g_free (name);
return FALSE; return FALSE;
@ -237,7 +235,7 @@ mc_fhl_init_from_standart_files (mc_fhl_t * fhl)
g_free (name); g_free (name);
/* ${sysconfdir}/mc/filehighlight.ini */ /* ${sysconfdir}/mc/filehighlight.ini */
name = concat_dir_and_file (mc_home, mc_fhl_INI_FILE); name = concat_dir_and_file (mc_home, MC_FHL_INI_FILE);
if (exist_file (name) && (!mc_fhl_read_ini_file (fhl, name))) { if (exist_file (name) && (!mc_fhl_read_ini_file (fhl, name))) {
g_free (name); g_free (name);
return FALSE; return FALSE;
@ -246,7 +244,7 @@ mc_fhl_init_from_standart_files (mc_fhl_t * fhl)
/* ~/.mc/filehighlight.ini */ /* ~/.mc/filehighlight.ini */
user_mc_dir = concat_dir_and_file (home_dir, MC_BASE); user_mc_dir = concat_dir_and_file (home_dir, MC_BASE);
name = concat_dir_and_file (user_mc_dir, mc_fhl_INI_FILE); name = concat_dir_and_file (user_mc_dir, MC_FHL_INI_FILE);
g_free (user_mc_dir); g_free (user_mc_dir);
if (exist_file (name) && (!mc_fhl_read_ini_file (fhl, name))) { if (exist_file (name) && (!mc_fhl_read_ini_file (fhl, name))) {
g_free (name); g_free (name);

View File

@ -756,7 +756,8 @@ static menu_entry CmdMenu[] = {
{' ', "", NULL_HOTKEY, 0}, {' ', "", NULL_HOTKEY, 0},
#endif #endif
{' ', N_("Edit &extension file"), NULL_HOTKEY, ext_cmd}, {' ', N_("Edit &extension file"), NULL_HOTKEY, ext_cmd},
{' ', N_("Edit &menu file"), NULL_HOTKEY, edit_mc_menu_cmd} {' ', N_("Edit &menu file"), NULL_HOTKEY, edit_mc_menu_cmd},
{' ', N_("Edit &highlighting group file"), NULL_HOTKEY, edit_fhl_cmd}
}; };
/* Must keep in sync with the constants in menu_cmd */ /* Must keep in sync with the constants in menu_cmd */