~ubuntu-branches/ubuntu/hoary/gedit/hoary-security

« back to all changes in this revision

Viewing changes to gedit/dialogs/gedit-dialog-uri.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2004-10-10 21:24:57 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20041010212457-f7q85htgynmslwf4
Tags: 2.8.1-0ubuntu1
* New upstream release:
  - do not try to open non regular files.
  - allow opening file by drag and drop on read only documents.
  - open dropped files in the right target gedit window.
  - do not change active document when closing an unmodified tab.
  - fix crash when trying to open an invalid sftp uri.
* debian/patches/01_relibtoolise.patch:
  - removed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 
2
/*
 
3
 * gedit-dialog-uri.c
 
4
 * This file is part of gedit
 
5
 *
 
6
 * Copyright (C) 2001 Paolo Maggi 
 
7
 *
 
8
 * This program is free software; you can redistribute it and/or modify
 
9
 * it under the terms of the GNU General Public License as published by
 
10
 * the Free Software Foundation; either version 2 of the License, or
 
11
 * (at your option) any later version.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 * GNU General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public License
 
19
 * along with this program; if not, write to the Free Software
 
20
 * Foundation, Inc., 59 Temple Place, Suite 330, 
 
21
 * Boston, MA 02111-1307, USA. 
 
22
 */
 
23
 
 
24
/*
 
25
 * Modified by the gedit Team, 1998-2001. See the AUTHORS file for a 
 
26
 * list of people on the gedit Team.  
 
27
 * See the ChangeLog files for a list of changes. 
 
28
 */
 
29
 
 
30
#ifdef HAVE_CONFIG_H
 
31
#include <config.h>
 
32
#endif
 
33
 
 
34
#include <glade/glade-xml.h>
 
35
#include <libgnome/gnome-help.h>
 
36
#include <libgnome/gnome-i18n.h>
 
37
#include <libgnomeui/gnome-entry.h>
 
38
 
 
39
#include "gedit2.h"
 
40
#include "gedit-mdi.h"
 
41
#include "gedit-utils.h"
 
42
#include "gedit-file.h"
 
43
#include "gedit-dialogs.h"
 
44
#include "gedit-encodings-option-menu.h"
 
45
 
 
46
typedef struct _GeditDialogOpenUri GeditDialogOpenUri;
 
47
 
 
48
struct _GeditDialogOpenUri {
 
49
        GtkWidget *dialog;
 
50
 
 
51
        GtkWidget *uri;
 
52
        GtkWidget *uri_list;
 
53
        GtkWidget *encoding_menu;
 
54
};
 
55
 
 
56
static void open_button_pressed (GeditDialogOpenUri * dialog);
 
57
static void help_button_pressed (GeditDialogOpenUri * dialog);
 
58
static GeditDialogOpenUri *dialog_open_uri_get_dialog (void);
 
59
 
 
60
static GeditDialogOpenUri *
 
61
dialog_open_uri_get_dialog (void)
 
62
{
 
63
        static GeditDialogOpenUri *dialog = NULL;
 
64
        GladeXML *gui;
 
65
        GtkWindow *window;
 
66
        GtkWidget *content;
 
67
        GtkWidget *encoding_label;
 
68
        GtkWidget *encoding_hbox;
 
69
        
 
70
        window = GTK_WINDOW (gedit_get_active_window ());
 
71
 
 
72
        if (dialog != NULL)
 
73
        {
 
74
                gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog),
 
75
                                              GTK_WINDOW (window));
 
76
                return dialog;
 
77
        }
 
78
 
 
79
        gui = glade_xml_new (GEDIT_GLADEDIR "uri.glade2",
 
80
                             "open_uri_dialog_content", NULL);
 
81
        if (!gui)
 
82
        {
 
83
                gedit_warning (window,
 
84
                               MISSING_FILE,
 
85
                               GEDIT_GLADEDIR "uri.glade2");
 
86
                return NULL;
 
87
        }
 
88
 
 
89
        dialog = g_new0 (GeditDialogOpenUri, 1);
 
90
 
 
91
        dialog->dialog = gtk_dialog_new_with_buttons (_("Open Location"),
 
92
                                                      window,
 
93
                                                      GTK_DIALOG_MODAL,
 
94
                                                      GTK_STOCK_CANCEL,
 
95
                                                      GTK_RESPONSE_CANCEL,
 
96
                                                      GTK_STOCK_OPEN,
 
97
                                                      GTK_RESPONSE_OK,
 
98
                                                      GTK_STOCK_HELP,
 
99
                                                      GTK_RESPONSE_HELP,
 
100
                                                      NULL);
 
101
 
 
102
        g_return_val_if_fail (dialog->dialog != NULL, NULL);
 
103
 
 
104
        gtk_window_set_resizable (GTK_WINDOW (dialog->dialog), FALSE);
 
105
        gtk_dialog_set_has_separator (GTK_DIALOG (dialog->dialog), FALSE);
 
106
 
 
107
        content = glade_xml_get_widget (gui, "open_uri_dialog_content");
 
108
 
 
109
        dialog->uri = glade_xml_get_widget (gui, "uri");
 
110
        dialog->uri_list = glade_xml_get_widget (gui, "uri_list");
 
111
        encoding_label = glade_xml_get_widget (gui, "encoding_label");
 
112
        encoding_hbox = glade_xml_get_widget (gui, "encoding_hbox");
 
113
        
 
114
        if (!dialog->uri || !dialog->uri_list || !encoding_label || !encoding_hbox) 
 
115
        {
 
116
                gedit_warning (window,
 
117
                               MISSING_WIDGETS,
 
118
                               GEDIT_GLADEDIR "uri.glade2");
 
119
                return NULL;
 
120
        }
 
121
 
 
122
        dialog->encoding_menu = gedit_encodings_option_menu_new (FALSE);
 
123
 
 
124
        gtk_label_set_mnemonic_widget (GTK_LABEL (encoding_label),
 
125
                                       dialog->encoding_menu);
 
126
 
 
127
        gtk_box_pack_end (GTK_BOX (encoding_hbox), 
 
128
                          dialog->encoding_menu,
 
129
                          TRUE,
 
130
                          TRUE,
 
131
                          0);
 
132
 
 
133
        gtk_widget_show (dialog->encoding_menu);
 
134
 
 
135
        gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog->dialog)->vbox),
 
136
                            content, FALSE, FALSE, 0);
 
137
 
 
138
        gtk_dialog_set_default_response (GTK_DIALOG (dialog->dialog),
 
139
                                         GTK_RESPONSE_OK);
 
140
 
 
141
        g_object_unref (gui);
 
142
 
 
143
        return dialog;
 
144
}
 
145
 
 
146
void
 
147
gedit_dialog_open_uri (void)
 
148
{
 
149
        GeditDialogOpenUri *dialog;
 
150
        gint response;
 
151
 
 
152
        dialog = dialog_open_uri_get_dialog ();
 
153
        if (!dialog)
 
154
                return;
 
155
 
 
156
        gedit_encodings_option_menu_set_selected_encoding (
 
157
                GEDIT_ENCODINGS_OPTION_MENU (dialog->encoding_menu),
 
158
                NULL);  
 
159
 
 
160
        gtk_widget_grab_focus (dialog->uri);
 
161
 
 
162
        gtk_entry_set_text (GTK_ENTRY (dialog->uri), "");
 
163
 
 
164
        do {
 
165
                response = gtk_dialog_run (GTK_DIALOG (dialog->dialog));
 
166
 
 
167
                switch (response) {
 
168
                case GTK_RESPONSE_OK:
 
169
                        open_button_pressed (dialog);
 
170
                        break;
 
171
 
 
172
                case GTK_RESPONSE_HELP:
 
173
                        help_button_pressed (dialog);
 
174
                        break;
 
175
 
 
176
                default:
 
177
                        gtk_widget_hide (dialog->dialog);
 
178
                }
 
179
 
 
180
        } while (response == GTK_RESPONSE_HELP);
 
181
}
 
182
 
 
183
static void
 
184
open_button_pressed (GeditDialogOpenUri * dialog)
 
185
{
 
186
        gchar *file_name = NULL;
 
187
        const GeditEncoding *encoding;
 
188
        
 
189
        g_return_if_fail (dialog != NULL);
 
190
 
 
191
        file_name =
 
192
            gtk_editable_get_chars (GTK_EDITABLE (dialog->uri), 0, -1);
 
193
 
 
194
        gnome_entry_prepend_history (GNOME_ENTRY (dialog->uri_list), 
 
195
                                     TRUE,
 
196
                                     file_name);
 
197
 
 
198
        gtk_widget_hide (dialog->dialog);
 
199
 
 
200
        encoding = gedit_encodings_option_menu_get_selected_encoding (
 
201
                        GEDIT_ENCODINGS_OPTION_MENU (dialog->encoding_menu));
 
202
        
 
203
        gedit_file_open_single_uri (file_name, encoding);
 
204
 
 
205
        g_free (file_name);
 
206
}
 
207
 
 
208
static void
 
209
help_button_pressed (GeditDialogOpenUri * dialog)
 
210
{
 
211
        GError *error = NULL;
 
212
 
 
213
        gnome_help_display ("gedit.xml", "gedit-open-from-uri", &error);
 
214
        
 
215
        if (error != NULL)
 
216
        {
 
217
                g_warning (error->message);
 
218
 
 
219
                g_error_free (error);
 
220
        }
 
221
 
 
222
}