Adding first version of Hindi translation
[geany-mirror.git] / src / notebook.c
blob420c4e3c3861989468c584419f65ef2e84af001d
1 /*
2 * notebook.c - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2006-2012 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
5 * Copyright 2006-2012 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 * Notebook tab Drag 'n' Drop reordering and tab management.
26 #include "geany.h"
28 #include <gdk/gdkkeysyms.h>
30 #include "notebook.h"
31 #include "document.h"
32 #include "editor.h"
33 #include "documentprivate.h"
34 #include "ui_utils.h"
35 #include "sidebar.h"
36 #include "support.h"
37 #include "callbacks.h"
38 #include "utils.h"
39 #include "keybindings.h"
40 #include "main.h"
42 #define GEANY_DND_NOTEBOOK_TAB_TYPE "geany_dnd_notebook_tab"
44 static const GtkTargetEntry drag_targets[] =
46 {GEANY_DND_NOTEBOOK_TAB_TYPE, GTK_TARGET_SAME_APP | GTK_TARGET_SAME_WIDGET, 0}
49 static GtkTargetEntry files_drop_targets[] = {
50 { "STRING", 0, 0 },
51 { "UTF8_STRING", 0, 0 },
52 { "text/plain", 0, 0 },
53 { "text/uri-list", 0, 0 }
56 static const gsize MAX_MRU_DOCS = 20;
57 static GQueue *mru_docs = NULL;
58 static guint mru_pos = 0;
60 static gboolean switch_in_progress = FALSE;
61 static GtkWidget *switch_dialog = NULL;
62 static GtkWidget *switch_dialog_label = NULL;
65 static void
66 notebook_page_reordered_cb(GtkNotebook *notebook, GtkWidget *child, guint page_num,
67 gpointer user_data);
69 static void
70 on_window_drag_data_received(GtkWidget *widget, GdkDragContext *drag_context,
71 gint x, gint y, GtkSelectionData *data, guint target_type,
72 guint event_time, gpointer user_data);
74 static void
75 notebook_tab_close_clicked_cb(GtkButton *button, gpointer user_data);
77 static void setup_tab_dnd(void);
80 static void update_mru_docs_head(GeanyDocument *doc)
82 if (doc)
84 g_queue_remove(mru_docs, doc);
85 g_queue_push_head(mru_docs, doc);
87 if (g_queue_get_length(mru_docs) > MAX_MRU_DOCS)
88 g_queue_pop_tail(mru_docs);
93 /* before the tab changes, add the current document to the MRU list */
94 static void on_notebook_switch_page(GtkNotebook *notebook,
95 gpointer page, guint page_num, gpointer user_data)
97 GeanyDocument *new;
99 new = document_get_from_page(page_num);
101 /* insert the very first document (when adding the second document
102 * and switching to it) */
103 if (g_queue_get_length(mru_docs) == 0 && gtk_notebook_get_n_pages(notebook) == 2)
104 update_mru_docs_head(document_get_current());
106 if (!switch_in_progress)
107 update_mru_docs_head(new);
111 static void on_document_close(GObject *obj, GeanyDocument *doc)
113 if (! main_status.quitting)
115 g_queue_remove(mru_docs, doc);
116 /* this prevents the pop up window from showing when there's a single
117 * document */
118 if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)) == 2)
119 g_queue_clear(mru_docs);
124 static GtkWidget *ui_minimal_dialog_new(GtkWindow *parent, const gchar *title)
126 GtkWidget *dialog;
128 dialog = gtk_window_new(GTK_WINDOW_POPUP);
130 if (parent)
132 gtk_window_set_transient_for(GTK_WINDOW(dialog), parent);
133 gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE);
135 gtk_window_set_title(GTK_WINDOW(dialog), title);
136 gtk_window_set_type_hint(GTK_WINDOW(dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
137 gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER_ON_PARENT);
139 gtk_widget_set_name(dialog, "GeanyDialog");
140 return dialog;
144 static gboolean is_modifier_key(guint keyval)
146 switch (keyval)
148 case GDK_Shift_L:
149 case GDK_Shift_R:
150 case GDK_Control_L:
151 case GDK_Control_R:
152 case GDK_Meta_L:
153 case GDK_Meta_R:
154 case GDK_Alt_L:
155 case GDK_Alt_R:
156 case GDK_Super_L:
157 case GDK_Super_R:
158 case GDK_Hyper_L:
159 case GDK_Hyper_R:
160 return TRUE;
161 default:
162 return FALSE;
167 static gboolean on_key_release_event(GtkWidget *widget, GdkEventKey *ev, gpointer user_data)
169 /* user may have rebound keybinding to a different modifier than Ctrl, so check all */
170 if (switch_in_progress && is_modifier_key(ev->keyval))
172 GeanyDocument *doc;
174 switch_in_progress = FALSE;
176 if (switch_dialog)
178 gtk_widget_destroy(switch_dialog);
179 switch_dialog = NULL;
182 doc = document_get_current();
183 update_mru_docs_head(doc);
184 mru_pos = 0;
185 document_check_disk_status(doc, TRUE);
187 return FALSE;
191 static GtkWidget *create_switch_dialog(void)
193 GtkWidget *dialog, *widget, *vbox;
195 dialog = ui_minimal_dialog_new(GTK_WINDOW(main_widgets.window), _("Switch to Document"));
196 gtk_window_set_decorated(GTK_WINDOW(dialog), FALSE);
197 gtk_window_set_default_size(GTK_WINDOW(dialog), 200, -1);
199 vbox = gtk_vbox_new(FALSE, 6);
200 gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
201 gtk_container_add(GTK_CONTAINER(dialog), vbox);
203 widget = gtk_image_new_from_stock(GTK_STOCK_JUMP_TO, GTK_ICON_SIZE_BUTTON);
204 gtk_container_add(GTK_CONTAINER(vbox), widget);
206 widget = gtk_label_new(NULL);
207 gtk_label_set_justify(GTK_LABEL(widget), GTK_JUSTIFY_CENTER);
208 gtk_container_add(GTK_CONTAINER(vbox), widget);
209 switch_dialog_label = widget;
211 g_signal_connect(dialog, "key-release-event", G_CALLBACK(on_key_release_event), NULL);
212 return dialog;
216 static void update_filename_label(void)
218 guint i;
219 gchar *msg = NULL;
220 guint queue_length;
221 GeanyDocument *doc;
223 if (!switch_dialog)
225 switch_dialog = create_switch_dialog();
226 gtk_widget_show_all(switch_dialog);
229 queue_length = g_queue_get_length(mru_docs);
230 for (i = mru_pos; (i <= mru_pos + 3) && (doc = g_queue_peek_nth(mru_docs, i % queue_length)); i++)
232 gchar *basename;
234 basename = g_path_get_basename(DOC_FILENAME(doc));
235 if (i == mru_pos)
236 msg = g_markup_printf_escaped ("<b>%s</b>", basename);
237 else if (i % queue_length == mru_pos) /* && i != mru_pos */
239 /* We have wrapped around and got to the starting document again */
240 g_free(basename);
241 break;
243 else
245 SETPTR(basename, g_markup_printf_escaped ("\n%s", basename));
246 SETPTR(msg, g_strconcat(msg, basename, NULL));
248 g_free(basename);
250 gtk_label_set_markup(GTK_LABEL(switch_dialog_label), msg);
251 g_free(msg);
255 static gboolean on_switch_timeout(G_GNUC_UNUSED gpointer data)
257 if (!switch_in_progress || switch_dialog)
259 return FALSE;
262 update_filename_label();
263 return FALSE;
267 void notebook_switch_tablastused(void)
269 GeanyDocument *last_doc;
270 gboolean switch_start = !switch_in_progress;
272 mru_pos += 1;
273 last_doc = g_queue_peek_nth(mru_docs, mru_pos);
275 if (! DOC_VALID(last_doc))
277 utils_beep();
278 mru_pos = 0;
279 last_doc = g_queue_peek_nth(mru_docs, mru_pos);
281 if (! DOC_VALID(last_doc))
282 return;
284 switch_in_progress = TRUE;
285 document_show_tab(last_doc);
287 /* if there's a modifier key, we can switch back in MRU order each time unless
288 * the key is released */
289 if (switch_start)
290 g_timeout_add(600, on_switch_timeout, NULL);
291 else
292 update_filename_label();
296 gboolean notebook_switch_in_progress(void)
298 return switch_in_progress;
302 static gboolean focus_sci(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
304 GeanyDocument *doc = document_get_current();
306 if (doc != NULL && event->button == 1)
307 gtk_widget_grab_focus(GTK_WIDGET(doc->editor->sci));
309 return FALSE;
313 static gboolean gtk_notebook_show_arrows(GtkNotebook *notebook)
315 return gtk_notebook_get_scrollable(notebook);
316 #if 0
317 /* To get this working we would need to define at least the first two fields of
318 * GtkNotebookPage since it is a private field. The better way would be to
319 * subclass GtkNotebook.
320 struct _FakeGtkNotebookPage
322 GtkWidget *child;
323 GtkWidget *tab_label;
326 gboolean show_arrow = FALSE;
327 GList *children;
329 if (! notebook->scrollable)
330 return FALSE;
332 children = notebook->children;
333 while (children)
335 struct _FakeGtkNotebookPage *page = children->data;
337 if (page->tab_label && ! gtk_widget_get_child_visible(page->tab_label))
338 show_arrow = TRUE;
340 children = children->next;
342 return show_arrow;
343 #endif
347 static gboolean is_position_on_tab_bar(GtkNotebook *notebook, GdkEventButton *event)
349 GtkWidget *page;
350 GtkWidget *tab;
351 GtkWidget *nb;
352 GtkPositionType tab_pos;
353 gint scroll_arrow_hlength, scroll_arrow_vlength;
354 gdouble x, y;
356 page = gtk_notebook_get_nth_page(notebook, 0);
357 g_return_val_if_fail(page != NULL, FALSE);
359 tab = gtk_notebook_get_tab_label(notebook, page);
360 g_return_val_if_fail(tab != NULL, FALSE);
362 tab_pos = gtk_notebook_get_tab_pos(notebook);
363 nb = GTK_WIDGET(notebook);
365 gtk_widget_style_get(GTK_WIDGET(notebook), "scroll-arrow-hlength", &scroll_arrow_hlength,
366 "scroll-arrow-vlength", &scroll_arrow_vlength, NULL);
368 if (! gdk_event_get_coords((GdkEvent*) event, &x, &y))
370 x = event->x;
371 y = event->y;
374 switch (tab_pos)
376 case GTK_POS_TOP:
377 case GTK_POS_BOTTOM:
379 if (event->y >= 0 && event->y <= tab->allocation.height)
381 if (! gtk_notebook_show_arrows(notebook) || (
382 x > scroll_arrow_hlength &&
383 x < nb->allocation.width - scroll_arrow_hlength))
384 return TRUE;
386 break;
388 case GTK_POS_LEFT:
389 case GTK_POS_RIGHT:
391 if (event->x >= 0 && event->x <= tab->allocation.width)
393 if (! gtk_notebook_show_arrows(notebook) || (
394 y > scroll_arrow_vlength &&
395 y < nb->allocation.height - scroll_arrow_vlength))
396 return TRUE;
401 return FALSE;
405 static void tab_bar_menu_activate_cb(GtkMenuItem *menuitem, gpointer data)
407 GeanyDocument *doc = data;
409 if (! DOC_VALID(doc))
410 return;
412 document_show_tab(doc);
416 static void on_open_in_new_window_activate(GtkMenuItem *menuitem, gpointer user_data)
418 gchar *geany_path;
419 GeanyDocument *doc = user_data;
421 g_return_if_fail(doc->is_valid);
423 geany_path = g_find_program_in_path("geany");
425 if (geany_path)
427 gchar *doc_path = utils_get_locale_from_utf8(doc->file_name);
428 gchar *argv[] = {geany_path, "-i", doc_path, NULL};
429 GError *err = NULL;
431 if (!utils_spawn_async(NULL, argv, NULL, 0, NULL, NULL, NULL, &err))
433 g_printerr("Unable to open new window: %s", err->message);
434 g_error_free(err);
436 g_free(doc_path);
437 g_free(geany_path);
439 else
440 g_printerr("Unable to find 'geany'");
444 static void show_tab_bar_popup_menu(GdkEventButton *event, GtkWidget *page)
446 GtkWidget *menu_item;
447 static GtkWidget *menu = NULL;
448 GeanyDocument *doc = NULL;
449 gint page_num;
451 if (menu == NULL)
452 menu = gtk_menu_new();
454 /* clear the old menu items */
455 gtk_container_foreach(GTK_CONTAINER(menu), (GtkCallback) gtk_widget_destroy, NULL);
457 ui_menu_add_document_items(GTK_MENU(menu), document_get_current(),
458 G_CALLBACK(tab_bar_menu_activate_cb));
460 menu_item = gtk_separator_menu_item_new();
461 gtk_widget_show(menu_item);
462 gtk_container_add(GTK_CONTAINER(menu), menu_item);
464 if (page != NULL)
466 page_num = gtk_notebook_page_num(GTK_NOTEBOOK(main_widgets.notebook), page);
467 doc = document_get_from_page(page_num);
470 menu_item = ui_image_menu_item_new(GTK_STOCK_OPEN, "Open in New _Window");
471 gtk_widget_show(menu_item);
472 gtk_container_add(GTK_CONTAINER(menu), menu_item);
473 g_signal_connect(menu_item, "activate",
474 G_CALLBACK(on_open_in_new_window_activate), doc);
475 /* disable if not on disk */
476 if (doc == NULL || !doc->real_path)
477 gtk_widget_set_sensitive(menu_item, FALSE);
479 menu_item = gtk_separator_menu_item_new();
480 gtk_widget_show(menu_item);
481 gtk_container_add(GTK_CONTAINER(menu), menu_item);
483 menu_item = gtk_image_menu_item_new_from_stock(GTK_STOCK_CLOSE, NULL);
484 gtk_widget_show(menu_item);
485 gtk_container_add(GTK_CONTAINER(menu), menu_item);
486 g_signal_connect(menu_item, "activate", G_CALLBACK(notebook_tab_close_clicked_cb), page);
487 gtk_widget_set_sensitive(GTK_WIDGET(menu_item), (page != NULL));
489 menu_item = ui_image_menu_item_new(GTK_STOCK_CLOSE, _("Close Ot_her Documents"));
490 gtk_widget_show(menu_item);
491 gtk_container_add(GTK_CONTAINER(menu), menu_item);
492 g_signal_connect(menu_item, "activate", G_CALLBACK(on_close_other_documents1_activate), page);
493 gtk_widget_set_sensitive(GTK_WIDGET(menu_item), (page != NULL));
495 menu_item = ui_image_menu_item_new(GTK_STOCK_CLOSE, _("C_lose All"));
496 gtk_widget_show(menu_item);
497 gtk_container_add(GTK_CONTAINER(menu), menu_item);
498 g_signal_connect(menu_item, "activate", G_CALLBACK(on_close_all1_activate), NULL);
500 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, event->button, event->time);
504 static gboolean notebook_tab_bar_click_cb(GtkWidget *widget, GdkEventButton *event,
505 gpointer user_data)
507 if (event->type == GDK_2BUTTON_PRESS)
509 GtkNotebook *notebook = GTK_NOTEBOOK(widget);
510 GtkWidget *event_widget = gtk_get_event_widget((GdkEvent *) event);
511 GtkWidget *child = gtk_notebook_get_nth_page(notebook, gtk_notebook_get_current_page(notebook));
513 /* ignore events from the content of the page (impl. stolen from GTK2 tab scrolling)
514 * TODO: we should also ignore notebook's action widgets, but that's more work and
515 * we don't have any of them yet anyway -- and GTK 2.16 don't have those actions. */
516 if (event_widget == NULL || event_widget == child || gtk_widget_is_ancestor(event_widget, child))
517 return FALSE;
519 if (is_position_on_tab_bar(notebook, event))
521 document_new_file(NULL, NULL, NULL);
522 return TRUE;
525 /* right-click is also handled here if it happened on the notebook tab bar but not
526 * on a tab directly */
527 else if (event->button == 3)
529 show_tab_bar_popup_menu(event, NULL);
530 return TRUE;
532 return FALSE;
536 void notebook_init()
538 g_signal_connect_after(main_widgets.notebook, "button-press-event",
539 G_CALLBACK(notebook_tab_bar_click_cb), NULL);
541 g_signal_connect(main_widgets.notebook, "drag-data-received",
542 G_CALLBACK(on_window_drag_data_received), NULL);
544 mru_docs = g_queue_new();
545 g_signal_connect(main_widgets.notebook, "switch-page",
546 G_CALLBACK(on_notebook_switch_page), NULL);
547 g_signal_connect(geany_object, "document-close",
548 G_CALLBACK(on_document_close), NULL);
550 /* in case the switch dialog misses an event while drawing the dialog */
551 g_signal_connect(main_widgets.window, "key-release-event", G_CALLBACK(on_key_release_event), NULL);
553 setup_tab_dnd();
557 void notebook_free(void)
559 g_queue_free(mru_docs);
563 static void setup_tab_dnd()
565 GtkWidget *notebook = main_widgets.notebook;
567 g_signal_connect(notebook, "page-reordered", G_CALLBACK(notebook_page_reordered_cb), NULL);
571 static void
572 notebook_page_reordered_cb(GtkNotebook *notebook, GtkWidget *child, guint page_num,
573 gpointer user_data)
575 /* Not necessary to update open files treeview if it's sorted.
576 * Note: if enabled, it's best to move the item instead of recreating all items. */
577 /*sidebar_openfiles_update_all();*/
581 /* call this after the number of tabs in main_widgets.notebook changes. */
582 static void tab_count_changed(void)
584 switch (gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)))
586 case 0:
587 /* Enables DnD for dropping files into the empty notebook widget */
588 gtk_drag_dest_set(main_widgets.notebook, GTK_DEST_DEFAULT_ALL,
589 files_drop_targets, G_N_ELEMENTS(files_drop_targets),
590 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_ASK);
591 break;
593 case 1:
594 /* Disables DnD for dropping files into the notebook widget and enables the DnD for moving file
595 * tabs. Files can still be dropped into the notebook widget because it will be handled by the
596 * active Scintilla Widget (only dropping to the tab bar is not possible but it should be ok) */
597 gtk_drag_dest_set(main_widgets.notebook, GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP,
598 drag_targets, G_N_ELEMENTS(drag_targets), GDK_ACTION_MOVE);
599 break;
604 static gboolean notebook_tab_click(GtkWidget *widget, GdkEventButton *event, gpointer data)
606 guint state;
608 /* toggle additional widgets on double click */
609 if (event->type == GDK_2BUTTON_PRESS)
611 if (interface_prefs.notebook_double_click_hides_widgets)
612 on_menu_toggle_all_additional_widgets1_activate(NULL, NULL);
614 return TRUE; /* stop other handlers like notebook_tab_bar_click_cb() */
616 /* close tab on middle click */
617 if (event->button == 2)
619 document_remove_page(gtk_notebook_page_num(GTK_NOTEBOOK(main_widgets.notebook),
620 GTK_WIDGET(data)));
621 return TRUE; /* stop other handlers like notebook_tab_bar_click_cb() */
623 /* switch last used tab on ctrl-click */
624 state = event->state & gtk_accelerator_get_default_mod_mask();
625 if (event->button == 1 && state == GDK_CONTROL_MASK)
627 keybindings_send_command(GEANY_KEY_GROUP_NOTEBOOK,
628 GEANY_KEYS_NOTEBOOK_SWITCHTABLASTUSED);
629 return TRUE;
631 /* right-click is first handled here if it happened on a notebook tab */
632 if (event->button == 3)
634 show_tab_bar_popup_menu(event, data);
635 return TRUE;
638 return FALSE;
642 static void notebook_tab_close_button_style_set(GtkWidget *btn, GtkRcStyle *prev_style,
643 gpointer data)
645 gint w, h;
647 gtk_icon_size_lookup_for_settings(gtk_widget_get_settings(btn), GTK_ICON_SIZE_MENU, &w, &h);
648 gtk_widget_set_size_request(btn, w + 2, h + 2);
652 /* Returns page number of notebook page, or -1 on error */
653 gint notebook_new_tab(GeanyDocument *this)
655 GtkWidget *hbox, *ebox;
656 gint tabnum;
657 GtkWidget *page;
658 gint cur_page;
660 g_return_val_if_fail(this != NULL, -1);
662 page = GTK_WIDGET(this->editor->sci);
664 this->priv->tab_label = gtk_label_new(NULL);
666 /* get button press events for the tab label and the space between it and
667 * the close button, if any */
668 ebox = gtk_event_box_new();
669 GTK_WIDGET_SET_FLAGS(ebox, GTK_NO_WINDOW);
670 g_signal_connect(ebox, "button-press-event", G_CALLBACK(notebook_tab_click), page);
671 /* focus the current document after clicking on a tab */
672 g_signal_connect_after(ebox, "button-release-event",
673 G_CALLBACK(focus_sci), NULL);
675 hbox = gtk_hbox_new(FALSE, 2);
676 gtk_box_pack_start(GTK_BOX(hbox), this->priv->tab_label, FALSE, FALSE, 0);
677 gtk_container_add(GTK_CONTAINER(ebox), hbox);
679 if (file_prefs.show_tab_cross)
681 GtkWidget *image, *btn, *align;
683 btn = gtk_button_new();
684 gtk_button_set_relief(GTK_BUTTON(btn), GTK_RELIEF_NONE);
685 gtk_button_set_focus_on_click(GTK_BUTTON(btn), FALSE);
686 gtk_widget_set_name(btn, "geany-close-tab-button");
688 image = gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
689 gtk_container_add(GTK_CONTAINER(btn), image);
691 align = gtk_alignment_new(1.0, 0.5, 0.0, 0.0);
692 gtk_container_add(GTK_CONTAINER(align), btn);
693 gtk_box_pack_start(GTK_BOX(hbox), align, TRUE, TRUE, 0);
695 g_signal_connect(btn, "clicked", G_CALLBACK(notebook_tab_close_clicked_cb), page);
696 /* button overrides event box, so make middle click on button also close tab */
697 g_signal_connect(btn, "button-press-event", G_CALLBACK(notebook_tab_click), page);
698 /* handle style modification to keep button small as possible even when theme change */
699 g_signal_connect(btn, "style-set", G_CALLBACK(notebook_tab_close_button_style_set), NULL);
702 gtk_widget_show_all(ebox);
704 document_update_tab_label(this);
706 if (file_prefs.tab_order_beside)
707 cur_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(main_widgets.notebook));
708 else
709 cur_page = file_prefs.tab_order_ltr ? -2 /* hack: -2 + 1 = -1, last page */ : 0;
710 if (file_prefs.tab_order_ltr)
711 tabnum = gtk_notebook_insert_page_menu(GTK_NOTEBOOK(main_widgets.notebook), page,
712 ebox, NULL, cur_page + 1);
713 else
714 tabnum = gtk_notebook_insert_page_menu(GTK_NOTEBOOK(main_widgets.notebook), page,
715 ebox, NULL, cur_page);
717 tab_count_changed();
719 /* enable tab DnD */
720 gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(main_widgets.notebook), page, TRUE);
722 return tabnum;
726 static void
727 notebook_tab_close_clicked_cb(GtkButton *button, gpointer user_data)
729 gint cur_page = gtk_notebook_page_num(GTK_NOTEBOOK(main_widgets.notebook),
730 GTK_WIDGET(user_data));
732 document_remove_page(cur_page);
736 /* Always use this instead of gtk_notebook_remove_page(). */
737 void notebook_remove_page(gint page_num)
739 gint page = gtk_notebook_get_current_page(GTK_NOTEBOOK(main_widgets.notebook));
741 if (page_num == page)
743 if (file_prefs.tab_order_ltr)
744 page += 1;
745 else if (page > 0) /* never go negative, it would select the last page */
746 page -= 1;
748 if (file_prefs.tab_close_switch_to_mru)
750 GeanyDocument *last_doc;
752 last_doc = g_queue_peek_nth(mru_docs, 0);
753 if (DOC_VALID(last_doc))
754 page = document_get_notebook_page(last_doc);
757 gtk_notebook_set_current_page(GTK_NOTEBOOK(main_widgets.notebook), page);
760 /* now remove the page (so we don't temporarily switch to the previous page) */
761 gtk_notebook_remove_page(GTK_NOTEBOOK(main_widgets.notebook), page_num);
763 tab_count_changed();
767 static void
768 on_window_drag_data_received(GtkWidget *widget, GdkDragContext *drag_context,
769 gint x, gint y, GtkSelectionData *data, guint target_type,
770 guint event_time, gpointer user_data)
772 gboolean success = FALSE;
773 gint length = gtk_selection_data_get_length(data);
775 if (length > 0 && gtk_selection_data_get_format(data) == 8)
777 document_open_file_list((const gchar *)gtk_selection_data_get_data(data), length);
779 success = TRUE;
781 gtk_drag_finish(drag_context, success, FALSE, event_time);