Make getting hyperlinks from ids useable throughtout the codebase
This commit is contained in:
parent
fdaf857885
commit
0d665495b8
@ -319,6 +319,7 @@ void play_canberra_sound(const char *which_sound, const char *event_id);
|
||||
#endif
|
||||
SPRITE_MAP_HANDLE alloc_sprite_map(unsigned int, unsigned int);
|
||||
SPRITE_MAP_HANDLE free_sprite_map(SPRITE_MAP_HANDLE);
|
||||
const char* get_hyperlink_for_id(const HYPERLINK_POOL_HANDLE, hyperlink_id_type id, bool only_url);
|
||||
|
||||
static inline void safe_close(int fd, const char* file UNUSED, const int line UNUSED) {
|
||||
#if 0
|
||||
|
||||
@ -137,11 +137,11 @@ get_id_for_hyperlink(Screen *screen, const char *id, const char *url) {
|
||||
}
|
||||
|
||||
const char*
|
||||
get_hyperlink_for_id(Screen *screen, hyperlink_id_type id) {
|
||||
HyperLinkPool *pool = (HyperLinkPool*)screen->hyperlink_pool;
|
||||
get_hyperlink_for_id(const HYPERLINK_POOL_HANDLE handle, hyperlink_id_type id, bool only_url) {
|
||||
const HyperLinkPool *pool = (HyperLinkPool*)handle;
|
||||
HyperLinkEntry *s, *tmp;
|
||||
HASH_ITER(hh, pool->hyperlinks, s, tmp) {
|
||||
if (s->id == id) return strstr(s->key, ":") + 1;
|
||||
if (s->id == id) return only_url ? strstr(s->key, ":") + 1 : s->key;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -15,4 +15,3 @@ hyperlink_id_type get_id_for_hyperlink(Screen*, const char*, const char*);
|
||||
hyperlink_id_type remap_hyperlink_ids(Screen *self, hyperlink_id_type *map);
|
||||
PyObject* screen_hyperlinks_as_list(Screen *screen);
|
||||
void screen_garbage_collect_hyperlink_pool(Screen *screen);
|
||||
const char* get_hyperlink_for_id(Screen *screen, hyperlink_id_type id);
|
||||
|
||||
@ -1956,7 +1956,7 @@ screen_open_url(Screen *self) {
|
||||
if (!self->url_ranges.count) return false;
|
||||
hyperlink_id_type hid = hyperlink_id_for_range(self, self->url_ranges.items);
|
||||
if (hid) {
|
||||
const char *url = get_hyperlink_for_id(self, hid);
|
||||
const char *url = get_hyperlink_for_id(self->hyperlink_pool, hid, true);
|
||||
if (url) {
|
||||
CALLBACK("open_url", "sH", url, hid);
|
||||
return true;
|
||||
@ -2014,7 +2014,7 @@ static PyObject*
|
||||
hyperlink_for_id(Screen *self, PyObject *val) {
|
||||
unsigned long id = PyLong_AsUnsignedLong(val);
|
||||
if (id > HYPERLINK_MAX_NUMBER) { PyErr_SetString(PyExc_IndexError, "Out of bounds"); return NULL; }
|
||||
return Py_BuildValue("s", get_hyperlink_for_id(self, id));
|
||||
return Py_BuildValue("s", get_hyperlink_for_id(self->hyperlink_pool, id, true));
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
@ -2768,7 +2768,7 @@ hyperlink_at(Screen *self, PyObject *args) {
|
||||
if (!self->url_ranges.count) Py_RETURN_NONE;
|
||||
hyperlink_id_type hid = hyperlink_id_for_range(self, self->url_ranges.items);
|
||||
if (!hid) Py_RETURN_NONE;
|
||||
const char *url = get_hyperlink_for_id(self, hid);
|
||||
const char *url = get_hyperlink_for_id(self->hyperlink_pool, hid, true);
|
||||
return Py_BuildValue("s", url);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user