[Xfce4-commits] <mousepad:master> * mousepad/mousepad-{document, window}.c: Allow uri and tab drops inside the textview widget. * mousepad/mousepad-window.c: Hide the searchbar when all the tabs are closed and make sure nothing segfaults when no active document is found. * mousepad/mousepad-window.c: Make sure the textview is focused when a new document has been added.
Nick Schermer
noreply at xfce.org
Sat May 5 21:30:27 CEST 2012
Updating branch refs/heads/master
to 72d49ecc7196fe7c8d5479e978593718e3b17a39 (commit)
from 2beb0bf4ad103e2bc112b516f6253157e821e2a7 (commit)
commit 72d49ecc7196fe7c8d5479e978593718e3b17a39
Author: Nick Schermer <nick at xfce.org>
Date: Tue May 1 15:59:28 2007 +0000
* mousepad/mousepad-{document,window}.c: Allow uri and tab
drops inside the textview widget.
* mousepad/mousepad-window.c: Hide the searchbar when all the
tabs are closed and make sure nothing segfaults when no
active document is found.
* mousepad/mousepad-window.c: Make sure the textview is
focused when a new document has been added.
(Old svn revision: 25661)
ChangeLog | 10 ++
TODO | 2 -
mousepad/mousepad-document.c | 51 +++++++++--
mousepad/mousepad-view.c | 8 +-
mousepad/mousepad-window.c | 205 +++++++++++++++++++++++-------------------
mousepad/mousepad-window.h | 12 +++
6 files changed, 180 insertions(+), 108 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index dfa8d47..f9de9f2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2007-05-01 Nick Schermer <nick at xfce.org>
+ * mousepad/mousepad-{document,window}.c: Allow uri and tab
+ drops inside the textview widget.
+ * mousepad/mousepad-window.c: Hide the searchbar when all the
+ tabs are closed and make sure nothing segfaults when no
+ active document is found.
+ * mousepad/mousepad-window.c: Make sure the textview is
+ focused when a new document has been added.
+
+
2007-04-28 Nick Schermer <nick at xfce.org>
* TODO: Removed the items I've fixed.
* Changelog: Break after 70 characters.
diff --git a/TODO b/TODO
index 21da6cc..fe0db97 100644
--- a/TODO
+++ b/TODO
@@ -13,8 +13,6 @@ Interface
- Tab font color when the file is modified or read only.
- Test the application with a screen reader and add Atk objects
where needed.
-- Allow dropping of tabs and uri's inside the textview, menubar
- and statusbar is already possible.
- Cleanup the menus and make them consistent. For example: we're
using both file and document atm. The name of the Go menu should
also be changed to something more descriptive.
diff --git a/mousepad/mousepad-document.c b/mousepad/mousepad-document.c
index d7d7c1f..de38641 100644
--- a/mousepad/mousepad-document.c
+++ b/mousepad/mousepad-document.c
@@ -65,6 +65,14 @@ static void mousepad_document_notify_cursor_position (GtkTextBuffer
static void mousepad_document_toggle_overwrite (GtkTextView *textview,
GParamSpec *pspec,
MousepadDocument *document);
+static void mousepad_document_drag_data_received (GtkWidget *widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time,
+ MousepadDocument *document);
static void mousepad_document_scroll_to_visible_area (MousepadDocument *document);
static gboolean mousepad_document_iter_search (const GtkTextIter *start,
const gchar *str,
@@ -235,6 +243,8 @@ mousepad_document_class_init (MousepadDocumentClass *klass)
static void
mousepad_document_init (MousepadDocument *document)
{
+ GtkTargetList *target_list;
+
/* initialize the variables */
document->filename = NULL;
document->display_name = NULL;
@@ -266,17 +276,17 @@ mousepad_document_init (MousepadDocument *document)
gtk_container_add (GTK_CONTAINER (document), GTK_WIDGET (document->textview));
gtk_widget_show (GTK_WIDGET (document->textview));
+ /* also allow dropping of uris and tabs in the textview */
+ target_list = gtk_drag_dest_get_target_list (GTK_WIDGET (document->textview));
+ gtk_target_list_add_table (target_list, drop_targets, G_N_ELEMENTS (drop_targets));
+
/* attach signals to the text view and buffer */
- g_signal_connect (G_OBJECT (document->buffer), "modified-changed",
- G_CALLBACK (mousepad_document_modified_changed), document);
- g_signal_connect (G_OBJECT (document->buffer), "notify::has-selection",
- G_CALLBACK (mousepad_document_notify_has_selection), document);
- g_signal_connect (G_OBJECT (document->buffer), "notify::cursor-position",
- G_CALLBACK (mousepad_document_notify_cursor_position), document);
- g_signal_connect (G_OBJECT (document->textview), "notify::overwrite",
- G_CALLBACK (mousepad_document_toggle_overwrite), document);
- g_signal_connect (G_OBJECT (document->textview), "populate-popup",
- G_CALLBACK (mousepad_undo_populate_popup), document->undo);
+ g_signal_connect (G_OBJECT (document->buffer), "modified-changed", G_CALLBACK (mousepad_document_modified_changed), document);
+ g_signal_connect (G_OBJECT (document->buffer), "notify::has-selection", G_CALLBACK (mousepad_document_notify_has_selection), document);
+ g_signal_connect (G_OBJECT (document->buffer), "notify::cursor-position", G_CALLBACK (mousepad_document_notify_cursor_position), document);
+ g_signal_connect (G_OBJECT (document->textview), "notify::overwrite", G_CALLBACK (mousepad_document_toggle_overwrite), document);
+ g_signal_connect (G_OBJECT (document->textview), "populate-popup", G_CALLBACK (mousepad_undo_populate_popup), document->undo);
+ g_signal_connect (G_OBJECT (document->textview), "drag-data-received", G_CALLBACK (mousepad_document_drag_data_received), document);
}
@@ -415,8 +425,29 @@ mousepad_document_toggle_overwrite (GtkTextView *textview,
static void
+mousepad_document_drag_data_received (GtkWidget *widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time,
+ MousepadDocument *document)
+{
+ _mousepad_return_if_fail (MOUSEPAD_IS_DOCUMENT (document));
+
+ /* emit the drag-data-received signal from the document when a tab or uri has been dropped */
+ if (info == TARGET_TEXT_URI_LIST || info == TARGET_GTK_NOTEBOOK_TAB)
+ g_signal_emit_by_name (G_OBJECT (document), "drag-data-received", context, x, y, selection_data, info, time);
+}
+
+
+
+static void
mousepad_document_scroll_to_visible_area (MousepadDocument *document)
{
+ _mousepad_return_if_fail (MOUSEPAD_IS_DOCUMENT (document));
+
/* scroll to visible area */
gtk_text_view_scroll_to_mark (document->textview,
gtk_text_buffer_get_insert (document->buffer),
diff --git a/mousepad/mousepad-view.c b/mousepad/mousepad-view.c
index 5f9fba3..bb4d8fd 100644
--- a/mousepad/mousepad-view.c
+++ b/mousepad/mousepad-view.c
@@ -149,8 +149,8 @@ mousepad_view_key_press_event (GtkWidget *widget,
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget));
/* check if we have to indent when the user pressed enter */
- if ((key == GDK_Return || key == GDK_KP_Enter) &&
- !(event->state & GDK_SHIFT_MASK) && view->auto_indent)
+ if ((key == GDK_Return || key == GDK_KP_Enter)
+ && !(event->state & GDK_SHIFT_MASK) && view->auto_indent)
{
/* get the iter */
mark = gtk_text_buffer_get_insert (buffer);
@@ -183,8 +183,8 @@ mousepad_view_key_press_event (GtkWidget *widget,
modifiers = gtk_accelerator_get_default_mod_mask ();
/* check if the user pressed the tab button for indenting lines */
- if ((key == GDK_Tab || key == GDK_KP_Tab || key == GDK_ISO_Left_Tab) &&
- ((event->state & modifiers) == 0 || (event->state & modifiers) == GDK_SHIFT_MASK))
+ if ((key == GDK_Tab || key == GDK_KP_Tab || key == GDK_ISO_Left_Tab)
+ && ((event->state & modifiers) == 0 || (event->state & modifiers) == GDK_SHIFT_MASK))
{
/* get the selected text */
has_selection = gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
diff --git a/mousepad/mousepad-window.c b/mousepad/mousepad-window.c
index 89f02b4..827643d 100644
--- a/mousepad/mousepad-window.c
+++ b/mousepad/mousepad-window.c
@@ -51,12 +51,6 @@
enum
{
- TARGET_TEXT_URI_LIST,
- TARGET_GTK_NOTEBOOK_TAB,
-};
-
-enum
-{
NEW_WINDOW,
NEW_WINDOW_WITH_DOCUMENT,
LAST_SIGNAL,
@@ -165,13 +159,22 @@ static void mousepad_window_recent_clear (MousepadW
/* dnd */
static void mousepad_window_drag_data_received (GtkWidget *widget,
- GdkDragContext *context,
- gint x,
- gint y,
- GtkSelectionData *selection_data,
- guint info,
- guint time,
- MousepadWindow *window);
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time,
+ MousepadWindow *window);
+
+/* search bar */
+static void mousepad_window_hide_search_bar (MousepadWindow *window);
+static gboolean mousepad_window_find_string (MousepadWindow *window,
+ const gchar *string,
+ MousepadSearchFlags flags);
+static gboolean mousepad_window_highlight_all (MousepadWindow *window,
+ const gchar *string,
+ MousepadSearchFlags flags);
/* actions */
static void mousepad_window_action_open_new_tab (GtkAction *action,
@@ -353,12 +356,6 @@ static const GtkToggleActionEntry toggle_action_entries[] =
{ "auto-indent", NULL, N_("_Auto Indent"), NULL, NULL, G_CALLBACK (mousepad_window_action_auto_indent), FALSE, },
};
-static const GtkTargetEntry drop_targets[] =
-{
- { "text/uri-list", 0, TARGET_TEXT_URI_LIST },
- { "GTK_NOTEBOOK_TAB", GTK_TARGET_SAME_APP, TARGET_GTK_NOTEBOOK_TAB },
-};
-
static GObjectClass *mousepad_window_parent_class;
@@ -1081,6 +1078,9 @@ mousepad_window_add (MousepadWindow *window,
/* switch to the new tab */
gtk_notebook_set_current_page (GTK_NOTEBOOK (window->notebook), page);
+ /* make sure the textview is focused in the new document */
+ mousepad_document_focus_textview (document);
+
/* destroy the previous tab if it was not modified, untitled and the new tab is not untitled */
if (active != NULL
&& mousepad_document_get_modified (active) == FALSE
@@ -1249,6 +1249,7 @@ mousepad_window_page_added (GtkNotebook *notebook,
g_signal_connect (G_OBJECT (page), "modified-changed", G_CALLBACK (mousepad_window_modified_changed), window);
g_signal_connect (G_OBJECT (page), "cursor-changed", G_CALLBACK (mousepad_window_cursor_changed), window);
g_signal_connect (G_OBJECT (page), "overwrite-changed", G_CALLBACK (mousepad_window_overwrite_changed), window);
+ g_signal_connect (G_OBJECT (page), "drag-data-received", G_CALLBACK (mousepad_window_drag_data_received), window);
g_signal_connect_swapped (G_OBJECT (page), "can-undo", G_CALLBACK (mousepad_window_can_undo), window);
g_signal_connect_swapped (G_OBJECT (page), "can-redo", G_CALLBACK (mousepad_window_can_redo), window);
@@ -1281,6 +1282,7 @@ mousepad_window_page_removed (GtkNotebook *notebook,
g_signal_handlers_disconnect_by_func (G_OBJECT (page), mousepad_window_modified_changed, window);
g_signal_handlers_disconnect_by_func (G_OBJECT (page), mousepad_window_cursor_changed, window);
g_signal_handlers_disconnect_by_func (G_OBJECT (page), mousepad_window_overwrite_changed, window);
+ g_signal_handlers_disconnect_by_func (G_OBJECT (page), mousepad_window_drag_data_received, window);
g_signal_handlers_disconnect_by_func (G_OBJECT (page), mousepad_window_can_undo, window);
g_signal_handlers_disconnect_by_func (G_OBJECT (page), mousepad_window_can_redo, window);
@@ -1316,9 +1318,13 @@ mousepad_window_page_removed (GtkNotebook *notebook,
/* hide all the actions that are not relevant without tabs */
mousepad_window_update_sensitivity (window, FALSE);
- /* the statusbar items */
+ /* hide the statusbar items */
if (window->statusbar)
mousepad_statusbar_visible (MOUSEPAD_STATUSBAR (window->statusbar), FALSE);
+
+ /* hide the search bar */
+ if (window->search_bar)
+ mousepad_window_hide_search_bar (window);
}
}
@@ -1963,13 +1969,13 @@ mousepad_window_recent_clear (MousepadWindow *window)
**/
static void
mousepad_window_drag_data_received (GtkWidget *widget,
- GdkDragContext *context,
- gint x,
- gint y,
- GtkSelectionData *selection_data,
- guint info,
- guint time,
- MousepadWindow *window)
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time,
+ MousepadWindow *window)
{
gchar **uris;
GtkWidget *notebook, **document;
@@ -1977,6 +1983,7 @@ mousepad_window_drag_data_received (GtkWidget *widget,
gint i, n_pages;
_mousepad_return_if_fail (MOUSEPAD_IS_WINDOW (window));
+ _mousepad_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
/* we only accept text/uri-list drops with format 8 and atleast one byte of data */
if (info == TARGET_TEXT_URI_LIST && selection_data->format == 8 && selection_data->length > 0)
@@ -1990,7 +1997,7 @@ mousepad_window_drag_data_received (GtkWidget *widget,
/* cleanup */
g_strfreev (uris);
- /* finish the drag */
+ /* finish the drag (copy) */
gtk_drag_finish (context, TRUE, FALSE, time);
}
else if (info == TARGET_GTK_NOTEBOOK_TAB)
@@ -2000,11 +2007,13 @@ mousepad_window_drag_data_received (GtkWidget *widget,
/* get the document that has been dragged */
document = (GtkWidget **) selection_data->data;
- g_object_ref (G_OBJECT (*document));
/* check */
_mousepad_return_if_fail (MOUSEPAD_IS_DOCUMENT (*document));
+ /* take a reference on the document before we remove it */
+ g_object_ref (G_OBJECT (*document));
+
/* remove the document from the source window */
gtk_container_remove (GTK_CONTAINER (notebook), *document);
@@ -2026,13 +2035,13 @@ mousepad_window_drag_data_received (GtkWidget *widget,
/* add the document to the new window */
mousepad_window_add (window, MOUSEPAD_DOCUMENT (*document));
- /* move it to the correct position */
+ /* move the tab to the correct position */
gtk_notebook_reorder_child (GTK_NOTEBOOK (window->notebook), *document, i);
- /* release out reference on the document */
+ /* release our reference on the document */
g_object_unref (G_OBJECT (*document));
- /* finish the drag */
+ /* finish the drag (move) */
gtk_drag_finish (context, TRUE, TRUE, time);
}
}
@@ -2040,6 +2049,58 @@ mousepad_window_drag_data_received (GtkWidget *widget,
/**
+ * Search Bar
+ **/
+static void
+mousepad_window_hide_search_bar (MousepadWindow *window)
+{
+ _mousepad_return_if_fail (MOUSEPAD_IS_WINDOW (window));
+
+ /* hide the search bar */
+ gtk_widget_hide (window->search_bar);
+ gtk_table_set_row_spacing (GTK_TABLE (window->table), 3, 0);
+
+ /* focus the active document's text view */
+ if (G_LIKELY (window->active))
+ mousepad_document_focus_textview (window->active);
+}
+
+
+
+static gboolean
+mousepad_window_find_string (MousepadWindow *window,
+ const gchar *string,
+ MousepadSearchFlags flags)
+{
+ gboolean found = FALSE;
+
+ _mousepad_return_val_if_fail (MOUSEPAD_IS_WINDOW (window), FALSE);
+ _mousepad_return_val_if_fail (g_utf8_validate (string, -1, NULL), FALSE);
+
+ if (G_LIKELY (window->active))
+ found = mousepad_document_find (window->active, string, flags);
+
+ return found;
+}
+
+static gboolean
+mousepad_window_highlight_all (MousepadWindow *window,
+ const gchar *string,
+ MousepadSearchFlags flags)
+{
+ _mousepad_return_val_if_fail (MOUSEPAD_IS_WINDOW (window), FALSE);
+ _mousepad_return_val_if_fail (g_utf8_validate (string, -1, NULL), FALSE);
+
+ /* hightlight all the occurences in the active document */
+ if (G_LIKELY (window->active))
+ mousepad_document_highlight_all (window->active, string, flags);
+
+ return FALSE;
+}
+
+
+
+/**
* Menu Actions
*
* All those function should be sorted by the menu structure so it's
@@ -2447,70 +2508,30 @@ mousepad_window_action_select_all (GtkAction *action,
static void
-mousepad_window_hide_search_bar (MousepadWindow *window)
-{
- _mousepad_return_if_fail (MOUSEPAD_IS_WINDOW (window));
-
- /* hide the search bar */
- gtk_widget_hide (window->search_bar);
- gtk_table_set_row_spacing (GTK_TABLE (window->table), 3, 0);
-
- /* focus the active document's text view */
- if (G_LIKELY (window->active))
- mousepad_document_focus_textview (window->active);
-}
-
-
-
-static gboolean
-mousepad_window_find_string (MousepadWindow *window,
- const gchar *string,
- MousepadSearchFlags flags)
-{
- gboolean found;
-
- _mousepad_return_val_if_fail (MOUSEPAD_IS_WINDOW (window), FALSE);
-
- found = mousepad_document_find (window->active, string, flags);
-
- return found;
-}
-
-static gboolean
-mousepad_window_highlight_all (MousepadWindow *window,
- const gchar *string,
- MousepadSearchFlags flags)
-{
- _mousepad_return_val_if_fail (MOUSEPAD_IS_WINDOW (window), FALSE);
-
- /* hightlight all the occurences in the active document */
- mousepad_document_highlight_all (window->active, string, flags);
-
- return FALSE;
-}
-
-static void
mousepad_window_action_find (GtkAction *action,
MousepadWindow *window)
{
- if (G_UNLIKELY (window->search_bar == NULL))
+ if (G_LIKELY (window->active))
{
- /* create a new toolbar */
- window->search_bar = mousepad_search_bar_new ();
- gtk_table_attach (GTK_TABLE (window->table), window->search_bar, 0, 1, 4, 5, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
-
- /* connect signals to the search bar */
- g_signal_connect_swapped (G_OBJECT (window->search_bar), "hide-bar", G_CALLBACK (mousepad_window_hide_search_bar), window);
- g_signal_connect_swapped (G_OBJECT (window->search_bar), "find-string", G_CALLBACK (mousepad_window_find_string), window);
- g_signal_connect_swapped (G_OBJECT (window->search_bar), "highlight-all", G_CALLBACK (mousepad_window_highlight_all), window);
- }
+ if (G_UNLIKELY (window->search_bar == NULL))
+ {
+ /* create a new toolbar */
+ window->search_bar = mousepad_search_bar_new ();
+ gtk_table_attach (GTK_TABLE (window->table), window->search_bar, 0, 1, 4, 5, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
+
+ /* connect signals to the search bar */
+ g_signal_connect_swapped (G_OBJECT (window->search_bar), "hide-bar", G_CALLBACK (mousepad_window_hide_search_bar), window);
+ g_signal_connect_swapped (G_OBJECT (window->search_bar), "find-string", G_CALLBACK (mousepad_window_find_string), window);
+ g_signal_connect_swapped (G_OBJECT (window->search_bar), "highlight-all", G_CALLBACK (mousepad_window_highlight_all), window);
+ }
- /* show the search bar and give some space to the table */
- gtk_widget_show (window->search_bar);
- gtk_table_set_row_spacing (GTK_TABLE (window->table), 3, WINDOW_SPACING);
+ /* show the search bar and give some space to the table */
+ gtk_widget_show (window->search_bar);
+ gtk_table_set_row_spacing (GTK_TABLE (window->table), 3, WINDOW_SPACING);
- /* focus the search entry */
- mousepad_search_bar_focus (MOUSEPAD_SEARCH_BAR (window->search_bar));
+ /* focus the search entry */
+ mousepad_search_bar_focus (MOUSEPAD_SEARCH_BAR (window->search_bar));
+ }
}
@@ -2520,7 +2541,7 @@ mousepad_window_action_find_next (GtkAction *action,
MousepadWindow *window)
{
/* only find the next occurence when the search bar is initialized */
- if (G_LIKELY (window->search_bar != NULL))
+ if (G_LIKELY (window->active && window->search_bar != NULL))
mousepad_search_bar_find_next (MOUSEPAD_SEARCH_BAR (window->search_bar));
}
@@ -2531,7 +2552,7 @@ mousepad_window_action_find_previous (GtkAction *action,
MousepadWindow *window)
{
/* only find the previous occurence when the search bar is initialized */
- if (G_LIKELY (window->search_bar != NULL))
+ if (G_LIKELY (window->active && window->search_bar != NULL))
mousepad_search_bar_find_previous (MOUSEPAD_SEARCH_BAR (window->search_bar));
}
diff --git a/mousepad/mousepad-window.h b/mousepad/mousepad-window.h
index f6de694..c4bc6c2 100644
--- a/mousepad/mousepad-window.h
+++ b/mousepad/mousepad-window.h
@@ -31,6 +31,18 @@ G_BEGIN_DECLS
#define MOUSEPAD_IS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOUSEPADL_TYPE_WINDOW))
#define MOUSEPAD_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOUSEPAD_TYPE_WINDOW, MousepadWindowClass))
+enum
+{
+ TARGET_TEXT_URI_LIST,
+ TARGET_GTK_NOTEBOOK_TAB,
+};
+
+static const GtkTargetEntry drop_targets[] =
+{
+ { "text/uri-list", 0, TARGET_TEXT_URI_LIST },
+ { "GTK_NOTEBOOK_TAB", GTK_TARGET_SAME_APP, TARGET_GTK_NOTEBOOK_TAB },
+};
+
typedef struct _MousepadWindowClass MousepadWindowClass;
typedef struct _MousepadWindow MousepadWindow;
More information about the Xfce4-commits
mailing list