Skip to content

Commit

Permalink
Merge branch 'paste-tables'
Browse files Browse the repository at this point in the history
  • Loading branch information
PHPirates committed Jan 14, 2021
2 parents 5041ee4 + fbbd066 commit 6382014
Show file tree
Hide file tree
Showing 14 changed files with 613 additions and 439 deletions.
1 change: 1 addition & 0 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@
<extendWordSelectionHandler implementation="nl.hannahsten.texifyidea.editor.LatexCommandSelectioner"/>
<basicWordSelectionFilter implementation="nl.hannahsten.texifyidea.editor.CommandSelectionFilter"/>
<customFileDropHandler implementation="nl.hannahsten.texifyidea.editor.GraphicsDragAndDropHandler"/>
<customPasteProvider implementation="nl.hannahsten.texifyidea.editor.TablePasteProvider"/>

<!-- References and refactoring -->
<lang.findUsagesProvider language="Latex" implementationClass="nl.hannahsten.texifyidea.reference.LatexUsagesProvider"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,23 @@ import com.intellij.openapi.ui.TextBrowseFolderListener
import com.intellij.openapi.ui.TextFieldWithBrowseButton
import com.intellij.ui.TitledSeparator
import com.intellij.ui.components.JBCheckBox
import com.intellij.ui.components.JBLabel
import com.intellij.ui.components.JBTextField
import com.intellij.ui.components.fields.ExpandableTextField
import com.intellij.ui.components.panels.HorizontalLayout
import nl.hannahsten.texifyidea.lang.graphic.CaptionLocation
import nl.hannahsten.texifyidea.lang.graphic.FigureLocation
import nl.hannahsten.texifyidea.util.Magic
import nl.hannahsten.texifyidea.util.addKeyReleasedListener
import nl.hannahsten.texifyidea.util.addTextChangeListener
import nl.hannahsten.texifyidea.util.setInputFilter
import java.awt.BorderLayout
import nl.hannahsten.texifyidea.util.*
import java.awt.Dimension
import javax.swing.*
import javax.swing.border.EmptyBorder
import javax.swing.Box
import javax.swing.BoxLayout
import javax.swing.JPanel
import javax.swing.JTextField

/**
* @author Hannah Schellekens
*/
open class InsertGraphicWizardDialogWrapper(val initialFilePath: String = "") : DialogWrapper(true) {

companion object {

/**
* The amount of pixels between the left pane border and the contorls.
*/
private const val CONTROL_LEFT_PADDING = 16
}

/**
* Stores the path to the graphics file.
*/
Expand Down Expand Up @@ -248,39 +237,6 @@ open class InsertGraphicWizardDialogWrapper(val initialFilePath: String = "") :
add(Box.createRigidArea(Dimension(0, margin)))
}

/**
* Adds a component to the panel with a label before it.
*
* @param component
* The component to add to the panel.
* @param description
* The label to put before the component.
* @param labelWidth
* The fixed label width, or `null` to use the label's inherent size.
*/
private fun JPanel.addLabeledComponent(component: JComponent, description: String, labelWidth: Int? = null): JPanel {
// Uses a border layout with West for the label and Center for the control itself.
// East is reserved for suffix elements.
val pane = JPanel(BorderLayout()).apply {
val label = JBLabel(description).apply {
// Left padding.
border = EmptyBorder(0, CONTROL_LEFT_PADDING, 0, 0)

// Custom width if specified.
labelWidth?.let {
preferredSize = Dimension(it, height)
}

// Align top.
alignmentY = 0.0f
}
add(label, BorderLayout.WEST)
add(component, BorderLayout.CENTER)
}
add(pane)
return pane
}

private fun updateFigureControlsState() {
val enabled = checkPlaceInFigure.isSelected

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nl.hannahsten.texifyidea.ui.tablecreationdialog
package nl.hannahsten.texifyidea.action.wizard.table

/**
* @author Abby Berkers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.PlatformDataKeys
import com.intellij.openapi.command.WriteCommandAction
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import nl.hannahsten.texifyidea.action.insert.InsertTable
import nl.hannahsten.texifyidea.lang.LatexPackage
import nl.hannahsten.texifyidea.ui.tablecreationdialog.ColumnType
import nl.hannahsten.texifyidea.ui.tablecreationdialog.TableCreationDialogWrapper
import nl.hannahsten.texifyidea.util.caretOffset
import nl.hannahsten.texifyidea.util.currentTextEditor
import nl.hannahsten.texifyidea.util.files.psiFile
Expand All @@ -23,17 +23,16 @@ import java.util.*
*/
class LatexTableWizardAction : AnAction() {

override fun actionPerformed(e: AnActionEvent) {
val file = e.getData(PlatformDataKeys.VIRTUAL_FILE) ?: return
val project = e.getData(PlatformDataKeys.PROJECT)
val editor = project?.currentTextEditor() ?: return
fun executeAction(file: VirtualFile, project: Project, defaultDialogWrapper: TableCreationDialogWrapper? = null) {
val editor = project.currentTextEditor() ?: return
val document = editor.editor.document

// Get the indentation from the current line.
val indent = document.lineIndentationByOffset(editor.editor.caretOffset())

// Create the dialog.
val dialogWrapper = TableCreationDialogWrapper()
val dialogWrapper = defaultDialogWrapper ?: TableCreationDialogWrapper()

// If the user pressed OK, do stuff.
if (dialogWrapper.showAndGet()) {

Expand All @@ -46,20 +45,28 @@ class LatexTableWizardAction : AnAction() {
// Insert the booktabs package.
WriteCommandAction.runWriteCommandAction(
project,
"Insert table",
"Insert Table",
"LaTeX",
Runnable { file.psiFile(project)!!.insertUsepackage(LatexPackage.BOOKTABS) },
Runnable { file.psiFile(project)?.insertUsepackage(LatexPackage.BOOKTABS) },
file.psiFile(project)
)
}
}

override fun actionPerformed(e: AnActionEvent) {
val file = e.getData(PlatformDataKeys.VIRTUAL_FILE) ?: return
val project = e.getData(PlatformDataKeys.PROJECT) ?: return
executeAction(file, project)
}

/**
* Convert the table information to a latex table that can be inserted into the file.
*
* @param tableInformation
* @param lineIndent is the indentation of the current line, to be used on each new line.
* @param tabIndent is the continuation indent.
* @param lineIndent
* The indentation of the current line, to be used on each new line.
* @param tabIndent
* The continuation indent.
*/
private fun convertTableToLatex(tableInformation: TableInformation, lineIndent: String, tabIndent: String = " "): String {
/**
Expand Down
Loading

0 comments on commit 6382014

Please sign in to comment.