Skip to content

Add functionality for Delete Template#4437

Open
unichronic wants to merge 1 commit intomapeditor:masterfrom
unichronic:deltempl
Open

Add functionality for Delete Template#4437
unichronic wants to merge 1 commit intomapeditor:masterfrom
unichronic:deltempl

Conversation

@unichronic
Copy link
Contributor

@unichronic unichronic commented Mar 16, 2026

ref #1723
I have added the delete functionality for templates. Please check it out if the changes are alright.

menu

Currently after deleting a template it takes 10-15s to disappear from the file list during Folders referesh using FileSystemWatcher.
Do you think that's an issue?

Copy link
Member

@bjorn bjorn left a comment

Choose a reason for hiding this comment

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

Thank you for looking into this feature, @unichronic!

Currently after deleting a template it takes 10-15s to disappear from the file list during Folders refresh using FileSystemWatcher.
Do you think that's an issue?

Yes, this is not ideal. It's rather longer than I would expect since the FileSystemWatcher sets mChangedPathsTimer.setInterval(500), meaning it should only take half a second until the list is refreshed. But I think regardless, we should remove the matching entry from the model immediately after successful removal of the file.

I've left two additional comments.

if (inUse) break;
}

if (inUse) {
Copy link
Member

Choose a reason for hiding this comment

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

Consider making a local static isTemplateInUse function, so you can just return true instead of setting and checking an isUse variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

{
if (auto templ = mObjectTemplates.take(fileName)) {
mWatcher->removePath(fileName);
delete templ;
Copy link
Member

Choose a reason for hiding this comment

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

Of course, we can't actually delete the template instance when it is still in use, even if the user might be fine with this. By deleting this object, any references to this template will become roaming pointers and can cause crashes or random broken behavior later.

Currently, templates are never unloaded, which is what avoids such issues. I wonder if it hurts to just keep them in memory even if we delete the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@unichronic
Copy link
Contributor Author

unichronic commented Mar 17, 2026

Yes, this is not ideal. It's rather longer than I would expect since the FileSystemWatcher sets mChangedPathsTimer.setInterval(500), meaning it should only take half a second until the list is refreshed.

yes, the FileSystemWatcher triggers instantly, but the time to remove depends on the size the project folder since the whole file tree is refreshed everytime. I tried with smaller smaller folder, it was removed instantly. So I think unless the project folder has too many items it won't take that much time (I had my project folder as one of my root folders xD).

Addressed the other comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants