Sublime Forum

Is there a way to create a non-modal dialog?

#1

I’m writing a plugin to navigate a large log file. There are commands to navigate to some specific structure in the log, and depending on whether my plugin has that location cached already, it might take a long time (say, a minute or more) to find it.

Searching in the main thread essentially hangs sublime for the minute or so, which isn’t exactly a great user experience, so I do the search in a background thread and then schedule a task on the main thread to navigate to the specified structure when it’s found. All of this works, so no problem there.

What I would really like is a non-modal dialog with a cancel button. That would give the user some feedback about what’s happening and give them a chance to cancel. I’m currently using a popup, but that’s non-ideal because it goes away if the cursor moves. The dialog methods in sublime look like they’re modal (they return the selection, rather than have a callback), which would defeat the purpose of the background thread.

Is there a UI element I’m missing?

0 Likes

#2

Unfortunately, no, and the modal dialogs hang every Sublime window even if you call them from another thread.

0 Likes

#3

Thanks for the help. The best I can come up with to report on a long-latency operation is to open an output panel and fake up a cancel “button” using a ViewEventListener for the panel with on_selection_modified(). Is there a better idiom than that?

0 Likes

#4

You could cancel via a key binding or a Command Palette command.

After all Sublime Text is designed to be keyboard driven and most Sublime Texters prefer not to have to reach for the mouse.

0 Likes

#5

Yes, I put in a key binding, and that works to cancel. What I’m missing is a good way to provide some visual feedback to the user about what’s going on. I want to say something along the lines of “I can do what you asked, but it’s going to take some time.” I don’t want the user to assume that the command failed and then be surprised a minute or two later when something happens.

A status_message() is very easy to miss, but a modal dialog is intrusive, and I don’t see much in between.

0 Likes

#6

It’s conventional to put a labeled animation in the status bar. It’s out of the way, but the animation calls attention to it. There should be a reference implementation in the next release of sublime_lib.

0 Likes

#7

That looks like exactly what I need. Thanks!

0 Likes