krot编辑器-开源

  • f9_870805
    了解作者
  • 81.3KB
    文件大小
  • 文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-04-22 02:41
    上传日期
这是krot编辑器。 创建此项目的主要目的是尝试创建新的,对我来说更方便的IDE。 希望我能达到这个目的。 今天,这是一个小型且错误的文本编辑器。
krot-0.1.tar.gz
  • krot-0.1
  • src
  • Makefile.am
    722B
  • Makefile.in
    12.6KB
  • main.c
    13.2KB
  • autogen.sh
    4.4KB
  • AUTHORS
    0B
  • COPYING
    17.6KB
  • aclocal.m4
    37.6KB
  • INSTALL
    9.3KB
  • install-sh
    9KB
  • Makefile.am
    625B
  • configure
    201.6KB
  • missing
    10.8KB
  • depcomp
    15.6KB
  • config.h.in
    633B
  • NEWS
    0B
  • TODO
    125B
  • Makefile.in
    18.7KB
  • README
    0B
  • configure.in
    472B
  • ChangeLog
    0B
内容介绍
#ifdef HAVE_CONFIG_H # include <config.h> #endif #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <string.h> #include <stdio.h> #include <bonobo.h> #include <gnome.h> #include <gtksourceview/gtksourceview.h> #include <gtksourceview/gtksourcebuffer.h> //Global variables . Temporary. GtkWidget *app1; GtkWidget *bonobodock1; GtkWidget *toolbar1; GtkIconSize tmp_toolbar_icon_size; GtkWidget *toolbutton1; GtkWidget *toolbutton2; GtkWidget *toolbutton3; GtkWidget *scrolledwindow1; GtkWidget *canvas1; GtkWidget *appbar1; GtkTooltips *tooltips; typedef struct { gboolean was_changed; gboolean is_new; gchar *full_file_name; } _Krot_Buffer_Env; typedef _Krot_Buffer_Env Krot_Buffer_Env; GtkWidget *textview; GtkSourceBuffer *buffer; char* mime_type; Krot_Buffer_Env file_env; void krot_buffer_env_init_new( Krot_Buffer_Env* env ) { env->was_changed = FALSE; env->is_new = TRUE; env->full_file_name = NULL; } void on_new1_activate ( GtkMenuItem *menuitem, gpointer user_data ) { } void on_open1_activate ( GtkMenuItem *menuitem, gpointer user_data ) { gsize file_size; GError *errors; GIOChannel* local_file; GtkWidget *dialog; gint result; gchar *open_filename; gchar *text; gchar *title; int file_pointer; errors = NULL; result = 0; dialog = gtk_file_chooser_dialog_new ( "Choose a File", GTK_WINDOW( app1 ), GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL ); gtk_file_chooser_set_current_folder ( GTK_FILE_CHOOSER( dialog ), g_get_home_dir() ); result = gtk_dialog_run ( GTK_DIALOG( dialog ) ); switch ( result ) { case ( GTK_RESPONSE_OK ) : open_filename = gtk_file_chooser_get_filename ( GTK_FILE_CHOOSER( dialog ) ); gtk_widget_destroy ( dialog ); if ( ! g_file_test ( open_filename, G_FILE_TEST_EXISTS ) ) { g_print( "Cannot open file. It does not exist!" ); } else { text = NULL; local_file = g_io_channel_new_file( open_filename, "r", &errors ); g_io_channel_read_to_end( local_file, &text, &file_size, &errors ); gtk_source_buffer_begin_not_undoable_action ( buffer ); gtk_text_buffer_set_text ( GTK_TEXT_BUFFER( buffer ), text, -1 ); gtk_source_buffer_end_not_undoable_action ( buffer ); g_free( text ); g_io_channel_shutdown( local_file, TRUE, &errors ); gtk_text_view_set_buffer ( GTK_TEXT_VIEW ( textview ), GTK_TEXT_BUFFER( buffer ) ); file_env.is_new = FALSE; file_env.was_changed = FALSE; if ( file_env.full_file_name ) g_free( file_env.full_file_name ); file_env.full_file_name = g_strdup( open_filename ); } break; default: gtk_widget_destroy ( dialog ); break; } } void on_save_as1_activate ( GtkMenuItem *menuitem, gpointer user_data ) { gsize file_size; GError *errors; GIOChannel* local_file; GtkWidget *dialog; gint result; gchar *open_filename; gchar *text; int file_pointer; GtkTextIter start, end; errors = NULL; dialog = gtk_file_chooser_dialog_new ( "Save file as", GTK_WINDOW( app1 ), GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL ); gtk_file_chooser_set_current_folder ( GTK_FILE_CHOOSER( dialog ), g_get_home_dir() ); gtk_file_chooser_set_current_name ( GTK_FILE_CHOOSER( dialog ), "untitled.txt" ); result = gtk_dialog_run ( GTK_DIALOG( dialog ) ); switch ( result ) { case ( GTK_RESPONSE_OK ) : open_filename = gtk_file_chooser_get_filename ( GTK_FILE_CHOOSER( dialog ) ); gtk_text_buffer_get_start_iter ( GTK_TEXT_BUFFER ( buffer ), &start ); gtk_text_buffer_get_end_iter ( GTK_TEXT_BUFFER ( buffer ), &end ); text = gtk_text_buffer_get_text ( GTK_TEXT_BUFFER ( buffer ), &start, &end, TRUE ); file_size = strlen( text ); local_file = g_io_channel_new_file( open_filename, "w", &errors ); g_io_channel_write_chars( local_file, text, -1, &file_size, &errors ); g_free( text ); g_io_channel_shutdown( local_file, TRUE, &errors ); file_env.is_new = FALSE; if ( file_env.full_file_name ) g_free( file_env.full_file_name ); file_env.full_file_name = g_strdup( open_filename ); break; default: break; } gtk_widget_destroy ( dialog ); } void on_save1_activate ( GtkMenuItem *menuitem, gpointer user_data ) { if ( file_env.is_new ) { on_save_as1_activate( menuitem, user_data ); } else { gsize file_size; GError *errors; GIOChannel* local_file; GtkWidget *dialog; gint result; gchar *open_filename; gchar *text; int file_pointer; GtkTextIter start, end; errors = NULL; gtk_text_buffer_get_start_iter ( GTK_TEXT_BUFFER ( buffer ), &start ); gtk_text_buffer_get_end_iter ( GTK_TEXT_BUFFER ( buffer ), &end ); text = gtk_text_buffer_get_text ( GTK_TEXT_BUFFER ( buffer ), &start, &end, TRUE ); local_file = g_io_channel_new_file( file_env.full_file_name, "w", &errors ); g_io_channel_write_chars( local_file, text, -1, &file_size, &errors ); g_free( text ); g_io_channel_shutdown( local_file, TRUE, &errors ); } } void on_quit1_activate ( GtkMenuItem *menuitem, gpointer user_data ) { } void on_cut1_activate ( GtkMenuItem *menuitem, gpointer user_data ) { } void on_copy1_activate ( GtkMenuItem *menuitem, gpointer user_data ) { } void on_paste1_activate ( GtkMenuItem *menuitem, gpointer user_data ) { } void on_clear1_activate ( GtkMenuItem *menuitem, gpointer user_data ) { } void on_properties1_activate ( GtkMenuItem *menuitem, gpointer user_data ) { } void on_preferences1_activate ( GtkMenuItem *menuitem, gpointer user_data ) { } void on_about1_activate ( GtkMenuItem *menuitem, gpointer user_data ) { } void on_toolbutton1_clicked ( GtkToolButton *toolbutton, gpointer user_data ) { } void on_toolbutton2_clicked ( GtkToolButton *toolbutton, gpointer user_data ) { on_open1_activate( NULL, user_data ); } void on_toolbutton3_clicked ( GtkToolButton *toolbutton, gpointer user_data ) { on_save1_activate( NULL, user_data ); } static GnomeUIInfo file1_menu_uiinfo[] = { GNOMEUIINFO_MENU_NEW_ITEM ( "_New", NULL, on_new1_activate, NULL ), GNOMEUIINFO_MENU_OPEN_ITEM ( on_open1_activate, NULL ), GNOMEUIINFO_MENU_SAVE_ITEM ( on_save1_activate, NULL ), GNOMEUIINFO_MENU_SAVE_AS_ITEM ( on_save_as1_activate, NULL ), GNOMEUIINFO_SEPARATOR, GNOMEUIINFO_MENU_EXIT_ITEM ( on_quit1_activate, NULL ), GNOMEUIINFO_END }; static GnomeUIInfo edit1_menu_uiinfo[] = { GNOMEUIINFO_MENU_CUT_ITEM ( on_cut1_activate, NULL ), GNOMEUIINFO_MENU_COPY_ITEM ( on_copy1_activate, NULL ), GNOMEUIINFO_MENU_PASTE_ITEM ( on_paste1_activate, NULL ),
评论
    相关推荐