Adding item to Eclipse text viewer context menu

后端 未结 1 847
说谎
说谎 2021-01-14 11:58

I am developing a plugin for eclipse. In this plugin I need to be able to add an item to the context menu in the text editor. So far I have been unsuccessful in this, does a

1条回答
  •  执笔经年
    2021-01-14 12:13

    Regarding the selection part, the question "Replace selected code from eclipse editor thru plugin comand" is quite adequate for your need:

    try {               
        IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
        if ( part instanceof ITextEditor ) {
            final ITextEditor editor = (ITextEditor)part;
            IDocumentProvider prov = editor.getDocumentProvider();
            IDocument doc = prov.getDocument( editor.getEditorInput() );
            ISelection sel = editor.getSelectionProvider().getSelection();
            if ( sel instanceof TextSelection ) {
    
                // Here is your String
                final TextSelection textSel = (TextSelection)sel;
    
            }
        }
    } catch ( Exception ex ) {
        ex.printStackTrace();
    }
    

    You can then link this selection with the addition of an item in the popup menu, as in this SO question:
    "How do you contribute a command to an editor context menu in Eclipse"

    
        
           
              
           
        
    

    0 讨论(0)
提交回复
热议问题