久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

IntelliJ IDEA 插件開發:保存選項卡組,持久保存并

IntelliJ IDEA Plugin Development: Save groups of tabs, save them persistently and reload a set of tabs if requested by the user(IntelliJ IDEA 插件開發:保存選項卡組,持久保存并在用戶請求時重新加載一組選項卡) - I
本文介紹了IntelliJ IDEA 插件開發:保存選項卡組,持久保存并在用戶請求時重新加載一組選項卡的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我目前正在編寫一個 IntelliJ 插件.我希望能夠存儲/恢復一組選項卡以在不同的選項卡會話之間切換(類似于 會話管理器 或 會話好友).

I am currently at the move to write an IntelliJ plugin. I want to be able to store/restore a set of tabs to switch between different tab sessions (comparable to browser plugins like Session Manager or Session Buddy).

因此我基本上需要三種類型的動作:

Therefore i need basically three types of actions:

  1. 讀取打開的選項卡(使用哪個文件和編輯器?)
  2. 將該信息永久存儲為選項卡會話
  3. 打開選定會話的標簽并關閉所有其他標簽

我查看了可用的操作:IdeActions.java - 似乎沒有我正在尋找的東西.但也許我看錯了地方.誰能告訴我我想要實現的目標是否可行,并給我一些正確方向的指點?

I looked at the available actions: IdeActions.java - it seems that there is not what i am searching for. But maybe i am looking at the wrong place. Can anyone tell me if what's i am trying to achieve is possible and give me some pointers in the right direction?

我成功創建了插件,它可以在 Github 上找到:http://alp82.github.com/idea-tabsession/

I succesfully created the plugin and it's available at Github: http://alp82.github.com/idea-tabsession/

它在官方插件庫中可用:Tab Session.

It is available in the official plugin repository: Tab Session.

這是關于拆分窗口的后續問題:檢索和設置拆分窗口設置

Here is a follow-up question regarding splitted windows: Retrieving and setting split window settings

推薦答案

2017年更新

我停止支持此插件,因為 IDEA 已經支持該功能.您可以輕松地保存和加載上下文,如下所示:https://github.com/alp82/idea-tabsession#discontinued

插件已準備就緒,可以在 IDEA -> 設置 -> 插件中下載.源代碼位于:https://github.com/alp82/idea-tabsession

The plugin is up and ready and can be downloaded in IDEA -> Settings -> Plugins. Source code is available at: https://github.com/alp82/idea-tabsession

要讀取當前打開的選項卡,請使用 EditorFactoryFileDocumentManager 單例:

To read which tabs are open right now, use the EditorFactory and FileDocumentManager Singletons:

    Editor[] editors = EditorFactory.getInstance().getAllEditors();
    FileDocumentManager fileDocManager = FileDocumentManager.getInstance();
    for(Editor editor : editors) {
        VirtualFile vf = fileDocManager.getFile(editor.getDocument());
        String path = vf.getCanonicalPath();
        System.out.println("path = " + path);
    }

要打開選項卡,請使用 FileEditorManager 單例(files 是規范路徑的字符串數組):

To open tabs use the FileEditorManager singleton (files being a String Array of canonical paths):

    FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
    for(String path : files) {
        System.out.println("path = " + path);
        VirtualFile vf = LocalFileSystem.getInstance().findFileByPath(path);
        fileEditorManager.openFile(vf, true, true);
    }

長答案

先決條件

  1. 激活插件開發、Groovy 和 UI Designer 插件
  2. 新建項目 -> IntelliJ IDEA 插件
  3. 簽出 IDEA Community Edition 源代碼到任何文件夾:

git clone git://git.jetbrains.org/idea/community.git idea

  • 配置 IDEA SDK 和創建插件

    插件結構

    創建插件后,您需要編輯位于 META-INF 文件夾中的 plugin.xml.修改idnamedescription.

    我們需要一個用于持久存儲的配置文件.在 src 文件夾中創建一個 mystorage.xml 文件.現在是時候創建所需的文件了:

    We need a configuration file for persistant storage. Create a mystorage.xml file in your src folder. It's now time to create the needed files:

    SessionComponent.java(使用Add Project Component向導創建它以自動創建所需的xml設置):

    SessionComponent.java (create it with the Add Project Component wizard to automatically create the needed xml settings):

    @State(
        name = "SessionComponent",
        storages = {
            @Storage(id = "default", file = StoragePathMacros.PROJECT_FILE),
            @Storage(id = "dir", file = StoragePathMacros.PROJECT_CONFIG_DIR + "/mystorage.xml", scheme = StorageScheme.DIRECTORY_BASED)
        }
    )
    public class SessionComponent implements ProjectComponent, PersistentStateComponent<SessionState> {
    
        Project project;
        SessionState sessionState;
    
        public SessionComponent(Project project) {
            this.project = project;
            sessionState = new SessionState();
        }
    
        public void initComponent() {
            // TODO: insert component initialization logic here
        }
    
        @Override
        public void loadState(SessionState sessionState) {
            System.out.println("load sessionState = " + sessionState);
            this.sessionState = sessionState;
        }
    
        public void projectOpened() {
            // called when project is opened
        }
    
        public void projectClosed() {
            // called when project is being closed
        }
    
        @Nullable
        @Override
        public SessionState getState() {
            System.out.println("save sessionState = " + sessionState);
            return sessionState;
        }
    
        public void disposeComponent() {
            // TODO: insert component disposal logic here
        }
    
        @NotNull
        public String getComponentName() {
            return "SessionComponent";
        }
    
        public int saveCurrentTabs() {
            Editor[] editors = getOpenEditors();
            FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
            VirtualFile[] selectedFiles = fileEditorManager.getSelectedFiles();
    
            FileDocumentManager fileDocManager = FileDocumentManager.getInstance();
            sessionState.files = new String[editors.length];
            int i = 0;
            for(Editor editor : editors) {
                VirtualFile vf = fileDocManager.getFile(editor.getDocument());
                String path = vf.getCanonicalPath();
                System.out.println("path = " + path);
                if(path.equals(selectedFiles[0].getCanonicalPath())) {
                    sessionState.focusedFile = path;
                }
                sessionState.files[i] = path;
                i++;
            }
    
            return editors.length;
        }
    
        public int loadSession() {
            closeCurrentTabs();
            FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
            for(String path : sessionState.files) {
                System.out.println("path = " + path);
                VirtualFile vf = LocalFileSystem.getInstance().findFileByPath(path);
                fileEditorManager.openFile(vf, true, true);
            }
    
            return sessionState.files.length;
        }
    
        public void closeCurrentTabs() {
            Editor[] editors = getOpenEditors();
            FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
            FileDocumentManager fileDocManager = FileDocumentManager.getInstance();
            for(Editor editor : editors) {
                System.out.println("editor = " + editor);
                VirtualFile vf = fileDocManager.getFile(editor.getDocument());
                fileEditorManager.closeFile(vf);
            }
        }
    
        public void showMessage(String htmlText) {
            StatusBar statusBar = WindowManager.getInstance().getStatusBar(project);
            JBPopupFactory.getInstance()
                .createHtmlTextBalloonBuilder(htmlText, MessageType.INFO, null)
                .setFadeoutTime(7500)
                .createBalloon()
                .show(RelativePoint.getCenterOf(statusBar.getComponent()), Balloon.Position.atRight);
        }
    
        private Editor[] getOpenEditors() {
            return EditorFactory.getInstance().getAllEditors();
        }
    
    }
    

    我們還需要存儲類:

    public class SessionState {
        public String[] files = new String[0];
        public String focusedFile = "";
    
        public String toString() {
            String result = "";
            for (String file : files) {
                result += file + ", ";
            }
            result += "selected: " + focusedFile;
            return result;
        }
    }
    

    組件類應該在你的 plugin.xml 中有一個像這樣的條目:

    The component class should have an entry in your plugin.xml like this one:

    <project-components>
      <component>
        <implementation-class>my.package.SessionComponent</implementation-class>
      </component>
    </project-components>
    

    組件類提供了所有需要的功能,但從未使用過.因此,我們需要執行加載和保存操作:

    The component class offers all needed functionality, but is never be used. Therefore, we need actions to perform loading and saving:

    保存.java:

    public class Save extends AnAction {
    
        public Save() {
            super();
        }
    
        public void actionPerformed(AnActionEvent event) {
            Project project = event.getData(PlatformDataKeys.PROJECT);
            SessionComponent sessionComponent = project.getComponent(SessionComponent.class);
    
            int tabCount = sessionComponent.saveCurrentTabs();
            String htmlText = "Saved " + String.valueOf(tabCount) + " tabs";
            sessionComponent.showMessage(htmlText);
        }
    
    }
    

    加載.java:

    public class Load extends AnAction {
    
        public Load() {
            super();
        }
    
        public void actionPerformed(AnActionEvent event) {
            Project project = event.getData(PlatformDataKeys.PROJECT);
            SessionComponent sessionComponent = project.getComponent(SessionComponent.class);
    
            int tabCount = sessionComponent.loadSession();
            String htmlText = "Loaded " + String.valueOf(tabCount) + " tabs";
            sessionComponent.showMessage(htmlText);
        }
    
    }
    

    Aaand...行動!

    我們需要的最后一件事是選擇這些操作的用戶界面.只需將其放在您的 plugin.xml 中:

      <actions>
        <!-- Add your actions here -->
          <group id="MyPlugin.SampleMenu" text="_Sample Menu" description="Sample menu">
              <add-to-group group-id="MainMenu" anchor="last"  />
              <action id="MyPlugin.Save" class="my.package.Save" text="_Save" description="A test menu item" />
              <action id="MyPlugin.Load" class="my.package.Load" text="_Load" description="A test menu item" />
          </group>
      </actions>
    

    插件部署

    基本功能已準備就緒.在部署此插件并將其發布到開源社區之前,我將添加對多個會話和其他一些簡潔內容的支持.鏈接將在此處發布,當它在線時.

    Plugin Deployment

    The basic functionality is ready. I will add support for multiple sessions and some other neat stuff before deploying this plugin and releasing it to the open-source community. Link will be posted here, when it's online.

    這篇關于IntelliJ IDEA 插件開發:保存選項卡組,持久保存并在用戶請求時重新加載一組選項卡的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

    【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!
  • 相關文檔推薦

    How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環繞文本?)
    MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
    Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
    Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數據庫)
    Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
    Use threading to process file chunk by chunk(使用線程逐塊處理文件)
    主站蜘蛛池模板: 国精品一区二区 | 亚洲在线 | 久久精品国产久精国产 | 欧美又大粗又爽又黄大片视频 | 日韩精品视频一区二区三区 | 欧美日韩亚洲视频 | 久操伊人 | 日韩一区二区三区在线视频 | 久久国产精品免费一区二区三区 | 免费骚视频 | h视频免费在线观看 | 日韩视频区 | 国产农村妇女毛片精品久久麻豆 | 亚洲日韩中文字幕一区 | 成人国产一区二区三区精品麻豆 | 视频一区二区中文字幕 | 日韩免费看视频 | 日韩在线免费视频 | 四虎影院一区二区 | 91精品国产91久久久久久密臀 | 欧美激情综合网 | 久久精品亚洲精品国产欧美 | 香蕉视频一区二区 | av国产精品毛片一区二区小说 | 日韩电影免费在线观看中文字幕 | 国产一级淫片a直接免费看 免费a网站 | 午夜精品久久久 | 久久综合伊人一区二区三 | 精品国产一区二区三区久久久蜜月 | 91精品国产综合久久久久 | 日韩欧美一级片 | 成人免费视频网站在线看 | 国产成人免费视频网站视频社区 | 久久鲁视频 | 亚洲成人三区 | 先锋资源网站 | 国产成人精品免高潮在线观看 | 日韩欧美国产精品一区二区三区 | 国产乱码精品一区二区三区忘忧草 | 性视频一区 | 成人在线中文字幕 |