Skip to content

Commit

Permalink
[47_4] open-url of customized protocol like zotero
Browse files Browse the repository at this point in the history
  • Loading branch information
da-liii authored Dec 10, 2023
1 parent a8e61c8 commit 04540a8
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 35 deletions.
11 changes: 6 additions & 5 deletions TeXmacs/progs/link/link-navigate.scm
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,10 @@
(default-root-handler (url-relative (current-buffer) u)))
((url-or? (url-expand u))
(default-root-disambiguator (url-expand u)))
(else (with (base qry) (process-url u)
(if (!= "" (url->system base))
(load-browse-buffer base))))))
(else
(with (base qry) (process-url u)
(if (!= "" (url->system base))
(load-browse-buffer base))))))

(define (tmfs-root-handler u)
(load-browse-buffer u))
Expand All @@ -489,8 +490,8 @@
(list http-root-handler http-post-handler))
((or (== root "http") (== root "https"))
(list http-root-handler http-post-handler))
(else (display* "Unhandled url root: " root "\n")
(list default-root-handler default-post-handler)))))
(else
(list default-root-handler default-post-handler)))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Actual navigation
Expand Down
18 changes: 17 additions & 1 deletion TeXmacs/progs/network/url-test.scm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@
(texmacs-module (network url-test)
(:use (network url)))

(define (regtest-zotero-url)
(regression-test-group
"url" "(url-or? u)"
url-or? :none
(test "case 1" "zotero://a/b/c" #f))
(regression-test-group
"url" "(url-complete u flags)"
(lambda (x)
(== (url-complete "zotero://a/b/c" x)
(string->url "zotero://a/b/c")))
:none
(test "r" "r" #t)
(test "df" "df" #t)
(test "rf" "rf" #t)))

(define (regtest-url-host)
(regression-test-group
"url" "host of the url"
Expand All @@ -23,6 +38,7 @@
(test "local file 1" "/tmp" "")))

(tm-define (regtest-url)
(let ((n (+ (regtest-url-host))))
(let ((n (+ (regtest-url-host)
(regtest-zotero-url))))
(display* "Total: " (object->string n) " tests.\n")
(display "Test suite of url: ok\n")))
2 changes: 1 addition & 1 deletion TeXmacs/progs/source/shortcut-widgets.scm
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
(tm-define (open-shortcuts-editor . opt)
(:interactive #t)
(let* ((b (current-buffer))
(u (string->url (string-append "tmfs://aux/edit-shortcuts")))
(u (string-append "tmfs://aux/edit-shortcuts"))
(sh (if (null? opt) "" (car opt)))
(cmd (if (or (null? opt) (null? (cdr opt))) "" (cadr opt))))
(dialogue-window (shortcuts-editor u sh cmd)
Expand Down
1 change: 1 addition & 0 deletions TeXmacs/progs/texmacs/texmacs/tm-files.scm
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@
(or (and (url-rooted-web? u)
;; FIXME: Use HTTP HEADERS to determine the real file format
(!= (file-format u) "texmacs-file"))
(not (in? (url-root u) (list "tmfs" "file" "default" "blank" "ramdisc")))
(file-of-format? u "image")
(file-of-format? u "pdf")
(file-of-format? u "postscript")
Expand Down
9 changes: 5 additions & 4 deletions src/Plugins/Qt/qt_sys_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ qt_get_pretty_os_name () {

void
qt_open_url (url u) {
if (is_rooted_web (u) || is_rooted (u, "file")) {
QString link= to_qstring (as_string (u));
debug_io << "open-url\t" << u << LF;
if (is_local_and_single (u)) {
QString link= to_qstring ("file:///" * as_string (u));
QDesktopServices::openUrl (QUrl (link));
}
else if (is_local_and_single (u)) {
QString link= to_qstring ("file:///" * as_string (u));
else {
QString link= to_qstring (as_string (u));
QDesktopServices::openUrl (QUrl (link));
}
}
4 changes: 2 additions & 2 deletions src/Scheme/L3/glue_url.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function main()
},
{
scm_name = "string->url",
cpp_name = "tm_url",
cpp_name = "url",
ret_type = "url",
arg_list = {
"string"
Expand All @@ -125,7 +125,7 @@ function main()
},
{
scm_name = "unix->url",
cpp_name = "tm_url",
cpp_name = "url",
ret_type = "url",
arg_list = {
"string"
Expand Down
11 changes: 1 addition & 10 deletions src/System/Classes/tm_url.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@
#include "analyze.hpp"
#include "scheme.hpp"

url tm_url (string name) {
if (starts (name, "tmfs://")) return tmfs_url (name (7, N (name)));
else return url_general (name, URL_UNIX);
}

bool url_test (url name, string filter) {
if (filter == "") return true;
int i, n= N(filter);
Expand Down Expand Up @@ -174,11 +169,7 @@ complete (url base, url u, string filter, bool flag) {
if (url_test (comp, filter)) return u;
return url_none ();
}
failed_error << "base = " << base << LF;
failed_error << "u = " << u << LF;
failed_error << "filter= " << filter << LF;
ASSERT (is_rooted (comp), "unrooted url");
TM_FAILED ("bad protocol in url");
return u;
}
if (is_root (u)) {
// FIXME: test filter flags here
Expand Down
1 change: 0 additions & 1 deletion src/System/Classes/tm_url.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "tree.hpp"
#include "tm_debug.hpp"

url tm_url (string name);
bool is_secure (url u); // is u secure?

/******************************************************************************
Expand Down
6 changes: 0 additions & 6 deletions src/System/Classes/tmfs_url.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@

#include "tmfs_url.hpp"

tmfs_url::tmfs_url (string name)
: url (url_root ("tmfs") * url_get_name (name)) {}

tmfs_url::tmfs_url (const char* name)
: url (url_root ("tmfs") * url_get_name (string (name))) {}

bool
is_tmfs_protocol (url u, string protocol) {
return u->t == protocol ||
Expand Down
2 changes: 1 addition & 1 deletion src/Texmacs/Data/new_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ latex_expand (tree doc, url name) {

tree
latex_expand (tree doc) {
tm_view vw= concrete_view (tm_url (as_string (extract (doc, "view"))));
tm_view vw= concrete_view (url_system (as_string (extract (doc, "view"))));
tree body= vw->ed->exec_latex (extract (doc, "body"));
doc= change_doc_attr (doc, "body", body);
return remove_doc_attr (doc, "view");
Expand Down
2 changes: 1 addition & 1 deletion src/Texmacs/Data/new_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ abstract_view (tm_view vw) {
string name= encode_url (vw->buf->buf->name);
//cout << vw->buf->buf->name << " -> " << name << "\n";
string nr = as_string (vw->nr);
return tm_url ("tmfs://view/" * nr * "/" * name);
return url_system ("tmfs://view/" * nr * "/" * name);
}

tm_view
Expand Down
2 changes: 1 addition & 1 deletion src/Texmacs/Window/tm_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ embedded_name (url name) {
static int nr= 0;
if (!is_none (name)) return name;
nr++;
return tm_url (string ("tmfs://aux/TeXmacs-input-" * as_string (nr)));
return url_system (string ("tmfs://aux/TeXmacs-input-" * as_string (nr)));
}

tree
Expand Down
4 changes: 2 additions & 2 deletions xmake/packages.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

-- The following versions are adopted on macOS/Windows/ArchLinux
-- We will use the system provided packages on Ubuntu 22.04/Debian 12/...
local LOLLY_VERSION = "1.3.5"
local LOLLY_VERSION = "1.3.6"
local TBOX_VERSION = "1.7.5"
local CPR_VERSION = "1.10.5"
local CURL_VERSION = "8.4.0"
Expand All @@ -47,7 +47,7 @@ package("lolly")
add_deps("cpr")
end

add_versions("v" .. LOLLY_VERSION, "95f371e041c69b2a287cf6735c7ae39de7f9bce7")
add_versions("v" .. LOLLY_VERSION, "3c0502ac6a090742c9d3b4eaaf4b2f770ef61fa3")

on_install("linux", "macosx", "mingw", "wasm", "windows", function (package)
local configs = {}
Expand Down

0 comments on commit 04540a8

Please sign in to comment.