~ubuntu-branches/ubuntu/wily/geany/wily

« back to all changes in this revision

Viewing changes to plugins/splitwindow.c

  • Committer: Package Import Robot
  • Author(s): Chow Loong Jin
  • Date: 2011-12-10 07:43:26 UTC
  • mfrom: (3.3.7 sid)
  • Revision ID: package-import@ubuntu.com-20111210074326-s8yqbew5i20h33tf
Tags: 0.21-1ubuntu1
* Merge from Debian Unstable, remaining changes:
  - debian/patches/20_use_evince_viewer.patch:
     + use evince as viewer for pdf and dvi files
  - debian/patches/20_use_x_terminal_emulator.patch:
     + use x-terminal-emulator as terminal
  - debian/control
     + Add breaks on geany-plugins-common << 0.20
* Also fixes bugs:
  - Filter for MATLAB/Octave files filters everythign (LP: 885505)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 *      splitwindow.c - this file is part of Geany, a fast and lightweight IDE
3
3
 *
4
 
 *      Copyright 2008-2010 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
5
 
 *      Copyright 2008-2010 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
 
4
 *      Copyright 2008-2011 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
 
5
 *      Copyright 2008-2011 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
6
6
 *
7
7
 *      This program is free software; you can redistribute it and/or modify
8
8
 *      it under the terms of the GNU General Public License as published by
19
19
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
20
 *      MA 02110-1301, USA.
21
21
 *
22
 
 * $Id: splitwindow.c 5351 2010-11-02 12:49:05Z ntrel $
 
22
 * $Id: splitwindow.c 5882 2011-08-03 15:20:26Z colombanw $
23
23
 */
24
24
 
25
25
/* Split Window plugin. */
26
26
 
 
27
#ifdef HAVE_CONFIG_H
 
28
#       include "config.h"
 
29
#endif
 
30
 
27
31
#include "geanyplugin.h"
28
32
#include <string.h>
29
33
 
73
77
        ScintillaObject *sci;           /* new editor widget */
74
78
        GtkWidget               *vbox;
75
79
        GtkWidget               *name_label;
 
80
        gint                    handler_id;
76
81
}
77
82
EditWindow;
78
83
 
79
 
static EditWindow edit_window = {NULL, NULL, NULL, NULL};
 
84
static EditWindow edit_window = {NULL, NULL, NULL, NULL, 0 };
80
85
 
81
86
 
82
87
static void on_unsplit(GtkMenuItem *menuitem, gpointer user_data);
103
108
}
104
109
 
105
110
 
 
111
static void on_sci_notify (ScintillaObject *sci, gint param, SCNotification *notif, gpointer data)
 
112
{
 
113
        gint line;
 
114
 
 
115
        switch (notif->nmhdr.code)
 
116
        {
 
117
                case SCN_MARGINCLICK:
 
118
                        if (notif->margin == 2)
 
119
                        {
 
120
                                line = sci_get_line_from_position(sci, notif->position);
 
121
                                scintilla_send_message(sci, SCI_TOGGLEFOLD, line, 0);
 
122
                        }
 
123
                        break;
 
124
 
 
125
                default: break;
 
126
        }
 
127
}
 
128
 
 
129
 
106
130
static void sync_to_current(ScintillaObject *sci, ScintillaObject *current)
107
131
{
108
132
        gpointer sdoc;
119
143
        /* override some defaults */
120
144
        set_line_numbers(sci, geany->editor_prefs->show_linenumber_margin);
121
145
        scintilla_send_message(sci, SCI_SETMARGINWIDTHN, 1, 0 ); /* hide marker margin (no commands) */
122
 
        scintilla_send_message(sci, SCI_SETMARGINWIDTHN, 2, 0 ); /* hide fold margin (no toggle callback) */
123
146
}
124
147
 
125
148
 
127
150
{
128
151
        editwin->editor = editor;
129
152
 
 
153
        if (editwin->handler_id > 0 && editwin->sci != NULL)
 
154
        {
 
155
                g_signal_handler_disconnect(editwin->sci, editwin->handler_id);
 
156
                editwin->handler_id = 0;
 
157
        }
 
158
 
130
159
        /* first destroy any widget, otherwise its signals will have an
131
160
         * invalid document as user_data */
132
161
        if (editwin->sci != NULL)
138
167
 
139
168
        sync_to_current(editwin->sci, editor->sci);
140
169
 
 
170
        if (geany->editor_prefs->folding)
 
171
                editwin->handler_id = g_signal_connect(editwin->sci, "sci-notify",
 
172
                                G_CALLBACK(on_sci_notify), NULL);
 
173
        else
 
174
                scintilla_send_message(editwin->sci, SCI_SETMARGINWIDTHN, 2, 0);
 
175
 
141
176
        gtk_label_set_text(GTK_LABEL(editwin->name_label), DOC_FILENAME(editor->document));
142
177
}
143
178
 
174
209
static GtkWidget *ui_tool_button_new(const gchar *stock_id, const gchar *label, const gchar *tooltip)
175
210
{
176
211
        GtkToolItem *item;
177
 
        gchar *dup = NULL;
 
212
        gchar *dupl = NULL;
178
213
 
179
214
        if (stock_id && !label)
180
215
        {
181
216
                label = ui_get_stock_label(stock_id);
182
217
        }
183
 
        dup = utils_str_remove_chars(g_strdup(label), "_");
184
 
        label = dup;
 
218
        dupl = utils_str_remove_chars(g_strdup(label), "_");
 
219
        label = dupl;
185
220
 
186
221
        item = gtk_tool_button_new(NULL, label);
187
222
        if (stock_id)
190
225
        if (!tooltip)
191
226
                tooltip = label;
192
227
        if (tooltip)
193
 
                ui_widget_set_tooltip_text(GTK_WIDGET(item), tooltip);
 
228
                gtk_widget_set_tooltip_text(GTK_WIDGET(item), tooltip);
194
229
 
195
 
        g_free(dup);
 
230
        g_free(dupl);
196
231
        return GTK_WIDGET(item);
197
232
}
198
233
 
237
272
        tool_item = gtk_menu_tool_button_new(NULL, NULL);
238
273
        gtk_tool_button_set_stock_id(GTK_TOOL_BUTTON(tool_item), GTK_STOCK_JUMP_TO);
239
274
        item = (GtkWidget*)tool_item;
240
 
        ui_widget_set_tooltip_text(item, _("Show the current document"));
 
275
        gtk_widget_set_tooltip_text(item, _("Show the current document"));
241
276
        gtk_container_add(GTK_CONTAINER(toolbar), item);
242
277
        g_signal_connect(item, "clicked", G_CALLBACK(on_refresh), NULL);
243
278
 
276
311
 
277
312
        set_state(horizontal ? STATE_SPLIT_HORIZONTAL : STATE_SPLIT_VERTICAL);
278
313
 
279
 
        /* temporarily put document notebook in main vbox (scintilla widgets must stay
280
 
         * in a visible parent window, otherwise there are X selection and scrollbar issues) */
281
 
        gtk_widget_reparent(notebook,
282
 
                ui_lookup_widget(geany->main_widgets->window, "vbox1"));
 
314
        gtk_widget_ref(notebook);
 
315
        gtk_container_remove(GTK_CONTAINER(parent), notebook);
283
316
 
284
317
        pane = horizontal ? gtk_hpaned_new() : gtk_vpaned_new();
285
318
        gtk_container_add(GTK_CONTAINER(parent), pane);
286
 
        gtk_widget_reparent(notebook, pane);
 
319
 
 
320
        gtk_container_add(GTK_CONTAINER(pane), notebook);
 
321
        gtk_widget_unref(notebook);
287
322
 
288
323
        box = gtk_vbox_new(FALSE, 0);
289
324
        toolbar = create_toolbar();
327
362
 
328
363
        g_return_if_fail(edit_window.editor);
329
364
 
330
 
        /* temporarily put document notebook in main vbox (scintilla widgets must stay
331
 
         * in a visible parent window, otherwise there are X selection and scrollbar issues) */
332
 
        gtk_widget_reparent(notebook,
333
 
                ui_lookup_widget(geany->main_widgets->window, "vbox1"));
 
365
        gtk_widget_ref(notebook);
 
366
        gtk_container_remove(GTK_CONTAINER(pane), notebook);
 
367
 
 
368
        if (edit_window.sci != NULL && edit_window.handler_id > 0)
 
369
        {
 
370
                g_signal_handler_disconnect(edit_window.sci, edit_window.handler_id);
 
371
                edit_window.handler_id = 0;
 
372
        }
334
373
 
335
374
        gtk_widget_destroy(pane);
336
375
        edit_window.editor = NULL;
337
376
        edit_window.sci = NULL;
338
 
        gtk_widget_reparent(notebook, parent);
 
377
 
 
378
        gtk_container_add(GTK_CONTAINER(parent), notebook);
 
379
        gtk_widget_unref(notebook);
339
380
}
340
381
 
341
382
 
372
413
        gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_items.main), menu);
373
414
 
374
415
        menu_items.horizontal = item =
375
 
                gtk_menu_item_new_with_mnemonic(_("_Horizontally"));
 
416
                gtk_menu_item_new_with_mnemonic(_("_Side by Side"));
376
417
        g_signal_connect(item, "activate", G_CALLBACK(on_split_horizontally), NULL);
377
418
        gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
378
419
 
379
420
        menu_items.vertical = item =
380
 
                gtk_menu_item_new_with_mnemonic(_("_Vertically"));
 
421
                gtk_menu_item_new_with_mnemonic(_("_Top and Bottom"));
381
422
        g_signal_connect(item, "activate", G_CALLBACK(on_split_vertically), NULL);
382
423
        gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
383
424
 
401
442
}
402
443
 
403
444
 
 
445
static gboolean do_select_current(gpointer data)
 
446
{
 
447
        GeanyDocument *doc;
 
448
 
 
449
        /* guard out for the unlikely case we get called after another unsplitting */
 
450
        if (plugin_state == STATE_UNSPLIT)
 
451
                return FALSE;
 
452
 
 
453
        doc = document_get_current();
 
454
        if (doc)
 
455
                set_editor(&edit_window, doc->editor);
 
456
        else
 
457
                on_unsplit(NULL, NULL);
 
458
 
 
459
        return FALSE;
 
460
}
 
461
 
 
462
 
404
463
static void on_document_close(GObject *obj, GeanyDocument *doc, gpointer user_data)
405
464
{
406
 
    /* remove the split window because the document won't exist anymore */
407
465
        if (doc->editor == edit_window.editor)
408
 
                on_unsplit(NULL, NULL);
 
466
        {
 
467
                /* select current or unsplit in IDLE time, so the tab has changed */
 
468
                plugin_idle_add(geany_plugin, do_select_current, NULL);
 
469
        }
409
470
}
410
471
 
411
472
 
417
478
}
418
479
 
419
480
 
 
481
static void on_document_filetype_set(GObject *obj, GeanyDocument *doc,
 
482
        GeanyFiletype *filetype_old, gpointer user_data)
 
483
{
 
484
        /* update styles */
 
485
        if (edit_window.editor == doc->editor)
 
486
                sync_to_current(edit_window.sci, doc->editor->sci);
 
487
}
 
488
 
 
489
 
420
490
PluginCallback plugin_callbacks[] =
421
491
{
422
 
    { "document-close", (GCallback) &on_document_close, FALSE, NULL },
423
 
    { "document-save", (GCallback) &on_document_save, FALSE, NULL },
424
 
    { NULL, NULL, FALSE, NULL }
 
492
        { "document-close", (GCallback) &on_document_close, FALSE, NULL },
 
493
        { "document-save", (GCallback) &on_document_save, FALSE, NULL },
 
494
        { "document-filetype-set", (GCallback) &on_document_filetype_set, FALSE, NULL },
 
495
        { NULL, NULL, FALSE, NULL }
425
496
};
426
497
 
427
498