提交 f5577950 编写于 作者: S serge-rider

SQL editor: hyperlinks navigation error handle

上级 2a684ed0
......@@ -32,6 +32,7 @@ import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.PreferencesUtil;
import org.eclipse.ui.internal.editors.text.EditorsPlugin;
......@@ -403,6 +404,8 @@ public abstract class SQLEditorBase extends BaseTextEditor implements IErrorVisu
addAction(menu, GROUP_SQL_EXTRAS, SQLEditorContributor.ACTION_CONTENT_ASSIST_PROPOSAL);
addAction(menu, GROUP_SQL_EXTRAS, SQLEditorContributor.ACTION_CONTENT_ASSIST_TIP);
addAction(menu, GROUP_SQL_EXTRAS, SQLEditorContributor.ACTION_CONTENT_ASSIST_INFORMATION);
menu.insertBefore(IWorkbenchActionConstants.MB_ADDITIONS, ActionUtils.makeCommandContribution(getSite(), "org.jkiss.dbeaver.ui.editors.sql.navigate.object"));
{
MenuManager formatMenu = new MenuManager("Format", "format");
IAction formatAction = getAction(SQLEditorContributor.ACTION_CONTENT_FORMAT_PROPOSAL);
......
......@@ -24,12 +24,15 @@ import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.TextViewer;
import org.eclipse.jface.text.hyperlink.IHyperlink;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.texteditor.IEditorStatusLine;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase;
import org.jkiss.dbeaver.ui.editors.sql.syntax.SQLHyperlinkDetector;
import org.jkiss.utils.ArrayUtils;
import org.jkiss.utils.CommonUtils;
public class NavigateObjectHandler extends AbstractHandler {
......@@ -65,7 +68,18 @@ public class NavigateObjectHandler extends AbstractHandler {
IRegion curRegion = new Region(selection.getOffset(), 0);
IHyperlink[] hyperLinks = hyperlinkDetector.detectHyperlinks(editor.getTextViewer(), curRegion, false);
return ArrayUtils.isEmpty(hyperLinks) ? null : hyperLinks[0];
if (!ArrayUtils.isEmpty(hyperLinks)) {
return hyperLinks[0];
}
String lastKeyword = hyperlinkDetector.getLastKeyword();
if (!CommonUtils.isEmpty(lastKeyword)) {
IEditorStatusLine statusLine = (IEditorStatusLine)editor.getAdapter(IEditorStatusLine.class);
if (statusLine != null) {
statusLine.setMessage(true, "Can't find metadata object for name '" + lastKeyword + "'", (Image)null);
}
editor.getEditorControl().getDisplay().beep();
}
return null;
}
/*
......
......@@ -16,12 +16,14 @@
*/
package org.jkiss.dbeaver.ui.editors.sql.syntax;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector;
import org.eclipse.jface.text.hyperlink.IHyperlink;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.sql.SQLSyntaxManager;
import org.jkiss.dbeaver.model.struct.DBSObjectReference;
import org.jkiss.dbeaver.ui.editors.entity.EntityHyperlink;
......@@ -35,6 +37,8 @@ import java.util.List;
*/
public class SQLHyperlinkDetector extends AbstractHyperlinkDetector
{
static protected final Log log = Log.getLog(SQLHyperlinkDetector.class);
private SQLContextInformer contextInformer;
public SQLHyperlinkDetector(SQLEditorBase editor, SQLSyntaxManager syntaxManager)
......@@ -63,6 +67,19 @@ public class SQLHyperlinkDetector extends AbstractHyperlinkDetector
}
}
public String getLastKeyword() {
final SQLIdentifierDetector.WordRegion wordRegion = this.contextInformer.getWordRegion();
if (wordRegion != null) {
final IRegion hlRegion = new Region(wordRegion.identStart, wordRegion.identEnd - wordRegion.identStart);
try {
return contextInformer.getEditor().getDocument().get(hlRegion.getOffset(), hlRegion.getLength());
} catch (BadLocationException e) {
log.error(e);
}
}
return null;
}
@Override
public void dispose()
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册