1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
/*
* Dr Genius an interactive geometry software
* (C) Copyright Hilaire Fernandes 2003
* hilaire@ofset.org
*
*
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public Licences as by published
* by the Free Software Foundation; either version 2; or (at your option)
* any later version
*
* This program is distributed in the hope that it will entertaining,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILTY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Publis 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.
* 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <gtk/gtk.h>
#include <errno.h>
#include <libintl.h>
#include "drgeo_gtkhelpers.h"
#include "drgenius_config.h"
#include "drgenius_mdi.h"
#define _(x) gettext (x)
#define N_(x) x
extern drgeniusMDI* mdi;
gchar *
gtk_text_view_get_text (GtkTextView *view)
{
GtkTextBuffer *description;
GtkTextIter start, end;
description = gtk_text_view_get_buffer (view);
gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (description),
&start);
gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (description),
&end);
return gtk_text_buffer_get_text (GTK_TEXT_BUFFER (description),
&start, &end, false);
}
void
gtk_text_view_clear (GtkTextView *view)
{
GtkTextBuffer *description;
GtkTextIter start, end;
description = gtk_text_view_get_buffer (view);
gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (description),
&start);
gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (description),
&end);
gtk_text_buffer_delete (GTK_TEXT_BUFFER (description),
&start, &end);
}
void
gtk_text_view_set_text (GtkTextView *view, gchar *text)
{
GtkTextBuffer *description;
gtk_text_view_clear (view);
description = gtk_text_view_get_buffer (view);
gtk_text_buffer_set_text (description, (const gchar *) text, -1);
}
gint
open_help_cb (GtkWidget *widget, const char *url)
{
gchar *str;
static gchar *lang = NULL;
GtkWidget *d;
// Fixme write this
if (lang == NULL)
{
lang = g_strndup (pango_language_to_string(gtk_get_default_language ())
, 2);
str = g_strconcat(DRGEO_HELPDIR, "/", lang, NULL);
if (!g_file_test (str, G_FILE_TEST_EXISTS))
{
d = gtk_message_dialog_new (mdi->mainWindow (),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
_("This help directory does not exist:\n'%s'\nMaybe the manual is not installed or it is not yet translated in your language.\n\nIf you want to translate the manual contact ofset@ofset.org."),
str, g_strerror (errno));
gtk_dialog_run (GTK_DIALOG (d));
gtk_widget_destroy (d);
g_free (lang);
g_free (str);
// Try to find the default one in C
str = g_strconcat (DRGEO_HELPDIR, "/c", NULL);
if (g_file_test (str, G_FILE_TEST_EXISTS))
{
d = gtk_message_dialog_new (mdi->mainWindow (),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_WARNING,
GTK_BUTTONS_CLOSE,
_("A default online manual\nin English will be used."),
g_strerror (errno));
gtk_dialog_run (GTK_DIALOG (d));
gtk_widget_destroy (d);
lang = g_strdup ("c");
}
else
{
d = gtk_message_dialog_new (mdi->mainWindow (),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_WARNING,
GTK_BUTTONS_CLOSE,
_("No default online manual can be found."),
g_strerror (errno));
gtk_dialog_run (GTK_DIALOG (d));
gtk_widget_destroy (d);
lang = NULL;
return false;
}
}
g_free (str);
}
str = g_strconcat (drgeoConfigGet(":htmlViewer"), " ",
DRGEO_HELPDIR, "/", lang, "/", url, NULL);
g_spawn_command_line_async ((const gchar *) str,
NULL);
g_free (str);
return true;
}
void
gtk_menu_append_label (GtkMenu *menu, const gchar *textItem)
{
GtkWidget *menuItem;
menuItem = gtk_menu_item_new_with_label (textItem);
gtk_widget_show (menuItem);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuItem);
}
|