-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
luojunhui
committed
Jul 12, 2019
1 parent
978e724
commit 7c8fb2d
Showing
13 changed files
with
607 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
# touch-fish | ||
一款jetbrains旗下的idea上touch fish的插件 | ||
|
||
# 安装 | ||
以IDEA为例: | ||
```Intellij IDEA File——>Settings——>IDE setttings——>Plugins——>Install plugin from disk``` | ||
|
||
选择`touch-fish.jar`,完成后重启IDEA. | ||
|
||
# 使用 | ||
|
||
> 1. 打开settings下的`touch fish`,输入文本文件的绝对路径/当前记录行/加载行数后保存. | ||
> 2. 快捷键↑向上读取内容,↓向下读取内容. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<idea-plugin> | ||
<id>cn.luojunhui.touchfish</id><!--插件id,不能和其他插件项目重复,推荐com.xxx.xxx的格式 --> | ||
<name>Touch Fish</name><!--插件名称 --> | ||
<version>1.0</version><!--插件版本号 --> | ||
<vendor email="yulewg@gmail.com" url="https://github.com/luojunhui/touch-fish">junhui</vendor> | ||
|
||
<!--插件描述信息,在这里可以介绍你的插件内容,支持HTML标签 --> | ||
<description> | ||
<![CDATA[ | ||
开启一个toolWindow展示文件的文本内容.<br> | ||
<ol> | ||
<li>打开settings的Other Settings下的<strong>touch fish<strong></li> | ||
<li>输入文本的绝对路径</li> | ||
<li>输入阅读的行数和每次阅读多少行</li> | ||
<li>快捷键↑向上读取内容</li> | ||
<li>快捷键↓向下读取内容</li> | ||
<li>在keymap里可以给本插件设置快捷键,可以快速呼出与隐藏</li> | ||
</ol> | ||
]]> | ||
</description> | ||
|
||
<!--插件版本变更日志,支持HTML标签 --> | ||
<!-- <change-notes>--> | ||
<!-- </change-notes>--> | ||
|
||
|
||
<idea-version since-build="145"/> | ||
<depends>com.intellij.modules.lang</depends> | ||
|
||
<extensions defaultExtensionNs="com.intellij"> | ||
<applicationConfigurable groupId="other" instance="config.BookConfigurable"></applicationConfigurable> | ||
<applicationService serviceInterface="config.ConfigService" serviceImplementation="config.ConfigServiceImpl"/> | ||
<toolWindow id="Touch Fish" secondary="false" anchor="bottom" icon="/icons/fish_14.png" | ||
factoryClass="windows.BookWindowFactory"> | ||
</toolWindow> | ||
</extensions> | ||
</idea-plugin> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
package config; | ||
|
||
import com.intellij.ide.ui.UINumericRange; | ||
import com.intellij.openapi.options.ConfigurationException; | ||
import com.intellij.openapi.options.SearchableConfigurable; | ||
import com.intellij.openapi.ui.ComboBox; | ||
import org.jetbrains.annotations.Nls; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import javax.swing.*; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.List; | ||
|
||
/** | ||
* BookConfigurable.class | ||
* @author junhui | ||
*/ | ||
public class BookConfigurable implements SearchableConfigurable { | ||
|
||
private PluginSettingForm form; | ||
|
||
@NotNull | ||
@Override | ||
public String getId() { | ||
return "touch fish"; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public Runnable enableSearch(String option) { | ||
return null; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Class<?> getOriginalClass() { | ||
return null; | ||
} | ||
|
||
@Nls(capitalization = Nls.Capitalization.Title) | ||
@Override | ||
public String getDisplayName() { | ||
return "touch fish"; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public String getHelpTopic() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean isModified(@NotNull JTextField textField, @NotNull String value) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isModified(@NotNull JTextField textField, int value, @NotNull UINumericRange range) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isModified(@NotNull JToggleButton toggleButton, boolean value) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public <T> boolean isModified(@NotNull ComboBox<T> comboBox, T value) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public JComponent getPreferredFocusedComponent() { | ||
return null; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public JComponent createComponent() { | ||
if (this.form == null) { | ||
this.form = new PluginSettingForm(); | ||
} | ||
return this.form.getPluginSettingPanel(); | ||
} | ||
|
||
/** | ||
* IDEA 初始化设置页面时,判断 "Apply" 按钮是否为可用 | ||
* | ||
* @return true 是;false 否 | ||
*/ | ||
@Override | ||
public boolean isModified() { | ||
return this.form != null; | ||
} | ||
|
||
/** | ||
* 用户点击 "Apply" 按钮或 "OK" 按钮之后,会调用此方法 | ||
*/ | ||
@Override | ||
public void apply() throws ConfigurationException { | ||
if (this.form != null){ | ||
Config config = ConfigService.getInstance().getState(); | ||
config.setBookPath(this.form.getBookPath()); | ||
config.setLine(this.form.getLine()); | ||
config.setRowCount(this.form.getRowCount()); | ||
// 更新文本内容 | ||
List<String> lines = null; | ||
try { | ||
lines = Files.readAllLines(Paths.get(config.getBookPath())); | ||
} catch (IOException e) { | ||
} | ||
config.setLines(lines); | ||
|
||
ConfigService.getInstance().setState(config); | ||
} | ||
} | ||
|
||
@Override | ||
public void reset() { | ||
Config confing = ConfigService.getInstance().getState(); | ||
this.form.setBookPath(confing.getBookPath()); | ||
this.form.setLine(confing.getLine()); | ||
this.form.setRowCount(confing.getRowCount()); | ||
} | ||
|
||
/** | ||
* IDEA 销毁设置页面后,会调用此方法 | ||
*/ | ||
@Override | ||
public void disposeUIResources() { | ||
this.form = null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package config; | ||
|
||
import com.intellij.util.xmlb.annotations.OptionTag; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Config.class | ||
* 配置类 | ||
* @author junhui | ||
*/ | ||
public class Config { | ||
@OptionTag | ||
private String bookPath; | ||
@OptionTag | ||
private Integer line = 0; | ||
@OptionTag | ||
private Integer rowCount = 0; | ||
|
||
@OptionTag | ||
private List<String> lines; | ||
|
||
|
||
public Config() { | ||
} | ||
|
||
public String getBookPath() { | ||
return bookPath; | ||
} | ||
|
||
public void setBookPath(String bookPath) { | ||
this.bookPath = bookPath; | ||
} | ||
|
||
public Integer getLine() { | ||
return line; | ||
} | ||
|
||
public void setLine(Integer line) { | ||
this.line = line; | ||
} | ||
|
||
public Integer getRowCount() { | ||
return rowCount; | ||
} | ||
|
||
public void setRowCount(Integer rowCount) { | ||
this.rowCount = rowCount; | ||
} | ||
|
||
public List<String> getLines() { | ||
return lines; | ||
} | ||
|
||
public void setLines(List<String> lines) { | ||
this.lines = lines; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package config; | ||
|
||
import com.intellij.openapi.components.PersistentStateComponent; | ||
import com.intellij.openapi.components.ServiceManager; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* ConfigService.class | ||
* @author junhui | ||
*/ | ||
public interface ConfigService extends PersistentStateComponent<Config> { | ||
/** | ||
* 由 Intellij Platform 保证的单例模式 | ||
* @return ConfigService | ||
*/ | ||
static ConfigService getInstance() { | ||
return ServiceManager.getService(ConfigService.class); | ||
} | ||
|
||
/** | ||
* 获取插件配置 | ||
* @return {@link Config} | ||
*/ | ||
@NotNull | ||
@Override | ||
Config getState(); | ||
|
||
/** | ||
* 修改插件配置 | ||
* @param state 将被保存的新配置对象 | ||
*/ | ||
void setState(@NotNull Config state); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package config; | ||
|
||
import com.intellij.openapi.components.State; | ||
import com.intellij.openapi.components.Storage; | ||
import com.intellij.util.xmlb.XmlSerializerUtil; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/*** | ||
* ConfigServiceImpl.class | ||
* @author junhui | ||
*/ | ||
@State(name = "config", storages = @Storage("bookSettings.xml")) | ||
public class ConfigServiceImpl implements ConfigService { | ||
private Config config; | ||
|
||
public ConfigServiceImpl() { | ||
this.config = new Config(); | ||
} | ||
|
||
@Override | ||
public void setState(@NotNull Config config) { | ||
this.config = config; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public Config getState() { | ||
return this.config; | ||
} | ||
|
||
@Override | ||
public void loadState(@NotNull Config config) { | ||
XmlSerializerUtil.copyBean(config, this.config); | ||
} | ||
|
||
@Override | ||
public void noStateLoaded() { | ||
|
||
} | ||
} |
Oops, something went wrong.