共通デスクトップ環境 ToolTalk メッセージの概要

Ttdt_file_cb の例

例 D-2 は、このコールバックの典型的なアルゴリズムの例です。


例 D-2 Ttdt_file_cb の典型的なアルゴリズム

Tt_message myFileCB(
    Tt_message      msg,
    Tttk_op         op,
    char            *pathname,
    int             trust,
    int             isMe 
) 
{
    tt_free( pathname );
    Tt_status status = TT_OK;
    switch (op) {
      case TTDT_MODIFIED:
        if ((_modifiedByMe) && (! isMe)) {
          // Hmm, the other editor either does not know or
          // does not care that we are already modifying the
          // file, so the last saver will win.
        } else {
          // Interrogate user if she ever modifies the buffer
          _modifiedByOther = 1;
          XtAddCallback( myTextWidget, XmNmodifyVerifyCallback,
                         myTextModifyCB, 0 );
        }
        break;
      case TTDT_GET_MODIFIED:
        tt_message_arg_ival_set( msg, 1, _modifiedByMe );
        tt_message_reply( msg );
        break;
      case TTDT_SAVE:
        status = mySave( trust );
        if (status == TT_OK) {
          tt_message_reply( msg );
        } else {
          tttk_message_fail( msg, status, 0, 0 );
        }                   break;
      case TTDT_REVERT:
        status = myRevert( trust );
        if (status == TT_OK) {
          tt_message_reply( msg );
        } else {
          tttk_message_fail( msg, status, 0, 0 );
        }
        break;
      case TTDT_REVERTED:
        if (! isMe) {
          _modifiedByOther = 0;
        }
        break;
      case TTDT_SAVED:
        if (! isMe) {
          _modifiedByOther = 0;
          int choice = myUserChoice( myContext, myBaseFrame,
                                     "Another tool has saved "
                                     "this file.", 2, "Ignore",
                                     "Revert" );
          switch (choice) {
            case 1:
              myRevert( 1 );
                break;
          }
        }
        break;
      case TTDT_MOVED:
      case TTDT_DELETED:
        // Do something appropriate
        break;
    }
    tttk_message_destroy( msg );
    return 0; 
}