mirror of
https://github.com/MidnightCommander/mc
synced 2025-03-30 11:42:54 +03:00
Ticket #321 (Trouble with mc's clipboard paste)
add: paste as vertical block if clipfile contain magic sequence add: vertical paste from file add: symbolic definition MAGIC_VERTICAL for "\1\1\1\1\n" magic sequence
This commit is contained in:
parent
8e5cc41da1
commit
5c28d2bda4
@ -131,6 +131,7 @@ typedef enum {
|
||||
EDIT_FILE_MENU = 2
|
||||
} edit_current_file_t;
|
||||
|
||||
extern const char VERTICAL_MAGIC[5];
|
||||
int edit_drop_hotkey_menu (WEdit *e, int key);
|
||||
void edit_menu_cmd (WEdit *e);
|
||||
struct WMenu *edit_create_menu (void);
|
||||
@ -200,6 +201,8 @@ void edit_get_match_keyword_cmd (WEdit *edit);
|
||||
int edit_save_block (WEdit * edit, const char *filename, long start, long finish);
|
||||
int edit_save_block_cmd (WEdit * edit);
|
||||
int edit_insert_file_cmd (WEdit * edit);
|
||||
void edit_insert_column_of_text (WEdit * edit, unsigned char *data, int size, int width);
|
||||
int edit_insert_column_of_text_from_file (WEdit * edit, int file);
|
||||
int edit_insert_file (WEdit * edit, const char *filename);
|
||||
int edit_load_back_cmd (WEdit * edit);
|
||||
int edit_load_forward_cmd (WEdit * edit);
|
||||
|
25
edit/edit.c
25
edit/edit.c
@ -85,7 +85,8 @@ char *option_backup_ext = NULL;
|
||||
|
||||
int edit_stack_iterator = 0;
|
||||
edit_stack_type edit_history_moveto [MAX_HISTORY_MOVETO];
|
||||
|
||||
/* magic sequense for say than block is vertical */
|
||||
const char VERTICAL_MAGIC[] = {'\1', '\1', '\1', '\1', '\n'};
|
||||
/*-
|
||||
*
|
||||
* here's a quick sketch of the layout: (don't run this through indent.)
|
||||
@ -441,13 +442,27 @@ edit_insert_file (WEdit *edit, const char *filename)
|
||||
} else {
|
||||
int i, file, blocklen;
|
||||
long current = edit->curs1;
|
||||
unsigned char *buf;
|
||||
int vertical_insertion = 0;
|
||||
char *buf;
|
||||
if ((file = mc_open (filename, O_RDONLY | O_BINARY)) == -1)
|
||||
return 0;
|
||||
buf = g_malloc (TEMP_BUF_LEN);
|
||||
while ((blocklen = mc_read (file, (char *) buf, TEMP_BUF_LEN)) > 0) {
|
||||
for (i = 0; i < blocklen; i++)
|
||||
edit_insert (edit, buf[i]);
|
||||
blocklen = mc_read (file, buf, sizeof(VERTICAL_MAGIC));
|
||||
if (blocklen > 0) {
|
||||
/* if contain signature VERTICAL_MAGIC tnen it vertical block */
|
||||
if ( memcmp(buf, VERTICAL_MAGIC, sizeof(VERTICAL_MAGIC)) == 0 ) {
|
||||
vertical_insertion = 1;
|
||||
} else {
|
||||
mc_lseek (file, 0, SEEK_SET);
|
||||
}
|
||||
}
|
||||
if (vertical_insertion) {
|
||||
blocklen = edit_insert_column_of_text_from_file (edit, file);
|
||||
} else {
|
||||
while ((blocklen = mc_read (file, (char *) buf, TEMP_BUF_LEN)) > 0) {
|
||||
for (i = 0; i < blocklen; i++)
|
||||
edit_insert (edit, buf[i]);
|
||||
}
|
||||
}
|
||||
edit_cursor_move (edit, current - edit->curs1);
|
||||
g_free (buf);
|
||||
|
@ -954,7 +954,7 @@ int eval_marks (WEdit * edit, long *start_mark, long *end_mark)
|
||||
|
||||
#define space_width 1
|
||||
|
||||
static void
|
||||
void
|
||||
edit_insert_column_of_text (WEdit * edit, unsigned char *data, int size, int width)
|
||||
{
|
||||
long cursor;
|
||||
@ -997,6 +997,62 @@ edit_insert_column_of_text (WEdit * edit, unsigned char *data, int size, int wid
|
||||
edit_cursor_move (edit, cursor - edit->curs1);
|
||||
}
|
||||
|
||||
#define TEMP_BUF_LEN 1024
|
||||
|
||||
int
|
||||
edit_insert_column_of_text_from_file (WEdit * edit, int file)
|
||||
{
|
||||
long cursor;
|
||||
int i, col;
|
||||
int blocklen = -1, width;
|
||||
unsigned char *data;
|
||||
cursor = edit->curs1;
|
||||
col = edit_get_col (edit);
|
||||
data = g_malloc (TEMP_BUF_LEN);
|
||||
while ((blocklen = mc_read (file, (char *) data, TEMP_BUF_LEN)) > 0) {
|
||||
for (width = 0; width < blocklen; width++) {
|
||||
if (data[width] == '\n')
|
||||
break;
|
||||
}
|
||||
for (i = 0; i < blocklen; i++) {
|
||||
if (data[i] == '\n') { /* fill in and move to next line */
|
||||
int l;
|
||||
long p;
|
||||
if (edit_get_byte (edit, edit->curs1) != '\n') {
|
||||
l = width - (edit_get_col (edit) - col);
|
||||
while (l > 0) {
|
||||
edit_insert (edit, ' ');
|
||||
l -= space_width;
|
||||
}
|
||||
}
|
||||
for (p = edit->curs1;; p++) {
|
||||
if (p == edit->last_byte) {
|
||||
edit_cursor_move (edit, edit->last_byte - edit->curs1);
|
||||
edit_insert_ahead (edit, '\n');
|
||||
p++;
|
||||
break;
|
||||
}
|
||||
if (edit_get_byte (edit, p) == '\n') {
|
||||
p++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
edit_cursor_move (edit, edit_move_forward3 (edit, p, col, 0) - edit->curs1);
|
||||
l = col - edit_get_col (edit);
|
||||
while (l >= space_width) {
|
||||
edit_insert (edit, ' ');
|
||||
l -= space_width;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
edit_insert (edit, data[i]);
|
||||
}
|
||||
}
|
||||
edit_cursor_move (edit, cursor - edit->curs1);
|
||||
g_free(data);
|
||||
edit->force |= REDRAW_PAGE;
|
||||
return blocklen;
|
||||
}
|
||||
|
||||
void
|
||||
edit_block_copy_cmd (WEdit *edit)
|
||||
@ -1623,9 +1679,6 @@ edit_ok_to_exit (WEdit *edit)
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
#define TEMP_BUF_LEN 1024
|
||||
|
||||
/* Return a null terminated length of text. Result must be g_free'd */
|
||||
static unsigned char *
|
||||
edit_get_block (WEdit *edit, long start, long finish, int *l)
|
||||
@ -1669,17 +1722,20 @@ edit_save_block (WEdit * edit, const char *filename, long start,
|
||||
return 0;
|
||||
|
||||
if (column_highlighting) {
|
||||
unsigned char *block, *p;
|
||||
int r;
|
||||
p = block = edit_get_block (edit, start, finish, &len);
|
||||
while (len) {
|
||||
r = mc_write (file, p, len);
|
||||
if (r < 0)
|
||||
break;
|
||||
p += r;
|
||||
len -= r;
|
||||
r = mc_write (file, VERTICAL_MAGIC, sizeof(VERTICAL_MAGIC));
|
||||
if (r > 0) {
|
||||
unsigned char *block, *p;
|
||||
p = block = edit_get_block (edit, start, finish, &len);
|
||||
while (len) {
|
||||
r = mc_write (file, p, len);
|
||||
if (r < 0)
|
||||
break;
|
||||
p += r;
|
||||
len -= r;
|
||||
}
|
||||
g_free (block);
|
||||
}
|
||||
g_free (block);
|
||||
} else {
|
||||
unsigned char *buf;
|
||||
int i = start, end;
|
||||
|
Loading…
x
Reference in New Issue
Block a user