Merge branch '30_external_clipboard_utility'

* 30_external_clipboard_utility:
  updated man's mc.1, ru/mc.1.
  Ticket #30 (use external clipboard utility)
This commit is contained in:
Ilia Maslakov 2010-06-11 14:11:27 +00:00
commit 781706ef9c
11 changed files with 163 additions and 3 deletions

View File

@ -1,5 +1,5 @@
.\"TOPICS "Topics:" .\"TOPICS "Topics:"
.TH MC 1 "August 2009" "MC Version 4.7.0\-pre1" "GNU Midnight Commander" .TH MC 1 "June 2010" "MC Version 4.7.3" "GNU Midnight Commander"
.\"SKIP_SECTION" .\"SKIP_SECTION"
.SH "NAME" .SH "NAME"
mc \- Visual shell for Unix\-like systems. mc \- Visual shell for Unix\-like systems.
@ -3970,6 +3970,22 @@ contents of the selected directory.
This variable holds the lifetime of a directory cache entry in seconds. The This variable holds the lifetime of a directory cache entry in seconds. The
default value is 900 seconds. default value is 900 seconds.
.TP .TP
.I clipbord_store
This variable contains path (with options) to the external clipboard
utility like 'xclip' to read text into X selection from file.
For example:
.PP
.nf
clipbord_store=xclip \-i
.TP
.I clipbord_paste
This variable contains path (with options) to the external clipboard
utility like 'xclip' to print the selection to standard out.
For example:
.PP
.nf
clipbord_store=xclip \-o
.TP
.I autodetect_codeset .I autodetect_codeset
This option allows use the `enca' command to autodetect codeset of text files This option allows use the `enca' command to autodetect codeset of text files
in internal viewer and editor. List of valid values can be obtain by the in internal viewer and editor. List of valid values can be obtain by the

View File

@ -1,6 +1,6 @@
.\"TOPICS "Разделы помощи:" .\"TOPICS "Разделы помощи:"
.\" TODO: Перевести раздел EXTernal File System .\" TODO: Перевести раздел EXTernal File System
.TH MC 1 "Сентябрь 2009" "MC Version 4.7.0-pre2" "GNU Midnight Commander" .TH MC 1 "Июнь 2010" "MC Version 4.7.3" "GNU Midnight Commander"
.\"SKIP_SECTION" .\"SKIP_SECTION"
.SH "НАИМЕНОВАНИЕ" .SH "НАИМЕНОВАНИЕ"
mc \- Визуальная оболочка для Unix\-подобных систем. mc \- Визуальная оболочка для Unix\-подобных систем.
@ -4266,6 +4266,24 @@ mc.ext\&.
Если эта переменная включена (по умолчанию она отключена), то при Если эта переменная включена (по умолчанию она отключена), то при
просмотре в одной из панелей структуры дерева каталогов во второй панели просмотре в одной из панелей структуры дерева каталогов во второй панели
автоматически будет отображаться список файлов выбранного каталога. автоматически будет отображаться список файлов выбранного каталога.
.TP
.I clipbord_store
Эта переменная позволяет назначить внешнюю программу (с параметрами) для
работы с буфером обмена, такую как 'xclip', для вставки данных в системный
буфер обмена.
Например:
.PP
.nf
clipbord_store=xclip \-i
.TP
.I clipbord_paste
Эта переменная позволяет назначить внешнюю программу (с параметрами) для
работы с буфером обмена, такую как 'xclip', для получения данных из системного
буфера обмена.
Например:
.PP
.nf
clipbord_store=xclip \-o
.PP .PP
.I autodetect_codeset .I autodetect_codeset
.IP .IP

View File

@ -87,6 +87,7 @@ mc_SOURCES = \
boxes.c boxes.h \ boxes.c boxes.h \
chmod.c chmod.h \ chmod.c chmod.h \
chown.c chown.h \ chown.c chown.h \
clipboard.c clipboard.h \
cmd.c cmd.h \ cmd.c cmd.h \
command.c command.h \ command.c command.h \
complete.c \ complete.c \

80
src/clipboard.c Normal file
View File

@ -0,0 +1,80 @@
/*
Util for external clipboard.
Copyright (C) 2009 The Free Software Foundation, Inc.
Written by:
Ilia Maslakon <il.smind@gmail.com>, 2010.
This file is part of the Midnight Commander.
The Midnight Commander is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Midnight Commander is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include "lib/global.h"
#include "lib/fileloc.h"
#include "main.h"
#include "src/execute.h"
#include "clipboard.h"
gboolean
copy_file_to_ext_clip (void)
{
char *tmp, *cmd;
int res = 0;
const char *d = getenv ("DISPLAY");
if (d == NULL || clipbord_store_path == NULL || clipbord_store_path[0] =='\0')
return FALSE;
tmp = concat_dir_and_file (home_dir, EDIT_CLIP_FILE);
cmd = g_strconcat (clipbord_store_path, " ", tmp, " 2>/dev/null", (char *) NULL);
if (cmd != NULL)
res = my_system (EXECUTE_AS_SHELL, shell, cmd);
g_free (cmd);
g_free (tmp);
return TRUE;
}
gboolean
paste_to_file_from_ext_clip (void)
{
char *tmp, *cmd;
int res = 0;
const char *d = getenv ("DISPLAY");
if (d == NULL || clipbord_paste_path == NULL || clipbord_paste_path[0] == '\0')
return FALSE;
tmp = concat_dir_and_file (home_dir, EDIT_CLIP_FILE);
cmd = g_strconcat (clipbord_paste_path, " > ", tmp, " 2>/dev/null", (char *) NULL);
if (cmd != NULL)
res = my_system (EXECUTE_AS_SHELL, shell, cmd);
g_free (cmd);
g_free (tmp);
return TRUE;
}

12
src/clipboard.h Normal file
View File

@ -0,0 +1,12 @@
/** \file clipboard.h
* \brief Header: Util for external clipboard
*/
#ifndef MC_CLIPBOARD_H
#define MC_CLIPBOARD_H
gboolean copy_file_to_ext_clip (void);
gboolean paste_to_file_from_ext_clip (void);
#endif

View File

@ -62,6 +62,7 @@
#include "src/charsets.h" #include "src/charsets.h"
#include "src/selcodepage.h" #include "src/selcodepage.h"
#include "src/cmddef.h" #include "src/cmddef.h"
#include "src/clipboard.h" /* copy_file_to_ext_clip, paste_to_file_from_ext_clip */
#include "src/editor/edit-impl.h" #include "src/editor/edit-impl.h"
#include "src/editor/editlock.h" #include "src/editor/editlock.h"
@ -2165,7 +2166,6 @@ edit_save_block_to_clip_file (WEdit * edit, long start, long finish)
return ret; return ret;
} }
void void
edit_paste_from_history (WEdit * edit) edit_paste_from_history (WEdit * edit)
{ {
@ -2185,6 +2185,9 @@ edit_copy_to_X_buf_cmd (WEdit * edit)
get_sys_error (_("Unable to save to file"))); get_sys_error (_("Unable to save to file")));
return 1; return 1;
} }
/* try use external clipboard utility */
copy_file_to_ext_clip ();
edit_mark_cmd (edit, 1); edit_mark_cmd (edit, 1);
return 0; return 0;
} }
@ -2200,6 +2203,9 @@ edit_cut_to_X_buf_cmd (WEdit * edit)
edit_error_dialog (_("Cut to clipboard"), _("Unable to save to file")); edit_error_dialog (_("Cut to clipboard"), _("Unable to save to file"));
return 1; return 1;
} }
/* try use external clipboard utility */
copy_file_to_ext_clip ();
edit_block_delete_cmd (edit); edit_block_delete_cmd (edit);
edit_mark_cmd (edit, 1); edit_mark_cmd (edit, 1);
return 0; return 0;
@ -2209,6 +2215,8 @@ void
edit_paste_from_X_buf_cmd (WEdit * edit) edit_paste_from_X_buf_cmd (WEdit * edit)
{ {
gchar *tmp; gchar *tmp;
/* try use external clipboard utility */
paste_to_file_from_ext_clip ();
tmp = concat_dir_and_file (home_dir, EDIT_CLIP_FILE); tmp = concat_dir_and_file (home_dir, EDIT_CLIP_FILE);
edit_insert_file (edit, tmp); edit_insert_file (edit, tmp);
g_free (tmp); g_free (tmp);

View File

@ -797,3 +797,4 @@ regex_command (const char *filename, const char *action, int *move_dir)
return -1; return -1;
return ret; return ret;
} }

View File

@ -256,6 +256,10 @@ int boot_current_is_left = 1;
*/ */
int xtree_mode = 0; int xtree_mode = 0;
/* path to X clipboard utility */
char* clipbord_store_path = NULL;
char* clipbord_paste_path = NULL;
/* If set, then print to the given file the last directory we were at */ /* If set, then print to the given file the last directory we were at */
static char *last_wd_string = NULL; static char *last_wd_string = NULL;
/* Set to 1 to suppress printing the last directory */ /* Set to 1 to suppress printing the last directory */
@ -2212,6 +2216,9 @@ main (int argc, char *argv[])
free_codepages_list (); free_codepages_list ();
g_free (autodetect_codeset); g_free (autodetect_codeset);
#endif #endif
g_free (clipbord_store_path);
g_free (clipbord_paste_path);
str_uninit_strings (); str_uninit_strings ();
g_free (mc_run_param0); g_free (mc_run_param0);

View File

@ -69,6 +69,9 @@ extern int eight_bit_clean;
extern int full_eight_bits; extern int full_eight_bits;
#endif /* !HAVE_CHARSET */ #endif /* !HAVE_CHARSET */
extern char* clipbord_store_path;
extern char* clipbord_paste_path;
extern int utf8_display; extern int utf8_display;
extern int fast_refresh; extern int fast_refresh;

View File

@ -827,6 +827,8 @@ load_setup (void)
if (buffer != NULL) if (buffer != NULL)
utf8_display = str_isutf8 (buffer); utf8_display = str_isutf8 (buffer);
#endif /* HAVE_CHARSET */ #endif /* HAVE_CHARSET */
clipbord_store_path = mc_config_get_string (mc_main_config, "Misc", "clipboard_store", "");
clipbord_paste_path = mc_config_get_string (mc_main_config, "Misc", "clipboard_paste", "");
} }
gboolean gboolean
@ -858,6 +860,9 @@ save_setup (void)
get_codepage_id (default_source_codepage)); get_codepage_id (default_source_codepage));
mc_config_set_string (mc_main_config, "Misc", "autodetect_codeset", autodetect_codeset); mc_config_set_string (mc_main_config, "Misc", "autodetect_codeset", autodetect_codeset);
#endif /* HAVE_CHARSET */ #endif /* HAVE_CHARSET */
mc_config_set_string (mc_main_config, "Misc", "clipboard_store", clipbord_store_path);
mc_config_set_string (mc_main_config, "Misc", "clipboard_paste", clipbord_paste_path);
tmp_profile = g_build_filename (home_dir, MC_USERCONF_DIR, MC_CONFIG_FILE, NULL); tmp_profile = g_build_filename (home_dir, MC_USERCONF_DIR, MC_CONFIG_FILE, NULL);
ret = mc_config_save_to_file (mc_main_config, tmp_profile, NULL); ret = mc_config_save_to_file (mc_main_config, tmp_profile, NULL);

View File

@ -61,6 +61,7 @@
#include "panel.h" /* current_panel */ #include "panel.h" /* current_panel */
#include "main.h" /* confirm_history_cleanup */ #include "main.h" /* confirm_history_cleanup */
#include "setup.h" /* num_history_items_recorded */ #include "setup.h" /* num_history_items_recorded */
#include "clipboard.h" /* copy_file_to_ext_clip, paste_to_file_from_ext_clip */
static void static void
widget_selectcolor (Widget * w, gboolean focused, gboolean hotkey) widget_selectcolor (Widget * w, gboolean focused, gboolean hotkey)
@ -1824,6 +1825,8 @@ copy_region (WInput * in, int x_first, int x_last)
{ {
/* Copy selected files to clipboard */ /* Copy selected files to clipboard */
panel_save_curent_file_to_clip_file (); panel_save_curent_file_to_clip_file ();
/* try use external clipboard utility */
copy_file_to_ext_clip ();
return; return;
} }
@ -1833,7 +1836,10 @@ copy_region (WInput * in, int x_first, int x_last)
last = str_offset_to_pos (in->buffer, last); last = str_offset_to_pos (in->buffer, last);
kill_buffer = g_strndup (in->buffer + first, last - first); kill_buffer = g_strndup (in->buffer + first, last - first);
save_text_to_clip_file (kill_buffer); save_text_to_clip_file (kill_buffer);
/* try use external clipboard utility */
copy_file_to_ext_clip ();
} }
static void static void
@ -1922,6 +1928,9 @@ ins_from_clip (WInput * in)
{ {
char *p = NULL; char *p = NULL;
/* try use external clipboard utility */
paste_to_file_from_ext_clip ();
if (load_text_from_clip_file (&p)) if (load_text_from_clip_file (&p))
{ {
char *pp; char *pp;