Chinaunix首页 | 论坛 | 博客
  • 博客访问: 110888
  • 博文数量: 16
  • 博客积分: 55
  • 博客等级: 民兵
  • 技术积分: 235
  • 用 户 组: 普通用户
  • 注册时间: 2012-10-25 21:49
个人简介

我的观点,您的建议!如有问题,敬请留言!

文章存档

2013年(12)

2012年(4)

我的朋友

分类: LINUX

2013-06-26 22:24:58

Sublime Text 2是一款功能很强大的图形界面的编辑器,可以安装各种插件,使之功能很强大!

  Ubuntu下 安装方法:
              

点击(此处)折叠或打开

  1. sudo add-apt-repository ppa:webupd8team/sublime-text-2
  2. sudo apt-get update
  3. sudo apt-get install sublime-text


   
! 注意: 
    Sublime Text安装好后一般是不能输入汉字      
    编译共享内库:
1.   保存下述代码为 sublime-imfix.c 文件;
     

点击(此处)折叠或打开

  1. /*
  2. sublime-imfix.c
  3. Use LD_PRELOAD to interpose some function to fix sublime input method support for linux.
  4. By Cjacker Huang <jianzhong.huang at i-soft.com.cn>

  5. gcc -shared -o libsublime-imfix.so sublime_imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC
  6. LD_PRELOAD=./libsublime-imfix.so sublime_text
  7. */
  8. #include <gtk/gtk.h>
  9. #include <gdk/gdkx.h>
  10. typedef GdkSegment GdkRegionBox;

  11. struct _GdkRegion
  12. {
  13.   long size;
  14.   long numRects;
  15.   GdkRegionBox *rects;
  16.   GdkRegionBox extents;
  17. };

  18. GtkIMContext *local_context;

  19. void
  20. gdk_region_get_clipbox (const GdkRegion *region,
  21.             GdkRectangle *rectangle)
  22. {
  23.   g_return_if_fail (region != NULL);
  24.   g_return_if_fail (rectangle != NULL);

  25.   rectangle->x = region->extents.x1;
  26.   rectangle->y = region->extents.y1;
  27.   rectangle->width = region->extents.x2 - region->extents.x1;
  28.   rectangle->height = region->extents.y2 - region->extents.y1;
  29.   GdkRectangle rect;
  30.   rect.x = rectangle->x;
  31.   rect.y = rectangle->y;
  32.   rect.width = 0;
  33.   rect.height = rectangle->height;
  34.   //The caret width is 2;
  35.   //Maybe sometimes we will make a mistake, but for most of the time, it should be the caret.
  36.   if(rectangle->width == 2 && GTK_IS_IM_CONTEXT(local_context)) {
  37.         gtk_im_context_set_cursor_location(local_context, rectangle);
  38.   }
  39. }

  40. //this is needed, for example, if you input something in file dialog and return back the edit area
  41. //context will lost, so here we set it again.

  42. static GdkFilterReturn event_filter (GdkXEvent *xevent, GdkEvent *event, gpointer im_context)
  43. {
  44.     XEvent *xev = (XEvent *)xevent;
  45.     if(xev->type == KeyRelease && GTK_IS_IM_CONTEXT(im_context)) {
  46.        GdkWindow * win = g_object_get_data(G_OBJECT(im_context),"window");
  47.        if(GDK_IS_WINDOW(win))
  48.          gtk_im_context_set_client_window(im_context, win);
  49.     }
  50.     return GDK_FILTER_CONTINUE;
  51. }

  52. void gtk_im_context_set_client_window (GtkIMContext *context,
  53.           GdkWindow *window)
  54. {
  55.   GtkIMContextClass *klass;
  56.   g_return_if_fail (GTK_IS_IM_CONTEXT (context));
  57.   klass = GTK_IM_CONTEXT_GET_CLASS (context);
  58.   if (klass->set_client_window)
  59.     klass->set_client_window (context, window);

  60.   if(!GDK_IS_WINDOW (window))
  61.     return;
  62.   g_object_set_data(G_OBJECT(context),"window",window);
  63.   int width = gdk_window_get_width(window);
  64.   int height = gdk_window_get_height(window);
  65.   if(width != 0 && height !=0) {
  66.     gtk_im_context_focus_in(context);
  67.     local_context = context;
  68.   }
  69.   gdk_window_add_filter (window, event_filter, context);
  70. }
2.安装C/C++的编译环境和gtk libgtk2.0-dev.

点击(此处)折叠或打开

  1. sudo apt-get install build-essential
  2. sudo apt-get install libgtk2.0-dev

 3.编译共享内库;]

点击(此处)折叠或打开

  1. gcc -shared -o libsublime-imfix.so sublime_imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC

4.启动 Sublime Text 2

好了,现在执行下述命令启动 Sublime Text 2,就可以使用fcitx输入中文了!


点击(此处)折叠或打开

  1. LD_PRELOAD=./libsublime-imfix.so sublime_text

5.但是这样的话,我们每次都要在终端里面使用命令启动sublime text 2,这样很不方便,接下来我们还要通过修改sublime-text-2.desktop达到点击图标启动。

    将libsublime-imfix.so移动到/usr/lib/;

点击(此处)折叠或打开

  1. sudo mv ./libsublime-imfix.so /usr/lib/
     打开终端进入applications修改sublime-text-2.desktop;
     

点击(此处)折叠或打开

  1. sudo gedit /usr/share/applications/sublime-text-2.desktop
打开sublime-text-2.desktop后,将

点击(此处)折叠或打开

  1. Exec=/usr/bin/subl %F
修改为

点击(此处)折叠或打开

  1. Exec=bash -c 'LD_PRELOAD=/usr/lib/libsublime-imfix.so /usr/bin/sublime-text' %F
还有将[[Desktop Action Window]下的

点击(此处)折叠或打开

  1. Exec=/usr/bin/sublime-text
修改为

点击(此处)折叠或打开

  1. Exec=bash -c 'LD_PRELOAD=/usr/lib/libsublime-imfix.so /usr/bin/sublime-text'

 如果你想单击鼠标右键用Sublime Text就直接打开文件的话,还需要进行一点小小的修改.不然,打开是空的.
  解决办法如下:
修改这个的时候

点击(此处)折叠或打开

  1. Exec=bash -c ‘LD_PRELOAD=/usr/lib/libsublime-imfix.so /usr/bin/sublime-text-2′ %F

    把单引号放到最后,如下

点击(此处)折叠或打开

  1. Exec=bash -c ‘LD_PRELOAD=/usr/lib/libsublime-imfix.so /usr/bin/sublime-text %F’


然后,这个问题就完美解决了.好了,接下来你在dash中点击打开sublime text2吧,开始你的代码之旅吧。
  
     

Sublime Text 3 插件的汉化、开发、发布方法教程
http://my.oschina.net/theforever/blog/136554

  参考资料:http://my.oschina.net/wugaoxing/blog/121281


  


   



阅读(4395) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~