Browse Source

Merge branch '30_external_clipboard_utility'

* 30_external_clipboard_utility:
  updated man's mc.1, ru/mc.1.
  Ticket #30 (use external clipboard utility)
Ilia Maslakov 14 years ago
parent
commit
781706ef9c
10 changed files with 154 additions and 3 deletions
  1. 17 1
      doc/man/mc.1.in
  2. 19 1
      doc/man/ru/mc.1.in
  3. 1 0
      src/Makefile.am
  4. 80 0
      src/clipboard.c
  5. 12 0
      src/clipboard.h
  6. 9 1
      src/editor/editcmd.c
  7. 1 0
      src/ext.c
  8. 7 0
      src/main.c
  9. 3 0
      src/main.h
  10. 5 0
      src/setup.c

+ 17 - 1
doc/man/mc.1.in

@@ -1,5 +1,5 @@
 .\"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"
 .SH "NAME"
 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
 default value is 900 seconds.
 .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
 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

+ 19 - 1
doc/man/ru/mc.1.in

@@ -1,6 +1,6 @@
 .\"TOPICS "Разделы помощи:"
 .\" 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"
 .SH "НАИМЕНОВАНИЕ"
 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
 .I autodetect_codeset
 .IP

+ 1 - 0
src/Makefile.am

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

+ 80 - 0
src/clipboard.c

@@ -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 - 0
src/clipboard.h

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

+ 9 - 1
src/editor/editcmd.c

@@ -62,6 +62,7 @@
 #include "src/charsets.h"
 #include "src/selcodepage.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/editlock.h"
@@ -2165,7 +2166,6 @@ edit_save_block_to_clip_file (WEdit * edit, long start, long finish)
     return ret;
 }
 
-
 void
 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")));
         return 1;
     }
+    /* try use external clipboard utility */
+    copy_file_to_ext_clip ();
+
     edit_mark_cmd (edit, 1);
     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"));
         return 1;
     }
+    /* try use external clipboard utility */
+    copy_file_to_ext_clip ();
+
     edit_block_delete_cmd (edit);
     edit_mark_cmd (edit, 1);
     return 0;
@@ -2209,6 +2215,8 @@ void
 edit_paste_from_X_buf_cmd (WEdit * edit)
 {
     gchar *tmp;
+    /* try use external clipboard utility */
+    paste_to_file_from_ext_clip ();
     tmp = concat_dir_and_file (home_dir, EDIT_CLIP_FILE);
     edit_insert_file (edit, tmp);
     g_free (tmp);

+ 1 - 0
src/ext.c

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

+ 7 - 0
src/main.c

@@ -256,6 +256,10 @@ int boot_current_is_left = 1;
  */
 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 */
 static char *last_wd_string = NULL;
 /* Set to 1 to suppress printing the last directory */
@@ -2212,6 +2216,9 @@ main (int argc, char *argv[])
     free_codepages_list ();
     g_free (autodetect_codeset);
 #endif
+    g_free (clipbord_store_path);
+    g_free (clipbord_paste_path);
+
     str_uninit_strings ();
 
     g_free (mc_run_param0);

+ 3 - 0
src/main.h

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

+ 5 - 0
src/setup.c

@@ -827,6 +827,8 @@ load_setup (void)
     if (buffer != NULL)
         utf8_display = str_isutf8 (buffer);
 #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
@@ -858,6 +860,9 @@ save_setup (void)
                           get_codepage_id (default_source_codepage));
     mc_config_set_string (mc_main_config, "Misc", "autodetect_codeset", autodetect_codeset);
 #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);
     ret = mc_config_save_to_file (mc_main_config, tmp_profile, NULL);
 

Some files were not shown because too many files changed in this diff