mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-20 18:40:57 +00:00
Add navigation through .md files on BrowserView
This commit is contained in:
parent
12726fedf2
commit
b5679a3f82
@ -795,7 +795,7 @@
|
||||
</menu>
|
||||
<menu text="&Help">
|
||||
<item command="OpenBrowser" text="Readme">
|
||||
<param name="filename" value="data/docs/README.md" />
|
||||
<param name="filename" value="README.md" />
|
||||
</item>
|
||||
<separator />
|
||||
<item command="Launch" text="Quick &Reference">
|
||||
|
@ -133,10 +133,16 @@ foreach(fn ${src_data_files})
|
||||
endforeach()
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_BINARY_DIR}/bin/data/docs/README.md
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/README.md ${CMAKE_BINARY_DIR}/bin/data/docs/README.md
|
||||
OUTPUT ${CMAKE_BINARY_DIR}/bin/data/README.md
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/README.md ${CMAKE_BINARY_DIR}/bin/data/README.md
|
||||
MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/README.md)
|
||||
list(APPEND out_data_files ${CMAKE_BINARY_DIR}/bin/data/docs/README.md)
|
||||
list(APPEND out_data_files ${CMAKE_BINARY_DIR}/bin/data/README.md)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_BINARY_DIR}/bin/data/EULA.txt
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/EULA.txt ${CMAKE_BINARY_DIR}/bin/data/EULA.txt
|
||||
MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/EULA.txt)
|
||||
list(APPEND out_data_files ${CMAKE_BINARY_DIR}/bin/data/EULA.txt)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_BINARY_DIR}/bin/data/docs/LICENSES.md
|
||||
|
@ -100,7 +100,7 @@ void AboutCommand::onExecute(Context* context)
|
||||
author5->Click.connect(
|
||||
[&window]{
|
||||
window->closeWindow(nullptr);
|
||||
App::instance()->mainWindow()->showBrowser("data/docs/LICENSES.md");
|
||||
App::instance()->mainWindow()->showBrowser("docs/LICENSES.md");
|
||||
});
|
||||
|
||||
window->openWindowInForeground();
|
||||
|
@ -8,9 +8,11 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "app/app.h"
|
||||
#include "app/app_menus.h"
|
||||
#include "app/resource_finder.h"
|
||||
#include "app/ui/browser_view.h"
|
||||
#include "app/ui/main_window.h"
|
||||
#include "app/ui/skin/skin_style_property.h"
|
||||
#include "app/ui/skin/skin_theme.h"
|
||||
#include "app/ui/workspace.h"
|
||||
@ -18,6 +20,7 @@
|
||||
#include "base/fs.h"
|
||||
#include "base/split_string.h"
|
||||
#include "she/font.h"
|
||||
#include "ui/alert.h"
|
||||
#include "ui/link_label.h"
|
||||
#include "ui/menu.h"
|
||||
#include "ui/message.h"
|
||||
@ -39,6 +42,25 @@ namespace app {
|
||||
using namespace ui;
|
||||
using namespace app::skin;
|
||||
|
||||
namespace {
|
||||
|
||||
RegisterMessage kLoadFileMessage;
|
||||
|
||||
class LoadFileMessage : public Message {
|
||||
public:
|
||||
LoadFileMessage(const std::string& file)
|
||||
: Message(kLoadFileMessage)
|
||||
, m_file(file) {
|
||||
}
|
||||
|
||||
const std::string& file() const { return m_file; }
|
||||
|
||||
private:
|
||||
std::string m_file;
|
||||
};
|
||||
|
||||
} // annonymous namespace
|
||||
|
||||
// TODO This is not the best implementation, but it's "good enough"
|
||||
// for a first version.
|
||||
class BrowserView::CMarkBox : public Widget {
|
||||
@ -63,13 +85,19 @@ public:
|
||||
|
||||
void loadFile(const std::string& inputFile) {
|
||||
std::string file = inputFile;
|
||||
if (file.size() >= 5 && file.substr(0, 5) == "data/") {
|
||||
{
|
||||
ResourceFinder rf;
|
||||
rf.includeDataDir(file.substr(5).c_str());
|
||||
rf.includeDataDir(file.c_str());
|
||||
if (rf.findFirst())
|
||||
file = rf.filename();
|
||||
}
|
||||
|
||||
if (!base::is_file(file)) {
|
||||
Alert::show("Error<<File <%s> not found||&Close",
|
||||
file.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
cmark_parser* parser = cmark_parser_new(CMARK_OPT_DEFAULT);
|
||||
FILE* fp = base::open_file_raw(file, "rb");
|
||||
if (fp) {
|
||||
@ -184,6 +212,11 @@ private:
|
||||
}
|
||||
|
||||
bool onProcessMessage(Message* msg) override {
|
||||
if (msg->type() == kLoadFileMessage) {
|
||||
loadFile(static_cast<LoadFileMessage*>(msg)->file());
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (msg->type()) {
|
||||
|
||||
case kMouseWheelMessage: {
|
||||
@ -429,6 +462,16 @@ private:
|
||||
void addLink(const std::string& url, const std::string& text) {
|
||||
auto label = new LinkLabel(url, text);
|
||||
|
||||
if (url.find(':') == std::string::npos) {
|
||||
label->setUrl("");
|
||||
label->Click.connect(
|
||||
[this, url]{
|
||||
Message* msg = new LoadFileMessage(url);
|
||||
msg->addRecipient(this);
|
||||
Manager::getDefault()->enqueueMessage(msg);
|
||||
});
|
||||
}
|
||||
|
||||
// Uncomment this line to debug labels
|
||||
//label->setBgColor(gfx::rgba((rand()%128)+128, 128, 128));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user