changeset 1445:36a81b29a15e

trim the labels of the stylesheet menu
author Jeremy Henty <onepoint@starurchin.org>
date Sat, 21 Nov 2009 01:54:44 +0000
parents 18354f36b06b
children 90fabbb4077b
files ChangeLog src/menu.cc
diffstat 2 files changed, 25 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Nov 20 21:04:43 2009 +0000
+++ b/ChangeLog	Sat Nov 21 01:54:44 2009 +0000
@@ -54,6 +54,9 @@
    Patches: corvid
 +- Support for the letter-spacing property.
    Patch: Johannes Hofmann, corvid
++- Fixed a bug in w3c_mode. In fact it wasn't working at all.
+ - Improve stylesheet menu.
+   Patches: Jeremy Henty
 
 -----------------------------------------------------------------------------
 
@@ -129,7 +132,6 @@
  - Fixed a memory leak in Klist().
  - Fix the comment for DLWin::del() (dpi/downloads.cc).
  - Removed redundant caller NULL checks already in the API.
- - Fixed a bug in w3c_mode. In fact it wasn't working at all.
    Patches: Jeremy Henty
 +- Implemented Basic authentication!
    Patch: Jeremy Henty, Jorge Arellano Cid
--- a/src/menu.cc	Fri Nov 20 21:04:43 2009 +0000
+++ b/src/menu.cc	Sat Nov 21 01:54:44 2009 +0000
@@ -238,9 +238,10 @@
       a_Html_form_display_hiddens(doc, v_form, !visible);
 }
 
-static void Menu_stylesheet_cb(Widget *w, void *)
+static void Menu_stylesheet_cb(Widget *w, void *vUrl)
 {
-   a_UIcmd_open_urlstr(popup_bw, w->label() + 5);
+   const DilloUrl *url = (const DilloUrl *) vUrl;
+   a_UIcmd_open_url(popup_bw, url);
 }
 
 /*
@@ -380,18 +381,34 @@
       /* get rid of the old ones */
       Widget *child = stylesheets->child(0);
       dFree((char *)child->label());
+      a_Url_free((DilloUrl *)child->user_data());
       delete child;
    }
 
    if (cssUrls && cssUrls->size () > 0) {
       stylesheets->activate();
       for (j = 0; j < cssUrls->size(); j++) {
-         DilloUrl *url = cssUrls->get(j);
+         /* may want ability to Load individual unloaded stylesheets as well */
          const char *action = "View ";
-         /* may want ability to Load individual unloaded stylesheets as well */
-         char *label = dStrconcat(action, URL_STR(url), NULL);
+         DilloUrl *url = cssUrls->get(j);
+         const char *url_str = URL_STR(url);
+         const uint_t head_length = 30, tail_length = 40,
+                      url_len = strlen(url_str);;
+         char *label;
+
+         if (url_len > head_length + tail_length + 3) {
+            /* trim long URLs when making the label */
+            char *url_head = dStrndup(url_str, head_length);
+            const char *url_tail = url_str + (url_len - tail_length);
+            label = dStrconcat(action, url_head, "...", url_tail, NULL);
+            dFree(url_head);
+         } else {
+            label = dStrconcat(action, url_str, NULL);
+         }
+
          i = new Item(label);
          i->set_flag(RAW_LABEL);
+         i->user_data(a_Url_dup(url));
          i->callback(Menu_stylesheet_cb);
          stylesheets->add(i);
       }