A URL is associated with a WebCard card of type Web at creation time but it may later be necessary to change or take action on the URL. For example, to correct a typo or visit the URL again if its web browser tab was closed since an earlier visit.
For such situations I added the items Visit URL and Edit URL to the title bar menu of Web cards. This is the menu:
The card holds the URL shown in the text area. Left-clicking on the title bar brings up the menu with the new items Visit URL and Edit URL at the top.
The NoteCards API function NCP.AddTitleBarMenuItemsToType adds items to the menu of a specified card type. It's easy to use but it wasn't clear to me what arguments the item callback functions are supposed to take. Some experimentation with throwaway code revealed the system passes only one argument to callbacks, a window.
Functions WCD.VisitURLMenuCmd and WCD.EditURLMenuCmd carry out the actual menu actions and are straightfoward. In addition to updating the URL property of the card, WCD.EditURLMenuCmd substitutes the new URL for the old in the text area.
As soon as the user starts typing, NCP.AskUser deletes the prefix https://, whereas I assumed the new text would be appended to https://. To avoid the confusion WCD.AskURL no longer prefills the input buffer unless the function is called with an optional prefix. Even if deleted when the user types, the current URL will serve as an initial reminder when editing a card URL.
Finally, I factored out the code that visits a URL into its own function WCD.VisitURL since I'll eventually revise the feature and call it in other contexts.
I started working on URL validation in WebCard and soon bumped into a bug.
When creating a new Web card, WebCard prompts for a URL to store in the card. I wrote the predicate WCD.ValidURLP to do some minimal validation and make sure the input resembles a URL. For example, the function checks whether the input starts with https://, http://, or mailto:. Although I don't want to write a URL parser I ended up adding more logic than anticipated.
I could skip URL validation altogether and defer error cheking and reporting to the web browser. Or allow URLs with no URL scheme such as interlisp.org that a browser can handle. But it's probably better to have full URLs as a form of card documentation.
Next I tried calling WCD.ValidURLP from WCD.AskURL, the function that prompts for a URL in a loop until the input is valid. An Interlisp iterative statement with a bind clause controls the loop.
But I'm getting syntax errors for bind in the statement. I checked the documentation, read sample code, and tested a few variations.
I wrote some throwaway code to experiment with editing cards of type Web in WebCard, my RetroChallenge 2024 project. The goal is to make the card read only with the least amount of effort.
In a NoteCards hypertext a Web card is a stand-in for a website, a placeholder for a URL that gets visited when links leading to the card are clicked. The Web card type inherits from the Text type but, since the user isn't supposed to enter text into a Web card, the card should be read only.
An approach I tried is to override the card editing operation for the Web type. The overridden function was a no-op that did nothing and immediately returned, as I thought not calling the TEdit editor would prevent text from being entered or modified.
It turned out the function worked even too well and did nothing at all, really. Like, not even opening or displaying the card.
Back to the drawing board.
A more substantial function would involve additional complexity to interact with TEdit, which would do nothing anyway. An easier approach is to make the content of a Web card read only in the constructor as soon as it's created.
I'm actually also considering to drop the read only requirement and allow editing the content of Web cards. It could be handy to enter a description or note about the website.
My WebCard prototype made NoteCards visit a site on the World-Wide Web for the first time. Think of it as a wormhole that connects the old world of hypertext with the new world of the modern web. WebCard, a NoteCards extension for visiting websites, is my RetroChallenge 2024 project.
This is my Linux desktop just after NoteCards visited a website for the very first time: