-
|
BACKGROUND Within e.g. Microsoft's EXCEL application I often use a feature which generates a current date string within any element currently selected or edited (e.g. a cell or a cell's comment element). As this feature is very convenient if the user is working with textual elements which often need the current date to be inserted, I'd like to create something similar for use within Freeplane mindmaps. ACTION SEQUENCE / USER INTERFACE
REQUIREMENTS
QUESTIONS
In effect, I want to be able to execute Groovy functions while staying in edit mode of the current context. In my current experience, calling Groovy functions from within a script causes the termination of the current edit operation. But I want to stay and continue in edit mode while the script is temporarily running. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
|
I asked your question ChatGPT and got the following answer. I have not verified it. Here's a complete Groovy script and accompanying explanation in English, tailored as a helpful post for a Freeplane user who wants to insert the current date into the text being edited — similar to Excel’s Ctrl+. behavior. ✅ Groovy Script: Insert Current Date at Caret Position in Edit Modeimport javax.swing.*
import java.awt.*
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import javax.swing.text.JTextComponent
// Get the current date as a string
def dateString = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))
// Get the currently focused component
def focusedComponent = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()
// If it's a text component (node text, note, or detail being edited), insert the date at the caret
if (focusedComponent instanceof JTextComponent) {
def editor = (JTextComponent) focusedComponent
def pos = editor.getCaretPosition()
editor.document.insertString(pos, dateString, null)
}💡 What This Script DoesThis script allows you to press a custom hotkey (like 🔍 Technical Notes
|
Beta Was this translation helpful? Give feedback.
I asked your question ChatGPT and got the following answer. I have not verified it.
Here's a complete Groovy script and accompanying explanation in English, tailored as a helpful post for a Freeplane user who wants to insert the current date into the text being edited — similar to Excel’s Ctrl+. behavior.
✅ Groovy Script: Insert Current Date at Caret Position in Edit Mode