Code Examples

cssed_plugin_unload_callback

        #include <gtk/gtk.h>
        #include <plugin.h>

        GtkWidget* button;
        CssedPlugin* plugin;

        // ... build the plugin ....

        button = gtk_button_new_with_label( "Unload plugin");
        gtk_widget_show( button );
        cssed_plugin_add_widget_to_toolbar( plugin, button, "Unload me", NULL );
        
        g_signal_connect( button, "clicked", cssed_plugin_unload_callback, plugin);

cssed_add_menu_item_to_plugins_menu

        #include <gtk/gtk.h>
        #include <plugin.h>

        GtkWidget* menu_item;
        CssedPlugin* plugin;

        // ... build the plugin ....

        menu_item = gtk_menu_item_new_with_label( "Do nothing" );
        gtk_widget_show( menu_item );
        cssed_add_menu_item_to_plugins_menu( plugin, menu_item );       

cssed_plugin_add_widget_to_toolbar

        #include <gtk/gtk.h>
        #include <plugin.h>

        GtkWidget* button;
        CssedPlugin* plugin;

        // ... build the plugin ....

        button = gtk_button_new_with_label( "Do nothing");
        gtk_widget_show( button );
        cssed_plugin_add_widget_to_toolbar( plugin, button, "Do nothing", NULL );       

cssed_plugin_add_page_with_widget_to_footer

        #include <gtk/gtk.h>
        #include <plugin.h>

        GtkWidget* button;
        CssedPlugin* plugin;

        // ... build the plugin ....

        button = gtk_button_new_with_label( "Unload plugin");
        gtk_widget_show( button );
        cssed_plugin_add_widget_to_footer( plugin, button, "Useless button" );

cssed_plugin_remove_page_with_widget_in_footer

        #include <gtk/gtk.h>
        #include <plugin.h>

        GtkWidget* button;
        CssedPlugin* plugin;
        
        // ... build the plugin ....

        button = gtk_button_new_with_label( "Unload plugin");
        gtk_widget_show( button );
        cssed_plugin_add_widget_to_footer( plugin, button, "Useless button" );
        // to destroy this widget.
        cssed_plugin_remove_page_with_widget_in_footer( plugin, button );       

cssed_plugin_add_page_with_widget_to_sidebar

        #include <gtk/gtk.h>
        #include <plugin.h>

        GtkWidget* button;
        CssedPlugin* plugin;

        // ... build the plugin ....

        button = gtk_button_new_with_label( "Unload plugin");
        gtk_widget_show( button );
        cssed_plugin_add_page_with_widget_to_sidebar( plugin, button, "Useless button" );

cssed_plugin_remove_page_with_widget_in_sidebar

        #include <gtk/gtk.h>
        #include <plugin.h>

        GtkWidget* button;
        CssedPlugin* plugin;
        
        // ... build the plugin ....

        button = gtk_button_new_with_label( "Unload plugin");
        gtk_widget_show( button );
        cssed_plugin_add_page_with_widget_to_sidebar( plugin, button, "Useless button" );
        // to destroy this widget.
        cssed_plugin_remove_page_with_widget_in_sidebar( plugin, button );      

Plugin document actions

Please remember all those functions perform their actions in the currently opened document.

cssed_plugin_add_text_to_document

        #include <gtk/gtk.h>
        #include <plugin.h>

        CssedPlugin* plugin;

        // ... build the plugin ....
        cssed_plugin_add_text_to_document( plugin, "Ahiooooo" );

cssed_plugin_get_position_at_line

        #include <gtk/gtk.h>
        #include <plugin.h>

        CssedPlugin* plugin;
        gint position;

        // ... build the plugin ....
        position = cssed_plugin_get_position_at_line( plugin, 2 );
        g_print("There're %d chars at before the start of line 2", position );

cssed_plugin_undo_document_action

        #include <gtk/gtk.h>
        #include <plugin.h>

        CssedPlugin* plugin;

        // ... build the plugin ....
        // add some text
        cssed_plugin_add_text_to_document( plugin, "Ahiooooo" );
        // undo this action
        cssed_plugin_undo_document_action( plugin );

cssed_plugin_redo_document_action

        #include <gtk/gtk.h>
        #include <plugin.h>

        CssedPlugin* plugin;

        // ... build the plugin ....
        // add some text
        cssed_plugin_add_text_to_document( plugin, "Ahiooooo" );
        // undo this action
        cssed_plugin_undo_document_action( plugin );
        // re do this now
        cssed_plugin_redo_document_action( plugin );

cssed_plugin_search_prev

        #include <gtk/gtk.h>
        #include <plugin.h>

        CssedPlugin* plugin;

        // ... build the plugin ....
        // search some text back
        cssed_plugin_search_prev( plugin, "Ahiooooo" );

cssed_plugin_search_next

        #include <gtk/gtk.h>
        #include <plugin.h>

        CssedPlugin* plugin;

        // ... build the plugin ....
        // search some text forward
        cssed_plugin_search_next( plugin, "Ahiooooo" );

cssed_plugin_cut

        #include <gtk/gtk.h>
        #include <plugin.h>

        CssedPlugin* plugin;

        // ...
        cssed_plugin_cut ( plugin );
        cssed_plugin_set_current_line( plugin, cssed_plugin_get_current_line(plugin)+1);
        cssed_plugin_paste( plugin );

cssed_plugin_copy

        #include <gtk/gtk.h>
        #include <plugin.h>

        CssedPlugin* plugin;

        // ...
        cssed_plugin_copy( plugin );
        cssed_plugin_set_current_line( plugin, cssed_plugin_get_current_line(plugin)+1);
        cssed_plugin_paste( plugin );

cssed_plugin_paste

        #include <gtk/gtk.h>
        #include <plugin.h>

        CssedPlugin* plugin;

        // ...
        cssed_plugin_copy( plugin );
        cssed_plugin_set_current_line( plugin, cssed_plugin_get_current_line(plugin)+1);
        cssed_plugin_paste( plugin );

cssed_plugin_get_selection_end

        #include <gtk/gtk.h>
        #include <plugin.h>

        CssedPlugin* plugin;
        gint end, start;

        // ...

        end = cssed_plugin_get_selection_end( plugin );
        start = cssed_plugin_get_selection_start( plugin );

        if( end > start ){
                cssed_error_message("There is text selected", "There is text selected from %d to %d", start, end);
        }else{
                cssed_error_message("There is no text selected", "The caret is at %d and the selection end at %d, so there's no selection.", start, end);
        }

cssed_plugin_get_selection_start

        #include <gtk/gtk.h>
        #include <plugin.h>

        CssedPlugin* plugin;
        gint end, start;

        // ...

        end = cssed_plugin_get_selection_end( plugin );
        start = cssed_plugin_get_selection_start( plugin );

        if( end > start ){
                cssed_plugin_error_message("There is text selected", "There is text selected from %d to %d", start, end);
        }else{
                cssed_plugin_error_message("There is no text selected", "The caret is at %d and the selection end at %d, so there's no selection.", start, end);
        }

cssed_plugin_set_selection_start

        #include <gtk/gtk.h>
        #include <plugin.h>

        CssedPlugin* plugin;
        gint end, start, len;

        // ... select all text on doc
        cssed_plugin_set_selection_start( plugin, 0);
        cssed_plugin_set_selection_end( plugin, cssed_plugin_get_length(plugin));       

cssed_plugin_set_selection_end

        #include <gtk/gtk.h>
        #include <plugin.h>

        CssedPlugin* plugin;
        gint end, start, len;

        // ... select all text on doc
        cssed_plugin_set_selection_start(plugin, 0);
        cssed_plugin_set_selection_end(plugin, cssed_plugin_get_length(plugin));        

cssed_plugin_set_selection_range

        #include <gtk/gtk.h>
        #include <plugin.h>

        CssedPlugin* plugin;
        gint end, start, len;

        // ... select all text on doc
        cssed_plugin_set_selection_range(plugin, 0, cssed_plugin_get_length(plugin));   

cssed_plugin_replace_sel

        #include <gtk/gtk.h>
        #include <plugin.h>

        CssedPlugin* plugin;
        gint end, start;

        // ...

        end = cssed_plugin_get_selection_end( plugin );
        start = cssed_plugin_get_selection_start( plugin );

        if( end > start ){
                cssed_plugin_replace_sel(plugin, "Replacement text");
        }

cssed_plugin_clear_sel

        #include <gtk/gtk.h>
        #include <plugin.h>

        CssedPlugin* plugin;
        gint end, start;

        // ...

        end = cssed_plugin_get_selection_end( plugin );
        start = cssed_plugin_get_selection_start( plugin );

        if( end > start ){ // clear selection if any
                cssed_plugin_clear_sel(plugin);
        }

cssed_plugin_get_length

        #include <gtk/gtk.h>
        #include <plugin.h>

        CssedPlugin* plugin;
        gint len;

        // ...

        len = cssed_plugin_get_length( plugin );

        cssed_plugin_error_message("Length", "The document have %d bytes.", len);

cssed_plugin_bookmark_next

        #include <gtk/gtk.h>
        #include <plugin.h>

        CssedPlugin* plugin;

        // ... 
        cssed_plugin_bookmark_next( plugin );

cssed_plugin_bookmark_prev

        #include <gtk/gtk.h>
        #include <plugin.h>

        CssedPlugin* plugin;

        // ... 
        cssed_plugin_bookmark_prev( plugin );

cssed_plugin_set_bookmark_at_line

        #include <gtk/gtk.h>
        #include <plugin.h>

        CssedPlugin* plugin;

        // set a bookmark on document's first line
        cssed_plugin_set_bookmark_at_line( plugin, TRUE, 0 );

cssed_plugin_is_bookmark_set_at_line

        #include <gtk/gtk.h>
        #include <plugin.h>

        CssedPlugin* plugin;

        // toggle a bookmark at first line
        cssed_plugin_set_bookmark_at_line( 
                plugin,
                0,
                cssed_plugin_is_bookmark_set_at_line( plugin, 0 )
        );

cssed_plugin_marker_next

        #include <gtk/gtk.h>
        #include <plugin.h>

        CssedPlugin* plugin;

        // ... 
        cssed_plugin_marker_next( plugin );

cssed_plugin_marker_prev

        #include <gtk/gtk.h>
        #include <plugin.h>

        CssedPlugin* plugin;

        // ... 
        cssed_plugin_marker_prev( plugin );

cssed_plugin_set_marker_at_line

        #include <gtk/gtk.h>
        #include <plugin.h>

        CssedPlugin* plugin;

        // set a marker on document's first line
        cssed_plugin_set_marker_at_line( plugin, TRUE, 0 );

cssed_plugin_is_marker_set_at_line

        #include <gtk/gtk.h>
        #include <plugin.h>

        CssedPlugin* plugin;

        // toggle a marker at first line
        cssed_plugin_set_marker_at_line( 
                plugin,
                0,
                cssed_plugin_is_marker_set_at_line( plugin, 0 )
        );

cssed_plugin_error_message

        #include <gtk/gtk.h>
        #include <plugin.h>

        CssedPlugin* plugin;

        // ... build the plugin ....
        // sown an error message
        cssed_plugin_error_message( "This is what happened", "I was %s and it happened %s because %s", action, result, explanation);

cssed_plugin_confirm_dialog

        #include <gtk/gtk.h>
        #include <plugin.h>

        CssedPlugin* plugin;
        gchar *something = "something";
        
        // ... build the plugin ....
        // ask something to the user
         if( cssed_plugin_confirm_dialog( "Please confirm", "Do you want me to do %s ?", something ) ){
                cssed_plugin_error_message( "The user wants you to do %s", something );
        }else{
                cssed_plugin_error_message("The user doesn't want you to do %s", something  );
        }

File Functions

cssed_plugin_open_file

        #include <gtk/gtk.h>
        #include <plugin.h>


        CssedPlugin* plugin;

        // ... build the plugin ....
        // open a file
        cssed_plugin_open_file( plugin, "/home/user/file" );

cssed_plugin_open_file_with_fileselector

        #include <gtk/gtk.h>
        #include <plugin.h>


        CssedPlugin* plugin;

        // ... build the plugin ....
        // show a file selector to open a file
        cssed_plugin_open_file_with_fileselector( plugin );

cssed_plugin_output_write

        #include <gtk/gtk.h>
        #include <plugin.h>


        CssedPlugin* plugin;

        // ... write to the output ....
        cssed_plugin_output_write( plugin, "This is a message to the output window" );

cssed_plugin_output_clear

        #include <gtk/gtk.h>
        #include <plugin.h>


        CssedPlugin* plugin;

        // ... write to the output ....
        cssed_plugin_output_write( plugin, "This is a message to the output window" );
        // .. now clear the output window
        cssed_plugin_output_clear (plugin);

cssed_plugin_get_line_from_position

        #include <gtk/gtk.h>
        #include <plugin.h>


        CssedPlugin* plugin;
        gint line;
        
        // ... build the plugin ....
        line = cssed_plugin_get_line_from_position( plugin, 12 );
        
        cssed_plugin_output_write( plugin, "Position 12 is at line %d", line );

cssed_plugin_get_position_from_line

        #include <gtk/gtk.h>
        #include <plugin.h>


        CssedPlugin* plugin;
        gint pos;
        
        // ... build the plugin ....
        pos = cssed_plugin_get_position_from_line( plugin, 1 );
        
        cssed_plugin_output_write( plugin, "Line 1 is at position %d", pos );

cssed_plugin_get_current_position

        #include <gtk/gtk.h>
        #include <plugin.h>


        CssedPlugin* plugin;
        gint pos;
        
        // ... build the plugin ....
        pos = cssed_plugin_get_current_position( plugin );
        
        cssed_plugin_output_write( plugin, "The caret is at position %d", pos );

cssed_plugin_set_current_position

        #include <gtk/gtk.h>
        #include <plugin.h>


        CssedPlugin* plugin;
        gint pos;
        
        // ... build the plugin ....
        pos = cssed_plugin_get_current_position( plugin );      
        cssed_plugin_set_current_position( plugin, pos+1 ); // advance 1 char

cssed_plugin_set_current_line

        #include <gtk/gtk.h>
        #include <plugin.h>


        CssedPlugin* plugin;
        gint line;
        
        // ... build the plugin ....
        line = cssed_plugin_get_current_line( plugin ); 
        cssed_plugin_set_current_line( plugin, pos+1 ); // advance 1 line

cssed_plugin_get_current_line

        #include <gtk/gtk.h>
        #include <plugin.h>


        CssedPlugin* plugin;
        gint line;
        
        // ... build the plugin ....
        line = cssed_plugin_get_current_line( plugin ); 
        cssed_plugin_set_current_line( plugin, pos+1 ); // advance 1 line

cssed_plugin_get_line_end_from_position

        #include <gtk/gtk.h>
        #include <plugin.h>


        CssedPlugin* plugin;
        gint pos, end;
        
        // ... build the plugin ....
        pos = cssed_plugin_get_current_position( plugin );      
        end = cssed_plugin_get_line_end_from_position( plugin, pos );   
        cssed_plugin_output_write( plugin, "The line at %d pos ends at %d", pos, end );

cssed_plugin_show_user_list

        #include <gtk/gtk.h>
        #include <plugin.h>


        CssedPlugin* plugin;
        
        // ... build the plugin ....
        cssed_plugin_show_user_list( plugin, "h1 h2 h3 h4 h5 h5" );

cssed_plugin_show_autocompletion_list

        #include <gtk/gtk.h>
        #include <plugin.h>


        CssedPlugin* plugin;
        
        // ... build the plugin ....
        cssed_plugin_add_text( plugin, "a:" );  
        cssed_plugin_show_autocompletion_list( plugin, 0, "link hover active visited" );

cssed_plugin_autocompletion_cancel

        #include <gtk/gtk.h>
        #include <plugin.h>


        CssedPlugin* plugin;
        
        // ... build the plugin ....
        if( cssed_plugin_is_autocompletion_active( plugin ) ){
                cssed_plugin_autocompletion_cancel( plugin );
        }

cssed_plugin_is_autocompletion_active

        #include <gtk/gtk.h>
        #include <plugin.h>


        CssedPlugin* plugin;
        
        // ... build the plugin ....
        if( cssed_plugin_is_autocompletion_active( plugin ) ){
                cssed_plugin_autocompletion_cancel( plugin );
        }

cssed_plugin_autocompletion_select

        #include <gtk/gtk.h>
        #include <plugin.h>


        CssedPlugin* plugin;
        
        // ... build the plugin ....
        cssed_plugin_add_text( plugin, "a:a" ); 
        cssed_plugin_show_autocompletion_list( plugin, 1, "link hover active visited" );
        cssed_plugin_autocompletion_select( plugin, "a" );

cssed_plugin_show_calltip

        #include <gtk/gtk.h>
        #include <plugin.h>


        CssedPlugin* plugin;
        
        // ... build the plugin ....
        cssed_plugin_show_calltip( plugin, 0, "cssed_plugin_cancel_calltip ( CssedPlugin* plugin )" );

cssed_plugin_cancel_calltip

        #include <gtk/gtk.h>
        #include <plugin.h>


        CssedPlugin* plugin;
        
        // ... build the plugin ....
        if( cssed_plugin_calltipactive( plugin ) ){
                cssed_plugin_cancel_calltip ( plugin );
        }

cssed_plugin_calltipactive

        #include <gtk/gtk.h>
        #include <plugin.h>


        CssedPlugin* plugin;
        
        // ... build the plugin ....
        if( cssed_plugin_calltipactive( plugin ) ){
                cssed_plugin_cancel_calltip ( plugin );
        }

cssed_plugin_calltiposstart

        #include <gtk/gtk.h>
        #include <plugin.h>


        CssedPlugin* plugin;
        gint pos;
        
        // ... build the plugin ....
        if( cssed_plugin_calltipactive( plugin ) ){
                pos = cssed_plugin_calltiposstart ( plugin );
                cssed_plugin_output_write( "Call tip started at %d", pos );
        }

Back to Index

This documentation is © Iago Rubio Sanfiz, 2004