How does the Markdown editor hide the toolbar?

已回答

 

1. I created a markdown editor, but when I click the toolbar icon, there is no response. I don't know what happened. If anyone knows, please tell me what to do?

 

2. I tried to find the relevant function to close this toolbar, but I couldn't find it. Is there any function that can be closed?

 

This is my code


class AddJobsDialog(val project: Project) : DialogWrapper(project) {

private val vF = LightVirtualFile("D",MarkdownFileType.INSTANCE,"# 请输入招聘内容")
private val mkEdit = FileEditorProviderManager.getInstance().getProviderList(project, vF).first() as MarkdownSplitEditorProvider
private val edit = mkEdit.createEditor(project,vF)
private val mkComp = edit as MarkdownEditorWithPreview
private val citySelect = JobsCitySelectWidgetWithComBox(project)

init {
super.init()
title = "发布新职位"
setSize(800, 600)
(mkComp.previewEditor as MarkdownPreviewFileEditor).selectNotify()
}

override fun createCenterPanel(): JComponent {
return panel {
row ("标题"){
textField().align(Align.FILL)
}
row ("城市"){
cell(citySelect)
}
row {
cell(mkComp.component)
}
}
}
val contentText:String get() = mkComp.editor.document.text

}


I found this function, but I can't call it

0

Hi,

Could you please clarify your goal?

  1. Make the toolbar work.
  2. Hide the toolbar.
0

Karol Lewandowski Hi , 

Both of the above

 
 
0

Unfortunatelly, layout change actions can't be properly used inside modal dialogs due to the lack of proper DataContext there.

I would suggest to not use the modal dialog with editor if possible. You can try to use EditorTextField.

 

As for the actual MD editor with the preview. As far as I understand, you want to be able to switch editor layout and not show that toolbar above the editor. You can achive this by using a floating toolbar instead of the on in the editor header (this was (and still is) a standard behaviour in the Old UI). You will need to override TextEditorWithPreview#isShowActionsInTabs to return false. Since MarkdownEditorWithPreview is final, you will have to implement your own editor:

class CustomMarkdownEditor(project: Project, file: VirtualFile): TextEditorWithPreview(
  PsiAwareTextEditorProvider().createEditor(project, file) as TextEditor,
  MarkdownPreviewFileEditor(project, file)
) {
  init {
    (previewEditor as MarkdownPreviewFileEditor).setMainEditor(editor)
  }

  override fun isShowActionsInTabs(): Boolean {
    return false
  }
}

You can add this editor to your dialog's panel.

Please note, that you will need to dispose the editor on the dialog close (use DialogWrapper#myDisposable for that).

0

请先登录再写评论。