/* ==========================================================
File:        CustomSaveListener.java
Description: Sends a heartbeat when a file is saved.
Maintainer:  WakaTime <support@wakatime.com>
License:     BSD, see LICENSE for more details.
Website:     https://wakatime.com/
===========================================================*/

package com.wakatime.intellij.plugin;

import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorFactory;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.fileEditor.FileDocumentManagerListener;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;

public class CustomSaveListener implements FileDocumentManagerListener {

    @Override
    public void beforeDocumentSaving(Document document) {
        Editor[] editors = EditorFactory.getInstance().getEditors(document);
        if (editors.length > 0) {
            FileDocumentManager instance = FileDocumentManager.getInstance();
            VirtualFile file = instance.getFile(document);
            Project project = editors[0].getProject();
            WakaTime.appendHeartbeat(file, project, true);
        }
    }

    @Override
    public void beforeAllDocumentsSaving() {
    }
}
@@ -730,16 +730,58 @@
 ualFile;
+%0Aimport org.jetbrains.annotations.NotNull;
 %0A%0Apublic
@@ -1363,10 +1363,511 @@
  %7B%0A    %7D
+%0A%0A    @Override%0A    public void beforeFileContentReload(@NotNull VirtualFile file, @NotNull Document document) %7B%0A    %7D%0A%0A    @Override%0A    public void fileWithNoDocumentChanged(@NotNull VirtualFile file) %7B%0A    %7D%0A%0A    @Override%0A    public void fileContentReloaded(@NotNull VirtualFile file, @NotNull Document document) %7B%0A    %7D%0A%0A    @Override%0A    public void fileContentLoaded(@NotNull VirtualFile file, @NotNull Document document) %7B%0A    %7D%0A%0A    @Override%0A    public void unsavedDocumentsDropped() %7B%0A    %7D
 %0A%7D

implement all FileDocumentManagerListener methods to fix #111