summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2014-01-04 04:37:14 +0000
committerDavid Robillard <d@drobilla.net>2014-01-04 04:37:14 +0000
commit39fd0894a1402f23ce4b5243ec595764aa11625c (patch)
treecb08507d5cf0193d907d0514dbd407b297d866ad /src
parentbcc0b2d27797d07bf48de1b3a03dea7f878cb2b6 (diff)
downloadingen-39fd0894a1402f23ce4b5243ec595764aa11625c.tar.gz
ingen-39fd0894a1402f23ce4b5243ec595764aa11625c.tar.bz2
ingen-39fd0894a1402f23ce4b5243ec595764aa11625c.zip
Fix documentation pane.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@5256 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r--src/client/PluginModel.cpp81
-rw-r--r--src/gui/Port.cpp20
-rw-r--r--src/gui/Port.hpp2
3 files changed, 63 insertions, 40 deletions
diff --git a/src/client/PluginModel.cpp b/src/client/PluginModel.cpp
index 1025a7dc..a85a9968 100644
--- a/src/client/PluginModel.cpp
+++ b/src/client/PluginModel.cpp
@@ -272,37 +272,43 @@ PluginModel::get_lv2_icon_path(const LilvPlugin* plugin)
}
static std::string
-heading(const std::string& text, bool html)
+heading(const std::string& text, bool html, unsigned level)
{
if (html) {
- return std::string("<h2>") + text + "</h2>\n";
+ const std::string tag = std::string("h") + std::to_string(level);
+ return std::string("<") + tag + ">" + text + "</" + tag + ">\n";
} else {
return text + ":\n\n";
}
}
+static std::string
+link(const std::string& addr, bool html)
+{
+ if (html) {
+ return std::string("<a href=\"") + addr + "\">" + addr + "</a>";
+ } else {
+ return addr;
+ }
+}
+
std::string
-PluginModel::documentation(bool html) const
+PluginModel::get_documentation(const LilvNode* subject, bool html) const
{
std::string doc;
- LilvNode* subject = (_lilv_plugin)
- ? lilv_node_duplicate(lilv_plugin_get_uri(_lilv_plugin))
- : lilv_new_uri(_lilv_world, uri().c_str());
-
LilvNode* lv2_documentation = lilv_new_uri(_lilv_world,
- LILV_NS_LV2 "documentation");
+ LV2_CORE__documentation);
LilvNode* rdfs_comment = lilv_new_uri(_lilv_world,
LILV_NS_RDFS "comment");
LilvNodes* vals = lilv_world_find_nodes(
_lilv_world, subject, lv2_documentation, NULL);
+ const bool doc_is_html = vals;
if (!vals) {
vals = lilv_world_find_nodes(
_lilv_world, subject, rdfs_comment, NULL);
- // TODO: If not html, must convert to plain text
}
- doc += heading(human_name(), html);
if (vals) {
const LilvNode* val = lilv_nodes_get_first(vals);
@@ -310,41 +316,52 @@ PluginModel::documentation(bool html) const
doc += lilv_node_as_string(val);
}
}
+
+ if (html && !doc_is_html) {
+ for (std::size_t i = 0; i < doc.size(); ++i) {
+ if (doc.substr(i, 2) == "\n\n") {
+ doc.replace(i, 2, "<br/><br/>");
+ i += strlen("<br/><br/>");
+ }
+ }
+ }
+
lilv_node_free(rdfs_comment);
lilv_node_free(lv2_documentation);
- lilv_node_free(subject);
- lilv_nodes_free(vals);
return doc;
}
std::string
-PluginModel::port_documentation(uint32_t index) const
+PluginModel::documentation(const bool html) const
{
- std::string doc;
+ LilvNode* subject = (_lilv_plugin)
+ ? lilv_node_duplicate(lilv_plugin_get_uri(_lilv_plugin))
+ : lilv_new_uri(_lilv_world, uri().c_str());
- if (!_lilv_plugin)
- return doc;
+ const std::string doc(get_documentation(subject, html));
- const LilvPort* port = lilv_plugin_get_port_by_index(_lilv_plugin, index);
+ lilv_node_free(subject);
- //LilvNode lv2_documentation = lilv_new_uri(
- // _lilv_world, LILV_NAMESPACE_LV2 "documentation");
- LilvNode* rdfs_comment = lilv_new_uri(
- _lilv_world, "http://www.w3.org/2000/01/rdf-schema#comment");
+ return (heading(human_name(), html, 2) +
+ link(uri(), html) + (html ? "<br/><br/>" : "\n\n") +
+ doc);
+}
- LilvNodes* vals = lilv_port_get_value(_lilv_plugin,
- port,
- rdfs_comment);
- if (vals) {
- const LilvNode* val = lilv_nodes_get_first(vals);
- if (lilv_node_is_string(val)) {
- doc += lilv_node_as_string(val);
- }
+std::string
+PluginModel::port_documentation(uint32_t index, bool html) const
+{
+ if (!_lilv_plugin) {
+ return "";
}
- lilv_node_free(rdfs_comment);
- lilv_nodes_free(vals);
- return doc;
+
+ const LilvPort* port = lilv_plugin_get_port_by_index(_lilv_plugin, index);
+ if (!port) {
+ return "";
+ }
+
+ return (heading(port_human_name(index), html, 2) +
+ get_documentation(lilv_port_get_node(_lilv_plugin, port), html));
}
const LilvPort*
diff --git a/src/gui/Port.cpp b/src/gui/Port.cpp
index 92775483..2bdf2e43 100644
--- a/src/gui/Port.cpp
+++ b/src/gui/Port.cpp
@@ -32,6 +32,7 @@
#include "Style.hpp"
#include "WidgetFactory.hpp"
#include "WindowFactory.hpp"
+#include "ingen_config.h"
using namespace Ingen::Client;
using namespace std;
@@ -434,22 +435,27 @@ Port::property_changed(const Raul::URI& key, const Atom& value)
}
}
-void
-Port::set_selected(gboolean b)
+bool
+Port::on_selected(gboolean b)
{
- if (b != get_selected()) {
- Ganv::Port::set_selected(b);
+ if (b) {
SPtr<const PortModel> pm = _port_model.lock();
- if (pm && b) {
+ if (pm) {
SPtr<const BlockModel> block = dynamic_ptr_cast<BlockModel>(pm->parent());
GraphWindow* win = _app.window_factory()->parent_graph_window(block);
if (win && win->documentation_is_visible() && block->plugin_model()) {
+ bool html = false;
+#ifdef HAVE_WEBKIT
+ html = true;
+#endif
const std::string& doc = block->plugin_model()->port_documentation(
- pm->index());
- win->set_documentation(doc, false);
+ pm->index(), html);
+ win->set_documentation(doc, html);
}
}
}
+
+ return true;
}
} // namespace GUI
diff --git a/src/gui/Port.hpp b/src/gui/Port.hpp
index 16fc5cde..24cddd4e 100644
--- a/src/gui/Port.hpp
+++ b/src/gui/Port.hpp
@@ -64,7 +64,7 @@ public:
void activity(const Atom& value);
void disconnected_from(SPtr<Client::PortModel> port);
- void set_selected(gboolean b);
+ bool on_selected(gboolean b);
private:
Port(App& app,