[VW 7.5] Hypertext linking to Web Browser

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

[VW 7.5] Hypertext linking to Web Browser

Stew MacLean

Hi,

 

I would like to be able to use hypertext within from within my app to link to external web pages.

 

Previous posts have mentioned using the Arbor/VWHelp components, or WithStyle.

 

Having looked at the VWHelp, it looks like it could be a nice lightweight solution.

 

The only trouble is, is that I can’t figure out how to “plug it in”.

 

It looks like I should be able to do it just using the Arbor Hypertext parcel.

 

But I’m not sure how to configure my instances of TextEditorView to use the ArborHypertextController.

 

Has anyone actually done this before?

 

Having done this, how does one go about adding ArborHyperlink’s to instances of ArborHypertext without having to resort to scripting?

 

How was the VW Help library created?

 

I would prefer to not use WithStyle, as this seems overkill for what I want to do, and it looks like with a little tweaking VW Help could be adapted to do this.

 

As usual, any help greatly appreciated,

 

Stewart

Reply | Threaded
Open this post in threaded view
|

Re: [VW 7.5] Hypertext linking to Web Browser

Karsten Kusche
Hi Stewart,

you should also have a look at the new RB which you can find on the
public repository. It has a hyperlink capable texteditor by default. I
don't have an image with this RB loaded right now, so i can't tell you
which packages are used there, but it was a pretty simple implementation
that used extra emphasis to add links to a text.

Kind Regards
Karsten



Stewart MacLean wrote:

>
> Hi,
>
> I would like to be able to use hypertext within from within my app to
> link to external web pages.
>
> Previous posts have mentioned using the Arbor/VWHelp components, or
> WithStyle.
>
> Having looked at the VWHelp, it looks like it could be a nice
> lightweight solution.
>
> The only trouble is, is that I can’t figure out how to “plug it in”.
>
> It looks like I should be able to do it just using the Arbor Hypertext
> parcel.
>
> But I’m not sure how to configure my instances of TextEditorView to
> use the ArborHypertextController.
>
> Has anyone actually done this before?
>
> Having done this, how does one go about adding ArborHyperlink’s to
> instances of ArborHypertext without having to resort to scripting?
>
> How was the VW Help library created?
>
> I would prefer to not use WithStyle, as this seems overkill for what I
> want to do, and it looks like with a little tweaking VW Help could be
> adapted to do this.
>
> As usual, any help greatly appreciated,
>
> Stewart
>

--
Karsten Kusche - Student - [hidden email]
Georg Heeg eK - Köthen
Handelsregister: Amtsgericht Dortmund A 12812

Reply | Threaded
Open this post in threaded view
|

Re: [VW 7.5] Hypertext linking to Web Browser

Mark Roberts
Stewart,

I created the content for the VisualWorks Help
browser, so I can say a few things about it.

First, you should know that it was a prototype.
We have long wanted to build a real one but there have been no resources.

To answer your question about the Help library
content: we used FrameMaker to author it in XML.
At the time, the version of FM that we could
afford would not produce structured XML, so it is
flat. If you are seriously considering the Arbor
code, there is a VisualWorks Technical Note that
explains all of this is more detail (see: /doc/TechNotes/HelpSystem.pdf).

That said, we have no plans to do anything
further with the Arbor code. It was never
adequately documented and has long since decayed
into rubbish. For a while, I was interested in
using WithStyle, it is far more capable but also
lacks API documentation and there are no plans to
integrate it with the VisualWorks product.

As for the hyperlink support in the RB that
Karsten mentioned, last time I checked it was not
real hypertext support, but rather a hack to make
strings that begin with "http://..." light up and
act like hyperlinks. This may or may not be
adequate for your needs. I asked whether we plan
to enhance this but never heard back. If you're curious, ask Travis.

There were also plans to add hypertext support to
Widgetry, but I don't know current status for
that. You could ask Sam. There is also code to
launch an external browser, which is in the
process of being reviewed/reworked for integration.

If we could build a replacement for the Help
browser, I would think of using DITA to represent
the content, and a Widgetry-enabled hypertext
widget, not Arbor. Another possibility would be
to just skip the VisualWorks GUI, since there
isn't any supported hypertext API, and use an
external browser. For the Help system, though,
that would mean losing the ability to click on
links that load example code, do searches of help
topics, etc., unless we run a local web server in
the image to serve the content, which seems a bit
like overkill for a help system.

Regards,

M



At 04:12 PM 8/21/2007, Karsten wrote:

>Hi Stewart,
>
>you should also have a look at the new RB which
>you can find on the public repository. It has a
>hyperlink capable texteditor by default. I don't
>have an image with this RB loaded right now, so
>i can't tell you which packages are used there,
>but it was a pretty simple implementation that
>used extra emphasis to add links to a text.
>
>Kind Regards
>Karsten
>
>
>
>Stewart MacLean wrote:
>>
>>Hi,
>>
>>I would like to be able to use hypertext within
>>from within my app to link to external web pages.
>>
>>Previous posts have mentioned using the
>>Arbor/VWHelp components, or WithStyle.
>>
>>Having looked at the VWHelp, it looks like it
>>could be a nice lightweight solution.
>>
>>The only trouble is, is that I can’t figure out how to “plug it in”.
>>
>>It looks like I should be able to do it just
>>using the Arbor Hypertext parcel.
>>
>>But I’m not sure how to configure my instances
>>of TextEditorView to use the ArborHypertextController.
>>
>>Has anyone actually done this before?
>>
>>Having done this, how does one go about adding
>>ArborHyperlink’s to instances of ArborHypertext
>>without having to resort to scripting?
>>
>>How was the VW Help library created?
>>
>>I would prefer to not use WithStyle, as this
>>seems overkill for what I want to do, and it
>>looks like with a little tweaking VW Help could be adapted to do this.
>>
>>As usual, any help greatly appreciated,
>>
>>Stewart
>
>--
>Karsten Kusche - Student - [hidden email]
>Georg Heeg eK - Köthen
>Handelsregister: Amtsgericht Dortmund A 12812
>


Reply | Threaded
Open this post in threaded view
|

RE: [VW 7.5] Hypertext linking to Web Browser

Stew MacLean
In reply to this post by Karsten Kusche
Hi Karsten,

Thanks for the pointer... it sounds like it would do the job, but may
need some refactoring.

I currently like the idea of just adapting the Arbor Hypertext parcel,
as it seems pretty self contained and should integrate well with my
existing context sensitive help framework.

I think it uses the extra emphasis trick as well.

Cheers,

Stewart

>-----Original Message-----
>From: Karsten [mailto:[hidden email]]
>Sent: 21 August 2007 7:13 p.m.
>To: Stewart MacLean
>Cc: [hidden email]
>Subject: Re: [VW 7.5] Hypertext linking to Web Browser
>
>Hi Stewart,
>
>you should also have a look at the new RB which you can find on the
>public repository. It has a hyperlink capable texteditor by default. I
>don't have an image with this RB loaded right now, so i can't tell you
>which packages are used there, but it was a pretty simple
implementation

>that used extra emphasis to add links to a text.
>
>Kind Regards
>Karsten
>
>
>
>Stewart MacLean wrote:
>>
>> Hi,
>>
>> I would like to be able to use hypertext within from within my app to
>> link to external web pages.
>>
>> Previous posts have mentioned using the Arbor/VWHelp components, or
>> WithStyle.
>>
>> Having looked at the VWHelp, it looks like it could be a nice
>> lightweight solution.
>>
>> The only trouble is, is that I can’t figure out how to “plug it in”.
>>
>> It looks like I should be able to do it just using the Arbor
Hypertext

>> parcel.
>>
>> But I’m not sure how to configure my instances of TextEditorView to
>> use the ArborHypertextController.
>>
>> Has anyone actually done this before?
>>
>> Having done this, how does one go about adding ArborHyperlink’s to
>> instances of ArborHypertext without having to resort to scripting?
>>
>> How was the VW Help library created?
>>
>> I would prefer to not use WithStyle, as this seems overkill for what
I

>> want to do, and it looks like with a little tweaking VW Help could be
>> adapted to do this.
>>
>> As usual, any help greatly appreciated,
>>
>> Stewart
>>
>
>--
>Karsten Kusche - Student - [hidden email]
>Georg Heeg eK - Köthen
>Handelsregister: Amtsgericht Dortmund A 12812



Reply | Threaded
Open this post in threaded view
|

RE: [VW 7.5] Hypertext linking to Web Browser

Stew MacLean
In reply to this post by Mark Roberts
Hi Mark,

Thanks for your informative reply. I've used the help quite a lot and,
for a prototype, works pretty well in my experience (as a consumer, it
looks like the problems come as a producer).

Reading the tech note, makes it all fall into place.

Widgetry seems the way to go, although as I've used the Arbor stuff
extensively (as I couldn't wait for Widgetry), I feel comfortable with
the idea using the Arbor Hypertext parcel, even if it requires a bit of
hacking...

My whole motivation for this is to enable the user to hyperlink to help
on my web site (yet to be written!), to supplement the internal context
sensitive help.

As for running a local help web server, you may want to check out
VisualAge. They deliver all their documentation in this manner. It works
quite well (and there's lots of it!). Being able to execute code and
load parcels comes in handy however, especially when learning and
exploring.

I hope you get some more resources in the not too distant future!

Cheers,

Stewart

>-----Original Message-----
>From: Mark Roberts [mailto:[hidden email]]
>Sent: 21 August 2007 7:50 p.m.
>To: Karsten; Stewart MacLean
>Cc: [hidden email]
>Subject: Re: [VW 7.5] Hypertext linking to Web Browser
>
>Stewart,
>
>I created the content for the VisualWorks Help
>browser, so I can say a few things about it.
>
>First, you should know that it was a prototype.
>We have long wanted to build a real one but there have been no
resources.
>
>To answer your question about the Help library
>content: we used FrameMaker to author it in XML.
>At the time, the version of FM that we could
>afford would not produce structured XML, so it is
>flat. If you are seriously considering the Arbor
>code, there is a VisualWorks Technical Note that
>explains all of this is more detail (see:
/doc/TechNotes/HelpSystem.pdf).

>
>That said, we have no plans to do anything
>further with the Arbor code. It was never
>adequately documented and has long since decayed
>into rubbish. For a while, I was interested in
>using WithStyle, it is far more capable but also
>lacks API documentation and there are no plans to
>integrate it with the VisualWorks product.
>
>As for the hyperlink support in the RB that
>Karsten mentioned, last time I checked it was not
>real hypertext support, but rather a hack to make
>strings that begin with "http://..." light up and
>act like hyperlinks. This may or may not be
>adequate for your needs. I asked whether we plan
>to enhance this but never heard back. If you're curious, ask Travis.
>
>There were also plans to add hypertext support to
>Widgetry, but I don't know current status for
>that. You could ask Sam. There is also code to
>launch an external browser, which is in the
>process of being reviewed/reworked for integration.
>
>If we could build a replacement for the Help
>browser, I would think of using DITA to represent
>the content, and a Widgetry-enabled hypertext
>widget, not Arbor. Another possibility would be
>to just skip the VisualWorks GUI, since there
>isn't any supported hypertext API, and use an
>external browser. For the Help system, though,
>that would mean losing the ability to click on
>links that load example code, do searches of help
>topics, etc., unless we run a local web server in
>the image to serve the content, which seems a bit
>like overkill for a help system.
>
>Regards,
>
>M
>
>
>
>At 04:12 PM 8/21/2007, Karsten wrote:
>>Hi Stewart,
>>
>>you should also have a look at the new RB which
>>you can find on the public repository. It has a
>>hyperlink capable texteditor by default. I don't
>>have an image with this RB loaded right now, so
>>i can't tell you which packages are used there,
>>but it was a pretty simple implementation that
>>used extra emphasis to add links to a text.
>>
>>Kind Regards
>>Karsten
>>
>>
>>
>>Stewart MacLean wrote:
>>>
>>>Hi,
>>>
>>>I would like to be able to use hypertext within
>>>from within my app to link to external web pages.
>>>
>>>Previous posts have mentioned using the
>>>Arbor/VWHelp components, or WithStyle.
>>>
>>>Having looked at the VWHelp, it looks like it
>>>could be a nice lightweight solution.
>>>
>>>The only trouble is, is that I can’t figure out how to “plug it in”.
>>>
>>>It looks like I should be able to do it just
>>>using the Arbor Hypertext parcel.
>>>
>>>But I’m not sure how to configure my instances
>>>of TextEditorView to use the ArborHypertextController.
>>>
>>>Has anyone actually done this before?
>>>
>>>Having done this, how does one go about adding
>>>ArborHyperlink’s to instances of ArborHypertext
>>>without having to resort to scripting?
>>>
>>>How was the VW Help library created?
>>>
>>>I would prefer to not use WithStyle, as this
>>>seems overkill for what I want to do, and it
>>>looks like with a little tweaking VW Help could be adapted to do
this.

>>>
>>>As usual, any help greatly appreciated,
>>>
>>>Stewart
>>
>>--
>>Karsten Kusche - Student - [hidden email]
>>Georg Heeg eK - Köthen
>>Handelsregister: Amtsgericht Dortmund A 12812
>>
>



Reply | Threaded
Open this post in threaded view
|

Re: [VW 7.5] Hypertext linking to Web Browser

Maarten Mostert-2
In reply to this post by Mark Roberts
Mark Roberts a écrit :
> For a while, I was interested in using WithStyle, it is far more
> capable but also lacks API documentation and there are no plans to
> integrate it with the VisualWorks product.
Not integrating WithStyle in VW would really be a shame. Having your own
webbrowser into your application can be really handy these days (Help
files are just one example).

> If we could build a replacement for the Help browser, I would think of
> using DITA to represent the content, and a Widgetry-enabled hypertext
> widget, not Arbor. Another possibility would be to just skip the
> VisualWorks GUI, since there isn't any supported hypertext API, and
> use an external browser. For the Help system, though, that would mean
> losing the ability to click on links that load example code, do
> searches of help topics, etc., unless we run a local web server in the
> image to serve the content, which seems a bit like overkill for a help
> system.
>
Overkill or not we can easily think of a system where we can intergate
Seaside,  HTML files and or WithStyle right into the application and
switch between on-line and off-line documentation as we like.


@+Maarten,

Reply | Threaded
Open this post in threaded view
|

Re: [VW 7.5] Hypertext linking to Web Browser

James Robertson-7
Bear in mind that WithStyle is no longer under active development.

----- Original Message -----
From: "Maarten Mostert" <[hidden email]>
To: "Mark Roberts" <[hidden email]>
Cc: "Karsten" <[hidden email]>; "Stewart MacLean" <[hidden email]>;
<[hidden email]>
Sent: Tuesday, August 21, 2007 7:13 AM
Subject: Re: [VW 7.5] Hypertext linking to Web Browser


> Mark Roberts a écrit :
>> For a while, I was interested in using WithStyle, it is far more capable
>> but also lacks API documentation and there are no plans to integrate it
>> with the VisualWorks product.
> Not integrating WithStyle in VW would really be a shame. Having your own
> webbrowser into your application can be really handy these days (Help
> files are just one example).
>> If we could build a replacement for the Help browser, I would think of
>> using DITA to represent the content, and a Widgetry-enabled hypertext
>> widget, not Arbor. Another possibility would be to just skip the
>> VisualWorks GUI, since there isn't any supported hypertext API, and use
>> an external browser. For the Help system, though, that would mean losing
>> the ability to click on links that load example code, do searches of help
>> topics, etc., unless we run a local web server in the image to serve the
>> content, which seems a bit like overkill for a help system.
>>
> Overkill or not we can easily think of a system where we can intergate
> Seaside,  HTML files and or WithStyle right into the application and
> switch between on-line and off-line documentation as we like.
>
>
> @+Maarten,
>
>

Reply | Threaded
Open this post in threaded view
|

Re: [VW 7.5] Hypertext linking to Web Browser

James Robertson-7
In reply to this post by Stew MacLean
I did a screencast on using WithStyle here:
 
 
It's not hard to use, and you shouldn't let the lack of a formal API scare you off.  The version you'll want to use is version 3 (The Wrapper based version), as the Widgetry based one is based on an older rev of Widgetry.  I didn't disentangle the pre-reqs for that; you'll get version 4 and the older rev of Widgetry when you load WS-Bundle from the public Store.  If you want to port version 4 up to the latest Widgetry, the main issue will be the change in the coordinate system.
----- Original Message -----
Sent: Tuesday, August 21, 2007 3:00 AM
Subject: [VW 7.5] Hypertext linking to Web Browser

Hi,

 

I would like to be able to use hypertext within from within my app to link to external web pages.

 

Previous posts have mentioned using the Arbor/VWHelp components, or WithStyle.

 

Having looked at the VWHelp, it looks like it could be a nice lightweight solution.

 

The only trouble is, is that I can’t figure out how to “plug it in”.

 

It looks like I should be able to do it just using the Arbor Hypertext parcel.

 

But I’m not sure how to configure my instances of TextEditorView to use the ArborHypertextController.

 

Has anyone actually done this before?

 

Having done this, how does one go about adding ArborHyperlink’s to instances of ArborHypertext without having to resort to scripting?

 

How was the VW Help library created?

 

I would prefer to not use WithStyle, as this seems overkill for what I want to do, and it looks like with a little tweaking VW Help could be adapted to do this.

 

As usual, any help greatly appreciated,

 

Stewart

Reply | Threaded
Open this post in threaded view
|

Re: [VW 7.5] Hypertext linking to Web Browser

Michael Lucas-Smith-2
In reply to this post by James Robertson-7
May be one day. When it comes down to the crunch - this was a very fun
project to do and I enjoyed it a lot. It showed me a different side to
UIs than the regular one. It also showed me how stupid the HTML world is
in terms of building UIs :) this isn't a big surprise for most people.

If I were going to jump in to this fray again, I'd do it out-of-spec,
ie: not listening to a word W3 says on how things should be put
together. They are clearly living in an alternate reality at this point.

The simplest-thing-that-could-possibly-work philosophy says we should
just make a Comment tab that toggles between view/edit mode and uses a
wiki-syntax. Everyone likes wiki syntax. It's very simple, gets the
point quickly and will let us annotate links and drop in graphics.

DITA is overkill. A simple TOC and good searching is all you really
need. Right now there isn't an easy way to search the images significant
number of comments. I hope to get some time to work on a fix for that
and make something like Apple's Spotlight for the Smalltalk image.

Anyway, those are just some random thoughts jumbled together in to an
email. Any feedback on particular bits of what I just said would be
appreciated.

Cheers,
Michael

James Robertson wrote:

> Bear in mind that WithStyle is no longer under active development.
>
> ----- Original Message ----- From: "Maarten Mostert"
> <[hidden email]>
> To: "Mark Roberts" <[hidden email]>
> Cc: "Karsten" <[hidden email]>; "Stewart MacLean"
> <[hidden email]>; <[hidden email]>
> Sent: Tuesday, August 21, 2007 7:13 AM
> Subject: Re: [VW 7.5] Hypertext linking to Web Browser
>
>
>> Mark Roberts a écrit :
>>> For a while, I was interested in using WithStyle, it is far more
>>> capable but also lacks API documentation and there are no plans to
>>> integrate it with the VisualWorks product.
>> Not integrating WithStyle in VW would really be a shame. Having your
>> own webbrowser into your application can be really handy these days
>> (Help files are just one example).
>>> If we could build a replacement for the Help browser, I would think
>>> of using DITA to represent the content, and a Widgetry-enabled
>>> hypertext widget, not Arbor. Another possibility would be to just
>>> skip the VisualWorks GUI, since there isn't any supported hypertext
>>> API, and use an external browser. For the Help system, though, that
>>> would mean losing the ability to click on links that load example
>>> code, do searches of help topics, etc., unless we run a local web
>>> server in the image to serve the content, which seems a bit like
>>> overkill for a help system.
>>>
>> Overkill or not we can easily think of a system where we can
>> intergate Seaside,  HTML files and or WithStyle right into the
>> application and switch between on-line and off-line documentation as
>> we like.
>>
>>
>> @+Maarten,
>>
>>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: [VW 7.5] Hypertext linking to Web Browser

Travis Griggs-3
In reply to this post by Stew MacLean
As others have mentioned the RB will highlight hyperlink looking things and allow you to open a web browser when you click on them. I'm a firm believer that you shouldn't have to load massive frameworks just to get this kind of thing to work. And that this should be layered to be reusable. I'll explain the parts, and you tell me if we got at all close. This is of course a work in progress, where I add to it and evolve it each time I need a little more, rather than imagine a visionary framework.

There are two basic packages that make it possible for the RB to do this. The first is ExternalWebBrowser. It's a small package that adds support for opening the OS preferred web browser on a given link. It's API is pretty straightforward:

ExternalWebBrowser open: aString

where aString is... whatever you want. Could be file:// link, or an http:// or whatever. That is "Layer 1" of the solution. An App could use it in a variety of ways.

For the next layers are had by loading the ExternalWebBrowser-Text package.

This allows you to put hyperlink text via Text emphases. For example:

ts := TextStream on: String new.
ts emphasis: #href -> 'http://en.wikipedia.org/wiki/Hello'.
ts nextPutAll: 'Hello'.
ts emphasis: nil.
ts space.
ts emphasis: #href -> 'http://en.wikipedia.org/wiki/World'.
ts nextPutAll: 'World'.
ComposedTextView open: ts contents asValue

You'll find that the text formats like standard hyperlink conventions. That when you hover your mouse over it, it get's the underline. That when you click on either Hello or World, you get a browser with the link open on it. An interesting note is that if you replace the last line with just 'ts contents' and inspect the expression, you'll get an inspector on the text. The cool thing is that even in the inspector, the hyperlinking and highlighting will work. Not sure what this says about Subject/Object separation, but I'm glad it was so easy and universal. To me, it's a tribute to Smalltalk and-dare I blaspheme-the ancient VisualWorks Wrapper framework, that I could bolt this in by adding 13 extension methods to existing classes. No overrides. There are some additional handy API's for placing href emphases on. I could have used for example:

text := 'Hello World' asText.
text addHrefLink: 'http://en.wikipedia.org/wiki/Hello' from: 1 to: 5.
text addHrefLink: 'http://en.wikipedia.org/wiki/World' from: 7 to: 11.

That last layer that the browser makes of is the ability to add these emphases by noting http:// prefixes in words when it looks at the code it loads into the source pane. The API it uses is

aText styleEmbeddedHttps

Each time the browser fetches some source for a method, or a comment, it sends that message to it, which automatically find http: prefixes in the text and add the styling. We've all come to expect this of things like email clients and irc clients and... basically it just notices text that looks suspiciously like a link, and offers it as a hyperlink.

HTH.

--
Travis Griggs
Objologist
"It’s actually much easier to get around on ice than it is on dry land—if you use skates." - Paul Graham


Reply | Threaded
Open this post in threaded view
|

Re: [VW 7.5] Hypertext linking to Web Browser

Mark Roberts
Hi Travis,

I just tried your code for hypertext and it looks really good.

One question:

I looked at the code a bit and it seems rather closely tried to the
notion of an external web browser. E.g., in
ParagraphEditor>>redButtonReleasedEvent:

        #{ExternalWebBrowser}
                ifDefinedDo:
                        [:webBrowserInterface |
                        (self hrefAtEvent: anEvent)
                                ifNotNil:
                                        [:hrefEmphasis |
                                        | link |
                                        link := hrefEmphasis value.
                                        link rememberHyperlinkVisit.
                                        self view simpleRedisplay.
                                        webBrowserInterface open: link]].


What would you think of making the red-button event activate a block
instead of always invoking an external web browser?

If it did that, hypertext could be used to invoke arbitrary Smalltalk
code, which is what we'd need to eventually replace the Help browser.

Cheers,

M

Reply | Threaded
Open this post in threaded view
|

RE: [VW 7.5] Hypertext linking to Web Browser

Stew MacLean
In reply to this post by Travis Griggs-3

Hi Travis,

 

Thanks for this detailed description of the RB hypertexting.

 

Since I posted, I’ve managed to integrate the VWHelp hypertext into my own text displays (you can edit too).

 

It was “relatively” straightforward, once I’d figured out the framework (see below).

 

Another testament to Wrapper and the Arbor framework, or is it ugly hacking?

 

Whatever, it works.

 

There’s only one problem - why does my colorBlue show up as yellow on the MacOSX?

 

Cheers,

 

Stewart

 

============================================================================================

For anyone that’s interested… it started with introducing a new Spec - VWHelp.HypertextEditorSpec (sub class of UI.TextEditorSpec)

 

This class has one method:

 

dispatchTo: policy with: builder

 

            "Added to enable plugging in of hypertext functionality."

 

            policy

                        textView: self

                        into: builder

                        view: AHSHelpTextEditorView new

                        controller: VWHelp.AHSHelpTextEditorController new

 

The LookPolicy method is a hack the existing textView: spec into: builder

 

textView: spec into: builder view: aView controller: aController

 

            "Added to enable plugging in of hypertext functionality. 22/08/07 SIM."

 

            | model component menu performer alignment style |

            model := spec modelInBuilder: builder.

            component := aView class model: model.

            component controller: aController.

            Etc.

 

To enable hypertext use this spec in your windowSpec. Beware, this is a manual edit of the generated UI builder code!

 

Then in my model class add these items to an appropriate menu:

 

menu addItem:

                        ((MenuItem labeled: 'Hypertext')

                                    nameKey: #hypertext;

                                    value: [: aHelpTextEditorController | self createLinkFor: aHelpTextEditorController).

            menu addItem:

                        ((MenuItem labeled: 'Remove Hypertext')

                                    nameKey: #removeHypertext;

                                    value: [: aHelpTextEditorController | self removeLinkFor: aHelpTextEditorController]).

 

Add the callbacks in the model:

 

createLinkFor: aController

 

            "Create a hypertext link for the current selection on aController.

            If there is already an existing link, get the current uri and present that to the user for modification."

 

            | displayString uri currentUri existingLink |

           

            displayString := aController selection ifEmpty: [^self].

 

            currentUri := (aController trackTextPosition: (self attributeAt: 'popupMenuPoint' ifAbsent: [0@0]))

                        ifNotNil: [: value | value firstAvailableLink ifNotNil: [: link | (existingLink := link) linkObject] ifNil: ['']].

 

            (uri := Dialog

                        request: ('Please enter the Uri to be linked with <1s>' with: displayString)

                        initialAnswer: currentUri) ifEmpty: [^self].

 

            self

                        removeLinkFor: aController;

                        addEmphasis:

                                    (ArborHyperlinkAssociation

                                                value: (URIHyperlinkObject new linkObject: uri))

 

removeLinkFor: aController

 

            | selectedText |

 

            selectedText := aController selection.

            selectedText removeAllHyperLinks.

            aController

                        replaceSelectionWith: selectedText;

                        accept.

            self changed: #linkRemoved.

            aController restoreSelection

 

 

within postOpen

 

            self

                        widget: #text

                        when: #popupMenuCreated

                        send: #aboutToPopupMenu

                        to: self

 

aboutToPopupMenu

 

            "Take note of the location of the cursor as the menu popping up.

            This is used later to access the underlying link."

 

            self

                        attributeAt: 'popupMenuPoint'

                        put: (self widgetAt: #text) controller sensor cursorPoint

 

and finally, the point of the whole thing:

 

engageURIHyperlink: aLink

 

            self openWebBrowserOn: aLink linkObject

 

For completeness, URIHyperlinkObject is a new subclass of VWHelp.ArborHyperlink with:

 

engageFor: anObject

            "The hyperlink has been engaged within the context of anObject."

 

            ^anObject engageURIHyperlink: self

 

with the emphasis methods overloaded.

 

 

-----Original Message-----
From: Travis Griggs [mailto:[hidden email]]
Sent: 22 August 2007 4:07 p.m.
To: VW NC
Subject: Re: [VW 7.5] Hypertext linking to Web Browser

 

As others have mentioned the RB will highlight hyperlink looking things and allow you to open a web browser when you click on them. I'm a firm believer that you shouldn't have to load massive frameworks just to get this kind of thing to work. And that this should be layered to be reusable. I'll explain the parts, and you tell me if we got at all close. This is of course a work in progress, where I add to it and evolve it each time I need a little more, rather than imagine a visionary framework.

 

There are two basic packages that make it possible for the RB to do this. The first is ExternalWebBrowser. It's a small package that adds support for opening the OS preferred web browser on a given link. It's API is pretty straightforward:

 

ExternalWebBrowser open: aString

 

where aString is... whatever you want. Could be file:// link, or an http:// or whatever. That is "Layer 1" of the solution. An App could use it in a variety of ways.

 

For the next layers are had by loading the ExternalWebBrowser-Text package.

 

This allows you to put hyperlink text via Text emphases. For example:

 

ts := TextStream on: String new.

ts emphasis: #href -> 'http://en.wikipedia.org/wiki/Hello'.

ts nextPutAll: 'Hello'.

ts emphasis: nil.

ts space.

ts emphasis: #href -> 'http://en.wikipedia.org/wiki/World'.

ts nextPutAll: 'World'.

ComposedTextView open: ts contents asValue

 

You'll find that the text formats like standard hyperlink conventions. That when you hover your mouse over it, it get's the underline. That when you click on either Hello or World, you get a browser with the link open on it. An interesting note is that if you replace the last line with just 'ts contents' and inspect the expression, you'll get an inspector on the text. The cool thing is that even in the inspector, the hyperlinking and highlighting will work. Not sure what this says about Subject/Object separation, but I'm glad it was so easy and universal. To me, it's a tribute to Smalltalk and-dare I blaspheme-the ancient VisualWorks Wrapper framework, that I could bolt this in by adding 13 extension methods to existing classes. No overrides. There are some additional handy API's for placing href emphases on. I could have used for example:

 

text := 'Hello World' asText.

text addHrefLink: 'http://en.wikipedia.org/wiki/Hello' from: 1 to: 5.

text addHrefLink: 'http://en.wikipedia.org/wiki/World' from: 7 to: 11.

 

That last layer that the browser makes of is the ability to add these emphases by noting http:// prefixes in words when it looks at the code it loads into the source pane. The API it uses is

 

aText styleEmbeddedHttps

 

Each time the browser fetches some source for a method, or a comment, it sends that message to it, which automatically find http: prefixes in the text and add the styling. We've all come to expect this of things like email clients and irc clients and... basically it just notices text that looks suspiciously like a link, and offers it as a hyperlink.

 

HTH.

 

--

Travis Griggs

Objologist

"It’s actually much easier to get around on ice than it is on dry land—if you use skates." - Paul Graham



 

Reply | Threaded
Open this post in threaded view
|

Re: [VW 7.5] Hypertext linking to Web Browser

Michael Lucas-Smith-2
In reply to this post by Mark Roberts

>
> What would you think of making the red-button event activate a block
> instead of always invoking an external web browser?

That'd be a different kind of emphasis - something like, aText
allEmphisisWith: (#code -> [... my code here...])

Good idea though. But not part of ExternalWebBrowser

Cheers,
Michael