Skip to content

Table creation wizard #907

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Nov 6, 2019
Merged

Table creation wizard #907

merged 19 commits into from
Nov 6, 2019

Conversation

slideclimb
Copy link
Collaborator

@slideclimb slideclimb commented May 27, 2019

Adds a menu option Edit > Latex > Table Creation Wizard to display a table creation wizard (#154). The created table will be inserted at the location of the cursor (like the insert section actions).

To do:

  • Automatically add new row when tabbing in the last cell of the last row
  • Button to add a new column
  • Different column styles in wizard (Text, Math, Numbers)
  • Edit columns in wizard
  • Caption and label
  • Convert table to latex
    • Different column styles:
      • Math: when converting table, enclose with $$
      • Numbers: align right
      • Text: align left
  • UI
  • Display warning when something is not filled in when clicking OK
  • Add to wiki

@slideclimb slideclimb added the enhancement New feature or (non bug related) change to the program. label May 27, 2019
@slideclimb slideclimb self-assigned this May 27, 2019
@slideclimb slideclimb marked this pull request as ready for review May 31, 2019 16:05
@slideclimb slideclimb added this to the b0.6.6 milestone May 31, 2019
Copy link
Member

@HannahSchellekens HannahSchellekens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love it, because I really want this feature. However, the wizard is extremely limited, like mixed content is not supported and a bit more (see the list below). It looks nice though.

  • Rename menu item to Table. You're inserting a table, not a table creation wizard. There is no insert, oops. I'd add a separator underneath the start action and then "Table Creation Wizard" or "Insert Table..."
  • It is not obvious how to insert new rows.
  • You cannot make the table row-oriënted (or both).
  • There is no cell merging.
  • You have no control over border styles.
  • By forcing a column type you restrict the user too much in my opinion. I'd go for mixed LaTeX content everywhere.

A (not so nice to use) but great illustration is tablesgenerator.com. The suggested changes might be a bit much. We should probably think of a requirement list for the wizard before adding anything, really.

Copy link
Member

@stenwessel stenwessel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a great addition! Adding to @RubenSchellekens' comments:

  • Add icon for the action (paging @RubenSchellekens)
  • I think users need to have a choice in bordering (and whether to use the booktabs package)
  • Add option to insert table caption either above or below the table itself

// Enclose with $ if the type of this column is math.
val index = row.indexOf(it)
val encloseWith = if (columnTypes[index] == ColumnType.MATH_COLUMN) "$" else ""
encloseWith + it.toString() + encloseWith
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get an NPE here when I attempt to create a table as follows: two columns (text and numbers) with a single empty row.

Stacktrace
java.lang.NullPointerException
	at nl.rubensten.texifyidea.action.tablewizard.LatexTableWizardAction$convertTableToLatex$1$processTableContent$$inlined$with$lambda$1$1.invoke(LatexTableWizardAction.kt:85)
	at nl.rubensten.texifyidea.action.tablewizard.LatexTableWizardAction$convertTableToLatex$1$processTableContent$$inlined$with$lambda$1$1.invoke(LatexTableWizardAction.kt:22)
	at kotlin.text.StringsKt__StringBuilderKt.appendElement(StringBuilder.kt:58)
	at kotlin.collections.CollectionsKt___CollectionsKt.joinTo(_Collections.kt:2291)
	at kotlin.collections.CollectionsKt___CollectionsKt.joinToString(_Collections.kt:2308)
	at kotlin.collections.CollectionsKt___CollectionsKt.joinToString$defa	ult(_Collections.kt:2307)
	at nl.rubensten.texifyidea.action.tablewizard.LatexTableWizardAction$convertTableToLatex$1$processTableContent$$inlined$with$lambda$1.invoke(LatexTableWizardAction.kt:77)
	at nl.rubensten.texifyidea.action.tablewizard.LatexTableWizardAction$convertTableToLatex$1$processTableContent$$inlined$with$lambda$1.invoke(LatexTableWizardAction.kt:22)
	at kotlin.text.StringsKt__StringBuilderKt.appendElement(StringBuilder.kt:58)
	at kotlin.collections.CollectionsKt___CollectionsKt.joinTo(_Collections.kt:2291)
	at kotlin.collections.CollectionsKt___CollectionsKt.joinToString(_Collections.kt:2308)
	at kotlin.collections.CollectionsKt___CollectionsKt.joinToString$default(_Collections.kt:2307)
	at nl.rubensten.texifyidea.action.tablewizard.LatexTableWizardAction$convertTableToLatex$1.invoke(LatexTableWizardAction.kt:76)
	at nl.rubensten.texifyidea.action.tablewizard.LatexTableWizardAction.convertTableToLatex(LatexTableWizardAction.kt:101)
	at nl.rubensten.texifyidea.action.tablewizard.LatexTableWizardAction.convertTableToLatex$default(LatexTableWizardAction.kt:62)
	at nl.rubensten.texifyidea.action.tablewizard.LatexTableWizardAction.actionPerformed(LatexTableWizardAction.kt:39)
	at com.intellij.openapi.actionSystem.ex.ActionUtil$1.run(ActionUtil.java:260)
	at com.intellij.openapi.actionSystem.ex.ActionUtil.performActionDumbAware(ActionUtil.java:277)
	at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.lambda$actionPerformed$0(ActionMenuItem.java:292)
	at com.intellij.openapi.wm.impl.FocusManagerImpl.runOnOwnContext(FocusManagerImpl.java:283)
	at com.intellij.openapi.wm.impl.IdeFocusManagerImpl.runOnOwnContext(IdeFocusManagerImpl.java:107)
	at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.actionPerformed(ActionMenuItem.java:282)
	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
	at com.intellij.openapi.actionSystem.impl.ActionMenuItem.lambda$fireActionPerformed$0(ActionMenuItem.java:111)
	at com.intellij.openapi.application.TransactionGuardImpl.runSyncTransaction(TransactionGuardImpl.java:88)
	at com.intellij.openapi.application.TransactionGuardImpl.lambda$submitTransaction$1(TransactionGuardImpl.java:111)
	at com.intellij.openapi.application.TransactionGuardImpl.submitTransaction(TransactionGuardImpl.java:120)
	at com.intellij.openapi.application.TransactionGuard.submitTransaction(TransactionGuard.java:121)
	at com.intellij.openapi.actionSystem.impl.ActionMenuItem.fireActionPerformed(ActionMenuItem.java:111)
	at com.intellij.ui.plaf.beg.BegMenuItemUI.doClick(BegMenuItemUI.java:524)
	at com.intellij.ui.plaf.beg.BegMenuItemUI.access$300(BegMenuItemUI.java:35)
	at com.intellij.ui.plaf.beg.BegMenuItemUI$MyMouseInputHandler.mouseReleased(BegMenuItemUI.java:546)
	at java.awt.Component.processMouseEvent(Component.java:6550)
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3325)
	at java.awt.Component.processEvent(Component.java:6315)
	at java.awt.Container.processEvent(Container.java:2239)
	at java.awt.Component.dispatchEventImpl(Component.java:4899)
	at java.awt.Container.dispatchEventImpl(Container.java:2297)
	at java.awt.Component.dispatchEvent(Component.java:4721)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4904)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4535)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4476)
	at java.awt.Container.dispatchEventImpl(Container.java:2283)
	at java.awt.Window.dispatchEventImpl(Window.java:2746)
	at java.awt.Component.dispatchEvent(Component.java:4721)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:766)
	at java.awt.EventQueue.access$500(EventQueue.java:98)
	at java.awt.EventQueue$3.run(EventQueue.java:715)
	at java.awt.EventQueue$3.run(EventQueue.java:709)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:84)
	at java.awt.EventQueue$4.run(EventQueue.java:739)
	at java.awt.EventQueue$4.run(EventQueue.java:737)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:736)
	at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:747)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:692)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:391)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be fixed now. When adding a column it would set all cells in the new column to null (instead of the empty string).

* @param title of the column.
* @param typedColumnIndex is the column type of the column.
*/
private val addColumnFun = fun(title: String, typedColumnIndex: Int, _: Int) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be a method? Or am I missing something obvious here why it should be a property?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an anonymous function that is passed to the TableCreationEditColumnDialog, it's the function that gets invoked when clicking OK.

}

if (show() == DialogWrapper.OK_EXIT_CODE) {
onOkFunction(columnNameField.text, columnTypeComboBox.selectedIndex, editingColumn)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer returning ColumnType.values()[columnTypeComboBox.selectedIndex] here directly such that the index (which means nothing) is not used later on, and the column type is directly available.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that makes more sense! Don't know why I didn't do that...

@PHPirates
Copy link
Collaborator

Please resolve merge conflicts

# Conflicts:
#	src/nl/hannahsten/texifyidea/action/insert/InsertTable.kt
#	src/nl/hannahsten/texifyidea/action/tablewizard/LatexTableWizardAction.kt
#	src/nl/hannahsten/texifyidea/action/tablewizard/TableInformation.kt
#	src/nl/hannahsten/texifyidea/lang/Package.kt
#	src/nl/hannahsten/texifyidea/ui/tablecreationdialog/ColumnType.kt
#	src/nl/hannahsten/texifyidea/ui/tablecreationdialog/TableCreationDialogWrapper.kt
#	src/nl/hannahsten/texifyidea/ui/tablecreationdialog/TableCreationEditColumnDialog.kt
#	src/nl/hannahsten/texifyidea/ui/tablecreationdialog/TableCreationTableModel.kt
@PHPirates PHPirates merged commit 99c3249 into master Nov 6, 2019
@PHPirates PHPirates deleted the table-creation-wizard branch November 6, 2019 20:23
@PHPirates PHPirates mentioned this pull request Nov 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or (non bug related) change to the program.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants