Пример #1
0
    void toggle_bookmark( )
    {
        if( mark_name.length( ) == 0 )
            error_message( "No bookmark defined" );

        else {
            // Get info on current position.
            EditBuffer   temp_name  = active_file( ).name( );
            FilePosition temp_point = active_file( ).CP( );

            // Change to saved current point. First see if the file is still loaded.
            if( lookup( mark_name.to_string( ).c_str( ) ) == true ) {
                active_file( ).CP( ) = mark_point;
            }

            // If not, reload (or even create!) the file.
            else if( new_file( mark_name.to_string( ).c_str( ) ) == true ) {
                active_file( ).CP( ) = mark_point;
            }

            // Hmmm...
            else {
                error_message( "Unable to restore marked position" );
            }

            // Save the old current point as the bookmark. Doing this even in the unlikely event
            // that we couldn't restore the position just redefines the bookmark to something
            // sensible. This is good.
            //
            mark_name  = temp_name;
            mark_point = temp_point;
        }
    }
Пример #2
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    qmlRegisterType<MemoryInitFile>("MemoryInitialization",1,0,"MemoryInitFile");
    qmlRegisterType<MemoryChunk>("MemoryInitialization", 1, 0, "MemoryChunk");
    qmlRegisterType<ChunkData>("MemoryInitialization", 1, 0, "ChunkData");
    QQmlApplicationEngine engine;

    MemoryInitFile  active_file(&app);
    QRegExp   regexp("[0-9abcdef]*");
    QRegExp   regexp2("[0-9]*");
    AddressValidator valid(&active_file,&app);
    ValueValidator   valid2(&active_file, &app);
    valid.setRegExpression(regexp);
    valid2.setRegExpression(regexp2);
    engine.rootContext()->setContextProperty("MemoryFileEngine",&active_file);
    engine.rootContext()->setContextProperty("AddressValidator",&valid);
    engine.rootContext()->setContextProperty("ValueValidator",&valid2);
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

    return app.exec();
}
Пример #3
0
 void set_bookmark( )
 {
     mark_name  = active_file( ).name( );
     mark_point = active_file( ).CP( );
 }
Пример #4
0
    bool insert_active( const char *new_name )
    {
        bool return_value = false;
        YEditFile     &old_entry = active_file();
        YEditFile     *new_entry;
        FilePosition old_CP = old_entry.CP();

        // If we are trying to insert this file into itself, do nothing.
        if( my_stricmp( old_entry.name(), new_name ) == 0 ) {
            return true;
        }

        // If a file with the new name exists, make it the active one.
        if( lookup( new_name ) == true ) {
            new_entry = *the_list.get( );
            return_value = true;
        }

        // No such file, try to create/load one.
        else if( new_file(new_name ) == true ) {
            new_entry = *the_list.get( );
            return_value = true;
        }

        // If I've got a target file, then transfer the text.
        if( return_value == true ) {
            long top;
            long bottom;
            bool old_state = old_entry.get_block_state( );

            // If the old file didn't have block mode on, then block entire file.
            if( old_state == false ) {
                old_entry.top_of_file( );
                old_entry.toggle_block( );
                old_entry.bottom_of_file( );
            }
            old_entry.block_limits( top, bottom );
            old_entry.CP( ).jump_to_line( top );

            // Adjust bottom if entire file is blocked.
            bottom = ( old_state == true ) ? bottom : bottom - 1;

            // Copy the text of the original file into the new file.
            for( long line_number = top;
                 return_value == true && line_number <= bottom;
                 line_number++) {
                if( new_entry->insert_line( old_entry.get_line( ) ) == false ) {
                    error_message( "Unable to completely build new file object" );
                    return_value = false;
                }
                else {
                    new_entry->CP( ).cursor_down( );
                    old_entry .CP( ).jump_to_line( line_number + 1 );
                }
            }
            old_entry.CP( ) = old_CP;

            // If the old file had block mode on, delete the block.
            if( old_state == true ) old_entry.delete_block( );

            // In any case, turn off the block mode.
            old_entry.toggle_block( );
        }

        return return_value;
    }
Пример #5
0
    bool new_file( const char *name )
    {
        char raw_extension[256];
        // Allow for extensions that are longer than three characters.

        // Find the extension and copy it into raw_extension[]. The check for backslash is so
        // that something like: \sub.dir\afile is handled correctly. Notice that the backslash
        // as a path delimiter is operating system dependent.
        //
        const char *end_pointer = std::strchr( name, '\0' );
        while( (  end_pointer >  name ) &&
               ( *end_pointer != '.'  ) &&
               ( *end_pointer != '\\' ) ) end_pointer--;
        if( *end_pointer == '.' ) std::strcpy( raw_extension, end_pointer );
        else raw_extension[0] = '\0';

        // Let's see if this file has an extension we know about.
        int i;
        for( i = 0; default_attributes[i].extension[0] != '\0'; i++ ) {
            if( my_stricmp( raw_extension, default_attributes[i].extension ) == 0 ) break;
        }

        FileType this_type = default_attributes[i].type;
        bool     return_value = false;

        // Create the appropriate type of YEditFile. Note that this is the only place this type
        // of switch is needed. Virtual functions handle it from here.

        YEditFile *new_thing;
        switch( this_type ) {
        case ADA  : new_thing = new   ADA_YEditFile( name ); break;
        case ASM  : new_thing = new   ASM_YEditFile( name ); break;
        case C    : new_thing = new     C_YEditFile( name ); break;
        case DOC  : new_thing = new   DOC_YEditFile( name ); break;
        case PCD  : new_thing = new   PCD_YEditFile( name ); break;
        case SCALA: new_thing = new SCALA_YEditFile( name ); break;
        case OTHER: new_thing = new OTHER_YEditFile( name ); break;
        default:    new_thing = NULL;                        break;
        }

        // Do the following only if a YEditFile was created.
        if( new_thing != NULL ) {

            // Try to insert the new file into the list after the current file.
            the_list.next( );
            if( the_list.insert( new_thing ) == NULL ) {
                // It didn't work. Get rid of the file and go back where we were.
                delete new_thing;
                the_list.previous( );
            }
            else {
                // It did work. Make the new file the currently active one.
                return_value = true;
                the_list.previous( );

                // See if this file has been in the editor before and if so set up its
                // attributes to agree with the descriptor.
                //
                active_file( ).set_attributes( );
            }
        }
        return return_value;
    }