// ================================================================ //
//                                                                  //
//   File      : AW_edit.cxx                                        //
//   Purpose   :                                                    //
//                                                                  //
//   Institute of Microbiology (Technical University Munich)        //
//   http://www.arb-home.de/                                        //
//                                                                  //
// ================================================================ //

#include "aw_edit.hxx"
#include "aw_msg.hxx"

#include <arb_msg.h>

void AW_edit(const char *path) {
    // Start external editor on file 'path' (asynchronously)
    //
    // Note: no longer use ARB_TEXTEDIT directly -> now completely delegates logic to script ../SH/arb_textedit

    arb_assert(!strchr(path, '$')); // AW_edit previously supported expansion of environment variables (please perform at caller where needed!)

    char *quotedFile = GBK_singlequote(path);
    char *command    = GBS_global_string_copy("arb_textedit %s &", quotedFile);

    GB_ERROR error = GBK_system(command);
    aw_message_if(error);

    free(command);
    free(quotedFile);
}

void AW_edit_notified(const char *path, const FileChangedCallback& callback) {
    // like AW_edit, but also installs a callback called whenever file is changed.
    // The callback remains active forever.

    AW_edit(path);
    AW_add_inotification(path, callback);
}

