让gedit有编译执行的能力(原创) 程序

让gedit有编译执行的能力(原创) 程序
Post by wolfItem on 2009-11-22 2:11 Sunday


在linux 下开发C 我一直用gedit编译.gedit可以安装一些组件来扩展很多功能.

每次写好代码都要用 命令行用gcc 编译执行.感觉很麻烦..就想有没有办法可以像集成开发环境一样,点按钮就自动编译执行了... 后来自己研究了gedit的功能.发现可以通过shell 自定义一些tools .

现在我把我写的编译与执行的工具代码复制上来.方便大家使用gedit编程. 大家可以看一看..欢迎提供宝贵意见!


#!/bin/sh
# [Gedit Tool]
# Name=编译当前文件
# Shortcut=F5
# Applicability=all
# Output=output-panel
# Input=nothing
# Save-files=nothing

clear
echo "开始编译...."
binfile=$(echo "$GEDIT_CURRENT_DOCUMENT_NAME" |cut -d "." -f1)

gcc $GEDIT_CURRENT_DOCUMENT_NAME -o $binfile
num=$?;
if [ $num -eq 0 ] ;then
ls -l $binfile;
echo "生成 $binfile 文件";
echo "$GEDIT_CURRENT_DOCUMENT_NAME 编译完成!"

#如果想编译后执行请加去掉下面的两行代码的#号
#echo "执行...";
#./$binfile;


else
echo "编译失败!";
fi



现在按F5就可以编译.执行你现在写的C程序了.上面的功能很简单.大家可以通过在这基础上做修改来编译其它语言. 有问题请留言!



原创文章如转载,请注明:转载自wolfitem [ https://www.360docs.net/doc/7813104355.html,/ ]

本文链接地址:https://www.360docs.net/doc/7813104355.html,/blog/post-85.html



标签: Linux C

linux 简单C编写2011-03-08 12:52在windows下写C程序是一件很容易的事,装好Turbo C就可以了,相信各位学过编程的都十分了解Turbo C吧。特别是现在大学里人人忙考级的情况下,二级C语言大概成了每个人默认考过的等级考试吧。可是在linux下又如何写C程序呢?其实,linux下写 C也是很容易的。IDE的话用 eclipse 集成 CDT 模块就行了。当然这属于重量级的了,就如同VC++之于windows一样。那有没有像Turbo C那样的小工具呢,主要也就是用到它的编译功能。恩,这就是这次我们要说的 GCC 了。

根据 wikipedia (google)上的定义,GCC(GNU Compiler Collection,GNU编译器套装),是一套由GNU开发的编程语言编译器。它是GNU toolchain的关键部分,亦是开放源代码的类Unix操作系统的标准编译器。

GCC跟Turbo C的处理过程大同小异,其由C语言源代码文件生成可执行文件的过程不仅仅是编译的过程,而是要经历四个相互关联的步骤∶预处理(也称预编译,Preprocessing)、编译(Compilation)、汇编(Assembly)和连接(Linking)。所以,基本上可以这么说,用过 Turbo C的,很容易就会习惯GCC了。

好了,现在我们来写个简单的程序吧。首先是安装GCC,如果你使用的是Ubuntu,则在终端中输入以下命令来安装GCC。

sudo apt-get install gcc
C就可以写程序了?别急

,现在GCC什么文件都还不能编译呢。还记得在Turbo C上我们不是还要设置头文件的路径吗?是的,我们需要安装这些头文件,这就是build- essential软件包。安装好这个包,系统就会自动安装上g++,libc6-dev,linux-libc- dev,libstdc++6-4.1- dev等一些必须的软件和头文件的库。我们可以在终端中输入下面命令来安装:

sudo apt-get install build-essential

好了,环境搭建完毕,就让我们开始动手写程序吧。首先来个最经典的hello world热热身。用 gedit 或者 vi 写下这个程序,并保存为hello.c。

#include

int main()

{

printf( “Hello world!\n” );

return 0;

}

将文件保存为hello.c后,在终端中使用敲入以下命令来使用GCC对程序进行编译。

gcc hello.c -o hello

编译通过后,我们会在当前目录中看到hello文件,这就是编译后生成的可执行文件。好了,我们来运行一下它,来跟world打个招呼。

./hello

我们可以看到在终端中输出了”Hello world!”,这就说明我们的程序运行成功了。

最后,需要特别说明的是GCC中对于文件后缀的规定有点特殊,特别是C++源代码文件的后缀不是cpp,而是cc或cxx。

.c为后缀的文件,C语言源代码文件;

.a为后缀的文件,是由目标文件构成的档案库文件;

.C,.cc或.cxx 为后缀的文件,是C++源代码文件;

.h为后缀的文件,是程序所包含的头文件;

.i 为后缀的文件,是已经预处理过的C源代码文件;

.ii为后缀的文件,是已经预处理过的C++源代码文件;

.m为后缀的文件,是Objective-C源代码文件;

.o为后缀的文件,是编译后的目标文件;

.s为后缀的文件,是汇编语言源代码文件;

.S为后缀的文件,是经过预编译的汇编语言源代码文件。

好了,发挥想象力尽情写程序吧!

来自
https://www.360docs.net/doc/7813104355.html,/Linux/2007-11/9200.htm


让gedit成为强大的C语言IDE
2009-12-05 13:13 835人阅读 评论(1) 收藏 举报



gedit是个简单易用的文本编辑器。gedit可扩展性很强,我们可以通过给gedit添加插件,让gedit成为一个强大的C语言IDE。gedit不支持代码自动缩进和自动代码提示,可以给gedit添加Smart indentation plugin for C/C++/Java 和 Word Completion 这两个插件,让gedit对C语言代码能够自动缩进和自动提示。Word Completion 并不能对库函数进行提示,它只能提示你在文件里输入过的单词。我们还可以给gedit添加一个终端插件Open terminal here,它可以在当前文件的目录下打开一个终端,这样可以方便我们用GCC编译代码。



下载



Smart indentation plugin for C/C++/Java的下载地址:https://www.360docs.net/doc/7813104355.html,/Gedit/Plugins?action=AttachFile&do=get&target=csmartindent.tar.gz



Word Completion 的下载地址:h

ttp://https://www.360docs.net/doc/7813104355.html,k.fi/~otsaloma/gedit/ (注意:把completion.gedit-plugin 和 completion.py 这两个文件下载就可以)



Open terminal here 的下载地址:https://www.360docs.net/doc/7813104355.html,/files/open-terminal-here.tar.gz




如果我们还需要其他的一些插件可以在https://www.360docs.net/doc/7813104355.html,/Gedit/Plugins下载





添加插件




gedit插件都存放在gedit目录下的plugins文件夹下。我的系统是rhel 5 ,gedit插件的存放目录是:/usr/lib/gedit-2/plugins/ 如果你不知道gedit目录在哪里,搜索下gedit。



我们把上面的插件下载完后,解压并复制到plugins文件夹下,这样就完成了插件的添加。但是这些插件还没有启用,需要在gedit里分别启用他们。





打开gedit,选择编辑->首选项->插件,在插件列表里把C-style Indentation、Open Terminal Here、Word completion这三个给勾上,关闭首选项,关闭gedit,重新启动gedit,这时的gedit就有了代码缩进和代码提示功能了。编写完代码后,可以直接点工具里的Open Terminal Here打开终端,用gcc编译代码和运行。

gedit插件配置
分类: 嵌入式 2011-01-13 11:18 294人阅读 评论(0) 收藏 举报
使用gEdit搭配terminal来写程序也有一段时间了,但一直当它是windows下的notepad,没有好好熟悉下它,今天无意中发现原来 gEdit也可以打造一个不错的编程环境。这里对相关的资料收集总结了一下,与大家共享。
gEdit是GNOME桌面环境中默认的文本编辑器,它 简单易用,对中文支持良好,支持多种字符编码,同时具有开放的插件支持特性。通过安装插件,作一些简单的设置,gEdit就可以做为一个简洁的编程环境。 在我的ubuntu 8.04下,默认情况只安装了gedit包,还有以下几个插件:


代码:
Change case: Changes the case of selected text.
Document Statistics: Analyses the current document and reports the number of words, lines, characters and non-space characters in it.
External tools: Execute external commands and shell scripts. (More)
File Browser: A file browser plugin allowing to easily access your filesystem (includes remote mounts, creating new files/dirs, monitor dirs for changes, etc) (More)
Indent: Indents or un-indents selected lines.
Modelines: Emacs, Kate and Vim-style modelines support for gedit.
Python console: Interactive python console standing in the bottom panel.
Snippets: Insert often used pieces of text in a fast way. (More)
Sort: Sorts a document or selected text.
Spell: Checks the spelling of the current document.
Tag list: Provides a method to easily insert into a document commonly used tags/strings without having to type them.
Insert Date/Time: Inserts current date and time at the cursor position.

就编程而言,我觉得比较有用的有External tools(外部工具),通过它在菜单上集成shell命令来编译运

行程序(由于不是交互性的shell,所以不便用于debug);File Browser(文件浏览器),提供一个多文件(工程)的视图,还有可以编辑远程文件,虽然后者我很少用到;Snippets(片断),提供一种代码模板 以快速输入,如我在snippets->C++下定义了如下for循环:

代码:
for( $1 ; $2 ; ${3:++ix} )
{
$4
}
$0

并且其Tab触发器设置为forlp+tab(表示输入 forlp,然后按下tab键)。之后在代码中每当我要输入for循环,在C++的源文件中,只需输入forlp,然后按下tab键,forlp+tab 就会自动扩展成上面的for循环,光标会处于$1处,此时可以直接输入for的初始条件,然后按一下tab,光标会跳到$2处,再按tab,跳到$3处, 如此类推。$3处设置了默认值++ix,如果直接按tab跳过,就为默认值++ix,如果输入ix++之后再按tab跳到$4,默认值就会被ix++覆 盖。$0为此模块最后跳转到的位置。
此外Tag list对编写网页等多tag源文件比较有用,Indent方便我们对代码进行缩进与取消缩进。默认安装好系统后,gedit能通过后缀正确识别到不同语 言的源代码,其语法高亮也做得比较好。但是要作为一个编程环境还有很多不方便的地方,此时就要安装另外一些插件来完善其功能了,首先我们安装软件源中 gedit的plugin集,terminal下输入:

代码:
$ sudo apt-get install gedit-plugins

安 装gedit-plugins。其中包括

代码:
* Smart Spaces: Forget you're not using tabulations. <=== 智能空格
* Embedded Terminal: Embed a terminal in the bottom pane. <=== 内嵌的terminal,应该是最有用的一个插件了,有了它,我们就可以不用上面External tools来编译调试程序啦,而且也不用心烦在gedit与terminal之间来回切换了,不足之处是貌似只能有一个terminal,有时不够方便。
* Show/Hide Tabbar: Add a menu entry to show/hide the tabbar. <=== 显示/隐藏标签栏
* Join/Split Lines: Join several lines or split long ones <=== 合并/分割行
* Color Picker: Pick a color from a dialog and insert its hexadecimal representation. <=== 拾色器
* Draw Spaces: Draw Spaces and Tabs <=== 特别显示空格与制表符
* Session Saver: Save and restore your working sessions <=== 会话保存 不过貌似不怎么管用哦,>3<
* Code comment: Comment out or uncomment a selected block of code. <=== 注释代码,这下要注释大片代码就方便了
* Bracket Completion: Automatically adds closing brackets. <=== 自动的括号补全
* Character Map: Insert special characters just by clicking on them. <=== 对特殊字符集映射,暂时对我而言没什么用

安装好后将觉得有用的插件启用,不用的插件禁用掉。比起notepad已经好用了很多,但是 还不够,要让gEdit变得更方便,登录gEdit的插件网站https://www.360docs.net/doc/7813104355.html,/Gedit/Plu

gins ,选择你需要的插件啦。这里写下个人觉得写代码比较有用的几个插件,仅供参考:
1.Class Browser:显示代码中类,函数,宏等的大纲,类似于VC或eclipse的类视图,支持多种语言,但这个插件相对简单,另一个Symbol Browser貌似更强大,不过暂时我找不到下载。
2.单词自动补全,有多个word completion的小插件,功能大同小异,都支持自动补全前文或所有打开的文件标签中已经出现过的单词,类似于visual assist或eclipse的自动补全功能,不足在于暂时不支持根据不同语言提供不同的关键字自动补全
3.Full screen: 在打开文件的情况下将gEdit全屏,偶尔会用下。
4.Open terminal here: 在当前文件夹下打开新terminal,有了Embedded Terminal这个插件比较鸡肋了
5.session autosave: 记录上次退出gEdit时打开的文件,下次打开时重新打开这些文件,由于止面的Session Saver好像不能用,所以装了这个。打开多个相关文件时比较有用,退出后下次就不用一个个文件手动打开啦
6.Code Formatter:自动格式化
7.snap open: 输入文件名(支持正则表达式)查找并打开文件
8.vigedit: 支持vi快捷键
9.Tabs Extend: 扩展的标签功能支持
gEdit的插件多用python来写,我们可以根据自己的偏好来修改 编写,gEdit的插件网站上也有很多的插件,可以根据自己的需要酌情安装。这些插件都放在~/.gnome2/gedit/plugins/目录下,如 果没有此目录则创建一个,下载的插件可以直接放到此目录下。
很多人可能习惯去改变编辑器的配色(代码高亮,像定制vim或Emacs时常常做的那 样),使经常面对着电脑写代码的眼睛没那么累,在gEdit的菜单 [编辑]->[首选项]->[字体和颜色] 中,只有4种配色可选,此外通过GUI并不能具体定制配色。要DIY配色的话,我们可以从网上下载载配置文件,添加配色,或自己重新写一个。下面提供两个 配色文件下载网站:
1. https://www.360docs.net/doc/7813104355.html,/mig/gedit-themes/tree/master
2. https://www.360docs.net/doc/7813104355.html,/GtkSourceView/StyleSchemes
gEdit 使用的是gtksourceview,我们将后缀为.xml的文件下载并放入
1. /usr/share/gtksourceview-2.0/styles <==== 所有用户均可用
or 2. ~/.gnome2/gedit/styles <==== 只有你自己可用
重启一次gedit,就可以在[编辑]->[首选 项]->[字体和颜色]选择喜欢的配色,也可以修改配色文件来DIY自己的Style.再定义一种好看的字体,对行号,备份时间等简单设置一下,整 个编辑环境就相当个性,舒服啦。
虽然比不上vim,emacs的灵活,也比不上IDE的强大,但Gedit也是不错的一种工具。即使搭配了众多的 插件,gEdit还是相当轻量的编辑器,如你像我一样,用不习惯vim或Emacs,又不喜欢那些慢悠悠的IDE,那就试下系统默认安装的Gedit吧。

分享到: 上一

篇:Ubuntu远程控制Windows XP系统
让gedit有编译执行的能力(原创) 程序
Post by wolfItem on 2009-11-22 2:11 Sunday


在linux 下开发C 我一直用gedit编译.gedit可以安装一些组件来扩展很多功能.

每次写好代码都要用 命令行用gcc 编译执行.感觉很麻烦..就想有没有办法可以像集成开发环境一样,点按钮就自动编译执行了... 后来自己研究了gedit的功能.发现可以通过shell 自定义一些tools .

现在我把我写的编译与执行的工具代码复制上来.方便大家使用gedit编程. 大家可以看一看..欢迎提供宝贵意见!


#!/bin/sh
# [Gedit Tool]
# Name=编译当前文件
# Shortcut=F5
# Applicability=all
# Output=output-panel
# Input=nothing
# Save-files=nothing

clear
echo "开始编译...."
binfile=$(echo "$GEDIT_CURRENT_DOCUMENT_NAME" |cut -d "." -f1)

gcc $GEDIT_CURRENT_DOCUMENT_NAME -o $binfile
num=$?;
if [ $num -eq 0 ] ;then
ls -l $binfile;
echo "生成 $binfile 文件";
echo "$GEDIT_CURRENT_DOCUMENT_NAME 编译完成!"

#如果想编译后执行请加去掉下面的两行代码的#号
#echo "执行...";
#./$binfile;


else
echo "编译失败!";
fi



现在按F5就可以编译.执行你现在写的C程序了.上面的功能很简单.大家可以通过在这基础上做修改来编译其它语言. 有问题请留言!



原创文章如转载,请注明:转载自wolfitem [ https://www.360docs.net/doc/7813104355.html,/ ]


Gedit New MDI plugin tutor.
-Muthiah Annamalai


Warning
Written for Gedit 2-new-mdi branch of CVS Please get if from https://www.360docs.net/doc/7813104355.html, using

$export CVSROOT=:pserver:anonymous@https://www.360docs.net/doc/7813104355.html,:/cvs/gnome
$cvs update -r 'new_mdi' gedit
$cvs update -r 'new_mdi' geditGedit is a very simple text editor. Its architecture is centered around a single gedit-window, that is a document viewer, and helps view text, and provides controls.

We can add new functionality to Gedit, using plugins. For making a plugin we have to do the following. Note: $plugin refers to the name of your plugin. eg os, changecase


0: make a new folder called $plugin in /gedit/plugins/$plugin

1: write your source file in c. $plugin/$plugin.c

write your $plugin.gedit-plugin.desktop.in

write your $plugin.gedit-plugin

2: write a Makefile.am there.

3: Edit /gedit/configure.in,
and add $plugin/Makefile in the AC_OUTPUT variable list.

Edit /gedit/plugins/Makefile.am
and add $plugin to DISTDIR SUBDIR variables.

4: compile gedit sources
5: install the module at $HOME/.gnome2/gedit/plugins/
This means the $plugin.gedit-plugin file, lib$https://www.360docs.net/doc/7813104355.html, and
the lib$plugin.so files.

See the default plugins present at
$prefix/lib/gedit-2/plugins/savecopy.gedit-plugin
eg, /usr/lib/gedit-2/plugins/savecopy.gedit-plugin or
/opt/lib/gedit-2/plugins/savecopy.gedit-pluginThe rest of this article is about step 1, writing your plugin.


New Plugin API


The plugin API is undergone a change in the new_MDI branch of gedit. This API uses a GObject as an underlying mechanism for plugin operation, and gives a more OO API, and lets us think in terms of Obejcts, overriding, inheritance etc.


Intro about GObject.
see Mathieu Lacages tutorial at https://www.360docs.net/doc/7813104355.html,/papers/gobject/


Plugin Structure
Plugin structure is defined in gedit sources at /gedit/gedit-plugin.h and its made of a structure GeditPlugin which has the first element as the GObject.


/*
* Main object structure
*/
typedef struct _GeditPlugin GeditPlugin;

struct _GeditPlugin
{
GObject parent;
};If you lookinto the class structure, GeditPluginClass you see


/*
* Class definition
*/
typedef struct _GeditPluginClass GeditPluginClass;

struct _GeditPluginClass
{
GObjectClass parent_class;

/* Virtual public methods */

void (*activate) (GeditPlugin *plugin,
GeditWindow *window);
void (*deactivate) (GeditPlugin *plugin,
GeditWindow *window);

void (*update_ui) (GeditPlugin *plugin,
GeditWindow *window);

GtkWidget *(*create_configure_dialog)
(GeditPlugin *plugin);

/* TODO: add place holders */
};again, inheritance [substructures], and lots of pointer to functions which are in C++ terms, member functions .

If you know the GObject system, and API you will find that each GObject {and so also its derivative} have to be created, using g_object_new(TYPE_CODE,arg1,arg2,etc); where TYPE_CODE is the unique number for your $plugin_type when you register with the GType system.

Now g_object_new() calls the following functions in order, *

g_$plugin_get_type()
This function executes once, and registers, is a singleton style. Every other time its called, it can only return the earlier got type value.
g_$plugin_class_init()
This is called only once, to set/override static type members, and member functions.
g_$plugin_instance_init()
This is called everytime a g_object_new() is invoked on the $plugin type. Here you will setup your member variables, and values. This is C++ equivalent of a constructor.
Thus you have a brand new object (GObject) in your hands!

When the object's reference count drops to zero, we call g_$plugin_destroy().

g_$plugin_destroy()

This function delete's the instance, like a C++ destructor. It works for every object, when its ref count falls to 0.
When the no object of $plugin types exits we call g_$plugin_finalize().

g_$plugin_finalize()

If you ever had an oppurtunity to write a type of C++ runtime, or MONO, you will write class unloaders: but help your

self, this cleans up functions and static data allocations when a type is removed from the GType system. As you guessed, this is invoked only once. You cant cleanup plugins twice! Once you wipe them clean wheres all the dirt [footprint]?
Now you read the 'Public Methods' things given below, you get to see the pattern running into this GeditPlugin class.

/*
* Public methods
*/
GType gedit_plugin_get_type (void) G_GNUC_CONST;

void gedit_plugin_activate (GeditPlugin *plugin,
GeditWindow *window);
void gedit_plugin_deactivate (GeditPlugin *plugin,
GeditWindow *window);

void gedit_plugin_update_ui (GeditPlugin *plugin,
GeditWindow *window);

gboolean gedit_plugin_is_configurable (GeditPlugin *plugin);
GtkWidget *gedit_plugin_create_configure_dialog For more gyann[Hindi for enlightenment], you may read gedit-plugins-engine.h, on how gedit loads the plugin modules.

Now this gedit-plugins-engine loads the variables resembling

gchar Module*;
gchar *IAge;
gchar *Name;
gchar *Desc;
gchar *Author;
gchar *Copyright;
gchar *Website;into the a structure, from your $plugin.gedit-plugin file which are used in Gedit preferences manager, to popup an About dialog for the plugin widget.

A typical $plugin.gedit-plugin file would look like this.

[Gedit Plugin]
Module=sample
IAge=2
_Name=User name
_Description=Inserts the user name at the cursor position.
Authors=Paolo Maggi
Copyright=Copyright ? 2002-2005 Paolo Maggi
Website=https://www.360docs.net/doc/7813104355.html,Now why this $plugin.gedit-plugin.desktop.in exists is, for makefile.in to convert on conditional basis.

The rest of the $pluginClass structure's members are given below. These, you will define in your Gedit $plugin.c file and do your programming within these methods.


void (*activate) (GeditPlugin *plugin,
GeditWindow *window);
void (*deactivate) (GeditPlugin *plugin,
GeditWindow *window);

void (*update_ui) (GeditPlugin *plugin,
GeditWindow *window);

GtkWidget *(*create_configure_dialog)
(GeditPlugin *plugin);
Init
will be performed within your $plugin_class_init function, which is to setup your $plugin for the whole Gedit application. Some static data can be loaded into plugin->private_data field using the g_type_class_add_private (object_class, sizeof ($plugin_private)); and set its value in t

he $plugin_init() method passed to your

g_type_register_static within the $plugin_get_type() function.
Generally all these details are hidden by your, GEDIT_PLUGIN_REGISTER_TYPE is


/*
* Utility macro used to register plugins
*
* use: GEDIT_PLUGIN_REGISTER_TYPE(GeditSamplePlugin, gedit_sample_plugin)
*/

#define GEDIT_PLUGIN_REGISTER_TYPE(PluginName, plugin_name) \
\
static GType plugin_name##_type = 0; \
\
GType \
plugin_name##_get_type (void) \
{ \
return plugin_name##_type; \
} \
\
static void plugin_name##_init (PluginName *self); \
static void plugin_name##_class_init (PluginName##Class *klass); \
static gpointer plugin_name##_parent_class = NULL; \
static void plugin_name##_class_intern_init (gpointer klass) \
{ \
plugin_name##_parent_class = g_type_class_peek_parent (klass); \
plugin_name##_class_init ((PluginName##Class *) klass); \
} \
\
G_MODULE_EXPORT GType \
register_gedit_plugin (GTypeModule *module) \
{ \
static const GTypeInfo our_info = \
{ \
sizeof (PluginName##Class), \
NULL, /* base_init */ \
NULL, /* base_finalize */ \
(GClassInitFunc) plugin_name##_class_intern_init, \
NULL, \
NULL, /* class_data */ \
sizeof (PluginName), \
0, /* n_preallocs */ \
(

GInstanceInitFunc) plugin_name##_init \
}; \
\
gedit_debug_message (DEBUG_PLUGINS, "Registering " #PluginName); \
\
/* Initialise the i18n stuff */ \
bindtextdomain (GETTEXT_PACKAGE, GEDIT_LOCALEDIR); \
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); \
\
plugin_name##_type = g_type_module_register_type (module, \
GEDIT_TYPE_PLUGIN, \
#PluginName, \
&our_info, \
0); \
return plugin_name##_type; \
}


which fills the GTypeInfo structure of glib-$version/gobject/gtype.h
struct _GTypeInfo
{
/* interface types, classed types, instantiated types */
guint16 class_size;

GBaseInitFunc base_init;
GBaseFinalizeFunc base_finalize;

/* interface types, classed types, instantiated types */
GClassInitFunc class_init;
GClassFinalizeFunc class_finalize;
gconstpointer class_data;

/* instantiated types */
guint16 instance_size;
guint16 n_preallocs;
GInstanceInitFunc instance_init;

/* value handling */
const GTypeValueTable *value_table;
};and fills the functions of *

$plugin_intern_init
$plugin_class_init

Activate
is to add your plugin thing into the menubar of all gedit toplevel windows. It can be copy-paste'd from other plugins. You must replace the menu's "activate" signal callback to your plugin's function. This is the actual starting point of whatever functionality youre going to add to gedit, the rest all is plain boiler-plate code.


Deactivate
remove the menus from toplevel windows. It can also be copy-paste'd from other plugins.


create_configure_dialog
this is to give the users the choice of plugin functionality. The 'time' plugin in /gedit/plugin/time allows users to choose a time format they want. Its kinda cool. Instead of running main-loop like in earlier versions of Gedit plugins, we just need to set dialog callbacks, and set the plugin to react later. We need to return a pointer to a widget dialog.


Update UI
update ui is for enabling you plugin-menu-item to sensitive or insensitive, depending of doc is readonly or not. It can also be copy-paste'd from other plugi

ns.


Destroy
Destroy is implemented in the $plugin_finalize() method. This is generally set in the $plugin_class_init() method by overriding the parent instances finalize handler. we may destroy the statically allocated priv->data and anyother

plugin inited resources can be uninitialized.
We may a entry priv to our a custom structure, which inherits, the GeditPlugin's features, so you can load your plugin[instance] specific data, like this:


typedef struct _GeditSamplePlugin GeditSamplePlugin;

struct _GeditSamplePlugin
{
GeditPlugin parent_instance;

/*< private >*/
GeditSamplePluginPrivate *priv;
}
Boiler Plate Generation
Thats it! Oops I think you mustve been demoralized by this story? No take heart, most of this code is boiler plate and Paolo Maggi, has written a script to generate a plugin-template, so you just need to save the files, and compile it.

Go to gedit/tools/ You see a tool called generate-plugin.py Run this from the command like like this,

$ ./generate-plugin.py Hello

For generating a 'Hello' plugin template, with UI menus etc. Now move this ./Hello folder to gedit/plugins/Hello and follow steps 0-5.

Well for more details dive into a full plugin like /gedit/plugins/sample and get started.

Muthiah Annamalai.


License
LICENSE: You may distribute this under GNU FDL.


相关文档
最新文档