#include "py_custview.hpp" //-------------------------------------------------------------------------- class my_custviewer: public customviewer_t { private: cvdata_simpleline_t data; size_t id_n; virtual bool on_popup_menu(size_t menu_id) { if ( menu_id == id_n ) msg("popup menu N chosen!\n"); return true; } virtual bool on_click(int shift) { msg("onclick; shift=%d\n", shift); return true; } virtual void on_close() { id_n = 0; msg("closed...\n"); } virtual bool on_keydown(int key, int shift) { switch ( key ) { case 'N': warning("The hotkey 'N' has been pressed"); return true; case 'I': { int x, y; place_t *pl = get_place(false, &x, &y); if ( pl == NULL ) return false; msg("x=%d y=%d\n", x, y); simpleline_t sl = *data.get_line(pl); sl.bgcolor = bgcolor_t(~uint32(sl.bgcolor)); data.set_line(data.to_lineno(pl), sl); refresh_current(); return true; } case 'A': { char buf[100]; qsnprintf(buf, sizeof(buf), "This is line %d\n", data.count()); data.add_line(buf); msg("Added one more line...\n"); return true; } case 'S': { twinpos_t p1, p2; ::readsel2(_cv, &p1, &p2); size_t y1 = data.to_lineno(p1.at); size_t y2 = data.to_lineno(p2.at); int x1 = p1.x; int x2 = p2.x; msg("(x1=%d y1=%d) (x2=%d y2=%d)", x1, y1, x2, y2); return true; } case 'X': data.set_minmax(); return true; case 'R': refresh(); msg("refreshing!\n"); return true; case IK_ESCAPE: close(); return true; } return false; } virtual void on_curpos_changed() { qstring word; if ( get_current_word(false, word) ) msg("Current word is: %s\n", word.c_str()); } virtual bool on_hint(place_t *place, int *important_lines, qstring &hint) { simpleline_t *line = data.get_line(place); if ( line == NULL ) return false; *important_lines = 1; hint = line->line; return true; } public: void init_sample_lines() { strvec_t &lines = data.get_lines(); static struct { const char *text; bgcolor_t color; } const sample_lines[] = { { "This is a sample text", 0xFFFFFF }, { "It will be displayed in the custom view", 0xFFC0C0 }, { COLSTR("This line will be colored as erroneous", SCOLOR_ERROR), 0xC0FFC0 }, { COLSTR("Every", SCOLOR_AUTOCMT) " " COLSTR("word", SCOLOR_DNAME) " " COLSTR("can", SCOLOR_IMPNAME) " " COLSTR("be", SCOLOR_NUMBER) " " COLSTR("colored!", SCOLOR_EXTRA), 0xC0C0FF }, { " No limit on the number of lines.", 0xC0FFFF }, }; for ( int i=0; iinit("My sample viewer!") ) { msg("Failed to create cv\n!"); return; } g_cv->show(); } #define DRIVER_INIT int driver_init() { g_cv = new my_custviewer(); return PLUGIN_KEEP; } #define DRIVER_TERM void driver_term() { g_cv->close(); delete g_cv; }