Hi, I have just added a new feature on Leafpad and try to make it a little bit extendable. (stay focus on footprint very low).
Would like to share it. Here are the files I modified, I could share new feature in the future. PS: if there is any way to add it by myself, I can do it :) Thanks Regards Samy
/*
* Leafpad - 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
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "leafpad.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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);
else
gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end);
gtk_text_buffer_place_cursor(buffer, &end_iter);
gtk_text_buffer_move_mark_by_name(buffer, "selection_bound", &start_iter);
}
void on_file_new(void)
{
gchar *comline;
gchar *option;
save_config_file();
option = pub->fi->charset_flag ?
g_strdup_printf("%s%s", " --codeset=", pub->fi->charset) : "";
comline = g_strdup_printf("%s%s", PACKAGE, option);
if (pub->fi->charset_flag)
g_free(option);
g_spawn_command_line_async(comline, NULL);
g_free(comline);
}
void on_file_open(void)
#ifdef ENABLE_CSDI
{ // too slow...
FileInfo *fi;
gchar *comline;
gchar *option = NULL;
fi = get_fileinfo_from_selector(pub->fi, OPEN);
if (fi) {
save_config_file();
option = g_strdup_printf("--codeset=%s ", fi->charset);
comline = g_strdup_printf("%s %s%s", PACKAGE,
fi->charset ? option : "",
fi->filename);
g_spawn_command_line_async(comline, NULL);
g_free(option);
g_free(comline);
g_free(fi);
}
}
#else
{
FileInfo *fi;
if (check_text_modification())
return;
fi = get_fileinfo_from_selector(pub->fi, OPEN);
if (fi) {
if (file_open_real(pub->mw->view, fi))
g_free(fi);
else {
g_free(pub->fi);
pub->fi = fi;
undo_clear_all(pub->mw->buffer);
// set_main_window_title();
force_call_cb_modified_changed(pub->mw->view);
// undo_init(sd->mainwin->textview, sd->mainwin->textbuffer, sd->mainwin->menubar);
}
}
}
#endif
gint on_file_save(void)
{
if (pub->fi->filename == NULL)
return on_file_save_as();
if (check_file_writable(pub->fi->filename) == FALSE)
return on_file_save_as();
if (file_save_real(pub->mw->view, pub->fi))
return -1;
// set_main_window_title();
force_call_cb_modified_changed(pub->mw->view);
// undo_reset_step_modif();
return 0;
}
gint on_file_save_as(void)
{
FileInfo *fi;
fi = get_fileinfo_from_selector(pub->fi, SAVE);
if (fi == NULL)
return -1;
if (file_save_real(pub->mw->view, fi)) {
g_free(fi);
return -1;
}
g_free(pub->fi);
pub->fi = fi;
undo_clear_all(pub->mw->buffer);
// set_main_window_title();
force_call_cb_modified_changed(pub->mw->view);
// undo_init(sd->mainwin->textview, sd->mainwin->textbuffer, sd->mainwin->menubar);
return 0;
}
void on_file_reopen (void) //reopen the current file with a more advanced editor
{
gchar *command = NULL;
gchar *advanced_editor = "emacs"; //TODO: hardcoded --> set a preference
GError *error = NULL;
if (pub->fi->filename == NULL)
return;
command = g_strdup_printf ("%s %s", advanced_editor, pub->fi->filename);
if (!g_spawn_command_line_async (command, &error))
{
g_printerr ("leafpad> ERROR *** Could not launch advanced editor\n");
//TODO: deal with the error
g_clear_error (&error);
g_free (command);
return;
}
g_free (command);
}
void on_file_reload(void)
{
if (pub->fi->filename == NULL)
return;
file_open_real(pub->mw->view, pub->fi);
}
#ifdef ENABLE_PRINT
# if GTK_CHECK_VERSION(2, 10, 0)
void on_file_print_preview(void)
{
create_gtkprint_preview_session(GTK_TEXT_VIEW(pub->mw->view),
get_file_basename(pub->fi->filename, FALSE));
}
void on_file_print(void)
{
create_gtkprint_session(GTK_TEXT_VIEW(pub->mw->view),
get_file_basename(pub->fi->filename, FALSE));
}
# else
void on_file_print(void)
{
create_gnomeprint_session();
}
# endif
#endif
void on_file_close(void)
{
if (!check_text_modification()) {
force_block_cb_modified_changed(pub->mw->view);
// undo_block_signal(textbuffer);
gtk_text_buffer_set_text(pub->mw->buffer, "", 0);
gtk_text_buffer_set_modified(pub->mw->buffer, FALSE);
if (pub->fi->filename)
g_free(pub->fi->filename);
pub->fi->filename = NULL;
if (pub->fi->charset)
g_free(pub->fi->charset);
pub->fi->charset = NULL;
pub->fi->charset_flag = FALSE;
pub->fi->lineend = LF;
undo_clear_all(pub->mw->buffer);
// set_main_window_title();
force_call_cb_modified_changed(pub->mw->view);
force_unblock_cb_modified_changed(pub->mw->view);
// undo_unblock_signal(textbuffer);
// undo_init(sd->mainwin->textview, textbuffer, sd->mainwin->menubar);
}
}
void on_file_quit(void)
{
if (!check_text_modification()) {
save_config_file();
gtk_main_quit();
}
}
void on_edit_undo(void)
{
undo_undo(pub->mw->buffer);
}
void on_edit_redo(void)
{
undo_redo(pub->mw->buffer);
}
void on_edit_cut(void)
{
g_signal_emit_by_name(G_OBJECT(pub->mw->view), "cut-clipboard");
}
void on_edit_copy(void)
{
g_signal_emit_by_name(G_OBJECT(pub->mw->view), "copy-clipboard");
}
void on_edit_paste(void)
{
g_signal_emit_by_name(G_OBJECT(pub->mw->view), "paste-clipboard");
// TODO: Use modify signal!!
/* gtk_text_view_scroll_mark_onscreen(
GTK_TEXT_VIEW(pub->mw->view),
gtk_text_buffer_get_insert(pub->mw->buffer));
*/}
void on_edit_delete(void)
{
gtk_text_buffer_delete_selection(pub->mw->buffer, TRUE, TRUE);
}
void on_edit_select_all(void)
{
set_selection_bound(pub->mw->buffer, 0, -1);
// g_signal_emit_by_name(G_OBJECT(pub->mw->view), "select-all");
}
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(
gtk_item_factory_get_widget(ifactory, "/Search/Find Next"),
TRUE);
gtk_widget_set_sensitive(
gtk_item_factory_get_widget(ifactory, "/Search/Find Previous"),
TRUE);
flag = TRUE;
}
}
void on_search_find(void)
{
if (run_dialog_search(pub->mw->view, 0) == GTK_RESPONSE_OK)
activate_quick_find();
}
void on_search_find_next(void)
{
document_search_real(pub->mw->view, 1);
}
void on_search_find_previous(void)
{
document_search_real(pub->mw->view, -1);
}
void on_search_replace(void)
{
if (run_dialog_search(pub->mw->view, 1) == GTK_RESPONSE_OK)
activate_quick_find();
}
void on_search_jump_to(void)
{
run_dialog_jump_to(pub->mw->view);
}
void on_option_font(void)
{
change_text_font_by_selector(pub->mw->view);
}
void on_duplicate_line(void)
{
duplicate_line(pub->mw->view);
}
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, "/Options/Word Wrap")));
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(pub->mw->view),
state ? GTK_WRAP_WORD : GTK_WRAP_NONE);
}
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, "/Options/Line Numbers")));
show_line_numbers(pub->mw->view, state);
}
void on_option_always_on_top(void)
{
#if GTK_CHECK_VERSION(2, 4, 0)
static gboolean flag = FALSE;
flag =! flag;
gtk_window_set_keep_above(GTK_WINDOW(pub->mw->window), flag);
#endif
}
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, "/Options/Auto Indent")));
indent_set_state(state);
}
void on_help_about(void)
{
const gchar *copyright = "Copyright \xc2\xa9 2004-2010 Tarot Osuji";
const gchar *comments = _("GTK+ based simple text editor"
"\nmodified by oluc and Samy Badjoudj");
const gchar *authors[] = {
"Tarot Osuji <[email protected]>",
"Samy Badjoudj <[email protected]>",
NULL
};
const gchar *translator_credits = _("translator-credits");
translator_credits = strcmp(translator_credits, "translator-credits")
? translator_credits : NULL;
#if GTK_CHECK_VERSION(2, 6, 0)
const gchar *artists[] = {
"Lapo Calamandrei <[email protected]>",
NULL
};
gtk_show_about_dialog(GTK_WINDOW(pub->mw->window),
// "name", PACKAGE_NAME,
"version", PACKAGE_VERSION,
"copyright", copyright,
"comments", comments,
"authors", authors,
"artists", artists,
"translator-credits", translator_credits,
"logo-icon-name", PACKAGE,
NULL);
#else
static GtkWidget *about = NULL;
if (about != NULL) {
gtk_window_present(GTK_WINDOW(about));
return;
}
const gchar *documenters[] = {
NULL
};
GdkPixbuf *logo = gdk_pixbuf_new_from_file(
ICONDIR G_DIR_SEPARATOR_S PACKAGE ".png", NULL);
about = create_about_dialog(
PACKAGE_NAME,
PACKAGE_VERSION,
copyright,
comments,
authors,
documenters,
translator_credits,
logo);
if (logo)
g_object_unref(logo);
gtk_window_set_transient_for(GTK_WINDOW(about),
GTK_WINDOW(pub->mw->window));
gtk_window_set_destroy_with_parent(GTK_WINDOW(about), TRUE);
g_signal_connect(G_OBJECT(about), "destroy",
G_CALLBACK(gtk_widget_destroyed), &about);
gtk_widget_show(about);
#endif
}
/* * Leafpad - 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 * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _CALLBACK_H #define _CALLBACK_H void on_file_new(void); void on_file_open(void); gint on_file_save(void); gint on_file_save_as(void); void on_file_reopen(void); void on_file_reload(void); void on_file_print_preview(void); void on_file_print(void); void on_file_close(void); void on_file_quit(void); void on_edit_undo(void); void on_edit_redo(void); void on_edit_cut(void); void on_edit_copy(void); void on_edit_paste(void); void on_edit_delete(void); void on_edit_select_all(void); void on_search_find(void); void on_search_find_next(void); void on_search_find_previous(void); void on_search_replace(void); void on_search_jump_to(void); void on_option_font(void); void on_duplicate_line(void); void on_option_word_wrap(void); void on_option_line_numbers(void); void on_option_always_on_top(void); void on_option_auto_indent(void); void on_help_about(void); #endif /* _CALLBACK_H */
/*
* Leafpad - GTK+ based simple text editor
* Copyright (C) 2004-2005 Tarot Osuji
*
* Feature added by Samy Badjoudj
*
* 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
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "leafpad.h"
#include "string.h"
void
duplicate_line (GtkWidget *textview)
{
GtkTextIter start, end;
GtkTextBuffer *textbuffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview));
GtkTextMark *cursor = gtk_text_buffer_get_insert (textbuffer);
gtk_text_buffer_get_iter_at_mark (textbuffer, &start, cursor);
gtk_text_buffer_get_iter_at_mark (textbuffer, &end, cursor);
gtk_text_iter_set_line_offset (&start, 0);
gtk_text_view_forward_display_line_end((GtkTextView *)textview,&end);
gchar *line = g_strconcat ("\n", gtk_text_buffer_get_text (textbuffer,
&start,
&end,
FALSE), NULL);
g_signal_emit_by_name (G_OBJECT (textbuffer),
"begin-user-action");
gtk_text_buffer_insert (textbuffer, &end, line,strlen(line));
g_signal_emit_by_name (G_OBJECT (textbuffer),
"end-user-action");
gtk_text_buffer_place_cursor (textbuffer, &end);
g_free(line);
}
/*
* Leafpad - GTK+ based simple text editor
* Copyright (C) 2004-2005 Tarot Osuji
*
* Feature added by Samy Badjoudj
*
* 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
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef EDITTEXTFEATURES_H
#define EDITTEXTFEATURES_H
void duplicate_line(GtkWidget *textview);
#endif /* EDITTEXTFEATURES_H */
/*
* Leafpad - 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
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _LEAFPAD_H
#define _LEAFPAD_H
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <gtk/gtk.h>
#include "i18n.h"
#ifndef ENABLE_PRINT
# if GTK_CHECK_VERSION(2, 10, 0)
# define ENABLE_PRINT
# endif
#endif
#include "edittextfeatures.h"
#include "window.h"
#include "menu.h"
#include "callback.h"
#include "view.h"
#include "undo.h"
#include "font.h"
#include "linenum.h"
#include "indent.h"
#include "hlight.h"
#include "selector.h"
#include "file.h"
#include "encoding.h"
#include "search.h"
#include "dialog.h"
#include "about.h"
#include "dnd.h"
#include "utils.h"
#include "emacs.h"
#ifdef ENABLE_PRINT
# if GTK_CHECK_VERSION(2, 10, 0)
# include "gtkprint.h"
# else
# include "gnomeprint.h"
# endif
#endif
typedef struct {
FileInfo *fi;
MainWin *mw;
} PublicData;
#ifdef GLOBAL_VARIABLE_DEFINE
# define GLOBAL
#else
# define GLOBAL extern
#endif
GLOBAL PublicData *pub;
void save_config_file(void);
#endif /* _LEAFPAD_H */
Makefile.am
Description: Binary data
/*
* Leafpad - 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
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "leafpad.h"
#include <gdk/gdkkeysyms.h>
static GtkWidget *menu_item_save;
static GtkWidget *menu_item_cut;
static GtkWidget *menu_item_copy;
static GtkWidget *menu_item_paste;
static GtkWidget *menu_item_delete;
static GtkItemFactoryEntry menu_items[] =
{
{ N_("/_File"), NULL,
NULL, 0, "<Branch>" },
{ N_("/File/_New"), "<control>N",
G_CALLBACK(on_file_new), 0, "<StockItem>", GTK_STOCK_NEW },
{ N_("/File/_Open..."), "<control>O",
G_CALLBACK(on_file_open), 0, "<StockItem>", GTK_STOCK_OPEN },
{ N_("/File/_Save"), "<control>S",
G_CALLBACK(on_file_save), 0, "<StockItem>", GTK_STOCK_SAVE },
{ N_("/File/Save _As..."), "<shift><control>S",
G_CALLBACK(on_file_save_as), 0, "<StockItem>", GTK_STOCK_SAVE_AS },
{ "/File/---", NULL,
NULL, 0, "<Separator>" },
{ N_("/File/_Re-open with..."), "<control>R",
G_CALLBACK(on_file_reopen), 0, "<StockItem>", GTK_STOCK_EXECUTE },
{ N_("/File/Re_load"), "<control>L",
G_CALLBACK(on_file_reload), 0, "<StockItem>", GTK_STOCK_REFRESH },
{ "/File/---", NULL,
NULL, 0, "<Separator>" },
#ifdef ENABLE_PRINT
# if GTK_CHECK_VERSION(2, 10, 0)
{ N_("/File/Print Pre_view"), "<shift><control>P",
G_CALLBACK(on_file_print_preview), 0, "<StockItem>", GTK_STOCK_PRINT_PREVIEW },
# endif
{ N_("/File/_Print..."), "<control>P",
G_CALLBACK(on_file_print), 0, "<StockItem>", GTK_STOCK_PRINT },
# if GTK_CHECK_VERSION(2, 10, 0)
{ "/File/---", NULL,
NULL, 0, "<Separator>" },
# endif
#endif
{ N_("/File/_Quit"), "<control>Q",
G_CALLBACK(on_file_quit), 0, "<StockItem>", GTK_STOCK_QUIT },
{ N_("/_Edit"), NULL,
NULL, 0, "<Branch>" },
{ N_("/Edit/_Undo"), "<control>Z",
G_CALLBACK(on_edit_undo), 0, "<StockItem>", GTK_STOCK_UNDO },
{ N_("/Edit/_Redo"), "<shift><control>Z",
G_CALLBACK(on_edit_redo), 0, "<StockItem>", GTK_STOCK_REDO },
{ "/Edit/---", NULL,
NULL, 0, "<Separator>" },
{ N_("/Edit/Cu_t"), "<control>X",
G_CALLBACK(on_edit_cut), 0, "<StockItem>", GTK_STOCK_CUT },
{ N_("/Edit/_Copy"), "<control>C",
G_CALLBACK(on_edit_copy), 0, "<StockItem>", GTK_STOCK_COPY },
{ N_("/Edit/_Paste"), "<control>V",
G_CALLBACK(on_edit_paste), 0, "<StockItem>", GTK_STOCK_PASTE },
{ N_("/Edit/_Delete"), NULL,
G_CALLBACK(on_edit_delete), 0, "<StockItem>", GTK_STOCK_DELETE },
{ "/Edit/---", NULL,
NULL, 0, "<Separator>" },
{ N_("/Edit/Select _All"), "<control>A",
G_CALLBACK(on_edit_select_all), 0 },
{ "/Edit/---", NULL,
NULL, 0, "<Separator>" },
{ N_("/Edit/D_uplicate Line"), "<control>D",
G_CALLBACK(on_duplicate_line), 0 },
{ N_("/_Search"), NULL,
NULL, 0, "<Branch>" },
{ N_("/Search/_Find..."), "<control>F",
G_CALLBACK(on_search_find), 0, "<StockItem>", GTK_STOCK_FIND },
{ N_("/Search/Find _Next"), "<control>G",
G_CALLBACK(on_search_find_next), 0 },
{ N_("/Search/Find _Previous"), "<shift><control>G",
G_CALLBACK(on_search_find_previous), 0 },
{ N_("/Search/_Replace..."), "<control>H",
G_CALLBACK(on_search_replace), 0, "<StockItem>", GTK_STOCK_FIND_AND_REPLACE },
{ "/Search/---", NULL,
NULL, 0, "<Separator>" },
{ N_("/Search/_Jump To..."), "<control>J",
G_CALLBACK(on_search_jump_to), 0, "<StockItem>", GTK_STOCK_JUMP_TO },
{ N_("/_Options"), NULL,
NULL, 0, "<Branch>" },
{ N_("/Options/_Font..."), NULL,
G_CALLBACK(on_option_font), 0, "<StockItem>", GTK_STOCK_SELECT_FONT },
{ N_("/Options/_Word Wrap"), NULL,
G_CALLBACK(on_option_word_wrap), 0, "<CheckItem>" },
{ N_("/Options/_Line Numbers"), NULL,
G_CALLBACK(on_option_line_numbers), 0, "<CheckItem>" },
{ "/Options/---", NULL,
NULL, 0, "<Separator>" },
{ N_("/Options/_Auto Indent"), NULL,
G_CALLBACK(on_option_auto_indent), 0, "<CheckItem>" },
{ N_("/_Help"), NULL,
NULL, 0, "<Branch>" },
{ N_("/Help/_About"), NULL,
#if GTK_CHECK_VERSION(2, 6, 0)
G_CALLBACK(on_help_about), 0, "<StockItem>", GTK_STOCK_ABOUT },
#else
G_CALLBACK(on_help_about), 0, "<StockItem>", "my-gtk-about" },
#endif
};
static gint nmenu_items = sizeof(menu_items) / sizeof(GtkItemFactoryEntry);
static gchar *menu_translate(const gchar *path, gpointer data)
{
gchar *str;
str = (gchar *)_(path);
return str;
}
void menu_sensitivity_from_modified_flag(gboolean is_text_modified)
{
gtk_widget_set_sensitive(menu_item_save, is_text_modified);
}
void menu_sensitivity_from_selection_bound(gboolean is_bound_exist)
{
gtk_widget_set_sensitive(menu_item_cut, is_bound_exist);
gtk_widget_set_sensitive(menu_item_copy, is_bound_exist);
gtk_widget_set_sensitive(menu_item_delete, is_bound_exist);
}
//void menu_sensitivity_from_clipboard(gboolean is_clipboard_exist)
void menu_sensitivity_from_clipboard(void)
{
//g_print("clip board checked.\n");
gtk_widget_set_sensitive(menu_item_paste,
gtk_clipboard_wait_is_text_available(
gtk_clipboard_get(GDK_SELECTION_CLIPBOARD)));
}
GtkWidget *create_menu_bar(GtkWidget *window)
{
GtkAccelGroup *accel_group;
GtkItemFactory *ifactory;
gboolean flag_emacs = FALSE;
gchar *key_theme = NULL;
GtkSettings *settings = gtk_settings_get_default();
if (settings) {
g_object_get(settings, "gtk-key-theme-name", &key_theme, NULL);
if (key_theme) {
if (!g_ascii_strcasecmp(key_theme, "Emacs"))
flag_emacs = TRUE;
g_free(key_theme);
}
}
accel_group = gtk_accel_group_new();
ifactory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<main>", accel_group);
gtk_item_factory_set_translate_func(ifactory, menu_translate, NULL, NULL);
gtk_item_factory_create_items(ifactory, nmenu_items, menu_items, 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,
g_cclosure_new_swap(G_CALLBACK(on_file_close), NULL, NULL));
gtk_accel_group_connect(
accel_group, GDK_T, GDK_CONTROL_MASK, 0,
g_cclosure_new_swap(G_CALLBACK(on_option_always_on_top), NULL, NULL));
gtk_widget_add_accelerator(
gtk_item_factory_get_widget(ifactory, "/Edit/Redo"),
"activate", accel_group, GDK_Y, GDK_CONTROL_MASK, 0);
gtk_widget_add_accelerator(
gtk_item_factory_get_widget(ifactory, "/Search/Find Next"),
"activate", accel_group, GDK_F3, 0, 0);
gtk_widget_add_accelerator(
gtk_item_factory_get_widget(ifactory, "/Search/Find Previous"),
"activate", accel_group, GDK_F3, GDK_SHIFT_MASK, 0);
gtk_widget_add_accelerator(
gtk_item_factory_get_widget(ifactory, "/Search/Replace..."),
"activate", accel_group, GDK_R, GDK_CONTROL_MASK, 0);
/* initialize sensitivities */
gtk_widget_set_sensitive(
gtk_item_factory_get_widget(ifactory, "/Search/Find Next"),
FALSE);
gtk_widget_set_sensitive(
gtk_item_factory_get_widget(ifactory, "/Search/Find Previous"),
FALSE);
menu_item_save = gtk_item_factory_get_widget(ifactory, "/File/Save");
menu_item_cut = gtk_item_factory_get_widget(ifactory, "/Edit/Cut");
menu_item_copy = gtk_item_factory_get_widget(ifactory, "/Edit/Copy");
menu_item_paste = gtk_item_factory_get_widget(ifactory, "/Edit/Paste");
menu_item_delete = gtk_item_factory_get_widget(ifactory, "/Edit/Delete");
menu_sensitivity_from_selection_bound(FALSE);
return gtk_item_factory_get_widget(ifactory, "<main>");
}
-- Ubuntu-motu mailing list [email protected] Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-motu
