2006-06-16 11:17:52 +00:00
|
|
|
/*
|
|
|
|
* notebook.c - this file is part of Geany, a fast and lightweight IDE
|
|
|
|
*
|
2008-01-06 18:11:57 +00:00
|
|
|
* Copyright 2006-2008 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
|
|
|
|
* Copyright 2006-2008 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
|
2006-06-16 11:17:52 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public 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.
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*/
|
|
|
|
|
2007-02-24 11:41:56 +00:00
|
|
|
/*
|
|
|
|
* Notebook tab Drag 'n' Drop reordering and tab management.
|
|
|
|
*/
|
|
|
|
|
2006-06-16 11:17:52 +00:00
|
|
|
#include "geany.h"
|
|
|
|
#include "notebook.h"
|
2006-06-25 12:13:35 +00:00
|
|
|
#include "document.h"
|
2008-07-08 16:30:37 +00:00
|
|
|
#include "editor.h"
|
2008-06-02 15:31:59 +00:00
|
|
|
#include "documentprivate.h"
|
2006-09-05 14:24:47 +00:00
|
|
|
#include "ui_utils.h"
|
2006-07-22 14:36:20 +00:00
|
|
|
#include "treeviews.h"
|
2006-12-05 10:37:36 +00:00
|
|
|
#include "support.h"
|
2007-11-11 10:19:50 +00:00
|
|
|
#include "callbacks.h"
|
2006-06-16 11:17:52 +00:00
|
|
|
|
|
|
|
#define GEANY_DND_NOTEBOOK_TAB_TYPE "geany_dnd_notebook_tab"
|
|
|
|
|
2006-07-08 18:23:20 +00:00
|
|
|
static const GtkTargetEntry drag_targets[] =
|
2006-06-16 11:17:52 +00:00
|
|
|
{
|
|
|
|
{GEANY_DND_NOTEBOOK_TAB_TYPE, GTK_TARGET_SAME_APP | GTK_TARGET_SAME_WIDGET, 0}
|
|
|
|
};
|
|
|
|
|
2006-11-21 18:39:23 +00:00
|
|
|
static GtkTargetEntry files_drop_targets[] = {
|
|
|
|
{ "STRING", 0, 0 },
|
|
|
|
{ "UTF8_STRING", 0, 0 },
|
|
|
|
{ "text/plain", 0, 0 },
|
|
|
|
{ "text/uri-list", 0, 0 }
|
|
|
|
};
|
|
|
|
|
2006-06-16 11:17:52 +00:00
|
|
|
|
2006-06-25 12:13:35 +00:00
|
|
|
static gboolean
|
|
|
|
notebook_drag_motion_cb(GtkWidget *widget, GdkDragContext *dc,
|
2007-03-09 13:52:26 +00:00
|
|
|
gint x, gint y, guint event_time, gpointer user_data);
|
2006-06-16 11:17:52 +00:00
|
|
|
|
2006-08-09 11:14:02 +00:00
|
|
|
static void
|
|
|
|
notebook_page_reordered_cb(GtkNotebook *notebook, GtkWidget *child, guint page_num,
|
|
|
|
gpointer user_data);
|
|
|
|
|
2006-07-18 22:01:24 +00:00
|
|
|
#if ! GTK_CHECK_VERSION(2, 8, 0)
|
2006-06-25 12:13:35 +00:00
|
|
|
static gboolean
|
|
|
|
notebook_motion_notify_event_cb(GtkWidget *widget, GdkEventMotion *event,
|
|
|
|
gpointer user_data);
|
2006-07-18 22:01:24 +00:00
|
|
|
#endif
|
2006-06-25 12:13:35 +00:00
|
|
|
|
2006-11-21 18:39:23 +00:00
|
|
|
static void
|
|
|
|
on_window_drag_data_received(GtkWidget *widget, GdkDragContext *drag_context,
|
|
|
|
gint x, gint y, GtkSelectionData *data, guint info,
|
2007-03-09 13:52:26 +00:00
|
|
|
guint event_time, gpointer user_data);
|
2006-11-21 18:39:23 +00:00
|
|
|
|
2006-06-25 12:13:35 +00:00
|
|
|
static gint
|
|
|
|
notebook_find_tab_num_at_pos(GtkNotebook *notebook, gint x, gint y);
|
2006-06-16 11:17:52 +00:00
|
|
|
|
2006-06-25 12:48:38 +00:00
|
|
|
static void
|
|
|
|
notebook_tab_close_clicked_cb(GtkButton *button, gpointer user_data);
|
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
static void setup_tab_dnd(void);
|
2006-08-09 11:14:02 +00:00
|
|
|
|
2006-06-25 12:13:35 +00:00
|
|
|
|
2008-07-30 18:19:19 +00:00
|
|
|
static gboolean focus_sci(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
|
2006-11-03 15:03:57 +00:00
|
|
|
{
|
2008-06-15 13:35:48 +00:00
|
|
|
GeanyDocument *doc = document_get_current();
|
2006-11-03 15:03:57 +00:00
|
|
|
|
2008-07-30 18:19:19 +00:00
|
|
|
if (doc != NULL)
|
|
|
|
gtk_widget_grab_focus(GTK_WIDGET(doc->editor->sci));
|
2006-11-03 15:03:57 +00:00
|
|
|
|
2008-07-30 18:19:19 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean is_position_on_tab_bar(GtkNotebook *notebook, GdkEventButton *event)
|
|
|
|
{
|
|
|
|
GtkWidget *page;
|
|
|
|
GtkWidget *tab;
|
|
|
|
GtkPositionType tab_pos;
|
|
|
|
|
|
|
|
page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(main_widgets.notebook), 0);
|
|
|
|
g_return_val_if_fail(page != NULL, FALSE);
|
|
|
|
|
|
|
|
tab = gtk_notebook_get_tab_label(GTK_NOTEBOOK(main_widgets.notebook), page);
|
|
|
|
g_return_val_if_fail(tab != NULL, FALSE);
|
|
|
|
|
|
|
|
tab_pos = gtk_notebook_get_tab_pos(GTK_NOTEBOOK(main_widgets.notebook));
|
|
|
|
|
|
|
|
switch (tab_pos)
|
|
|
|
{
|
|
|
|
case GTK_POS_TOP:
|
|
|
|
case GTK_POS_BOTTOM:
|
|
|
|
{
|
|
|
|
if (event->y >= 0 && event->y <= tab->allocation.height)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
case GTK_POS_LEFT:
|
|
|
|
case GTK_POS_RIGHT:
|
|
|
|
{
|
|
|
|
if (event->x >= 0 && event->x <= tab->allocation.width)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean notebook_tab_bar_click_cb(GtkWidget *widget, GdkEventButton *event,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
if (event->type == GDK_2BUTTON_PRESS)
|
|
|
|
{
|
|
|
|
/* accessing ::event_window is a little hacky but we need to make sure the click
|
|
|
|
* was in the tab bar and not inside the child */
|
|
|
|
if (event->window != GTK_NOTEBOOK(main_widgets.notebook)->event_window)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (! is_position_on_tab_bar(GTK_NOTEBOOK(widget), event))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
document_new_file(NULL, NULL, NULL);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2006-11-03 15:03:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-16 11:17:52 +00:00
|
|
|
void notebook_init()
|
2006-08-09 11:14:02 +00:00
|
|
|
{
|
2008-07-30 18:19:19 +00:00
|
|
|
g_signal_connect_after(main_widgets.notebook, "button-press-event",
|
|
|
|
G_CALLBACK(notebook_tab_bar_click_cb), NULL);
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* focus the current document after clicking on a tab */
|
2008-07-18 13:40:48 +00:00
|
|
|
g_signal_connect_after(main_widgets.notebook, "button-release-event",
|
2006-11-03 15:03:57 +00:00
|
|
|
G_CALLBACK(focus_sci), NULL);
|
|
|
|
|
2008-07-18 13:40:48 +00:00
|
|
|
g_signal_connect(main_widgets.notebook, "drag-data-received",
|
2006-11-21 18:39:23 +00:00
|
|
|
G_CALLBACK(on_window_drag_data_received), NULL);
|
|
|
|
|
2006-08-09 11:14:02 +00:00
|
|
|
setup_tab_dnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void setup_tab_dnd()
|
2006-06-16 11:17:52 +00:00
|
|
|
{
|
2008-05-22 14:41:28 +00:00
|
|
|
GtkWidget *notebook = main_widgets.notebook;
|
2006-06-16 11:17:52 +00:00
|
|
|
|
2006-08-09 11:14:02 +00:00
|
|
|
/* Due to a segfault with manual tab DnD setup on GTK 2.10, we must
|
|
|
|
* use the built in gtk_notebook_set_tab_reorderable from GTK 2.10.
|
|
|
|
* This means a binary compiled against < 2.10 but run on >= 2.10
|
|
|
|
* will not have tab DnD support, but this is necessary until
|
|
|
|
* there is a fix for the older tab DnD code or GTK 2.10. */
|
2008-02-27 13:17:29 +00:00
|
|
|
if (gtk_check_version(2, 10, 0) == NULL) /* null means version ok */
|
2006-08-09 11:14:02 +00:00
|
|
|
{
|
|
|
|
#if GTK_CHECK_VERSION(2, 10, 0)
|
2008-07-18 13:40:48 +00:00
|
|
|
g_signal_connect(notebook, "page-reordered", G_CALLBACK(notebook_page_reordered_cb), NULL);
|
2006-08-09 11:14:02 +00:00
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
2006-06-16 11:17:52 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* Set up drag movement callback */
|
2008-07-18 13:40:48 +00:00
|
|
|
g_signal_connect(notebook, "drag-motion", G_CALLBACK(notebook_drag_motion_cb), NULL);
|
2006-06-16 11:17:52 +00:00
|
|
|
|
2006-08-09 11:14:02 +00:00
|
|
|
/* There is a bug on GTK 2.6 with drag reordering of notebook tabs.
|
|
|
|
* Clicking (not dragging) on a notebook tab, then making a selection in the
|
|
|
|
* Scintilla widget will cause a strange selection bug.
|
|
|
|
* It seems there is a conflict; the drag cursor is shown,
|
|
|
|
* and the selection is blocked; however, when releasing the
|
|
|
|
* mouse button, the selection continues.
|
|
|
|
* Bug is present with gtk+2.6.8, not gtk+2.8.x - ntrel */
|
2006-06-25 12:13:35 +00:00
|
|
|
#if ! GTK_CHECK_VERSION(2, 8, 0)
|
2008-02-27 13:17:29 +00:00
|
|
|
/* handle higher gtk+ runtime than build environment */
|
|
|
|
if (gtk_check_version(2, 8, 0) != NULL) /* null means version ok */
|
2006-07-24 17:30:08 +00:00
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
/* workaround GTK+2.6 drag start bug when over sci widget: */
|
2006-08-09 11:14:02 +00:00
|
|
|
gtk_widget_add_events(notebook, GDK_POINTER_MOTION_MASK);
|
2008-07-18 13:40:48 +00:00
|
|
|
g_signal_connect(notebook, "motion-notify-event",
|
2006-07-24 17:30:08 +00:00
|
|
|
G_CALLBACK(notebook_motion_notify_event_cb), NULL);
|
|
|
|
}
|
2006-06-25 12:13:35 +00:00
|
|
|
#endif
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* set up drag motion for moving notebook pages */
|
2006-06-16 11:17:52 +00:00
|
|
|
gtk_drag_dest_set(notebook, GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP,
|
|
|
|
drag_targets, G_N_ELEMENTS(drag_targets), GDK_ACTION_MOVE);
|
2008-02-27 13:17:29 +00:00
|
|
|
/* set drag source, but for GTK+2.6 it's changed in motion-notify-event handler */
|
2006-06-25 12:13:35 +00:00
|
|
|
gtk_drag_source_set(notebook, GDK_BUTTON1_MASK,
|
|
|
|
drag_targets, G_N_ELEMENTS(drag_targets), GDK_ACTION_MOVE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-08 18:23:20 +00:00
|
|
|
#if ! GTK_CHECK_VERSION(2, 8, 0)
|
2006-08-09 11:14:02 +00:00
|
|
|
/* This is used to disable tab DnD when the cursor is over the
|
|
|
|
* Scintilla widget, and re-enable tab DnD when over the notebook tabs
|
|
|
|
*/
|
2006-06-25 12:13:35 +00:00
|
|
|
static gboolean
|
|
|
|
notebook_motion_notify_event_cb(GtkWidget *widget, GdkEventMotion *event,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
static gboolean drag_enabled = TRUE; /* stores current state */
|
2008-05-22 14:41:28 +00:00
|
|
|
GtkWidget *page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(main_widgets.notebook),
|
|
|
|
gtk_notebook_get_current_page(GTK_NOTEBOOK(main_widgets.notebook)));
|
2006-06-25 12:13:35 +00:00
|
|
|
|
|
|
|
if (page == NULL || event->x < 0 || event->y < 0) return FALSE;
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
if (event->window == page->window) /* cursor over sci widget */
|
2006-06-25 12:13:35 +00:00
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
if (drag_enabled) gtk_drag_source_unset(widget); /* disable */
|
2006-06-25 12:13:35 +00:00
|
|
|
drag_enabled = FALSE;
|
|
|
|
}
|
2008-02-27 13:17:29 +00:00
|
|
|
else /* assume cursor over notebook tab */
|
2006-06-25 12:13:35 +00:00
|
|
|
{
|
|
|
|
if (! drag_enabled)
|
|
|
|
gtk_drag_source_set(widget, GDK_BUTTON1_MASK,
|
|
|
|
drag_targets, G_N_ELEMENTS(drag_targets), GDK_ACTION_MOVE);
|
|
|
|
drag_enabled = TRUE;
|
|
|
|
}
|
2008-02-27 13:17:29 +00:00
|
|
|
return FALSE; /* propagate event */
|
2006-06-16 11:17:52 +00:00
|
|
|
}
|
2006-07-08 18:23:20 +00:00
|
|
|
#endif
|
2006-06-16 11:17:52 +00:00
|
|
|
|
|
|
|
|
2006-08-09 11:14:02 +00:00
|
|
|
static void
|
|
|
|
notebook_page_reordered_cb(GtkNotebook *notebook, GtkWidget *child, guint page_num,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2007-03-14 12:11:50 +00:00
|
|
|
/* Not necessary to update open files treeview if it's sorted.
|
|
|
|
* Note: if enabled, it's best to move the item instead of recreating all items. */
|
2008-02-27 13:17:29 +00:00
|
|
|
/*treeviews_openfiles_update_all();*/
|
2006-08-09 11:14:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-25 12:13:35 +00:00
|
|
|
static gboolean
|
2006-06-16 11:17:52 +00:00
|
|
|
notebook_drag_motion_cb(GtkWidget *widget, GdkDragContext *dc,
|
2007-03-09 13:52:26 +00:00
|
|
|
gint x, gint y, guint event_time, gpointer user_data)
|
2006-06-16 11:17:52 +00:00
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
static gint oldx, oldy; /* for determining direction of mouse drag */
|
2007-03-09 13:52:26 +00:00
|
|
|
GtkNotebook *notebook = GTK_NOTEBOOK(widget);
|
2006-06-16 11:17:52 +00:00
|
|
|
gint ndest = notebook_find_tab_num_at_pos(notebook, x, y);
|
|
|
|
gint ncurr = gtk_notebook_get_current_page(notebook);
|
|
|
|
|
2007-03-09 13:52:26 +00:00
|
|
|
if (ndest >= 0 && ndest != ncurr)
|
2006-06-16 11:17:52 +00:00
|
|
|
{
|
|
|
|
gboolean ok = FALSE;
|
2008-02-27 13:17:29 +00:00
|
|
|
/* prevent oscillation between non-homogeneous sized tabs */
|
2006-06-16 11:17:52 +00:00
|
|
|
switch(gtk_notebook_get_tab_pos(notebook))
|
|
|
|
{
|
2007-01-12 16:56:23 +00:00
|
|
|
case GTK_POS_LEFT:
|
|
|
|
case GTK_POS_RIGHT:
|
|
|
|
ok = ((ndest > ncurr) && (y > oldy)) || ((ndest < ncurr) && (y < oldy));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_POS_TOP:
|
|
|
|
case GTK_POS_BOTTOM:
|
|
|
|
ok = ((ndest > ncurr) && (x > oldx)) || ((ndest < ncurr) && (x < oldx));
|
|
|
|
break;
|
2006-06-16 11:17:52 +00:00
|
|
|
}
|
|
|
|
|
2006-07-22 14:36:20 +00:00
|
|
|
if (ok)
|
|
|
|
{
|
|
|
|
gtk_notebook_reorder_child(notebook,
|
|
|
|
gtk_notebook_get_nth_page(notebook, ncurr), ndest);
|
2006-08-09 11:14:02 +00:00
|
|
|
notebook_page_reordered_cb(NULL, NULL, ndest, NULL);
|
2006-07-22 14:36:20 +00:00
|
|
|
}
|
2006-06-16 11:17:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
oldx = x; oldy = y;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-25 12:13:35 +00:00
|
|
|
/* Adapted from Epiphany absolute version in ephy-notebook.c, thanks.
|
|
|
|
* x,y are co-ordinates local to the notebook (not including border padding)
|
|
|
|
* notebook tab label widgets must not be NULL.
|
|
|
|
* N.B. This only checks the dimension that the tabs are in,
|
|
|
|
* e.g. for GTK_POS_TOP it does not check the y coordinate. */
|
|
|
|
static gint
|
|
|
|
notebook_find_tab_num_at_pos(GtkNotebook *notebook, gint x, gint y)
|
2006-06-16 11:17:52 +00:00
|
|
|
{
|
|
|
|
GtkPositionType tab_pos;
|
|
|
|
int page_num = 0;
|
|
|
|
GtkWidget *page;
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* deal with less than 2 pages */
|
2006-06-16 11:17:52 +00:00
|
|
|
switch(gtk_notebook_get_n_pages(notebook))
|
|
|
|
{case 0: return -1; case 1: return 0;}
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
tab_pos = gtk_notebook_get_tab_pos(notebook); /* which edge */
|
2006-06-16 11:17:52 +00:00
|
|
|
|
|
|
|
while ((page = gtk_notebook_get_nth_page(notebook, page_num)))
|
|
|
|
{
|
|
|
|
gint max_x, max_y;
|
|
|
|
GtkWidget *tab = gtk_notebook_get_tab_label(notebook, page);
|
|
|
|
|
|
|
|
g_return_val_if_fail(tab != NULL, -1);
|
|
|
|
|
|
|
|
if (!GTK_WIDGET_MAPPED(GTK_WIDGET(tab)))
|
2008-02-27 13:17:29 +00:00
|
|
|
{ /* skip hidden tabs, e.g. tabs scrolled out of view */
|
2006-06-16 11:17:52 +00:00
|
|
|
page_num++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* subtract notebook pos to remove possible border padding */
|
2008-07-30 18:19:19 +00:00
|
|
|
max_x = tab->allocation.x + tab->allocation.width - GTK_WIDGET(notebook)->allocation.x;
|
|
|
|
max_y = tab->allocation.y + tab->allocation.height - GTK_WIDGET(notebook)->allocation.y;
|
|
|
|
|
|
|
|
if (((tab_pos == GTK_POS_TOP) || (tab_pos == GTK_POS_BOTTOM)) && (x<=max_x))
|
|
|
|
return page_num;
|
|
|
|
else if (((tab_pos == GTK_POS_LEFT) || (tab_pos == GTK_POS_RIGHT)) && (y<=max_y))
|
|
|
|
return page_num;
|
2006-06-16 11:17:52 +00:00
|
|
|
|
|
|
|
page_num++;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2006-06-25 12:13:35 +00:00
|
|
|
|
|
|
|
|
2008-05-22 14:41:28 +00:00
|
|
|
/* call this after the number of tabs in main_widgets.notebook changes. */
|
2008-02-20 11:24:23 +00:00
|
|
|
static void tab_count_changed(void)
|
2006-11-22 16:07:18 +00:00
|
|
|
{
|
2008-05-22 14:41:28 +00:00
|
|
|
switch (gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)))
|
2006-11-22 16:07:18 +00:00
|
|
|
{
|
2006-11-23 16:06:54 +00:00
|
|
|
case 0:
|
2006-11-22 16:07:18 +00:00
|
|
|
/* Enables DnD for dropping files into the empty notebook widget */
|
2008-05-22 14:41:28 +00:00
|
|
|
gtk_drag_dest_set(main_widgets.notebook, GTK_DEST_DEFAULT_ALL,
|
2006-11-22 16:07:18 +00:00
|
|
|
files_drop_targets, G_N_ELEMENTS(files_drop_targets),
|
|
|
|
GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_ASK);
|
2006-11-23 16:06:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
2006-11-22 16:07:18 +00:00
|
|
|
/* Disables DnD for dropping files into the notebook widget and enables the DnD for moving file
|
|
|
|
* tabs. Files can still be dropped into the notebook widget because it will be handled by the
|
|
|
|
* active Scintilla Widget (only dropping to the tab bar is not possible but it should be ok) */
|
2008-05-22 14:41:28 +00:00
|
|
|
gtk_drag_dest_set(main_widgets.notebook, GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP,
|
2006-11-22 16:07:18 +00:00
|
|
|
drag_targets, G_N_ELEMENTS(drag_targets), GDK_ACTION_MOVE);
|
2006-11-23 16:06:54 +00:00
|
|
|
break;
|
2006-11-22 16:07:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-30 18:19:19 +00:00
|
|
|
|
|
|
|
static gboolean notebook_tab_label_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
|
2007-11-11 10:19:50 +00:00
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
/* toggle additional widgets on double click */
|
2007-11-11 10:19:50 +00:00
|
|
|
if (event->type == GDK_2BUTTON_PRESS)
|
2008-07-30 18:19:19 +00:00
|
|
|
{
|
2007-11-11 10:19:50 +00:00
|
|
|
on_menu_toggle_all_additional_widgets1_activate(NULL, NULL);
|
2008-07-30 18:19:19 +00:00
|
|
|
return TRUE; /* stop other handlers like notebook_tab_bar_click_cb() */
|
|
|
|
}
|
2008-02-27 13:17:29 +00:00
|
|
|
/* close tab on middle click */
|
2007-11-11 10:19:50 +00:00
|
|
|
if (event->button == 2)
|
2008-07-30 18:19:19 +00:00
|
|
|
{
|
2008-06-15 13:35:48 +00:00
|
|
|
document_remove_page(gtk_notebook_page_num(GTK_NOTEBOOK(main_widgets.notebook),
|
|
|
|
GTK_WIDGET(user_data)));
|
2008-07-30 18:19:19 +00:00
|
|
|
return TRUE; /* stop other handlers like notebook_tab_bar_click_cb() */
|
|
|
|
}
|
2007-11-11 10:19:50 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2006-11-22 16:07:18 +00:00
|
|
|
|
2006-12-05 10:37:36 +00:00
|
|
|
/* Returns page number of notebook page, or -1 on error */
|
2008-06-15 13:35:48 +00:00
|
|
|
gint notebook_new_tab(GeanyDocument *this)
|
2006-06-25 12:13:35 +00:00
|
|
|
{
|
2007-11-11 10:19:50 +00:00
|
|
|
GtkWidget *hbox, *ebox;
|
2006-06-25 12:13:35 +00:00
|
|
|
gint tabnum;
|
2006-12-05 10:37:36 +00:00
|
|
|
gchar *title;
|
2008-06-02 15:31:59 +00:00
|
|
|
Document *fdoc = DOCUMENT(this);
|
2006-12-05 10:37:36 +00:00
|
|
|
GtkWidget *page;
|
2006-06-25 12:13:35 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
g_return_val_if_fail(this != NULL, -1);
|
2006-06-25 12:13:35 +00:00
|
|
|
|
2008-07-14 11:13:54 +00:00
|
|
|
page = GTK_WIDGET(this->editor->sci);
|
2008-06-15 13:35:48 +00:00
|
|
|
title = g_path_get_basename(DOC_FILENAME(this));
|
2006-12-05 10:37:36 +00:00
|
|
|
|
2008-06-02 15:31:59 +00:00
|
|
|
fdoc->tab_label = gtk_label_new(title);
|
2006-06-25 12:13:35 +00:00
|
|
|
|
2007-11-11 10:19:50 +00:00
|
|
|
ebox = gtk_event_box_new();
|
|
|
|
GTK_WIDGET_SET_FLAGS(ebox, GTK_NO_WINDOW);
|
2008-07-18 13:40:48 +00:00
|
|
|
g_signal_connect(ebox, "button-press-event", G_CALLBACK(notebook_tab_label_cb), page);
|
2007-11-11 10:19:50 +00:00
|
|
|
|
2007-10-01 11:46:19 +00:00
|
|
|
hbox = gtk_hbox_new(FALSE, 2);
|
2008-06-02 15:31:59 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(ebox), fdoc->tab_label);
|
2007-11-11 10:19:50 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), ebox, FALSE, FALSE, 0);
|
2006-06-25 12:13:35 +00:00
|
|
|
|
2008-05-16 12:08:39 +00:00
|
|
|
if (file_prefs.show_tab_cross)
|
2007-08-25 14:16:52 +00:00
|
|
|
{
|
2007-10-01 11:46:19 +00:00
|
|
|
GtkWidget *image, *btn, *align;
|
2007-10-02 14:23:11 +00:00
|
|
|
GtkRcStyle *rcstyle;
|
|
|
|
GtkRequisition size;
|
2007-10-01 11:46:19 +00:00
|
|
|
|
|
|
|
btn = gtk_button_new();
|
|
|
|
gtk_button_set_relief(GTK_BUTTON(btn), GTK_RELIEF_NONE);
|
|
|
|
|
|
|
|
/* don't allow focus on the close button */
|
|
|
|
gtk_button_set_focus_on_click(GTK_BUTTON(btn), FALSE);
|
|
|
|
|
2007-10-02 14:23:11 +00:00
|
|
|
/* make it as small as possible */
|
|
|
|
rcstyle = gtk_rc_style_new();
|
|
|
|
rcstyle->xthickness = rcstyle->ythickness = 0;
|
|
|
|
gtk_widget_modify_style(btn, rcstyle);
|
|
|
|
gtk_rc_style_unref(rcstyle);
|
|
|
|
|
2007-10-01 11:46:19 +00:00
|
|
|
image = gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
|
2007-10-02 14:23:11 +00:00
|
|
|
gtk_widget_size_request(image, &size);
|
|
|
|
gtk_widget_set_size_request(btn, size.width, size.height);
|
2007-10-01 11:46:19 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(btn), image);
|
2007-08-25 14:16:52 +00:00
|
|
|
|
|
|
|
align = gtk_alignment_new(1.0, 0.0, 0.0, 0.0);
|
2007-10-01 11:46:19 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(align), btn);
|
2007-08-25 14:16:52 +00:00
|
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), align, TRUE, TRUE, 0);
|
|
|
|
|
2008-07-18 13:40:48 +00:00
|
|
|
g_signal_connect(btn, "clicked", G_CALLBACK(notebook_tab_close_clicked_cb), page);
|
2007-08-25 14:16:52 +00:00
|
|
|
}
|
2006-06-25 12:13:35 +00:00
|
|
|
|
|
|
|
gtk_widget_show_all(hbox);
|
|
|
|
|
2008-06-02 15:31:59 +00:00
|
|
|
fdoc->tabmenu_label = gtk_label_new(title);
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(fdoc->tabmenu_label), 0.0, 0);
|
2006-06-25 12:13:35 +00:00
|
|
|
|
2008-05-16 12:08:39 +00:00
|
|
|
if (file_prefs.tab_order_ltr)
|
2008-05-22 14:41:28 +00:00
|
|
|
tabnum = gtk_notebook_append_page_menu(GTK_NOTEBOOK(main_widgets.notebook), page,
|
2008-06-02 15:31:59 +00:00
|
|
|
hbox, fdoc->tabmenu_label);
|
2006-06-25 12:13:35 +00:00
|
|
|
else
|
2008-05-22 14:41:28 +00:00
|
|
|
tabnum = gtk_notebook_insert_page_menu(GTK_NOTEBOOK(main_widgets.notebook), page,
|
2008-06-02 15:31:59 +00:00
|
|
|
hbox, fdoc->tabmenu_label, 0);
|
2006-06-25 12:13:35 +00:00
|
|
|
|
2006-11-22 16:07:18 +00:00
|
|
|
tab_count_changed();
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* This is where tab DnD is enabled for GTK 2.10 and higher */
|
2006-08-09 11:14:02 +00:00
|
|
|
#if GTK_CHECK_VERSION(2, 10, 0)
|
2008-02-27 13:17:29 +00:00
|
|
|
if (gtk_check_version(2, 10, 0) == NULL) /* null means version ok */
|
2006-08-09 11:14:02 +00:00
|
|
|
{
|
2008-05-22 14:41:28 +00:00
|
|
|
gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(main_widgets.notebook), page, TRUE);
|
2006-08-09 11:14:02 +00:00
|
|
|
}
|
|
|
|
#endif
|
2006-12-05 10:37:36 +00:00
|
|
|
g_free(title);
|
2006-06-25 12:13:35 +00:00
|
|
|
return tabnum;
|
|
|
|
}
|
|
|
|
|
2006-06-25 12:48:38 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
notebook_tab_close_clicked_cb(GtkButton *button, gpointer user_data)
|
|
|
|
{
|
2008-05-22 14:41:28 +00:00
|
|
|
gint cur_page = gtk_notebook_page_num(GTK_NOTEBOOK(main_widgets.notebook),
|
2006-06-25 12:48:38 +00:00
|
|
|
GTK_WIDGET(user_data));
|
2008-05-29 17:00:54 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
document_remove_page(cur_page);
|
2006-06-25 12:48:38 +00:00
|
|
|
}
|
2006-11-21 18:39:23 +00:00
|
|
|
|
|
|
|
|
2008-02-25 17:02:23 +00:00
|
|
|
/* Always use this instead of gtk_notebook_remove_page(). */
|
2006-11-22 16:07:18 +00:00
|
|
|
void notebook_remove_page(gint page_num)
|
2006-11-21 18:39:23 +00:00
|
|
|
{
|
2008-05-22 14:41:28 +00:00
|
|
|
gint curpage = gtk_notebook_get_current_page(GTK_NOTEBOOK(main_widgets.notebook));
|
2008-02-25 17:02:23 +00:00
|
|
|
|
|
|
|
/* Focus the next page, not the previous */
|
2008-05-16 12:08:39 +00:00
|
|
|
if (curpage == page_num && file_prefs.tab_order_ltr)
|
2008-02-25 17:02:23 +00:00
|
|
|
{
|
2008-05-22 14:41:28 +00:00
|
|
|
gtk_notebook_set_current_page(GTK_NOTEBOOK(main_widgets.notebook), curpage + 1);
|
2008-02-25 17:02:23 +00:00
|
|
|
}
|
2008-03-21 13:05:47 +00:00
|
|
|
|
|
|
|
/* now remove the page (so we don't temporarily switch to the previous page) */
|
2008-05-22 14:41:28 +00:00
|
|
|
gtk_notebook_remove_page(GTK_NOTEBOOK(main_widgets.notebook), page_num);
|
2008-03-21 13:05:47 +00:00
|
|
|
|
|
|
|
tab_count_changed();
|
2006-11-21 18:39:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_window_drag_data_received(GtkWidget *widget, GdkDragContext *drag_context,
|
|
|
|
gint x, gint y, GtkSelectionData *data, guint target_type,
|
2007-03-09 13:52:26 +00:00
|
|
|
guint event_time, gpointer user_data)
|
2006-11-21 18:39:23 +00:00
|
|
|
{
|
|
|
|
gboolean success = FALSE;
|
|
|
|
|
|
|
|
if (data->length > 0 && data->format == 8)
|
|
|
|
{
|
|
|
|
if (drag_context->action == GDK_ACTION_ASK)
|
|
|
|
{
|
|
|
|
drag_context->action = GDK_ACTION_COPY;
|
|
|
|
}
|
|
|
|
|
|
|
|
document_open_file_list((const gchar *)data->data, data->length);
|
|
|
|
|
|
|
|
success = TRUE;
|
|
|
|
}
|
2007-03-09 13:52:26 +00:00
|
|
|
gtk_drag_finish(drag_context, success, FALSE, event_time);
|
2006-11-21 18:39:23 +00:00
|
|
|
}
|
|
|
|
|
2006-11-22 16:07:18 +00:00
|
|
|
|