* l3afpad-0.8.18.1.3

This commit is contained in:
Wen-Yen Chuang
2011-12-12 21:35:35 +08:00
parent c3c63280d4
commit c9b1ad4888
98 changed files with 1300 additions and 643 deletions

View File

@@ -39,7 +39,7 @@ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2005 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -25,7 +25,7 @@
static void set_selection_bound(GtkTextBuffer *buffer, gint start, gint end)
{
GtkTextIter start_iter, end_iter;
gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start);
if (end < 0)
gtk_text_buffer_get_end_iter(buffer, &end_iter);
@@ -56,7 +56,7 @@ void on_file_open(void)
FileInfo *fi;
gchar *comline;
gchar *option = NULL;
fi = get_fileinfo_from_selector(pub->fi, OPEN);
if (fi) {
save_config_file();
@@ -73,7 +73,7 @@ void on_file_open(void)
#else
{
FileInfo *fi;
if (check_text_modification())
return;
fi = get_fileinfo_from_selector(pub->fi, OPEN);
@@ -109,7 +109,7 @@ gint on_file_save(void)
gint on_file_save_as(void)
{
FileInfo *fi;
fi = get_fileinfo_from_selector(pub->fi, SAVE);
if (fi == NULL)
return -1;
@@ -125,7 +125,7 @@ gint on_file_save_as(void)
// undo_init(sd->mainwin->textview, sd->mainwin->textbuffer, sd->mainwin->menubar);
return 0;
}
#ifdef ENABLE_PRINT
#if ENABLE_PRINT
void on_file_print_preview(void)
{
create_gtkprint_preview_session(GTK_TEXT_VIEW(pub->mw->view),
@@ -214,7 +214,7 @@ static void activate_quick_find(void)
{
GtkItemFactory *ifactory;
static gboolean flag = FALSE;
if (!flag) {
ifactory = gtk_item_factory_from_widget(pub->mw->menubar);
gtk_widget_set_sensitive(
@@ -263,7 +263,7 @@ void on_option_word_wrap(void)
{
GtkItemFactory *ifactory;
gboolean state;
ifactory = gtk_item_factory_from_widget(pub->mw->menubar);
state = gtk_check_menu_item_get_active(
GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item(ifactory, "/M/Options/WordWrap")));
@@ -275,7 +275,7 @@ void on_option_line_numbers(void)
{
GtkItemFactory *ifactory;
gboolean state;
ifactory = gtk_item_factory_from_widget(pub->mw->menubar);
state = gtk_check_menu_item_get_active(
GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item(ifactory, "/M/Options/LineNumbers")));
@@ -285,7 +285,7 @@ void on_option_line_numbers(void)
void on_option_always_on_top(void)
{
static gboolean flag = FALSE;
flag =! flag;
gtk_window_set_keep_above(GTK_WINDOW(pub->mw->window), flag);
}
@@ -294,7 +294,7 @@ void on_option_auto_indent(void)
{
GtkItemFactory *ifactory;
gboolean state;
ifactory = gtk_item_factory_from_widget(pub->mw->menubar);
state = gtk_check_menu_item_get_active(
GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item(ifactory, "/M/Options/AutoIndent")));
@@ -311,16 +311,16 @@ void on_help_about(void)
NULL
};
const gchar *translator_credits = _("translator-credits");
translator_credits = strcmp(translator_credits, "translator-credits")
? translator_credits : NULL;
const gchar *artists[] = {
"Lapo Calamandrei <calamandrei@gmail.com>",
NULL
};
gtk_show_about_dialog(GTK_WINDOW(pub->mw->window),
"program-name", "Lɜafpad",
"program-name", _("Lɜafpad"),
"version", PACKAGE_VERSION,
"copyright", copyright,
"comments", comments,

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2005 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2005 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -27,11 +27,11 @@ void run_dialog_message(GtkWidget *window,
va_list ap;
GtkWidget *dialog;
gchar *str;
va_start(ap, message);
str = g_strdup_vprintf(message, ap);
va_end(ap);
dialog = gtk_message_dialog_new(GTK_WINDOW(window),
GTK_DIALOG_DESTROY_WITH_PARENT,
type,
@@ -42,7 +42,7 @@ void run_dialog_message(GtkWidget *window,
GTK_STOCK_OK, GTK_RESPONSE_CANCEL, NULL);
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_CANCEL);
g_free(str);
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
}
@@ -52,11 +52,11 @@ GtkWidget *create_dialog_message_question(GtkWidget *window, gchar *message, ...
va_list ap;
GtkWidget *dialog;
gchar *str;
va_start(ap, message);
str = g_strdup_vprintf(message, ap);
va_end(ap);
dialog = gtk_message_dialog_new(GTK_WINDOW(window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_QUESTION,
@@ -70,7 +70,7 @@ GtkWidget *create_dialog_message_question(GtkWidget *window, gchar *message, ...
NULL);
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_YES);
g_free(str);
return dialog;
}
@@ -80,16 +80,16 @@ gint run_dialog_message_question(GtkWidget *window, gchar *message, ...)
GtkWidget *dialog;
gchar *str;
gint res;
va_start(ap, message);
str = g_strdup_vprintf(message, ap);
va_end(ap);
dialog = create_dialog_message_question(window, str);
g_free(str);
res = gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
return res;
}

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2005 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2006 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -65,7 +65,7 @@ void dnd_init(GtkWidget *widget)
static void dnd_open_first_file(gchar *filename)
{
FileInfo *fi;
if (check_text_modification())
return;
fi = g_malloc(sizeof(FileInfo));
@@ -82,7 +82,7 @@ static void dnd_open_first_file(gchar *filename)
set_main_window_title();
// undo_init(sd->mainwin->textview, sd->mainwin->textbuffer, sd->mainwin->menubar);
}
}
}
#endif
#if 0
@@ -101,9 +101,9 @@ static void dnd_drag_data_recieved_handler(GtkWidget *widget,
j = 1;
#endif
DV(g_print("DND start!\n"));
#if 0
if (g_strcasecmp(gdk_atom_name(context->targets->data),
if (g_ascii_strcasecmp(gdk_atom_name(context->targets->data),
"GTK_TEXT_BUFFER_CONTENTS") != 0) {
#endif
if (flag_called_once) {
@@ -114,8 +114,8 @@ DV(g_print("second drop signal killed.\n"));
} else
flag_called_once = TRUE;
}
DV({
DV({
g_print("info = %d\n", info);
g_print("time = %d\n", time);
g_print("context->protocol = %d\n", context->protocol);
@@ -133,8 +133,8 @@ DV({
g_print("selection_data->format = %d\n", selection_data->format);
g_print("selection_data->length = %d\n", selection_data->length);
g_print("%s\n", selection_data->data);
});
});
if (selection_data->data && info == TARGET_URI_LIST) {
files = g_strsplit((gchar *)selection_data->data, "\n" , -1);
while (files[i]) {
@@ -169,13 +169,13 @@ DV(g_print(">%s\n", comline));
if (info == TARGET_UTF8_STRING) {
undo_set_sequency_reserve();
context->action = GDK_ACTION_MOVE;
} else if (info == TARGET_PLAIN
} else if (info == TARGET_PLAIN
&& g_utf8_validate((gchar *)selection_data->data, -1, NULL)) {
selection_data->type =
gdk_atom_intern("UTF8_STRING", FALSE);
}
}
return;
}
@@ -185,7 +185,7 @@ static gboolean dnd_drag_motion_handler(GtkWidget *widget,
GList *targets;
gchar *name;
gboolean flag = FALSE;
targets = context->targets;
while (targets) {
name = gdk_atom_name(targets->data);
@@ -200,11 +200,11 @@ DV(g_print("%s\n", name));
else
context->action = GDK_ACTION_COPY;
// g_signal_stop_emission_by_name(widget, "drag_motion");
*/
*/
/* if (!flag) {
gint bx, by;
GtkTextIter iter;
gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(widget),
GTK_TEXT_WINDOW_WIDGET,
x, y, &bx, &by);
@@ -219,7 +219,7 @@ DV(g_print("%s\n", name));
dnd_mark, &iter);
gtk_text_mark_set_visible(dnd_mark, TRUE);
}
*/
*/
return flag;
}
#endif

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2005 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2006 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -20,7 +20,7 @@
#include "l3afpad.h"
#include <gdk/gdkkeysyms.h>
#ifdef ENABLE_EMACS
#if ENABLE_EMACS
static void cb_key_release_event(GtkWidget *view, GdkEventKey *event)
{
@@ -105,7 +105,7 @@ static void cb_key_press_event(GtkWidget *view, GdkEventKey *event)
static void emacs_key_prefix(void)
{
gulong id;
gtk_widget_set_sensitive(pub->mw->menubar, FALSE);
// gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(pub->mw->view), FALSE);
gtk_text_view_set_editable(GTK_TEXT_VIEW(pub->mw->view), FALSE);
@@ -114,13 +114,13 @@ static void emacs_key_prefix(void)
G_CALLBACK(cb_key_release_event), NULL);
gtk_main();
g_signal_handler_disconnect(G_OBJECT(pub->mw->window), id);
/* waiting for input sequence */
id = g_signal_connect(G_OBJECT(pub->mw->window), "key-press-event",
G_CALLBACK(cb_key_press_event), NULL);
gtk_main();
g_signal_handler_disconnect(G_OBJECT(pub->mw->window), id);
gtk_text_view_set_editable(GTK_TEXT_VIEW(pub->mw->view), TRUE);
// gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(pub->mw->view), TRUE);
gtk_widget_set_sensitive(pub->mw->menubar, TRUE);
@@ -133,7 +133,7 @@ gboolean check_emacs_key_theme(GtkWindow *window, GtkItemFactory *ifactory)
gchar *key_theme = NULL;
gboolean emacs_flag = FALSE;
GtkSettings *settings = gtk_settings_get_default();
g_object_get(settings, "gtk-key-theme-name", &key_theme, NULL);
if (key_theme) {
if (!g_ascii_strcasecmp(key_theme, "Emacs"))
@@ -142,7 +142,7 @@ gboolean check_emacs_key_theme(GtkWindow *window, GtkItemFactory *ifactory)
}
if (!emacs_flag)
return FALSE;
groups = gtk_accel_groups_from_object(G_OBJECT(window));
accel_group = groups->data;
if (accel_group) {
@@ -150,14 +150,14 @@ gboolean check_emacs_key_theme(GtkWindow *window, GtkItemFactory *ifactory)
g_object_unref(accel_group);
}
accel_group = gtk_accel_group_new();
gtk_rc_parse_string (
"binding \"gtk-emacs-text-entry\""
"{\n"
"bind \"<ctrl>w\" { \"cut-clipboard\" () }"
"}\n"
);
/* gtk_widget_remove_accelerator(
gtk_item_factory_get_widget(ifactory, "/M/File/New"),
accel_group, GDK_N, GDK_CONTROL_MASK);
@@ -170,7 +170,7 @@ gboolean check_emacs_key_theme(GtkWindow *window, GtkItemFactory *ifactory)
gtk_widget_remove_accelerator(
gtk_item_factory_get_widget(ifactory, "/M/File/SaveAs"),
accel_group, GDK_S, GDK_SHIFT_MASK | GDK_CONTROL_MASK);
#ifdef ENABLE_PRINT
#if ENABLE_PRINT
gtk_widget_remove_accelerator(
gtk_item_factory_get_widget(ifactory, "/M/File/Print"),
accel_group, GDK_P, GDK_CONTROL_MASK);
@@ -208,13 +208,13 @@ gboolean check_emacs_key_theme(GtkWindow *window, GtkItemFactory *ifactory)
*/ gtk_widget_add_accelerator(
gtk_item_factory_get_widget(ifactory, "/M/Search/JumpTo"),
"activate", accel_group, GDK_G, GDK_MOD1_MASK, GTK_ACCEL_VISIBLE);
gtk_accel_group_connect(
accel_group, GDK_X, GDK_CONTROL_MASK, 0,
g_cclosure_new_swap(G_CALLBACK(emacs_key_prefix), NULL, NULL));
gtk_window_add_accel_group(GTK_WINDOW(window), accel_group);
return TRUE;
}

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2006 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2005 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -98,7 +98,7 @@ guint get_encoding_code(void)
static guint code = END_CODE;
const gchar *env;
guint i, j = 1;
if (code == END_CODE) {
env = g_getenv("LC_ALL");
if (!env)
@@ -118,7 +118,7 @@ guint get_encoding_code(void)
if (code == END_CODE)
code = 0;
}
return code;
}
@@ -126,23 +126,23 @@ EncArray *get_encoding_items(guint code)
{
gint i;
static EncArray *array = NULL;
if (!array) {
array = g_malloc(sizeof(EncArray));
for (i = 0; i < ENCODING_MAX_ITEM_NUM; i++)
array->item[i] = encoding_table[code][i] ?
encoding_table[code][i] : NULL;
}
return array;
}
const gchar *get_default_charset(void)
{
const gchar *charset;
g_get_charset(&charset);
return charset;
}
@@ -154,7 +154,7 @@ http://examples.oreilly.com/cjkvinfo/Ch7/DetectCodeType.c
void convert_line_ending_to_lf(gchar *text)
{
gint i, j;
for (i = 0, j = 0; TRUE; i++, j++) {
if (*(text + i) == CR) {
*(text + j) = LF;
@@ -173,7 +173,7 @@ void convert_line_ending(gchar **text, gint retcode)
gchar *buf, *str = *text;
const gint len = strlen(str);
gint i, j, LFNum = 0;
switch (retcode) {
case CR:
while (*str != '\0') {
@@ -222,9 +222,9 @@ static const gchar *detect_charset_cylillic(const gchar *text)
guint8 c = *text;
gboolean noniso = FALSE;
guint32 xc = 0, xd = 0, xef = 0;
const gchar *charset = get_encoding_items(get_encoding_code())->item[OPENI18N];
while ((c = *text++) != '\0') {
if (c >= 0x80 && c <= 0x9F)
noniso = TRUE;
@@ -235,21 +235,21 @@ static const gchar *detect_charset_cylillic(const gchar *text)
else if (c >= 0xE0)
xef++;
}
if (!noniso && ((xc + xef) < xd))
charset = "ISO-8859-5";
else if ((xc + xd) < xef)
charset = "CP1251";
return charset;
}
static const gchar *detect_charset_chinese(const gchar *text)
{
guint8 c = *text;
const gchar *charset = get_encoding_items(get_encoding_code())->item[IANA];
while ((c = *text++) != '\0') {
if (c >= 0x81 && c <= 0x87) {
charset = "GB18030";
@@ -279,7 +279,7 @@ static const gchar *detect_charset_chinese(const gchar *text)
}
}
}
return charset;
}
@@ -287,7 +287,7 @@ static const gchar *detect_charset_japanese(const gchar *text)
{
guint8 c = *text;
gchar *charset = NULL;
while (charset == NULL && (c = *text++) != '\0') {
if (c >= 0x81 && c <= 0x9F) {
if (c == 0x8E) /* SS2 */ {
@@ -322,10 +322,10 @@ static const gchar *detect_charset_japanese(const gchar *text)
else if (c >= 0xF0)
break;
}
if (charset == NULL)
charset = "EUC-JP";
return charset;
}
@@ -335,7 +335,7 @@ static const gchar *detect_charset_korean(const gchar *text)
gboolean noneuc = FALSE;
gboolean nonjohab = FALSE;
gchar *charset = NULL;
while (charset == NULL && (c = *text++) != '\0') {
if (c >= 0x81 && c < 0x84) {
charset = "CP949";
@@ -380,21 +380,21 @@ static const gchar *detect_charset_korean(const gchar *text)
if (noneuc && nonjohab)
charset = "CP949";
}
if (charset == NULL) {
if (noneuc)
charset = "CP949";
else
charset = "EUC-KR";
}
return charset;
}
static gboolean detect_noniso(const gchar *text)
{
guint8 c = *text;
while ((c = *text++) != '\0') {
if (c >= 0x80 && c <= 0x9F)
return TRUE;
@@ -406,7 +406,7 @@ const gchar *detect_charset(const gchar *text)
{
guint8 c = *text;
const gchar *charset = NULL;
if (g_utf8_validate(text, -1, NULL)) {
while ((c = *text++) != '\0') {
if (c > 0x7F) {
@@ -445,7 +445,7 @@ const gchar *detect_charset(const gchar *text)
if (!charset)
charset = get_default_charset();
}
if (!charset) {
switch (get_encoding_code()) {
case LATINC:
@@ -477,9 +477,9 @@ const gchar *detect_charset(const gchar *text)
else
charset = get_encoding_items(get_encoding_code())->item[OPENI18N];
if (!charset)
charset = get_encoding_items(get_encoding_code())->item[IANA];
charset = get_encoding_items(get_encoding_code())->item[IANA];
}
}
return charset;
}

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2005 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2005 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -31,7 +31,7 @@
gboolean check_file_writable(gchar *filename)
{
FILE *fp;
if ((fp = fopen(filename, "a")) != NULL) {
fclose(fp);
return TRUE;
@@ -44,7 +44,7 @@ gchar *get_file_basename(gchar *filename, gboolean bracket)
gchar *basename = NULL;
gchar *tmp;
gboolean exist_flag;
if (filename) {
tmp = g_path_get_basename(
g_filename_to_utf8(filename, -1, NULL, NULL, NULL));
@@ -55,7 +55,7 @@ gchar *get_file_basename(gchar *filename, gboolean bracket)
tmp = g_strdup(_("Untitled"));
exist_flag = FALSE;
}
if (bracket) {
if (!exist_flag) {
GString *string = g_string_new(tmp);
@@ -71,11 +71,11 @@ gchar *get_file_basename(gchar *filename, gboolean bracket)
g_string_free(string, TRUE);
}
}
if (!basename)
basename = g_strdup(tmp);
g_free(tmp);
return basename;
}
@@ -83,7 +83,7 @@ gchar *parse_file_uri(gchar *uri)
{
gchar *filename;
// gchar **strs;
if (g_strstr_len(uri, 5, "file:"))
filename = g_filename_from_uri(uri, NULL, NULL);
else {
@@ -98,7 +98,7 @@ gchar *parse_file_uri(gchar *uri)
filename = g_strjoinv("\\ ", strs);
g_strfreev(strs);
}
*/
*/
return filename;
}
@@ -110,9 +110,9 @@ gint file_open_real(GtkWidget *view, FileInfo *fi)
const gchar *charset;
gchar *str = NULL;
GtkTextIter iter;
GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view));
if (!g_file_get_contents(fi->filename, &contents, &length, &err)) {
if (g_file_test(fi->filename, G_FILE_TEST_EXISTS)) {
run_dialog_message(gtk_widget_get_toplevel(view),
@@ -124,11 +124,11 @@ gint file_open_real(GtkWidget *view, FileInfo *fi)
err = NULL;
contents = g_strdup("");
}
fi->lineend = detect_line_ending(contents);
if (fi->lineend != LF)
convert_line_ending_to_lf(contents);
if (fi->charset)
charset = fi->charset;
else {
@@ -149,18 +149,18 @@ gint file_open_real(GtkWidget *view, FileInfo *fi)
else
str = g_strdup("");
g_free(contents);
if (charset != fi->charset) {
g_free(fi->charset);
fi->charset = g_strdup(charset);
if (fi->charset_flag)
fi->charset_flag = FALSE;
}
// undo_disconnect_signal(textbuffer);
// undo_block_signal(buffer);
force_block_cb_modified_changed(view);
gtk_text_buffer_set_text(buffer, "", 0);
gtk_text_buffer_get_start_iter(buffer, &iter);
gtk_text_buffer_insert(buffer, &iter, str, strlen(str));
@@ -169,11 +169,11 @@ gint file_open_real(GtkWidget *view, FileInfo *fi)
gtk_text_buffer_set_modified(buffer, FALSE);
gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(view), &iter, 0, FALSE, 0, 0);
g_free(str);
force_unblock_cb_modified_changed(view);
menu_sensitivity_from_modified_flag(FALSE);
// undo_unblock_signal(buffer);
return 0;
}
@@ -184,13 +184,13 @@ gint file_save_real(GtkWidget *view, FileInfo *fi)
gchar *str, *cstr;
gsize rbytes, wbytes;
GError *err = NULL;
GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view));
gtk_text_buffer_get_start_iter(buffer, &start);
gtk_text_buffer_get_end_iter(buffer, &end);
gtk_text_buffer_get_end_iter(buffer, &end);
str = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
switch (fi->lineend) {
case CR:
convert_line_ending(&str, CR);
@@ -198,7 +198,7 @@ gint file_save_real(GtkWidget *view, FileInfo *fi)
case CR+LF:
convert_line_ending(&str, CR+LF);
}
if (!fi->charset)
fi->charset = g_strdup(get_default_charset());
cstr = g_convert(str, -1, fi->charset, "UTF-8", &rbytes, &wbytes, &err);
@@ -216,7 +216,7 @@ gint file_save_real(GtkWidget *view, FileInfo *fi)
g_error_free(err);
return -1;
}
fp = fopen(fi->filename, "w");
if (!fp) {
run_dialog_message(gtk_widget_get_toplevel(view),
@@ -228,10 +228,10 @@ gint file_save_real(GtkWidget *view, FileInfo *fi)
GTK_MESSAGE_ERROR, _("Can't write file"));
return -1;
}
gtk_text_buffer_set_modified(buffer, FALSE);
fclose(fp);
g_free(cstr);
return 0;
}

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2005 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2005 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -22,7 +22,7 @@
void set_text_font_by_name(GtkWidget *widget, gchar *fontname)
{
PangoFontDescription *font_desc;
font_desc = pango_font_description_from_string(fontname);
gtk_widget_modify_font(widget, font_desc);
pango_font_description_free(font_desc);
@@ -31,7 +31,7 @@ void set_text_font_by_name(GtkWidget *widget, gchar *fontname)
gchar *get_font_name_from_widget(GtkWidget *widget) /* MUST BE FREED */
{
GtkStyle *style;
style = gtk_widget_get_style(widget);
return pango_font_description_to_string(style->font_desc);
}
@@ -40,7 +40,7 @@ static gchar *get_font_name_by_selector(GtkWidget *window, gchar *current_fontna
{
GtkWidget *dialog;
gchar *fontname;
dialog = gtk_font_selection_dialog_new(_("Font"));
gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(window));
gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(dialog), current_fontname);
@@ -49,14 +49,14 @@ static gchar *get_font_name_by_selector(GtkWidget *window, gchar *current_fontna
else
fontname = NULL;
gtk_widget_destroy(dialog);
return fontname;
}
void change_text_font_by_selector(GtkWidget *widget)
{
gchar *current_fontname, *fontname;
current_fontname = get_font_name_from_widget(widget);
fontname = get_font_name_by_selector(
gtk_widget_get_toplevel(widget), current_fontname);
@@ -64,7 +64,7 @@ void change_text_font_by_selector(GtkWidget *widget)
set_text_font_by_name(widget, fontname);
indent_refresh_tab_width(widget);
}
g_free(fontname);
g_free(current_fontname);
}

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2005 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2007 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -31,7 +31,7 @@ static void get_tab_array(PangoTabArray **tabs,
{
gint xft_dpi, loc;
GtkSettings *settings = gtk_settings_get_default();
g_object_get(settings, "gtk-xft-dpi", &xft_dpi, NULL);
if ((*tabs = gtk_text_view_get_tabs(text_view))) {
pango_tab_array_get_tab(*tabs, 0, NULL, &loc);
@@ -48,10 +48,10 @@ static void cb_begin_print(GtkPrintOperation *op,
GtkTextIter start, end;
GtkTextBuffer *buffer = gtk_text_view_get_buffer(data);
PangoTabArray *tabs;
gtk_text_buffer_get_bounds(buffer, &start, &end);
text = g_strchomp(gtk_text_buffer_get_text(buffer, &start, &end, FALSE));
page_width = gtk_print_context_get_width(ctx);
page_height = gtk_print_context_get_height(ctx);
font_desc = gtk_style_context_get_font(gtk_widget_get_style_context(data), GTK_STATE_FLAG_NORMAL);
@@ -59,21 +59,21 @@ static void cb_begin_print(GtkPrintOperation *op,
pango_layout_set_width(layout, page_width * PANGO_SCALE);
pango_layout_set_font_description(layout, font_desc);
pango_layout_set_text(layout, text, -1);
get_tab_array(&tabs, ctx, data);
if (tabs) {
pango_layout_set_tabs(layout, tabs);
pango_tab_array_free(tabs);
}
pango_layout_get_size(layout, NULL, &layout_height);
line_count = pango_layout_get_line_count(layout);
text_height = pango_font_description_get_size(font_desc) / PANGO_SCALE;
lines_per_page = page_height / text_height;
n_pages = (line_count - 1) / lines_per_page + 1;
gtk_print_operation_set_n_pages(op, n_pages);
g_free(text);
}
@@ -83,19 +83,19 @@ static void cb_draw_page(GtkPrintOperation *op,
cairo_t *cr;
PangoLayoutLine *line;
gint n_line, i, j = 0;
PangoLayout *layout_lh, *layout_rh;
gchar *page_text;
gint layout_width;
cr = gtk_print_context_get_cairo_context(ctx);
layout_lh = gtk_print_context_create_pango_layout(ctx);
pango_layout_set_font_description(layout_lh, font_desc);
pango_layout_set_text(layout_lh, page_title, -1);
cairo_move_to(cr, 0, - 72 / 25.4 * 10);
pango_cairo_show_layout(cr, layout_lh);
page_text = g_strdup_printf("%d / %d", page_nr + 1, n_pages);
layout_rh = gtk_print_context_create_pango_layout(ctx);
pango_layout_set_font_description(layout_rh, font_desc);
@@ -106,18 +106,18 @@ static void cb_draw_page(GtkPrintOperation *op,
page_width - layout_width / PANGO_SCALE, - 72 / 25.4 * 10);
pango_cairo_show_layout(cr, layout_rh);
g_free(page_text);
if (line_count > lines_per_page * (page_nr + 1))
n_line = lines_per_page * (page_nr + 1);
else
n_line = line_count;
for (i = lines_per_page * page_nr; i < n_line; i++) {
line = pango_layout_get_line(layout, i);
cairo_move_to(cr, 0, text_height * (j + 1));
pango_cairo_show_layout_line(cr, line);
j++;
}
}
}
static void cb_end_print(GtkPrintOperation *op,
@@ -132,12 +132,12 @@ static GtkPrintOperation *create_print_operation(GtkTextView *text_view)
{
GtkPrintOperation *op;
static GtkPageSetup *page_setup = NULL;
op = gtk_print_operation_new();
if (settings)
gtk_print_operation_set_print_settings(op, settings);
if (!page_setup) {
page_setup = gtk_page_setup_new();
gtk_page_setup_set_top_margin(page_setup, 25.0, GTK_UNIT_MM);
@@ -146,18 +146,18 @@ static GtkPrintOperation *create_print_operation(GtkTextView *text_view)
gtk_page_setup_set_right_margin(page_setup, 20.0, GTK_UNIT_MM);
}
gtk_print_operation_set_default_page_setup(op, page_setup);
g_signal_connect(op, "begin-print", G_CALLBACK(cb_begin_print), text_view);
g_signal_connect(op, "draw-page", G_CALLBACK(cb_draw_page), NULL);
g_signal_connect(op, "end-print", G_CALLBACK(cb_end_print), NULL);
return op;
}
static void create_error_dialog(GtkTextView *text_view, gchar *message)
{
GtkWidget *dialog;
dialog = gtk_message_dialog_new(
GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(text_view))),
GTK_DIALOG_DESTROY_WITH_PARENT,
@@ -177,10 +177,10 @@ void create_gtkprint_session(GtkTextView *text_view, const gchar *title)
GtkPrintOperation *op;
GtkPrintOperationResult res;
GError *err = NULL;
page_title = title;
op = create_print_operation(text_view);
res = gtk_print_operation_run(op, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(text_view))), &err);
switch (res) {
@@ -194,7 +194,7 @@ void create_gtkprint_session(GtkTextView *text_view, const gchar *title)
default:
break;
}
g_object_unref(op);
}
@@ -203,16 +203,16 @@ void create_gtkprint_preview_session(GtkTextView *text_view, const gchar *title)
GtkPrintOperation *op;
GtkPrintOperationResult res;
GError *err = NULL;
page_title = title;
op = create_print_operation(text_view);
res = gtk_print_operation_run(op, GTK_PRINT_OPERATION_ACTION_PREVIEW,
GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(text_view))), &err);
if (res == GTK_PRINT_OPERATION_RESULT_ERROR) {
create_error_dialog(text_view, err->message);
g_error_free(err);
}
g_object_unref(op);
}

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2007 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or

View File

@@ -1,7 +1,7 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
* gtksourceiter.h
*
* Copyright (C) 2000, 2002 Paolo Maggi
* Copyright (C) 2000, 2002 Paolo Maggi
* Copyright (C) 2002, 2003 Jeroen Zwartepoorte
*
* This library is free software; you can redistribute it and/or
@@ -198,7 +198,7 @@ g_utf8_caselessnmatch (const char *s1, const char *s2,
finally_2:
g_free (normalized_s1);
g_free (normalized_s2);
g_free (normalized_s2);
return ret;
}
@@ -231,7 +231,7 @@ forward_chars_with_skipping (GtkTextIter *iter,
{
/* being UTF8 correct sucks; this accounts for extra
offsets coming from canonical decompositions of
UTF8 characters (e.g. accented characters) which
UTF8 characters (e.g. accented characters) which
g_utf8_normalize() performs */
gunichar *decomp;
gsize decomp_len;
@@ -512,14 +512,14 @@ strbreakup (const char *string,
* @match_start: return location for start of match, or %NULL
* @match_end: return location for end of match, or %NULL
* @limit: bound for the search, or %NULL for the end of the buffer
*
* Searches forward for @str. Any match is returned by setting
* @match_start to the first character of the match and @match_end to the
*
* Searches forward for @str. Any match is returned by setting
* @match_start to the first character of the match and @match_end to the
* first character after the match. The search will not continue past
* @limit. Note that a search is a linear or O(n) operation, so you
* may wish to use @limit to avoid locking up your UI on large
* buffers.
*
*
* If the #GTK_SOURCE_SEARCH_VISIBLE_ONLY flag is present, the match may
* have invisible text interspersed in @str. i.e. @str will be a
* possibly-noncontiguous subsequence of the matched range. similarly,
@@ -532,7 +532,7 @@ strbreakup (const char *string,
*
* Same as gtk_text_iter_forward_search(), but supports case insensitive
* searching.
*
*
* Return value: whether a match was found
**/
gboolean
@@ -556,7 +556,7 @@ gtk_source_iter_forward_search (const GtkTextIter *iter,
if ((flags & GTK_SOURCE_SEARCH_CASE_INSENSITIVE) == 0)
return gtk_text_iter_forward_search (iter, str, flags,
match_start, match_end,
limit);
limit);
if (limit && gtk_text_iter_compare (iter, limit) >= 0)
return FALSE;
@@ -632,10 +632,10 @@ gtk_source_iter_forward_search (const GtkTextIter *iter,
* @match_start: return location for start of match, or %NULL
* @match_end: return location for end of match, or %NULL
* @limit: location of last possible @match_start, or %NULL for start of buffer
*
*
* Same as gtk_text_iter_backward_search(), but supports case insensitive
* searching.
*
*
* Return value: whether a match was found
**/
gboolean
@@ -659,7 +659,7 @@ gtk_source_iter_backward_search (const GtkTextIter *iter,
if ((flags & GTK_SOURCE_SEARCH_CASE_INSENSITIVE) == 0)
return gtk_text_iter_backward_search (iter, str, flags,
match_start, match_end,
limit);
limit);
if (limit && gtk_text_iter_compare (iter, limit) <= 0)
return FALSE;

View File

@@ -1,7 +1,7 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
* gtksourceiter.h
*
* Copyright (C) 2000, 2002 Paolo Maggi
* Copyright (C) 2000, 2002 Paolo Maggi
* Copyright (C) 2002, 2003 Jeroen Zwartepoorte
*
* This library is free software; you can redistribute it and/or

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2005 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -26,7 +26,7 @@ static gboolean searched_flag = FALSE;
static void cb_changed(GtkTextBuffer *buffer)
{
GtkTextIter start, end;
gtk_text_buffer_get_bounds(buffer, &start, &end);
// gtk_text_buffer_remove_tag_by_name(buffer,
// "searched", &start, &end);
@@ -39,7 +39,7 @@ static void cb_changed(GtkTextBuffer *buffer)
static void cb_paste_clipboard(void)
{
gchar *text;
text = gtk_clipboard_wait_for_text(
gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
if (text) {
@@ -82,7 +82,7 @@ void hlight_init(GtkTextBuffer *buffer)
G_CALLBACK(cb_changed), NULL);
g_signal_handlers_block_by_func(G_OBJECT(buffer),
G_CALLBACK(cb_changed), NULL);
g_signal_connect(G_OBJECT(pub->mw->view), "paste-clipboard",
G_CALLBACK(cb_paste_clipboard), NULL);
}

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2005 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2005 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -45,7 +45,7 @@ static gchar *compute_indentation(GtkTextBuffer *buffer, GtkTextIter *iter, gint
{
GtkTextIter start_iter, end_iter;
gunichar ch;
gtk_text_buffer_get_iter_at_line(buffer, &start_iter, line);
end_iter = start_iter;
ch = gtk_text_iter_get_char(&end_iter);
@@ -56,7 +56,7 @@ static gchar *compute_indentation(GtkTextBuffer *buffer, GtkTextIter *iter, gint
}
if (gtk_text_iter_equal(&start_iter, &end_iter))
return NULL;
if (iter && gtk_text_iter_compare(iter, &end_iter) < 0)
return gtk_text_iter_get_text(&start_iter, iter);
return gtk_text_iter_get_text(&start_iter, &end_iter);
@@ -66,9 +66,9 @@ void indent_real(GtkWidget *text_view)
{
GtkTextIter iter;
gchar *ind, *str;
GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_view));
g_signal_emit_by_name(G_OBJECT(buffer), "begin-user-action");
gtk_text_buffer_delete_selection(buffer, TRUE, TRUE);
gtk_text_buffer_get_iter_at_mark(buffer, &iter, gtk_text_buffer_get_insert(buffer));
@@ -78,7 +78,7 @@ void indent_real(GtkWidget *text_view)
g_signal_emit_by_name(G_OBJECT(buffer), "end-user-action");
g_free(str);
g_free(ind);
gtk_text_view_scroll_mark_onscreen(
GTK_TEXT_VIEW(text_view),
gtk_text_buffer_get_insert(buffer));
@@ -96,7 +96,7 @@ static gint calculate_real_tab_width(GtkWidget *text_view, guint tab_size) //fro
tab_string = g_strnfill(tab_size, 0x20);
layout = gtk_widget_create_pango_layout(text_view, tab_string);
g_free (tab_string);
if (layout != NULL) {
pango_layout_get_pixel_size(layout, &tab_width, NULL);
g_object_unref(G_OBJECT(layout));
@@ -109,7 +109,7 @@ static gint calculate_real_tab_width(GtkWidget *text_view, guint tab_size) //fro
void indent_refresh_tab_width(GtkWidget *text_view)
{
PangoTabArray *tab_array;
tab_array = pango_tab_array_new(1, TRUE);
pango_tab_array_set_tab(tab_array, 0, PANGO_TAB_LEFT,
calculate_real_tab_width(text_view, current_tab_width));
@@ -140,7 +140,7 @@ void indent_multi_line_indent(GtkTextBuffer *buffer)
GtkTextIter start_iter, end_iter, iter;
gint start_line, end_line, i;
gboolean pos;
gtk_text_buffer_get_selection_bounds(buffer, &start_iter, &end_iter);
start_line = gtk_text_iter_get_line(&start_iter);
end_line = gtk_text_iter_get_line(&end_iter);
@@ -155,7 +155,7 @@ void indent_multi_line_indent(GtkTextBuffer *buffer)
undo_set_sequency(TRUE);
}
undo_set_sequency(FALSE);
gtk_text_buffer_get_iter_at_line(buffer, &start_iter, start_line);
gtk_text_buffer_get_iter_at_line(buffer, &end_iter, end_line);
if (pos) {
@@ -171,11 +171,11 @@ static gint compute_indent_offset_length(const gchar *ind)
{
guint8 c = *ind;
gint len = 1;
if (c == 0x20)
while ((len < current_tab_width) && (c = *++ind) == 0x20)
len++;
return len;
}
@@ -185,7 +185,7 @@ void indent_multi_line_unindent(GtkTextBuffer *buffer)
gint start_line, end_line, i, len;
gboolean pos;
gchar *ind;
gtk_text_buffer_get_selection_bounds(buffer, &start_iter, &end_iter);
start_line = gtk_text_iter_get_line(&start_iter);
end_line = gtk_text_iter_get_line(&end_iter);
@@ -210,7 +210,7 @@ void indent_multi_line_unindent(GtkTextBuffer *buffer)
i++;
} while (i < end_line);
undo_set_sequency(FALSE);
gtk_text_buffer_get_iter_at_line(buffer, &start_iter, start_line);
gtk_text_buffer_get_iter_at_line(buffer, &end_iter, end_line);
if (pos) {

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2005 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2005 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -27,6 +27,10 @@
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#ifndef ENABLE_PRINT
#define ENABLE_PRINT 1
#endif
#include "window.h"
#include "menu.h"
#include "callback.h"
@@ -44,9 +48,10 @@
#include "dnd.h"
#include "utils.h"
#include "emacs.h"
#ifdef ENABLE_PRINT
#if ENABLE_PRINT
#include "gtkprint.h"
#endif
#include <gdk/gdkkeysyms-compat.h>
#undef GTK_CHECK_MENU_ITEM
#define GTK_CHECK_MENU_ITEM
@@ -55,8 +60,6 @@
#define gtk_item_factory_from_widget (GtkUIManager*)
#define gtk_item_factory_get_item(x,y) GTK_TOGGLE_ACTION(gtk_ui_manager_get_action(x,y))
#define gtk_item_factory_get_widget gtk_ui_manager_get_widget
#if GTK_CHECK_VERSION(3, 0, 0)
#include <gdk/gdkkeysyms-compat.h>
#define GTK_OPTION_MENU GTK_COMBO_BOX
#define GTK_WIDGET_IS_SENSITIVE gtk_widget_is_sensitive
#define GTK_WIDGET_VISIBLE gtk_widget_get_visible
@@ -65,6 +68,17 @@
#define gtk_option_menu_new gtk_combo_box_text_new
#define gtk_option_menu_set_history gtk_combo_box_set_active
#define gtk_option_menu_set_menu(x,y)
#ifndef USE_GTK_GRID
#define gtk_orientable_set_orientation(x,y)
#define gtk_widget_set_hexpand(x,y)
#define gtk_widget_set_vexpand(x,y)
#endif
#ifdef USE_GTK_GRID
#undef GTK_BOX
#define GTK_BOX GTK_GRID
#define gtk_hbox_new(x,y) gtk_grid_new()
#define gtk_vbox_new(x,y) gtk_grid_new()
#define gtk_box_pack_start(v,w,x,y,z) gtk_container_add(GTK_CONTAINER(v),w)
#endif
#if GTK_CHECK_VERSION(3,1,12)
#undef GTK_FONT_SELECTION_DIALOG

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2005 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -59,13 +59,13 @@ get_lines (GtkTextView *text_view,
gint size;
#endif
gint last_line_num;
g_array_set_size (buffer_coords, 0);
g_array_set_size (numbers, 0);
/* Get iter at first y */
gtk_text_view_get_line_at_y (text_view, &iter, y1, NULL);
/* For each iter, get its location and add it to the arrays.
* Stop when we pass y2
*/
@@ -73,41 +73,41 @@ get_lines (GtkTextView *text_view,
#if 0
size = 0;
#endif
while (!gtk_text_iter_is_end (&iter))
{
gint y, height;
gtk_text_view_get_line_yrange (text_view, &iter, &y, &height);
g_array_append_val (buffer_coords, y);
last_line_num = gtk_text_iter_get_line (&iter);
g_array_append_val (numbers, last_line_num);
++count;
if ((y + height) >= y2)
break;
gtk_text_iter_forward_line (&iter);
}
if (gtk_text_iter_is_end (&iter))
{
gint y, height;
gint line_num;
gtk_text_view_get_line_yrange (text_view, &iter, &y, &height);
line_num = gtk_text_iter_get_line (&iter);
if (line_num != last_line_num) {
g_array_append_val (buffer_coords, y);
g_array_append_val (numbers, line_num);
++count;
}
}
*countp = count;
}
@@ -132,17 +132,17 @@ line_numbers_expose (GtkWidget *widget, cairo_t *event)
cairo_t *gc;
gint height;
#endif
if (line_number_visible){{{{{ // omit calculation
text_view = GTK_TEXT_VIEW (widget);
/* See if this expose is on the line numbers window */
/* left_win = gtk_text_view_get_window (text_view,
GTK_TEXT_WINDOW_LEFT);
right_win = gtk_text_view_get_window (text_view,
GTK_TEXT_WINDOW_RIGHT);
if (event->window == left_win)
{
type = GTK_TEXT_WINDOW_LEFT;
@@ -155,48 +155,48 @@ line_numbers_expose (GtkWidget *widget, cairo_t *event)
}
else
return FALSE;
*/
*/
#if 0
GdkWindow *win;
win = gtk_text_view_get_window (text_view,
GTK_TEXT_WINDOW_LEFT);
if (event->window != win)
return FALSE;
// style = gtk_style_copy (widget->style);
// style = gtk_style_copy (gtk_widget_get_default_style());
y1 = event->area.y;
y2 = y1 + event->area.height;
#endif
gtk_text_view_window_to_buffer_coords (text_view,
GTK_TEXT_WINDOW_LEFT,
0,
y1,
NULL,
&y1);
gtk_text_view_window_to_buffer_coords (text_view,
GTK_TEXT_WINDOW_LEFT,
0,
y2,
NULL,
&y2);
numbers = g_array_new (FALSE, FALSE, sizeof (gint));
pixels = g_array_new (FALSE, FALSE, sizeof (gint));
get_lines (text_view,
y1,
y2,
pixels,
numbers,
&count);
/* a zero-lined document should display a "1"; we don't need to worry about
scrolling effects of the text widget in this special case */
if (count == 0)
{
gint y = 0;
@@ -205,21 +205,21 @@ line_numbers_expose (GtkWidget *widget, cairo_t *event)
g_array_append_val (pixels, y);
g_array_append_val (numbers, n);
}
DV({g_print("Painting line numbers %d - %d\n",
g_array_index(numbers, gint, 0),
g_array_index(numbers, gint, count - 1)); });
layout = gtk_widget_create_pango_layout (widget, "");
// str = g_strdup_printf ("%d", gtk_text_buffer_get_line_count(text_view->buffer));
g_snprintf (str, sizeof (str),
"%d", MAX (99, gtk_text_buffer_get_line_count(gtk_text_view_get_buffer(text_view))));
pango_layout_set_text (layout, str, -1);
// g_free (str);
pango_layout_get_pixel_size (layout, &layout_width, NULL);
min_number_window_width = calculate_min_number_window_width(widget);
if (layout_width > min_number_window_width)
gtk_text_view_set_border_window_size (text_view,
@@ -231,10 +231,10 @@ DV({g_print("Painting line numbers %d - %d\n",
// }
justify_width = min_number_window_width - layout_width;
}
pango_layout_set_width (layout, layout_width);
pango_layout_set_alignment (layout, PANGO_ALIGN_RIGHT);
alist = pango_attr_list_new();
attr = pango_attr_foreground_new(
#if 1
@@ -251,27 +251,27 @@ DV({g_print("Painting line numbers %d - %d\n",
pango_attr_list_insert(alist, attr);
pango_layout_set_attributes(layout, alist);
pango_attr_list_unref(alist);
/* Draw fully internationalized numbers! */
i = 0;
while (i < count)
{
gint pos;
gtk_text_view_buffer_to_window_coords (text_view,
GTK_TEXT_WINDOW_LEFT,
0,
g_array_index (pixels, gint, i),
NULL,
&pos);
// str = g_strdup_printf ("%d", g_array_index (numbers, gint, i) + 1);
g_snprintf (str, sizeof (str),
"%d", g_array_index (numbers, gint, i) + 1);
pango_layout_set_text (layout, str, -1);
gtk_paint_layout (gtk_widget_get_style(widget),
event,
gtk_widget_get_state (widget),
@@ -282,20 +282,20 @@ DV({g_print("Painting line numbers %d - %d\n",
pos,
layout);
// g_free (str);
++i;
}
g_array_free (pixels, TRUE);
g_array_free (numbers, TRUE);
g_object_unref (G_OBJECT (layout));
// g_object_ref (G_OBJECT (style));
/* don't stop emission, need to draw children */
}}}}}
#if 0
gc = gdk_gc_new(event->window);
gdk_gc_set_foreground(gc, widget->style->base);
@@ -305,10 +305,10 @@ DV({g_print("Painting line numbers %d - %d\n",
layout_width + justify_width + margin : 0,
0, submargin,
height);
g_object_unref(gc);
#endif
return FALSE;
}

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2005 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2005 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -38,7 +38,7 @@ static void load_config_file(Conf *conf)
gchar *path;
gchar buf[BUFSIZ];
gchar **num;
path = g_build_filename(g_get_user_config_dir(),
PACKAGE, PACKAGE "rc", NULL);
fp = fopen(path, "r");
@@ -76,7 +76,7 @@ void save_config_file(void)
gint width, height;
gchar *fontname;
gboolean wordwrap, linenumbers, autoindent;
gtk_window_get_size(GTK_WINDOW(pub->mw->window), &width, &height);
fontname = get_font_name_from_widget(pub->mw->view);
ifactory = gtk_item_factory_from_widget(pub->mw->menubar);
@@ -89,7 +89,7 @@ void save_config_file(void)
autoindent = gtk_check_menu_item_get_active(
GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item(ifactory,
"/M/Options/AutoIndent")));
path = g_build_filename(g_get_user_config_dir(), PACKAGE, NULL);
if (!g_file_test(path, G_FILE_TEST_IS_DIR))
g_mkdir_with_parents(path, 0700);
@@ -102,7 +102,7 @@ void save_config_file(void)
return;
}
g_free(path);
fprintf(fp, "%s\n", PACKAGE_VERSION);
fprintf(fp, "%d\n", width);
fprintf(fp, "%d\n", height);
@@ -111,7 +111,7 @@ void save_config_file(void)
fprintf(fp, "%d\n", linenumbers);
fprintf(fp, "%d\n", autoindent);
fclose(fp);
g_free(fontname);
}
@@ -122,13 +122,13 @@ static void parse_args(gint argc, gchar **argv, FileInfo *fi)
EncArray *encarray;
gint i;
GError *error = NULL;
GOptionContext *context;
gchar *opt_codeset = NULL;
gint opt_tab_width = 0;
gboolean opt_jump = 0;
gboolean opt_version = FALSE;
GOptionEntry entries[] =
GOptionEntry entries[] =
{
{ "codeset", 0, 0, G_OPTION_ARG_STRING, &opt_codeset, "Set codeset to open file", "CODESET" },
{ "tab-width", 0, 0, G_OPTION_ARG_INT, &opt_tab_width, "Set tab width", "WIDTH" },
@@ -136,14 +136,14 @@ static void parse_args(gint argc, gchar **argv, FileInfo *fi)
{ "version", 0, 0, G_OPTION_ARG_NONE, &opt_version, "Show version number", NULL },
{ NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
};
context = g_option_context_new("[filename]");
g_option_context_add_main_entries(context, entries, PACKAGE);
g_option_context_add_group(context, gtk_get_option_group(TRUE));
g_option_context_set_ignore_unknown_options(context, FALSE);
g_option_context_parse(context, &argc, &argv, &error);
g_option_context_free(context);
if (error) {
g_print("%s: %s\n", PACKAGE, error->message);
g_error_free(error);
@@ -167,19 +167,19 @@ static void parse_args(gint argc, gchar **argv, FileInfo *fi)
indent_set_default_tab_width(opt_tab_width);
if (opt_jump)
jump_linenum = opt_jump;
if (fi->charset
&& (g_strcasecmp(fi->charset, get_default_charset()) != 0)
&& (g_strcasecmp(fi->charset, "UTF-8") != 0)) {
if (fi->charset
&& (g_ascii_strcasecmp(fi->charset, get_default_charset()) != 0)
&& (g_ascii_strcasecmp(fi->charset, "UTF-8") != 0)) {
encarray = get_encoding_items(get_encoding_code());
for (i = 0; i < ENCODING_MAX_ITEM_NUM; i++)
if (encarray->item[i])
if (g_strcasecmp(fi->charset, encarray->item[i]) == 0)
if (g_ascii_strcasecmp(fi->charset, encarray->item[i]) == 0)
break;
if (i == ENCODING_MAX_ITEM_NUM)
fi->charset_flag = TRUE;
}
if (argc >= 2)
fi->filename = parse_file_uri(argv[1]);
}
@@ -189,25 +189,25 @@ gint main(gint argc, gchar **argv)
Conf *conf;
GtkItemFactory *ifactory;
gchar *stdin_data = NULL;
bindtextdomain(PACKAGE, LOCALEDIR);
bind_textdomain_codeset(PACKAGE, "UTF-8");
textdomain(PACKAGE);
pub = g_malloc(sizeof(PublicData));
pub->fi = g_malloc(sizeof(FileInfo));
pub->fi->filename = NULL;
pub->fi->charset = NULL;
pub->fi->charset_flag = FALSE;
pub->fi->lineend = LF;
parse_args(argc, argv, pub->fi);
gtk_init(&argc, &argv);
g_set_application_name(PACKAGE_NAME);
pub->mw = create_main_window();
conf = g_malloc(sizeof(Conf));
conf->width = 600;
conf->height = 400;
@@ -215,13 +215,12 @@ gint main(gint argc, gchar **argv)
conf->wordwrap = FALSE;
conf->linenumbers = FALSE;
conf->autoindent = FALSE;
load_config_file(conf);
gtk_window_set_default_size(
GTK_WINDOW(pub->mw->window), conf->width, conf->height);
set_text_font_by_name(pub->mw->view, conf->fontname);
gtk_window_set_icon_from_file(GTK_WINDOW(pub->mw->window), ICONDIR"/l3afpad.png", NULL);
set_text_font_by_name(pub->mw->view, conf->fontname);
ifactory = gtk_item_factory_from_widget(pub->mw->menubar);
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
@@ -234,22 +233,22 @@ gint main(gint argc, gchar **argv)
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
(GtkCheckMenuItem*)gtk_item_factory_get_widget(ifactory, "/M/Options/AutoIndent")),
conf->autoindent);
gtk_widget_show_all(pub->mw->window);
g_free(conf->fontname);
g_free(conf);
#ifdef ENABLE_EMACS
#if ENABLE_EMACS
check_emacs_key_theme(GTK_WINDOW(pub->mw->window), ifactory);
#endif
hlight_init(pub->mw->buffer);
undo_init(pub->mw->view,
gtk_item_factory_get_widget(ifactory, "/M/Edit/Undo"),
gtk_item_factory_get_widget(ifactory, "/M/Edit/Redo"));
// hlight_init(pub->mw->buffer);
dnd_init(pub->mw->view);
if (pub->fi->filename)
file_open_real(pub->mw->view, pub->fi);
#ifdef G_OS_UNIX
@@ -259,11 +258,11 @@ gint main(gint argc, gchar **argv)
if (stdin_data) {
gchar *str;
GtkTextIter iter;
str = g_convert(stdin_data, -1, "UTF-8",
get_default_charset(), NULL, NULL, NULL);
g_free(stdin_data);
// gtk_text_buffer_set_text(buffer, "", 0);
gtk_text_buffer_get_start_iter(pub->mw->buffer, &iter);
gtk_text_buffer_insert(pub->mw->buffer, &iter, str, strlen(str));
@@ -273,20 +272,20 @@ gint main(gint argc, gchar **argv)
gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(pub->mw->view), &iter, 0, FALSE, 0, 0);
g_free(str);
}
if (jump_linenum) {
GtkTextIter iter;
gtk_text_buffer_get_iter_at_line(pub->mw->buffer, &iter, jump_linenum - 1);
gtk_text_buffer_place_cursor(pub->mw->buffer, &iter);
// gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(textview), &iter, 0.1, FALSE, 0.5, 0.5);
scroll_to_cursor(pub->mw->buffer, 0.25);
}
set_main_window_title();
// hlight_apply_all(pub->mw->buffer);
gtk_main();
return 0;
}

View File

@@ -2,7 +2,7 @@
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2005 Tarot Osuji
* Copyright (C) 2011 Wen-Yen Chuang <caleb AT calno DOT com>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -40,7 +40,7 @@ static GtkActionEntry menu_items[] =
{ "Open", GTK_STOCK_OPEN, N_("_Open..."), "<control>O", NULL, G_CALLBACK(on_file_open) },
{ "Save", GTK_STOCK_SAVE, N_("_Save"), "<control>S", NULL, G_CALLBACK(on_file_save) },
{ "SaveAs", GTK_STOCK_SAVE_AS, N_("Save _As..."), "<shift><control>S", NULL, G_CALLBACK(on_file_save_as) },
#ifdef ENABLE_PRINT
#if ENABLE_PRINT
{ "PrintPreview", GTK_STOCK_PRINT_PREVIEW, N_("Print Pre_view"), "<shift><control>P", NULL, G_CALLBACK(on_file_print_preview) },
{ "Print", GTK_STOCK_PRINT, N_("_Print..."), "<control>P", NULL, G_CALLBACK(on_file_print) },
#endif
@@ -71,7 +71,7 @@ static GtkToggleActionEntry toggle_entries[] =
};
static guint n_toggle_entries = G_N_ELEMENTS (toggle_entries);
static const gchar *ui_info =
static const gchar *ui_info =
"<ui>"
" <menubar name='M'>"
" <menu action='File'>"
@@ -80,9 +80,11 @@ static const gchar *ui_info =
" <menuitem action='Save'/>"
" <menuitem action='SaveAs'/>"
" <separator/>"
#if ENABLE_PRINT
" <menuitem action='PrintPreview'/>"
" <menuitem action='Print'/>"
" <separator/>"
#endif
" <menuitem action='Quit'/>"
" </menu>"
" <menu action='Edit'>"
@@ -120,9 +122,9 @@ static const gchar *ui_info =
static gchar *menu_translate(const gchar *path, gpointer data)
{
gchar *str;
str = (gchar *)_(path);
return str;
}
@@ -152,7 +154,7 @@ GtkWidget *create_menu_bar(GtkWidget *window)
GtkItemFactory *ifactory;
#if 0
gboolean flag_emacs = FALSE;
gchar *key_theme = NULL;
GtkSettings *settings = gtk_settings_get_default();
if (settings) {
@@ -164,7 +166,7 @@ GtkWidget *create_menu_bar(GtkWidget *window)
}
}
#endif
ifactory = gtk_ui_manager_new();
GtkActionGroup *actions = gtk_action_group_new("Actions");
gtk_action_group_set_translate_func(actions, menu_translate, NULL, NULL);
@@ -174,7 +176,7 @@ GtkWidget *create_menu_bar(GtkWidget *window)
g_object_unref(actions);
gtk_ui_manager_add_ui_from_string(ifactory, ui_info, -1, NULL);
gtk_window_add_accel_group(GTK_WINDOW(window), accel_group);
/* hidden keybinds */
gtk_accel_group_connect(
accel_group, GDK_W, GDK_CONTROL_MASK, 0,
@@ -194,7 +196,7 @@ GtkWidget *create_menu_bar(GtkWidget *window)
gtk_widget_add_accelerator(
gtk_item_factory_get_widget(ifactory, "/M/Search/Replace"),
"activate", accel_group, GDK_R, GDK_CONTROL_MASK, 0);
/* initialize sensitivities */
gtk_widget_set_sensitive(
gtk_item_factory_get_widget(ifactory, "/M/Search/FindNext"),
@@ -202,13 +204,13 @@ GtkWidget *create_menu_bar(GtkWidget *window)
gtk_widget_set_sensitive(
gtk_item_factory_get_widget(ifactory, "/M/Search/FindPrevious"),
FALSE);
menu_item_save = gtk_item_factory_get_widget(ifactory, "/M/File/Save");
menu_item_cut = gtk_item_factory_get_widget(ifactory, "/M/Edit/Cut");
menu_item_copy = gtk_item_factory_get_widget(ifactory, "/M/Edit/Copy");
menu_item_paste = gtk_item_factory_get_widget(ifactory, "/M/Edit/Paste");
menu_item_delete = gtk_item_factory_get_widget(ifactory, "/M/Edit/Delete");
menu_sensitivity_from_selection_bound(FALSE);
return (GtkWidget*)ifactory;
}

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2005 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2005 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -19,19 +19,8 @@
#include <string.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include "dialog.h"
#include "utils.h"
#include "view.h"
#include "undo.h"
#include "l3afpad.h"
#include "gtksourceiter.h"
#include "search.h"
#include "hlight.h"
static gchar *string_find = NULL;
static gchar *string_replace = NULL;
@@ -43,13 +32,13 @@ static gboolean hlight_searched_strings(GtkTextBuffer *buffer, gchar *str)
gboolean res, retval = FALSE;
GtkSourceSearchFlags search_flags =
GTK_SOURCE_SEARCH_VISIBLE_ONLY | GTK_SOURCE_SEARCH_TEXT_ONLY;
if (!string_find)
return FALSE;
if (!match_case)
search_flags = search_flags | GTK_SOURCE_SEARCH_CASE_INSENSITIVE;
gtk_text_buffer_get_bounds(buffer, &start, &end);
/* gtk_text_buffer_remove_tag_by_name(buffer,
"searched", &start, &end);
@@ -72,7 +61,7 @@ static gboolean hlight_searched_strings(GtkTextBuffer *buffer, gchar *str)
replace_mode = FALSE;
else */
hlight_toggle_searched(buffer);
return retval;
}
@@ -82,21 +71,21 @@ gboolean document_search_real(GtkWidget *textview, gint direction)
gboolean res;
GtkSourceSearchFlags search_flags = GTK_SOURCE_SEARCH_VISIBLE_ONLY | GTK_SOURCE_SEARCH_TEXT_ONLY;
GtkTextBuffer *textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
if (!string_find)
return FALSE;
if (!match_case)
search_flags = search_flags | GTK_SOURCE_SEARCH_CASE_INSENSITIVE;
// if (direction == 0 || !hlight_check_searched())
if (direction == 0 || (direction != 2 && !hlight_check_searched()))
hlight_searched_strings(gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)), string_find);
gtk_text_mark_set_visible(
gtk_text_buffer_get_selection_bound(
gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview))), FALSE);
gtk_text_buffer_get_iter_at_mark(textbuffer, &iter, gtk_text_buffer_get_insert(textbuffer));
if (direction < 0) {
res = gtk_source_iter_backward_search(
@@ -110,7 +99,7 @@ gboolean document_search_real(GtkWidget *textview, gint direction)
&iter, string_find, search_flags, &match_start, &match_end, NULL);
}
/* TODO: both gtk_(text/source)_iter_backward_search works not fine for multi-byte */
/* wrap */
/* TODO: define limit NULL -> proper value */
if (!res) {
@@ -124,17 +113,17 @@ gboolean document_search_real(GtkWidget *textview, gint direction)
&iter, string_find, search_flags, &match_start, &match_end, NULL);
}
}
if (res) {
gtk_text_buffer_place_cursor(textbuffer, &match_start);
gtk_text_buffer_move_mark_by_name(textbuffer, "insert", &match_end);
// gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(textview), &match_start, 0.1, FALSE, 0.5, 0.5);
scroll_to_cursor(textbuffer, 0.05);
}
}
else if (direction == 0)
run_dialog_message(gtk_widget_get_toplevel(textview), GTK_MESSAGE_WARNING,
_("Search string not found"));
return res;
}
@@ -145,18 +134,18 @@ static gint document_replace_real(GtkWidget *textview)
gboolean res;
gint num = 0, offset;
GtkWidget *q_dialog = NULL;
GtkSourceSearchFlags search_flags = GTK_SOURCE_SEARCH_VISIBLE_ONLY | GTK_SOURCE_SEARCH_TEXT_ONLY;
GtkSourceSearchFlags search_flags = GTK_SOURCE_SEARCH_VISIBLE_ONLY | GTK_SOURCE_SEARCH_TEXT_ONLY;
GtkTextBuffer *textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
if (!match_case)
search_flags = search_flags | GTK_SOURCE_SEARCH_CASE_INSENSITIVE;
if (replace_all) {
gtk_text_buffer_get_iter_at_mark(textbuffer,
&iter, gtk_text_buffer_get_insert(textbuffer));
mark_init = gtk_text_buffer_create_mark(textbuffer, NULL, &iter, FALSE);
gtk_text_buffer_get_start_iter(textbuffer, &iter);
gtk_text_buffer_get_end_iter(textbuffer, &match_end);
// gtk_text_buffer_remove_tag_by_name(textbuffer,
// "replaced", &iter, &match_end);
@@ -166,7 +155,7 @@ static gint document_replace_real(GtkWidget *textview)
hlight_searched_strings(textbuffer, string_find);
hlight_toggle_searched(textbuffer);
}
do {
if (replace_all) {
res = gtk_source_iter_forward_search(
@@ -181,7 +170,7 @@ static gint document_replace_real(GtkWidget *textview)
else
// res = document_search_real(textview, 0);
res = document_search_real(textview, 2);
if (res) {
if (!replace_all) {
if (num == 0 && q_dialog == NULL)
@@ -227,7 +216,7 @@ static gint document_replace_real(GtkWidget *textview)
gtk_text_buffer_get_iter_at_mark(
textbuffer, &iter,
gtk_text_buffer_get_insert(textbuffer));
num++;
/* if (replace_all)
undo_set_sequency(TRUE);
@@ -238,7 +227,7 @@ static gint document_replace_real(GtkWidget *textview)
} while (res);
if (!hlight_check_searched())
hlight_toggle_searched(textbuffer);
if (q_dialog)
gtk_widget_destroy(q_dialog);
/* if (strlen(string_replace)) {
@@ -252,7 +241,7 @@ static gint document_replace_real(GtkWidget *textview)
_("%d strings replaced"), num);
undo_set_sequency(FALSE);
}
return num;
}
@@ -293,7 +282,7 @@ gint run_dialog_search(GtkWidget *textview, gint mode)
GtkWidget *entry_find, *entry_replace = NULL;
GtkWidget *check_case, *check_all;
gint res;
if (mode)
dialog = gtk_dialog_new_with_buttons(_("Replace"),
GTK_WINDOW(gtk_widget_get_toplevel(textview)),
@@ -308,7 +297,7 @@ gint run_dialog_search(GtkWidget *textview, gint mode)
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_FIND, GTK_RESPONSE_OK,
NULL);
table = gtk_table_new(mode + 2, 2, FALSE);
gtk_table_set_row_spacings(GTK_TABLE(table), 8);
gtk_table_set_col_spacings(GTK_TABLE(table), 8);
@@ -346,7 +335,7 @@ gint run_dialog_search(GtkWidget *textview, gint mode)
gtk_entry_set_activates_default(GTK_ENTRY(entry_find), TRUE);
if (mode)
gtk_entry_set_activates_default(GTK_ENTRY(entry_replace), TRUE);
check_case = gtk_check_button_new_with_mnemonic(_("_Match case"));
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_case), match_case);
g_signal_connect(check_case, "toggled", G_CALLBACK(toggle_check_case), NULL);
@@ -358,8 +347,8 @@ gint run_dialog_search(GtkWidget *textview, gint mode)
gtk_table_attach_defaults(GTK_TABLE(table), check_all, 0, 2, 2 + mode, 3 + mode);
}
gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE);
gtk_widget_show_all(table);
gtk_widget_show_all(table);
res = gtk_dialog_run(GTK_DIALOG(dialog));
if (res == GTK_RESPONSE_OK) {
g_free(string_find);
@@ -369,9 +358,9 @@ gint run_dialog_search(GtkWidget *textview, gint mode)
string_replace = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry_replace)));
}
}
gtk_widget_destroy(dialog);
if (res == GTK_RESPONSE_OK) {
if (strlen(string_find)) {
if (mode)
@@ -380,7 +369,7 @@ gint run_dialog_search(GtkWidget *textview, gint mode)
document_search_real(textview, 0);
}
}
return res;
}
@@ -394,15 +383,15 @@ void run_dialog_jump_to(GtkWidget *textview)
GtkAdjustment *spinner_adj;
GtkTextIter iter;
gint num, max_num;
GtkTextBuffer *textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
gtk_text_buffer_get_iter_at_mark(textbuffer, &iter,
gtk_text_buffer_get_insert(textbuffer));
num = gtk_text_iter_get_line(&iter) + 1;
gtk_text_buffer_get_end_iter(textbuffer, &iter);
max_num = gtk_text_iter_get_line(&iter) + 1;
dialog = gtk_dialog_new_with_buttons(_("Jump To"),
GTK_WINDOW(gtk_widget_get_toplevel(textview)),
GTK_DIALOG_DESTROY_WITH_PARENT,
@@ -423,11 +412,11 @@ void run_dialog_jump_to(GtkWidget *textview)
gtk_entry_set_activates_default(GTK_ENTRY(spinner), TRUE);
gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1);
gtk_table_attach_defaults(GTK_TABLE(table), spinner, 1, 2, 0, 1);
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK);
gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE);
gtk_widget_show_all(dialog);
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
gtk_text_buffer_get_iter_at_line(textbuffer, &iter,
gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinner)) - 1);
@@ -435,6 +424,6 @@ void run_dialog_jump_to(GtkWidget *textview)
// gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(textview), &iter, 0.1, FALSE, 0.5, 0.5);
scroll_to_cursor(textbuffer, 0.25);
}
gtk_widget_destroy (dialog);
}

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2005 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2005 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -46,23 +46,22 @@ static void cb_select_lineend(GtkOptionMenu *option_menu, FileInfo *selected_fi)
static GtkWidget *create_lineend_menu(FileInfo *selected_fi)
{
GtkWidget *option_menu;
GtkWidget *menu;
GtkWidget *menu_item;
GtkListStore *store = gtk_list_store_new (1, G_TYPE_STRING);
GtkTreeIter iter;
GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
GtkWidget *option_menu = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
gint i;
option_menu = gtk_option_menu_new();
menu = gtk_menu_new();
for (i = 0; i <= 2; i++) {
menu_item = gtk_menu_item_new_with_label(lineend_str[i]);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu_item);
gtk_widget_show(menu_item); // <- required for width adjustment
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, 0, lineend_str[i], -1);
}
gtk_option_menu_set_menu(GTK_OPTION_MENU(option_menu), menu);
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (option_menu), renderer, FALSE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (option_menu), renderer, "text", 0, NULL);
g_signal_connect(G_OBJECT(option_menu), "changed",
G_CALLBACK(cb_select_lineend), selected_fi);
i = 0;
switch (selected_fi->lineend) {
case CR+LF:
@@ -72,7 +71,7 @@ static GtkWidget *create_lineend_menu(FileInfo *selected_fi)
i = 2;
}
gtk_option_menu_set_history(GTK_OPTION_MENU(option_menu), i);
return option_menu;
}
@@ -87,7 +86,7 @@ static CharsetTable *get_charset_table(void)
static CharsetTable *ctable = NULL;
EncArray *encarray;
gint i;
if (!ctable) {
ctable = g_malloc(sizeof(CharsetTable));
ctable->num = 0;
@@ -105,7 +104,7 @@ static CharsetTable *get_charset_table(void)
ctable->num++;
}
}
return ctable;
}
@@ -121,14 +120,14 @@ static GtkWidget *init_menu_item_manual_charset(gchar *manual_charset)
{
static GtkLabel *label;
gchar *str;
if (other_codeset_title == NULL)
other_codeset_title = _("Other Codeset");
str = manual_charset
? g_strdup_printf("%s (%s)", other_codeset_title, manual_charset)
: g_strdup_printf("%s...", other_codeset_title);
if (!menu_item_manual_charset) {
menu_item_manual_charset = gtk_menu_item_new_with_label(str);
label = GTK_LABEL(gtk_bin_get_child(GTK_BIN(menu_item_manual_charset)));
@@ -136,7 +135,7 @@ static GtkWidget *init_menu_item_manual_charset(gchar *manual_charset)
// gtk_label_set_text(GTK_LABEL(GTK_BIN(menu_item_manual_charset)->child), str);
gtk_label_set_text(label, str);
g_free(str);
return menu_item_manual_charset;
}
@@ -148,7 +147,7 @@ static gboolean get_manual_charset(GtkOptionMenu *option_menu, FileInfo *selecte
GtkWidget *entry;
GError *err = NULL;
gchar *str;
dialog = gtk_dialog_new_with_buttons(other_codeset_title,
GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(option_menu))),
GTK_DIALOG_DESTROY_WITH_PARENT,
@@ -157,28 +156,31 @@ static gboolean get_manual_charset(GtkOptionMenu *option_menu, FileInfo *selecte
NULL);
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK);
gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_MOUSE);
vbox = gtk_vbox_new(FALSE, 0);
gtk_orientable_set_orientation(GTK_ORIENTABLE(vbox), GTK_ORIENTATION_VERTICAL);
gtk_container_set_border_width(GTK_CONTAINER(vbox), 8);
gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), vbox, FALSE, FALSE, 0);
label = gtk_label_new_with_mnemonic(_("Code_set:"));
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 5);
entry = gtk_entry_new();
gtk_widget_set_hexpand (entry, TRUE);
gtk_widget_set_vexpand (entry, TRUE);
gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE);
gtk_label_set_mnemonic_widget(GTK_LABEL(label), entry);
gtk_box_pack_start(GTK_BOX(vbox), entry, FALSE, FALSE, 5);
gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), GTK_RESPONSE_OK, FALSE);
g_signal_connect_after(G_OBJECT(entry), "changed",
G_CALLBACK(toggle_sensitivity), NULL);
if (selected_fi->charset_flag)
gtk_entry_set_text(GTK_ENTRY(entry), selected_fi->charset);
gtk_widget_show_all(vbox);
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
g_convert("TEST", -1, "UTF-8", gtk_entry_get_text(GTK_ENTRY(entry)), NULL, NULL, &err);
if (err) {
@@ -193,15 +195,15 @@ static gboolean get_manual_charset(GtkOptionMenu *option_menu, FileInfo *selecte
selected_fi->charset = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
selected_fi->charset_flag = TRUE;
gtk_widget_destroy(dialog);
init_menu_item_manual_charset(selected_fi->charset_flag
? selected_fi->charset : NULL);
return TRUE;
}
}
gtk_widget_destroy(dialog);
return FALSE;
}
@@ -211,7 +213,7 @@ static void cb_select_charset(GtkOptionMenu *option_menu, FileInfo *selected_fi)
{
CharsetTable *ctable;
static guint index_history = 0, prev_history;
prev_history = index_history;
index_history = gtk_option_menu_get_history(option_menu);
if (!charset_menu_init_flag) {
@@ -235,40 +237,36 @@ static void cb_select_charset(GtkOptionMenu *option_menu, FileInfo *selected_fi)
static GtkWidget *create_charset_menu(FileInfo *selected_fi)
{
GtkWidget *option_menu;
GtkWidget *menu;
GtkWidget *menu_item;
GtkListStore *store = gtk_list_store_new (1, G_TYPE_STRING);
GtkTreeIter iter;
GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
GtkWidget *option_menu = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
CharsetTable *ctable;
guint i;
option_menu = gtk_option_menu_new();
menu = gtk_menu_new();
if (mode == OPEN) {
menu_item = gtk_menu_item_new_with_label(_("Auto-Detect"));
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu_item);
gtk_widget_show(menu_item); // <- required for width adjustment
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, 0, _("Auto-Detect"), -1);
}
ctable = get_charset_table();
for (i = 0; i < ctable->num; i++) {
menu_item = gtk_menu_item_new_with_label(ctable->str[i]);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu_item);
gtk_widget_show(menu_item); // <- required for width adjustment
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, 0, ctable->str[i], -1);
}
menu_item_manual_charset = NULL;
gtk_menu_shell_append(GTK_MENU_SHELL(menu),
init_menu_item_manual_charset(selected_fi->charset_flag
? selected_fi->charset : NULL));
gtk_widget_show(menu_item_manual_charset); // <- required for width adjustment
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, 0, gtk_menu_item_get_label(GTK_MENU_ITEM(init_menu_item_manual_charset(selected_fi->charset_flag
? selected_fi->charset : NULL))), -1);
charset_menu_init_flag = TRUE;
g_signal_connect(G_OBJECT(option_menu), "changed",
G_CALLBACK(cb_select_charset), selected_fi);
gtk_option_menu_set_menu(GTK_OPTION_MENU(option_menu), menu);
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (option_menu), renderer, FALSE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (option_menu), renderer, "text", 0, NULL);
i = 0;
if (selected_fi->charset) {
do {
if (g_strcasecmp(selected_fi->charset, ctable->charset[i]) == 0)
if (g_ascii_strcasecmp(selected_fi->charset, ctable->charset[i]) == 0)
break;
i++;
} while (i < ctable->num);
@@ -283,7 +281,7 @@ static GtkWidget *create_charset_menu(FileInfo *selected_fi)
if (mode == SAVE || selected_fi->charset_flag)
gtk_option_menu_set_history(GTK_OPTION_MENU(option_menu), i);
charset_menu_init_flag = FALSE;
return option_menu;
}
@@ -296,16 +294,16 @@ static GtkWidget *create_file_selector(FileInfo *selected_fi)
GtkWidget *option_menu_charset;
GtkWidget *option_menu_lineend;
const gchar *title;
title = mode ? _("Open") : _("Save As");
selector = gtk_file_chooser_dialog_new(title, NULL,
mode ? GTK_FILE_CHOOSER_ACTION_OPEN : GTK_FILE_CHOOSER_ACTION_SAVE,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
mode ? GTK_STOCK_OPEN : GTK_STOCK_SAVE, GTK_RESPONSE_OK,
NULL);
gtk_dialog_set_default_response(GTK_DIALOG(selector), GTK_RESPONSE_OK);
// align = gtk_alignment_new(0.5, 0, 0, 0);
align = gtk_alignment_new(1, 0, 0, 0);
gtk_file_chooser_set_extra_widget(GTK_FILE_CHOOSER(selector), align);
@@ -323,10 +321,10 @@ static GtkWidget *create_file_selector(FileInfo *selected_fi)
gtk_table_attach_defaults(GTK_TABLE(table), option_menu_lineend, 2, 3, 0, 1);
}
gtk_widget_show_all(align);
if (selected_fi->filename)
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(selector), selected_fi->filename);
return selector;
}
@@ -336,7 +334,7 @@ FileInfo *get_fileinfo_from_selector(FileInfo *fi, gint requested_mode)
GtkWidget *selector;
gchar *basename, *str;
gint res, len;
/* init values */
mode = requested_mode;
selected_fi = g_malloc(sizeof(FileInfo));
@@ -346,11 +344,11 @@ FileInfo *get_fileinfo_from_selector(FileInfo *fi, gint requested_mode)
fi->charset ? g_strdup(fi->charset) : NULL;
selected_fi->charset_flag = fi->charset_flag;
selected_fi->lineend = fi->lineend;
selector = create_file_selector(selected_fi);
gtk_window_set_transient_for(GTK_WINDOW(selector),
GTK_WINDOW(pub->mw->window));
do {
res = gtk_dialog_run(GTK_DIALOG(selector));
if (res == GTK_RESPONSE_OK) {
@@ -384,15 +382,15 @@ FileInfo *get_fileinfo_from_selector(FileInfo *fi, gint requested_mode)
}
gtk_widget_hide(selector);
} while (GTK_WIDGET_VISIBLE(selector));
if (res != GTK_RESPONSE_OK) {
if (selected_fi->charset)
g_free(selected_fi->charset);
selected_fi = NULL;
g_free(selected_fi);
}
gtk_widget_destroy(selector);
return selected_fi;
}

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2005 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2005 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -66,16 +66,16 @@ static GList *undo_clear_info_list(GList *info_list)
static void undo_append_undo_info(GtkTextBuffer *buffer, gchar command, gint start, gint end, gchar *str)
{
UndoInfo *ui = g_malloc(sizeof(UndoInfo));
ui->command = command;
ui->start = start;
ui->end = end;
// ui->seq = FALSE;
ui->seq = seq_reserve;
ui->str = str;
seq_reserve = FALSE;
undo_list = g_list_append(undo_list, ui);
DV(g_print("undo_cb: %d %s (%d-%d)\n", command, str, start, end));
}
@@ -86,11 +86,11 @@ static void undo_create_undo_info(GtkTextBuffer *buffer, gchar command, gint sta
gboolean seq_flag = FALSE;
gchar *str;
gint keyval = get_current_keyval();
gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start);
gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end);
str = gtk_text_buffer_get_text(buffer, &start_iter, &end_iter, FALSE);
if (undo_gstr->len) {
if ((end - start == 1) && (command == ui_tmp->command)) {
switch (keyval) {
@@ -139,10 +139,10 @@ static void undo_create_undo_info(GtkTextBuffer *buffer, gchar command, gint sta
undo_append_undo_info(buffer, ui_tmp->command, ui_tmp->start, ui_tmp->end, g_strdup(undo_gstr->str));
undo_gstr = g_string_erase(undo_gstr, 0, -1);
}
if (!keyval && prev_keyval)
undo_set_sequency(TRUE);
if (end - start == 1 &&
((keyval && keyval < 0xF000) ||
keyval == GDK_BackSpace || keyval == GDK_Delete || keyval == GDK_Tab)) {
@@ -151,9 +151,9 @@ static void undo_create_undo_info(GtkTextBuffer *buffer, gchar command, gint sta
ui_tmp->end = end;
undo_gstr = g_string_erase(undo_gstr, 0, -1);
g_string_append(undo_gstr, str);
} else
} else
undo_append_undo_info(buffer, command, start, end, g_strdup(str));
redo_list = undo_clear_info_list(redo_list);
prev_keyval = keyval;
clear_current_keyval();
@@ -165,11 +165,11 @@ static void undo_create_undo_info(GtkTextBuffer *buffer, gchar command, gint sta
static void cb_insert_text(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *str)
{
gint start, end;
DV( g_print("insert-text\n"));
end = gtk_text_iter_get_offset(iter);
start = end - g_utf8_strlen(str, -1);
undo_create_undo_info(buffer, INS, start, end);
}
@@ -177,11 +177,11 @@ static void cb_delete_range(GtkTextBuffer *buffer, GtkTextIter *start_iter, GtkT
{
gint start, end;
gchar command;
DV( g_print("delete-range\n"));
start = gtk_text_iter_get_offset(start_iter);
end = gtk_text_iter_get_offset(end_iter);
if (get_current_keyval() == GDK_BackSpace)
command = BS;
else
@@ -199,7 +199,7 @@ DV(g_print("undo_reset_modified_step: Reseted modified_step by %d\n", modified_s
static void undo_check_modified_step(GtkTextBuffer *buffer)
{
gboolean flag;
flag = (modified_step == g_list_length(undo_list));
//g_print("%d - %d = %d\n", modified_step, g_list_length(undo_list), flag);
if (gtk_text_buffer_get_modified(buffer) == flag)
@@ -224,7 +224,7 @@ static void undo_check_modified_step(GtkTextBuffer *buffer)
*/
static void cb_begin_user_action(GtkTextBuffer *buffer)
{
g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
G_CALLBACK(cb_insert_text), NULL);
g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
G_CALLBACK(cb_delete_range), NULL);
@@ -234,7 +234,7 @@ DV(g_print(": keyval = 0x%X\n", get_current_keyval()));
static void cb_end_user_action(GtkTextBuffer *buffer)
{
g_signal_handlers_block_by_func(G_OBJECT(buffer),
g_signal_handlers_block_by_func(G_OBJECT(buffer),
G_CALLBACK(cb_insert_text), NULL);
g_signal_handlers_block_by_func(G_OBJECT(buffer),
G_CALLBACK(cb_delete_range), NULL);
@@ -248,7 +248,7 @@ void undo_clear_all(GtkTextBuffer *buffer)
undo_reset_modified_step(buffer);
gtk_widget_set_sensitive(undo_w, FALSE);
gtk_widget_set_sensitive(redo_w, FALSE);
ui_tmp->command = INS;
undo_gstr = g_string_erase(undo_gstr, 0, -1);
prev_keyval = 0;
@@ -257,10 +257,10 @@ void undo_clear_all(GtkTextBuffer *buffer)
void undo_init(GtkWidget *view, GtkWidget *undo_button, GtkWidget *redo_button)
{
GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view));
undo_w = undo_button;
redo_w = redo_button;
g_signal_connect_after(G_OBJECT(buffer), "insert-text",
G_CALLBACK(cb_insert_text), NULL);
g_signal_connect(G_OBJECT(buffer), "delete-range",
@@ -270,10 +270,10 @@ void undo_init(GtkWidget *view, GtkWidget *undo_button, GtkWidget *redo_button)
g_signal_connect(G_OBJECT(buffer), "end-user-action",
G_CALLBACK(cb_end_user_action), NULL);
cb_end_user_action(buffer);
ui_tmp = g_malloc(sizeof(UndoInfo));
undo_gstr = g_string_new("");
undo_clear_all(buffer);
}
@@ -281,7 +281,7 @@ void undo_set_sequency(gboolean seq)
{
if (g_list_length(undo_list))
((UndoInfo *)g_list_last(undo_list)->data)->seq = seq;
DV(g_print("<undo_set_sequency: %d>\n", seq));
DV(g_print("<undo_set_sequency: %d>\n", seq));
}
void undo_set_sequency_reserve(void)
@@ -302,7 +302,7 @@ gboolean undo_undo_real(GtkTextBuffer *buffer)
{
GtkTextIter start_iter, end_iter;
UndoInfo *ui;
undo_flush_temporal_buffer(buffer);
if (g_list_length(undo_list)) {
// undo_block_signal(buffer);
@@ -340,7 +340,7 @@ gboolean undo_redo_real(GtkTextBuffer *buffer)
{
GtkTextIter start_iter, end_iter;
UndoInfo *ri;
if (g_list_length(redo_list)) {
// undo_block_signal(buffer);
ri = g_list_last(redo_list)->data;

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2005 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2005 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -17,7 +17,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <gtk/gtk.h>
#include "l3afpad.h"
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
@@ -37,7 +37,7 @@ gchar *gedit_utils_get_stdin (void)
// GnomeVFSResult res;
fd_set rfds;
struct timeval tv;
FD_ZERO (&rfds);
FD_SET (0, &rfds);
@@ -52,7 +52,7 @@ gchar *gedit_utils_get_stdin (void)
g_return_val_if_fail (tmp_buf != NULL, FALSE);
file_contents = g_string_new (NULL);
while (feof (stdin) == 0)
{
buffer_length = fread (tmp_buf, 1, GEDIT_STDIN_BUFSIZE, stdin);
@@ -61,8 +61,8 @@ gchar *gedit_utils_get_stdin (void)
if (ferror (stdin) != 0)
{
// res = gnome_vfs_result_from_errno ();
// res = gnome_vfs_result_from_errno ();
g_free (tmp_buf);
g_string_free (file_contents, TRUE);
return NULL;
@@ -82,21 +82,25 @@ GtkWidget *create_button_with_stock_image(const gchar *text, const gchar *stock_
GtkWidget *image;
GtkWidget *label;
GtkWidget *align;
hbox = gtk_hbox_new(FALSE, 2);
image = gtk_image_new_from_stock(stock_id, GTK_ICON_SIZE_BUTTON);
gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0);
label = gtk_label_new_with_mnemonic(text);
#if USE_GTK_GRID
gtk_grid_attach_next_to (GTK_BOX (hbox), label, image, GTK_POS_RIGHT, 1, 1);
#else
gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
#endif
align = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
gtk_container_add(GTK_CONTAINER(align), hbox);
button = gtk_button_new();
gtk_container_add(GTK_CONTAINER(button), align);
gtk_widget_show_all(button);
return button;
}

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2005 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2005 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -37,7 +37,7 @@ void clear_current_keyval(void)
gboolean scroll_to_cursor(GtkTextBuffer *buffer, gdouble within_margin)
{
GtkTextIter iter;
// gtk_text_buffer_get_start_iter(buffer, &iter);
gtk_text_buffer_get_iter_at_mark(buffer, &iter,
gtk_text_buffer_get_insert(buffer));
@@ -56,7 +56,7 @@ gint check_text_modification(void)
{
gchar *basename, *str;
gint res;
if (gtk_text_buffer_get_modified(pub->mw->buffer)) {
basename = get_file_basename(pub->fi->filename, FALSE);
str = g_strdup_printf(_("Save changes to '%s'?"), basename);
@@ -72,7 +72,7 @@ gint check_text_modification(void)
}
return -1;
}
return 0;
}
@@ -80,10 +80,10 @@ gint check_text_modification(void)
static gint check_preedit(GtkWidget *view)
{
gint cursor_pos;
gtk_im_context_get_preedit_string(
GTK_TEXT_VIEW(view)->im_context, NULL, NULL, &cursor_pos);
return cursor_pos;
}
#endif
@@ -92,7 +92,7 @@ static gboolean check_selection_bound(GtkTextBuffer *buffer)
{
GtkTextIter start, end;
gchar *str, *p;
if (gtk_text_buffer_get_selection_bounds(buffer, &start, &end)) {
str = gtk_text_iter_get_text(&start, &end);
p = strchr(str, '\n');
@@ -100,7 +100,7 @@ static gboolean check_selection_bound(GtkTextBuffer *buffer)
if (p)
return TRUE;
}
return FALSE;
}
@@ -110,17 +110,17 @@ static gboolean cb_key_press_event(GtkWidget *view, GdkEventKey *event)
GtkTextMark *mark;
GtkTextIter iter;
GdkRectangle prev_rect;
#if 0
if (check_preedit(view))
return FALSE;
#endif
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view));
mark = gtk_text_buffer_get_insert(buffer);
gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
gtk_text_view_get_iter_location(GTK_TEXT_VIEW(view), &iter, &prev_rect);
keyval = 0;
//g_print("key-press-event: 0x%X\n", event->keyval);
switch (event->keyval) {
@@ -131,7 +131,7 @@ static gboolean cb_key_press_event(GtkWidget *view, GdkEventKey *event)
gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
gtk_text_view_get_iter_location(GTK_TEXT_VIEW(view), &iter, &iter_rect);
if (iter_rect.y < prev_rect.y) {
gtk_text_view_get_line_at_y(GTK_TEXT_VIEW(view), &iter,
gtk_text_view_get_line_at_y(GTK_TEXT_VIEW(view), &iter,
iter_rect.y - iter_rect.height, NULL);
gtk_text_buffer_move_mark(buffer, mark, &iter);
}
@@ -195,7 +195,7 @@ static gboolean cb_key_press_event(GtkWidget *view, GdkEventKey *event)
keyval = keyval + 0x10000;
//g_print("=================================================\n");
}
return FALSE;
}
@@ -203,9 +203,9 @@ static gboolean cb_button_press_event(GtkWidget *view, GdkEventButton *event)
{
GtkTextIter iter, start, end;
gint x, y;
GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view));
if ((event->button) == 3 && (event->type == GDK_BUTTON_PRESS)) {
gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(view),
gtk_text_view_get_window_type(GTK_TEXT_VIEW(view), event->window),
@@ -215,7 +215,7 @@ static gboolean cb_button_press_event(GtkWidget *view, GdkEventButton *event)
if (!gtk_text_iter_in_range(&iter, &start, &end))
gtk_text_buffer_place_cursor(buffer, &iter);
}
return FALSE;
}
@@ -223,7 +223,7 @@ static void cb_modified_changed(GtkTextBuffer *buffer, GtkWidget *view)
{
gboolean modified_flag, exist_flag = FALSE;
gchar *filename, *title;
modified_flag = gtk_text_buffer_get_modified(buffer);
filename = get_file_basename(pub->fi->filename, TRUE);
if (modified_flag)
@@ -286,14 +286,14 @@ static void cb_focus_event(GtkWidget *view, GdkEventFocus *event)
/*
static void cb_begin_user_action(GtkTextBuffer *buffer, GtkWidget *view)
{
g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
G_CALLBACK(cb_modified_changed), view);
// g_print("begin-user-action\n");
}
static void cb_end_user_action(GtkTextBuffer *buffer, GtkWidget *view)
{
g_signal_handlers_block_by_func(G_OBJECT(buffer),
g_signal_handlers_block_by_func(G_OBJECT(buffer),
G_CALLBACK(cb_modified_changed), view);
gtk_text_view_scroll_mark_onscreen( // TODO: require?
GTK_TEXT_VIEW(view),
@@ -325,13 +325,13 @@ GtkWidget *create_text_view(void)
{
GtkWidget *view;
GtkTextBuffer *buffer;
view = gtk_text_view_new();
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view));
// gtk_text_view_set_left_margin(GTK_TEXT_VIEW(view), 1);
// gtk_text_view_set_right_margin(GTK_TEXT_VIEW(view), 1);
g_signal_connect(G_OBJECT(view), "key-press-event",
G_CALLBACK(cb_key_press_event), NULL);
g_signal_connect(G_OBJECT(view), "button-press-event",
@@ -350,7 +350,7 @@ GtkWidget *create_text_view(void)
G_CALLBACK(cb_focus_event), NULL);
g_signal_connect_after(G_OBJECT(view), "focus-out-event",
G_CALLBACK(cb_focus_event), NULL);
g_signal_connect(G_OBJECT(buffer), "mark-set",
G_CALLBACK(cb_mark_changed), NULL);
g_signal_connect(G_OBJECT(buffer), "mark-deleted",
@@ -364,8 +364,8 @@ GtkWidget *create_text_view(void)
g_signal_connect_after(G_OBJECT(buffer), "end-user-action",
G_CALLBACK(cb_end_user_action), view);
cb_end_user_action(buffer, view);
*/
*/
linenum_init(view);
return view;
}

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2005 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2005 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -33,55 +33,59 @@ MainWin *create_main_window(void)
GtkWidget *view;
// gint size;
// GtkAdjustment *hadj, *vadj;
MainWin *mw = g_malloc(sizeof(MainWin));
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
// gtk_window_set_title(GTK_WINDOW(window), PACKAGE_NAME);
gtk_widget_set_name(window, PACKAGE_NAME);
gtk_window_set_icon_from_file(GTK_WINDOW(window), ICONDIR"/l3afpad.png", NULL);
gtk_window_set_default_icon_name(PACKAGE);
g_signal_connect(G_OBJECT(window), "delete-event",
G_CALLBACK(on_file_quit), NULL);
g_signal_connect_after(G_OBJECT(window), "delete-event",
G_CALLBACK(gtk_widget_hide_on_delete), NULL);
vbox = gtk_vbox_new(FALSE, 0);
gtk_orientable_set_orientation(GTK_ORIENTABLE(vbox), GTK_ORIENTATION_VERTICAL);
gtk_container_add(GTK_CONTAINER(window), vbox);
menubar = create_menu_bar(window);
gtk_box_pack_start(GTK_BOX(vbox), gtk_item_factory_get_widget(GTK_UI_MANAGER(menubar), "/M"), FALSE, FALSE, 0);
sw = gtk_scrolled_window_new(NULL, NULL);
gtk_widget_set_hexpand (sw, TRUE);
gtk_widget_set_vexpand (sw, TRUE);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw),
GTK_SHADOW_IN);
gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0);
view = create_text_view();
gtk_container_add(GTK_CONTAINER(sw), view);
/*
/*
hadj = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(sw));
vadj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(sw));
g_signal_connect_after(G_OBJECT(hadj), "value-changed",
G_CALLBACK(cb_scroll_event), view);
g_signal_connect_after(G_OBJECT(vadj), "value-changed",
G_CALLBACK(cb_scroll_event), view);
*/
*/
mw->window = window;
mw->menubar = menubar;
mw->view = view;
mw->buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view));
return mw;
}
void set_main_window_title(void)
{
gchar *title;
title = get_file_basename(pub->fi->filename, TRUE);
gtk_window_set_title(GTK_WINDOW(pub->mw->window), title);
g_free(title);

View File

@@ -1,7 +1,7 @@
/*
* L3afpad - GTK+ based simple text editor
* Copyright (C) 2004-2005 Tarot Osuji
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or