mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 21:21:32 +00:00
New attempt on #9906: allow following hyperlinks via context menu.
Now safer version with the help of Qt.
This commit is contained in:
parent
836300cd33
commit
48b1e8a0ac
@ -673,6 +673,8 @@ Menuset
|
|||||||
#
|
#
|
||||||
Menu "context-hyperlink"
|
Menu "context-hyperlink"
|
||||||
Item "Settings...|S" "inset-settings"
|
Item "Settings...|S" "inset-settings"
|
||||||
|
Separator
|
||||||
|
Item "Open Target...|O" "inset-edit"
|
||||||
End
|
End
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -12,6 +12,9 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include "InsetHyperlink.h"
|
#include "InsetHyperlink.h"
|
||||||
|
|
||||||
|
#include <QtGui/QDesktopServices>
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
#include "Buffer.h"
|
#include "Buffer.h"
|
||||||
#include "DispatchResult.h"
|
#include "DispatchResult.h"
|
||||||
#include "Encoding.h"
|
#include "Encoding.h"
|
||||||
@ -30,6 +33,7 @@
|
|||||||
#include "support/filetools.h"
|
#include "support/filetools.h"
|
||||||
#include "support/gettext.h"
|
#include "support/gettext.h"
|
||||||
#include "support/lstrings.h"
|
#include "support/lstrings.h"
|
||||||
|
#include "support/qstring_helpers.h"
|
||||||
|
|
||||||
#include "frontends/alert.h"
|
#include "frontends/alert.h"
|
||||||
|
|
||||||
@ -106,9 +110,13 @@ bool InsetHyperlink::getStatus(Cursor & cur, FuncRequest const & cmd,
|
|||||||
FuncStatus & flag) const
|
FuncStatus & flag) const
|
||||||
{
|
{
|
||||||
switch (cmd.action()) {
|
switch (cmd.action()) {
|
||||||
case LFUN_INSET_EDIT:
|
case LFUN_INSET_EDIT: {
|
||||||
flag.setEnabled(getParam("type").empty() || getParam("type") == "file:");
|
QUrl url(toqstr(getParam("target")),QUrl::StrictMode);
|
||||||
|
bool url_valid = getParam("type").empty() && url.isValid();
|
||||||
|
|
||||||
|
flag.setEnabled(url_valid || getParam("type") == "file:");
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return InsetCommand::getStatus(cur, cmd, flag);
|
return InsetCommand::getStatus(cur, cmd, flag);
|
||||||
@ -118,7 +126,12 @@ bool InsetHyperlink::getStatus(Cursor & cur, FuncRequest const & cmd,
|
|||||||
|
|
||||||
void InsetHyperlink::viewTarget() const
|
void InsetHyperlink::viewTarget() const
|
||||||
{
|
{
|
||||||
if (getParam("type") == "file:") {
|
if (getParam("type").empty()) { //==Web
|
||||||
|
QUrl url(toqstr(getParam("target")),QUrl::StrictMode);
|
||||||
|
if (!QDesktopServices::openUrl(url))
|
||||||
|
LYXERR0("Unable to open URL!");
|
||||||
|
|
||||||
|
} else if (getParam("type") == "file:") {
|
||||||
FileName url = makeAbsPath(to_utf8(getParam("target")), buffer().filePath());
|
FileName url = makeAbsPath(to_utf8(getParam("target")), buffer().filePath());
|
||||||
string const format = theFormats().getFormatFromFile(url);
|
string const format = theFormats().getFormatFromFile(url);
|
||||||
theFormats().view(buffer(), url, format);
|
theFormats().view(buffer(), url, format);
|
||||||
|
Loading…
Reference in New Issue
Block a user