<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ## 前言 最近工作上在做IDEA插件開發的東西,所以需要深入學習。在網上看到一個比較好的例子,實現一個筆記插件,故實現后發布這篇博客,分享給同樣在學習的你。 (mdNote插件下載地址:https://mangomei.lanzouy.com/iWLPb00tn8vc) 更多細節及實現歡迎下載源碼學習:https://gitee.com/mgang/idea-demo/tree/master/md-note 其實也可以按[第一個IDEA插件hello ide開發](%E7%AC%AC%E4%B8%80%E4%B8%AAIDEA%E6%8F%92%E4%BB%B6helloide%E5%BC%80%E5%8F%91.md)里提到的發布插件的方式,發布到官網插件倉庫。 ## 環境信息 ![](https://img.kancloud.cn/ef/05/ef05bfeaaefe8956aa6d9e7433022112_1280x800.png) (小插曲:之前下載的是最新版的idea ce版2021.3.1,出現插件中文4橫線中文亂碼問題。所以換成2019.3.5版本,沒有上述中文亂碼問題。) ## 主要功能列表及知識點 1. 提供一個視窗,展示要保存的筆記數據(視窗開發) 2. 選中文件內的文本右鍵能加入到筆記數據(右鍵action及彈窗) 3. 點擊保存md按鈕后,生成對應的md筆記(文件選擇器及模板渲染) ## 實現步驟詳細 ### 建立視窗并注冊 通過視窗工廠創建視窗內容,其中`MdNoteUI`是通過`GUI Form`的方式創建(布局和邏輯分離) ![](https://img.kancloud.cn/c9/10/c910733a7a15206646e70201f244e33d_1888x1054.png) ``` java /** * md note 視窗提供者 */ public class MdNoteWindowFactory implements ToolWindowFactory { @Override public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) { // 從toolWindow獲取contentManager ContentManager contentManager = toolWindow.getContentManager(); // 從contentManager獲取contentFactory ContentFactory contentFactory = contentManager.getFactory(); // contentFactory創建內容 MdNoteUI mdNoteUI = new MdNoteUI(project); Content content = contentFactory.createContent(mdNoteUI.view(),"main",true); // 將內容通過contentManager注冊到視窗 contentManager.addContent(content); } } ``` 并注冊到擴展點上。 ~~~ <extensions defaultExtensionNs="com.intellij"> <!-- Add your extensions here --> <toolWindow factoryClass="com.mango.idea.md.note.window.MdNoteWindowFactory" id="MdNote" anchor="right"></toolWindow> </extensions> ~~~ ### 視窗內容設計 按如下布局設計內容 ![](https://img.kancloud.cn/94/fd/94fd9841312463a1c0387981114e71cd_2524x1408.png) ### 選擇文本并右擊保持到筆記 新建action注冊到右鍵菜單`EditorPopupMenu`,取名為`add md note`。 ~~~ <action id="mp-add-note-note" class="com.mango.idea.md.note.action.AddMdNoteAction" text="add md note" description="add md note"> <add-to-group group-id="EditorPopupMenu" anchor="first"/> <keyboard-shortcut keymap="$default" first-keystroke="shift ctrl meta M"/> </action> ~~~ 在選擇文本后點擊`add md note`,彈出標題和描述對話框。 ~~~ /** * 添加md note action */ public class AddMdNoteAction extends AnAction { @Override public void actionPerformed(AnActionEvent e) { // 獲取鼠標選中的文本 String selectedText = e.getRequiredData(CommonDataKeys.EDITOR).getSelectionModel().getSelectedText(); // 獲取當前右鍵的文件名 VirtualFile virtualFile = e.getData(PlatformDataKeys.VIRTUAL_FILE); String fileName = virtualFile.getName(); // 顯示彈框,填寫標題和描述 AddNoteDialog addNoteDialog = new AddNoteDialog(selectedText,fileName); addNoteDialog.showAndGet(); } } ~~~ ![](https://img.kancloud.cn/41/89/4189473e61796ca6abde55d3e7d4a9f6_1450x1450.png) ![](https://img.kancloud.cn/bb/34/bb343440db6130d01b5a8667c483f17b_648x412.png) 確定后,視窗就能正常顯示出筆記。 ### 點擊保存到md保存筆記 輸入筆記標題,并點擊保存到md ![](https://img.kancloud.cn/e2/fa/e2fab7e6f9f562c488e954c8683ccca5_946x1862.png) 最后預覽一下生成的筆記。(使用freemarker做模板生成) ![](https://img.kancloud.cn/9a/e4/9ae492ed29aef13ec50d3cdaaf26f61e_2716x1396.png) ## 總結 * 學習到如何開發設計一個視窗 * 學習到如何獲取鼠標選中的文本 * 學習到如何使用`GUI form`的方式做布局 * 學習到`JTable`做數據展示及清除 * 學習到如何使用`FileChooser`做文件路徑選擇 更多細節及實現歡迎下載源碼學習:https://gitee.com/mgang/idea-demo/tree/master/md-note
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看