mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 20:36:50 +03:00
Ticket #30 (use external clipboard utility)
added params clipbord_store, clipbord_paste into [Misc] section. created src/clipbord.[ch] added copy_file_to_ext_clip, paste_to_file_from_ext_clip for copy/paste text to the global X clipboard. Signed-off-by: Andrew Borodin <aborodin@vmail.ru> Signed-off-by: Ilia Maslakov <il.smind@gmail.com>
This commit is contained in:
parent
e9b75676a5
commit
c46e2925e1
@ -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
src/clipboard.c
Normal file
80
src/clipboard.c
Normal 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
12
src/clipboard.h
Normal 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
|
@ -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);
|
||||
|
@ -797,3 +797,4 @@ regex_command (const char *filename, const char *action, int *move_dir)
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -61,6 +61,7 @@
|
||||
#include "panel.h" /* current_panel */
|
||||
#include "main.h" /* confirm_history_cleanup */
|
||||
#include "setup.h" /* num_history_items_recorded */
|
||||
#include "clipboard.h" /* copy_file_to_ext_clip, paste_to_file_from_ext_clip */
|
||||
|
||||
static void
|
||||
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 */
|
||||
panel_save_curent_file_to_clip_file ();
|
||||
/* try use external clipboard utility */
|
||||
copy_file_to_ext_clip ();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1833,7 +1836,10 @@ copy_region (WInput * in, int x_first, int x_last)
|
||||
last = str_offset_to_pos (in->buffer, last);
|
||||
|
||||
kill_buffer = g_strndup (in->buffer + first, last - first);
|
||||
|
||||
save_text_to_clip_file (kill_buffer);
|
||||
/* try use external clipboard utility */
|
||||
copy_file_to_ext_clip ();
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1922,6 +1928,9 @@ ins_from_clip (WInput * in)
|
||||
{
|
||||
char *p = NULL;
|
||||
|
||||
/* try use external clipboard utility */
|
||||
paste_to_file_from_ext_clip ();
|
||||
|
||||
if (load_text_from_clip_file (&p))
|
||||
{
|
||||
char *pp;
|
||||
|
Loading…
Reference in New Issue
Block a user