Skip to content

Commit

Permalink
Code review:
Browse files Browse the repository at this point in the history
1. create action and enums and util package.
2. create IconLoadUtil.java process icon file.
3. create BrowserEngineType.java control engine type.
  • Loading branch information
727474430 committed Mar 20, 2020
1 parent fce82e0 commit dc497de
Show file tree
Hide file tree
Showing 12 changed files with 327 additions and 227 deletions.
46 changes: 0 additions & 46 deletions src/com/raindrop/SearchBaiDu.java

This file was deleted.

44 changes: 0 additions & 44 deletions src/com/raindrop/SearchDuckduckgo.java

This file was deleted.

46 changes: 0 additions & 46 deletions src/com/raindrop/SearchGoogle.java

This file was deleted.

45 changes: 0 additions & 45 deletions src/com/raindrop/SearchInBing.java

This file was deleted.

46 changes: 0 additions & 46 deletions src/com/raindrop/SearchStackOverflow.java

This file was deleted.

51 changes: 51 additions & 0 deletions src/com/raindrop/action/SearchBaiDu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.raindrop.action;

import com.intellij.ide.BrowserUtil;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.SelectionModel;
import com.intellij.openapi.util.text.StringUtil;
import com.raindrop.enums.BrowserEngineType;
import com.raindrop.util.IconLoadUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
* @name: com.raindrop.action.SearchBaiDu.java
* @description: BaiDu search action
* @author: Raindrop
* @create Time: 2018/5/16 20:47
*/
public class SearchBaiDu extends AnAction {

private static final Logger logger = LoggerFactory.getLogger(SearchBaiDu.class);

public SearchBaiDu() {
super(null, null, IconLoadUtil.loadByPath("icon/baidu.png"));
}

@Override
public void actionPerformed(AnActionEvent e) {
// get editor
final Editor editor = e.getData(PlatformDataKeys.EDITOR);
// get select model
SelectionModel selectionModel = editor.getSelectionModel();
// get user selected text
String text = selectionModel.getSelectedText();
if (!StringUtil.isEmpty(text)) {
try {
text = URLEncoder.encode(text, "utf-8");
} catch (UnsupportedEncodingException ex) {
logger.error("BaiDu search url encode error: {}", ex.getMessage());
}
logger.info("BaiDu search text : {}", text);
BrowserUtil.browse(BrowserEngineType.BAIDU_ENGINE.getEnginePath() + text);
}
}

}
51 changes: 51 additions & 0 deletions src/com/raindrop/action/SearchDuckDuckGo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.raindrop.action;

import com.intellij.ide.BrowserUtil;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.SelectionModel;
import com.intellij.openapi.util.text.StringUtil;
import com.raindrop.enums.BrowserEngineType;
import com.raindrop.util.IconLoadUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
* @name: com.raindrop.action.SearchDuckDuckGo.java
* @description: DuckDuckGo search action
* @author: Raindrop
* @create Time: 2018/5/16 20:47
*/
public class SearchDuckDuckGo extends AnAction {

private static final Logger logger = LoggerFactory.getLogger(SearchDuckDuckGo.class);

public SearchDuckDuckGo() {
super(null, null, IconLoadUtil.loadByPath("icon/duckduckgo.png"));
}

@Override
public void actionPerformed(AnActionEvent e) {
// get editor
final Editor editor = e.getData(PlatformDataKeys.EDITOR);
// get select model
SelectionModel selectionModel = editor.getSelectionModel();
// get user selected text
String text = selectionModel.getSelectedText();
if (!StringUtil.isEmpty(text)) {
try {
text = URLEncoder.encode(text, "utf-8");
} catch (UnsupportedEncodingException ex) {
logger.error("DuckDuckGo search url encode error: {}", ex.getMessage());
}
logger.info("DuckDuckGo search text : {}", text);
BrowserUtil.browse(BrowserEngineType.DUCK_ENGINE.getEnginePath() + text);
}
}

}
51 changes: 51 additions & 0 deletions src/com/raindrop/action/SearchGoogle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.raindrop.action;

import com.intellij.ide.BrowserUtil;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.SelectionModel;
import com.intellij.openapi.util.text.StringUtil;
import com.raindrop.enums.BrowserEngineType;
import com.raindrop.util.IconLoadUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
* @name: com.raindrop.action.SearchGoogle.java
* @description: Google search action
* @author: Raindrop
* @create Time: 2018/5/16 20:47
*/
public class SearchGoogle extends AnAction {

private static final Logger logger = LoggerFactory.getLogger(SearchGoogle.class);

public SearchGoogle() {
super(null, null, IconLoadUtil.loadByPath("icon/chrome.png"));
}

@Override
public void actionPerformed(AnActionEvent e) {
// get editor
final Editor editor = e.getData(PlatformDataKeys.EDITOR);
// get select model
SelectionModel selectionModel = editor.getSelectionModel();
// get user selected text
String text = selectionModel.getSelectedText();
if (!StringUtil.isEmpty(text)) {
try {
text = URLEncoder.encode(text, "utf-8");
} catch (UnsupportedEncodingException ex) {
logger.error("Google search url encode error: {}", ex.getMessage());
}
logger.info("Google search text : {}", text);
BrowserUtil.browse(BrowserEngineType.GOOGLE_ENGINE.getEnginePath() + text);
}
}

}
Loading

0 comments on commit dc497de

Please sign in to comment.