lynx-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

lynx-dev [PATCH 2.8.4dev.18] Copy and paste URL


From: Ilya Zakharevich
Subject: lynx-dev [PATCH 2.8.4dev.18] Copy and paste URL
Date: Tue, 20 Feb 2001 01:28:28 -0500
User-agent: Mutt/1.2.5i

This patch enables pasting an URL into Lynx (similar to 'g'), and
improves the code to copy an URL from Lynx.

Does it make sense to have two different bindings, one for copying the
current link URL, another for copying the current document URL?  What
about copying *the contents* of the document (as in printing)?

The code to handle TO_CLIPBOARD needs improvement.  I would not mind
copying of the *filled* link URL when on Submit button, and appending
the GET data to the URL of the current document.

When PASTE_URLing, whitespace is trimmed at the end, and the embedded
whitespace is trimmed around embedded newlines.  Thus you can paste
URL broken into several lines, and filenames including whitespace.

Enjoy,
Ilya

--- ./src/LYKeymap.c-pre-paste  Thu Feb 15 01:21:22 2001
+++ ./src/LYKeymap.c    Tue Feb 20 00:29:22 2001
@@ -1,7 +1,7 @@
 #include <HTUtils.h>
 #include <LYUtils.h>
-#include <LYKeymap.h>
 #include <LYGlobalDefs.h>
+#include <LYKeymap.h>
 #include <LYCharSets.h>                /* for LYlowest_eightbit - kw */
 #include <HTAccess.h>
 #include <HTFormat.h>
@@ -933,9 +933,6 @@ PRIVATE Kcmd revmap[] = {
     DATA(
        LYK_CHG_CENTER, "CHANGE_CENTER",
        "toggle center alignment in HTML TABLE" ),
-    DATA(
-       LYK_TO_CLIPBOARD, "TO_CLIPBOARD",
-       "link's URL to Clip Board" ),
 #endif
 #ifdef KANJI_CODE_OVERRIDE
     DATA(
@@ -958,6 +955,14 @@ PRIVATE Kcmd revmap[] = {
     DATA(
        LYK_LINEWRAP_TOGGLE, "LINEWRAP_TOGGLE",
        "toggle linewrap on/off" ),
+#endif
+#ifdef CAN_CUT_AND_PASTE
+    DATA(
+       LYK_PASTE_URL, "PASTE_URL",
+       "Goto the URL in the clipboard" ),
+    DATA(
+       LYK_TO_CLIPBOARD, "TO_CLIPBOARD",
+       "link's URL to Clip Board" ),
 #endif
     DATA(
        LYK_UNKNOWN, NULL,
--- ./src/LYKeymap.h-pre-paste  Thu Feb 15 01:22:10 2001
+++ ./src/LYKeymap.h    Tue Feb 20 00:30:12 2001
@@ -237,7 +237,6 @@ typedef enum {
 
 #ifdef SH_EX
   , LYK_CHG_CENTER
-  , LYK_TO_CLIPBOARD
 #endif /* SH_EX */
 
 #ifdef KANJI_CODE_OVERRIDE
@@ -258,6 +257,13 @@ typedef enum {
 #define LYK_LINEWRAP_TOGGLE LYK_UNKNOWN
 #endif
 
+#ifdef CAN_CUT_AND_PASTE
+  , LYK_PASTE_URL
+  , LYK_TO_CLIPBOARD
+#else
+#define LYK_PASTE_URL      LYK_UNKNOWN
+#define LYK_TO_CLIPBOARD   LYK_UNKNOWN
+#endif
 } LYKeymapCode;
 
 /*
--- ./src/LYMainLoop.c-pre-paste        Sun Feb 18 01:10:48 2001
+++ ./src/LYMainLoop.c  Tue Feb 20 01:01:08 2001
@@ -6907,14 +6907,86 @@ new_cmd:  /*
            handle_LYK_DOWN_HALF(&old_c, real_c);
            break;
 
-#if defined(WIN_EX) && defined(SH_EX)  /*1997/12/22 (Mon) 09:28:56 */
+#ifdef CAN_CUT_AND_PASTE
        case LYK_TO_CLIPBOARD:  /* ^S */
            {
-               if (put_clip(links[curdoc.link].lname) == 0) {
-                   HTInfoMsg("URL to Clip Board.");
-               } else {
+               char *s;
+               int c;
+
+               /* The logic resembles one of ADD_BOOKMARK */
+               if (nlinks > 0 && links[curdoc.link].lname
+                   && links[curdoc.link].type != WWW_FORM_LINK_TYPE) {
+                   /* Makes sense to copy a link */
+                   _statusline("Copy D)ocument's or L)ink's URL to clipboard 
or C)ancel?");
+                   c = LYgetch_single();
+                   if (c == 'D')
+                       s = curdoc.address;
+                   else if (c == 'C')
+                       break;
+                   else
+                       s = links[curdoc.link].lname;
+               } else
+                   s = curdoc.address;
+               if (!s && !*s)
                    HTInfoMsg("Current URL is empty.");
+               if (put_clip(s))
+                   HTInfoMsg("Copy to clipboard failed.");
+               else if (s == curdoc.address)
+                   HTInfoMsg("Document URL put to clipboard.");
+               else
+                   HTInfoMsg("Link URL put to clipboard.");
+           }
+           break;
+
+       case LYK_PASTE_URL:
+           if (no_goto && !LYValidate) { /*  Go to not allowed. - FM */
+               HTUserMsg(GOTO_DISALLOWED);
+           } else {
+               unsigned char *s = get_clip_grab(), *e, *t;
+               char *buf;
+               int len;
+
+               if (!s)
+                   break;
+               len = strlen(s);
+               e = s + len;
+               while (s < e && strchr(" \t\n\r", *s))
+                   s++;
+               while (s < e && strchr(" \t\n\r", e[-1]))
+                   e--;
+               if (s >= e) {
+                   HTInfoMsg("No URL in the clipboard.");
+                   break;
                }
+               buf = (char*)malloc(e - s + 1);
+               strncpy(buf, s, e - s);
+               buf[e - s] = '\0';
+               t = buf;
+           
+               while (s < e) {
+                   if (strchr(" \t\n\r", *s)) {
+                       int nl = 0;     /* Keep whitespace without NL - file 
names! */
+                       unsigned char *s1 = s;
+
+                       while (strchr(" \t\n\r", *s)) {
+                           if (!nl && *s == '\n')
+                               nl = 1;
+                           s++;
+                       }
+                       if (!nl) {
+                           while (s1 < s) {
+                               if (*s1 != '\r' && *s1 != '\r')
+                                   *t = *s1;
+                               t++, s1++;
+                           }
+                       }
+                   } else
+                       *t++ = *s++;
+               }
+               *t = '\0';
+               get_clip_release();
+               do_check_goto_URL(buf, &temp, &force_load);
+               free(buf);
            }
            break;
 #endif
--- ./src/LYUtils.h-pre-paste   Tue Feb 20 00:10:40 2001
+++ ./src/LYUtils.h     Tue Feb 20 00:10:50 2001
@@ -2,6 +2,7 @@
 #define LYUTILS_H
 
 #include <LYCharVals.h>  /* S/390 -- gil -- 2149 */
+#include <LYGlobalDefs.h>
 #include <LYKeymap.h>
 
 #ifndef HTLIST_H

; To UNSUBSCRIBE: Send "unsubscribe lynx-dev" to address@hidden

reply via email to

[Prev in Thread] Current Thread [Next in Thread]