Removed DnD handler for the main window (not very useful).

Fixed broken tab reordering by only enabling DnD for dropping files when there are no open file tabs, otherwise disable it and enable DnD for moving file tabs. Dropping files into Geany when file tabs are open still works because then it is handled by the Scintilla widget.


git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@1015 ea778897-0a13-0410-b9d1-a72fbfd435f5
master
Enrico Tröger 2006-11-21 18:39:23 +00:00
parent fef33d6da5
commit 4306f9091a
7 changed files with 91 additions and 51 deletions

View File

@ -1,3 +1,15 @@
2006-11-21 Enrico Tröger <enrico.troeger@uvena.de>
* src/callbacks.c, src/callbacks.h, src/document.c, src/main.c,
src/notebook.c, src/notebook.h:
Removed DnD handler for the main window (not very useful).
Fixed broken tab reordering by only enabling DnD for dropping files
when there are no open file tabs, otherwise disable it and enable
DnD for moving file tabs. Dropping files into Geany when file tabs
are open still works because then it is handled by the Scintilla
widget.
2006-11-18 Nick Treleaven <nick.treleaven@btinternet.com>
* src/sciwrappers.c, src/sciwrappers.h:

View File

@ -2067,26 +2067,3 @@ on_menu_decrease_indent1_activate (GtkMenuItem *menuitem,
}
}
void
on_window_drag_data_received
(GtkWidget *widget, GdkDragContext *drag_context,
gint x, gint y, GtkSelectionData *data, guint info,
guint time, gpointer user_data)
{
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;
}
gtk_drag_finish(drag_context, success, FALSE, time);
}

View File

@ -551,9 +551,3 @@ void
on_menu_toggle_line_commentation1_activate
(GtkMenuItem *menuitem,
gpointer user_data);
void
on_window_drag_data_received
(GtkWidget *widget, GdkDragContext *drag_context,
gint x, gint y, GtkSelectionData *data, guint info,
guint time, gpointer user_data);

View File

@ -257,8 +257,15 @@ static gint document_create_new_sci(const gchar *filename)
gint new_idx;
document *this;
gint tabnum;
gint cur_pages = gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook));
if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)) == 1)
if (cur_pages == 0)
{
// now we get the first file tab so enable moving of file tabs and
// disable Dnd for dropping files
notebook_disable_dnd_for_dropping_files();
}
else if (cur_pages == 1)
{
gint idx = document_get_cur_idx();
// remove the empty document and open a new one
@ -380,6 +387,10 @@ gboolean document_remove(guint page_num)
document_undo_clear(idx);
if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)) == 0)
{
// no more open file tabs so disable moving of file tabs and
// enable Dnd for dropping files
notebook_enable_dnd_for_dropping_files();
ui_update_tag_list(-1, FALSE);
//on_notebook1_switch_page(GTK_NOTEBOOK(app->notebook), NULL, 0, NULL);
ui_set_window_title(-1);
@ -1007,7 +1018,7 @@ gint document_find_text(gint idx, const gchar *text, gint flags, gboolean search
if (flags & SCFIND_REGEXP) search_backwards = FALSE;
first_visible_line = sci_get_first_visible_line(doc_list[idx].sci);
selection_start = sci_get_selection_start(doc_list[idx].sci);
selection_end = sci_get_selection_end(doc_list[idx].sci);
if ((selection_end - selection_start) > 0)

View File

@ -554,26 +554,6 @@ gint main(gint argc, gchar **argv)
g_signal_connect(G_OBJECT(app->window), "key-press-event", G_CALLBACK(on_window_key_press_event), NULL);
g_signal_connect(G_OBJECT(app->toolbar), "button-press-event", G_CALLBACK(toolbar_popup_menu), NULL);
/* enable DnD files somewhere in the main window */
{
GtkTargetEntry targets[] = {
{ "STRING", 0, 0 },
{ "UTF8_STRING", 0, 0 },
{ "text/plain", 0, 0 },
{ "text/uri-list", 0, 0 }
};
gtk_drag_dest_set(app->window, GTK_DEST_DEFAULT_ALL, targets,
G_N_ELEMENTS(targets),
GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_ASK);
gtk_drag_dest_set(app->notebook, GTK_DEST_DEFAULT_ALL, targets,
G_N_ELEMENTS(targets),
GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_ASK);
g_signal_connect(G_OBJECT(app->window), "drag-data-received",
G_CALLBACK(on_window_drag_data_received), NULL);
g_signal_connect(G_OBJECT(app->notebook), "drag-data-received",
G_CALLBACK(on_window_drag_data_received), NULL);
}
treeviews_prepare_openfiles();
treeviews_create_taglist_popup_menu();
treeviews_create_openfiles_popup_menu();

View File

@ -34,6 +34,13 @@ static const GtkTargetEntry drag_targets[] =
{GEANY_DND_NOTEBOOK_TAB_TYPE, GTK_TARGET_SAME_APP | GTK_TARGET_SAME_WIDGET, 0}
};
static GtkTargetEntry files_drop_targets[] = {
{ "STRING", 0, 0 },
{ "UTF8_STRING", 0, 0 },
{ "text/plain", 0, 0 },
{ "text/uri-list", 0, 0 }
};
static gboolean
notebook_drag_motion_cb(GtkWidget *widget, GdkDragContext *dc,
@ -49,6 +56,11 @@ notebook_motion_notify_event_cb(GtkWidget *widget, GdkEventMotion *event,
gpointer user_data);
#endif
static void
on_window_drag_data_received(GtkWidget *widget, GdkDragContext *drag_context,
gint x, gint y, GtkSelectionData *data, guint info,
guint time, gpointer user_data);
static gint
notebook_find_tab_num_at_pos(GtkNotebook *notebook, gint x, gint y);
@ -74,6 +86,9 @@ void notebook_init()
g_signal_connect_after(G_OBJECT(app->notebook), "button-release-event",
G_CALLBACK(focus_sci), NULL);
g_signal_connect(G_OBJECT(app->notebook), "drag-data-received",
G_CALLBACK(on_window_drag_data_received), NULL);
setup_tab_dnd();
}
@ -315,3 +330,46 @@ notebook_tab_close_clicked_cb(GtkButton *button, gpointer user_data)
GTK_WIDGET(user_data));
document_remove(cur_page);
}
/* Enables DnD for dropping files into the empty notebook widget */
void notebook_enable_dnd_for_dropping_files()
{
gtk_drag_dest_set(app->notebook, GTK_DEST_DEFAULT_ALL,
files_drop_targets, G_N_ELEMENTS(files_drop_targets),
GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_ASK);
}
/* 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) */
void notebook_disable_dnd_for_dropping_files()
{
gtk_drag_dest_set(app->notebook, GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP,
drag_targets, G_N_ELEMENTS(drag_targets), GDK_ACTION_MOVE);
}
static void
on_window_drag_data_received(GtkWidget *widget, GdkDragContext *drag_context,
gint x, gint y, GtkSelectionData *data, guint target_type,
guint time, gpointer user_data)
{
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;
}
gtk_drag_finish(drag_context, success, FALSE, time);
}

View File

@ -29,4 +29,12 @@ void notebook_init();
/* Returns index of notebook page, or -1 on error */
gint notebook_new_tab(gint doc_idx, gchar *title, GtkWidget *page);
/* Enables DnD for dropping files into the empty notebook widget */
void notebook_enable_dnd_for_dropping_files();
/* 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) */
void notebook_disable_dnd_for_dropping_files();
#endif