提交 a3efe7ca 编写于 作者: S Serge Rider

Remove unformatted text action. Fix SQL editor "Edit" menu.

上级 255b04c7
......@@ -22,15 +22,12 @@ import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.editors.text.TextEditorActionContributor;
import org.eclipse.ui.texteditor.BasicTextEditorActionContributor;
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
import org.eclipse.ui.texteditor.RetargetTextEditorAction;
import org.jkiss.dbeaver.core.CoreCommands;
import org.jkiss.dbeaver.core.CoreMessages;
import org.jkiss.dbeaver.core.DBeaverActivator;
import org.jkiss.dbeaver.core.DBeaverUI;
import org.jkiss.dbeaver.ui.ActionUtils;
import org.jkiss.dbeaver.ui.editors.sql.handlers.CopyUnformattedTextAction;
import java.util.ResourceBundle;
......@@ -50,7 +47,6 @@ public class SQLEditorContributor extends TextEditorActionContributor
private RetargetTextEditorAction contentAssistTip;
private RetargetTextEditorAction contentAssistInformation;
private RetargetTextEditorAction contentFormatProposal;
private CopyUnformattedTextAction copyUnformattedTextAction;
public SQLEditorContributor()
{
......@@ -83,8 +79,6 @@ public class SQLEditorContributor extends TextEditorActionContributor
contentAssistInformation = new RetargetTextEditorAction(bundle, getActionResourcePrefix(ACTION_CONTENT_ASSIST_INFORMATION));
contentAssistInformation.setActionDefinitionId(ITextEditorActionDefinitionIds.SHOW_INFORMATION);
copyUnformattedTextAction = new CopyUnformattedTextAction();
}
@Override
......@@ -115,7 +109,6 @@ public class SQLEditorContributor extends TextEditorActionContributor
contentAssistTip.setAction(getAction(activeEditorPart, ACTION_CONTENT_ASSIST_TIP)); //$NON-NLS-1$
contentAssistInformation.setAction(getAction(activeEditorPart, ACTION_CONTENT_ASSIST_INFORMATION)); //$NON-NLS-1$
contentFormatProposal.setAction(getAction(activeEditorPart, ACTION_CONTENT_FORMAT_PROPOSAL)); //$NON-NLS-1$
copyUnformattedTextAction.setEditor(activeEditorPart);
}
}
......@@ -140,10 +133,7 @@ public class SQLEditorContributor extends TextEditorActionContributor
editMenu.add(contentAssistProposal);
editMenu.add(contentAssistTip);
editMenu.add(contentAssistInformation);
MenuManager formatMenu = new MenuManager(CoreMessages.actions_menu_edit_ContentFormat);
editMenu.add(formatMenu);
formatMenu.add(contentFormatProposal);
formatMenu.add(copyUnformattedTextAction);
editMenu.add(contentFormatProposal);
}
IMenuManager navMenu = manager.findMenuUsingPath(IWorkbenchActionConstants.M_NAVIGATE);
if (navMenu != null) {
......
......@@ -151,7 +151,7 @@ public class CopySourceCodeHandler extends AbstractHandler {
SashForm sash = new SashForm(previewPanel, SWT.VERTICAL);
sash.setLayoutData(new GridData(GridData.FILL_BOTH));
createSQLPanel(sash);
Composite targetGroup = UIUtils.createPlaceholder(sash, 1);
Composite targetGroup = UIUtils.createPlaceholder(sash, 1, 5);
targetGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
UIUtils.createControlLabel(targetGroup, "Result");
targetText = new StyledText(targetGroup, SWT.BORDER | SWT.READ_ONLY | SWT.V_SCROLL | SWT.WRAP);
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ui.editors.sql.handlers;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.widgets.Display;
import org.jkiss.dbeaver.model.sql.SQLDialect;
import org.jkiss.dbeaver.ui.TextUtils;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase;
import org.jkiss.dbeaver.ui.editors.sql.syntax.SQLRuleManager;
import org.jkiss.dbeaver.ui.editors.sql.syntax.tokens.SQLCommentToken;
import org.jkiss.utils.Pair;
/**
* CopyUnformattedTextAction
*/
public class CopyUnformattedTextAction extends Action {
private SQLEditorBase sqlEditor;
public CopyUnformattedTextAction()
{
super("Copy Unformatted Text");
setToolTipText("Copies unformatted text to clipboard");
}
@Override
public void run()
{
if (sqlEditor == null) {
return;
}
ITextSelection selection = (ITextSelection) sqlEditor.getSelectionProvider().getSelection();
IDocument document = sqlEditor.getDocumentProvider().getDocument(sqlEditor.getEditorInput());
if (document == null) {
return;
}
int startPos, endPos;
if (selection.getLength() > 1) {
startPos = selection.getOffset();
endPos = startPos + selection.getLength();
} else {
startPos = 0;
endPos = document.getLength();
}
StringBuilder result = new StringBuilder();
SQLRuleManager ruleManager = sqlEditor.getRuleManager();
SQLDialect dialect = sqlEditor.getSyntaxManager().getDialect();
ruleManager.setRange(document, startPos, endPos - startPos);
String[] singleLineComments = dialect.getSingleLineComments();
Pair<String, String> multiLineComments = dialect.getMultiLineComments();
boolean lastWhitespace = false;
try {
for (;;) {
IToken token = ruleManager.nextToken();
if (token.isEOF()) {
break;
}
int tokenOffset = ruleManager.getTokenOffset();
final int tokenLength = ruleManager.getTokenLength();
if (token.isWhitespace()) {
if (!lastWhitespace) {
result.append(' ');
}
lastWhitespace = true;
} else if (token instanceof SQLCommentToken) {
String comment = document.get(tokenOffset, tokenLength);
for (String slc : singleLineComments) {
if (comment.startsWith(slc)) {
if (multiLineComments != null) {
comment = multiLineComments.getFirst() + comment.substring(slc.length()) + multiLineComments.getSecond();
}
break;
}
}
comment = TextUtils.compactWhiteSpaces(comment);
result.append(comment);
} else {
lastWhitespace = false;
result.append(document.get(tokenOffset, tokenLength));
}
}
} catch (BadLocationException e) {
// dump
e.printStackTrace();
}
UIUtils.setClipboardContents(
Display.getCurrent(),
TextTransfer.getInstance(),
result.toString().trim());
}
public void setEditor(SQLEditorBase textEditor)
{
setEnabled(textEditor != null);
this.sqlEditor = textEditor;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册