プラグイン作って覚えたことを淡々と記録するよ(エディタヘッダ編)
Edit→Findで出てくるインクリメンタルサーチ用のパネルは,自分らもいじれるという話。
あのパネルの正体は,EditorSearchComponent(com.intellij.findパッケージ)というJPanelの子どもなんだけど,それを表示している場所がEditorのヘッダ部。
ヘッダ?なるほどEditorにはそんな場所があったのか。都合の良いことにEditorはOpenAPIで公開されている*1ので,さっそくOpenAPIのJavadoc見てみたよ。
setHeaderComponent
void setHeaderComponent(@Nullable
javax.swing.JComponent header)
Set up a header component for this text editor. Please note this is used for textual find feature so your component will most probably will be reset once the user presses Ctrl+F.
使っても良いけどインクリメンタルサーチで上書きされちゃうよって事すか。まあ,それでも良い。
#欲を言えば,フッタも欲しかったな。:-P
ちなみにコードはこんなの。
public class ShowEditorHeaderAction extends EditorAction { public ShowEditorHeaderAction() { super(new Handler()); } private static class Handler extends EditorActionHandler { public void execute(Editor editor, DataContext datacontext) { Header header = new Header(editor); } public boolean isEnabled(Editor editor, DataContext datacontext) { Project project = (Project) DataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(editor.getComponent())); return project != null; } } }
ヘッダコンポーネント(Header)は超やっつけ仕事で,こんなの。