How to implement a dropdown with available rake-tasks in RubyMine plugin?

Hi!
Could you please explain how to implement a dropdown with list of rake-tasks in RubyMine plugin? It's present in RubyMine in Run/Debug Configurations dialog when you create a Rake-task configuration (screenshot is attached).

I've traced that I should look into RakeRunConfigurationEditor and RunConfigurationUIUtil classes (thanks for java decompiler by the way!), but unfortunately somewhere the code is obfuscated, so it's not easy to understand how to use them.

Thank you!



Attachment(s):
Rake-task-list-dropdown.png
1 comment
Comment actions Permalink

Happily I have found the solution by myself! Below is the code for those, who may be interested :) Thanks again for Java decompiler, guys!))

 
private TextFieldWithAutoCompletion<RakeTask> createRakeTaskNamesEdit() {

    TextFieldWithAutoCompletionListProvider<RakeTask> listProvider =
            new TextFieldWithAutoCompletionListProvider<RakeTask>(null) {
                @Nullable
                @Override
                protected
Icon getIcon(@NotNull RakeTask rakeTask) {
                    return RubyIcons.Rake.Rake_runConfiguration;
                
}

                @NotNull
                @Override
                protected
String getLookupString(@NotNull RakeTask rakeTask) {
                    if (rakeTask.getFullCommand() == null)
                        return "";

                    return
rakeTask.getFullCommand();
                
}

                @Nullable
                @Override
                protected
String getTailText(@NotNull RakeTask rakeTask) {
                    return " " + rakeTask.getDescription();
                
}

                @Nullable
                @Override
                protected
String getTypeText(@NotNull RakeTask rakeTask) {
                    return null;
                
}

                @Override
                public int compare
(RakeTask rakeTask, RakeTask rakeTask2) {
                    return StringUtil.compare(rakeTask.getFullCommand(),
                            
rakeTask2.getFullCommand(), false);
                
}
            };


    
TextFieldWithAutoCompletion<RakeTask> field = new TextFieldWithAutoCompletion<RakeTask>(
            myModule.getProject(), listProvider, true, null);

    
RakeTaskModuleCache cachedTasks = RakeTaskModuleCache.getInstance(myModule);
    
List<RakeTask> rakeList = cachedTasks != null ? cachedTasks.getRakeTaskCmdsList() : null;
    
listProvider.setItems(rakeList);

    return
field;
}
0

Please sign in to leave a comment.