#include "Editor.h"

//#include "Text.h"
#include "User.h"

namespace MM
{
Editor * Editor::last_ = 0;
//bool     Editor::busy_    = false;

Editor::~Editor()
{
    last_ = 0;
}

void Editor::
start_editing ()
{
    if (is_different_editor() && last_/* && previous_is_busy()*/)
    {
        Text /*result,*/ message, last;
        int n;

        last = "\"" + last_->name () + "\"";

        message  = "Previous ";
        message += last;
        message += " process ";
        message += "\n does not finished its job.\n\n";
        message += "Do your want to:";

        Array <Text> action;
        action.push_back (Text("Finish ")    + last);
        action.push_back (Text("Cancel ")    + last);
        //action.push_back (Text("Return to ") + last);

        to_user().choose (message, action, /*result,*/ n);

        switch (n)
        {
        case 0:
            last_->handle_finish_editing();
            break;
        case 1:
            last_->handle_cancel_editing();
            break;
        case 2:
            last_->handle_activate_editing();
            return;
        default:
            last_->handle_cancel_editing();
        }
    }

    //if (last_)
    //    last_->handle_finish_editing();
    last_ = this;
}

void Editor::
finish_editing ()
{
    //handle_finish_editing();
    last_ = 0;
}

void Editor::
cancel_editing ()
{
    //handle_cancel_editing();
    last_ = 0;
}

}//MM
