mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
search with google editor and console action
This commit is contained in:
@@ -224,7 +224,7 @@ public class LanguageConsoleImpl implements Disposable, TypeSafeDataProvider {
|
||||
private void setupComponents() {
|
||||
setupEditorDefault(myConsoleEditor);
|
||||
setupEditorDefault(myHistoryViewer);
|
||||
myConsoleEditor.addEditorMouseListener(EditorActionUtil.createEditorPopupHandler(IdeActions.GROUP_CUT_COPY_PASTE));
|
||||
myConsoleEditor.addEditorMouseListener(EditorActionUtil.createEditorPopupHandler(IdeActions.GROUP_CONSOLE_EDITOR_POPUP));
|
||||
//noinspection PointlessBooleanExpression,ConstantConditions
|
||||
if (SEPARATOR_THICKNESS > 0 && myShowSeparatorLine) {
|
||||
myHistoryViewer.getComponent().setBorder(new SideBorder(Color.LIGHT_GRAY, SideBorder.BOTTOM));
|
||||
|
||||
@@ -894,7 +894,7 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo
|
||||
if (group == null) {
|
||||
group = (ActionGroup)actionManager.getAction(CONSOLE_VIEW_POPUP_MENU);
|
||||
}
|
||||
final ActionPopupMenu menu = actionManager.createActionPopupMenu(ActionPlaces.UNKNOWN, group);
|
||||
final ActionPopupMenu menu = actionManager.createActionPopupMenu(ActionPlaces.EDITOR_POPUP, group);
|
||||
menu.getComponent().show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY());
|
||||
}
|
||||
|
||||
@@ -1092,13 +1092,6 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo
|
||||
}
|
||||
}
|
||||
|
||||
public static class CopyAction extends EditorCopyAction {
|
||||
@Override
|
||||
protected boolean isEnabled(AnActionEvent e) {
|
||||
return super.isEnabled(e) && e.getData(LangDataKeys.CONSOLE_VIEW) != null;
|
||||
}
|
||||
}
|
||||
|
||||
private class MyHighlighter extends DocumentAdapter implements EditorHighlighter {
|
||||
private HighlighterClient myEditor;
|
||||
|
||||
|
||||
@@ -82,6 +82,7 @@ public interface IdeActions {
|
||||
@NonNls String GROUP_MAIN_MENU = "MainMenu";
|
||||
@NonNls String GROUP_MAIN_TOOLBAR = "MainToolBar";
|
||||
@NonNls String GROUP_EDITOR_POPUP = "EditorPopupMenu";
|
||||
@NonNls String GROUP_CONSOLE_EDITOR_POPUP = "ConsoleEditorPopupMenu";
|
||||
@NonNls String GROUP_CUT_COPY_PASTE = "CutCopyPasteGroup";
|
||||
@NonNls String GROUP_EDITOR_TAB_POPUP = "EditorTabPopupMenu";
|
||||
|
||||
|
||||
@@ -27,6 +27,12 @@ public class PasteAction extends AnAction implements DumbAware {
|
||||
|
||||
PasteProvider provider = PlatformDataKeys.PASTE_PROVIDER.getData(dataContext);
|
||||
presentation.setEnabled(provider != null && provider.isPastePossible(dataContext));
|
||||
if (event.getPlace().equals(ActionPlaces.EDITOR_POPUP) && provider != null) {
|
||||
presentation.setVisible(presentation.isEnabled());
|
||||
}
|
||||
else {
|
||||
presentation.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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 com.intellij.ide.actions;
|
||||
|
||||
import com.intellij.ide.BrowserUtil;
|
||||
import com.intellij.ide.CopyProvider;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.ide.CopyPasteManager;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
public class SearchWebAction extends AnAction implements DumbAware {
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
DataContext dataContext = e.getDataContext();
|
||||
CopyProvider provider = PlatformDataKeys.COPY_PROVIDER.getData(dataContext);
|
||||
if (provider == null) {
|
||||
return;
|
||||
}
|
||||
provider.performCopy(dataContext);
|
||||
Transferable contents = CopyPasteManager.getInstance().getContents();
|
||||
String string;
|
||||
try {
|
||||
string = contents == null? null : (String)contents.getTransferData(DataFlavor.stringFlavor);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return;
|
||||
}
|
||||
if (StringUtil.isNotEmpty(string)) {
|
||||
BrowserUtil.launchBrowser("http://www.google.com/search?q="+ URLEncoder.encode(string));
|
||||
}
|
||||
}
|
||||
|
||||
public void update(AnActionEvent event) {
|
||||
Presentation presentation = event.getPresentation();
|
||||
DataContext dataContext = event.getDataContext();
|
||||
CopyProvider provider = PlatformDataKeys.COPY_PROVIDER.getData(dataContext);
|
||||
boolean available = provider != null && provider.isCopyEnabled(dataContext);
|
||||
presentation.setEnabled(available);
|
||||
presentation.setVisible(available);
|
||||
}
|
||||
}
|
||||
@@ -94,7 +94,7 @@ class EventLogConsole {
|
||||
editor.addEditorMouseListener(new EditorPopupHandler() {
|
||||
public void invokePopup(final EditorMouseEvent event) {
|
||||
final ActionManager actionManager = ActionManager.getInstance();
|
||||
final ActionPopupMenu menu = actionManager.createActionPopupMenu(ActionPlaces.UNKNOWN, createPopupActions(actionManager, clearLog));
|
||||
final ActionPopupMenu menu = actionManager.createActionPopupMenu(ActionPlaces.EDITOR_POPUP, createPopupActions(actionManager, clearLog));
|
||||
final MouseEvent mouseEvent = event.getMouseEvent();
|
||||
menu.getComponent().show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY());
|
||||
}
|
||||
@@ -103,9 +103,8 @@ class EventLogConsole {
|
||||
}
|
||||
|
||||
private DefaultActionGroup createPopupActions(ActionManager actionManager, ClearLog action) {
|
||||
DefaultActionGroup group = new DefaultActionGroup();
|
||||
group.add(new EditorCopyAction());
|
||||
group.add(actionManager.getAction(IdeActions.ACTION_COMPARE_CLIPBOARD_WITH_SELECTION));
|
||||
AnAction[] children = ((ActionGroup)actionManager.getAction(IdeActions.GROUP_CONSOLE_EDITOR_POPUP)).getChildren(null);
|
||||
DefaultActionGroup group = new DefaultActionGroup(children);
|
||||
group.addSeparator();
|
||||
group.add(action);
|
||||
return group;
|
||||
|
||||
+2
-1
@@ -134,7 +134,8 @@ public class MultiplePasteAction extends AnAction implements DumbAware {
|
||||
private static boolean isEnabled(AnActionEvent e) {
|
||||
Object component = e.getData(PlatformDataKeys.CONTEXT_COMPONENT);
|
||||
if (!(component instanceof JComponent)) return false;
|
||||
if (e.getData(PlatformDataKeys.EDITOR) != null) return true;
|
||||
Editor editor = e.getData(PlatformDataKeys.EDITOR);
|
||||
if (editor != null) return !editor.isViewer();
|
||||
Action pasteAction = ((JComponent)component).getActionMap().get(DefaultEditorKit.pasteAction);
|
||||
return pasteAction != null;
|
||||
}
|
||||
|
||||
@@ -64,5 +64,10 @@ public class SimplePasteAction extends EditorAction {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(Editor editor, DataContext dataContext) {
|
||||
return !editor.isViewer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4611,6 +4611,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
|
||||
|
||||
@Override
|
||||
public boolean isCutVisible(@NotNull DataContext dataContext) {
|
||||
if (!isCutEnabled(dataContext)) return false;
|
||||
return getSelectionModel().hasSelection() || getSelectionModel().hasBlockSelection();
|
||||
}
|
||||
|
||||
|
||||
@@ -277,6 +277,8 @@ action.$Cut.text=Cu_t
|
||||
action.$Cut.description=Cut to clipboard
|
||||
action.$Copy.text=_Copy
|
||||
action.$Copy.description=Copy to clipboard
|
||||
action.$SearchWeb.text=_Search with Google
|
||||
action.$SearchWeb.description=Search selection with Google
|
||||
action.CopyPaths.text=C_opy Paths
|
||||
action.CopyPaths.description=Copy paths corresponding to selected files or directories to clipboard
|
||||
action.CopyReference.text=Cop_y Reference
|
||||
|
||||
@@ -775,8 +775,7 @@
|
||||
</group>
|
||||
|
||||
<group id="ConsoleView.PopupMenu">
|
||||
<action id="ConsoleView.Copy" class="com.intellij.execution.impl.ConsoleViewImpl$CopyAction"/>
|
||||
<reference ref="CompareClipboardWithSelection"/>
|
||||
<reference ref="ConsoleEditorPopupMenu"/>
|
||||
<separator/>
|
||||
<action id="ConsoleView.ClearAll" class="com.intellij.execution.impl.ConsoleViewImpl$ClearAllAction"/>
|
||||
</group>
|
||||
|
||||
@@ -406,11 +406,19 @@
|
||||
<reference ref="PasteMultiple"/>
|
||||
<reference ref="EditorPasteSimple"/>
|
||||
<reference ref="EditorToggleColumnMode"/>
|
||||
<action id="$SearchWeb" class="com.intellij.ide.actions.SearchWebAction"/>
|
||||
<separator/>
|
||||
<reference ref="CompareClipboardWithSelection"/>
|
||||
<reference ref="ChangeFileEncodingGroup"/>
|
||||
</group>
|
||||
|
||||
<group id="ConsoleEditorPopupMenu">
|
||||
<reference ref="CutCopyPasteGroup"/>
|
||||
<separator/>
|
||||
<reference ref="CompareClipboardWithSelection"/>
|
||||
<reference ref="$SearchWeb"/>
|
||||
</group>
|
||||
|
||||
<group id="EditorTabPopupMenu">
|
||||
<reference ref="CloseEditorsGroup"/>
|
||||
<separator/>
|
||||
|
||||
Reference in New Issue
Block a user