editmain.c

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 616 行 · 第 1/2 页

C
616
字号
                    if( !InputKeyMaps[LastEvent].inuse ) {
                        return( StartInputKeyMap( LastEvent ) );
                    }
                }
                return( (EventList[LastEvent].ins)() );
            }
        }
    }

} /* DoLastEvent */

/*
 * DoneLastEvent - finished with the last event
 */
void DoneLastEvent( int rc, bool is_dotmode )
{
    if( !EditFlags.InsertModeActive ) {
        /*
         * save last command for '.'
         */
        if( !is_dotmode ) {
            if( EditFlags.DotMode ) {
                EditFlags.DotMode = FALSE;
            } else if( EditFlags.Dotable && !EditFlags.MemorizeMode ) {
                SaveDotCmd();
            }
        }

        /*
         * reset number and and buffer number
         */
        if( rc != GOT_A_SAVEBUF ) {
            if( rc != GOT_A_DIGIT ) {
                /* repeat count should not reset save buf */
                SavebufNumber = NO_SAVEBUF;
                DoneRepeat();
            }
        }

        if( !is_dotmode ) {
            EditFlags.Dotable = FALSE;
        }
    }

} /* DoneLastEvent */

/*
 * EditMain - main driver for editor (command mode)
 */
void EditMain( void )
{
    int         rc;
    char        *msg;
    bool        doclear;

    /*
     * loop forever, or at least until all done
     */
    while( TRUE ) {

    #if 0
    #ifdef __WIN__
        PushMode();
        UpdateFiles();
        PopMode();
    #endif
    #endif
        if( !EditFlags.InsertModeActive || EditFlags.Modeless ) {
            if( EditFlags.Modeless ) {
                UpdateEditStatus();
                EditFlags.NoCapsLock = FALSE;
            } else {
                UpdateCurrentStatus( CSTATUS_COMMAND );
                EditFlags.NoCapsLock = TRUE;
            }

            if( !EditFlags.Modeless && EditFlags.ReturnToInsertMode &&
                                !NonKeyboardEventsPending() ) {
                EditFlags.ReturnToInsertMode = FALSE;
                if( EditFlags.WasOverstrike ) {
                    LastEvent = 'R';
                } else {
                    LastEvent = 'i';
                }
            } else {
                DCUpdateAll();
                #ifdef __WIN__
                    SetWindowCursorForReal();
                #endif
                LastEvent = GetNextEvent( TRUE );
            }
            EditFlags.NoCapsLock = FALSE;
            doclear = TRUE;
            if( LastEvent == VI_KEY( MOUSEEVENT ) ) {
                if( LastMouseEvent == MOUSE_MOVE ) {
                    doclear = FALSE;
                }
            }
            if( doclear ) {
                if( EditFlags.AutoMessageClear ) {
                    ClearWindow( MessageWindow );
                }
                #ifndef __WIN__
                    ResetDisplayLine();
                #endif
            }
        } else {
            // Cannot do a RestoreInfo while we are in insert mode
            // because it will call ValidateCurrentColumn which will
            // do something stupid on us... PushMode/PopMode solution
            // not working yet... this needs a little work
            DCUpdate();
            #ifdef __WIN__
                SetWindowCursorForReal();
            #endif
            LastEvent = GetNextEvent( TRUE );
        }

        rc = DoLastEvent();

        if( EditFlags.ReadOnlyError && rc <= 0 ) {
            EditFlags.ReadOnlyError = FALSE;
            rc = ERR_READ_ONLY_FILE_MODIFIED;
        }
        if( rc > 0 ) {
            msg = GetErrorMsg( rc );
        }

        DoneLastEvent( rc, FALSE );

        if( rc > 0 ) {
            Error( msg );
        }

    }

} /* EditMain */

/*
 * AbsoluteNullResponse - give no response
 */
int AbsoluteNullResponse( void )
{
    return( ERR_NO_ERR );
}

/*
 * NullResponse - give null response for keystroke
 */
int NullResponse( void )
{
    if( !EditFlags.EscapeMessage ) {
        ClearWindow( MessageWindow );
    } else {
        DisplayFileStatus();
    }
    UnselectRegion();
    return( ERR_NO_ERR );

} /* NullResponse */

static window_id        repeatWindow=-1;

/*
 * KillRepeatWindow - just like it says
 */
void KillRepeatWindow( void )
{
    if( repeatWindow != NO_WINDOW ) {
        CloseAWindow( repeatWindow );
        repeatWindow = NO_WINDOW;
    }
}

/*
 * DoneRepeat - done getting repeat count
 */
void DoneRepeat( void )
{
    RepeatDigits=0;
    if( !EditFlags.MemorizeMode ) {
        DotDigits = 0;
    }
    KillRepeatWindow();

} /* DoneRepeat */

/*
 * SetRepeatCount - set up a fake repeat count
 */
void SetRepeatCount( long num )
{
    char        str[MAX_NUM_STR];

    ltoa( num, str, 10 );
    strcpy( RepeatString, str );
    RepeatDigits = strlen( str );

} /* SetRepeatCount */

/*
 * GetRepeatCount - return repeat count and reset it
 */
long GetRepeatCount( void )
{
    long        i;

    if( RepeatDigits == 0 ) {
        NoRepeatInfo = TRUE;
        return( 1L );
    }
    i = atol( RepeatString );
    RepeatDigits = 0;
    NoRepeatInfo = FALSE;
    return( i );

} /* GetRepeatCount */

#ifndef __WIN__
#define UpdateRepeatString( str ) DisplayLineInWindow( repeatWindow, 1, str )
#else
extern void UpdateRepeatString( char *str );
#endif

/*
 * DoDigit - process a digit typed in
 */
int DoDigit( void )
{
    int i;

    if( LastEvent == '0' && RepeatDigits == 0 ) {
        LeftColumn = 0;
        GoToColumnOK( 1 );
        DCDisplayAllLines();
        return( ERR_NO_ERR );
    }

    if( RepeatDigits == MAX_REPEAT_STRING-1 ) {
        DoneRepeat();
        return( ERR_REPEAT_STRING_TOO_LONG );
    }

    if( repeatWindow == (window_id)-1 && EditFlags.RepeatInfo ) {
        i = NewWindow2( &repeatWindow, &repcntw_info );
        if( i ) {
            DoneRepeat();
            return( i );
        }
        WindowTitle( repeatWindow, "Repeat Count" );
    }

    RepeatString[RepeatDigits++] = LastEvent;
    RepeatString[RepeatDigits] = 0;
    if( repeatWindow != (window_id)-1 ) {
        UpdateRepeatString( RepeatString );
    }
    return( GOT_A_DIGIT );

} /* DoDigit */

/*
 * InvalidKey - process invalid keystroke
 */
int InvalidKey( void )
{
    Error( GetErrorMsg( ERR_INVALID_KEY ), LastEvent );
    return( DO_NOT_CLEAR_MESSAGE_WINDOW );

} /* InvalidKey */

/*
 * Modified - set file modified flag
 */
void Modified( bool f )
{
    if( f ) {
        CurrentFile->need_autosave = TRUE;
        if( EditFlags.ReadOnlyCheck ) {
            if( CFileReadOnly() ) {
                EditFlags.ReadOnlyError = TRUE;
            }
        }
    }
    if( CurrentFile->modified != f  ) {
        CurrentFile->modified = f;
        SetModifiedVar( f );
    }
    UnselectRegion();

} /* Modified */

/*
 * ResetDisplayLine - reset display line, if required (after hilight)
 */
void ResetDisplayLine( void )
{
    if( EditFlags.ResetDisplayLine ) {
        memcpy( WorkLine->data, CurrentLine->data, CurrentLine->len+1 );
        WorkLine->len = CurrentLine->len;
        DisplayWorkLine( FALSE );
        DCUpdate();
        WorkLine->len = -1;
        EditFlags.ResetDisplayLine = FALSE;
    }

} /* ResetDisplayLine */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?