geany  1.38
About: Geany is a text editor (using GTK2) with basic features of an integrated development environment (syntax highlighting, code folding, symbol name auto-completion, ...). F: office T: editor programming GTK+ IDE
  Fossies Dox: geany-1.38.tar.bz2  ("unofficial" and yet experimental doxygen-generated source code documentation)  

notebook.c
Go to the documentation of this file.
1/*
2 * notebook.c - this file is part of Geany, a fast and lightweight IDE
3 *
4 * Copyright 2006 The Geany contributors
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21/*
22 * Notebook tab Drag 'n' Drop reordering and tab management.
23 */
24
25#ifdef HAVE_CONFIG_H
26# include "config.h"
27#endif
28
29#include "notebook.h"
30
31#include "callbacks.h"
32#include "documentprivate.h"
33#include "geanyobject.h"
34#include "keybindings.h"
35#include "main.h"
36#include "support.h"
37#include "ui_utils.h"
38#include "utils.h"
39
40#include <gtk/gtk.h>
41#include <gdk/gdkkeysyms.h>
42
43
44#define GEANY_DND_NOTEBOOK_TAB_TYPE "geany_dnd_notebook_tab"
45
46static const GtkTargetEntry drag_targets[] =
47{
48 {GEANY_DND_NOTEBOOK_TAB_TYPE, GTK_TARGET_SAME_APP | GTK_TARGET_SAME_WIDGET, 0}
49};
50
51static GtkTargetEntry files_drop_targets[] = {
52 { "STRING", 0, 0 },
53 { "UTF8_STRING", 0, 0 },
54 { "text/plain", 0, 0 },
55 { "text/uri-list", 0, 0 }
56};
57
58static const gsize MAX_MRU_DOCS = 20;
59static GQueue *mru_docs = NULL;
60static guint mru_pos = 0;
61
62static gboolean switch_in_progress = FALSE;
63static GtkWidget *switch_dialog = NULL;
64static GtkWidget *switch_dialog_label = NULL;
65
66
67static void
68notebook_page_reordered_cb(GtkNotebook *notebook, GtkWidget *child, guint page_num,
69 gpointer user_data);
70
71static void
72on_window_drag_data_received(GtkWidget *widget, GdkDragContext *drag_context,
73 gint x, gint y, GtkSelectionData *data, guint target_type,
74 guint event_time, gpointer user_data);
75
76static void
77notebook_tab_close_clicked_cb(GtkButton *button, gpointer user_data);
78
79static void setup_tab_dnd(void);
80
81
83{
84 if (doc)
85 {
86 g_queue_remove(mru_docs, doc);
87 g_queue_push_head(mru_docs, doc);
88
89 if (g_queue_get_length(mru_docs) > MAX_MRU_DOCS)
90 g_queue_pop_tail(mru_docs);
91 }
92}
93
94
95/* before the tab changes, add the current document to the MRU list */
96static void on_notebook_switch_page(GtkNotebook *notebook,
97 gpointer page, guint page_num, gpointer user_data)
98{
99 GeanyDocument *new;
100
101 new = document_get_from_page(page_num);
102
103 /* insert the very first document (when adding the second document
104 * and switching to it) */
105 if (g_queue_get_length(mru_docs) == 0 && gtk_notebook_get_n_pages(notebook) == 2)
107
110}
111
112
113static void on_document_close(GObject *obj, GeanyDocument *doc)
114{
115 if (! main_status.quitting)
116 {
117 g_queue_remove(mru_docs, doc);
118 /* this prevents the pop up window from showing when there's a single
119 * document */
120 if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)) == 2)
121 g_queue_clear(mru_docs);
122 }
123}
124
125
126static GtkWidget *ui_minimal_dialog_new(GtkWindow *parent, const gchar *title)
127{
128 GtkWidget *dialog;
129
130 dialog = gtk_window_new(GTK_WINDOW_POPUP);
131
132 if (parent)
133 {
134 gtk_window_set_transient_for(GTK_WINDOW(dialog), parent);
135 gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE);
136 }
137 gtk_window_set_title(GTK_WINDOW(dialog), title);
138 gtk_window_set_type_hint(GTK_WINDOW(dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
139 gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER_ON_PARENT);
140
141 gtk_widget_set_name(dialog, "GeanyDialog");
142 return dialog;
143}
144
145
146static gboolean is_modifier_key(guint keyval)
147{
148 switch (keyval)
149 {
150 case GDK_KEY_Shift_L:
151 case GDK_KEY_Shift_R:
152 case GDK_KEY_Control_L:
153 case GDK_KEY_Control_R:
154 case GDK_KEY_Meta_L:
155 case GDK_KEY_Meta_R:
156 case GDK_KEY_Alt_L:
157 case GDK_KEY_Alt_R:
158 case GDK_KEY_Super_L:
159 case GDK_KEY_Super_R:
160 case GDK_KEY_Hyper_L:
161 case GDK_KEY_Hyper_R:
162 return TRUE;
163 default:
164 return FALSE;
165 }
166}
167
168
169static gboolean on_key_release_event(GtkWidget *widget, GdkEventKey *ev, gpointer user_data)
170{
171 /* user may have rebound keybinding to a different modifier than Ctrl, so check all */
172 if (switch_in_progress && is_modifier_key(ev->keyval))
173 {
174 GeanyDocument *doc;
175
176 switch_in_progress = FALSE;
177
178 if (switch_dialog)
179 {
180 gtk_widget_destroy(switch_dialog);
182 }
183
184 doc = document_get_current();
186 mru_pos = 0;
188 }
189 return FALSE;
190}
191
192
193static GtkWidget *create_switch_dialog(void)
194{
195 GtkWidget *dialog, *widget, *vbox;
196
197 dialog = ui_minimal_dialog_new(GTK_WINDOW(main_widgets.window), _("Switch to Document"));
198 gtk_window_set_decorated(GTK_WINDOW(dialog), FALSE);
199 gtk_window_set_default_size(GTK_WINDOW(dialog), 200, -1);
200
201 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6);
202 gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
203 gtk_container_add(GTK_CONTAINER(dialog), vbox);
204
205 widget = gtk_image_new_from_stock(GTK_STOCK_JUMP_TO, GTK_ICON_SIZE_BUTTON);
206 gtk_container_add(GTK_CONTAINER(vbox), widget);
207
208 widget = gtk_label_new(NULL);
209 gtk_label_set_justify(GTK_LABEL(widget), GTK_JUSTIFY_CENTER);
210 gtk_container_add(GTK_CONTAINER(vbox), widget);
211 switch_dialog_label = widget;
212
213 g_signal_connect(dialog, "key-release-event", G_CALLBACK(on_key_release_event), NULL);
214 return dialog;
215}
216
217
218static void update_filename_label(void)
219{
220 guint i;
221 gchar *msg = NULL;
222 guint queue_length;
223 GeanyDocument *doc;
224
225 if (!switch_dialog)
226 {
229 }
230
231 queue_length = g_queue_get_length(mru_docs);
232 for (i = mru_pos; (i <= mru_pos + 3) && (doc = g_queue_peek_nth(mru_docs, i % queue_length)); i++)
233 {
234 gchar *basename;
235
236 basename = g_path_get_basename(DOC_FILENAME(doc));
237 if (i == mru_pos)
238 msg = g_markup_printf_escaped ("<b>%s</b>", basename);
239 else if (i % queue_length == mru_pos) /* && i != mru_pos */
240 {
241 /* We have wrapped around and got to the starting document again */
242 g_free(basename);
243 break;
244 }
245 else
246 {
247 SETPTR(basename, g_markup_printf_escaped ("\n%s", basename));
248 SETPTR(msg, g_strconcat(msg, basename, NULL));
249 }
250 g_free(basename);
251 }
252 gtk_label_set_markup(GTK_LABEL(switch_dialog_label), msg);
253 g_free(msg);
254}
255
256
257static gboolean on_switch_timeout(G_GNUC_UNUSED gpointer data)
258{
260 {
261 return FALSE;
262 }
263
265 return FALSE;
266}
267
268
270{
271 GeanyDocument *last_doc;
272 gboolean switch_start = !switch_in_progress;
273
274 mru_pos += 1;
275 last_doc = g_queue_peek_nth(mru_docs, mru_pos);
276
277 if (! DOC_VALID(last_doc))
278 {
279 utils_beep();
280 mru_pos = 0;
281 last_doc = g_queue_peek_nth(mru_docs, mru_pos);
282 }
283 if (! DOC_VALID(last_doc))
284 return;
285
286 switch_in_progress = TRUE;
287 document_show_tab(last_doc);
288
289 /* if there's a modifier key, we can switch back in MRU order each time unless
290 * the key is released */
291 if (switch_start)
292 g_timeout_add(600, on_switch_timeout, NULL);
293 else
295}
296
297
299{
300 return switch_in_progress;
301}
302
303
304static gboolean focus_sci(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
305{
307
308 if (doc != NULL && event->button == 1)
309 gtk_widget_grab_focus(GTK_WIDGET(doc->editor->sci));
310
311 return FALSE;
312}
313
314
315static gboolean gtk_notebook_show_arrows(GtkNotebook *notebook)
316{
317 return gtk_notebook_get_scrollable(notebook);
318#if 0
319 /* To get this working we would need to define at least the first two fields of
320 * GtkNotebookPage since it is a private field. The better way would be to
321 * subclass GtkNotebook.
322struct _FakeGtkNotebookPage
323{
324 GtkWidget *child;
325 GtkWidget *tab_label;
326};
327 */
328 gboolean show_arrow = FALSE;
329 GList *children;
330
331 if (! notebook->scrollable)
332 return FALSE;
333
334 children = notebook->children;
335 while (children)
336 {
337 struct _FakeGtkNotebookPage *page = children->data;
338
339 if (page->tab_label && ! gtk_widget_get_child_visible(page->tab_label))
340 show_arrow = TRUE;
341
342 children = children->next;
343 }
344 return show_arrow;
345#endif
346}
347
348
349static gboolean is_position_on_tab_bar(GtkNotebook *notebook, GdkEventButton *event)
350{
351 GtkWidget *page;
352 GtkWidget *tab;
353 GtkWidget *nb;
354 GtkPositionType tab_pos;
355 gint scroll_arrow_hlength, scroll_arrow_vlength;
356 gdouble x, y;
357
358 page = gtk_notebook_get_nth_page(notebook, 0);
359 g_return_val_if_fail(page != NULL, FALSE);
360
361 tab = gtk_notebook_get_tab_label(notebook, page);
362 g_return_val_if_fail(tab != NULL, FALSE);
363
364 tab_pos = gtk_notebook_get_tab_pos(notebook);
365 nb = GTK_WIDGET(notebook);
366
367 gtk_widget_style_get(GTK_WIDGET(notebook), "scroll-arrow-hlength", &scroll_arrow_hlength,
368 "scroll-arrow-vlength", &scroll_arrow_vlength, NULL);
369
370 if (! gdk_event_get_coords((GdkEvent*) event, &x, &y))
371 {
372 x = event->x;
373 y = event->y;
374 }
375
376 switch (tab_pos)
377 {
378 case GTK_POS_TOP:
379 case GTK_POS_BOTTOM:
380 {
381 if (event->y >= 0 && event->y <= gtk_widget_get_allocated_height(tab))
382 {
383 if (! gtk_notebook_show_arrows(notebook) || (
384 x > scroll_arrow_hlength &&
385 x < gtk_widget_get_allocated_width(nb) - scroll_arrow_hlength))
386 return TRUE;
387 }
388 break;
389 }
390 case GTK_POS_LEFT:
391 case GTK_POS_RIGHT:
392 {
393 if (event->x >= 0 && event->x <= gtk_widget_get_allocated_width(tab))
394 {
395 if (! gtk_notebook_show_arrows(notebook) || (
396 y > scroll_arrow_vlength &&
397 y < gtk_widget_get_allocated_height(nb) - scroll_arrow_vlength))
398 return TRUE;
399 }
400 }
401 }
402
403 return FALSE;
404}
405
406
407static void tab_bar_menu_activate_cb(GtkMenuItem *menuitem, gpointer data)
408{
409 GeanyDocument *doc = data;
410
411 if (! DOC_VALID(doc))
412 return;
413
415}
416
417
418static void on_open_in_new_window_activate(GtkMenuItem *menuitem, gpointer user_data)
419{
420 GeanyDocument *doc = user_data;
421 gchar *doc_path;
422
423 g_return_if_fail(doc->is_valid);
424
425 doc_path = utils_get_locale_from_utf8(doc->file_name);
427 g_free(doc_path);
428}
429
430
431static gboolean has_tabs_on_right(GeanyDocument *doc)
432{
433 GtkNotebook *nb = GTK_NOTEBOOK(main_widgets.notebook);
434 gint total_pages = gtk_notebook_get_n_pages(nb);
435 gint doc_page = document_get_notebook_page(doc);
436 return total_pages > (doc_page + 1);
437}
438
439
440static void on_close_documents_right_activate(GtkMenuItem *menuitem, GeanyDocument *doc)
441{
442 g_return_if_fail(has_tabs_on_right(doc));
443 GtkNotebook *nb = GTK_NOTEBOOK(main_widgets.notebook);
444 gint current_page = gtk_notebook_get_current_page(nb);
445 gint doc_page = document_get_notebook_page(doc);
446 for (gint i = doc_page + 1; i < gtk_notebook_get_n_pages(nb); )
447 {
449 i++; // only increment if tab wasn't closed
450 }
451 /* keep the current tab to the original one unless it has been closed, in
452 * which case use the activated one */
453 gtk_notebook_set_current_page(nb, MIN(current_page, doc_page));
454}
455
456
457static void show_tab_bar_popup_menu(GdkEventButton *event, GeanyDocument *doc)
458{
459 GtkWidget *menu_item;
460 static GtkWidget *menu = NULL;
461
462 if (menu == NULL)
463 menu = gtk_menu_new();
464
465 /* clear the old menu items */
466 gtk_container_foreach(GTK_CONTAINER(menu), (GtkCallback) gtk_widget_destroy, NULL);
467
469 G_CALLBACK(tab_bar_menu_activate_cb));
470
471 menu_item = gtk_separator_menu_item_new();
472 gtk_widget_show(menu_item);
473 gtk_container_add(GTK_CONTAINER(menu), menu_item);
474
475 menu_item = ui_image_menu_item_new(GTK_STOCK_OPEN, _("Open in New _Window"));
476 gtk_widget_show(menu_item);
477 gtk_container_add(GTK_CONTAINER(menu), menu_item);
478 g_signal_connect(menu_item, "activate",
479 G_CALLBACK(on_open_in_new_window_activate), doc);
480 /* disable if not on disk */
481 if (doc == NULL || !doc->real_path)
482 gtk_widget_set_sensitive(menu_item, FALSE);
483
484 menu_item = gtk_separator_menu_item_new();
485 gtk_widget_show(menu_item);
486 gtk_container_add(GTK_CONTAINER(menu), menu_item);
487
488 menu_item = gtk_image_menu_item_new_from_stock(GTK_STOCK_CLOSE, NULL);
489 gtk_widget_show(menu_item);
490 gtk_container_add(GTK_CONTAINER(menu), menu_item);
491 g_signal_connect(menu_item, "activate", G_CALLBACK(notebook_tab_close_clicked_cb), doc);
492 gtk_widget_set_sensitive(GTK_WIDGET(menu_item), (doc != NULL));
493
494 menu_item = ui_image_menu_item_new(GTK_STOCK_CLOSE, _("Close Ot_her Documents"));
495 gtk_widget_show(menu_item);
496 gtk_container_add(GTK_CONTAINER(menu), menu_item);
497 g_signal_connect(menu_item, "activate", G_CALLBACK(on_close_other_documents1_activate), doc);
498 gtk_widget_set_sensitive(GTK_WIDGET(menu_item), (doc != NULL));
499
500 menu_item = ui_image_menu_item_new(GTK_STOCK_CLOSE, _("Close Documents to the _Right"));
501 gtk_widget_show(menu_item);
502 gtk_container_add(GTK_CONTAINER(menu), menu_item);
503 g_signal_connect(menu_item, "activate", G_CALLBACK(on_close_documents_right_activate), doc);
504 gtk_widget_set_sensitive(GTK_WIDGET(menu_item), doc != NULL && has_tabs_on_right(doc));
505
506 menu_item = ui_image_menu_item_new(GTK_STOCK_CLOSE, _("C_lose All"));
507 gtk_widget_show(menu_item);
508 gtk_container_add(GTK_CONTAINER(menu), menu_item);
509 g_signal_connect(menu_item, "activate", G_CALLBACK(on_close_all1_activate), NULL);
510
511 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, event->button, event->time);
512}
513
514
515static gboolean notebook_tab_bar_click_cb(GtkWidget *widget, GdkEventButton *event,
516 gpointer user_data)
517{
518 if (event->type == GDK_2BUTTON_PRESS)
519 {
520 GtkNotebook *notebook = GTK_NOTEBOOK(widget);
521 GtkWidget *event_widget = gtk_get_event_widget((GdkEvent *) event);
522 GtkWidget *child = gtk_notebook_get_nth_page(notebook, gtk_notebook_get_current_page(notebook));
523
524 /* ignore events from the content of the page (impl. stolen from GTK2 tab scrolling)
525 * TODO: we should also ignore notebook's action widgets, but that's more work and
526 * we don't have any of them yet anyway -- and GTK 2.16 don't have those actions. */
527 if (event_widget == NULL || event_widget == child || gtk_widget_is_ancestor(event_widget, child))
528 return FALSE;
529
530 if (is_position_on_tab_bar(notebook, event))
531 {
533 return TRUE;
534 }
535 }
536 /* right-click is also handled here if it happened on the notebook tab bar but not
537 * on a tab directly */
538 else if (event->button == 3)
539 {
541 return TRUE;
542 }
543 return FALSE;
544}
545
546
548{
549 g_signal_connect_after(main_widgets.notebook, "button-press-event",
550 G_CALLBACK(notebook_tab_bar_click_cb), NULL);
551
552 g_signal_connect(main_widgets.notebook, "drag-data-received",
554
555 mru_docs = g_queue_new();
556 g_signal_connect(main_widgets.notebook, "switch-page",
557 G_CALLBACK(on_notebook_switch_page), NULL);
558 g_signal_connect(geany_object, "document-close",
559 G_CALLBACK(on_document_close), NULL);
560
561 /* in case the switch dialog misses an event while drawing the dialog */
562 g_signal_connect(main_widgets.window, "key-release-event", G_CALLBACK(on_key_release_event), NULL);
563
565}
566
567
569{
570 g_queue_free(mru_docs);
571}
572
573
574static void setup_tab_dnd(void)
575{
576 GtkWidget *notebook = main_widgets.notebook;
577
578 g_signal_connect(notebook, "page-reordered", G_CALLBACK(notebook_page_reordered_cb), NULL);
579}
580
581
582static void
583notebook_page_reordered_cb(GtkNotebook *notebook, GtkWidget *child, guint page_num,
584 gpointer user_data)
585{
586 /* Not necessary to update open files treeview if it's sorted.
587 * Note: if enabled, it's best to move the item instead of recreating all items. */
588 /*sidebar_openfiles_update_all();*/
589}
590
591
592/* call this after the number of tabs in main_widgets.notebook changes. */
593static void tab_count_changed(void)
594{
595 switch (gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)))
596 {
597 case 0:
598 /* Enables DnD for dropping files into the empty notebook widget */
599 gtk_drag_dest_set(main_widgets.notebook, GTK_DEST_DEFAULT_ALL,
601 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_ASK);
602 break;
603
604 case 1:
605 /* Disables DnD for dropping files into the notebook widget and enables the DnD for moving file
606 * tabs. Files can still be dropped into the notebook widget because it will be handled by the
607 * active Scintilla Widget (only dropping to the tab bar is not possible but it should be ok) */
608 gtk_drag_dest_set(main_widgets.notebook, GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP,
609 drag_targets, G_N_ELEMENTS(drag_targets), GDK_ACTION_MOVE);
610 break;
611 }
612}
613
614
615static gboolean notebook_tab_click(GtkWidget *widget, GdkEventButton *event, gpointer data)
616{
617 guint state;
618 GeanyDocument *doc = (GeanyDocument *) data;
619
620 /* toggle additional widgets on double click */
621 if (event->type == GDK_2BUTTON_PRESS)
622 {
625
626 return TRUE; /* stop other handlers like notebook_tab_bar_click_cb() */
627 }
628 /* close tab on middle click */
629 if (event->button == 2)
630 {
631 document_close(doc);
632 return TRUE; /* stop other handlers like notebook_tab_bar_click_cb() */
633 }
634 /* switch last used tab on ctrl-click */
635 state = keybindings_get_modifiers(event->state);
636 if (event->button == 1 && state == GEANY_PRIMARY_MOD_MASK)
637 {
640 return TRUE;
641 }
642 /* right-click is first handled here if it happened on a notebook tab */
643 if (event->button == 3)
644 {
645 show_tab_bar_popup_menu(event, doc);
646 return TRUE;
647 }
648
649 return FALSE;
650}
651
652
653static void notebook_tab_close_button_style_set(GtkWidget *btn, GtkRcStyle *prev_style,
654 gpointer data)
655{
656 gint w, h;
657
658 gtk_icon_size_lookup_for_settings(gtk_widget_get_settings(btn), GTK_ICON_SIZE_MENU, &w, &h);
659 gtk_widget_set_size_request(btn, w + 2, h + 2);
660}
661
662
663/* Returns page number of notebook page, or -1 on error
664 *
665 * Note: the widget added to the notebook is *not* shown by this function, so you have to call
666 * something like `gtk_widget_show(document_get_notebook_child(doc))` when finished setting up the
667 * document. This is necessary because when the notebook tab is added, the document isn't ready
668 * yet, and we need the notebook to emit ::switch-page after it actually is. Actually this
669 * doesn't prevent the signal to me emitted straight when we insert the page (this looks like a
670 * GTK bug), but it emits it again when showing the child, and it's all we need. */
672{
673 GtkWidget *hbox, *ebox, *vbox;
674 gint tabnum;
675 GtkWidget *page;
676 gint cur_page;
677
678 g_return_val_if_fail(this != NULL, -1);
679
680 /* page is packed into a vbox so we can stack infobars above it */
681 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
682 page = GTK_WIDGET(this->editor->sci);
683 gtk_box_pack_start(GTK_BOX(vbox), page, TRUE, TRUE, 0);
684
685 this->priv->tab_label = gtk_label_new(NULL);
686
687 /* get button press events for the tab label and the space between it and
688 * the close button, if any */
689 ebox = gtk_event_box_new();
690 gtk_widget_set_has_window(ebox, FALSE);
691 g_signal_connect(ebox, "button-press-event", G_CALLBACK(notebook_tab_click), this);
692 /* focus the current document after clicking on a tab */
693 g_signal_connect_after(ebox, "button-release-event",
694 G_CALLBACK(focus_sci), NULL);
695
696 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2);
697 gtk_box_pack_start(GTK_BOX(hbox), this->priv->tab_label, FALSE, FALSE, 0);
698 gtk_container_add(GTK_CONTAINER(ebox), hbox);
699
701 {
702 GtkWidget *image, *btn, *align;
703
704 btn = gtk_button_new();
705 gtk_button_set_relief(GTK_BUTTON(btn), GTK_RELIEF_NONE);
706 gtk_button_set_focus_on_click(GTK_BUTTON(btn), FALSE);
707 gtk_widget_set_name(btn, "geany-close-tab-button");
708
709 image = gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
710 gtk_container_add(GTK_CONTAINER(btn), image);
711
712 align = gtk_alignment_new(1.0, 0.5, 0.0, 0.0);
713 gtk_container_add(GTK_CONTAINER(align), btn);
714 gtk_box_pack_start(GTK_BOX(hbox), align, TRUE, TRUE, 0);
715
716 g_signal_connect(btn, "clicked", G_CALLBACK(notebook_tab_close_clicked_cb), this);
717 /* button overrides event box, so make middle click on button also close tab */
718 g_signal_connect(btn, "button-press-event", G_CALLBACK(notebook_tab_click), this);
719 /* handle style modification to keep button small as possible even when theme change */
720 g_signal_connect(btn, "style-set", G_CALLBACK(notebook_tab_close_button_style_set), NULL);
721 }
722
724
726
728 cur_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(main_widgets.notebook));
729 else
730 cur_page = file_prefs.tab_order_ltr ? -2 /* hack: -2 + 1 = -1, last page */ : 0;
732 tabnum = gtk_notebook_insert_page_menu(GTK_NOTEBOOK(main_widgets.notebook), vbox,
733 ebox, NULL, cur_page + 1);
734 else
735 tabnum = gtk_notebook_insert_page_menu(GTK_NOTEBOOK(main_widgets.notebook), vbox,
736 ebox, NULL, cur_page);
737
739
740 /* enable tab DnD */
741 gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(main_widgets.notebook), vbox, TRUE);
742
743 return tabnum;
744}
745
746
747static void
748notebook_tab_close_clicked_cb(GtkButton *button, gpointer data)
749{
750 GeanyDocument *doc = (GeanyDocument *) data;
751
752 document_close(doc);
753}
754
755
756/* Always use this instead of gtk_notebook_remove_page(). */
757void notebook_remove_page(gint page_num)
758{
759 gint page = gtk_notebook_get_current_page(GTK_NOTEBOOK(main_widgets.notebook));
760
761 if (page_num == page)
762 {
764 page += 1;
765 else if (page > 0) /* never go negative, it would select the last page */
766 page -= 1;
767
769 {
770 GeanyDocument *last_doc;
771
772 last_doc = g_queue_peek_nth(mru_docs, 0);
773 if (DOC_VALID(last_doc))
774 page = document_get_notebook_page(last_doc);
775 }
776
777 gtk_notebook_set_current_page(GTK_NOTEBOOK(main_widgets.notebook), page);
778 }
779
780 /* now remove the page (so we don't temporarily switch to the previous page) */
781 gtk_notebook_remove_page(GTK_NOTEBOOK(main_widgets.notebook), page_num);
782
784}
785
786
787static void
788on_window_drag_data_received(GtkWidget *widget, GdkDragContext *drag_context,
789 gint x, gint y, GtkSelectionData *data, guint target_type,
790 guint event_time, gpointer user_data)
791{
792 gboolean success = FALSE;
793 gint length = gtk_selection_data_get_length(data);
794
795 if (length > 0 && gtk_selection_data_get_format(data) == 8)
796 {
797 document_open_file_list((const gchar *)gtk_selection_data_get_data(data), length);
798
799 success = TRUE;
800 }
801 gtk_drag_finish(drag_context, success, FALSE, event_time);
802}
void on_menu_toggle_all_additional_widgets1_activate(GtkMenuItem *menuitem, gpointer user_data)
Definition: callbacks.c:1547
void on_close_all1_activate(GtkMenuItem *menuitem, gpointer user_data)
Definition: callbacks.c:153
void on_close_other_documents1_activate(GtkMenuItem *menuitem, gpointer user_data)
Definition: callbacks.c:1729
GeanyDocument * document_get_current(void)
Finds the current document.
Definition: document.c:371
GeanyDocument * document_get_from_page(guint page_num)
Finds the document for the given notebook page page_num.
Definition: document.c:352
gint document_get_notebook_page(GeanyDocument *doc)
Gets the notebook page index for a document.
Definition: document.c:289
void document_show_tab(GeanyDocument *doc)
Definition: document.c:1273
gboolean document_check_disk_status(GeanyDocument *doc, gboolean force)
Definition: document.c:3674
GeanyFilePrefs file_prefs
Definition: document.c:86
void document_open_file_list(const gchar *data, gsize length)
Definition: document.c:1521
void document_update_tab_label(GeanyDocument *doc)
Definition: document.c:430
GeanyDocument * document_new_file(const gchar *utf8_filename, GeanyFiletype *ft, const gchar *text)
Creates a new document.
Definition: document.c:824
#define DOC_VALID(doc_ptr)
Null-safe way to check GeanyDocument::is_valid.
Definition: document.h:162
#define DOC_FILENAME(doc)
Returns the filename of the document passed or GEANY_STRING_UNTITLED (e.g.
Definition: document.h:170
GObject * geany_object
Definition: geanyobject.c:41
void keybindings_send_command(guint group_id, guint key_id)
Mimics a (built-in only) keybinding action.
Definition: keybindings.c:1426
GdkModifierType keybindings_get_modifiers(GdkModifierType mods)
Gets significant modifiers from a GdkModifierType mask.
Definition: keybindings.c:121
Configurable keyboard shortcuts.
#define GEANY_PRIMARY_MOD_MASK
Defines the primary modifier mask which is the Ctrl key mask on UNIX/Windows and Command key mask on ...
Definition: keybindings.h:36
@ GEANY_KEY_GROUP_NOTEBOOK
Group.
Definition: keybindings.h:114
@ GEANY_KEYS_NOTEBOOK_SWITCHTABLASTUSED
Keybinding.
Definition: keybindings.h:212
GeanyStatus main_status
Definition: libmain.c:89
Main program-related commands.
static void on_open_in_new_window_activate(GtkMenuItem *menuitem, gpointer user_data)
Definition: notebook.c:418
static GtkWidget * switch_dialog
Definition: notebook.c:63
gboolean notebook_switch_in_progress(void)
Definition: notebook.c:298
static void notebook_tab_close_clicked_cb(GtkButton *button, gpointer user_data)
Definition: notebook.c:748
static gboolean notebook_tab_click(GtkWidget *widget, GdkEventButton *event, gpointer data)
Definition: notebook.c:615
static void on_notebook_switch_page(GtkNotebook *notebook, gpointer page, guint page_num, gpointer user_data)
Definition: notebook.c:96
static void on_document_close(GObject *obj, GeanyDocument *doc)
Definition: notebook.c:113
static void update_filename_label(void)
Definition: notebook.c:218
static gboolean gtk_notebook_show_arrows(GtkNotebook *notebook)
Definition: notebook.c:315
static void on_close_documents_right_activate(GtkMenuItem *menuitem, GeanyDocument *doc)
Definition: notebook.c:440
static gboolean is_modifier_key(guint keyval)
Definition: notebook.c:146
void notebook_remove_page(gint page_num)
Definition: notebook.c:757
static const GtkTargetEntry drag_targets[]
Definition: notebook.c:46
#define GEANY_DND_NOTEBOOK_TAB_TYPE
Definition: notebook.c:44
void notebook_switch_tablastused(void)
Definition: notebook.c:269
static gboolean on_key_release_event(GtkWidget *widget, GdkEventKey *ev, gpointer user_data)
Definition: notebook.c:169
static void notebook_page_reordered_cb(GtkNotebook *notebook, GtkWidget *child, guint page_num, gpointer user_data)
Definition: notebook.c:583
static void show_tab_bar_popup_menu(GdkEventButton *event, GeanyDocument *doc)
Definition: notebook.c:457
static gboolean is_position_on_tab_bar(GtkNotebook *notebook, GdkEventButton *event)
Definition: notebook.c:349
void notebook_init(void)
Definition: notebook.c:547
static gboolean on_switch_timeout(G_GNUC_UNUSED gpointer data)
Definition: notebook.c:257
static GtkWidget * create_switch_dialog(void)
Definition: notebook.c:193
static gboolean focus_sci(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
Definition: notebook.c:304
static void tab_count_changed(void)
Definition: notebook.c:593
static GQueue * mru_docs
Definition: notebook.c:59
static void on_window_drag_data_received(GtkWidget *widget, GdkDragContext *drag_context, gint x, gint y, GtkSelectionData *data, guint target_type, guint event_time, gpointer user_data)
Definition: notebook.c:788
static gboolean has_tabs_on_right(GeanyDocument *doc)
Definition: notebook.c:431
static guint mru_pos
Definition: notebook.c:60
static void notebook_tab_close_button_style_set(GtkWidget *btn, GtkRcStyle *prev_style, gpointer data)
Definition: notebook.c:653
static GtkWidget * switch_dialog_label
Definition: notebook.c:64
static gboolean switch_in_progress
Definition: notebook.c:62
static void update_mru_docs_head(GeanyDocument *doc)
Definition: notebook.c:82
static const gsize MAX_MRU_DOCS
Definition: notebook.c:58
static void setup_tab_dnd(void)
Definition: notebook.c:574
static GtkTargetEntry files_drop_targets[]
Definition: notebook.c:51
static GtkWidget * ui_minimal_dialog_new(GtkWindow *parent, const gchar *title)
Definition: notebook.c:126
void notebook_free(void)
Definition: notebook.c:568
gint notebook_new_tab(GeanyDocument *this)
Definition: notebook.c:671
static gboolean notebook_tab_bar_click_cb(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
Definition: notebook.c:515
static void tab_bar_menu_activate_cb(GtkMenuItem *menuitem, gpointer data)
Definition: notebook.c:407
signal void(* document_close)(GObject *obj, GeanyDocument *doc, gpointer user_data)
Sent before closing a document.
static GeanyProjectPrivate priv
Definition: project.c:56
#define NULL
Definition: rbtree.h:150
GtkWidget * dialog
gtk_container_add(GTK_CONTAINER(dialog->vbox), check_button)
gtk_widget_show_all(dialog)
Structure for representing an open tab with all its properties.
Definition: document.h:81
gchar * file_name
The UTF-8 encoded file name.
Definition: document.h:92
gchar * real_path
The link-dereferenced, locale-encoded file name.
Definition: document.h:115
gboolean is_valid
Flag used to check if this document is valid when iterating GeanyData::documents_array.
Definition: document.h:83
GeanyEditor * editor
The editor associated with the document.
Definition: document.h:98
ScintillaObject * sci
The Scintilla editor GtkWidget.
Definition: editor.h:152
gboolean tab_order_beside
Definition: document.h:54
gboolean show_tab_cross
Definition: document.h:55
gboolean tab_close_switch_to_mru
Definition: document.h:65
gboolean tab_order_ltr
Definition: document.h:53
gboolean notebook_double_click_hides_widgets
whether a double click on notebook tabs hides all other windows
Definition: ui_utils.h:59
GtkWidget * window
Main window.
Definition: ui_utils.h:80
GtkWidget * notebook
Document notebook.
Definition: ui_utils.h:83
Defines internationalization macros.
#define _(String)
Definition: support.h:42
void ui_menu_add_document_items(GtkMenu *menu, GeanyDocument *active, GCallback callback)
<simplesect kind="geany:skip"></simplesect> Adds a list of document items to menu.
Definition: ui_utils.c:2929
GeanyMainWidgets main_widgets
Definition: ui_utils.c:72
GtkWidget * ui_image_menu_item_new(const gchar *stock_id, const gchar *label)
Creates a GtkImageMenuItem with a stock image and a custom label.
Definition: ui_utils.c:1574
GeanyInterfacePrefs interface_prefs
Definition: ui_utils.c:71
User Interface general utility functions.
void utils_beep(void)
Definition: utils.c:918
void utils_start_new_geany_instance(const gchar *doc_path)
Definition: utils.c:2348
gchar * utils_get_locale_from_utf8(const gchar *utf8_text)
Converts the given UTF-8 encoded string into locale encoding.
Definition: utils.c:1243
General utility functions, non-GTK related.
#define SETPTR(ptr, result)
Assigns result to ptr, then frees the old value.
Definition: utils.h:50