查看: 1858|回复: 2

[有事请教] wxRuby使用StyledTextCtrl求教

[复制链接]

傻♂逼

梦石
0
星屑
374
在线时间
1606 小时
注册时间
2007-3-13
回帖
6005

烫烫烫开拓者

发表于 2012-1-24 20:03:37 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
本帖最后由 yangff 于 2012-1-24 20:05 编辑

1.
QQ截图20120124195940.png
如图,"#{aaa}"中aaa是变量却被当成字符串
$aaa.aaa后面那个"aaa"是方法名却被当成$aaa的一部分当作全局变量处理了
2.
如何实现Notepad++的那种会变色的折叠效果(边上那条表示折叠结构的线)
3.
如何实现多标签页?(一定要建多个StyledTextCtrl?我记得S是支持多页的吧,看默认的编辑器……)
下面是代码,使用时在Frame里面CodeBlock.new(self)就可以了
4. wxRuby里面哪些是可以跨平台的,或者说哪些是不行的
  1. class CodeBlock
  2.   def sci
  3.     return @sci
  4.   end
  5.   def initialize(window)
  6.     font = Font.new(12, TELETYPE, NORMAL, NORMAL,false,"Lucida Console")
  7.     @sci = StyledTextCtrl.new(window)  
  8.     @sci.set_edge_mode(STC_EDGE_LINE)
  9.     @sci.set_margin_width 0, @sci.text_width(STC_STYLE_LINENUMBER, '_9999')
  10.     @sci.set_tab_width(2)
  11.     @sci.set_use_tabs(false)
  12.     @sci.set_tab_indents(true)
  13.     @sci.set_back_space_un_indents(true)
  14.     @sci.set_indent(2)
  15.     @sci.set_edge_column(80)
  16.     @sci.style_set_font(STC_STYLE_DEFAULT, font);
  17.     @sci.style_set_foreground(STC_STYLE_DEFAULT, BLACK);
  18.     @sci.style_set_background(STC_STYLE_DEFAULT, Colour.new(250,255,250));
  19.     @sci.style_clear_all()
  20.     @sci.ensure_caret_visible();
  21.     @sci.set_caret_line_visible(true)
  22.     @sci.set_caret_line_background(Colour.new(200,200,248))
  23.     @sci.set_caret_line_back_alpha(40)
  24.     @sci.style_set_foreground(STC_STYLE_LINENUMBER, LIGHT_GREY);
  25.     @sci.style_set_background(STC_STYLE_LINENUMBER, WHITE);
  26.     @sci.style_set_foreground(STC_STYLE_INDENTGUIDE, LIGHT_GREY);
  27.     @sci.set_lexer(STC_LEX_RUBY)
  28.     @sci.style_set_foreground(0, Colour.new(0,0,0))           #SCE_RB_DEFAULT
  29.     @sci.style_set_foreground(2,Colour.new(0,128,0))          #SCE_RB_COMMENTLINE
  30.     @sci.style_set_foreground(3, Colour.new(0,128,0))         #SCE_RB_POD
  31.     @sci.style_set_foreground(4, Colour.new(128,0,0))         #SCE_RB_NUMBER
  32.     @sci.style_set_foreground(5, BLUE)                        #SCE_RB_WORD
  33.     @sci.style_set_foreground(6, Colour.new(128,0,128))       #SCE_RB_STRING
  34.     @sci.style_set_foreground(7, Colour.new(128,0,128))       #SCE_RB_CHARACTER
  35.     @sci.style_set_foreground(8, Colour.new(0,0,128))         #SCE_RB_CLASSNAME
  36.     @sci.style_set_foreground(9, Colour.new(0,0,128))         #SCE_RB_DEFNAME
  37.     @sci.style_set_foreground(10, Colour.new(0,128,192))      #SCE_RB_OPERATOR
  38.     #@sci.style_set_bold(11,true)                             #SCE_RB_IDENTIFIER 局部变量 函数。。
  39.     #@sci.style_set_italic(11,true)
  40.     @sci.style_set_foreground(12,Colour.new(128,0,128))       #SCE_RB_REGEX
  41.     @sci.style_set_italic(13,true)                            #SCE_RB_GLOBAL
  42.     @sci.style_set_bold(13,true)
  43.     @sci.style_set_foreground(14,Colour.new(192,96,0))        #SCE_RB_SYMBOL
  44.     @sci.style_set_foreground(15, Colour.new(0,0,128))        #SCE_RB_MODULE_NAME
  45.     @sci.style_set_italic(16,true)                            #SCE_RB_INSTANCE_VAR
  46.     #@sci.style_set_bold(16,true)                             #SCE_RB_INSTANCE_VAR
  47.     @sci.style_set_italic(17,true)                            #SCE_RB_CLASS_VAR
  48.     @sci.style_set_bold(17,true)                              #SCE_RB_CLASS_VAR
  49.     @sci.style_set_foreground(18, Colour.new(128,0,128))      #SCE_RB_BACKTICKS
  50.     #SCE_RB_DATASECTION
  51.     @sci.style_set_foreground(19, Colour.new(0,0,0))          #SCE_RB_DATASECTION
  52.     @sci.style_set_foreground(20, Colour.new(128,0,128))      #SCE_RB_HERE_DELIM
  53.     @sci.style_set_foreground(21, Colour.new(128,0,128))      #SCE_RB_HERE_DELIM Q
  54.     @sci.style_set_foreground(22, Colour.new(128,0,128))      #SCE_RB_HERE_DELIM QQ
  55.     @sci.style_set_foreground(23, Colour.new(128,0,128))      #SCE_RB_HERE_DELIM QX
  56.     @sci.style_set_foreground(24, Colour.new(128,0,128))      #SCE_RB_STRING Q  
  57.     @sci.style_set_foreground(25, Colour.new(128,0,128))      #SCE_RB_STRING QQ
  58.     @sci.style_set_foreground(26, Colour.new(128,0,128))      #SCE_RB_STRING QX
  59.     @sci.style_set_foreground(27, Colour.new(128,0,128))      #SCE_RB_STRING QR
  60.     @sci.style_set_foreground(28, Colour.new(128,0,128))      #SCE_RB_STRING QW
  61.     @sci.style_set_foreground(29, BLUE)                       #SCE_RB_WORD_DEMOTED
  62.     @sci.style_set_foreground(30, BLUE)                       #SCE_RB_STDIN
  63.     @sci.style_set_foreground(31, BLUE)                       #SCE_RB_STDOUT
  64.     @sci.style_set_foreground(40, BLUE)                       #SCE_RB_STDERR
  65.    
  66.     #SCE_RB_UPPER_BOUND
  67.     @sci.set_key_words(0, "attr_accessor attr_reader attr_writer module_function begin break elsif module retry unless end case next return until class ensure nil self when def false not super while alias defined? for or then yield and do if redo true else in rescue undef")
  68.    
  69.    
  70.     @sci.set_property("fold","1")
  71.     @sci.set_property("fold.compact", "0")
  72.     @sci.set_property("fold.comment", "1")
  73.     @sci.set_property("fold.preprocessor", "1")
  74.    
  75.     @sci.set_margin_width(1, 0)
  76.     @sci.set_margin_type(1, STC_MARGIN_SYMBOL)
  77.     @sci.set_margin_mask(1, STC_MASK_FOLDERS)
  78.     @sci.set_margin_width(1, 20)

  79.     @sci.marker_define(STC_MARKNUM_FOLDER, STC_MARK_PLUS)
  80.     @sci.marker_define(STC_MARKNUM_FOLDEROPEN, STC_MARK_MINUS)
  81.     @sci.marker_define(STC_MARKNUM_FOLDEREND, STC_MARK_EMPTY)
  82.     @sci.marker_define(STC_MARKNUM_FOLDERMIDTAIL, STC_MARK_EMPTY)
  83.     @sci.marker_define(STC_MARKNUM_FOLDEROPENMID, STC_MARK_EMPTY)
  84.     @sci.marker_define(STC_MARKNUM_FOLDERSUB, STC_MARK_EMPTY)
  85.     @sci.marker_define(STC_MARKNUM_FOLDERTAIL, STC_MARK_EMPTY)
  86.     #SendEditor(SCI_SETFOLDFLAGS, 16, 0);
  87.     @sci.set_fold_flags(16)

  88.     @sci.set_margin_sensitive(1,1)
  89.    
  90.    
  91.     @sci.set_margin_type(0,STC_MARGIN_SYMBOL)
  92.     @sci.set_margin_width(0, 10)
  93.     @sci.set_margin_mask(0,1)
  94.     @sci.marker_define(0,STC_MARK_ARROW)
  95.     @sci.set_margin_sensitive(0,1)
  96.     @sci.marker_set_foreground(0,Colour.new(255,0,0))
  97.     #@sci.marker_add(0,0)

  98.     window.evt_stc_charadded(@sci.get_id) {|evt| onCharadded(evt)}
  99.     window.evt_stc_marginclick(@sci.get_id) {|evt| onMarginClick(evt)}
  100.     #window.evt_stc_markerclick(@sci.get_id) {|evt| onMarkerClick(evt)}
  101.   end

  102.   def onCharadded(evt)
  103.     chr =  evt.get_key
  104.     curr_line = @sci.get_current_line
  105.    
  106.     if(chr == 13)
  107.         if curr_line > 0
  108.           line_ind = @sci.get_line_indentation(curr_line - 1)
  109.           if line_ind > 0
  110.             @sci.set_line_indentation(curr_line, line_ind)
  111.             @sci.goto_pos(@sci.position_from_line(curr_line)+line_ind)
  112.           end
  113.         end
  114.     end

  115.   end

  116.   def onMarginClick(evt)
  117.     line_num = @sci.line_from_position(evt.get_position)
  118.     margin = evt.get_margin
  119.     if(margin == 0)
  120.       if @sci.marker_get(line_num)==1
  121.         @sci.marker_delete(line_num,0)
  122.       else
  123.         @sci.marker_add(line_num,0)
  124.       end
  125.       
  126.     end
  127.     if(margin == 1)
  128.       @sci.toggle_fold(line_num)
  129.       
  130.     end  

  131.   end

  132. end
复制代码

点评

http://ondineyuga.com/svn/RGE2/Tools/RGESEditor/RGESEditor_lang/EditorScintilla/Scintilla.cs  发表于 2012-1-25 12:02
哎呀,蛋疼什么的最有爱了

虚構歪曲

梦石
0
星屑
354
在线时间
1196 小时
注册时间
2010-12-18
回帖
3842

贵宾

发表于 2012-1-24 20:07:11 | 显示全部楼层
本帖最后由 忧雪の伤 于 2012-1-24 20:07 编辑

竟然是用 Ruby 写的?
回复

使用道具 举报

傻♂逼

梦石
0
星屑
374
在线时间
1606 小时
注册时间
2007-3-13
回帖
6005

烫烫烫开拓者

 楼主| 发表于 2012-1-24 21:33:41 | 显示全部楼层
哎呀,蛋疼什么的最有爱了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部