mapeditor / tiled

Flexible level editor
https://www.mapeditor.org/
Other
11.18k stars 1.76k forks source link

Calling external command (text editor) for editing string properties #1825

Open WeirdConstructor opened 6 years ago

WeirdConstructor commented 6 years ago

I have a feature request, which would possibly benefit many programmers and extensive NPC dialogue writers:

Make it possible to configure an external command to be called for editing text/string properties.

The use case: Make it possible to use a proper text editor (VIM, Emacs, Sublime, Atom, Notepad++, ...) with syntax highlighting for Scripts that are local to the map or the object. It would also make any other form of text editing much more comfortable to do.

This is so useful, that I might hack it into Tiled myself someday, but I might not have the time to execute the change properly for a pull request and I am currently involved too much in other projects. Maybe someone else likes this idea so much, that he is also urged to implement it before I get the chance.

Preparations

Algorithm for that button click

  1. contents of the string property is written to a temporary file (with random filename, which is eventually deleted after the text editor exits). (If QString is internally used, store the contents UTF-8 encoded.)
  2. run the external editor command, in case an error value is returned signal an error to the user (typical error confirmation dialog) and delete the temporary file.
  3. if the editor was successfully started, start a timer, which regularly checks if the modified time of the temporary file changed. If it changed, update the contents of the text property.
  4. once the editor finally exits, check again if the temporary file changed, and replace the string property if necessary.
  5. delete the temporary file to prevent the temp directory from clobbering.

Possible Future Extensions

bjorn commented 6 years ago

I quite like the idea. Implementation-wise, this should probably integrate with the Custom Commands functionality. We can also look at how Qt Creator implemented this since their "External Tools" settings already have similar options.

Unfortunately there is no easy way to add content type information to string properties, but if this is done by setting up external tools then the user could at least set up different tools if he wants to use it for different kinds of data.