[gedit/multiviews] Add split view and multiviews support.
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gedit/multiviews] Add split view and multiviews support.
- Date: Sat, 7 Nov 2009 15:03:49 +0000 (UTC)
commit 3da1078a698873ad7afb06cbf68f8208c33d7273
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Sat Nov 7 15:48:40 2009 +0100
Add split view and multiviews support.
I added the next:
- gedit-document and gedit-view interfaces
- gedit-text-view and gedit-web-view implements gedit-view
- gedit-text-buffer implements gedit-document
- gedit-tab was renamed to gedit-view-container
- gedit-page was added to manage the splits and add the gedit-view-containers
- updated class diagram
This is not yet finished. Plugins aren't working and there are some issues
that need testing. Also sensitivity of the splits isn't managed yet.
configure.ac | 1 +
docs/class-diagram.dia | Bin 8258 -> 9460 bytes
gedit/Makefile.am | 24 +-
gedit/dialogs/gedit-close-confirmation-dialog.c | 2 +-
gedit/dialogs/gedit-close-confirmation-dialog.h | 2 +-
gedit/dialogs/gedit-preferences-dialog.c | 2 +-
gedit/gedit-commands-documents.c | 8 +-
gedit/gedit-commands-edit.c | 30 +-
gedit/gedit-commands-file-print.c | 32 +-
gedit/gedit-commands-file.c | 578 +++--
gedit/gedit-commands-search.c | 94 +-
gedit/gedit-commands-view.c | 44 +
gedit/gedit-commands.h | 16 +-
gedit/gedit-data-binding.c | 303 +++
gedit/gedit-data-binding.h | 72 +
gedit/gedit-debug.c | 4 +-
gedit/gedit-debug.h | 4 +-
gedit/gedit-document-interface.c | 734 ++++++
gedit/gedit-document-interface.h | 273 ++
gedit/gedit-document-loader.c | 8 +-
gedit/gedit-document-loader.h | 2 +-
gedit/gedit-document-saver.h | 2 +-
gedit/gedit-document.h | 290 ---
gedit/gedit-documents-panel.c | 275 ++-
gedit/gedit-gio-document-loader.c | 9 +-
gedit/gedit-gio-document-loader.h | 2 +-
gedit/gedit-gio-document-saver.c | 10 +-
gedit/gedit-io-error-message-area.c | 2 +-
gedit/gedit-notebook.c | 465 ++--
gedit/gedit-notebook.h | 50 +-
gedit/gedit-page.c | 826 ++++++
gedit/gedit-page.h | 88 +
gedit/gedit-prefs-manager-app.c | 95 +-
gedit/gedit-print-job.h | 2 +-
gedit/gedit-session.c | 23 +-
gedit/gedit-tab.c | 2837 ---------------------
gedit/gedit-tab.h | 162 --
gedit/{gedit-document.c => gedit-text-buffer.c} | 1453 +++++------
gedit/gedit-text-buffer.h | 172 ++
gedit/{gedit-view.c => gedit-text-view.c} | 785 +++---
gedit/gedit-text-view.h | 93 +
gedit/gedit-ui.h | 9 +
gedit/gedit-ui.xml | 8 +
gedit/gedit-utils.c | 2 +-
gedit/gedit-view-container.c | 3049 +++++++++++++++++++++++
gedit/gedit-view-container.h | 181 ++
gedit/gedit-view-interface.c | 332 +++
gedit/gedit-view-interface.h | 97 +
gedit/gedit-view.h | 108 -
gedit/gedit-web-view.c | 158 ++
gedit/gedit-web-view.h | 62 +
gedit/gedit-window-private.h | 15 +-
gedit/gedit-window.c | 1403 ++++++-----
gedit/gedit-window.h | 56 +-
gedit/gedit.c | 10 +-
plugin-loaders/Makefile.am | 1 -
56 files changed, 9382 insertions(+), 5983 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 3e8053f..05ca39d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -253,6 +253,7 @@ PKG_CHECK_MODULES(GEDIT, [
gtk+-2.0 >= 2.16.0
gtksourceview-2.0 >= 2.4.0
gconf-2.0 >= 1.1.11
+ webkit-1.0
])
dnl FIXME: Remove this when removing gedit-message-area
diff --git a/docs/class-diagram.dia b/docs/class-diagram.dia
index 25264b7..08b3fa0 100644
Binary files a/docs/class-diagram.dia and b/docs/class-diagram.dia differ
diff --git a/gedit/Makefile.am b/gedit/Makefile.am
index 40f64f1..d2fafad 100644
--- a/gedit/Makefile.am
+++ b/gedit/Makefile.am
@@ -75,14 +75,16 @@ NOINST_H_FILES = \
gedit-prefs-manager-private.h \
gedittextregion.h \
gedit-session.h \
- gedit-dirs.h
+ gedit-dirs.h \
+ gedit-web-view.h \
+ gedit-data-binding.h
INST_H_FILES = \
gedit-app.h \
gedit-commands.h \
gedit-convert.h \
gedit-debug.h \
- gedit-document.h \
+ gedit-document-interface.h \
gedit-encodings.h \
gedit-encodings-option-menu.h \
gedit-file-chooser-dialog.h \
@@ -100,9 +102,12 @@ INST_H_FILES = \
gedit-progress-message-area.h \
gedit-statusbar.h \
gedit-status-combo-box.h \
- gedit-tab.h \
+ gedit-view-container.h \
gedit-utils.h \
- gedit-view.h \
+ gedit-view-interface.h \
+ gedit-text-view.h \
+ gedit-text-buffer.h \
+ gedit-page.h \
gedit-window.h
headerdir = $(prefix)/include/gedit- GEDIT_API_VERSION@/gedit
@@ -133,7 +138,7 @@ libgedit_la_SOURCES = \
gedit-convert.c \
gedit-debug.c \
gedit-dirs.c \
- gedit-document.c \
+ gedit-document-interface.c \
gedit-document-loader.c \
gedit-gio-document-loader.c \
gedit-document-saver.c \
@@ -168,11 +173,16 @@ libgedit_la_SOURCES = \
gedit-statusbar.c \
gedit-status-combo-box.c \
gedit-style-scheme-manager.c \
- gedit-tab.c \
+ gedit-view-container.c \
gedit-utils.c \
- gedit-view.c \
+ gedit-view-interface.c \
+ gedit-text-view.c \
+ gedit-text-buffer.c \
+ gedit-web-view.c \
+ gedit-page.c \
gedit-window.c \
gedittextregion.c \
+ gedit-data-binding.c \
$(NOINST_H_FILES) \
$(INST_H_FILES)
diff --git a/gedit/dialogs/gedit-close-confirmation-dialog.c b/gedit/dialogs/gedit-close-confirmation-dialog.c
index 336d5ac..6c71b40 100644
--- a/gedit/dialogs/gedit-close-confirmation-dialog.c
+++ b/gedit/dialogs/gedit-close-confirmation-dialog.c
@@ -404,7 +404,7 @@ get_text_secondary_label (GeditDocument *doc)
glong seconds;
gchar *secondary_msg;
- seconds = MAX (1, _gedit_document_get_seconds_since_last_save_or_load (doc));
+ seconds = MAX (1, gedit_document_get_seconds_since_last_save_or_load (doc));
if (seconds < 55)
{
diff --git a/gedit/dialogs/gedit-close-confirmation-dialog.h b/gedit/dialogs/gedit-close-confirmation-dialog.h
index 563289a..c1e5424 100644
--- a/gedit/dialogs/gedit-close-confirmation-dialog.h
+++ b/gedit/dialogs/gedit-close-confirmation-dialog.h
@@ -32,7 +32,7 @@
#include <glib.h>
#include <gtk/gtk.h>
-#include <gedit/gedit-document.h>
+#include <gedit/gedit-document-interface.h>
#define GEDIT_TYPE_CLOSE_CONFIRMATION_DIALOG (gedit_close_confirmation_dialog_get_type ())
#define GEDIT_CLOSE_CONFIRMATION_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_CLOSE_CONFIRMATION_DIALOG, GeditCloseConfirmationDialog))
diff --git a/gedit/dialogs/gedit-preferences-dialog.c b/gedit/dialogs/gedit-preferences-dialog.c
index 252ed38..e3e3a2e 100644
--- a/gedit/dialogs/gedit-preferences-dialog.c
+++ b/gedit/dialogs/gedit-preferences-dialog.c
@@ -44,7 +44,7 @@
#include "gedit-preferences-dialog.h"
#include "gedit-utils.h"
#include "gedit-debug.h"
-#include "gedit-document.h"
+#include "gedit-document-interface.h"
#include "gedit-style-scheme-manager.h"
#include "gedit-plugin-manager.h"
#include "gedit-help.h"
diff --git a/gedit/gedit-commands-documents.c b/gedit/gedit-commands-documents.c
index 016ebbe..9c00bc8 100644
--- a/gedit/gedit-commands-documents.c
+++ b/gedit/gedit-commands-documents.c
@@ -70,18 +70,18 @@ _gedit_cmd_documents_move_to_new_window (GtkAction *action,
GeditWindow *window)
{
GeditNotebook *old_notebook;
- GeditTab *tab;
+ GeditPage *page;
gedit_debug (DEBUG_COMMANDS);
- tab = gedit_window_get_active_tab (window);
+ page = gedit_window_get_active_page (window);
- if (tab == NULL)
+ if (page == NULL)
return;
old_notebook = GEDIT_NOTEBOOK (_gedit_window_get_notebook (window));
g_return_if_fail (gtk_notebook_get_n_pages (GTK_NOTEBOOK (old_notebook)) > 1);
- _gedit_window_move_tab_to_new_window (window, tab);
+ _gedit_window_move_page_to_new_window (window, page);
}
diff --git a/gedit/gedit-commands-edit.c b/gedit/gedit-commands-edit.c
index e2cedeb..6d2e885 100644
--- a/gedit/gedit-commands-edit.c
+++ b/gedit/gedit-commands-edit.c
@@ -39,24 +39,26 @@
#include "gedit-commands.h"
#include "gedit-window.h"
#include "gedit-debug.h"
-#include "gedit-view.h"
+#include "gedit-view-interface.h"
#include "dialogs/gedit-preferences-dialog.h"
void
_gedit_cmd_edit_undo (GtkAction *action,
- GeditWindow *window)
+ GeditWindow *window)
{
+ GeditViewContainer *container;
+ GeditDocument *active_document;
GeditView *active_view;
- GtkSourceBuffer *active_document;
gedit_debug (DEBUG_COMMANDS);
- active_view = gedit_window_get_active_view (window);
- g_return_if_fail (active_view);
+ container = gedit_window_get_active_view_container (window);
+ g_return_if_fail (container);
- active_document = GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (active_view)));
+ active_document = gedit_view_container_get_document (container);
+ active_view = gedit_view_container_get_view (container);
- gtk_source_buffer_undo (active_document);
+ gedit_document_undo (active_document);
gedit_view_scroll_to_cursor (active_view);
@@ -65,19 +67,21 @@ _gedit_cmd_edit_undo (GtkAction *action,
void
_gedit_cmd_edit_redo (GtkAction *action,
- GeditWindow *window)
+ GeditWindow *window)
{
+ GeditViewContainer *container;
+ GeditDocument *active_document;
GeditView *active_view;
- GtkSourceBuffer *active_document;
gedit_debug (DEBUG_COMMANDS);
- active_view = gedit_window_get_active_view (window);
- g_return_if_fail (active_view);
+ container = gedit_window_get_active_view_container (window);
+ g_return_if_fail (container);
- active_document = GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (active_view)));
+ active_document = gedit_view_container_get_document (container);
+ active_view = gedit_view_container_get_view (container);
- gtk_source_buffer_redo (active_document);
+ gedit_document_redo (active_document);
gedit_view_scroll_to_cursor (active_view);
diff --git a/gedit/gedit-commands-file-print.c b/gedit/gedit-commands-file-print.c
index 455e2e2..df46089 100644
--- a/gedit/gedit-commands-file-print.c
+++ b/gedit/gedit-commands-file-print.c
@@ -39,7 +39,7 @@
#include "gedit-commands.h"
#include "gedit-window.h"
-#include "gedit-tab.h"
+#include "gedit-view-container.h"
#include "gedit-debug.h"
#if !GTK_CHECK_VERSION (2, 17, 4)
@@ -47,15 +47,15 @@ void
_gedit_cmd_file_page_setup (GtkAction *action,
GeditWindow *window)
{
- GeditTab *tab;
+ GeditViewContainer *container;
gedit_debug (DEBUG_COMMANDS);
- tab = gedit_window_get_active_tab (window);
- if (tab == NULL)
+ container = gedit_window_get_active_view_container (window);
+ if (container == NULL)
return;
- _gedit_tab_page_setup (tab);
+ _gedit_view_container_page_setup (container);
}
#endif
@@ -63,29 +63,35 @@ void
_gedit_cmd_file_print_preview (GtkAction *action,
GeditWindow *window)
{
- GeditTab *tab;
+ GeditPage *page;
+ GeditViewContainer *container;
gedit_debug (DEBUG_COMMANDS);
- tab = gedit_window_get_active_tab (window);
- if (tab == NULL)
+ page = gedit_window_get_active_page (window);
+ if (page == NULL)
return;
- _gedit_tab_print_preview (tab);
+ container = gedit_page_get_active_view_container (page);
+
+ _gedit_view_container_print_preview (container);
}
void
_gedit_cmd_file_print (GtkAction *action,
GeditWindow *window)
{
- GeditTab *tab;
+ GeditPage *page;
+ GeditViewContainer *container;
gedit_debug (DEBUG_COMMANDS);
- tab = gedit_window_get_active_tab (window);
- if (tab == NULL)
+ page = gedit_window_get_active_page (window);
+ if (page == NULL)
return;
- _gedit_tab_print (tab);
+ container = gedit_page_get_active_view_container (page);
+
+ _gedit_view_container_print (container);
}
diff --git a/gedit/gedit-commands-file.c b/gedit/gedit-commands-file.c
index 23767fc..2cd30c2 100644
--- a/gedit/gedit-commands-file.c
+++ b/gedit/gedit-commands-file.c
@@ -52,16 +52,16 @@
/* Defined constants */
#define GEDIT_OPEN_DIALOG_KEY "gedit-open-dialog-key"
-#define GEDIT_TAB_TO_SAVE_AS "gedit-tab-to-save-as"
-#define GEDIT_LIST_OF_TABS_TO_SAVE_AS "gedit-list-of-tabs-to-save-as"
+#define GEDIT_PAGE_TO_SAVE_AS "gedit-page-to-save-as"
+#define GEDIT_LIST_OF_PAGES_TO_SAVE_AS "gedit-list-of-pages-to-save-as"
#define GEDIT_IS_CLOSING_ALL "gedit-is-closing-all"
#define GEDIT_IS_QUITTING "gedit-is-quitting"
-#define GEDIT_IS_CLOSING_TAB "gedit-is-closing-tab"
+#define GEDIT_IS_CLOSING_PAGE "gedit-is-closing-page"
-static void tab_state_changed_while_saving (GeditTab *tab,
- GParamSpec *pspec,
- GeditWindow *window);
+static void view_container_state_changed_while_saving (GeditViewContainer *container,
+ GParamSpec *pspec,
+ GeditWindow *window);
void
_gedit_cmd_file_new (GtkAction *action,
@@ -69,18 +69,19 @@ _gedit_cmd_file_new (GtkAction *action,
{
gedit_debug (DEBUG_COMMANDS);
- gedit_window_create_tab (window, TRUE);
+ gedit_window_create_page (window, TRUE);
}
-static GeditTab *
-get_tab_from_file (GList *docs, GFile *file)
+static GeditPage *
+get_page_from_file (GList *docs, GFile *file)
{
- GeditTab *tab = NULL;
+ GeditPage *page = NULL;
while (docs != NULL)
{
gchar *u;
GeditDocument *d;
+ GeditViewContainer *container;
d = GEDIT_DOCUMENT (docs->data);
@@ -94,7 +95,8 @@ get_tab_from_file (GList *docs, GFile *file)
if (g_file_equal (f, file))
{
- tab = gedit_tab_get_from_document (d);
+ container = gedit_view_container_get_from_document (d);
+ page = gedit_page_get_from_container (container);
g_object_unref (f);
break;
}
@@ -105,7 +107,7 @@ get_tab_from_file (GList *docs, GFile *file)
docs = g_list_next (docs);
}
- return tab;
+ return page;
}
static gboolean
@@ -130,7 +132,7 @@ load_file_list (GeditWindow *window,
gint line_pos,
gboolean create)
{
- GeditTab *tab;
+ GeditPage *page;
gint loaded_files = 0; /* Number of files to load */
gboolean jump_to = TRUE; /* Whether to jump to the new tab */
GList *win_docs;
@@ -147,21 +149,23 @@ load_file_list (GeditWindow *window,
{
if (!is_duplicated_file (files_to_load, l->data))
{
- tab = get_tab_from_file (win_docs, l->data);
- if (tab != NULL)
+ page = get_page_from_file (win_docs, l->data);
+ if (page != NULL)
{
if (l == files)
{
- gedit_window_set_active_tab (window, tab);
+ gedit_window_set_active_page (window, page);
jump_to = FALSE;
if (line_pos > 0)
{
+ GeditViewContainer *container;
GeditDocument *doc;
GeditView *view;
- doc = gedit_tab_get_document (tab);
- view = gedit_tab_get_view (tab);
+ container = gedit_page_get_active_view_container (page);
+ doc = gedit_view_container_get_document (container);
+ view = gedit_view_container_get_view (container);
/* document counts lines starting from 0 */
gedit_document_goto_line (doc, line_pos - 1);
@@ -187,25 +191,27 @@ load_file_list (GeditWindow *window,
files_to_load = g_slist_reverse (files_to_load);
l = files_to_load;
- tab = gedit_window_get_active_tab (window);
- if (tab != NULL)
+ page = gedit_window_get_active_page (window);
+ if (page != NULL)
{
+ GeditViewContainer *container;
GeditDocument *doc;
- doc = gedit_tab_get_document (tab);
+ container = gedit_page_get_active_view_container (page);
+ doc = gedit_view_container_get_document (container);
if (gedit_document_is_untouched (doc) &&
- (gedit_tab_get_state (tab) == GEDIT_TAB_STATE_NORMAL))
+ (gedit_view_container_get_state (container) == GEDIT_VIEW_CONTAINER_STATE_NORMAL))
{
gchar *uri;
// FIXME: pass the GFile to tab when api is there
uri = g_file_get_uri (l->data);
- _gedit_tab_load (tab,
- uri,
- encoding,
- line_pos,
- create);
+ _gedit_view_container_load (container,
+ uri,
+ encoding,
+ line_pos,
+ create);
g_free (uri);
l = g_slist_next (l);
@@ -223,15 +229,15 @@ load_file_list (GeditWindow *window,
// FIXME: pass the GFile to tab when api is there
uri = g_file_get_uri (l->data);
- tab = gedit_window_create_tab_from_uri (window,
- uri,
- encoding,
- line_pos,
- create,
- jump_to);
+ page = gedit_window_create_page_from_uri (window,
+ uri,
+ encoding,
+ line_pos,
+ create,
+ jump_to);
g_free (uri);
- if (tab != NULL)
+ if (page != NULL)
{
jump_to = FALSE;
++loaded_files;
@@ -242,12 +248,14 @@ load_file_list (GeditWindow *window,
if (loaded_files == 1)
{
+ GeditViewContainer *container;
GeditDocument *doc;
gchar *uri_for_display;
- g_return_val_if_fail (tab != NULL, loaded_files);
+ g_return_val_if_fail (page != NULL, loaded_files);
- doc = gedit_tab_get_document (tab);
+ container = gedit_page_get_active_view_container (page);
+ doc = gedit_view_container_get_document (container);
uri_for_display = gedit_document_get_uri_for_display (doc);
gedit_statusbar_flash_message (GEDIT_STATUSBAR (window->priv->statusbar),
@@ -510,7 +518,7 @@ _gedit_cmd_file_open (GtkAction *action,
}
/* File saving */
-static void file_save_as (GeditTab *tab, GeditWindow *window);
+static void file_save_as (GeditPage *page, GeditWindow *window);
static gboolean
is_read_only (GFile *location)
@@ -567,7 +575,7 @@ replace_read_only_file (GtkWindow *parent, GFile *file)
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_NONE,
_("The file \"%s\" is read-only."),
- name_for_display);
+ name_for_display);
g_free (name_for_display);
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
@@ -602,20 +610,20 @@ save_dialog_response_cb (GeditFileChooserDialog *dialog,
{
GFile *file;
const GeditEncoding *encoding;
- GeditTab *tab;
+ GeditPage *page;
gpointer data;
- GSList *tabs_to_save_as;
+ GSList *pages_to_save_as;
gedit_debug (DEBUG_COMMANDS);
- tab = GEDIT_TAB (g_object_get_data (G_OBJECT (dialog),
- GEDIT_TAB_TO_SAVE_AS));
+ page = GEDIT_PAGE (g_object_get_data (G_OBJECT (dialog),
+ GEDIT_PAGE_TO_SAVE_AS));
if (response_id != GTK_RESPONSE_OK)
{
gtk_widget_destroy (GTK_WIDGET (dialog));
- goto save_next_tab;
+ goto save_next_page;
}
file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
@@ -625,13 +633,15 @@ save_dialog_response_cb (GeditFileChooserDialog *dialog,
gtk_widget_destroy (GTK_WIDGET (dialog));
- if (tab != NULL)
+ if (page != NULL)
{
+ GeditViewContainer *container;
GeditDocument *doc;
gchar *parse_name;
gchar *uri;
- doc = gedit_tab_get_document (tab);
+ container = gedit_page_get_active_view_container (page);
+ doc = gedit_view_container_get_document (container);
g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
parse_name = g_file_get_parse_name (file);
@@ -649,51 +659,54 @@ save_dialog_response_cb (GeditFileChooserDialog *dialog,
// FIXME: pass the GFile to tab when api is there
uri = g_file_get_uri (file);
- _gedit_tab_save_as (tab, uri, encoding);
+ _gedit_view_container_save_as (container, uri, encoding);
g_free (uri);
}
g_object_unref (file);
-save_next_tab:
+save_next_page:
data = g_object_get_data (G_OBJECT (window),
- GEDIT_LIST_OF_TABS_TO_SAVE_AS);
+ GEDIT_LIST_OF_PAGES_TO_SAVE_AS);
if (data == NULL)
return;
/* Save As the next tab of the list (we are Saving All files) */
- tabs_to_save_as = (GSList *)data;
- g_return_if_fail (tab == GEDIT_TAB (tabs_to_save_as->data));
+ pages_to_save_as = (GSList *)data;
+ g_return_if_fail (page == GEDIT_PAGE (pages_to_save_as->data));
/* Remove the first item of the list */
- tabs_to_save_as = g_slist_delete_link (tabs_to_save_as,
- tabs_to_save_as);
+ pages_to_save_as = g_slist_delete_link (pages_to_save_as,
+ pages_to_save_as);
g_object_set_data (G_OBJECT (window),
- GEDIT_LIST_OF_TABS_TO_SAVE_AS,
- tabs_to_save_as);
+ GEDIT_LIST_OF_PAGES_TO_SAVE_AS,
+ pages_to_save_as);
- if (tabs_to_save_as != NULL)
+ if (pages_to_save_as != NULL)
{
- tab = GEDIT_TAB (tabs_to_save_as->data);
+ page = GEDIT_PAGE (pages_to_save_as->data);
- if (GPOINTER_TO_BOOLEAN (g_object_get_data (G_OBJECT (tab),
- GEDIT_IS_CLOSING_TAB)) == TRUE)
+ if (GPOINTER_TO_BOOLEAN (g_object_get_data (G_OBJECT (page),
+ GEDIT_IS_CLOSING_PAGE)) == TRUE)
{
- g_object_set_data (G_OBJECT (tab),
- GEDIT_IS_CLOSING_TAB,
+ GeditViewContainer *container;
+
+ g_object_set_data (G_OBJECT (page),
+ GEDIT_IS_CLOSING_PAGE,
NULL);
- /* Trace tab state changes */
- g_signal_connect (tab,
+ container = gedit_page_get_active_view_container (page);
+ /* Trace page state changes */
+ g_signal_connect (container,
"notify::state",
- G_CALLBACK (tab_state_changed_while_saving),
+ G_CALLBACK (view_container_state_changed_while_saving),
window);
}
- gedit_window_set_active_tab (window, tab);
- file_save_as (tab, window);
+ gedit_window_set_active_page (window, page);
+ file_save_as (page, window);
}
}
@@ -730,7 +743,7 @@ confirm_overwrite_callback (GtkFileChooser *dialog,
}
static void
-file_save_as (GeditTab *tab,
+file_save_as (GeditPage *page,
GeditWindow *window)
{
GtkWidget *save_dialog;
@@ -739,8 +752,9 @@ file_save_as (GeditTab *tab,
GFile *file;
gboolean uri_set = FALSE;
const GeditEncoding *encoding;
+ GeditViewContainer *container;
- g_return_if_fail (GEDIT_IS_TAB (tab));
+ g_return_if_fail (GEDIT_IS_PAGE (page));
g_return_if_fail (GEDIT_IS_WINDOW (window));
gedit_debug (DEBUG_COMMANDS);
@@ -769,7 +783,8 @@ file_save_as (GeditTab *tab,
gtk_window_set_modal (GTK_WINDOW (save_dialog), TRUE);
/* Set the suggested file name */
- doc = gedit_tab_get_document (tab);
+ container = gedit_page_get_active_view_container (page);
+ doc = gedit_view_container_get_document (container);
file = gedit_document_get_location (doc);
if (file != NULL)
@@ -816,8 +831,8 @@ file_save_as (GeditTab *tab,
encoding);
g_object_set_data (G_OBJECT (save_dialog),
- GEDIT_TAB_TO_SAVE_AS,
- tab);
+ GEDIT_PAGE_TO_SAVE_AS,
+ page);
g_signal_connect (save_dialog,
"response",
@@ -828,18 +843,20 @@ file_save_as (GeditTab *tab,
}
static void
-file_save (GeditTab *tab,
+file_save (GeditPage *page,
GeditWindow *window)
{
+ GeditViewContainer *container;
GeditDocument *doc;
gchar *uri_for_display;
gedit_debug (DEBUG_COMMANDS);
- g_return_if_fail (GEDIT_IS_TAB (tab));
+ g_return_if_fail (GEDIT_IS_PAGE (page));
g_return_if_fail (GEDIT_IS_WINDOW (window));
- doc = gedit_tab_get_document (tab);
+ container = gedit_page_get_active_view_container (page);
+ doc = gedit_view_container_get_document (container);
g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
if (gedit_document_is_untitled (doc) ||
@@ -847,7 +864,7 @@ file_save (GeditTab *tab,
{
gedit_debug_message (DEBUG_COMMANDS, "Untitled or Readonly");
- file_save_as (tab, window);
+ file_save_as (page, window);
return;
}
@@ -860,43 +877,43 @@ file_save (GeditTab *tab,
g_free (uri_for_display);
- _gedit_tab_save (tab);
+ _gedit_view_container_save (container);
}
void
_gedit_cmd_file_save (GtkAction *action,
- GeditWindow *window)
+ GeditWindow *window)
{
- GeditTab *tab;
+ GeditPage *page;
gedit_debug (DEBUG_COMMANDS);
- tab = gedit_window_get_active_tab (window);
- if (tab == NULL)
+ page = gedit_window_get_active_page (window);
+ if (page == NULL)
return;
- file_save (tab, window);
+ file_save (page, window);
}
void
_gedit_cmd_file_save_as (GtkAction *action,
GeditWindow *window)
{
- GeditTab *tab;
+ GeditPage *page;
gedit_debug (DEBUG_COMMANDS);
- tab = gedit_window_get_active_tab (window);
- if (tab == NULL)
+ page = gedit_window_get_active_page (window);
+ if (page == NULL)
return;
- file_save_as (tab, window);
+ file_save_as (page, window);
}
static gboolean
document_needs_saving (GeditDocument *doc)
{
- if (gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (doc)))
+ if (gedit_document_get_modified (doc))
return TRUE;
/* we check if it was deleted only for local files
@@ -915,7 +932,7 @@ _gedit_cmd_file_save_documents_list (GeditWindow *window,
GList *docs)
{
GList *l;
- GSList *tabs_to_save_as = NULL;
+ GSList *pages_to_save_as = NULL;
gedit_debug (DEBUG_COMMANDS);
@@ -926,23 +943,25 @@ _gedit_cmd_file_save_documents_list (GeditWindow *window,
l = docs;
while (l != NULL)
{
+ GeditPage *p;
GeditDocument *doc;
- GeditTab *t;
- GeditTabState state;
+ GeditViewContainer *c;
+ GeditViewContainerState state;
g_return_if_fail (GEDIT_IS_DOCUMENT (l->data));
doc = GEDIT_DOCUMENT (l->data);
- t = gedit_tab_get_from_document (doc);
- state = gedit_tab_get_state (t);
+ c = gedit_view_container_get_from_document (doc);
+ p = gedit_page_get_from_container (c);
+ state = gedit_view_container_get_state (c);
- g_return_if_fail (state != GEDIT_TAB_STATE_PRINTING);
- g_return_if_fail (state != GEDIT_TAB_STATE_PRINT_PREVIEWING);
- g_return_if_fail (state != GEDIT_TAB_STATE_CLOSING);
+ g_return_if_fail (state != GEDIT_VIEW_CONTAINER_STATE_PRINTING);
+ g_return_if_fail (state != GEDIT_VIEW_CONTAINER_STATE_PRINT_PREVIEWING);
+ g_return_if_fail (state != GEDIT_VIEW_CONTAINER_STATE_CLOSING);
- if ((state == GEDIT_TAB_STATE_NORMAL) ||
- (state == GEDIT_TAB_STATE_SHOWING_PRINT_PREVIEW) ||
- (state == GEDIT_TAB_STATE_GENERIC_NOT_EDITABLE))
+ if ((state == GEDIT_VIEW_CONTAINER_STATE_NORMAL) ||
+ (state == GEDIT_VIEW_CONTAINER_STATE_SHOWING_PRINT_PREVIEW) ||
+ (state == GEDIT_VIEW_CONTAINER_STATE_GENERIC_NOT_EDITABLE))
{
/* FIXME: manage the case of local readonly files owned by the
user is running gedit - Paolo (Dec. 8, 2005) */
@@ -950,37 +969,37 @@ _gedit_cmd_file_save_documents_list (GeditWindow *window,
gedit_document_get_readonly (doc))
{
if (document_needs_saving (doc))
- {
- tabs_to_save_as = g_slist_prepend (tabs_to_save_as,
- t);
- }
+ {
+ pages_to_save_as = g_slist_prepend (pages_to_save_as,
+ p);
+ }
}
else
{
- file_save (t, window);
+ file_save (p, window);
}
}
else
{
/* If the state is:
- - GEDIT_TAB_STATE_LOADING: we do not save since we are sure the file is unmodified
- - GEDIT_TAB_STATE_REVERTING: we do not save since the user wants
+ - GEDIT_VIEW_CONTAINER_STATE_LOADING: we do not save since we are sure the file is unmodified
+ - GEDIT_VIEW_CONTAINER_STATE_REVERTING: we do not save since the user wants
to return back to the version of the file she previously saved
- - GEDIT_TAB_STATE_SAVING: well, we are already saving (no need to save again)
- - GEDIT_TAB_STATE_PRINTING, GEDIT_TAB_STATE_PRINT_PREVIEWING: there is not a
+ - GEDIT_VIEW_CONTAINER_STATE_SAVING: well, we are already saving (no need to save again)
+ - GEDIT_VIEW_CONTAINER_STATE_PRINTING, GEDIT_VIEW_CONTAINER_STATE_PRINT_PREVIEWING: there is not a
real reason for not saving in this case, we do not save to avoid to run
two operations using the message area at the same time (may be we can remove
this limitation in the future). Note that SaveAll, ClosAll
and Quit are unsensitive if the window state is PRINTING.
- - GEDIT_TAB_STATE_GENERIC_ERROR: we do not save since the document contains
+ - GEDIT_VIEW_CONTAINER_STATE_GENERIC_ERROR: we do not save since the document contains
errors (I don't think this is a very frequent case, we should probably remove
this state)
- - GEDIT_TAB_STATE_LOADING_ERROR: there is nothing to save
- - GEDIT_TAB_STATE_REVERTING_ERROR: there is nothing to save and saving the current
+ - GEDIT_VIEW_CONTAINER_STATE_LOADING_ERROR: there is nothing to save
+ - GEDIT_VIEW_CONTAINER_STATE_REVERTING_ERROR: there is nothing to save and saving the current
document will overwrite the copy of the file the user wants to go back to
- - GEDIT_TAB_STATE_SAVING_ERROR: we do not save since we just failed to save, so there is
+ - GEDIT_VIEW_CONTAINER_STATE_SAVING_ERROR: we do not save since we just failed to save, so there is
no reason to automatically retry... we wait for user intervention
- - GEDIT_TAB_STATE_CLOSING: this state is invalid in this case
+ - GEDIT_VIEW_CONTAINER_STATE_CLOSING: this state is invalid in this case
*/
gchar *uri_for_display;
@@ -996,23 +1015,23 @@ _gedit_cmd_file_save_documents_list (GeditWindow *window,
l = g_list_next (l);
}
- if (tabs_to_save_as != NULL)
+ if (pages_to_save_as != NULL)
{
- GeditTab *tab;
+ GeditPage *page;
- tabs_to_save_as = g_slist_reverse (tabs_to_save_as );
+ pages_to_save_as = g_slist_reverse (pages_to_save_as );
g_return_if_fail (g_object_get_data (G_OBJECT (window),
- GEDIT_LIST_OF_TABS_TO_SAVE_AS) == NULL);
+ GEDIT_LIST_OF_PAGES_TO_SAVE_AS) == NULL);
g_object_set_data (G_OBJECT (window),
- GEDIT_LIST_OF_TABS_TO_SAVE_AS,
- tabs_to_save_as);
+ GEDIT_LIST_OF_PAGES_TO_SAVE_AS,
+ pages_to_save_as);
- tab = GEDIT_TAB (tabs_to_save_as->data);
+ page = GEDIT_PAGE (pages_to_save_as->data);
- gedit_window_set_active_tab (window, tab);
- file_save_as (tab, window);
+ gedit_window_set_active_page (window, page);
+ file_save_as (page, window);
}
}
@@ -1034,7 +1053,7 @@ gedit_commands_save_all_documents (GeditWindow *window)
void
_gedit_cmd_file_save_all (GtkAction *action,
- GeditWindow *window)
+ GeditWindow *window)
{
gedit_commands_save_all_documents (window);
}
@@ -1043,28 +1062,30 @@ void
gedit_commands_save_document (GeditWindow *window,
GeditDocument *document)
{
- GeditTab *tab;
+ GeditViewContainer *container;
+ GeditPage *page;
g_return_if_fail (GEDIT_IS_WINDOW (window));
g_return_if_fail (GEDIT_IS_DOCUMENT (document));
gedit_debug (DEBUG_COMMANDS);
- tab = gedit_tab_get_from_document (document);
- file_save (tab, window);
+ container = gedit_view_container_get_from_document (document);
+ page = gedit_page_get_from_container (container);
+ file_save (page, window);
}
/* File revert */
static void
-do_revert (GeditWindow *window,
- GeditTab *tab)
+do_revert (GeditWindow *window,
+ GeditViewContainer *container)
{
GeditDocument *doc;
gchar *docname;
gedit_debug (DEBUG_COMMANDS);
- doc = gedit_tab_get_document (tab);
+ doc = gedit_view_container_get_document (container);
docname = gedit_document_get_short_name_for_display (doc);
gedit_statusbar_flash_message (GEDIT_STATUSBAR (window->priv->statusbar),
@@ -1074,7 +1095,7 @@ do_revert (GeditWindow *window,
g_free (docname);
- _gedit_tab_revert (tab);
+ _gedit_view_container_revert (container);
}
static void
@@ -1082,22 +1103,25 @@ revert_dialog_response_cb (GtkDialog *dialog,
gint response_id,
GeditWindow *window)
{
- GeditTab *tab;
+ GeditPage *page;
gedit_debug (DEBUG_COMMANDS);
/* FIXME: we are relying on the fact that the dialog is
modal so the active tab can't be changed...
not very nice - Paolo (Oct 11, 2005) */
- tab = gedit_window_get_active_tab (window);
- if (tab == NULL)
+ page = gedit_window_get_active_page (window);
+ if (page == NULL)
return;
gtk_widget_destroy (GTK_WIDGET (dialog));
if (response_id == GTK_RESPONSE_OK)
{
- do_revert (window, tab);
+ GeditViewContainer *container;
+
+ container = gedit_page_get_active_view_container (page);
+ do_revert (window, container);
}
}
@@ -1118,7 +1142,7 @@ revert_dialog (GeditWindow *window,
docname);
g_free (docname);
- seconds = MAX (1, _gedit_document_get_seconds_since_last_save_or_load (doc));
+ seconds = MAX (1, gedit_document_get_seconds_since_last_save_or_load (doc));
if (seconds < 55)
{
@@ -1222,28 +1246,31 @@ revert_dialog (GeditWindow *window,
void
_gedit_cmd_file_revert (GtkAction *action,
- GeditWindow *window)
+ GeditWindow *window)
{
- GeditTab *tab;
- GeditDocument *doc;
- GtkWidget *dialog;
- GtkWindowGroup *wg;
+ GeditPage *page;
+ GeditViewContainer *container;
+ GeditDocument *doc;
+ GtkWidget *dialog;
+ GtkWindowGroup *wg;
gedit_debug (DEBUG_COMMANDS);
- tab = gedit_window_get_active_tab (window);
- g_return_if_fail (tab != NULL);
+ page = gedit_window_get_active_page (window);
+ g_return_if_fail (page != NULL);
+
+ container = gedit_page_get_active_view_container (page);
/* If we are already displaying a notification
* reverting will drop local modifications, do
* not bug the user further */
- if (gedit_tab_get_state (tab) == GEDIT_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION)
+ if (gedit_view_container_get_state (container) == GEDIT_VIEW_CONTAINER_STATE_EXTERNALLY_MODIFIED_NOTIFICATION)
{
- do_revert (window, tab);
+ do_revert (window, container);
return;
}
- doc = gedit_tab_get_document (tab);
+ doc = gedit_view_container_get_document (container);
g_return_if_fail (doc != NULL);
g_return_if_fail (!gedit_document_is_untitled (doc));
@@ -1265,24 +1292,26 @@ _gedit_cmd_file_revert (GtkAction *action,
/* Close tab */
static gboolean
-really_close_tab (GeditTab *tab)
+really_close_container (GeditViewContainer *container)
{
GtkWidget *toplevel;
GeditWindow *window;
gedit_debug (DEBUG_COMMANDS);
+
+ /* FIXME: This is wrong */
- g_return_val_if_fail (gedit_tab_get_state (tab) == GEDIT_TAB_STATE_CLOSING,
+ g_return_val_if_fail (gedit_view_container_get_state (container) == GEDIT_VIEW_CONTAINER_STATE_CLOSING,
FALSE);
- toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tab));
+ toplevel = gtk_widget_get_toplevel (GTK_WIDGET (container));
g_return_val_if_fail (GEDIT_IS_WINDOW (toplevel), FALSE);
- window = GEDIT_WINDOW (toplevel);
+ /*window = GEDIT_WINDOW (toplevel);
- gedit_window_close_tab (window, tab);
+ gedit_window_close_tab (window, page);
- if (gedit_window_get_active_tab (window) == NULL)
+ if (gedit_window_get_active_view_container (window) == NULL)
{
gboolean is_quitting;
@@ -1291,33 +1320,33 @@ really_close_tab (GeditTab *tab)
if (is_quitting)
gtk_widget_destroy (GTK_WIDGET (window));
- }
+ }*/
return FALSE;
}
static void
-tab_state_changed_while_saving (GeditTab *tab,
- GParamSpec *pspec,
- GeditWindow *window)
+view_container_state_changed_while_saving (GeditViewContainer *container,
+ GParamSpec *pspec,
+ GeditWindow *window)
{
- GeditTabState ts;
+ GeditViewContainerState ts;
- ts = gedit_tab_get_state (tab);
+ ts = gedit_view_container_get_state (container);
gedit_debug_message (DEBUG_COMMANDS, "State while saving: %d\n", ts);
/* When the state become NORMAL, it means the saving operation is
finished */
- if (ts == GEDIT_TAB_STATE_NORMAL)
+ if (ts == GEDIT_VIEW_CONTAINER_STATE_NORMAL)
{
GeditDocument *doc;
- g_signal_handlers_disconnect_by_func (tab,
- G_CALLBACK (tab_state_changed_while_saving),
+ g_signal_handlers_disconnect_by_func (container,
+ G_CALLBACK (view_container_state_changed_while_saving),
window);
- doc = gedit_tab_get_document (tab);
+ doc = gedit_view_container_get_document (container);
g_return_if_fail (doc != NULL);
/* If the saving operation failed or was interrupted, then the
@@ -1328,121 +1357,131 @@ tab_state_changed_while_saving (GeditTab *tab,
/* Close the document only if it has been succesfully saved.
Tab state is set to CLOSING (it is a state without exiting
transitions) and the tab is closed in a idle handler */
- _gedit_tab_mark_for_closing (tab);
+ _gedit_view_container_mark_for_closing (container);
g_idle_add_full (G_PRIORITY_HIGH_IDLE,
- (GSourceFunc)really_close_tab,
- tab,
+ (GSourceFunc)really_close_container,
+ container,
NULL);
}
}
static void
-save_and_close (GeditTab *tab,
+save_and_close (GeditPage *page,
GeditWindow *window)
{
+ GeditViewContainer *container;
+
gedit_debug (DEBUG_COMMANDS);
+ container = gedit_page_get_active_view_container (page);
+
/* Trace tab state changes */
- g_signal_connect (tab,
+ g_signal_connect (container,
"notify::state",
- G_CALLBACK (tab_state_changed_while_saving),
+ G_CALLBACK (view_container_state_changed_while_saving),
window);
- file_save (tab, window);
+ file_save (page, window);
}
static void
-save_as_and_close (GeditTab *tab,
+save_as_and_close (GeditPage *page,
GeditWindow *window)
{
+ GeditViewContainer *container;
+
gedit_debug (DEBUG_COMMANDS);
- g_object_set_data (G_OBJECT (tab),
- GEDIT_IS_CLOSING_TAB,
+ g_object_set_data (G_OBJECT (page),
+ GEDIT_IS_CLOSING_PAGE,
NULL);
+ container = gedit_page_get_active_view_container (page);
+
/* Trace tab state changes */
- g_signal_connect (tab,
+ g_signal_connect (container,
"notify::state",
- G_CALLBACK (tab_state_changed_while_saving),
+ G_CALLBACK (view_container_state_changed_while_saving),
window);
- gedit_window_set_active_tab (window, tab);
- file_save_as (tab, window);
+ gedit_window_set_active_page (window, page);
+ file_save_as (page, window);
}
static void
save_and_close_all_documents (const GList *docs,
GeditWindow *window)
{
- GList *tabs;
+ GList *pages;
GList *l;
GSList *sl;
- GSList *tabs_to_save_as;
- GSList *tabs_to_save_and_close;
- GList *tabs_to_close;
+ GSList *pages_to_save_as;
+ GSList *pages_to_save_and_close;
+ GList *pages_to_close;
gedit_debug (DEBUG_COMMANDS);
g_return_if_fail (!(gedit_window_get_state (window) & GEDIT_WINDOW_STATE_PRINTING));
- tabs = gtk_container_get_children (
+ pages = gtk_container_get_children (
GTK_CONTAINER (_gedit_window_get_notebook (window)));
- tabs_to_save_as = NULL;
- tabs_to_save_and_close = NULL;
- tabs_to_close = NULL;
+ pages_to_save_as = NULL;
+ pages_to_save_and_close = NULL;
+ pages_to_close = NULL;
- l = tabs;
+ l = pages;
while (l != NULL)
{
- GeditTab *t;
- GeditTabState state;
+ GeditPage *p;
+ GeditViewContainer *c;
+ GeditViewContainerState state;
GeditDocument *doc;
- t = GEDIT_TAB (l->data);
+ p = GEDIT_PAGE (l->data);
+ c = gedit_page_get_active_view_container (p);
- state = gedit_tab_get_state (t);
- doc = gedit_tab_get_document (t);
+ state = gedit_view_container_get_state (c);
+ doc = gedit_view_container_get_document (c);
/* If the state is: ([*] invalid states)
- - GEDIT_TAB_STATE_NORMAL: close (and if needed save)
- - GEDIT_TAB_STATE_LOADING: close, we are sure the file is unmodified
- - GEDIT_TAB_STATE_REVERTING: since the user wants
+ - GEDIT_VIEW_CONTAINER_STATE_NORMAL: close (and if needed save)
+ - GEDIT_VIEW_CONTAINER_STATE_LOADING: close, we are sure the file is unmodified
+ - GEDIT_VIEW_CONTAINER_STATE_REVERTING: since the user wants
to return back to the version of the file she previously saved, we can close
without saving (CHECK: are we sure this is the right behavior, suppose the case
the original file has been deleted)
- - [*] GEDIT_TAB_STATE_SAVING: invalid, ClosAll
+ - [*] GEDIT_VIEW_CONTAINER_STATE_SAVING: invalid, ClosAll
and Quit are unsensitive if the window state is SAVING.
- - [*] GEDIT_TAB_STATE_PRINTING, GEDIT_TAB_STATE_PRINT_PREVIEWING: there is not a
+ - [*] GEDIT_VIEW_CONTAINER_STATE_PRINTING, GEDIT_VIEW_CONTAINER_STATE_PRINT_PREVIEWING: there is not a
real reason for not closing in this case, we do not save to avoid to run
two operations using the message area at the same time (may be we can remove
this limitation in the future). Note that ClosAll
and Quit are unsensitive if the window state is PRINTING.
- - GEDIT_TAB_STATE_SHOWING_PRINT_PREVIEW: close (and if needed save)
- - GEDIT_TAB_STATE_LOADING_ERROR: close without saving (if the state is LOADING_ERROR then the
+ - GEDIT_VIEW_CONTAINER_STATE_SHOWING_PRINT_PREVIEW: close (and if needed save)
+ - GEDIT_VIEW_CONTAINER_STATE_LOADING_ERROR: close without saving (if the state is LOADING_ERROR then the
document is not modified)
- - GEDIT_TAB_STATE_REVERTING_ERROR: we do not close since the document contains errors
- - GEDIT_TAB_STATE_SAVING_ERROR: we do not close since the document contains errors
- - GEDIT_TAB_STATE_GENERIC_ERROR: we do not close since the document contains
+ - GEDIT_VIEW_CONTAINER_STATE_REVERTING_ERROR: we do not close since the document contains errors
+ - GEDIT_VIEW_CONTAINER_STATE_SAVING_ERROR: we do not close since the document contains errors
+ - GEDIT_VIEW_CONTAINER_STATE_GENERIC_ERROR: we do not close since the document contains
errors (CHECK: we should problably remove this state)
- - [*] GEDIT_TAB_STATE_CLOSING: this state is invalid in this case
+ - [*] GEDIT_VIEW_CONTAINER_STATE_CLOSING: this state is invalid in this case
*/
- g_return_if_fail (state != GEDIT_TAB_STATE_PRINTING);
- g_return_if_fail (state != GEDIT_TAB_STATE_PRINT_PREVIEWING);
- g_return_if_fail (state != GEDIT_TAB_STATE_CLOSING);
- g_return_if_fail (state != GEDIT_TAB_STATE_SAVING);
+ g_return_if_fail (state != GEDIT_VIEW_CONTAINER_STATE_PRINTING);
+ g_return_if_fail (state != GEDIT_VIEW_CONTAINER_STATE_PRINT_PREVIEWING);
+ g_return_if_fail (state != GEDIT_VIEW_CONTAINER_STATE_CLOSING);
+ g_return_if_fail (state != GEDIT_VIEW_CONTAINER_STATE_SAVING);
- if ((state != GEDIT_TAB_STATE_SAVING_ERROR) &&
- (state != GEDIT_TAB_STATE_GENERIC_ERROR) &&
- (state != GEDIT_TAB_STATE_REVERTING_ERROR))
+ if ((state != GEDIT_VIEW_CONTAINER_STATE_SAVING_ERROR) &&
+ (state != GEDIT_VIEW_CONTAINER_STATE_GENERIC_ERROR) &&
+ (state != GEDIT_VIEW_CONTAINER_STATE_REVERTING_ERROR))
{
if ((g_list_index ((GList *)docs, doc) >= 0) &&
- (state != GEDIT_TAB_STATE_LOADING) &&
- (state != GEDIT_TAB_STATE_LOADING_ERROR) &&
- (state != GEDIT_TAB_STATE_REVERTING)) /* CHECK: is this the right behavior with REVERTING ?*/
+ (state != GEDIT_VIEW_CONTAINER_STATE_LOADING) &&
+ (state != GEDIT_VIEW_CONTAINER_STATE_LOADING_ERROR) &&
+ (state != GEDIT_VIEW_CONTAINER_STATE_REVERTING)) /* CHECK: is this the right behavior with REVERTING ?*/
{
/* The document must be saved before closing */
g_return_if_fail (document_needs_saving (doc));
@@ -1452,63 +1491,63 @@ save_and_close_all_documents (const GList *docs,
if (gedit_document_is_untitled (doc) ||
gedit_document_get_readonly (doc))
{
- g_object_set_data (G_OBJECT (t),
- GEDIT_IS_CLOSING_TAB,
+ g_object_set_data (G_OBJECT (p),
+ GEDIT_IS_CLOSING_PAGE,
GBOOLEAN_TO_POINTER (TRUE));
- tabs_to_save_as = g_slist_prepend (tabs_to_save_as,
- t);
+ pages_to_save_as = g_slist_prepend (pages_to_save_as,
+ p);
}
else
{
- tabs_to_save_and_close = g_slist_prepend (tabs_to_save_and_close,
- t);
+ pages_to_save_and_close = g_slist_prepend (pages_to_save_and_close,
+ p);
}
}
else
{
/* The document must be closed without saving */
- tabs_to_close = g_list_prepend (tabs_to_close,
- t);
+ pages_to_close = g_list_prepend (pages_to_close,
+ p);
}
}
l = g_list_next (l);
}
- g_list_free (tabs);
+ g_list_free (pages);
/* Close all tabs to close (in a sync way) */
- gedit_window_close_tabs (window, tabs_to_close);
- g_list_free (tabs_to_close);
+ gedit_window_close_pages (window, pages_to_close);
+ g_list_free (pages_to_close);
/* Save and close all the files in tabs_to_save_and_close */
- sl = tabs_to_save_and_close;
+ sl = pages_to_save_and_close;
while (sl != NULL)
{
- save_and_close (GEDIT_TAB (sl->data),
+ save_and_close (GEDIT_PAGE (sl->data),
window);
sl = g_slist_next (sl);
}
- g_slist_free (tabs_to_save_and_close);
+ g_slist_free (pages_to_save_and_close);
/* Save As and close all the files in tabs_to_save_as */
- if (tabs_to_save_as != NULL)
+ if (pages_to_save_as != NULL)
{
- GeditTab *tab;
+ GeditPage *page;
- tabs_to_save_as = g_slist_reverse (tabs_to_save_as );
+ pages_to_save_as = g_slist_reverse (pages_to_save_as );
g_return_if_fail (g_object_get_data (G_OBJECT (window),
- GEDIT_LIST_OF_TABS_TO_SAVE_AS) == NULL);
+ GEDIT_LIST_OF_PAGES_TO_SAVE_AS) == NULL);
g_object_set_data (G_OBJECT (window),
- GEDIT_LIST_OF_TABS_TO_SAVE_AS,
- tabs_to_save_as);
+ GEDIT_LIST_OF_PAGES_TO_SAVE_AS,
+ pages_to_save_as);
- tab = GEDIT_TAB (tabs_to_save_as->data);
+ page = GEDIT_PAGE (pages_to_save_as->data);
- save_as_and_close (tab, window);
+ save_as_and_close (page, window);
}
}
@@ -1516,27 +1555,30 @@ static void
save_and_close_document (const GList *docs,
GeditWindow *window)
{
- GeditTab *tab;
+ GeditPage *page;
+ GeditViewContainer *container;
gedit_debug (DEBUG_COMMANDS);
g_return_if_fail (docs->next == NULL);
- tab = gedit_tab_get_from_document (GEDIT_DOCUMENT (docs->data));
- g_return_if_fail (tab != NULL);
+ container = gedit_view_container_get_from_document (GEDIT_DOCUMENT (docs->data));
+ g_return_if_fail (container != NULL);
+
+ page = gedit_page_get_from_container (container);
- save_and_close (tab, window);
+ save_and_close (page, window);
}
static void
-close_all_tabs (GeditWindow *window)
+close_all_pages (GeditWindow *window)
{
gboolean is_quitting;
gedit_debug (DEBUG_COMMANDS);
/* There is no document to save -> close all tabs */
- gedit_window_close_all_tabs (window);
+ gedit_window_close_all_pages (window);
is_quitting = GPOINTER_TO_BOOLEAN (g_object_get_data (G_OBJECT (window),
GEDIT_IS_QUITTING));
@@ -1551,14 +1593,17 @@ static void
close_document (GeditWindow *window,
GeditDocument *doc)
{
- GeditTab *tab;
+ GeditPage *page;
+ GeditViewContainer *container;
gedit_debug (DEBUG_COMMANDS);
- tab = gedit_tab_get_from_document (doc);
- g_return_if_fail (tab != NULL);
+ container = gedit_view_container_get_from_document (doc);
+ g_return_if_fail (container != NULL);
+
+ page = gedit_page_get_from_container (container);
- gedit_window_close_tab (window, tab);
+ gedit_window_close_page (window, page);
}
static void
@@ -1589,7 +1634,7 @@ close_confirmation_dialog_response_handler (GeditCloseConfirmationDialog *dlg,
* because close_all_tabs could destroy the gedit window */
gtk_widget_destroy (GTK_WIDGET (dlg));
- close_all_tabs (window);
+ close_all_pages (window);
return;
}
@@ -1621,7 +1666,7 @@ close_confirmation_dialog_response_handler (GeditCloseConfirmationDialog *dlg,
* because close_all_tabs could destroy the gedit window */
gtk_widget_destroy (GTK_WIDGET (dlg));
- close_all_tabs (window);
+ close_all_pages (window);
return;
}
@@ -1649,18 +1694,22 @@ close_confirmation_dialog_response_handler (GeditCloseConfirmationDialog *dlg,
gtk_widget_destroy (GTK_WIDGET (dlg));
}
-/* Returns TRUE if the tab can be immediately closed */
+/* Returns TRUE if the page can be immediately closed */
static gboolean
-tab_can_close (GeditTab *tab,
- GtkWindow *window)
+page_can_close (GeditPage *page,
+ GtkWindow *window)
{
+ GeditViewContainer *container;
GeditDocument *doc;
gedit_debug (DEBUG_COMMANDS);
- doc = gedit_tab_get_document (tab);
+ /* FIXME: We have to take care of all containers */
- if (!_gedit_tab_can_close (tab))
+ container = gedit_page_get_active_view_container (page);
+ doc = gedit_view_container_get_document (container);
+
+ if (!_gedit_view_container_can_close (container))
{
GtkWidget *dlg;
@@ -1689,12 +1738,12 @@ tab_can_close (GeditTab *tab,
* GEDIT_IS_CLOSING_ALL flag!
*/
void
-_gedit_cmd_file_close_tab (GeditTab *tab,
- GeditWindow *window)
+_gedit_cmd_file_close_page (GeditPage *page,
+ GeditWindow *window)
{
gedit_debug (DEBUG_COMMANDS);
- g_return_if_fail (GTK_WIDGET (window) == gtk_widget_get_toplevel (GTK_WIDGET (tab)));
+ g_return_if_fail (GTK_WIDGET (window) == gtk_widget_get_toplevel (GTK_WIDGET (page)));
g_object_set_data (G_OBJECT (window),
GEDIT_IS_CLOSING_ALL,
@@ -1704,23 +1753,23 @@ _gedit_cmd_file_close_tab (GeditTab *tab,
GEDIT_IS_QUITTING,
GBOOLEAN_TO_POINTER (FALSE));
- if (tab_can_close (tab, GTK_WINDOW (window)))
- gedit_window_close_tab (window, tab);
+ if (page_can_close (page, GTK_WINDOW (window)))
+ gedit_window_close_page (window, page);
}
void
_gedit_cmd_file_close (GtkAction *action,
- GeditWindow *window)
+ GeditWindow *window)
{
- GeditTab *active_tab;
+ GeditPage *active_page;
gedit_debug (DEBUG_COMMANDS);
- active_tab = gedit_window_get_active_tab (window);
- if (active_tab == NULL)
+ active_page = gedit_window_get_active_page (window);
+ if (active_page == NULL)
return;
- _gedit_cmd_file_close_tab (active_tab, window);
+ _gedit_cmd_file_close_page (active_page, window);
}
/* Close all tabs */
@@ -1751,7 +1800,7 @@ file_close_all (GeditWindow *window,
if (unsaved_docs == NULL)
{
/* There is no document to save -> close all tabs */
- gedit_window_close_all_tabs (window);
+ gedit_window_close_all_pages (window);
if (is_quitting)
gtk_widget_destroy (GTK_WIDGET (window));
@@ -1762,15 +1811,18 @@ file_close_all (GeditWindow *window,
if (unsaved_docs->next == NULL)
{
/* There is only one unsaved document */
- GeditTab *tab;
+ GeditPage *page;
+ GeditViewContainer *container;
GeditDocument *doc;
doc = GEDIT_DOCUMENT (unsaved_docs->data);
- tab = gedit_tab_get_from_document (doc);
- g_return_if_fail (tab != NULL);
+ container = gedit_view_container_get_from_document (doc);
+ g_return_if_fail (container != NULL);
+
+ page = gedit_page_get_from_container (container);
- gedit_window_set_active_tab (window, tab);
+ gedit_window_set_active_page (window, page);
dlg = gedit_close_confirmation_dialog_new_single (
GTK_WINDOW (window),
@@ -1796,7 +1848,7 @@ file_close_all (GeditWindow *window,
void
_gedit_cmd_file_close_all (GtkAction *action,
- GeditWindow *window)
+ GeditWindow *window)
{
gedit_debug (DEBUG_COMMANDS);
@@ -1811,7 +1863,7 @@ _gedit_cmd_file_close_all (GtkAction *action,
/* Quit */
void
_gedit_cmd_file_quit (GtkAction *action,
- GeditWindow *window)
+ GeditWindow *window)
{
gedit_debug (DEBUG_COMMANDS);
diff --git a/gedit/gedit-commands-search.c b/gedit/gedit-commands-search.c
index 5a8797a..9a39a4e 100644
--- a/gedit/gedit-commands-search.c
+++ b/gedit/gedit-commands-search.c
@@ -45,6 +45,7 @@
#include "gedit-window-private.h"
#include "gedit-utils.h"
#include "dialogs/gedit-search-dialog.h"
+#include "gedit-text-buffer.h"
#define GEDIT_SEARCH_DIALOG_KEY "gedit-search-dialog-key"
#define GEDIT_LAST_SEARCH_DATA_KEY "gedit-last-search-data-key"
@@ -157,7 +158,11 @@ run_search (GeditView *view,
GtkTextIter match_end;
gboolean found = FALSE;
- doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
+ doc = gedit_view_get_document (view);
+
+ /* FIXME */
+ if (!GEDIT_IS_TEXT_BUFFER (doc))
+ return FALSE;
if (!search_backwards)
{
@@ -165,11 +170,11 @@ run_search (GeditView *view,
NULL,
&start_iter);
- found = gedit_document_search_forward (doc,
- &start_iter,
- NULL,
- &match_start,
- &match_end);
+ found = gedit_text_buffer_search_forward (GEDIT_TEXT_BUFFER (doc),
+ &start_iter,
+ NULL,
+ &match_start,
+ &match_end);
}
else
{
@@ -177,27 +182,27 @@ run_search (GeditView *view,
&start_iter,
NULL);
- found = gedit_document_search_backward (doc,
- NULL,
- &start_iter,
- &match_start,
- &match_end);
+ found = gedit_text_buffer_search_backward (GEDIT_TEXT_BUFFER (doc),
+ NULL,
+ &start_iter,
+ &match_start,
+ &match_end);
}
if (!found && wrap_around)
{
if (!search_backwards)
- found = gedit_document_search_forward (doc,
- NULL,
- NULL, /* FIXME: set the end_inter */
- &match_start,
- &match_end);
+ found = gedit_text_buffer_search_forward (GEDIT_TEXT_BUFFER (doc),
+ NULL,
+ NULL, /* FIXME: set the end_inter */
+ &match_start,
+ &match_end);
else
- found = gedit_document_search_backward (doc,
- NULL, /* FIXME: set the start_inter */
- NULL,
- &match_start,
- &match_end);
+ found = gedit_text_buffer_search_backward (GEDIT_TEXT_BUFFER (doc),
+ NULL, /* FIXME: set the start_inter */
+ NULL,
+ &match_start,
+ &match_end);
}
if (found)
@@ -242,7 +247,11 @@ do_find (GeditSearchDialog *dialog,
if (active_view == NULL)
return;
- doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (active_view)));
+ doc = gedit_view_get_document (active_view);
+
+ /* FIXME */
+ if (!GEDIT_IS_TEXT_BUFFER (doc))
+ return;
entry_text = gedit_search_dialog_get_search_text (dialog);
@@ -254,13 +263,15 @@ do_find (GeditSearchDialog *dialog,
GEDIT_SEARCH_SET_CASE_SENSITIVE (flags, match_case);
GEDIT_SEARCH_SET_ENTIRE_WORD (flags, entire_word);
- search_text = gedit_document_get_search_text (doc, &old_flags);
+ search_text = gedit_text_buffer_get_search_text (GEDIT_TEXT_BUFFER (doc),
+ &old_flags);
if ((search_text == NULL) ||
(strcmp (search_text, entry_text) != 0) ||
(flags != old_flags))
{
- gedit_document_set_search_text (doc, entry_text, flags);
+ gedit_text_buffer_set_search_text (GEDIT_TEXT_BUFFER (doc),
+ entry_text, flags);
}
g_free (search_text);
@@ -335,7 +346,7 @@ do_replace (GeditSearchDialog *dialog,
gboolean match_case;
doc = gedit_window_get_active_document (window);
- if (doc == NULL)
+ if (doc == NULL || !GEDIT_IS_TEXT_BUFFER (doc))
return;
search_entry_text = gedit_search_dialog_get_search_text (dialog);
@@ -395,7 +406,11 @@ do_replace_all (GeditSearchDialog *dialog,
if (active_view == NULL)
return;
- doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (active_view)));
+ doc = gedit_view_get_document (active_view);
+
+ /* FIXME */
+ if (!GEDIT_IS_TEXT_BUFFER (doc))
+ return;
search_entry_text = gedit_search_dialog_get_search_text (dialog);
g_return_if_fail ((search_entry_text) != NULL);
@@ -411,10 +426,10 @@ do_replace_all (GeditSearchDialog *dialog,
GEDIT_SEARCH_SET_CASE_SENSITIVE (flags, match_case);
GEDIT_SEARCH_SET_ENTIRE_WORD (flags, entire_word);
- count = gedit_document_replace_all (doc,
- search_entry_text,
- replace_entry_text,
- flags);
+ count = gedit_text_buffer_replace_all (GEDIT_TEXT_BUFFER (doc),
+ search_entry_text,
+ replace_entry_text,
+ flags);
if (count > 0)
{
@@ -516,6 +531,10 @@ _gedit_cmd_search_find (GtkAction *action,
doc = gedit_window_get_active_document (window);
g_return_if_fail (doc != NULL);
+ /* FIXME */
+ if (!GEDIT_IS_TEXT_BUFFER (doc))
+ return;
+
selection_exists = get_selected_text (GTK_TEXT_BUFFER (doc),
&find_text,
&sel_len);
@@ -582,6 +601,10 @@ _gedit_cmd_search_replace (GtkAction *action,
doc = gedit_window_get_active_document (window);
g_return_if_fail (doc != NULL);
+
+ /* FIXME */
+ if (!GEDIT_IS_TEXT_BUFFER (doc))
+ return;
selection_exists = get_selected_text (GTK_TEXT_BUFFER (doc),
&find_text,
@@ -650,9 +673,14 @@ _gedit_cmd_search_clear_highlight (GtkAction *action,
gedit_debug (DEBUG_COMMANDS);
doc = gedit_window_get_active_document (window);
- gedit_document_set_search_text (GEDIT_DOCUMENT (doc),
- "",
- GEDIT_SEARCH_DONT_SET_FLAGS);
+
+ /* FIXME */
+ if (!GEDIT_IS_TEXT_BUFFER (doc))
+ return;
+
+ gedit_text_buffer_set_search_text (GEDIT_TEXT_BUFFER (doc),
+ "",
+ GEDIT_SEARCH_DONT_SET_FLAGS);
}
void
diff --git a/gedit/gedit-commands-view.c b/gedit/gedit-commands-view.c
index 2366e49..8a44097 100644
--- a/gedit/gedit-commands-view.c
+++ b/gedit/gedit-commands-view.c
@@ -152,3 +152,47 @@ _gedit_cmd_view_leave_fullscreen_mode (GtkAction *action,
(view_action, G_CALLBACK (_gedit_cmd_view_toggle_fullscreen_mode),
window);
}
+
+void
+_gedit_cmd_view_split_horizontally (GtkAction *action,
+ GeditWindow *window)
+{
+ GeditPage *page;
+
+ page = gedit_window_get_active_page (window);
+
+ _gedit_page_split_horizontally (page);
+}
+
+void
+_gedit_cmd_view_split_vertically (GtkAction *action,
+ GeditWindow *window)
+{
+ GeditPage *page;
+
+ page = gedit_window_get_active_page (window);
+
+ _gedit_page_split_vertically (page);
+}
+
+void
+_gedit_cmd_view_unsplit (GtkAction *action,
+ GeditWindow *window)
+{
+ GeditPage *page;
+
+ page = gedit_window_get_active_page (window);
+
+ _gedit_page_unsplit (page);
+}
+
+void
+_gedit_cmd_view_switch_split (GtkAction *action,
+ GeditWindow *window)
+{
+ GeditPage *page;
+
+ page = gedit_window_get_active_page (window);
+
+ _gedit_page_switch_between_splits (page);
+}
diff --git a/gedit/gedit-commands.h b/gedit/gedit-commands.h
index 08e7088..6995cd1 100644
--- a/gedit/gedit-commands.h
+++ b/gedit/gedit-commands.h
@@ -120,6 +120,18 @@ void _gedit_cmd_view_toggle_fullscreen_mode (GtkAction *action,
GeditWindow *window);
void _gedit_cmd_view_leave_fullscreen_mode (GtkAction *action,
GeditWindow *window);
+void _gedit_cmd_view_split_horizontally (GtkAction *action,
+ GeditWindow *window);
+void _gedit_cmd_view_split_vertically (GtkAction *action,
+ GeditWindow *window);
+void _gedit_cmd_view_clone_horizontally (GtkAction *action,
+ GeditWindow *window);
+void _gedit_cmd_view_clone_vertically (GtkAction *action,
+ GeditWindow *window);
+void _gedit_cmd_view_unsplit (GtkAction *action,
+ GeditWindow *window);
+void _gedit_cmd_view_switch_split (GtkAction *action,
+ GeditWindow *window);
void _gedit_cmd_search_find (GtkAction *action,
GeditWindow *window);
@@ -134,7 +146,7 @@ void _gedit_cmd_search_clear_highlight (GtkAction *action,
void _gedit_cmd_search_goto_line (GtkAction *action,
GeditWindow *window);
void _gedit_cmd_search_incremental_search (GtkAction *action,
- GeditWindow *window);
+ GeditWindow *window);
void _gedit_cmd_documents_previous_document (GtkAction *action,
GeditWindow *window);
@@ -148,7 +160,7 @@ void _gedit_cmd_help_contents (GtkAction *action,
void _gedit_cmd_help_about (GtkAction *action,
GeditWindow *window);
-void _gedit_cmd_file_close_tab (GeditTab *tab,
+void _gedit_cmd_file_close_page (GeditPage *page,
GeditWindow *window);
void _gedit_cmd_file_save_documents_list (GeditWindow *window,
diff --git a/gedit/gedit-data-binding.c b/gedit/gedit-data-binding.c
new file mode 100644
index 0000000..10f13bf
--- /dev/null
+++ b/gedit/gedit-data-binding.c
@@ -0,0 +1,303 @@
+/*
+ * gedit-data-binding.c
+ *
+ * Copyright (C) 2009 - Jesse van den Kieboom
+ *
+ * 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., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "gedit-data-binding.h"
+
+#include <gdk/gdk.h>
+
+typedef struct
+{
+ GObject *object;
+
+ gchar *property;
+ GType type;
+
+ guint notify_id;
+ GeditDataBindingConversion conversion;
+ gpointer userdata;
+} Binding;
+
+typedef enum
+{
+ GEDIT_DATA_BINDING_NONE = 0,
+ GEDIT_DATA_BINDING_MUTUAL = 1 << 0
+} GeditDataBindingFlags;
+
+struct _GeditDataBinding
+{
+ Binding source;
+ Binding dest;
+ GeditDataBindingFlags flags;
+};
+
+static void on_data_binding_destroy (GeditDataBinding *binding, GObject *source);
+static void gedit_data_binding_finalize (GeditDataBinding *binding);
+
+static void on_data_binding_changed (GObject *source, GParamSpec *spec, GeditDataBinding *binding);
+
+static void
+binding_connect (GeditDataBinding *binding,
+ Binding *bd)
+{
+ gchar *nid = g_strconcat ("notify::", bd->property, NULL);
+ bd->notify_id = g_signal_connect_after (bd->object, nid,
+ G_CALLBACK(on_data_binding_changed),
+ binding);
+ g_free(nid);
+}
+
+static void
+binding_fill (Binding *binding,
+ gpointer object,
+ const gchar *property,
+ GType type,
+ GeditDataBindingConversion conversion,
+ gpointer userdata)
+{
+ binding->object = G_OBJECT (object);
+ binding->property = g_strdup (property);
+ binding->type = type;
+ binding->conversion = conversion ? conversion : (GeditDataBindingConversion)g_value_transform;
+ binding->userdata = userdata;
+}
+
+static GeditDataBinding *
+gedit_data_binding_create (gpointer source,
+ const gchar *source_property,
+ gpointer dest, const gchar *dest_property,
+ GeditDataBindingConversion source_to_dest,
+ GeditDataBindingConversion dest_to_source,
+ gpointer userdata,
+ GeditDataBindingFlags flags)
+{
+ GeditDataBinding *binding;
+ GObjectClass *sclass;
+ GObjectClass *dclass;
+ GParamSpec *sspec;
+ GParamSpec *dspec;
+
+ g_return_val_if_fail (G_IS_OBJECT (source), NULL);
+ g_return_val_if_fail (G_IS_OBJECT (dest), NULL);
+
+ sclass = G_OBJECT_GET_CLASS (source);
+ dclass = G_OBJECT_GET_CLASS (dest);
+
+ sspec = g_object_class_find_property (sclass, source_property);
+
+ if (!sspec)
+ {
+ g_warning("No such source property found: %s", source_property);
+ return NULL;
+ }
+
+ dspec = g_object_class_find_property (dclass, dest_property);
+
+ if (!dspec)
+ {
+ g_warning("No such dest property found: %s", dest_property);
+ return NULL;
+ }
+
+ binding = g_slice_new0 (GeditDataBinding);
+
+ binding->flags = flags;
+
+ binding_fill (&binding->source, source, source_property,
+ G_PARAM_SPEC_VALUE_TYPE(sspec), source_to_dest, userdata);
+ binding_fill (&binding->dest, dest, dest_property,
+ G_PARAM_SPEC_VALUE_TYPE(dspec), dest_to_source, userdata);
+
+ binding_connect(binding, &binding->source);
+
+ if (flags & GEDIT_DATA_BINDING_MUTUAL)
+ binding_connect (binding, &binding->dest);
+
+ g_object_weak_ref (binding->source.object,
+ (GWeakNotify)on_data_binding_destroy, binding);
+ g_object_weak_ref (binding->dest.object,
+ (GWeakNotify)on_data_binding_destroy, binding);
+
+ /* initial value */
+ on_data_binding_changed (binding->source.object, NULL, binding);
+
+ return binding;
+}
+
+GeditDataBinding *
+gedit_data_binding_new_full (gpointer source,
+ const gchar *source_property,
+ gpointer dest,
+ const gchar *dest_property,
+ GeditDataBindingConversion conversion,
+ gpointer userdata)
+{
+ return gedit_data_binding_create (source, source_property,
+ dest, dest_property,
+ conversion, NULL,
+ userdata,
+ GEDIT_DATA_BINDING_NONE);
+}
+
+GeditDataBinding *
+gedit_data_binding_new (gpointer source,
+ const gchar *source_property,
+ gpointer dest,
+ const gchar *dest_property)
+{
+ return gedit_data_binding_new_full (source, source_property,
+ dest, dest_property,
+ NULL, NULL);
+}
+
+GeditDataBinding *
+gedit_data_binding_new_mutual_full (gpointer source,
+ const gchar *source_property,
+ gpointer dest,
+ const gchar *dest_property,
+ GeditDataBindingConversion source_to_dest,
+ GeditDataBindingConversion dest_to_source,
+ gpointer userdata)
+{
+ return gedit_data_binding_create (source, source_property,
+ dest, dest_property,
+ source_to_dest, dest_to_source,
+ userdata,
+ GEDIT_DATA_BINDING_MUTUAL);
+}
+
+GeditDataBinding *
+gedit_data_binding_new_mutual (gpointer source,
+ const gchar *source_property,
+ gpointer dest,
+ const gchar *dest_property)
+{
+ return gedit_data_binding_new_mutual_full (source, source_property,
+ dest, dest_property,
+ NULL, NULL,
+ NULL);
+}
+static void
+gedit_data_binding_finalize (GeditDataBinding *binding)
+{
+ g_free (binding->source.property);
+ g_free (binding->dest.property);
+
+ g_slice_free (GeditDataBinding, binding);
+}
+
+void
+gedit_data_binding_free (GeditDataBinding *binding)
+{
+ if (binding->source.notify_id)
+ g_signal_handler_disconnect (binding->source.object,
+ binding->source.notify_id);
+
+ if (binding->dest.notify_id)
+ g_signal_handler_disconnect (binding->dest.object,
+ binding->dest.notify_id);
+
+ g_object_weak_unref (binding->source.object,
+ (GWeakNotify)on_data_binding_destroy, binding);
+ g_object_weak_unref (binding->dest.object,
+ (GWeakNotify)on_data_binding_destroy, binding);
+
+ gedit_data_binding_finalize (binding);
+}
+
+static void
+on_data_binding_destroy (GeditDataBinding *binding,
+ GObject *object)
+{
+ Binding *bd = binding->source.object == object ? &binding->dest : &binding->source;
+
+ /* disconnect notify handler */
+ if (bd->notify_id)
+ g_signal_handler_disconnect (bd->object, bd->notify_id);
+
+ /* remove weak ref */
+ g_object_weak_unref (bd->object, (GWeakNotify)on_data_binding_destroy,
+ binding);
+
+ /* finalize binding */
+ gedit_data_binding_finalize (binding);
+}
+
+static void
+on_data_binding_changed (GObject *object,
+ GParamSpec *spec,
+ GeditDataBinding *binding)
+{
+ Binding *source = binding->source.object == object ? &binding->source : &binding->dest;
+ Binding *dest = binding->source.object == object ? &binding->dest : &binding->source;
+
+ /* Transmit to dest */
+ GValue value = { 0, };
+ g_value_init (&value, dest->type);
+
+ GValue svalue = { 0, };
+ g_value_init (&svalue, source->type);
+
+ g_object_get_property (source->object, source->property, &svalue);
+ g_object_get_property (dest->object, dest->property, &value);
+
+ if (source->conversion (&svalue, &value, source->userdata))
+ {
+ if (dest->notify_id)
+ g_signal_handler_block (dest->object, dest->notify_id);
+
+ g_object_set_property (dest->object, dest->property, &value);
+
+ if (dest->notify_id)
+ g_signal_handler_unblock (dest->object, dest->notify_id);
+ }
+
+ g_value_unset (&value);
+ g_value_unset (&svalue);
+}
+
+/* conversion utilities */
+gboolean
+gedit_data_binding_color_to_string (GValue const *color,
+ GValue *string,
+ gpointer userdata)
+{
+ GdkColor *clr = g_value_get_boxed (color);
+ gchar *s = gdk_color_to_string (clr);
+
+ g_value_take_string (string, s);
+
+ return TRUE;
+}
+
+gboolean
+gedit_data_binding_string_to_color (GValue const *string,
+ GValue *color,
+ gpointer userdata)
+{
+ const gchar *s = g_value_get_string (string);
+ GdkColor clr;
+
+ gdk_color_parse (s, &clr);
+ g_value_set_boxed (color, &clr);
+
+ return TRUE;
+}
+
diff --git a/gedit/gedit-data-binding.h b/gedit/gedit-data-binding.h
new file mode 100644
index 0000000..2955206
--- /dev/null
+++ b/gedit/gedit-data-binding.h
@@ -0,0 +1,72 @@
+/*
+ * gedit-data-binding.h
+ *
+ * Copyright (C) 2009 - Jesse van den Kieboom
+ *
+ * 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., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GEDIT_DATA_BINDING_H__
+#define __GEDIT_DATA_BINDING_H__
+
+#include <glib-object.h>
+
+typedef struct _GeditDataBinding GeditDataBinding;
+
+typedef gboolean (*GeditDataBindingConversion) (GValue const *source,
+ GValue *dest,
+ gpointer userdata);
+
+GeditDataBinding *gedit_data_binding_new (gpointer source,
+ const gchar *source_property,
+ gpointer dest,
+ const gchar *dest_property);
+
+GeditDataBinding *gedit_data_binding_new_full (gpointer source,
+ const gchar *source_property,
+ gpointer dest,
+ const gchar *dest_property,
+ GeditDataBindingConversion conversion,
+ gpointer userdata);
+
+GeditDataBinding *gedit_data_binding_new_mutual (gpointer source,
+ const gchar *source_property,
+ gpointer dest,
+ const gchar *dest_property);
+
+GeditDataBinding *gedit_data_binding_new_mutual_full
+ (gpointer source,
+ const gchar *source_property,
+ gpointer dest,
+ const gchar *dest_property,
+ GeditDataBindingConversion source_to_dest,
+ GeditDataBindingConversion dest_to_source,
+ gpointer userdata);
+
+void gedit_data_binding_free (GeditDataBinding *binding);
+
+/* conversion utilities */
+gboolean gedit_data_binding_color_to_string
+ (GValue const *color,
+ GValue *string,
+ gpointer userdata);
+gboolean gedit_data_binding_string_to_color
+ (GValue const *string,
+ GValue *color,
+ gpointer userdata);
+
+#endif /* __GEDIT_DATA_BINDING_H__ */
+
diff --git a/gedit/gedit-debug.c b/gedit/gedit-debug.c
index 163a5a5..4c623cc 100644
--- a/gedit/gedit-debug.c
+++ b/gedit/gedit-debug.c
@@ -66,8 +66,8 @@ gedit_debug_init (void)
debug = debug | GEDIT_DEBUG_PRINT;
if (g_getenv ("GEDIT_DEBUG_PLUGINS") != NULL)
debug = debug | GEDIT_DEBUG_PLUGINS;
- if (g_getenv ("GEDIT_DEBUG_TAB") != NULL)
- debug = debug | GEDIT_DEBUG_TAB;
+ if (g_getenv ("GEDIT_DEBUG_VIEW_CONTAINER") != NULL)
+ debug = debug | GEDIT_DEBUG_VIEW_CONTAINER;
if (g_getenv ("GEDIT_DEBUG_DOCUMENT") != NULL)
debug = debug | GEDIT_DEBUG_DOCUMENT;
if (g_getenv ("GEDIT_DEBUG_COMMANDS") != NULL)
diff --git a/gedit/gedit-debug.h b/gedit/gedit-debug.h
index af7d737..93cd07b 100644
--- a/gedit/gedit-debug.h
+++ b/gedit/gedit-debug.h
@@ -47,7 +47,7 @@ typedef enum {
GEDIT_DEBUG_PRINT = 1 << 2,
GEDIT_DEBUG_PREFS = 1 << 3,
GEDIT_DEBUG_PLUGINS = 1 << 4,
- GEDIT_DEBUG_TAB = 1 << 5,
+ GEDIT_DEBUG_VIEW_CONTAINER = 1 << 5,
GEDIT_DEBUG_DOCUMENT = 1 << 6,
GEDIT_DEBUG_COMMANDS = 1 << 7,
GEDIT_DEBUG_APP = 1 << 8,
@@ -65,7 +65,7 @@ typedef enum {
#define DEBUG_PRINT GEDIT_DEBUG_PRINT, __FILE__, __LINE__, G_STRFUNC
#define DEBUG_PREFS GEDIT_DEBUG_PREFS, __FILE__, __LINE__, G_STRFUNC
#define DEBUG_PLUGINS GEDIT_DEBUG_PLUGINS, __FILE__, __LINE__, G_STRFUNC
-#define DEBUG_TAB GEDIT_DEBUG_TAB, __FILE__, __LINE__, G_STRFUNC
+#define DEBUG_VIEW_CONTAINER GEDIT_DEBUG_VIEW_CONTAINER, __FILE__, __LINE__, G_STRFUNC
#define DEBUG_DOCUMENT GEDIT_DEBUG_DOCUMENT,__FILE__, __LINE__, G_STRFUNC
#define DEBUG_COMMANDS GEDIT_DEBUG_COMMANDS,__FILE__, __LINE__, G_STRFUNC
#define DEBUG_APP GEDIT_DEBUG_APP, __FILE__, __LINE__, G_STRFUNC
diff --git a/gedit/gedit-document-interface.c b/gedit/gedit-document-interface.c
new file mode 100644
index 0000000..db487d9
--- /dev/null
+++ b/gedit/gedit-document-interface.c
@@ -0,0 +1,734 @@
+/*
+ * gedit-document-interface.c
+ * This file is part of gedit
+ *
+ * Copyright (C) 2009 - Ignacio Casal Quinteiro
+ *
+ * gedit 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.
+ *
+ * gedit 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 gedit; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+
+#include "gedit-document-interface.h"
+#include "gedit-marshal.h"
+#include "gedit-enum-types.h"
+#include "gedit-utils.h"
+
+enum {
+ MODIFIED_CHANGED,
+ LOAD,
+ LOADING,
+ LOADED,
+ SAVE,
+ SAVING,
+ SAVED,
+ LAST_SIGNAL
+};
+
+static guint document_signals[LAST_SIGNAL] = { 0 };
+
+/* Default implementation */
+
+static GFile *
+gedit_document_get_location_default (GeditDocument *doc)
+{
+ g_return_val_if_reached (NULL);
+}
+
+static gchar *
+gedit_document_get_uri_default (GeditDocument *doc)
+{
+ g_return_val_if_reached (NULL);
+}
+
+static void
+gedit_document_set_uri_default (GeditDocument *doc,
+ const gchar *uri)
+{
+ g_return_if_reached ();
+}
+
+static gchar *
+gedit_document_get_uri_for_display_default (GeditDocument *doc)
+{
+ g_return_val_if_reached (NULL);
+}
+
+static gchar *
+gedit_document_get_short_name_for_display_default (GeditDocument *doc)
+{
+ g_return_val_if_reached (NULL);
+}
+
+static gchar *
+gedit_document_get_content_type_default (GeditDocument *doc)
+{
+ g_return_val_if_reached (NULL);
+}
+
+static gchar *
+gedit_document_get_mime_type_default (GeditDocument *doc)
+{
+ g_return_val_if_reached (NULL);
+}
+
+static gboolean
+gedit_document_get_readonly_default (GeditDocument *doc)
+{
+ g_return_val_if_reached (FALSE);
+}
+
+static gboolean
+gedit_document_load_cancel_default (GeditDocument *doc)
+{
+ g_return_val_if_reached (FALSE);
+}
+
+static gboolean
+gedit_document_is_untouched_default (GeditDocument *doc)
+{
+ g_return_val_if_reached (FALSE);
+}
+
+static gboolean
+gedit_document_is_untitled_default (GeditDocument *doc)
+{
+ g_return_val_if_reached (FALSE);
+}
+
+static gboolean
+gedit_document_is_local_default (GeditDocument *doc)
+{
+ g_return_val_if_reached (FALSE);
+}
+
+static gboolean
+gedit_document_get_deleted_default (GeditDocument *doc)
+{
+ g_return_val_if_reached (FALSE);
+}
+
+static gboolean
+gedit_document_goto_line_default (GeditDocument *doc,
+ gint line)
+{
+ g_return_val_if_reached (FALSE);
+}
+
+static gboolean
+gedit_document_goto_line_offset_default (GeditDocument *doc,
+ gint line,
+ gint line_offset)
+{
+ g_return_val_if_reached (FALSE);
+}
+
+static const GeditEncoding *
+gedit_document_get_encoding_default (GeditDocument *doc)
+{
+ g_return_val_if_reached (NULL);
+}
+
+static glong
+gedit_document_get_seconds_since_last_save_or_load_default (GeditDocument *doc)
+{
+ g_return_val_if_reached (0);
+}
+
+static gboolean
+gedit_document_check_externally_modified_default (GeditDocument *doc)
+{
+ g_return_val_if_reached (FALSE);
+}
+
+static void
+gedit_document_undo_default (GeditDocument *doc)
+{
+ g_return_if_reached ();
+}
+
+static void
+gedit_document_redo_default (GeditDocument *doc)
+{
+ g_return_if_reached ();
+}
+
+static gboolean
+gedit_document_can_undo_default (GeditDocument *doc)
+{
+ g_return_val_if_reached (FALSE);
+}
+
+static gboolean
+gedit_document_can_redo_default (GeditDocument *doc)
+{
+ g_return_val_if_reached (FALSE);
+}
+
+static void
+gedit_document_begin_not_undoable_action_default (GeditDocument *doc)
+{
+ g_return_if_reached ();
+}
+
+static void
+gedit_document_end_not_undoable_action_default (GeditDocument *doc)
+{
+ g_return_if_reached ();
+}
+
+static void
+gedit_document_set_text_default (GeditDocument *doc,
+ const gchar *text,
+ gint len)
+{
+ g_return_if_reached ();
+}
+
+static void
+gedit_document_set_modified_default (GeditDocument *doc,
+ gboolean setting)
+{
+ g_return_if_reached ();
+}
+
+static gboolean
+gedit_document_get_modified_default (GeditDocument *doc)
+{
+ g_return_val_if_reached (FALSE);
+}
+
+static gboolean
+gedit_document_get_has_selection_default (GeditDocument *doc)
+{
+ g_return_val_if_reached (FALSE);
+}
+
+static void
+gedit_document_init (GeditDocumentIface *iface)
+{
+ static gboolean initialized = FALSE;
+
+ iface->get_location = gedit_document_get_location_default;
+ iface->get_uri = gedit_document_get_uri_default;
+ iface->set_uri = gedit_document_set_uri_default;
+ iface->get_uri_for_display = gedit_document_get_uri_for_display_default;
+ iface->get_short_name_for_display = gedit_document_get_short_name_for_display_default;
+ iface->get_content_type = gedit_document_get_content_type_default;
+ iface->get_mime_type = gedit_document_get_mime_type_default;
+ iface->get_readonly = gedit_document_get_readonly_default;
+ iface->load_cancel = gedit_document_load_cancel_default;
+ iface->is_untouched = gedit_document_is_untouched_default;
+ iface->is_untitled = gedit_document_is_untitled_default;
+ iface->is_local = gedit_document_is_local_default;
+ iface->get_deleted = gedit_document_get_deleted_default;
+ iface->goto_line = gedit_document_goto_line_default;
+ iface->goto_line_offset = gedit_document_goto_line_offset_default;
+ iface->get_encoding = gedit_document_get_encoding_default;
+ iface->get_seconds_since_last_save_or_load = gedit_document_get_seconds_since_last_save_or_load_default;
+ iface->check_externally_modified = gedit_document_check_externally_modified_default;
+ iface->undo = gedit_document_undo_default;
+ iface->redo = gedit_document_redo_default;
+ iface->can_undo = gedit_document_can_undo_default;
+ iface->can_redo = gedit_document_can_redo_default;
+ iface->begin_not_undoable_action = gedit_document_begin_not_undoable_action_default;
+ iface->end_not_undoable_action = gedit_document_end_not_undoable_action_default;
+ iface->set_text = gedit_document_set_text_default;
+ iface->set_modified = gedit_document_set_modified_default;
+ iface->get_modified = gedit_document_get_modified_default;
+ iface->get_has_selection = gedit_document_get_has_selection_default;
+
+ if (!initialized)
+ {
+ g_object_interface_install_property (iface,
+ g_param_spec_string ("uri",
+ "URI",
+ "The document's URI",
+ NULL,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_interface_install_property (iface,
+ g_param_spec_string ("shortname",
+ "Short Name",
+ "The document's short name",
+ NULL,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_interface_install_property (iface,
+ g_param_spec_string ("content-type",
+ "Content Type",
+ "The document's Content Type",
+ NULL,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_interface_install_property (iface,
+ g_param_spec_boolean ("read-only",
+ "Read Only",
+ "Whether the document is read only or not",
+ FALSE,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+
+ document_signals[MODIFIED_CHANGED] =
+ g_signal_new ("modified-changed",
+ G_TYPE_FROM_INTERFACE (iface),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GeditDocumentIface, modified_changed),
+ NULL, NULL,
+ gedit_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0);
+
+ /**
+ * GeditDocument::load:
+ * @document: the #GeditDocument.
+ * @uri: the uri where to load the document from.
+ * @encoding: the #GeditEncoding to encode the document.
+ * @line_pos: the line to show.
+ * @create: whether the document should be created if it doesn't exist.
+ *
+ * The "load" signal is emitted when a document is loaded.
+ */
+ document_signals[LOAD] =
+ g_signal_new ("load",
+ G_TYPE_FROM_INTERFACE (iface),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GeditDocumentIface, load),
+ NULL, NULL,
+ gedit_marshal_VOID__STRING_BOXED_INT_BOOLEAN,
+ G_TYPE_NONE,
+ 4,
+ G_TYPE_STRING,
+ /* we rely on the fact that the GeditEncoding pointer stays
+ * the same forever */
+ GEDIT_TYPE_ENCODING | G_SIGNAL_TYPE_STATIC_SCOPE,
+ G_TYPE_INT,
+ G_TYPE_BOOLEAN);
+
+
+ document_signals[LOADING] =
+ g_signal_new ("loading",
+ G_TYPE_FROM_INTERFACE (iface),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GeditDocumentIface, loading),
+ NULL, NULL,
+ gedit_marshal_VOID__UINT64_UINT64,
+ G_TYPE_NONE,
+ 2,
+ G_TYPE_UINT64,
+ G_TYPE_UINT64);
+
+ document_signals[LOADED] =
+ g_signal_new ("loaded",
+ G_TYPE_FROM_INTERFACE (iface),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GeditDocumentIface, loaded),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE,
+ 1,
+ G_TYPE_POINTER);
+
+ /**
+ * GeditDocument::save:
+ * @document: the #GeditDocument.
+ * @uri: the uri where the document is about to be saved.
+ * @encoding: the #GeditEncoding used to save the document.
+ * @flags: the #GeditDocumentSaveFlags for the save operation.
+ *
+ * The "save" signal is emitted when the document is saved.
+ */
+ document_signals[SAVE] =
+ g_signal_new ("save",
+ G_TYPE_FROM_INTERFACE (iface),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GeditDocumentIface, save),
+ NULL, NULL,
+ gedit_marshal_VOID__STRING_BOXED_FLAGS,
+ G_TYPE_NONE,
+ 3,
+ G_TYPE_STRING,
+ /* we rely on the fact that the GeditEncoding pointer stays
+ * the same forever */
+ GEDIT_TYPE_ENCODING | G_SIGNAL_TYPE_STATIC_SCOPE,
+ GEDIT_TYPE_DOCUMENT_SAVE_FLAGS);
+
+ document_signals[SAVING] =
+ g_signal_new ("saving",
+ G_TYPE_FROM_INTERFACE (iface),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GeditDocumentIface, saving),
+ NULL, NULL,
+ gedit_marshal_VOID__UINT64_UINT64,
+ G_TYPE_NONE,
+ 2,
+ G_TYPE_UINT64,
+ G_TYPE_UINT64);
+
+ document_signals[SAVED] =
+ g_signal_new ("saved",
+ G_TYPE_FROM_INTERFACE (iface),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GeditDocumentIface, saved),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE,
+ 1,
+ G_TYPE_POINTER);
+
+ initialized = TRUE;
+ }
+}
+
+GType
+gedit_document_get_type ()
+{
+ static GType gedit_document_type_id = 0;
+
+ if (!gedit_document_type_id)
+ {
+ static const GTypeInfo g_define_type_info =
+ {
+ sizeof (GeditDocumentIface),
+ (GBaseInitFunc) gedit_document_init,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ 0,
+ 0,
+ NULL
+ };
+
+ gedit_document_type_id =
+ g_type_register_static (G_TYPE_INTERFACE,
+ "GeditDocument",
+ &g_define_type_info,
+ 0);
+
+ g_type_interface_add_prerequisite (gedit_document_type_id,
+ G_TYPE_OBJECT);
+ }
+
+ return gedit_document_type_id;
+}
+
+
+GQuark
+gedit_document_error_quark (void)
+{
+ static GQuark quark = 0;
+
+ if (G_UNLIKELY (quark == 0))
+ quark = g_quark_from_static_string ("gedit_io_load_error");
+
+ return quark;
+}
+
+GFile *
+gedit_document_get_location (GeditDocument *doc)
+{
+ g_return_val_if_fail (GEDIT_DOCUMENT (doc), NULL);
+ return GEDIT_DOCUMENT_GET_INTERFACE (doc)->get_location (doc);
+}
+
+gchar *
+gedit_document_get_uri (GeditDocument *doc)
+{
+ g_return_val_if_fail (GEDIT_DOCUMENT (doc), NULL);
+ return GEDIT_DOCUMENT_GET_INTERFACE (doc)->get_uri (doc);
+}
+
+void
+gedit_document_set_uri (GeditDocument *doc,
+ const gchar *uri)
+{
+ g_return_if_fail (GEDIT_DOCUMENT (doc));
+ GEDIT_DOCUMENT_GET_INTERFACE (doc)->set_uri (doc, uri);
+}
+
+gchar *
+gedit_document_get_uri_for_display (GeditDocument *doc)
+{
+ g_return_val_if_fail (GEDIT_DOCUMENT (doc), g_strdup (""));
+ return GEDIT_DOCUMENT_GET_INTERFACE (doc)->get_uri_for_display (doc);
+}
+
+gchar *
+gedit_document_get_short_name_for_display (GeditDocument *doc)
+{
+ g_return_val_if_fail (GEDIT_DOCUMENT (doc), g_strdup (""));
+ return GEDIT_DOCUMENT_GET_INTERFACE (doc)->get_short_name_for_display (doc);
+}
+
+/* FIXME: Only gedit-text-buffer? */
+gchar *
+gedit_document_get_content_type (GeditDocument *doc)
+{
+ g_return_val_if_fail (GEDIT_DOCUMENT (doc), NULL);
+ return GEDIT_DOCUMENT_GET_INTERFACE (doc)->get_content_type (doc);
+}
+
+/* FIXME: Only gedit-text-buffer? */
+gchar *
+gedit_document_get_mime_type (GeditDocument *doc)
+{
+ g_return_val_if_fail (GEDIT_DOCUMENT (doc), g_strdup ("text/plain"));
+ return GEDIT_DOCUMENT_GET_INTERFACE (doc)->get_mime_type (doc);
+}
+
+gboolean
+gedit_document_get_readonly (GeditDocument *doc)
+{
+ g_return_val_if_fail (GEDIT_DOCUMENT (doc), FALSE);
+ return GEDIT_DOCUMENT_GET_INTERFACE (doc)->get_readonly (doc);
+}
+
+/**
+ * gedit_document_load_document:
+ * @doc: the #GeditDocument.
+ * @uri: the uri where to load the document from.
+ * @encoding: the #GeditEncoding to encode the document.
+ * @line_pos: the line to show.
+ * @create: whether the document should be created if it doesn't exist.
+ *
+ * Load a document. This results in the "load" signal to be emitted.
+ */
+void
+gedit_document_load (GeditDocument *doc,
+ const gchar *uri,
+ const GeditEncoding *encoding,
+ gint line_pos,
+ gboolean create)
+{
+ g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
+ g_return_if_fail (uri != NULL);
+ g_return_if_fail (gedit_utils_is_valid_uri (uri));
+
+ g_signal_emit (doc, document_signals[LOAD], 0, uri, encoding, line_pos, create);
+}
+
+/**
+ * gedit_document_load_cancel:
+ * @doc: the #GeditDocument.
+ *
+ * Cancel load of a document.
+ */
+gboolean
+gedit_document_load_cancel (GeditDocument *doc)
+{
+ g_return_val_if_fail (GEDIT_DOCUMENT (doc), FALSE);
+ return GEDIT_DOCUMENT_GET_INTERFACE (doc)->load_cancel (doc);
+}
+
+/**
+ * gedit_document_save:
+ * @doc: the #GeditDocument.
+ * @flags: optionnal #GeditDocumentSaveFlags.
+ *
+ * Save the document to its previous location. This results in the "save"
+ * signal to be emitted.
+ */
+void
+gedit_document_save (GeditDocument *doc,
+ GeditDocumentSaveFlags flags)
+{
+ g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
+ g_return_if_fail (gedit_document_get_uri (doc) != NULL);
+
+ g_signal_emit (doc,
+ document_signals[SAVE],
+ 0,
+ gedit_document_get_uri (doc),
+ gedit_document_get_encoding (doc),
+ flags);
+}
+
+/**
+ * gedit_document_save_as:
+ * @doc: the #GeditDocument.
+ * @uri: the uri where to save the document.
+ * @encoding: the #GeditEncoding to encode the document.
+ * @flags: optionnal #GeditDocumentSaveFlags.
+ *
+ * Save the document to a new location. This results in the "save" signal
+ * to be emitted.
+ */
+void
+gedit_document_save_as (GeditDocument *doc,
+ const gchar *uri,
+ const GeditEncoding *encoding,
+ GeditDocumentSaveFlags flags)
+{
+ g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
+ g_return_if_fail (uri != NULL);
+ g_return_if_fail (encoding != NULL);
+
+ /* priv->mtime refers to the the old uri (if any). Thus, it should be
+ * ignored when saving as. */
+ g_signal_emit (doc,
+ document_signals[SAVE],
+ 0,
+ uri,
+ encoding,
+ flags | GEDIT_DOCUMENT_SAVE_IGNORE_MTIME);
+}
+
+gboolean
+gedit_document_is_untouched (GeditDocument *doc)
+{
+ g_return_val_if_fail (GEDIT_DOCUMENT (doc), FALSE);
+ return GEDIT_DOCUMENT_GET_INTERFACE (doc)->is_untouched (doc);
+}
+
+gboolean
+gedit_document_is_untitled (GeditDocument *doc)
+{
+ g_return_val_if_fail (GEDIT_DOCUMENT (doc), FALSE);
+ return GEDIT_DOCUMENT_GET_INTERFACE (doc)->is_untitled (doc);
+}
+
+gboolean
+gedit_document_is_local (GeditDocument *doc)
+{
+ g_return_val_if_fail (GEDIT_DOCUMENT (doc), FALSE);
+ return GEDIT_DOCUMENT_GET_INTERFACE (doc)->is_local (doc);
+}
+
+gboolean
+gedit_document_get_deleted (GeditDocument *doc)
+{
+ g_return_val_if_fail (GEDIT_DOCUMENT (doc), FALSE);
+ return GEDIT_DOCUMENT_GET_INTERFACE (doc)->get_deleted (doc);
+}
+
+gboolean
+gedit_document_goto_line (GeditDocument *doc,
+ gint line)
+{
+ g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
+ g_return_val_if_fail (line >= -1, FALSE);
+ return GEDIT_DOCUMENT_GET_INTERFACE (doc)->goto_line (doc, line);
+}
+
+gboolean
+gedit_document_goto_line_offset (GeditDocument *doc,
+ gint line,
+ gint line_offset)
+{
+ g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
+ g_return_val_if_fail (line >= -1, FALSE);
+ g_return_val_if_fail (line_offset >= -1, FALSE);
+ return GEDIT_DOCUMENT_GET_INTERFACE (doc)->goto_line_offset (doc, line,
+ line_offset);
+}
+
+const GeditEncoding *
+gedit_document_get_encoding (GeditDocument *doc)
+{
+ g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), NULL);
+ return GEDIT_DOCUMENT_GET_INTERFACE (doc)->get_encoding (doc);
+}
+
+glong
+gedit_document_get_seconds_since_last_save_or_load (GeditDocument *doc)
+{
+ g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), -1);
+ return GEDIT_DOCUMENT_GET_INTERFACE (doc)->get_seconds_since_last_save_or_load (doc);
+}
+
+gboolean
+gedit_document_check_externally_modified (GeditDocument *doc)
+{
+ g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
+ return GEDIT_DOCUMENT_GET_INTERFACE (doc)->check_externally_modified (doc);
+}
+
+void
+gedit_document_undo (GeditDocument *doc)
+{
+ g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
+ GEDIT_DOCUMENT_GET_INTERFACE (doc)->undo (doc);
+}
+
+void
+gedit_document_redo (GeditDocument *doc)
+{
+ g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
+ GEDIT_DOCUMENT_GET_INTERFACE (doc)->redo (doc);
+}
+
+gboolean
+gedit_document_can_undo (GeditDocument *doc)
+{
+ g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
+ return GEDIT_DOCUMENT_GET_INTERFACE (doc)->can_undo (doc);
+}
+
+gboolean
+gedit_document_can_redo (GeditDocument *doc)
+{
+ g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
+ return GEDIT_DOCUMENT_GET_INTERFACE (doc)->can_redo (doc);
+}
+
+void
+gedit_document_begin_not_undoable_action (GeditDocument *doc)
+{
+ g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
+ GEDIT_DOCUMENT_GET_INTERFACE (doc)->begin_not_undoable_action (doc);
+}
+
+void
+gedit_document_end_not_undoable_action (GeditDocument *doc)
+{
+ g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
+ GEDIT_DOCUMENT_GET_INTERFACE (doc)->end_not_undoable_action (doc);
+}
+
+void
+gedit_document_set_text (GeditDocument *doc,
+ const gchar *text,
+ gint len)
+{
+ g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
+ g_return_if_fail (text != NULL);
+ GEDIT_DOCUMENT_GET_INTERFACE (doc)->set_text (doc, text, len);
+}
+
+void
+gedit_document_set_modified (GeditDocument *doc,
+ gboolean setting)
+{
+ g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
+ GEDIT_DOCUMENT_GET_INTERFACE (doc)->set_modified (doc, setting);
+}
+
+gboolean
+gedit_document_get_modified (GeditDocument *doc)
+{
+ g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
+ return GEDIT_DOCUMENT_GET_INTERFACE (doc)->get_modified (doc);
+}
+
+gboolean
+gedit_document_get_has_selection (GeditDocument *doc)
+{
+ g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
+ return GEDIT_DOCUMENT_GET_INTERFACE (doc)->get_has_selection (doc);
+}
diff --git a/gedit/gedit-document-interface.h b/gedit/gedit-document-interface.h
new file mode 100644
index 0000000..a07d139
--- /dev/null
+++ b/gedit/gedit-document-interface.h
@@ -0,0 +1,273 @@
+/*
+ * gedit-document.h
+ * This file is part of gedit
+ *
+ * Copyright (C) 1998, 1999 Alex Roberts, Evan Lawrence
+ * Copyright (C) 2000, 2001 Chema Celorio, Paolo Maggi
+ * Copyright (C) 2002-2005 Paolo Maggi
+ *
+ * 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., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Modified by the gedit Team, 1998-2005. See the AUTHORS file for a
+ * list of people on the gedit Team.
+ * See the ChangeLog files for a list of changes.
+ *
+ * $Id$
+ */
+
+#ifndef __GEDIT_DOCUMENT_H__
+#define __GEDIT_DOCUMENT_H__
+
+#include <glib-object.h>
+#include <gio/gio.h>
+#include <gedit/gedit-encodings.h>
+
+G_BEGIN_DECLS
+
+#define GEDIT_TYPE_DOCUMENT (gedit_document_get_type ())
+#define GEDIT_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_DOCUMENT, GeditDocument))
+#define GEDIT_IS_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEDIT_TYPE_DOCUMENT))
+#define GEDIT_DOCUMENT_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GEDIT_TYPE_DOCUMENT, GeditDocumentIface))
+
+typedef struct _GeditDocument GeditDocument;
+typedef struct _GeditDocumentIface GeditDocumentIface;
+
+typedef enum
+{
+ GEDIT_SEARCH_DONT_SET_FLAGS = 1 << 0,
+ GEDIT_SEARCH_ENTIRE_WORD = 1 << 1,
+ GEDIT_SEARCH_CASE_SENSITIVE = 1 << 2
+
+} GeditSearchFlags;
+
+/**
+ * GeditDocumentSaveFlags:
+ * @GEDIT_DOCUMENT_SAVE_IGNORE_MTIME: save file despite external modifications.
+ * @GEDIT_DOCUMENT_SAVE_IGNORE_BACKUP: write the file directly without attempting to backup.
+ * @GEDIT_DOCUMENT_SAVE_PRESERVE_BACKUP: preserve previous backup file, needed to support autosaving.
+ */
+typedef enum
+{
+ GEDIT_DOCUMENT_SAVE_IGNORE_MTIME = 1 << 0,
+ GEDIT_DOCUMENT_SAVE_IGNORE_BACKUP = 1 << 1,
+ GEDIT_DOCUMENT_SAVE_PRESERVE_BACKUP = 1 << 2
+} GeditDocumentSaveFlags;
+
+struct _GeditDocumentIface
+{
+ GTypeInterface parent;
+
+ /* Signals */
+
+ void (* modified_changed) (GeditDocument *document);
+
+ /* Document load */
+ void (* load) (GeditDocument *document,
+ const gchar *uri,
+ const GeditEncoding *encoding,
+ gint line_pos,
+ gboolean create);
+
+ void (* loading) (GeditDocument *document,
+ goffset size,
+ goffset total_size);
+
+ void (* loaded) (GeditDocument *document,
+ const GError *error);
+
+ /* Document save */
+ void (* save) (GeditDocument *document,
+ const gchar *uri,
+ const GeditEncoding *encoding,
+ GeditDocumentSaveFlags flags);
+
+ void (* saving) (GeditDocument *document,
+ goffset size,
+ goffset total_size);
+
+ void (* saved) (GeditDocument *document,
+ const GError *error);
+
+ /* Virtual table */
+
+ GFile * (* get_location) (GeditDocument *doc);
+
+ gchar * (* get_uri) (GeditDocument *doc);
+
+ void (* set_uri) (GeditDocument *doc,
+ const gchar *uri);
+
+ gchar * (* get_uri_for_display) (GeditDocument *doc);
+
+ gchar * (* get_short_name_for_display)
+ (GeditDocument *doc);
+
+ gchar * (* get_content_type) (GeditDocument *doc);
+
+ gchar * (* get_mime_type) (GeditDocument *doc);
+
+ gboolean (* get_readonly) (GeditDocument *doc);
+
+ gboolean (* load_cancel) (GeditDocument *doc);
+
+ gboolean (* is_untouched) (GeditDocument *doc);
+ gboolean (* is_untitled) (GeditDocument *doc);
+
+ gboolean (* is_local) (GeditDocument *doc);
+
+ gboolean (* get_deleted) (GeditDocument *doc);
+
+ gboolean (* goto_line) (GeditDocument *doc,
+ gint line);
+
+ gboolean (* goto_line_offset) (GeditDocument *doc,
+ gint line,
+ gint line_offset);
+
+ const GeditEncoding * (* get_encoding)
+ (GeditDocument *doc);
+
+ glong (* get_seconds_since_last_save_or_load)
+ (GeditDocument *doc);
+
+ gboolean (* check_externally_modified)
+ (GeditDocument *doc);
+
+ /* GSV releated functions */
+
+ void (* undo) (GeditDocument *doc);
+ void (* redo) (GeditDocument *doc);
+
+ gboolean (* can_undo) (GeditDocument *doc);
+ gboolean (* can_redo) (GeditDocument *doc);
+
+ void (* begin_not_undoable_action) (GeditDocument *doc);
+ void (* end_not_undoable_action) (GeditDocument *doc);
+
+ /* GtkTextBuffer releated functions */
+
+ void (* set_text) (GeditDocument *doc,
+ const gchar *text,
+ gint len);
+
+ void (* set_modified) (GeditDocument *doc,
+ gboolean setting);
+
+ gboolean (* get_modified) (GeditDocument *doc);
+
+ gboolean (* get_has_selection) (GeditDocument *doc);
+};
+
+#define GEDIT_DOCUMENT_ERROR gedit_document_error_quark ()
+
+enum
+{
+ GEDIT_DOCUMENT_ERROR_EXTERNALLY_MODIFIED,
+ GEDIT_DOCUMENT_ERROR_CANT_CREATE_BACKUP,
+ GEDIT_DOCUMENT_ERROR_TOO_BIG,
+ GEDIT_DOCUMENT_NUM_ERRORS
+};
+
+GQuark gedit_document_error_quark (void);
+
+GType gedit_document_get_type (void) G_GNUC_CONST;
+
+GFile *gedit_document_get_location (GeditDocument *doc);
+
+gchar *gedit_document_get_uri (GeditDocument *doc);
+void gedit_document_set_uri (GeditDocument *doc,
+ const gchar *uri);
+
+gchar *gedit_document_get_uri_for_display
+ (GeditDocument *doc);
+gchar *gedit_document_get_short_name_for_display
+ (GeditDocument *doc);
+
+gchar *gedit_document_get_content_type
+ (GeditDocument *doc);
+
+gchar *gedit_document_get_mime_type (GeditDocument *doc);
+
+gboolean gedit_document_get_readonly (GeditDocument *doc);
+
+void gedit_document_load (GeditDocument *doc,
+ const gchar *uri,
+ const GeditEncoding *encoding,
+ gint line_pos,
+ gboolean create);
+
+gboolean gedit_document_load_cancel (GeditDocument *doc);
+
+void gedit_document_save (GeditDocument *doc,
+ GeditDocumentSaveFlags flags);
+
+void gedit_document_save_as (GeditDocument *doc,
+ const gchar *uri,
+ const GeditEncoding *encoding,
+ GeditDocumentSaveFlags flags);
+
+gboolean gedit_document_is_untouched (GeditDocument *doc);
+gboolean gedit_document_is_untitled (GeditDocument *doc);
+
+gboolean gedit_document_is_local (GeditDocument *doc);
+
+gboolean gedit_document_get_deleted (GeditDocument *doc);
+
+gboolean gedit_document_goto_line (GeditDocument *doc,
+ gint line);
+
+gboolean gedit_document_goto_line_offset(GeditDocument *doc,
+ gint line,
+ gint line_offset);
+
+const GeditEncoding
+ *gedit_document_get_encoding (GeditDocument *doc);
+
+glong gedit_document_get_seconds_since_last_save_or_load
+ (GeditDocument *doc);
+
+/* Note: this is a sync stat: use only on local files */
+gboolean gedit_document_check_externally_modified
+ (GeditDocument *doc);
+
+
+void gedit_document_undo (GeditDocument *doc);
+void gedit_document_redo (GeditDocument *doc);
+
+gboolean gedit_document_can_undo (GeditDocument *doc);
+gboolean gedit_document_can_redo (GeditDocument *doc);
+
+void gedit_document_begin_not_undoable_action
+ (GeditDocument *doc);
+void gedit_document_end_not_undoable_action
+ (GeditDocument *doc);
+
+void gedit_document_set_text (GeditDocument *doc,
+ const gchar *text,
+ gint len);
+
+void gedit_document_set_modified (GeditDocument *doc,
+ gboolean setting);
+
+gboolean gedit_document_get_modified (GeditDocument *doc);
+
+gboolean gedit_document_get_has_selection(GeditDocument *doc);
+
+G_END_DECLS
+
+#endif /* __GEDIT_DOCUMENT_H__ */
diff --git a/gedit/gedit-document-loader.c b/gedit/gedit-document-loader.c
index f528eb0..eab7db2 100644
--- a/gedit/gedit-document-loader.c
+++ b/gedit/gedit-document-loader.c
@@ -195,7 +195,7 @@ insert_text_in_document (GeditDocumentLoader *loader,
g_return_if_fail (text != NULL);
- gtk_source_buffer_begin_not_undoable_action (GTK_SOURCE_BUFFER (doc));
+ gedit_document_begin_not_undoable_action (doc);
/* If the last char is a newline, don't add it to the buffer (otherwise
GtkTextView shows it as an empty line). See bug #324942. */
@@ -203,11 +203,11 @@ insert_text_in_document (GeditDocumentLoader *loader,
len--;
/* Insert text in the buffer */
- gtk_text_buffer_set_text (GTK_TEXT_BUFFER (doc), text, len);
+ gedit_document_set_text (doc, text, len);
- gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (doc), FALSE);
+ gedit_document_set_modified (doc, FALSE);
- gtk_source_buffer_end_not_undoable_action (GTK_SOURCE_BUFFER (doc));
+ gedit_document_end_not_undoable_action (doc);
}
/* This function is only meant to be called by child classes */
diff --git a/gedit/gedit-document-loader.h b/gedit/gedit-document-loader.h
index 97f6a3d..d5bed70 100644
--- a/gedit/gedit-document-loader.h
+++ b/gedit/gedit-document-loader.h
@@ -32,7 +32,7 @@
#ifndef __GEDIT_DOCUMENT_LOADER_H__
#define __GEDIT_DOCUMENT_LOADER_H__
-#include <gedit/gedit-document.h>
+#include <gedit/gedit-document-interface.h>
G_BEGIN_DECLS
diff --git a/gedit/gedit-document-saver.h b/gedit/gedit-document-saver.h
index 2095ec3..b3bc9a7 100644
--- a/gedit/gedit-document-saver.h
+++ b/gedit/gedit-document-saver.h
@@ -32,7 +32,7 @@
#ifndef __GEDIT_DOCUMENT_SAVER_H__
#define __GEDIT_DOCUMENT_SAVER_H__
-#include <gedit/gedit-document.h>
+#include <gedit/gedit-document-interface.h>
G_BEGIN_DECLS
diff --git a/gedit/gedit-documents-panel.c b/gedit/gedit-documents-panel.c
index 543bf83..414c2ce 100644
--- a/gedit/gedit-documents-panel.c
+++ b/gedit/gedit-documents-panel.c
@@ -49,7 +49,7 @@ struct _GeditDocumentsPanelPrivate
GtkWidget *treeview;
GtkTreeModel *model;
- gboolean adding_tab;
+ gboolean adding_page;
gboolean is_reodering;
};
@@ -64,58 +64,62 @@ enum
#define MAX_DOC_NAME_LENGTH 60
static gchar *
-tab_get_name (GeditTab *tab)
+page_get_name (GeditPage *page)
{
+ GeditViewContainer *container;
GeditDocument *doc;
gchar *name;
gchar *docname;
- gchar *tab_name;
+ gchar *page_name;
- g_return_val_if_fail (GEDIT_IS_TAB (tab), NULL);
+ g_return_val_if_fail (GEDIT_IS_PAGE (page), NULL);
- doc = gedit_tab_get_document (tab);
+ container = gedit_page_get_active_view_container (page);
+
+ /* FIXME: check container == NULL? */
+ doc = gedit_view_container_get_document (container);
name = gedit_document_get_short_name_for_display (doc);
/* Truncate the name so it doesn't get insanely wide. */
docname = gedit_utils_str_middle_truncate (name, MAX_DOC_NAME_LENGTH);
- if (gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (doc)))
+ if (gedit_document_get_modified (doc))
{
if (gedit_document_get_readonly (doc))
{
- tab_name = g_markup_printf_escaped ("<i>%s</i> [<i>%s</i>]",
- docname,
- _("Read Only"));
+ page_name = g_markup_printf_escaped ("<i>%s</i> [<i>%s</i>]",
+ docname,
+ _("Read Only"));
}
else
{
- tab_name = g_markup_printf_escaped ("<i>%s</i>",
- docname);
+ page_name = g_markup_printf_escaped ("<i>%s</i>",
+ docname);
}
}
else
{
if (gedit_document_get_readonly (doc))
{
- tab_name = g_markup_printf_escaped ("%s [<i>%s</i>]",
- docname,
- _("Read Only"));
+ page_name = g_markup_printf_escaped ("%s [<i>%s</i>]",
+ docname,
+ _("Read Only"));
}
else
{
- tab_name = g_markup_escape_text (docname, -1);
+ page_name = g_markup_escape_text (docname, -1);
}
}
g_free (docname);
g_free (name);
- return tab_name;
+ return page_name;
}
static void
-get_iter_from_tab (GeditDocumentsPanel *panel, GeditTab *tab, GtkTreeIter *iter)
+get_iter_from_page (GeditDocumentsPanel *panel, GeditPage *page, GtkTreeIter *iter)
{
gint num;
GtkWidget *nb;
@@ -123,7 +127,7 @@ get_iter_from_tab (GeditDocumentsPanel *panel, GeditTab *tab, GtkTreeIter *iter)
nb = _gedit_window_get_notebook (panel->priv->window);
num = gtk_notebook_page_num (GTK_NOTEBOOK (nb),
- GTK_WIDGET (tab));
+ GTK_WIDGET (page));
path = gtk_tree_path_new_from_indices (num, -1);
gtk_tree_model_get_iter (panel->priv->model,
@@ -133,22 +137,22 @@ get_iter_from_tab (GeditDocumentsPanel *panel, GeditTab *tab, GtkTreeIter *iter)
}
static void
-window_active_tab_changed (GeditWindow *window,
- GeditTab *tab,
- GeditDocumentsPanel *panel)
+window_active_page_changed (GeditWindow *window,
+ GeditPage *page,
+ GeditDocumentsPanel *panel)
{
- g_return_if_fail (tab != NULL);
+ g_return_if_fail (page != NULL);
- if (!_gedit_window_is_removing_tabs (window))
+ if (!_gedit_window_is_removing_pages (window))
{
GtkTreeIter iter;
GtkTreeSelection *selection;
- get_iter_from_tab (panel, tab, &iter);
+ get_iter_from_page (panel, page, &iter);
if (gtk_list_store_iter_is_valid (GTK_LIST_STORE (panel->priv->model),
&iter))
- {
+ {
selection = gtk_tree_view_get_selection (
GTK_TREE_VIEW (panel->priv->treeview));
@@ -162,11 +166,11 @@ refresh_list (GeditDocumentsPanel *panel)
{
/* TODO: refresh the list only if the panel is visible */
- GList *tabs;
+ GList *pages;
GList *l;
GtkWidget *nb;
GtkListStore *list_store;
- GeditTab *active_tab;
+ GeditPage *active_page;
/* g_debug ("refresh_list"); */
@@ -174,23 +178,26 @@ refresh_list (GeditDocumentsPanel *panel)
gtk_list_store_clear (list_store);
- active_tab = gedit_window_get_active_tab (panel->priv->window);
+ active_page = gedit_window_get_active_page (panel->priv->window);
nb = _gedit_window_get_notebook (panel->priv->window);
- tabs = gtk_container_get_children (GTK_CONTAINER (nb));
- l = tabs;
+ pages = gtk_container_get_children (GTK_CONTAINER (nb));
+ l = pages;
- panel->priv->adding_tab = TRUE;
+ panel->priv->adding_page = TRUE;
while (l != NULL)
{
GdkPixbuf *pixbuf;
gchar *name;
GtkTreeIter iter;
+ GeditViewContainer *container;
+
+ container = gedit_page_get_active_view_container (GEDIT_PAGE (l->data));
- name = tab_get_name (GEDIT_TAB (l->data));
- pixbuf = _gedit_tab_get_icon (GEDIT_TAB (l->data));
+ name = page_get_name (GEDIT_PAGE (l->data));
+ pixbuf = _gedit_view_container_get_icon (container);
/* Add a new row to the model */
gtk_list_store_append (list_store, &iter);
@@ -205,7 +212,7 @@ refresh_list (GeditDocumentsPanel *panel)
if (pixbuf != NULL)
g_object_unref (pixbuf);
- if (l->data == active_tab)
+ if (l->data == active_page)
{
GtkTreeSelection *selection;
@@ -218,31 +225,31 @@ refresh_list (GeditDocumentsPanel *panel)
l = g_list_next (l);
}
- panel->priv->adding_tab = FALSE;
+ panel->priv->adding_page = FALSE;
- g_list_free (tabs);
+ g_list_free (pages);
}
static void
-sync_name_and_icon (GeditTab *tab,
- GParamSpec *pspec,
+sync_name_and_icon (GeditPage *page,
+ GeditViewContainer *container,
GeditDocumentsPanel *panel)
{
GdkPixbuf *pixbuf;
gchar *name;
GtkTreeIter iter;
- get_iter_from_tab (panel, tab, &iter);
+ get_iter_from_page (panel, page, &iter);
- name = tab_get_name (tab);
- pixbuf = _gedit_tab_get_icon (tab);
+ name = page_get_name (page);
+ pixbuf = _gedit_view_container_get_icon (container);
- gtk_list_store_set (GTK_LIST_STORE (panel->priv->model),
+ gtk_list_store_set (GTK_LIST_STORE (panel->priv->model),
&iter,
- 0, pixbuf,
- 1, name,
- 2, tab,
- -1);
+ 0, pixbuf,
+ 1, name,
+ 2, page,
+ -1);
g_free (name);
if (pixbuf != NULL)
@@ -250,43 +257,69 @@ sync_name_and_icon (GeditTab *tab,
}
static void
-window_tab_removed (GeditWindow *window,
- GeditTab *tab,
- GeditDocumentsPanel *panel)
+on_notify_name_changed (GeditViewContainer *container,
+ GParamSpec *pspec,
+ GeditDocumentsPanel *panel)
{
- g_signal_handlers_disconnect_by_func (tab,
- G_CALLBACK (sync_name_and_icon),
- panel);
+ GeditPage *page;
- if (_gedit_window_is_removing_tabs (window))
+ page = gedit_page_get_from_container (container);
+
+ sync_name_and_icon (page, container, panel);
+}
+
+static void
+window_page_removed (GeditWindow *window,
+ GeditPage *page,
+ GeditDocumentsPanel *panel)
+{
+ g_signal_handlers_disconnect_by_func (page,
+ G_CALLBACK (sync_name_and_icon),
+ panel);
+
+ if (_gedit_window_is_removing_pages (window))
gtk_list_store_clear (GTK_LIST_STORE (panel->priv->model));
else
refresh_list (panel);
}
static void
-window_tab_added (GeditWindow *window,
- GeditTab *tab,
- GeditDocumentsPanel *panel)
+window_page_added (GeditWindow *window,
+ GeditPage *page,
+ GeditDocumentsPanel *panel)
{
GtkTreeIter iter;
GtkTreeIter sibling;
GdkPixbuf *pixbuf;
gchar *name;
+ GList *containers, *l;
+ GeditViewContainer *container;
+
+ /* FIXME: split-added instead ? */
+
+ containers = gedit_page_get_view_containers (page);
- g_signal_connect (tab,
- "notify::name",
- G_CALLBACK (sync_name_and_icon),
- panel);
-
- g_signal_connect (tab,
- "notify::state",
+ for (l = containers; l != NULL; l = g_list_next (l))
+ {
+ g_signal_connect (l->data,
+ "notify::name",
+ G_CALLBACK (on_notify_name_changed),
+ panel);
+
+ g_signal_connect (l->data,
+ "notify::state",
+ G_CALLBACK (on_notify_name_changed),
+ panel);
+ }
+
+ g_signal_connect (page,
+ "active-container-changed",
G_CALLBACK (sync_name_and_icon),
panel);
- get_iter_from_tab (panel, tab, &sibling);
+ get_iter_from_page (panel, page, &sibling);
- panel->priv->adding_tab = TRUE;
+ panel->priv->adding_page = TRUE;
if (gtk_list_store_iter_is_valid (GTK_LIST_STORE (panel->priv->model),
&sibling))
@@ -297,14 +330,14 @@ window_tab_added (GeditWindow *window,
}
else
{
- GeditTab *active_tab;
+ GeditPage *active_page;
gtk_list_store_append (GTK_LIST_STORE (panel->priv->model),
&iter);
- active_tab = gedit_window_get_active_tab (panel->priv->window);
+ active_page = gedit_window_get_active_page (panel->priv->window);
- if (tab == active_tab)
+ if (page == active_page)
{
GtkTreeSelection *selection;
@@ -315,30 +348,32 @@ window_tab_added (GeditWindow *window,
}
}
- name = tab_get_name (tab);
- pixbuf = _gedit_tab_get_icon (tab);
+ container = gedit_page_get_active_view_container (page);
- gtk_list_store_set (GTK_LIST_STORE (panel->priv->model),
+ name = page_get_name (page);
+ pixbuf = _gedit_view_container_get_icon (container);
+
+ gtk_list_store_set (GTK_LIST_STORE (panel->priv->model),
&iter,
- 0, pixbuf,
- 1, name,
- 2, tab,
- -1);
+ 0, pixbuf,
+ 1, name,
+ 2, page,
+ -1);
g_free (name);
if (pixbuf != NULL)
g_object_unref (pixbuf);
- panel->priv->adding_tab = FALSE;
-}
-
+ panel->priv->adding_page = FALSE;
+}
+
static void
-window_tabs_reordered (GeditWindow *window,
- GeditDocumentsPanel *panel)
+window_pages_reordered (GeditWindow *window,
+ GeditDocumentsPanel *panel)
{
if (panel->priv->is_reodering)
return;
-
+
refresh_list (panel);
}
@@ -352,21 +387,21 @@ set_window (GeditDocumentsPanel *panel,
panel->priv->window = g_object_ref (window);
g_signal_connect (window,
- "tab_added",
- G_CALLBACK (window_tab_added),
+ "page_added",
+ G_CALLBACK (window_page_added),
panel);
g_signal_connect (window,
- "tab_removed",
- G_CALLBACK (window_tab_removed),
+ "page_removed",
+ G_CALLBACK (window_page_removed),
panel);
g_signal_connect (window,
- "tabs_reordered",
- G_CALLBACK (window_tabs_reordered),
+ "pages_reordered",
+ G_CALLBACK (window_pages_reordered),
panel);
g_signal_connect (window,
- "active_tab_changed",
- G_CALLBACK (window_active_tab_changed),
- panel);
+ "active_page_changed",
+ G_CALLBACK (window_active_page_changed),
+ panel);
}
static void
@@ -375,32 +410,32 @@ treeview_cursor_changed (GtkTreeView *view,
{
GtkTreeIter iter;
GtkTreeSelection *selection;
- gpointer tab;
+ gpointer page;
selection = gtk_tree_view_get_selection (
GTK_TREE_VIEW (panel->priv->treeview));
if (gtk_tree_selection_get_selected (selection, NULL, &iter))
{
- gtk_tree_model_get (panel->priv->model,
- &iter,
- 2,
- &tab,
+ gtk_tree_model_get (panel->priv->model,
+ &iter,
+ 2,
+ &page,
-1);
- if (gedit_window_get_active_tab (panel->priv->window) != tab)
+ if (gedit_window_get_active_page (panel->priv->window) != page)
{
- gedit_window_set_active_tab (panel->priv->window,
- GEDIT_TAB (tab));
- }
- }
+ gedit_window_set_active_page (panel->priv->window,
+ GEDIT_PAGE (page));
+ }
+ }
}
static void
gedit_documents_panel_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
GeditDocumentsPanel *panel = GEDIT_DOCUMENTS_PANEL (object);
@@ -432,7 +467,7 @@ gedit_documents_panel_get_property (GObject *object,
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
+ break;
}
}
@@ -641,7 +676,8 @@ treeview_query_tooltip (GtkWidget *widget,
GtkTreeView *tree_view = GTK_TREE_VIEW (widget);
GtkTreeModel *model = gtk_tree_view_get_model (tree_view);
GtkTreePath *path = NULL;
- gpointer *tab;
+ gpointer *page;
+ GeditViewContainer *container;
gchar *tip;
if (keyboard_tip)
@@ -674,10 +710,11 @@ treeview_query_tooltip (GtkWidget *widget,
gtk_tree_model_get (model,
&iter,
2,
- &tab,
+ &page,
-1);
- tip = _gedit_tab_get_tooltips (GEDIT_TAB (tab));
+ container = gedit_page_get_active_view_container (GEDIT_PAGE (page));
+ tip = _gedit_view_container_get_tooltips (container);
gtk_tooltip_set_markup (tooltip, tip);
g_free (tip);
@@ -692,17 +729,17 @@ treeview_row_inserted (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GeditDocumentsPanel *panel)
{
- GeditTab *tab;
+ GeditPage *page;
gint *indeces;
GtkWidget *nb;
gint old_position;
gint new_position;
- if (panel->priv->adding_tab)
+ if (panel->priv->adding_page)
return;
- tab = gedit_window_get_active_tab (panel->priv->window);
- g_return_if_fail (tab != NULL);
+ page = gedit_window_get_active_page (panel->priv->window);
+ g_return_if_fail (page != NULL);
panel->priv->is_reodering = TRUE;
@@ -714,15 +751,15 @@ treeview_row_inserted (GtkTreeModel *tree_model,
new_position = indeces[0];
old_position = gtk_notebook_page_num (GTK_NOTEBOOK (nb),
- GTK_WIDGET (tab));
+ GTK_WIDGET (page));
if (new_position > old_position)
new_position = MAX (0, new_position - 1);
- gedit_notebook_reorder_tab (GEDIT_NOTEBOOK (nb),
- tab,
- new_position);
+ gedit_notebook_reorder_page (GEDIT_NOTEBOOK (nb),
+ page,
+ new_position);
- panel->priv->is_reodering = FALSE;
+ panel->priv->is_reodering = FALSE;
}
static void
@@ -735,7 +772,7 @@ gedit_documents_panel_init (GeditDocumentsPanel *panel)
panel->priv = GEDIT_DOCUMENTS_PANEL_GET_PRIVATE (panel);
- panel->priv->adding_tab = FALSE;
+ panel->priv->adding_page = FALSE;
panel->priv->is_reodering = FALSE;
/* Create the scrolled window */
@@ -746,8 +783,8 @@ gedit_documents_panel_init (GeditDocumentsPanel *panel)
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
- GTK_SHADOW_IN);
- gtk_widget_show (sw);
+ GTK_SHADOW_IN);
+ gtk_widget_show (sw);
gtk_box_pack_start (GTK_BOX (panel), sw, TRUE, TRUE, 0);
/* Create the empty model */
diff --git a/gedit/gedit-gio-document-loader.c b/gedit/gedit-gio-document-loader.c
index 1bc65bb..3247a1e 100644
--- a/gedit/gedit-gio-document-loader.c
+++ b/gedit/gedit-gio-document-loader.c
@@ -342,6 +342,7 @@ query_info_cb (GFile *source,
finish_query_info (async);
}
+#if 0
static void
mount_ready_callback (GFile *file,
GAsyncResult *res,
@@ -369,11 +370,12 @@ mount_ready_callback (GFile *file,
open_async_read (async);
}
}
-
+#endif
+/* FIXME */
static void
recover_not_mounted (AsyncData *async)
{
- GeditDocument *doc;
+ /*GeditDocument *doc;
GMountOperation *mount_operation;
gedit_debug (DEBUG_LOADER);
@@ -389,9 +391,10 @@ recover_not_mounted (AsyncData *async)
(GAsyncReadyCallback) mount_ready_callback,
async);
- g_object_unref (mount_operation);
+ g_object_unref (mount_operation);*/
}
+
static void
async_read_ready_callback (GObject *source,
GAsyncResult *res,
diff --git a/gedit/gedit-gio-document-loader.h b/gedit/gedit-gio-document-loader.h
index 78c9e8a..a6b4b56 100644
--- a/gedit/gedit-gio-document-loader.h
+++ b/gedit/gedit-gio-document-loader.h
@@ -33,7 +33,7 @@
#ifndef __GEDIT_GIO_DOCUMENT_LOADER_H__
#define __GEDIT_GIO_DOCUMENT_LOADER_H__
-#include <gedit/gedit-document.h>
+#include <gedit/gedit-document-interface.h>
#include "gedit-document-loader.h"
G_BEGIN_DECLS
diff --git a/gedit/gedit-gio-document-saver.c b/gedit/gedit-gio-document-saver.c
index d57f98c..80f8237 100644
--- a/gedit/gedit-gio-document-saver.c
+++ b/gedit/gedit-gio-document-saver.c
@@ -562,7 +562,7 @@ begin_write (AsyncData *async)
(GAsyncReadyCallback) async_replace_ready_callback,
async);
}
-
+#if 0
static void
mount_ready_callback (GFile *file,
GAsyncResult *res,
@@ -590,11 +590,13 @@ mount_ready_callback (GFile *file,
check_modified_async (async);
}
}
+#endif
+/* FIXME */
static void
recover_not_mounted (AsyncData *async)
{
- GeditDocument *doc;
+ /*GeditDocument *doc;
GMountOperation *mount_operation;
gedit_debug (DEBUG_LOADER);
@@ -608,9 +610,9 @@ recover_not_mounted (AsyncData *async)
mount_operation,
async->cancellable,
(GAsyncReadyCallback) mount_ready_callback,
- async);
+ async);
- g_object_unref (mount_operation);
+ g_object_unref (mount_operation);*/
}
static void
diff --git a/gedit/gedit-io-error-message-area.c b/gedit/gedit-io-error-message-area.c
index 7e76013..641885a 100644
--- a/gedit/gedit-io-error-message-area.c
+++ b/gedit/gedit-io-error-message-area.c
@@ -44,7 +44,7 @@
#include "gedit-utils.h"
#include "gedit-convert.h"
-#include "gedit-document.h"
+#include "gedit-document-interface.h"
#include "gedit-io-error-message-area.h"
#include "gedit-prefs-manager.h"
#include <gedit/gedit-encodings-option-menu.h>
diff --git a/gedit/gedit-notebook.c b/gedit/gedit-notebook.c
index b0fc2fb..ac89f54 100644
--- a/gedit/gedit-notebook.c
+++ b/gedit/gedit-notebook.c
@@ -65,7 +65,7 @@ struct _GeditNotebookPrivate
gint drag_in_progress : 1;
gint always_show_tabs : 1;
gint close_buttons_sensitive : 1;
- gint tab_drag_and_drop_enabled : 1;
+ gint page_drag_and_drop_enabled : 1;
};
G_DEFINE_TYPE(GeditNotebook, gedit_notebook, GTK_TYPE_NOTEBOOK)
@@ -75,10 +75,10 @@ static void gedit_notebook_finalize (GObject *object);
static gboolean gedit_notebook_change_current_page (GtkNotebook *notebook,
gint offset);
-static void move_current_tab_to_another_notebook (GeditNotebook *src,
- GeditNotebook *dest,
- GdkEventMotion *event,
- gint dest_position);
+static void move_current_page_to_another_notebook (GeditNotebook *src,
+ GeditNotebook *dest,
+ GdkEventMotion *event,
+ gint dest_position);
/* Local variables */
static GdkCursor *cursor = NULL;
@@ -86,11 +86,11 @@ static GdkCursor *cursor = NULL;
/* Signals */
enum
{
- TAB_ADDED,
- TAB_REMOVED,
- TABS_REORDERED,
- TAB_DETACHED,
- TAB_CLOSE_REQUEST,
+ PAGE_ADDED,
+ PAGE_REMOVED,
+ PAGES_REORDERED,
+ PAGE_DETACHED,
+ PAGE_CLOSE_REQUEST,
LAST_SIGNAL
};
@@ -106,57 +106,57 @@ gedit_notebook_class_init (GeditNotebookClass *klass)
notebook_class->change_current_page = gedit_notebook_change_current_page;
- signals[TAB_ADDED] =
- g_signal_new ("tab_added",
+ signals[PAGE_ADDED] =
+ g_signal_new ("gedit-page-added",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (GeditNotebookClass, tab_added),
+ G_STRUCT_OFFSET (GeditNotebookClass, gedit_page_added),
NULL, NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE,
1,
- GEDIT_TYPE_TAB);
- signals[TAB_REMOVED] =
- g_signal_new ("tab_removed",
+ GEDIT_TYPE_PAGE);
+ signals[PAGE_REMOVED] =
+ g_signal_new ("gedit-page_removed",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (GeditNotebookClass, tab_removed),
+ G_STRUCT_OFFSET (GeditNotebookClass, gedit_page_removed),
NULL, NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE,
1,
- GEDIT_TYPE_TAB);
- signals[TAB_DETACHED] =
- g_signal_new ("tab_detached",
+ GEDIT_TYPE_PAGE);
+ signals[PAGE_DETACHED] =
+ g_signal_new ("page_detached",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (GeditNotebookClass, tab_detached),
+ G_STRUCT_OFFSET (GeditNotebookClass, page_detached),
NULL, NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE,
1,
- GEDIT_TYPE_TAB);
- signals[TABS_REORDERED] =
- g_signal_new ("tabs_reordered",
+ GEDIT_TYPE_PAGE);
+ signals[PAGES_REORDERED] =
+ g_signal_new ("pages_reordered",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (GeditNotebookClass, tabs_reordered),
+ G_STRUCT_OFFSET (GeditNotebookClass, pages_reordered),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE,
0);
- signals[TAB_CLOSE_REQUEST] =
- g_signal_new ("tab-close-request",
+ signals[PAGE_CLOSE_REQUEST] =
+ g_signal_new ("page-close-request",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GeditNotebookClass, tab_close_request),
+ G_STRUCT_OFFSET (GeditNotebookClass, page_close_request),
NULL, NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE,
1,
- GEDIT_TYPE_TAB);
+ GEDIT_TYPE_PAGE);
- g_type_class_add_private (object_class, sizeof(GeditNotebookPrivate));
+ g_type_class_add_private (object_class, sizeof (GeditNotebookPrivate));
/* Set up a style for the close button with no focus padding. */
gtk_rc_parse_string (
@@ -218,9 +218,9 @@ is_in_notebook_window (GeditNotebook *notebook,
}
static gint
-find_tab_num_at_pos (GeditNotebook *notebook,
- gint abs_x,
- gint abs_y)
+find_page_num_at_pos (GeditNotebook *notebook,
+ gint abs_x,
+ gint abs_y)
{
GtkPositionType tab_pos;
int page_num = 0;
@@ -282,10 +282,10 @@ find_tab_num_at_pos (GeditNotebook *notebook,
}
static gint
-find_notebook_and_tab_at_pos (gint abs_x,
- gint abs_y,
- GeditNotebook **notebook,
- gint *page_num)
+find_notebook_and_page_at_pos (gint abs_x,
+ gint abs_y,
+ GeditNotebook **notebook,
+ gint *page_num)
{
*notebook = find_notebook_at_pointer (abs_x, abs_y);
if (*notebook == NULL)
@@ -293,7 +293,7 @@ find_notebook_and_tab_at_pos (gint abs_x,
return NOT_IN_APP_WINDOWS;
}
- *page_num = find_tab_num_at_pos (*notebook, abs_x, abs_y);
+ *page_num = find_page_num_at_pos (*notebook, abs_x, abs_y);
if (*page_num < 0)
{
@@ -306,70 +306,70 @@ find_notebook_and_tab_at_pos (gint abs_x,
}
/**
- * gedit_notebook_move_tab:
+ * gedit_notebook_move_page:
* @src: a #GeditNotebook
* @dest: a #GeditNotebook
- * @tab: a #GeditTab
+ * @page: a #GeditPage
* @dest_position: the position for @tab
*
- * Moves @tab from @src to @dest.
- * If dest_position is greater than or equal to the number of tabs
- * of the destination nootebook or negative, tab will be moved to the
- * end of the tabs.
+ * Moves @page from @src to @dest.
+ * If dest_position is greater than or equal to the number of pages
+ * of the destination notebook or negative, page will be moved to the
+ * end of the pages.
*/
void
-gedit_notebook_move_tab (GeditNotebook *src,
- GeditNotebook *dest,
- GeditTab *tab,
- gint dest_position)
+gedit_notebook_move_page (GeditNotebook *src,
+ GeditNotebook *dest,
+ GeditPage *page,
+ gint dest_position)
{
- g_return_if_fail (GEDIT_IS_NOTEBOOK (src));
+ g_return_if_fail (GEDIT_IS_NOTEBOOK (src));
g_return_if_fail (GEDIT_IS_NOTEBOOK (dest));
g_return_if_fail (src != dest);
- g_return_if_fail (GEDIT_IS_TAB (tab));
+ g_return_if_fail (GEDIT_IS_PAGE (page));
/* make sure the tab isn't destroyed while we move it */
- g_object_ref (tab);
- gedit_notebook_remove_tab (src, tab);
- gedit_notebook_add_tab (dest, tab, dest_position, TRUE);
- g_object_unref (tab);
+ g_object_ref (page);
+ gedit_notebook_remove_page (src, page);
+ gedit_notebook_add_page (dest, page, dest_position, TRUE);
+ g_object_unref (page);
}
/**
- * gedit_notebook_reorder_tab:
+ * gedit_notebook_reorder_page:
* @src: a #GeditNotebook
- * @tab: a #GeditTab
- * @dest_position: the position for @tab
+ * @page: a #GeditPage
+ * @dest_position: the position for @page
*
- * Reorders the page containing @tab, so that it appears in @dest_position position.
- * If dest_position is greater than or equal to the number of tabs
+ * Reorders the page containing @page, so that it appears in @dest_position position.
+ * If dest_position is greater than or equal to the number of pages
* of the destination notebook or negative, tab will be moved to the
- * end of the tabs.
+ * end of the pages.
*/
void
-gedit_notebook_reorder_tab (GeditNotebook *src,
- GeditTab *tab,
- gint dest_position)
+gedit_notebook_reorder_page (GeditNotebook *src,
+ GeditPage *page,
+ gint dest_position)
{
gint old_position;
- g_return_if_fail (GEDIT_IS_NOTEBOOK (src));
- g_return_if_fail (GEDIT_IS_TAB (tab));
+ g_return_if_fail (GEDIT_IS_NOTEBOOK (src));
+ g_return_if_fail (GEDIT_IS_PAGE (page));
+
+ old_position = gtk_notebook_page_num (GTK_NOTEBOOK (src),
+ GTK_WIDGET (page));
- old_position = gtk_notebook_page_num (GTK_NOTEBOOK (src),
- GTK_WIDGET (tab));
-
if (old_position == dest_position)
return;
gtk_notebook_reorder_child (GTK_NOTEBOOK (src),
- GTK_WIDGET (tab),
+ GTK_WIDGET (page),
dest_position);
if (!src->priv->drag_in_progress)
{
g_signal_emit (G_OBJECT (src),
- signals[TABS_REORDERED],
+ signals[PAGES_REORDERED],
0);
}
}
@@ -394,8 +394,8 @@ drag_start (GeditNotebook *notebook,
gdk_pointer_grab (gtk_widget_get_window (GTK_WIDGET (notebook)),
FALSE,
GDK_BUTTON1_MOTION_MASK | GDK_BUTTON_RELEASE_MASK,
- NULL,
- cursor,
+ NULL,
+ cursor,
time);
}
}
@@ -405,8 +405,8 @@ drag_stop (GeditNotebook *notebook)
{
if (notebook->priv->drag_in_progress)
{
- g_signal_emit (G_OBJECT (notebook),
- signals[TABS_REORDERED],
+ g_signal_emit (G_OBJECT (notebook),
+ signals[PAGES_REORDERED],
0);
}
@@ -423,8 +423,8 @@ drag_stop (GeditNotebook *notebook)
* here, instead we do it on drag_stop
*/
static void
-move_current_tab (GeditNotebook *notebook,
- gint dest_position)
+move_current_page (GeditNotebook *notebook,
+ gint dest_position)
{
gint cur_page_num;
@@ -432,14 +432,14 @@ move_current_tab (GeditNotebook *notebook,
if (dest_position != cur_page_num)
{
- GtkWidget *cur_tab;
+ GtkWidget *cur_page;
+
+ cur_page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook),
+ cur_page_num);
- cur_tab = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook),
- cur_page_num);
-
- gedit_notebook_reorder_tab (GEDIT_NOTEBOOK (notebook),
- GEDIT_TAB (cur_tab),
- dest_position);
+ gedit_notebook_reorder_page (GEDIT_NOTEBOOK (notebook),
+ GEDIT_PAGE (cur_page),
+ dest_position);
}
}
@@ -454,7 +454,7 @@ motion_notify_cb (GeditNotebook *notebook,
if (notebook->priv->drag_in_progress == FALSE)
{
- if (notebook->priv->tab_drag_and_drop_enabled == FALSE)
+ if (notebook->priv->page_drag_and_drop_enabled == FALSE)
return FALSE;
if (gtk_drag_check_threshold (GTK_WIDGET (notebook),
@@ -470,24 +470,24 @@ motion_notify_cb (GeditNotebook *notebook,
return FALSE;
}
- result = find_notebook_and_tab_at_pos ((gint)event->x_root,
- (gint)event->y_root,
- &dest,
- &page_num);
+ result = find_notebook_and_page_at_pos ((gint)event->x_root,
+ (gint)event->y_root,
+ &dest,
+ &page_num);
if (result != NOT_IN_APP_WINDOWS)
{
if (dest != notebook)
{
- move_current_tab_to_another_notebook (notebook,
- dest,
- event,
- page_num);
+ move_current_page_to_another_notebook (notebook,
+ dest,
+ event,
+ page_num);
}
else
{
g_return_val_if_fail (page_num >= -1, FALSE);
- move_current_tab (notebook, page_num);
+ move_current_page (notebook, page_num);
}
}
@@ -495,16 +495,16 @@ motion_notify_cb (GeditNotebook *notebook,
}
static void
-move_current_tab_to_another_notebook (GeditNotebook *src,
- GeditNotebook *dest,
- GdkEventMotion *event,
- gint dest_position)
+move_current_page_to_another_notebook (GeditNotebook *src,
+ GeditNotebook *dest,
+ GdkEventMotion *event,
+ gint dest_position)
{
- GeditTab *tab;
+ GeditPage *page;
gint cur_page;
- /* This is getting tricky, the tab was dragged in a notebook
- * in another window of the same app, we move the tab
+ /* This is getting tricky, the page was dragged in a notebook
+ * in another window of the same app, we move the page
* to that new notebook, and let this notebook handle the
* drag
*/
@@ -512,8 +512,8 @@ move_current_tab_to_another_notebook (GeditNotebook *src,
g_return_if_fail (dest != src);
cur_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (src));
- tab = GEDIT_TAB (gtk_notebook_get_nth_page (GTK_NOTEBOOK (src),
- cur_page));
+ page = GEDIT_PAGE (gtk_notebook_get_nth_page (GTK_NOTEBOOK (src),
+ cur_page));
/* stop drag in origin window */
/* ungrab the pointer if it's grabbed */
@@ -524,7 +524,7 @@ move_current_tab_to_another_notebook (GeditNotebook *src,
}
gtk_grab_remove (GTK_WIDGET (src));
- gedit_notebook_move_tab (src, dest, tab, dest_position);
+ gedit_notebook_move_page (src, dest, page, dest_position);
/* start drag handling in dest notebook */
dest->priv->motion_notify_handler_id =
@@ -556,7 +556,7 @@ button_release_cb (GeditNotebook *notebook,
{
/* Tab was detached */
g_signal_emit (G_OBJECT (notebook),
- signals[TAB_DETACHED],
+ signals[PAGE_DETACHED],
0,
cur_page);
}
@@ -585,10 +585,10 @@ button_press_cb (GeditNotebook *notebook,
if (notebook->priv->drag_in_progress)
return TRUE;
- tab_clicked = find_tab_num_at_pos (notebook,
- event->x_root,
- event->y_root);
-
+ tab_clicked = find_page_num_at_pos (notebook,
+ event->x_root,
+ event->y_root);
+
if ((event->button == 1) &&
(event->type == GDK_BUTTON_PRESS) &&
(tab_clicked >= 0))
@@ -646,6 +646,7 @@ gedit_notebook_switch_page_cb (GtkNotebook *notebook,
{
GeditNotebook *nb = GEDIT_NOTEBOOK (notebook);
GtkWidget *child;
+ GeditViewContainer *container;
GeditView *view;
child = gtk_notebook_get_nth_page (notebook, page_num);
@@ -662,7 +663,8 @@ gedit_notebook_switch_page_cb (GtkNotebook *notebook,
child);
/* give focus to the view */
- view = gedit_tab_get_view (GEDIT_TAB (child));
+ container = gedit_page_get_active_view_container (GEDIT_PAGE (child));
+ view = gedit_view_container_get_view (GEDIT_VIEW_CONTAINER (container));
gtk_widget_grab_focus (GTK_WIDGET (view));
}
@@ -692,7 +694,7 @@ gedit_notebook_init (GeditNotebook *notebook)
notebook->priv = GEDIT_NOTEBOOK_GET_PRIVATE (notebook);
notebook->priv->close_buttons_sensitive = TRUE;
- notebook->priv->tab_drag_and_drop_enabled = TRUE;
+ notebook->priv->page_drag_and_drop_enabled = TRUE;
gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE);
gtk_notebook_set_show_border (GTK_NOTEBOOK (notebook), FALSE);
@@ -729,7 +731,7 @@ gedit_notebook_finalize (GObject *object)
}
/*
- * We need to override this because when we don't show the tabs, like in
+ * We need to override this because when we don't show the pages, like in
* fullscreen we need to have wrap around too
*/
static gboolean
@@ -772,7 +774,9 @@ gedit_notebook_change_current_page (GtkNotebook *notebook,
}
static void
-sync_name (GeditTab *tab, GParamSpec *pspec, GtkWidget *hbox)
+sync_name (GeditPage *page,
+ GeditViewContainer *container,
+ GtkWidget *hbox)
{
GeditNotebook *nb;
GtkWidget *label;
@@ -781,7 +785,7 @@ sync_name (GeditTab *tab, GParamSpec *pspec, GtkWidget *hbox)
GtkWidget *spinner;
gchar *str;
GtkImage *icon;
- GeditTabState state;
+ GeditViewContainerState state;
label = GTK_WIDGET (g_object_get_data (G_OBJECT (hbox), "label"));
ebox = GTK_WIDGET (g_object_get_data (G_OBJECT (hbox), "label-ebox"));
@@ -789,39 +793,41 @@ sync_name (GeditTab *tab, GParamSpec *pspec, GtkWidget *hbox)
button = GTK_WIDGET (g_object_get_data (G_OBJECT (hbox), "close-button"));
spinner = GTK_WIDGET (g_object_get_data (G_OBJECT (hbox), "spinner"));
- nb = GEDIT_NOTEBOOK (gtk_widget_get_parent (GTK_WIDGET (tab)));
+ nb = GEDIT_NOTEBOOK (gtk_widget_get_parent (GTK_WIDGET (page)));
+ container = gedit_page_get_active_view_container (page);
g_return_if_fail ((label != NULL) &&
(ebox != NULL) &&
(button != NULL) &&
(icon != NULL) &&
(spinner != NULL) &&
- (nb != NULL));
+ (nb != NULL) &&
+ (page != NULL));
- str = _gedit_tab_get_name (tab);
+ str = _gedit_view_container_get_name (container);
g_return_if_fail (str != NULL);
gtk_label_set_text (GTK_LABEL (label), str);
g_free (str);
- str = _gedit_tab_get_tooltips (tab);
+ str = _gedit_view_container_get_tooltips (container);
g_return_if_fail (str != NULL);
gtk_widget_set_tooltip_markup (ebox, str);
g_free (str);
-
- state = gedit_tab_get_state (tab);
+
+ state = gedit_view_container_get_state (container);
gtk_widget_set_sensitive (button,
- nb->priv->close_buttons_sensitive &&
- (state != GEDIT_TAB_STATE_CLOSING) &&
- (state != GEDIT_TAB_STATE_SAVING) &&
- (state != GEDIT_TAB_STATE_SHOWING_PRINT_PREVIEW) &&
- (state != GEDIT_TAB_STATE_SAVING_ERROR));
+ nb->priv->close_buttons_sensitive &&
+ (state != GEDIT_VIEW_CONTAINER_STATE_CLOSING) &&
+ (state != GEDIT_VIEW_CONTAINER_STATE_SAVING) &&
+ (state != GEDIT_VIEW_CONTAINER_STATE_SHOWING_PRINT_PREVIEW) &&
+ (state != GEDIT_VIEW_CONTAINER_STATE_SAVING_ERROR));
- if ((state == GEDIT_TAB_STATE_LOADING) ||
- (state == GEDIT_TAB_STATE_SAVING) ||
- (state == GEDIT_TAB_STATE_REVERTING))
+ if ((state == GEDIT_VIEW_CONTAINER_STATE_LOADING) ||
+ (state == GEDIT_VIEW_CONTAINER_STATE_SAVING) ||
+ (state == GEDIT_VIEW_CONTAINER_STATE_REVERTING))
{
gtk_widget_hide (GTK_WIDGET (icon));
@@ -836,7 +842,7 @@ sync_name (GeditTab *tab, GParamSpec *pspec, GtkWidget *hbox)
{
GdkPixbuf *pixbuf;
- pixbuf = _gedit_tab_get_icon (tab);
+ pixbuf = _gedit_view_container_get_icon (container);
gtk_image_set_from_pixbuf (icon, pixbuf);
if (pixbuf != NULL)
@@ -854,13 +860,25 @@ sync_name (GeditTab *tab, GParamSpec *pspec, GtkWidget *hbox)
}
static void
-close_button_clicked_cb (GtkWidget *widget,
- GtkWidget *tab)
+on_notify_name_cb (GeditViewContainer *container,
+ GParamSpec *pspec,
+ GtkWidget *hbox)
+{
+ GeditPage *page;
+
+ page = gedit_page_get_from_container (container);
+
+ sync_name (page, container, hbox);
+}
+
+static void
+close_button_clicked_cb (GtkWidget *widget,
+ GtkWidget *page)
{
GeditNotebook *notebook;
- notebook = GEDIT_NOTEBOOK (gtk_widget_get_parent (tab));
- g_signal_emit (notebook, signals[TAB_CLOSE_REQUEST], 0, tab);
+ notebook = GEDIT_NOTEBOOK (gtk_widget_get_parent (page));
+ g_signal_emit (notebook, signals[PAGE_CLOSE_REQUEST], 0, page);
}
static void
@@ -878,7 +896,7 @@ close_button_style_set_cb (GtkWidget *button,
static GtkWidget *
build_tab_label (GeditNotebook *nb,
- GeditTab *tab)
+ GeditPage *page)
{
GtkWidget *hbox, *label_hbox, *label_ebox;
GtkWidget *label, *dummy_label;
@@ -916,7 +934,7 @@ build_tab_label (GeditNotebook *nb,
g_signal_connect (close_button,
"clicked",
G_CALLBACK (close_button_clicked_cb),
- tab);
+ page);
/* setup spinner */
#ifdef BUILD_SPINNER
@@ -948,7 +966,7 @@ build_tab_label (GeditNotebook *nb,
gtk_widget_show (label_ebox);
gtk_widget_show (label_hbox);
gtk_widget_show (label);
- gtk_widget_show (dummy_label);
+ gtk_widget_show (dummy_label);
gtk_widget_show (image);
gtk_widget_show (close_button);
gtk_widget_show (icon);
@@ -958,7 +976,7 @@ build_tab_label (GeditNotebook *nb,
g_object_set_data (G_OBJECT (hbox), "spinner", spinner);
g_object_set_data (G_OBJECT (hbox), "icon", icon);
g_object_set_data (G_OBJECT (hbox), "close-button", close_button);
- g_object_set_data (G_OBJECT (tab), "close-button", close_button);
+ g_object_set_data (G_OBJECT (page), "close-button", close_button);
return hbox;
}
@@ -966,13 +984,13 @@ build_tab_label (GeditNotebook *nb,
/**
* gedit_notebook_set_always_show_tabs:
* @nb: a #GeditNotebook
- * @show_tabs: %TRUE to always show the tabs
+ * @show_pages: %TRUE to always show the tabs
*
* Sets the visibility of the tabs in the @nb.
*/
void
gedit_notebook_set_always_show_tabs (GeditNotebook *nb,
- gboolean show_tabs)
+ gboolean show_tabs)
{
g_return_if_fail (GEDIT_IS_NOTEBOOK (nb));
@@ -982,75 +1000,88 @@ gedit_notebook_set_always_show_tabs (GeditNotebook *nb,
}
/**
- * gedit_notebook_add_tab:
+ * gedit_notebook_add_page:
* @nb: a #GeditNotebook
- * @tab: a #GeditTab
- * @position: the position where the @tab should be added
- * @jump_to: %TRUE to set the @tab as active
+ * @page: a #GeditPage
+ * @position: the position where the @page should be added
+ * @jump_to: %TRUE to set the @page as active
*
- * Adds the specified @tab to the @nb.
+ * Adds the specified @page to the @nb.
*/
void
-gedit_notebook_add_tab (GeditNotebook *nb,
- GeditTab *tab,
- gint position,
- gboolean jump_to)
+gedit_notebook_add_page (GeditNotebook *nb,
+ GeditPage *page,
+ gint position,
+ gboolean jump_to)
{
GtkWidget *label;
+ GList *containers, *l;
g_return_if_fail (GEDIT_IS_NOTEBOOK (nb));
- g_return_if_fail (GEDIT_IS_TAB (tab));
+ g_return_if_fail (GEDIT_IS_PAGE (page));
- label = build_tab_label (nb, tab);
+ label = build_tab_label (nb, page);
update_tabs_visibility (nb, TRUE);
gtk_notebook_insert_page (GTK_NOTEBOOK (nb),
- GTK_WIDGET (tab),
+ GTK_WIDGET (page),
label,
position);
- sync_name (tab, NULL, label);
-
- g_signal_connect_object (tab,
- "notify::name",
- G_CALLBACK (sync_name),
- label,
- 0);
- g_signal_connect_object (tab,
- "notify::state",
- G_CALLBACK (sync_name),
- label,
- 0);
-
- g_signal_emit (G_OBJECT (nb), signals[TAB_ADDED], 0, tab);
+ sync_name (page, NULL, label);
+
+ containers = gedit_page_get_view_containers (page);
+ for (l = containers; l != NULL; l = g_list_next (l))
+ {
+ g_signal_connect_object (l->data,
+ "notify::name",
+ G_CALLBACK (on_notify_name_cb),
+ label,
+ 0);
+ g_signal_connect_object (l->data,
+ "notify::state",
+ G_CALLBACK (on_notify_name_cb),
+ label,
+ 0);
+ }
+
+ g_signal_connect_object (page,
+ "active-container-changed",
+ G_CALLBACK (sync_name),
+ label,
+ 0);
+
+ g_signal_emit (G_OBJECT (nb), signals[PAGE_ADDED], 0, page);
/* The signal handler may have reordered the tabs */
position = gtk_notebook_page_num (GTK_NOTEBOOK (nb),
- GTK_WIDGET (tab));
+ GTK_WIDGET (page));
if (jump_to)
{
+ GeditViewContainer *container;
GeditView *view;
gtk_notebook_set_current_page (GTK_NOTEBOOK (nb), position);
- g_object_set_data (G_OBJECT (tab),
+ g_object_set_data (G_OBJECT (page),
"jump_to",
GINT_TO_POINTER (jump_to));
- view = gedit_tab_get_view (tab);
+ container = gedit_page_get_active_view_container (page);
+ view = gedit_view_container_get_view (container);
gtk_widget_grab_focus (GTK_WIDGET (view));
}
}
static void
-smart_tab_switching_on_closure (GeditNotebook *nb,
- GeditTab *tab)
+smart_page_switching_on_closure (GeditNotebook *nb,
+ GeditPage *page)
{
gboolean jump_to;
jump_to = GPOINTER_TO_INT (g_object_get_data
- (G_OBJECT (tab), "jump_to"));
+ (G_OBJECT (page), "jump_to"));
if (!jump_to || !nb->priv->focused_pages)
{
@@ -1073,74 +1104,74 @@ smart_tab_switching_on_closure (GeditNotebook *nb,
}
static void
-remove_tab (GeditTab *tab,
- GeditNotebook *nb)
+remove_page (GeditPage *page,
+ GeditNotebook *nb)
{
GtkWidget *label, *ebox;
gint position;
- position = gtk_notebook_page_num (GTK_NOTEBOOK (nb), GTK_WIDGET (tab));
+ position = gtk_notebook_page_num (GTK_NOTEBOOK (nb), GTK_WIDGET (page));
- label = gtk_notebook_get_tab_label (GTK_NOTEBOOK (nb), GTK_WIDGET (tab));
+ label = gtk_notebook_get_tab_label (GTK_NOTEBOOK (nb), GTK_WIDGET (page));
ebox = GTK_WIDGET (g_object_get_data (G_OBJECT (label), "label-ebox"));
- g_signal_handlers_disconnect_by_func (tab,
- G_CALLBACK (sync_name),
+ g_signal_handlers_disconnect_by_func (page,
+ G_CALLBACK (sync_name),
label);
- /* we ref the tab so that it's still alive while the tabs_removed
+ /* we ref the page so that it's still alive while the page_removed
* signal is processed.
*/
- g_object_ref (tab);
+ g_object_ref (page);
gtk_notebook_remove_page (GTK_NOTEBOOK (nb), position);
update_tabs_visibility (nb, FALSE);
- g_signal_emit (G_OBJECT (nb), signals[TAB_REMOVED], 0, tab);
+ g_signal_emit (G_OBJECT (nb), signals[PAGE_REMOVED], 0, page);
- g_object_unref (tab);
+ g_object_unref (page);
}
/**
* gedit_notebook_remove_tab:
* @nb: a #GeditNotebook
- * @tab: a #GeditTab
+ * @page: a #GeditPage
*
- * Removes @tab from @nb.
+ * Removes @page from @nb.
*/
void
-gedit_notebook_remove_tab (GeditNotebook *nb,
- GeditTab *tab)
+gedit_notebook_remove_page (GeditNotebook *nb,
+ GeditPage *page)
{
gint position, curr;
g_return_if_fail (GEDIT_IS_NOTEBOOK (nb));
- g_return_if_fail (GEDIT_IS_TAB (tab));
+ g_return_if_fail (GEDIT_IS_PAGE (page));
/* Remove the page from the focused pages list */
nb->priv->focused_pages = g_list_remove (nb->priv->focused_pages,
- tab);
+ page);
- position = gtk_notebook_page_num (GTK_NOTEBOOK (nb), GTK_WIDGET (tab));
+ position = gtk_notebook_page_num (GTK_NOTEBOOK (nb), GTK_WIDGET (page));
curr = gtk_notebook_get_current_page (GTK_NOTEBOOK (nb));
if (position == curr)
{
- smart_tab_switching_on_closure (nb, tab);
+ smart_page_switching_on_closure (nb, page);
}
- remove_tab (tab, nb);
+ remove_page (page, nb);
}
/**
- * gedit_notebook_remove_all_tabs:
+ * gedit_notebook_remove_all_pages:
* @nb: a #GeditNotebook
*
- * Removes all #GeditTab from @nb.
+ * Removes all #GeditPage from @nb.
*/
void
-gedit_notebook_remove_all_tabs (GeditNotebook *nb)
+gedit_notebook_remove_all_pages (GeditNotebook *nb)
{
g_return_if_fail (GEDIT_IS_NOTEBOOK (nb));
@@ -1148,31 +1179,33 @@ gedit_notebook_remove_all_tabs (GeditNotebook *nb)
nb->priv->focused_pages = NULL;
gtk_container_foreach (GTK_CONTAINER (nb),
- (GtkCallback)remove_tab,
+ (GtkCallback)remove_page,
nb);
}
static void
-set_close_buttons_sensitivity (GeditTab *tab,
+set_close_buttons_sensitivity (GeditPage *page,
GeditNotebook *nb)
{
- GtkWidget *button;
- GeditTabState state;
+ GtkWidget *button;
+ GeditViewContainerState state;
+ GeditViewContainer *container;
- button = GTK_WIDGET (g_object_get_data (G_OBJECT (tab),
- "close-button"));
+ button = GTK_WIDGET (g_object_get_data (G_OBJECT (page),
+ "close-button"));
g_return_if_fail (button != NULL);
- state = gedit_tab_get_state (tab);
+ container = gedit_page_get_active_view_container (page);
+ state = gedit_view_container_get_state (container);
- gtk_widget_set_sensitive (button,
+ gtk_widget_set_sensitive (button,
nb->priv->close_buttons_sensitive &&
- (state != GEDIT_TAB_STATE_CLOSING) &&
- (state != GEDIT_TAB_STATE_SAVING) &&
- (state != GEDIT_TAB_STATE_SHOWING_PRINT_PREVIEW) &&
- (state != GEDIT_TAB_STATE_PRINTING) &&
- (state != GEDIT_TAB_STATE_PRINT_PREVIEWING) &&
- (state != GEDIT_TAB_STATE_SAVING_ERROR));
+ (state != GEDIT_VIEW_CONTAINER_STATE_CLOSING) &&
+ (state != GEDIT_VIEW_CONTAINER_STATE_SAVING) &&
+ (state != GEDIT_VIEW_CONTAINER_STATE_SHOWING_PRINT_PREVIEW) &&
+ (state != GEDIT_VIEW_CONTAINER_STATE_PRINTING) &&
+ (state != GEDIT_VIEW_CONTAINER_STATE_PRINT_PREVIEWING) &&
+ (state != GEDIT_VIEW_CONTAINER_STATE_SAVING_ERROR));
}
/**
@@ -1180,7 +1213,7 @@ set_close_buttons_sensitivity (GeditTab *tab,
* @nb: a #GeditNotebook
* @sensitive: %TRUE to make the buttons sensitive
*
- * Sets whether the close buttons in the tabs of @nb are sensitive.
+ * Sets whether the close buttons in the pages of @nb are sensitive.
*/
void
gedit_notebook_set_close_buttons_sensitive (GeditNotebook *nb,
@@ -1217,28 +1250,28 @@ gedit_notebook_get_close_buttons_sensitive (GeditNotebook *nb)
}
/**
- * gedit_notebook_set_tab_drag_and_drop_enabled:
+ * gedit_notebook_set_page_drag_and_drop_enabled:
* @nb: a #GeditNotebook
* @enable: %TRUE to enable the drag and drop
*
- * Sets whether drag and drop of tabs in the @nb is enabled.
+ * Sets whether drag and drop of pages in the @nb is enabled.
*/
void
-gedit_notebook_set_tab_drag_and_drop_enabled (GeditNotebook *nb,
- gboolean enable)
+gedit_notebook_set_page_drag_and_drop_enabled (GeditNotebook *nb,
+ gboolean enable)
{
g_return_if_fail (GEDIT_IS_NOTEBOOK (nb));
enable = (enable != FALSE);
- if (enable == nb->priv->tab_drag_and_drop_enabled)
+ if (enable == nb->priv->page_drag_and_drop_enabled)
return;
- nb->priv->tab_drag_and_drop_enabled = enable;
+ nb->priv->page_drag_and_drop_enabled = enable;
}
/**
- * gedit_notebook_get_tab_drag_and_drop_enabled:
+ * gedit_notebook_get_page_drag_and_drop_enabled:
* @nb: a #GeditNotebook
*
* Whether the drag and drop is enabled in the @nb.
@@ -1246,10 +1279,10 @@ gedit_notebook_set_tab_drag_and_drop_enabled (GeditNotebook *nb,
* Returns: %TRUE if the drag and drop is enabled.
*/
gboolean
-gedit_notebook_get_tab_drag_and_drop_enabled (GeditNotebook *nb)
+gedit_notebook_get_page_drag_and_drop_enabled (GeditNotebook *nb)
{
g_return_val_if_fail (GEDIT_IS_NOTEBOOK (nb), TRUE);
- return nb->priv->tab_drag_and_drop_enabled;
+ return nb->priv->page_drag_and_drop_enabled;
}
diff --git a/gedit/gedit-notebook.h b/gedit/gedit-notebook.h
index ada7c27..0dfd42d 100644
--- a/gedit/gedit-notebook.h
+++ b/gedit/gedit-notebook.h
@@ -38,7 +38,7 @@
#ifndef GEDIT_NOTEBOOK_H
#define GEDIT_NOTEBOOK_H
-#include <gedit/gedit-tab.h>
+#include <gedit/gedit-page.h>
#include <glib.h>
#include <gtk/gtk.h>
@@ -81,16 +81,18 @@ struct _GeditNotebookClass
GtkNotebookClass parent_class;
/* Signals */
- void (* tab_added) (GeditNotebook *notebook,
- GeditTab *tab);
- void (* tab_removed) (GeditNotebook *notebook,
- GeditTab *tab);
- void (* tab_detached) (GeditNotebook *notebook,
- GeditTab *tab);
- void (* tabs_reordered) (GeditNotebook *notebook);
- void (* tab_close_request)
- (GeditNotebook *notebook,
- GeditTab *tab);
+ void (* gedit_page_added)
+ (GeditNotebook *notebook,
+ GeditPage *page);
+ void (* gedit_page_removed)
+ (GeditNotebook *notebook,
+ GeditPage *page);
+ void (* page_detached) (GeditNotebook *notebook,
+ GeditPage *page);
+ void (* pages_reordered) (GeditNotebook *notebook);
+ void (* page_close_request)
+ (GeditNotebook *notebook,
+ GeditPage *tab);
};
/*
@@ -100,29 +102,29 @@ GType gedit_notebook_get_type (void) G_GNUC_CONST;
GtkWidget *gedit_notebook_new (void);
-void gedit_notebook_add_tab (GeditNotebook *nb,
- GeditTab *tab,
+void gedit_notebook_add_page (GeditNotebook *nb,
+ GeditPage *page,
gint position,
gboolean jump_to);
-void gedit_notebook_remove_tab (GeditNotebook *nb,
- GeditTab *tab);
+void gedit_notebook_remove_page (GeditNotebook *nb,
+ GeditPage *page);
-void gedit_notebook_remove_all_tabs (GeditNotebook *nb);
+void gedit_notebook_remove_all_pages (GeditNotebook *nb);
-void gedit_notebook_reorder_tab (GeditNotebook *src,
- GeditTab *tab,
+void gedit_notebook_reorder_page (GeditNotebook *src,
+ GeditPage *page,
gint dest_position);
-void gedit_notebook_move_tab (GeditNotebook *src,
+void gedit_notebook_move_page (GeditNotebook *src,
GeditNotebook *dest,
- GeditTab *tab,
+ GeditPage *tab,
gint dest_position);
/* FIXME: do we really need this function ? */
-void gedit_notebook_set_always_show_tabs
+void gedit_notebook_set_always_show_tabs
(GeditNotebook *nb,
- gboolean show_tabs);
+ gboolean show_pages);
void gedit_notebook_set_close_buttons_sensitive
(GeditNotebook *nb,
@@ -131,11 +133,11 @@ void gedit_notebook_set_close_buttons_sensitive
gboolean gedit_notebook_get_close_buttons_sensitive
(GeditNotebook *nb);
-void gedit_notebook_set_tab_drag_and_drop_enabled
+void gedit_notebook_set_page_drag_and_drop_enabled
(GeditNotebook *nb,
gboolean enable);
-gboolean gedit_notebook_get_tab_drag_and_drop_enabled
+gboolean gedit_notebook_get_page_drag_and_drop_enabled
(GeditNotebook *nb);
G_END_DECLS
diff --git a/gedit/gedit-page.c b/gedit/gedit-page.c
new file mode 100644
index 0000000..e44bc41
--- /dev/null
+++ b/gedit/gedit-page.c
@@ -0,0 +1,826 @@
+/*
+ * gedit-page.c
+ * This file is part of gedit
+ *
+ * Copyright (C) 2009 - Ignacio Casal Quinteiro
+ *
+ * gedit 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.
+ *
+ * gedit 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 gedit; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+
+#include "gedit-page.h"
+#include "gedit-data-binding.h"
+#include "gedit-view-container.h"
+#include "gedit-text-view.h"
+
+#define GEDIT_PAGE_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GEDIT_TYPE_PAGE, GeditPagePrivate))
+
+#define DESTROY_DATA_KEY "gedit-page-destroy-data-key"
+#define VIRTUAL_DOCUMENT_KEY "gedit-page-virtual-document-key"
+
+enum
+{
+ AUTO_INDENT,
+ DRAW_SPACES,
+ HIGHLIGHT_CURRENT_LINE,
+ INDENT_ON_TAB,
+ INDENT_WIDTH,
+ INSERT_SPACES_INSTEAD_OF_TABS,
+ RIGHT_MARGIN_POSITION,
+ SHOW_LINE_MARKS,
+ SHOW_LINE_NUMBERS,
+ SHOW_RIGHT_MARGIN,
+ SMART_HOME_END,
+ TAB_WIDTH,
+ HIGHLIGHT_MATCHING_BRACKETS,
+ HIGHLIGHT_SYNTAX,
+ LANGUAGE,
+ MAX_UNDO_LEVELS,
+ STYLE_SCHEME,
+ LAST_PROPERTY
+};
+
+enum
+{
+ REAL,
+ VIRTUAL,
+ N_STATES
+};
+
+typedef struct _Binding
+{
+ GeditDocument *docs[N_STATES];
+ GtkWidget *views[N_STATES];
+
+ gulong insert_text_id[N_STATES];
+ gulong delete_range_id[N_STATES];
+
+ GeditDataBinding *bindings[LAST_PROPERTY];
+} Binding;
+
+typedef struct _VirtualDocument
+{
+ GList *bindings; /* List of Binding */
+} VirtualDocument;
+
+typedef struct _DestroyData
+{
+ GtkWidget *view;
+ VirtualDocument *vdoc;
+} DestroyData;
+
+struct _GeditPagePrivate
+{
+ GList *containers;
+ GeditViewContainer *active_container;
+};
+
+/* Signals */
+enum
+{
+ CONTAINER_ADDED,
+ CONTAINER_REMOVED,
+ ACTIVE_CONTAINER_CHANGED,
+ LAST_SIGNAL
+};
+
+static guint signals [LAST_SIGNAL] = { 0 };
+
+G_DEFINE_TYPE (GeditPage, gedit_page, GTK_TYPE_VBOX)
+
+static Binding *
+get_binding_from_view (DestroyData *data)
+{
+ GList *l;
+
+ for (l = data->vdoc->bindings; l != NULL; l = g_list_next (l))
+ {
+ Binding *binding = (Binding *)l->data;
+
+ if (data->view == binding->views[REAL] ||
+ data->view == binding->views[VIRTUAL])
+ return binding;
+ }
+
+ return NULL;
+}
+
+static void
+unbind (Binding *binding)
+{
+ gint i;
+
+ for (i = 0; i < LAST_PROPERTY; i++)
+ {
+ gedit_data_binding_free (binding->bindings[i]);
+ }
+
+ g_signal_handler_disconnect (binding->docs[REAL],
+ binding->insert_text_id[REAL]);
+ g_signal_handler_disconnect (binding->docs[VIRTUAL],
+ binding->insert_text_id[VIRTUAL]);
+ g_signal_handler_disconnect (binding->docs[REAL],
+ binding->delete_range_id[REAL]);
+ g_signal_handler_disconnect (binding->docs[VIRTUAL],
+ binding->delete_range_id[VIRTUAL]);
+}
+
+static void
+insert_text_on_virtual_doc_cb (GtkTextBuffer *textbuffer,
+ GtkTextIter *location,
+ gchar *text,
+ gint len,
+ gpointer user_data)
+{
+ Binding *binding = (Binding *)user_data;
+ GtkTextBuffer *doc;
+ GtkTextIter iter;
+ gint line;
+ gint line_offset;
+ gulong id;
+
+ if (textbuffer == GTK_TEXT_BUFFER (binding->docs[REAL]))
+ {
+ doc = GTK_TEXT_BUFFER (binding->docs[VIRTUAL]);
+ id = binding->insert_text_id[VIRTUAL];
+ }
+ else
+ {
+ doc = GTK_TEXT_BUFFER (binding->docs[REAL]);
+ id = binding->insert_text_id[REAL];
+ }
+
+ line = gtk_text_iter_get_line (location);
+ line_offset = gtk_text_iter_get_line_offset (location);
+
+ gtk_text_buffer_get_iter_at_line_index (doc,
+ &iter,
+ line,
+ line_offset);
+
+ g_signal_handler_block (doc, id);
+ gtk_text_buffer_insert (doc, &iter, text, len);
+ g_signal_handler_unblock (doc, id);
+}
+
+static void
+delete_range_on_virtual_doc_cb (GtkTextBuffer *textbuffer,
+ GtkTextIter *start,
+ GtkTextIter *end,
+ gpointer user_data)
+{
+ Binding *binding = (Binding *)user_data;
+ GtkTextBuffer *doc;
+ GtkTextIter start_iter, end_iter;
+ gint line;
+ gint line_offset;
+ gulong id;
+
+ if (textbuffer == GTK_TEXT_BUFFER (binding->docs[REAL]))
+ {
+ doc = GTK_TEXT_BUFFER (binding->docs[VIRTUAL]);
+ id = binding->delete_range_id[VIRTUAL];
+ }
+ else
+ {
+ doc = GTK_TEXT_BUFFER (binding->docs[REAL]);
+ id = binding->delete_range_id[REAL];
+ }
+
+ line = gtk_text_iter_get_line (start);
+ line_offset = gtk_text_iter_get_line_offset (start);
+
+ gtk_text_buffer_get_iter_at_line_index (doc,
+ &start_iter,
+ line,
+ line_offset);
+
+ line = gtk_text_iter_get_line (end);
+ line_offset = gtk_text_iter_get_line_offset (end);
+
+ gtk_text_buffer_get_iter_at_line_index (doc,
+ &end_iter,
+ line,
+ line_offset);
+
+ g_signal_handler_block (doc, id);
+ gtk_text_buffer_delete (doc, &start_iter, &end_iter);
+ g_signal_handler_unblock (doc, id);
+}
+
+static void
+bind (Binding *binding,
+ gboolean loaded)
+{
+ binding->insert_text_id[REAL] =
+ g_signal_connect (binding->docs[REAL], "insert-text",
+ G_CALLBACK (insert_text_on_virtual_doc_cb),
+ binding);
+
+ binding->delete_range_id[REAL] =
+ g_signal_connect (binding->docs[REAL], "delete-range",
+ G_CALLBACK (delete_range_on_virtual_doc_cb),
+ binding);
+
+ if (loaded)
+ {
+ binding->insert_text_id[VIRTUAL] =
+ g_signal_connect (binding->docs[VIRTUAL], "insert-text",
+ G_CALLBACK (insert_text_on_virtual_doc_cb),
+ binding);
+
+ binding->delete_range_id[VIRTUAL] =
+ g_signal_connect (binding->docs[VIRTUAL], "delete-range",
+ G_CALLBACK (delete_range_on_virtual_doc_cb),
+ binding);
+ }
+
+ /* Bind all properties */
+ binding->bindings[AUTO_INDENT] =
+ gedit_data_binding_new_mutual (binding->views[REAL], "auto-indent",
+ binding->views[VIRTUAL], "auto-indent");
+ binding->bindings[DRAW_SPACES] =
+ gedit_data_binding_new_mutual (binding->views[REAL], "draw-spaces",
+ binding->views[VIRTUAL], "draw-spaces");
+ binding->bindings[HIGHLIGHT_CURRENT_LINE] =
+ gedit_data_binding_new_mutual (binding->views[REAL], "highlight-current-line",
+ binding->views[VIRTUAL], "highlight-current-line");
+ binding->bindings[INDENT_ON_TAB] =
+ gedit_data_binding_new_mutual (binding->views[REAL], "indent-on-tab",
+ binding->views[VIRTUAL], "indent-on-tab");
+ binding->bindings[INDENT_WIDTH] =
+ gedit_data_binding_new_mutual (binding->views[REAL], "indent-width",
+ binding->views[VIRTUAL], "indent-width");
+ binding->bindings[INSERT_SPACES_INSTEAD_OF_TABS] =
+ gedit_data_binding_new_mutual (binding->views[REAL], "insert-spaces-instead-of-tabs",
+ binding->views[VIRTUAL], "insert-spaces-instead-of-tabs");
+ binding->bindings[RIGHT_MARGIN_POSITION] =
+ gedit_data_binding_new_mutual (binding->views[REAL], "right-margin-position",
+ binding->views[VIRTUAL], "right-margin-position");
+ binding->bindings[SHOW_LINE_MARKS] =
+ gedit_data_binding_new_mutual (binding->views[REAL], "show-line-marks",
+ binding->views[VIRTUAL], "show-line-marks");
+ binding->bindings[SHOW_LINE_NUMBERS] =
+ gedit_data_binding_new_mutual (binding->views[REAL], "show-line-numbers",
+ binding->views[VIRTUAL], "show-line-numbers");
+ binding->bindings[SHOW_RIGHT_MARGIN] =
+ gedit_data_binding_new_mutual (binding->views[REAL], "show-right-margin",
+ binding->views[VIRTUAL], "show-right-margin");
+ binding->bindings[SMART_HOME_END] =
+ gedit_data_binding_new_mutual (binding->views[REAL], "smart-home-end",
+ binding->views[VIRTUAL], "smart-home-end");
+ binding->bindings[TAB_WIDTH] =
+ gedit_data_binding_new_mutual (binding->views[REAL], "tab-width",
+ binding->views[VIRTUAL], "tab-width");
+
+ binding->bindings[HIGHLIGHT_MATCHING_BRACKETS] =
+ gedit_data_binding_new_mutual (binding->docs[REAL], "highlight-matching-brackets",
+ binding->docs[VIRTUAL], "highlight-matching-brackets");
+ binding->bindings[HIGHLIGHT_SYNTAX] =
+ gedit_data_binding_new_mutual (binding->docs[REAL], "highlight-syntax",
+ binding->docs[VIRTUAL], "highlight-syntax");
+ binding->bindings[LANGUAGE] =
+ gedit_data_binding_new_mutual (binding->docs[REAL], "language",
+ binding->docs[VIRTUAL], "language");
+ binding->bindings[MAX_UNDO_LEVELS] =
+ gedit_data_binding_new_mutual (binding->docs[REAL], "max-undo-levels",
+ binding->docs[VIRTUAL], "max-undo-levels");
+ binding->bindings[STYLE_SCHEME] =
+ gedit_data_binding_new_mutual (binding->docs[REAL], "style-scheme",
+ binding->docs[VIRTUAL], "style-scheme");
+}
+
+static void
+on_container_destroy (GeditViewContainer *container,
+ GeditPage *page)
+{
+ DestroyData *destroy_data;
+ Binding *binding;
+ VirtualDocument *vdoc;
+ GList *l, *aux_bind = NULL;
+
+ destroy_data = g_object_get_data (G_OBJECT (container), DESTROY_DATA_KEY);
+
+ if (destroy_data == NULL)
+ return;
+
+ vdoc = destroy_data->vdoc;
+
+ binding = get_binding_from_view (destroy_data);
+
+ /* FIXME: There are appends inside loops */
+ while (binding != NULL)
+ {
+ aux_bind = g_list_append (aux_bind, binding);
+
+ vdoc->bindings = g_list_remove (vdoc->bindings, binding);
+
+ unbind (binding);
+
+ binding = get_binding_from_view (destroy_data);
+ }
+
+ for (l = aux_bind; l != NULL; l = g_list_next (l))
+ {
+ binding = (Binding *)l->data;
+
+ if (l->next != NULL)
+ {
+ Binding *b = (Binding *)l->next->data;
+ Binding *b2;
+ gint i, j;
+
+ /* We need the opposite */
+ if (destroy_data->view == b->views[REAL])
+ i = VIRTUAL;
+ else
+ i = REAL;
+ if (destroy_data->view == binding->views[REAL])
+ j = VIRTUAL;
+ else
+ j = REAL;
+
+ b2 = g_slice_new (Binding);
+ b2->views[REAL] = b->views[i];
+ b2->views[VIRTUAL] = binding->views[j];
+ b2->docs[REAL] = b->docs[i];
+ b2->docs[VIRTUAL] = binding->docs[j];
+
+ bind (b2, TRUE);
+
+ vdoc->bindings = g_list_append (vdoc->bindings, b2);
+ }
+
+ g_slice_free (Binding, binding);
+ }
+
+ g_signal_emit (G_OBJECT (page),
+ signals[CONTAINER_REMOVED],
+ 0,
+ container);
+}
+
+static void
+on_grab_focus (GeditView *view,
+ GeditPage *page)
+{
+ GeditViewContainer *container;
+
+ container = gedit_view_container_get_from_view (view);
+
+ if (page->priv->active_container == container)
+ return;
+
+ page->priv->active_container = container;
+
+ g_signal_emit (G_OBJECT (page),
+ signals[ACTIVE_CONTAINER_CHANGED],
+ 0,
+ container);
+}
+
+static void
+add_container (GeditPage *page,
+ GtkWidget *container,
+ gboolean main_container,
+ gboolean horizontal)
+{
+ GList *views, *l;
+
+ if (main_container)
+ {
+ gtk_box_pack_start (GTK_BOX (page), GTK_WIDGET (container),
+ TRUE, TRUE, 0);
+ }
+ else
+ {
+ GtkWidget *active_container = GTK_WIDGET (page->priv->active_container);
+ GtkWidget *paned;
+ GtkWidget *parent;
+
+ if (horizontal)
+ paned = gtk_hpaned_new ();
+ else
+ paned = gtk_vpaned_new ();
+
+ gtk_widget_show (paned);
+
+ /* First we remove the active container from its parent to make
+ this we add a ref to it*/
+ g_object_ref (active_container);
+ parent = gtk_widget_get_parent (active_container);
+
+ gtk_container_remove (GTK_CONTAINER (parent), active_container);
+ gtk_container_add (GTK_CONTAINER (parent), paned);
+
+ gtk_paned_pack1 (GTK_PANED (paned), active_container, FALSE, TRUE);
+ g_object_unref (active_container);
+
+ gtk_paned_pack2 (GTK_PANED (paned), container, FALSE, TRUE);
+ }
+
+ views = gedit_view_container_get_views (GEDIT_VIEW_CONTAINER (container));
+ for (l = views; l != NULL; l = g_list_next (l))
+ {
+ g_signal_connect (l->data,
+ "grab-focus",
+ G_CALLBACK (on_grab_focus),
+ page);
+ }
+
+ page->priv->containers = g_list_append (page->priv->containers, container);
+
+ g_signal_emit (G_OBJECT (page),
+ signals[CONTAINER_ADDED],
+ 0,
+ container);
+}
+
+static void
+remove_container (GeditPage *page,
+ GtkWidget *container)
+{
+ GtkWidget *parent;
+ GtkWidget *grandpa;
+ GList *children;
+
+ parent = gtk_widget_get_parent (container);
+ if (GEDIT_IS_PAGE (parent))
+ {
+ g_warning ("We can't have an empty page");
+ return;
+ }
+
+ /* Now we destroy the widget, we get the children of parent and we destroy
+ parent too as the parent is an useless paned. Finally we add the child
+ into the grand parent */
+ g_object_ref (container);
+ gtk_widget_destroy (container);
+
+ children = gtk_container_get_children (GTK_CONTAINER (parent));
+ if (g_list_length (children) > 1)
+ {
+ g_warning ("The parent is not a paned");
+ return;
+ }
+ grandpa = gtk_widget_get_parent (parent);
+
+ g_object_ref (children->data);
+ gtk_container_remove (GTK_CONTAINER (parent),
+ GTK_WIDGET (children->data));
+ gtk_widget_destroy (parent);
+ gtk_container_add (GTK_CONTAINER (grandpa),
+ GTK_WIDGET (children->data));
+ g_object_unref (children->data);
+
+ if (page->priv->active_container == GEDIT_VIEW_CONTAINER (container))
+ {
+ _gedit_page_switch_between_splits (page);
+ page->priv->containers = g_list_remove (page->priv->containers,
+ container);
+ }
+
+ g_list_free (children);
+ g_object_unref (container);
+}
+
+static void
+on_virtual_document_loaded_cb (GeditDocument *document,
+ const GError *error,
+ gpointer user_data)
+{
+ Binding *binding = (Binding *)user_data;
+
+ binding->insert_text_id[VIRTUAL] =
+ g_signal_connect (document, "insert-text",
+ G_CALLBACK (insert_text_on_virtual_doc_cb),
+ binding);
+
+ binding->delete_range_id[VIRTUAL] =
+ g_signal_connect (document, "delete-range",
+ G_CALLBACK (delete_range_on_virtual_doc_cb),
+ binding);
+}
+
+static void
+split_page (GeditPage *page,
+ gboolean horizontally)
+{
+ DestroyData *destroy_data;
+ VirtualDocument *vdoc;
+ Binding *binding;
+ GtkWidget *container;
+ GeditView *view;
+ gchar *uri;
+
+ g_return_if_fail (GEDIT_IS_PAGE (page));
+
+ view = gedit_view_container_get_view (page->priv->active_container);
+
+ g_return_if_fail (GEDIT_IS_TEXT_VIEW (view));
+
+ container = _gedit_view_container_new ();
+ gtk_widget_show (container);
+ add_container (page, container, FALSE, horizontally);
+
+ vdoc = g_object_get_data (G_OBJECT (page->priv->active_container),
+ VIRTUAL_DOCUMENT_KEY);
+
+ if (vdoc == NULL)
+ {
+ vdoc = g_slice_new (VirtualDocument);
+ vdoc->bindings = NULL;
+
+ g_object_set_data (G_OBJECT (page->priv->active_container),
+ VIRTUAL_DOCUMENT_KEY,
+ vdoc);
+ }
+
+ g_object_set_data (G_OBJECT (container),
+ VIRTUAL_DOCUMENT_KEY,
+ vdoc);
+
+ destroy_data = g_object_get_data (G_OBJECT (page->priv->active_container),
+ DESTROY_DATA_KEY);
+
+ if (destroy_data == NULL)
+ {
+ destroy_data = g_slice_new (DestroyData);
+ destroy_data->vdoc = vdoc;
+ destroy_data->view = GTK_WIDGET (view);
+
+ g_object_set_data (G_OBJECT (page->priv->active_container),
+ DESTROY_DATA_KEY,
+ destroy_data);
+
+ g_signal_connect (page->priv->active_container,
+ "destroy",
+ G_CALLBACK (on_container_destroy),
+ page);
+ }
+
+ g_object_set_data (G_OBJECT (container),
+ DESTROY_DATA_KEY,
+ destroy_data);
+
+ g_signal_connect (container,
+ "destroy",
+ G_CALLBACK (on_container_destroy),
+ page);
+
+ binding = g_slice_new (Binding);
+ binding->views[REAL] = GTK_WIDGET (view);
+ binding->views[VIRTUAL] = GTK_WIDGET (gedit_view_container_get_view (GEDIT_VIEW_CONTAINER (container)));
+ binding->docs[REAL] = gedit_view_container_get_document (page->priv->active_container);
+ binding->docs[VIRTUAL] = gedit_view_container_get_document (GEDIT_VIEW_CONTAINER (container));
+
+ vdoc->bindings = g_list_append (vdoc->bindings, binding);
+
+ uri = gedit_document_get_uri (binding->docs[REAL]);
+ if (uri != NULL)
+ {
+ GtkTextMark *insert_mark;
+ GtkTextIter iter;
+
+ /* Load the document */
+ insert_mark = gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (binding->docs[REAL]));
+ gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (binding->docs[REAL]),
+ &iter, insert_mark);
+
+ gedit_document_load (binding->docs[VIRTUAL],
+ uri,
+ NULL,
+ gtk_text_iter_get_line (&iter) + 1,
+ FALSE);
+
+ g_signal_connect (binding->docs[VIRTUAL], "loaded",
+ G_CALLBACK (on_virtual_document_loaded_cb),
+ binding);
+
+ g_free (uri);
+
+ bind (binding, FALSE);
+ }
+ else
+ {
+ GtkTextIter start, end;
+ gchar *content;
+
+ gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (binding->docs[REAL]),
+ &start, &end);
+
+ content = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (binding->docs[REAL]),
+ &start, &end, FALSE);
+
+ gtk_text_buffer_set_text (GTK_TEXT_BUFFER (binding->docs[VIRTUAL]),
+ content, -1);
+
+ g_free (content);
+
+ bind (binding, TRUE);
+ }
+}
+
+static void
+gedit_page_finalize (GObject *object)
+{
+ GeditPage *page = GEDIT_PAGE (object);
+
+ g_list_free (page->priv->containers);
+
+ G_OBJECT_CLASS (gedit_page_parent_class)->finalize (object);
+}
+
+static void
+gedit_page_class_init (GeditPageClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = gedit_page_finalize;
+
+ signals[CONTAINER_ADDED] =
+ g_signal_new ("container-added",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (GeditPageClass, container_added),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE,
+ 1,
+ GEDIT_TYPE_VIEW_CONTAINER);
+
+ signals[CONTAINER_REMOVED] =
+ g_signal_new ("container-removed",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (GeditPageClass, container_removed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE,
+ 1,
+ GEDIT_TYPE_VIEW_CONTAINER);
+
+ signals[ACTIVE_CONTAINER_CHANGED] =
+ g_signal_new ("active-container-changed",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (GeditPageClass, active_container_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE,
+ 1,
+ GEDIT_TYPE_VIEW_CONTAINER);
+
+ g_type_class_add_private (object_class, sizeof (GeditPagePrivate));
+}
+
+static void
+gedit_page_init (GeditPage *page)
+{
+ page->priv = GEDIT_PAGE_GET_PRIVATE (page);
+}
+
+/**
+ * gedit_page_new:
+ * @container: a #GeditViewContainer or %NULL
+ *
+ * Creates a new #GeditPage. If @container is %NULL a new default
+ * #GeditViewContainer is created.
+ *
+ * Returns: a new #GeditPage object.
+ */
+GtkWidget *
+_gedit_page_new (GeditViewContainer *container)
+{
+ GeditPage *page;
+
+ page = g_object_new (GEDIT_TYPE_PAGE, NULL);
+
+ if (container == NULL)
+ {
+ container = GEDIT_VIEW_CONTAINER (_gedit_view_container_new ());
+ }
+
+ gtk_widget_show (GTK_WIDGET (container));
+ add_container (page, GTK_WIDGET (container), TRUE, FALSE);
+ page->priv->active_container = container;
+
+ return GTK_WIDGET (page);
+}
+
+GeditViewContainer *
+gedit_page_get_active_view_container (GeditPage *page)
+{
+ g_return_val_if_fail (GEDIT_IS_PAGE (page), NULL);
+
+ return page->priv->active_container;
+}
+
+GList *
+gedit_page_get_view_containers (GeditPage *page)
+{
+ g_return_val_if_fail (GEDIT_IS_PAGE (page), NULL);
+
+ return page->priv->containers;
+}
+
+GeditPage *
+gedit_page_get_from_container (GeditViewContainer *container)
+{
+ GtkWidget *parent;
+
+ g_return_val_if_fail (GEDIT_IS_VIEW_CONTAINER (container), NULL);
+
+ parent = gtk_widget_get_parent (GTK_WIDGET (container));
+
+ /* We are going to have X paned widgets and then the page */
+ while (!GTK_IS_VBOX (parent))
+ {
+ parent = gtk_widget_get_parent (parent);
+ }
+
+ return GEDIT_PAGE (parent);
+}
+
+void
+_gedit_page_switch_between_splits (GeditPage *page)
+{
+ GeditView *view;
+ GList *active;
+
+ active = g_list_find (page->priv->containers,
+ page->priv->active_container);
+
+ if (active->next)
+ active = active->next;
+ else
+ active = g_list_first (active);
+
+ /* Maybe there are no more views in the page */
+ if (active == NULL)
+ return;
+
+ view = gedit_view_container_get_view (GEDIT_VIEW_CONTAINER (active->data));
+ gtk_widget_grab_focus (GTK_WIDGET (view));
+}
+
+void
+_gedit_page_unsplit (GeditPage *page)
+{
+ remove_container (page, GTK_WIDGET (page->priv->active_container));
+}
+
+gboolean
+_gedit_page_can_unsplit (GeditPage *page)
+{
+ GtkWidget *parent;
+
+ g_return_val_if_fail (GEDIT_IS_PAGE (page), FALSE);
+
+ parent = gtk_widget_get_parent (GTK_WIDGET (page->priv->active_container));
+
+ if (parent == GTK_WIDGET (page))
+ return FALSE;
+
+ return TRUE;
+}
+
+gboolean
+_gedit_page_can_split (GeditPage *page)
+{
+ GeditView *view;
+
+ g_return_val_if_fail (GEDIT_IS_PAGE (page), FALSE);
+
+ view = gedit_view_container_get_view (page->priv->active_container);
+
+ if (GEDIT_IS_TEXT_VIEW (view))
+ return TRUE;
+
+ return FALSE;
+}
+
+void
+_gedit_page_split_horizontally (GeditPage *page)
+{
+ split_page (page, TRUE);
+}
+
+void
+_gedit_page_split_vertically (GeditPage *page)
+{
+ split_page (page, FALSE);
+}
diff --git a/gedit/gedit-page.h b/gedit/gedit-page.h
new file mode 100644
index 0000000..9b7d576
--- /dev/null
+++ b/gedit/gedit-page.h
@@ -0,0 +1,88 @@
+/*
+ * gedit-page.h
+ * This file is part of gedit
+ *
+ * Copyright (C) 2009 - Ignacio Casal Quinteiro
+ *
+ * gedit 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.
+ *
+ * gedit 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 gedit; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+
+#ifndef __GEDIT_PAGE_H__
+#define __GEDIT_PAGE_H__
+
+#include <gtk/gtk.h>
+#include <gedit/gedit-view-container.h>
+
+G_BEGIN_DECLS
+
+#define GEDIT_TYPE_PAGE (gedit_page_get_type ())
+#define GEDIT_PAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_PAGE, GeditPage))
+#define GEDIT_PAGE_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_PAGE, GeditPage const))
+#define GEDIT_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEDIT_TYPE_PAGE, GeditPageClass))
+#define GEDIT_IS_PAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEDIT_TYPE_PAGE))
+#define GEDIT_IS_PAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEDIT_TYPE_PAGE))
+#define GEDIT_PAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEDIT_TYPE_PAGE, GeditPageClass))
+
+typedef struct _GeditPage GeditPage;
+typedef struct _GeditPageClass GeditPageClass;
+typedef struct _GeditPagePrivate GeditPagePrivate;
+
+struct _GeditPage
+{
+ GtkVBox parent;
+
+ GeditPagePrivate *priv;
+};
+
+struct _GeditPageClass
+{
+ GtkVBoxClass parent_class;
+
+ void (*container_added) (GeditPage *page,
+ GeditViewContainer *container);
+ void (*container_removed) (GeditPage *page,
+ GeditViewContainer *container);
+ void (*active_container_changed)
+ (GeditPage *page,
+ GeditViewContainer *container);
+};
+
+GType gedit_page_get_type (void) G_GNUC_CONST;
+
+GtkWidget *_gedit_page_new (GeditViewContainer *container);
+
+GeditViewContainer *gedit_page_get_active_view_container (GeditPage *page);
+
+GList *gedit_page_get_view_containers (GeditPage *page);
+
+GeditPage *gedit_page_get_from_container (GeditViewContainer *container);
+
+void _gedit_page_switch_between_splits (GeditPage *page);
+
+void _gedit_page_unsplit (GeditPage *page);
+
+gboolean _gedit_page_can_unsplit (GeditPage *page);
+
+gboolean _gedit_page_can_split (GeditPage *page);
+
+void _gedit_page_split_horizontally (GeditPage *page);
+
+void _gedit_page_split_vertically (GeditPage *page);
+
+G_END_DECLS
+
+#endif /* __GEDIT_PAGE_H__ */
diff --git a/gedit/gedit-prefs-manager-app.c b/gedit/gedit-prefs-manager-app.c
index 802cd8a..de4820a 100644
--- a/gedit/gedit-prefs-manager-app.c
+++ b/gedit/gedit-prefs-manager-app.c
@@ -40,12 +40,13 @@
#include "gedit-prefs-manager-app.h"
#include "gedit-app.h"
#include "gedit-debug.h"
-#include "gedit-view.h"
+#include "gedit-view-interface.h"
#include "gedit-window.h"
#include "gedit-window-private.h"
#include "gedit-plugins-engine.h"
#include "gedit-style-scheme-manager.h"
#include "gedit-dirs.h"
+#include "gedit-text-buffer.h"
static void gedit_prefs_manager_editor_font_changed (GConfClient *client,
guint cnxn_id,
@@ -800,7 +801,9 @@ gedit_prefs_manager_editor_font_changed (GConfClient *client,
{
/* Note: we use def=FALSE to avoid GeditView to query gconf */
gedit_view_set_font (GEDIT_VIEW (l->data), FALSE, font);
- gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (l->data), ts);
+
+ if (GTK_IS_SOURCE_VIEW (l->data))
+ gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (l->data), ts);
l = l->next;
}
@@ -846,7 +849,8 @@ gedit_prefs_manager_system_font_changed (GConfClient *client,
/* Note: we use def=FALSE to avoid GeditView to query gconf */
gedit_view_set_font (GEDIT_VIEW (l->data), FALSE, font);
- gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (l->data), ts);
+ if (GTK_IS_SOURCE_VIEW (l->data))
+ gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (l->data), ts);
l = l->next;
}
@@ -883,8 +887,9 @@ gedit_prefs_manager_tabs_size_changed (GConfClient *client,
while (l != NULL)
{
- gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (l->data),
- tab_width);
+ if (GTK_IS_SOURCE_VIEW (l->data))
+ gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (l->data),
+ tab_width);
l = l->next;
}
@@ -907,9 +912,10 @@ gedit_prefs_manager_tabs_size_changed (GConfClient *client,
while (l != NULL)
{
- gtk_source_view_set_insert_spaces_instead_of_tabs (
- GTK_SOURCE_VIEW (l->data),
- enable);
+ if (GTK_IS_SOURCE_VIEW (l->data))
+ gtk_source_view_set_insert_spaces_instead_of_tabs (
+ GTK_SOURCE_VIEW (l->data),
+ enable);
l = l->next;
}
@@ -964,7 +970,7 @@ gedit_prefs_manager_wrap_mode_changed (GConfClient *client,
views = gedit_app_get_views (gedit_app_get_default ());
l = views;
- while (l != NULL)
+ while (l != NULL && GTK_IS_TEXT_VIEW (l->data))
{
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (l->data),
wrap_mode);
@@ -1003,8 +1009,9 @@ gedit_prefs_manager_line_numbers_changed (GConfClient *client,
while (l != NULL)
{
- gtk_source_view_set_show_line_numbers (GTK_SOURCE_VIEW (l->data),
- dln);
+ if (GTK_IS_SOURCE_VIEW (l->data))
+ gtk_source_view_set_show_line_numbers (GTK_SOURCE_VIEW (l->data),
+ dln);
l = l->next;
}
@@ -1040,8 +1047,9 @@ gedit_prefs_manager_hl_current_line_changed (GConfClient *client,
while (l != NULL)
{
- gtk_source_view_set_highlight_current_line (GTK_SOURCE_VIEW (l->data),
- hl);
+ if (GTK_IS_SOURCE_VIEW (l->data))
+ gtk_source_view_set_highlight_current_line (GTK_SOURCE_VIEW (l->data),
+ hl);
l = l->next;
}
@@ -1077,8 +1085,9 @@ gedit_prefs_manager_bracket_matching_changed (GConfClient *client,
while (l != NULL)
{
- gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (l->data),
- enable);
+ if (GTK_IS_SOURCE_VIEW (l->data))
+ gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (l->data),
+ enable);
l = l->next;
}
@@ -1113,9 +1122,10 @@ gedit_prefs_manager_auto_indent_changed (GConfClient *client,
l = views;
while (l != NULL)
- {
- gtk_source_view_set_auto_indent (GTK_SOURCE_VIEW (l->data),
- enable);
+ {
+ if (GTK_IS_SOURCE_VIEW (l->data))
+ gtk_source_view_set_auto_indent (GTK_SOURCE_VIEW (l->data),
+ enable);
l = l->next;
}
@@ -1153,8 +1163,9 @@ gedit_prefs_manager_undo_changed (GConfClient *client,
while (l != NULL)
{
- gtk_source_buffer_set_max_undo_levels (GTK_SOURCE_BUFFER (l->data),
- ul);
+ if (GTK_IS_SOURCE_BUFFER (l->data))
+ gtk_source_buffer_set_max_undo_levels (GTK_SOURCE_BUFFER (l->data),
+ ul);
l = l->next;
}
@@ -1192,8 +1203,9 @@ gedit_prefs_manager_right_margin_changed (GConfClient *client,
while (l != NULL)
{
- gtk_source_view_set_right_margin_position (GTK_SOURCE_VIEW (l->data),
- pos);
+ if (GTK_IS_SOURCE_VIEW (l->data))
+ gtk_source_view_set_right_margin_position (GTK_SOURCE_VIEW (l->data),
+ pos);
l = l->next;
}
@@ -1216,8 +1228,9 @@ gedit_prefs_manager_right_margin_changed (GConfClient *client,
while (l != NULL)
{
- gtk_source_view_set_show_right_margin (GTK_SOURCE_VIEW (l->data),
- display);
+ if (GTK_IS_SOURCE_VIEW (l->data))
+ gtk_source_view_set_show_right_margin (GTK_SOURCE_VIEW (l->data),
+ display);
l = l->next;
}
@@ -1273,8 +1286,9 @@ gedit_prefs_manager_smart_home_end_changed (GConfClient *client,
while (l != NULL)
{
- gtk_source_view_set_smart_home_end (GTK_SOURCE_VIEW (l->data),
- smart_he);
+ if (GTK_IS_SOURCE_VIEW (l->data))
+ gtk_source_view_set_smart_home_end (GTK_SOURCE_VIEW (l->data),
+ smart_he);
l = l->next;
}
@@ -1311,10 +1325,9 @@ gedit_prefs_manager_syntax_hl_enable_changed (GConfClient *client,
while (l != NULL)
{
- g_return_if_fail (GTK_IS_SOURCE_BUFFER (l->data));
-
- gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (l->data),
- enable);
+ if (GTK_IS_SOURCE_BUFFER (l->data))
+ gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (l->data),
+ enable);
l = l->next;
}
@@ -1369,8 +1382,9 @@ gedit_prefs_manager_search_hl_enable_changed (GConfClient *client,
{
g_return_if_fail (GEDIT_IS_DOCUMENT (l->data));
- gedit_document_set_enable_search_highlighting (GEDIT_DOCUMENT (l->data),
- enable);
+ if (GEDIT_IS_TEXT_BUFFER (l->data))
+ gedit_text_buffer_set_enable_search_highlighting (GEDIT_TEXT_BUFFER (l->data),
+ enable);
l = l->next;
}
@@ -1431,10 +1445,11 @@ gedit_prefs_manager_source_style_scheme_changed (GConfClient *client,
docs = gedit_app_get_documents (gedit_app_get_default ());
for (l = docs; l != NULL; l = l->next)
{
- g_return_if_fail (GTK_IS_SOURCE_BUFFER (l->data));
-
- gtk_source_buffer_set_style_scheme (GTK_SOURCE_BUFFER (l->data),
- style);
+ if (GTK_IS_SOURCE_BUFFER (l->data))
+ {
+ gtk_source_buffer_set_style_scheme (GTK_SOURCE_BUFFER (l->data),
+ style);
+ }
}
g_list_free (docs);
@@ -1512,9 +1527,9 @@ gedit_prefs_manager_auto_save_changed (GConfClient *client,
while (l != NULL)
{
GeditDocument *doc = GEDIT_DOCUMENT (l->data);
- GeditTab *tab = gedit_tab_get_from_document (doc);
+ GeditViewContainer *tab = gedit_view_container_get_from_document (doc);
- gedit_tab_set_auto_save_enabled (tab, auto_save);
+ gedit_view_container_set_auto_save_enabled (tab, auto_save);
l = l->next;
}
@@ -1541,9 +1556,9 @@ gedit_prefs_manager_auto_save_changed (GConfClient *client,
while (l != NULL)
{
GeditDocument *doc = GEDIT_DOCUMENT (l->data);
- GeditTab *tab = gedit_tab_get_from_document (doc);
+ GeditViewContainer *tab = gedit_view_container_get_from_document (doc);
- gedit_tab_set_auto_save_interval (tab, auto_save_interval);
+ gedit_view_container_set_auto_save_interval (tab, auto_save_interval);
l = l->next;
}
diff --git a/gedit/gedit-print-job.h b/gedit/gedit-print-job.h
index 956dc73..3ec3415 100644
--- a/gedit/gedit-print-job.h
+++ b/gedit/gedit-print-job.h
@@ -33,7 +33,7 @@
#define __GEDIT_PRINT_JOB_H__
#include <gtk/gtk.h>
-#include <gedit/gedit-view.h>
+#include <gedit/gedit-view-interface.h>
G_BEGIN_DECLS
diff --git a/gedit/gedit-session.c b/gedit/gedit-session.c
index 7468664..bd4f629 100644
--- a/gedit/gedit-session.c
+++ b/gedit/gedit-session.c
@@ -283,15 +283,18 @@ show_confirmation_dialog (GeditWindow *window)
if (unsaved_docs->next == NULL)
{
/* There is only one unsaved document */
- GeditTab *tab;
+ GeditPage *page;
+ GeditViewContainer *container;
GeditDocument *doc;
doc = GEDIT_DOCUMENT (unsaved_docs->data);
- tab = gedit_tab_get_from_document (doc);
- g_return_if_fail (tab != NULL);
+ container = gedit_view_container_get_from_document (doc);
+ g_return_if_fail (container != NULL);
- gedit_window_set_active_tab (window, tab);
+ page = gedit_page_get_from_container (container);
+
+ gedit_window_set_active_page (window, page);
dlg = gedit_close_confirmation_dialog_new_single (
GTK_WINDOW (window),
@@ -550,12 +553,12 @@ parse_window (GKeyFile *state_file, const char *group_name)
"URI: %s (%s)",
documents[i],
jump_to ? "active" : "not active");
- gedit_window_create_tab_from_uri (window,
- documents[i],
- NULL,
- 0,
- FALSE,
- jump_to);
+ gedit_window_create_page_from_uri (window,
+ documents[i],
+ NULL,
+ 0,
+ FALSE,
+ jump_to);
}
g_strfreev (documents);
}
diff --git a/gedit/gedit-document.c b/gedit/gedit-text-buffer.c
similarity index 65%
rename from gedit/gedit-document.c
rename to gedit/gedit-text-buffer.c
index aafb422..75f574e 100644
--- a/gedit/gedit-document.c
+++ b/gedit/gedit-text-buffer.c
@@ -41,7 +41,8 @@
#include <gtksourceview/gtksourceiter.h>
#include "gedit-prefs-manager-app.h"
-#include "gedit-document.h"
+#include "gedit-document-interface.h"
+#include "gedit-text-buffer.h"
#include "gedit-debug.h"
#include "gedit-utils.h"
#include "gedit-metadata-manager.h"
@@ -71,35 +72,37 @@ PROFILE (static GTimer *timer = NULL)
#define GEDIT_MAX_PATH_LEN 2048
#endif
-#define GEDIT_DOCUMENT_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), GEDIT_TYPE_DOCUMENT, GeditDocumentPrivate))
+#define GEDIT_TEXT_BUFFER_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), GEDIT_TYPE_TEXT_BUFFER, GeditTextBufferPrivate))
-static void gedit_document_load_real (GeditDocument *doc,
+static void gedit_text_buffer_load_real (GeditDocument *doc,
const gchar *uri,
const GeditEncoding *encoding,
gint line_pos,
gboolean create);
-static void gedit_document_save_real (GeditDocument *doc,
+static void gedit_text_buffer_save_real (GeditDocument *doc,
const gchar *uri,
const GeditEncoding *encoding,
GeditDocumentSaveFlags flags);
-static void gedit_document_set_readonly (GeditDocument *doc,
+static void gedit_text_buffer_set_readonly (GeditTextBuffer *doc,
gboolean readonly);
-static void to_search_region_range (GeditDocument *doc,
- GtkTextIter *start,
+static void to_search_region_range (GeditTextBuffer *doc,
+ GtkTextIter *start,
GtkTextIter *end);
-static void insert_text_cb (GeditDocument *doc,
- GtkTextIter *pos,
- const gchar *text,
+static void insert_text_cb (GeditTextBuffer *doc,
+ GtkTextIter *pos,
+ const gchar *text,
gint length);
-static void delete_range_cb (GeditDocument *doc,
- GtkTextIter *start,
- GtkTextIter *end);
+static void delete_range_cb (GeditTextBuffer *doc,
+ GtkTextIter *start,
+ GtkTextIter *end);
-struct _GeditDocumentPrivate
+static void gedit_text_buffer_iface_init (GeditDocumentIface *iface);
+
+struct _GeditTextBufferPrivate
{
gint readonly : 1;
- gint last_save_was_manually : 1;
+ gint last_save_was_manually : 1;
gint language_set_by_user : 1;
gint stop_cursor_moved_emission : 1;
gint dispose_has_run : 1;
@@ -129,13 +132,13 @@ struct _GeditDocumentPrivate
/* Saving stuff */
GeditDocumentSaver *saver;
- /* Search highlighting support variables */
+ /* Search highlighting support variables */
GeditTextRegion *to_search_region;
GtkTextTag *found_tag;
/* Mount operation factory */
- GeditMountOperationFactory mount_operation_factory;
- gpointer mount_operation_userdata;
+ /*GeditMountOperationFactory mount_operation_factory;
+ gpointer mount_operation_userdata;*/
};
enum {
@@ -144,7 +147,6 @@ enum {
PROP_URI,
PROP_SHORTNAME,
PROP_CONTENT_TYPE,
- PROP_MIME_TYPE,
PROP_READ_ONLY,
PROP_ENCODING,
PROP_CAN_SEARCH_AGAIN,
@@ -153,30 +155,17 @@ enum {
enum {
CURSOR_MOVED,
- LOAD,
- LOADING,
- LOADED,
- SAVE,
- SAVING,
- SAVED,
SEARCH_HIGHLIGHT_UPDATED,
LAST_SIGNAL
};
static guint document_signals[LAST_SIGNAL] = { 0 };
-G_DEFINE_TYPE(GeditDocument, gedit_document, GTK_TYPE_SOURCE_BUFFER)
-
-GQuark
-gedit_document_error_quark (void)
-{
- static GQuark quark = 0;
-
- if (G_UNLIKELY (quark == 0))
- quark = g_quark_from_static_string ("gedit_io_load_error");
-
- return quark;
-}
+G_DEFINE_TYPE_WITH_CODE (GeditTextBuffer,
+ gedit_text_buffer,
+ GTK_TYPE_SOURCE_BUFFER,
+ G_IMPLEMENT_INTERFACE (GEDIT_TYPE_DOCUMENT,
+ gedit_text_buffer_iface_init))
static GHashTable *allocated_untitled_numbers = NULL;
@@ -214,9 +203,9 @@ release_untitled_number (gint n)
}
static void
-gedit_document_dispose (GObject *object)
+gedit_text_buffer_dispose (GObject *object)
{
- GeditDocument *doc = GEDIT_DOCUMENT (object);
+ GeditTextBuffer *doc = GEDIT_TEXT_BUFFER (object);
gedit_debug (DEBUG_DOCUMENT);
@@ -230,7 +219,7 @@ gedit_document_dispose (GObject *object)
gchar *position;
gtk_text_buffer_get_iter_at_mark (
- GTK_TEXT_BUFFER (doc),
+ GTK_TEXT_BUFFER (doc),
&iter,
gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (doc)));
@@ -246,7 +235,7 @@ gedit_document_dispose (GObject *object)
{
GtkSourceLanguage *lang;
- lang = gedit_document_get_language (doc);
+ lang = gedit_text_buffer_get_language (doc);
gedit_metadata_manager_set (doc->priv->uri,
"language",
@@ -262,13 +251,13 @@ gedit_document_dispose (GObject *object)
doc->priv->dispose_has_run = TRUE;
- G_OBJECT_CLASS (gedit_document_parent_class)->dispose (object);
+ G_OBJECT_CLASS (gedit_text_buffer_parent_class)->dispose (object);
}
static void
-gedit_document_finalize (GObject *object)
+gedit_text_buffer_finalize (GObject *object)
{
- GeditDocument *doc = GEDIT_DOCUMENT (object);
+ GeditTextBuffer *doc = GEDIT_TEXT_BUFFER (object);
gedit_debug (DEBUG_DOCUMENT);
@@ -288,21 +277,22 @@ gedit_document_finalize (GObject *object)
gedit_text_region_destroy (doc->priv->to_search_region, FALSE);
}
- G_OBJECT_CLASS (gedit_document_parent_class)->finalize (object);
+ G_OBJECT_CLASS (gedit_text_buffer_parent_class)->finalize (object);
}
static void
-gedit_document_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+gedit_text_buffer_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
+ GeditTextBuffer *buf = GEDIT_TEXT_BUFFER (object);
GeditDocument *doc = GEDIT_DOCUMENT (object);
switch (prop_id)
{
case PROP_URI:
- g_value_set_string (value, doc->priv->uri);
+ g_value_set_string (value, buf->priv->uri);
break;
case PROP_SHORTNAME:
g_value_take_string (value, gedit_document_get_short_name_for_display (doc));
@@ -310,20 +300,17 @@ gedit_document_get_property (GObject *object,
case PROP_CONTENT_TYPE:
g_value_take_string (value, gedit_document_get_content_type (doc));
break;
- case PROP_MIME_TYPE:
- g_value_take_string (value, gedit_document_get_mime_type (doc));
- break;
case PROP_READ_ONLY:
- g_value_set_boolean (value, doc->priv->readonly);
+ g_value_set_boolean (value, buf->priv->readonly);
break;
case PROP_ENCODING:
- g_value_set_boxed (value, doc->priv->encoding);
+ g_value_set_boxed (value, buf->priv->encoding);
break;
case PROP_CAN_SEARCH_AGAIN:
- g_value_set_boolean (value, gedit_document_get_can_search_again (doc));
+ g_value_set_boolean (value, gedit_text_buffer_get_can_search_again (buf));
break;
case PROP_ENABLE_SEARCH_HIGHLIGHTING:
- g_value_set_boolean (value, gedit_document_get_enable_search_highlighting (doc));
+ g_value_set_boolean (value, gedit_text_buffer_get_enable_search_highlighting (buf));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -332,18 +319,18 @@ gedit_document_get_property (GObject *object,
}
static void
-gedit_document_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+gedit_text_buffer_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- GeditDocument *doc = GEDIT_DOCUMENT (object);
+ GeditTextBuffer *doc = GEDIT_TEXT_BUFFER (object);
switch (prop_id)
{
case PROP_ENABLE_SEARCH_HIGHLIGHTING:
- gedit_document_set_enable_search_highlighting (doc,
- g_value_get_boolean (value));
+ gedit_text_buffer_set_enable_search_highlighting (doc,
+ g_value_get_boolean (value));
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -351,7 +338,7 @@ gedit_document_set_property (GObject *object,
}
static void
-emit_cursor_moved (GeditDocument *doc)
+emit_cursor_moved (GeditTextBuffer *doc)
{
if (!doc->priv->stop_cursor_moved_emission)
{
@@ -362,16 +349,16 @@ emit_cursor_moved (GeditDocument *doc)
}
static void
-gedit_document_mark_set (GtkTextBuffer *buffer,
- const GtkTextIter *iter,
- GtkTextMark *mark)
+gedit_text_buffer_mark_set (GtkTextBuffer *buffer,
+ const GtkTextIter *iter,
+ GtkTextMark *mark)
{
- GeditDocument *doc = GEDIT_DOCUMENT (buffer);
+ GeditTextBuffer *doc = GEDIT_TEXT_BUFFER (buffer);
- if (GTK_TEXT_BUFFER_CLASS (gedit_document_parent_class)->mark_set)
- GTK_TEXT_BUFFER_CLASS (gedit_document_parent_class)->mark_set (buffer,
- iter,
- mark);
+ if (GTK_TEXT_BUFFER_CLASS (gedit_text_buffer_parent_class)->mark_set)
+ GTK_TEXT_BUFFER_CLASS (gedit_text_buffer_parent_class)->mark_set (buffer,
+ iter,
+ mark);
if (mark == gtk_text_buffer_get_insert (buffer))
{
@@ -380,69 +367,42 @@ gedit_document_mark_set (GtkTextBuffer *buffer,
}
static void
-gedit_document_changed (GtkTextBuffer *buffer)
+gedit_text_buffer_changed (GtkTextBuffer *buffer)
{
- emit_cursor_moved (GEDIT_DOCUMENT (buffer));
+ emit_cursor_moved (GEDIT_TEXT_BUFFER (buffer));
- GTK_TEXT_BUFFER_CLASS (gedit_document_parent_class)->changed (buffer);
+ GTK_TEXT_BUFFER_CLASS (gedit_text_buffer_parent_class)->changed (buffer);
}
static void
-gedit_document_class_init (GeditDocumentClass *klass)
+gedit_text_buffer_class_init (GeditTextBufferClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkTextBufferClass *buf_class = GTK_TEXT_BUFFER_CLASS (klass);
- object_class->dispose = gedit_document_dispose;
- object_class->finalize = gedit_document_finalize;
- object_class->get_property = gedit_document_get_property;
- object_class->set_property = gedit_document_set_property;
-
- buf_class->mark_set = gedit_document_mark_set;
- buf_class->changed = gedit_document_changed;
-
- klass->load = gedit_document_load_real;
- klass->save = gedit_document_save_real;
-
- g_object_class_install_property (object_class, PROP_URI,
- g_param_spec_string ("uri",
- "URI",
- "The document's URI",
- NULL,
- G_PARAM_READABLE |
- G_PARAM_STATIC_STRINGS));
-
- g_object_class_install_property (object_class, PROP_SHORTNAME,
- g_param_spec_string ("shortname",
- "Short Name",
- "The document's short name",
- NULL,
- G_PARAM_READABLE |
- G_PARAM_STATIC_STRINGS));
-
- g_object_class_install_property (object_class, PROP_CONTENT_TYPE,
- g_param_spec_string ("content-type",
- "Content Type",
- "The document's Content Type",
- NULL,
- G_PARAM_READABLE |
- G_PARAM_STATIC_STRINGS));
-
- g_object_class_install_property (object_class, PROP_MIME_TYPE,
- g_param_spec_string ("mime-type",
- "MIME Type",
- "The document's MIME Type",
- "text/plain",
- G_PARAM_READABLE |
- G_PARAM_STATIC_STRINGS));
-
- g_object_class_install_property (object_class, PROP_READ_ONLY,
- g_param_spec_boolean ("read-only",
- "Read Only",
- "Whether the document is read only or not",
- FALSE,
- G_PARAM_READABLE |
- G_PARAM_STATIC_STRINGS));
+ object_class->dispose = gedit_text_buffer_dispose;
+ object_class->finalize = gedit_text_buffer_finalize;
+ object_class->get_property = gedit_text_buffer_get_property;
+ object_class->set_property = gedit_text_buffer_set_property;
+
+ buf_class->mark_set = gedit_text_buffer_mark_set;
+ buf_class->changed = gedit_text_buffer_changed;
+
+ g_object_class_override_property (object_class,
+ PROP_URI,
+ "uri");
+
+ g_object_class_override_property (object_class,
+ PROP_SHORTNAME,
+ "shortname");
+
+ g_object_class_override_property (object_class,
+ PROP_CONTENT_TYPE,
+ "content-type");
+
+ g_object_class_override_property (object_class,
+ PROP_READ_ONLY,
+ "read-only");
g_object_class_install_property (object_class, PROP_ENCODING,
g_param_spec_boxed ("encoding",
@@ -475,121 +435,20 @@ gedit_document_class_init (GeditDocumentClass *klass)
* improve performance.
*/
document_signals[CURSOR_MOVED] =
- g_signal_new ("cursor-moved",
+ g_signal_new ("cursor-moved",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GeditDocumentClass, cursor_moved),
+ G_STRUCT_OFFSET (GeditTextBufferClass, cursor_moved),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE,
0);
- /**
- * GeditDocument::load:
- * @document: the #GeditDocument.
- * @uri: the uri where to load the document from.
- * @encoding: the #GeditEncoding to encode the document.
- * @line_pos: the line to show.
- * @create: whether the document should be created if it doesn't exist.
- *
- * The "load" signal is emitted when a document is loaded.
- *
- * Since: 2.22
- */
- document_signals[LOAD] =
- g_signal_new ("load",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GeditDocumentClass, load),
- NULL, NULL,
- gedit_marshal_VOID__STRING_BOXED_INT_BOOLEAN,
- G_TYPE_NONE,
- 4,
- G_TYPE_STRING,
- /* we rely on the fact that the GeditEncoding pointer stays
- * the same forever */
- GEDIT_TYPE_ENCODING | G_SIGNAL_TYPE_STATIC_SCOPE,
- G_TYPE_INT,
- G_TYPE_BOOLEAN);
-
-
- document_signals[LOADING] =
- g_signal_new ("loading",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GeditDocumentClass, loading),
- NULL, NULL,
- gedit_marshal_VOID__UINT64_UINT64,
- G_TYPE_NONE,
- 2,
- G_TYPE_UINT64,
- G_TYPE_UINT64);
-
- document_signals[LOADED] =
- g_signal_new ("loaded",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GeditDocumentClass, loaded),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE,
- 1,
- G_TYPE_POINTER);
-
- /**
- * GeditDocument::save:
- * @document: the #GeditDocument.
- * @uri: the uri where the document is about to be saved.
- * @encoding: the #GeditEncoding used to save the document.
- * @flags: the #GeditDocumentSaveFlags for the save operation.
- *
- * The "save" signal is emitted when the document is saved.
- *
- * Since: 2.20
- */
- document_signals[SAVE] =
- g_signal_new ("save",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GeditDocumentClass, save),
- NULL, NULL,
- gedit_marshal_VOID__STRING_BOXED_FLAGS,
- G_TYPE_NONE,
- 3,
- G_TYPE_STRING,
- /* we rely on the fact that the GeditEncoding pointer stays
- * the same forever */
- GEDIT_TYPE_ENCODING | G_SIGNAL_TYPE_STATIC_SCOPE,
- GEDIT_TYPE_DOCUMENT_SAVE_FLAGS);
-
- document_signals[SAVING] =
- g_signal_new ("saving",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GeditDocumentClass, saving),
- NULL, NULL,
- gedit_marshal_VOID__UINT64_UINT64,
- G_TYPE_NONE,
- 2,
- G_TYPE_UINT64,
- G_TYPE_UINT64);
-
- document_signals[SAVED] =
- g_signal_new ("saved",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GeditDocumentClass, saved),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE,
- 1,
- G_TYPE_POINTER);
-
document_signals[SEARCH_HIGHLIGHT_UPDATED] =
- g_signal_new ("search_highlight_updated",
+ g_signal_new ("search_highlight_updated",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GeditDocumentClass, search_highlight_updated),
+ G_STRUCT_OFFSET (GeditTextBufferClass, search_highlight_updated),
NULL, NULL,
gedit_marshal_VOID__BOXED_BOXED,
G_TYPE_NONE,
@@ -597,11 +456,11 @@ gedit_document_class_init (GeditDocumentClass *klass)
GTK_TYPE_TEXT_ITER | G_SIGNAL_TYPE_STATIC_SCOPE,
GTK_TYPE_TEXT_ITER | G_SIGNAL_TYPE_STATIC_SCOPE);
- g_type_class_add_private (object_class, sizeof(GeditDocumentPrivate));
+ g_type_class_add_private (object_class, sizeof (GeditTextBufferPrivate));
}
static void
-set_language (GeditDocument *doc,
+set_language (GeditTextBuffer *doc,
GtkSourceLanguage *lang,
gboolean set_by_user)
{
@@ -633,124 +492,6 @@ set_language (GeditDocument *doc,
doc->priv->language_set_by_user = set_by_user;
}
-static void
-set_encoding (GeditDocument *doc,
- const GeditEncoding *encoding,
- gboolean set_by_user)
-{
- g_return_if_fail (encoding != NULL);
-
- gedit_debug (DEBUG_DOCUMENT);
-
- if (doc->priv->encoding == encoding)
- return;
-
- doc->priv->encoding = encoding;
-
- if (set_by_user)
- {
- const gchar *charset;
-
- charset = gedit_encoding_get_charset (encoding);
-
- gedit_metadata_manager_set (doc->priv->uri,
- "encoding",
- charset);
- }
-
- g_object_notify (G_OBJECT (doc), "encoding");
-}
-
-static GtkSourceStyleScheme *
-get_default_style_scheme (void)
-{
- gchar *scheme_id;
- GtkSourceStyleScheme *def_style;
- GtkSourceStyleSchemeManager *manager;
-
- manager = gedit_get_style_scheme_manager ();
- scheme_id = gedit_prefs_manager_get_source_style_scheme ();
- def_style = gtk_source_style_scheme_manager_get_scheme (manager,
- scheme_id);
-
- if (def_style == NULL)
- {
- g_warning ("Default style scheme '%s' cannot be found, falling back to 'classic' style scheme ", scheme_id);
-
- def_style = gtk_source_style_scheme_manager_get_scheme (manager, "classic");
- if (def_style == NULL)
- {
- g_warning ("Style scheme 'classic' cannot be found, check your GtkSourceView installation.");
- }
- }
-
- g_free (scheme_id);
-
- return def_style;
-}
-
-static void
-gedit_document_init (GeditDocument *doc)
-{
- GtkSourceStyleScheme *style_scheme;
-
- gedit_debug (DEBUG_DOCUMENT);
-
- doc->priv = GEDIT_DOCUMENT_GET_PRIVATE (doc);
-
- doc->priv->uri = NULL;
- doc->priv->untitled_number = get_untitled_number ();
-
- doc->priv->content_type = g_content_type_from_mime_type ("text/plain");
-
- doc->priv->readonly = FALSE;
-
- doc->priv->stop_cursor_moved_emission = FALSE;
-
- doc->priv->last_save_was_manually = TRUE;
- doc->priv->language_set_by_user = FALSE;
-
- doc->priv->dispose_has_run = FALSE;
-
- doc->priv->mtime = 0;
-
- g_get_current_time (&doc->priv->time_of_last_save_or_load);
-
- doc->priv->encoding = gedit_encoding_get_utf8 ();
-
- gtk_source_buffer_set_max_undo_levels (GTK_SOURCE_BUFFER (doc),
- gedit_prefs_manager_get_undo_actions_limit ());
-
- gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (doc),
- gedit_prefs_manager_get_bracket_matching ());
-
- gedit_document_set_enable_search_highlighting (doc,
- gedit_prefs_manager_get_enable_search_highlighting ());
-
- style_scheme = get_default_style_scheme ();
- if (style_scheme != NULL)
- gtk_source_buffer_set_style_scheme (GTK_SOURCE_BUFFER (doc),
- style_scheme);
-
- g_signal_connect_after (doc,
- "insert-text",
- G_CALLBACK (insert_text_cb),
- NULL);
-
- g_signal_connect_after (doc,
- "delete-range",
- G_CALLBACK (delete_range_cb),
- NULL);
-}
-
-GeditDocument *
-gedit_document_new (void)
-{
- gedit_debug (DEBUG_DOCUMENT);
-
- return GEDIT_DOCUMENT (g_object_new (GEDIT_TYPE_DOCUMENT, NULL));
-}
-
static GtkSourceLanguage *
guess_language (const gchar *uri,
const gchar *content_type)
@@ -799,9 +540,9 @@ guess_language (const gchar *uri,
/* If content type is null, we guess from the filename */
/* If uri is null, we only set the content-type */
static void
-set_uri (GeditDocument *doc,
- const gchar *uri,
- const gchar *content_type)
+set_uri (GeditTextBuffer *doc,
+ const gchar *uri,
+ const gchar *content_type)
{
gedit_debug (DEBUG_DOCUMENT);
@@ -856,131 +597,240 @@ set_uri (GeditDocument *doc,
g_object_notify (G_OBJECT (doc), "shortname");
}
-GFile *
-gedit_document_get_location (GeditDocument *doc)
+static GFile *
+gedit_text_buffer_get_location_impl (GeditDocument *doc)
{
- g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), NULL);
+ GeditTextBuffer *buf;
- return doc->priv->uri == NULL ? NULL : g_file_new_for_uri (doc->priv->uri);
+ g_return_val_if_fail (GEDIT_IS_TEXT_BUFFER (doc), NULL);
+
+ buf = GEDIT_TEXT_BUFFER (doc);
+
+ return buf->priv->uri == NULL ? NULL : g_file_new_for_uri (buf->priv->uri);
}
-gchar *
-gedit_document_get_uri (GeditDocument *doc)
+static gchar *
+gedit_text_buffer_get_uri_impl (GeditDocument *doc)
{
- g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), NULL);
+ GeditTextBuffer *buf = GEDIT_TEXT_BUFFER (doc);
- return g_strdup (doc->priv->uri);
+ return g_strdup (buf->priv->uri);
}
-void
-gedit_document_set_uri (GeditDocument *doc,
- const gchar *uri)
+static void
+gedit_text_buffer_set_uri_impl (GeditDocument *doc,
+ const gchar *uri)
{
- set_uri (doc, uri, doc->priv->content_type);
+ GeditTextBuffer *buf = GEDIT_TEXT_BUFFER (doc);
+
+ set_uri (buf, uri, buf->priv->content_type);
}
/* Never returns NULL */
-gchar *
-gedit_document_get_uri_for_display (GeditDocument *doc)
+static gchar *
+gedit_text_buffer_get_uri_for_display_impl (GeditDocument *doc)
{
- g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), g_strdup (""));
+ GeditTextBuffer *buf = GEDIT_TEXT_BUFFER (doc);
- if (doc->priv->uri == NULL)
+ if (buf->priv->uri == NULL)
return g_strdup_printf (_("Unsaved Document %d"),
- doc->priv->untitled_number);
+ buf->priv->untitled_number);
else
- return gedit_utils_uri_for_display (doc->priv->uri);
+ return gedit_utils_uri_for_display (buf->priv->uri);
}
/* Never returns NULL */
-gchar *
-gedit_document_get_short_name_for_display (GeditDocument *doc)
+static gchar *
+gedit_text_buffer_get_short_name_for_display_impl (GeditDocument *doc)
{
- g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), g_strdup (""));
+ GeditTextBuffer *buf = GEDIT_TEXT_BUFFER (doc);
- if (doc->priv->uri == NULL)
+ if (buf->priv->uri == NULL)
return g_strdup_printf (_("Unsaved Document %d"),
- doc->priv->untitled_number);
+ buf->priv->untitled_number);
else
- return gedit_utils_basename_for_display (doc->priv->uri);
+ return gedit_utils_basename_for_display (buf->priv->uri);
}
-gchar *
-gedit_document_get_content_type (GeditDocument *doc)
+static gchar *
+gedit_text_buffer_get_content_type_impl (GeditDocument *doc)
{
- g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), NULL);
+ GeditTextBuffer *buf = GEDIT_TEXT_BUFFER (doc);
- return g_strdup (doc->priv->content_type);
+ return g_strdup (buf->priv->content_type);
}
/* Never returns NULL */
-gchar *
-gedit_document_get_mime_type (GeditDocument *doc)
+static gchar *
+gedit_text_buffer_get_mime_type_impl (GeditDocument *doc)
{
+ GeditTextBuffer *buf = GEDIT_TEXT_BUFFER (doc);
gchar *mime_type = NULL;
- g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), g_strdup ("text/plain"));
-
- if ((doc->priv->content_type != NULL) &&
- (!g_content_type_is_unknown (doc->priv->content_type)))
+ if ((buf->priv->content_type != NULL) &&
+ (!g_content_type_is_unknown (buf->priv->content_type)))
{
- mime_type = g_content_type_get_mime_type (doc->priv->content_type);
+ mime_type = g_content_type_get_mime_type (buf->priv->content_type);
}
return mime_type != NULL ? mime_type : g_strdup ("text/plain");
}
-/* Note: do not emit the notify::read-only signal */
-static void
-set_readonly (GeditDocument *doc,
- gboolean readonly)
+static gboolean
+gedit_text_buffer_get_readonly_impl (GeditDocument *doc)
{
- gedit_debug (DEBUG_DOCUMENT);
-
- readonly = (readonly != FALSE);
+ GeditTextBuffer *buf = GEDIT_TEXT_BUFFER (doc);
- if (doc->priv->readonly == readonly)
- return;
+ return buf->priv->readonly;
+}
- doc->priv->readonly = readonly;
+static gboolean
+gedit_text_buffer_load_cancel_impl (GeditDocument *doc)
+{
+ GeditTextBuffer *buf = GEDIT_TEXT_BUFFER (doc);
+
+ if (buf->priv->loader == NULL)
+ return FALSE;
+
+ return gedit_document_loader_cancel (buf->priv->loader);
}
-static void
-gedit_document_set_readonly (GeditDocument *doc,
- gboolean readonly)
+static gboolean
+gedit_text_buffer_is_untouched_impl (GeditDocument *doc)
+{
+ GeditTextBuffer *buf = GEDIT_TEXT_BUFFER (doc);
+
+ return (buf->priv->uri == NULL) &&
+ (!gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (doc)));
+}
+
+static gboolean
+gedit_text_buffer_is_untitled_impl (GeditDocument *doc)
+{
+ GeditTextBuffer *buf = GEDIT_TEXT_BUFFER (doc);
+
+ return (buf->priv->uri == NULL);
+}
+
+static gboolean
+gedit_text_buffer_is_local_impl (GeditDocument *doc)
{
+ GeditTextBuffer *buf = GEDIT_TEXT_BUFFER (doc);
+
+ if (buf->priv->uri == NULL)
+ {
+ return FALSE;
+ }
+
+ return gedit_utils_uri_has_file_scheme (buf->priv->uri);
+}
+
+static gboolean
+gedit_text_buffer_get_deleted_impl (GeditDocument *doc)
+{
+ GeditTextBuffer *buf = GEDIT_TEXT_BUFFER (doc);
+
+ return buf->priv->uri && !gedit_utils_uri_exists (buf->priv->uri);
+}
+
+/*
+ * If @line is bigger than the lines of the document, the cursor is moved
+ * to the last line and FALSE is returned.
+ */
+static gboolean
+gedit_text_buffer_goto_line_impl (GeditDocument *doc,
+ gint line)
+{
+ gboolean ret = TRUE;
+ guint line_count;
+ GtkTextIter iter;
+
gedit_debug (DEBUG_DOCUMENT);
- g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
+ line_count = gtk_text_buffer_get_line_count (GTK_TEXT_BUFFER (doc));
- set_readonly (doc, readonly);
+ if (line >= line_count)
+ {
+ ret = FALSE;
+ gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (doc),
+ &iter);
+ }
+ else
+ {
+ gtk_text_buffer_get_iter_at_line (GTK_TEXT_BUFFER (doc),
+ &iter,
+ line);
+ }
- g_object_notify (G_OBJECT (doc), "read-only");
+ gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER (doc), &iter);
+
+ return ret;
}
-gboolean
-gedit_document_get_readonly (GeditDocument *doc)
+static gboolean
+gedit_text_buffer_goto_line_offset_impl (GeditDocument *doc,
+ gint line,
+ gint line_offset)
{
- g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), TRUE);
+ gboolean ret = TRUE;
+ guint offset_count;
+ GtkTextIter iter;
+
+ gtk_text_buffer_get_iter_at_line (GTK_TEXT_BUFFER (doc),
+ &iter,
+ line);
- return doc->priv->readonly;
+ offset_count = gtk_text_iter_get_chars_in_line (&iter);
+ if (line_offset > offset_count)
+ {
+ ret = FALSE;
+ }
+ else
+ {
+ gtk_text_iter_set_line_offset (&iter, line_offset);
+ }
+
+ gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER (doc), &iter);
+
+ return ret;
}
-gboolean
-_gedit_document_check_externally_modified (GeditDocument *doc)
+static const GeditEncoding *
+gedit_text_buffer_get_encoding_impl (GeditDocument *doc)
+{
+ GeditTextBuffer *buf = GEDIT_TEXT_BUFFER (doc);
+
+ return buf->priv->encoding;
+}
+
+static glong
+gedit_text_buffer_get_seconds_since_last_save_or_load_impl (GeditDocument *doc)
+{
+ GeditTextBuffer *buf = GEDIT_TEXT_BUFFER (doc);
+
+ GTimeVal current_time;
+
+ gedit_debug (DEBUG_DOCUMENT);
+
+ g_get_current_time (¤t_time);
+
+ return (current_time.tv_sec - buf->priv->time_of_last_save_or_load.tv_sec);
+}
+
+static gboolean
+gedit_text_buffer_check_externally_modified_impl (GeditDocument *doc)
{
+ GeditTextBuffer *buf = GEDIT_TEXT_BUFFER (doc);
GFile *gfile;
GFileInfo *info;
GTimeVal timeval;
- g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
-
- if (doc->priv->uri == NULL)
+ if (buf->priv->uri == NULL)
{
return FALSE;
}
- gfile = g_file_new_for_uri (doc->priv->uri);
+ gfile = g_file_new_for_uri (buf->priv->uri);
info = g_file_query_info (gfile,
G_FILE_ATTRIBUTE_TIME_MODIFIED,
G_FILE_QUERY_INFO_NONE,
@@ -996,11 +846,257 @@ _gedit_document_check_externally_modified (GeditDocument *doc)
g_file_info_get_modification_time (info, &timeval);
g_object_unref (info);
- return timeval.tv_sec > doc->priv->mtime;
+ return timeval.tv_sec > buf->priv->mtime;
+}
+
+static void
+gedit_text_buffer_undo_impl (GeditDocument *doc)
+{
+ gtk_source_buffer_undo (GTK_SOURCE_BUFFER (doc));
+}
+
+static void
+gedit_text_buffer_redo_impl (GeditDocument *doc)
+{
+ gtk_source_buffer_redo (GTK_SOURCE_BUFFER (doc));
+}
+
+static gboolean
+gedit_text_buffer_can_undo_impl (GeditDocument *doc)
+{
+ return gtk_source_buffer_can_undo (GTK_SOURCE_BUFFER (doc));
+}
+
+static gboolean
+gedit_text_buffer_can_redo_impl (GeditDocument *doc)
+{
+ return gtk_source_buffer_can_redo (GTK_SOURCE_BUFFER (doc));
+}
+
+static void
+gedit_text_buffer_begin_not_undoable_action_impl (GeditDocument *doc)
+{
+ gtk_source_buffer_begin_not_undoable_action (GTK_SOURCE_BUFFER (doc));
+}
+
+static void
+gedit_text_buffer_end_not_undoable_action_impl (GeditDocument *doc)
+{
+ gtk_source_buffer_end_not_undoable_action (GTK_SOURCE_BUFFER (doc));
+}
+
+static void
+gedit_text_buffer_set_text_impl (GeditDocument *doc,
+ const gchar *text,
+ gint len)
+{
+ gtk_text_buffer_set_text (GTK_TEXT_BUFFER (doc), text, len);
+}
+
+static void
+gedit_text_buffer_set_modified_impl (GeditDocument *doc,
+ gboolean setting)
+{
+ gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (doc), setting);
+}
+
+static gboolean
+gedit_text_buffer_get_modified_impl (GeditDocument *doc)
+{
+ return gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (doc));
+}
+
+static gboolean
+gedit_text_buffer_get_has_selection_impl (GeditDocument *doc)
+{
+ return gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER (doc));
+}
+
+static void
+gedit_text_buffer_iface_init (GeditDocumentIface *iface)
+{
+ iface->get_location = gedit_text_buffer_get_location_impl;
+ iface->get_uri = gedit_text_buffer_get_uri_impl;
+ iface->set_uri = gedit_text_buffer_set_uri_impl;
+ iface->get_uri_for_display = gedit_text_buffer_get_uri_for_display_impl;
+ iface->get_short_name_for_display = gedit_text_buffer_get_short_name_for_display_impl;
+ iface->get_content_type = gedit_text_buffer_get_content_type_impl;
+ iface->get_mime_type = gedit_text_buffer_get_mime_type_impl;
+ iface->get_readonly = gedit_text_buffer_get_readonly_impl;
+ iface->load_cancel = gedit_text_buffer_load_cancel_impl;
+ iface->is_untouched = gedit_text_buffer_is_untouched_impl;
+ iface->is_untitled = gedit_text_buffer_is_untitled_impl;
+ iface->is_local = gedit_text_buffer_is_local_impl;
+ iface->get_deleted = gedit_text_buffer_get_deleted_impl;
+ iface->goto_line = gedit_text_buffer_goto_line_impl;
+ iface->goto_line_offset = gedit_text_buffer_goto_line_offset_impl;
+ iface->get_encoding = gedit_text_buffer_get_encoding_impl;
+ iface->get_seconds_since_last_save_or_load = gedit_text_buffer_get_seconds_since_last_save_or_load_impl;
+ iface->check_externally_modified = gedit_text_buffer_check_externally_modified_impl;
+ iface->undo = gedit_text_buffer_undo_impl;
+ iface->redo = gedit_text_buffer_redo_impl;
+ iface->can_undo = gedit_text_buffer_can_undo_impl;
+ iface->can_redo = gedit_text_buffer_can_redo_impl;
+ iface->begin_not_undoable_action = gedit_text_buffer_begin_not_undoable_action_impl;
+ iface->end_not_undoable_action = gedit_text_buffer_end_not_undoable_action_impl;
+ iface->set_text = gedit_text_buffer_set_text_impl;
+ iface->set_modified = gedit_text_buffer_set_modified_impl;
+ iface->get_modified = gedit_text_buffer_get_modified_impl;
+ iface->get_has_selection = gedit_text_buffer_get_has_selection_impl;
+
+ /* signals */
+ iface->load = gedit_text_buffer_load_real;
+ iface->save = gedit_text_buffer_save_real;
+}
+
+static void
+set_encoding (GeditTextBuffer *doc,
+ const GeditEncoding *encoding,
+ gboolean set_by_user)
+{
+ g_return_if_fail (encoding != NULL);
+
+ gedit_debug (DEBUG_DOCUMENT);
+
+ if (doc->priv->encoding == encoding)
+ return;
+
+ doc->priv->encoding = encoding;
+
+ if (set_by_user)
+ {
+ const gchar *charset;
+
+ charset = gedit_encoding_get_charset (encoding);
+
+ gedit_metadata_manager_set (doc->priv->uri,
+ "encoding",
+ charset);
+ }
+
+ g_object_notify (G_OBJECT (doc), "encoding");
+}
+
+static GtkSourceStyleScheme *
+get_default_style_scheme (void)
+{
+ gchar *scheme_id;
+ GtkSourceStyleScheme *def_style;
+ GtkSourceStyleSchemeManager *manager;
+
+ manager = gedit_get_style_scheme_manager ();
+ scheme_id = gedit_prefs_manager_get_source_style_scheme ();
+ def_style = gtk_source_style_scheme_manager_get_scheme (manager,
+ scheme_id);
+
+ if (def_style == NULL)
+ {
+ g_warning ("Default style scheme '%s' cannot be found, falling back to 'classic' style scheme ", scheme_id);
+
+ def_style = gtk_source_style_scheme_manager_get_scheme (manager, "classic");
+ if (def_style == NULL)
+ {
+ g_warning ("Style scheme 'classic' cannot be found, check your GtkSourceView installation.");
+ }
+ }
+
+ g_free (scheme_id);
+
+ return def_style;
+}
+
+static void
+gedit_text_buffer_init (GeditTextBuffer *doc)
+{
+ GtkSourceStyleScheme *style_scheme;
+
+ gedit_debug (DEBUG_DOCUMENT);
+
+ doc->priv = GEDIT_TEXT_BUFFER_GET_PRIVATE (doc);
+
+ doc->priv->uri = NULL;
+ doc->priv->untitled_number = get_untitled_number ();
+
+ doc->priv->content_type = g_content_type_from_mime_type ("text/plain");
+
+ doc->priv->readonly = FALSE;
+
+ doc->priv->stop_cursor_moved_emission = FALSE;
+
+ doc->priv->last_save_was_manually = TRUE;
+ doc->priv->language_set_by_user = FALSE;
+
+ doc->priv->dispose_has_run = FALSE;
+
+ doc->priv->mtime = 0;
+
+ g_get_current_time (&doc->priv->time_of_last_save_or_load);
+
+ doc->priv->encoding = gedit_encoding_get_utf8 ();
+
+ gtk_source_buffer_set_max_undo_levels (GTK_SOURCE_BUFFER (doc),
+ gedit_prefs_manager_get_undo_actions_limit ());
+
+ gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (doc),
+ gedit_prefs_manager_get_bracket_matching ());
+
+ gedit_text_buffer_set_enable_search_highlighting (doc,
+ gedit_prefs_manager_get_enable_search_highlighting ());
+
+ style_scheme = get_default_style_scheme ();
+ if (style_scheme != NULL)
+ gtk_source_buffer_set_style_scheme (GTK_SOURCE_BUFFER (doc),
+ style_scheme);
+
+ g_signal_connect_after (doc,
+ "insert-text",
+ G_CALLBACK (insert_text_cb),
+ NULL);
+
+ g_signal_connect_after (doc,
+ "delete-range",
+ G_CALLBACK (delete_range_cb),
+ NULL);
+}
+
+GeditDocument *
+gedit_text_buffer_new (void)
+{
+ gedit_debug (DEBUG_DOCUMENT);
+
+ return GEDIT_DOCUMENT (g_object_new (GEDIT_TYPE_TEXT_BUFFER, NULL));
+}
+
+/* Note: do not emit the notify::read-only signal */
+static void
+set_readonly (GeditTextBuffer *doc,
+ gboolean readonly)
+{
+ gedit_debug (DEBUG_DOCUMENT);
+
+ readonly = (readonly != FALSE);
+
+ if (doc->priv->readonly == readonly)
+ return;
+
+ doc->priv->readonly = readonly;
+}
+
+static void
+gedit_text_buffer_set_readonly (GeditTextBuffer *doc,
+ gboolean readonly)
+{
+ gedit_debug (DEBUG_DOCUMENT);
+
+ g_return_if_fail (GEDIT_IS_TEXT_BUFFER (doc));
+
+ set_readonly (doc, readonly);
+
+ g_object_notify (G_OBJECT (doc), "read-only");
}
static void
-reset_temp_loading_data (GeditDocument *doc)
+reset_temp_loading_data (GeditTextBuffer *doc)
{
/* the loader has been used, throw it away */
g_object_unref (doc->priv->loader);
@@ -1013,7 +1109,7 @@ reset_temp_loading_data (GeditDocument *doc)
static void
document_loader_loaded (GeditDocumentLoader *loader,
const GError *error,
- GeditDocument *doc)
+ GeditTextBuffer *doc)
{
/* load was successful */
if (error == NULL)
@@ -1087,18 +1183,16 @@ document_loader_loaded (GeditDocumentLoader *loader,
{
reset_temp_loading_data (doc);
- g_signal_emit (doc,
- document_signals[LOADED],
- 0,
- NULL);
+ g_signal_emit_by_name (GEDIT_DOCUMENT (doc),
+ "loaded",
+ NULL);
return;
}
- g_signal_emit (doc,
- document_signals[LOADED],
- 0,
- error);
+ g_signal_emit_by_name (GEDIT_DOCUMENT (doc),
+ "loaded",
+ error);
reset_temp_loading_data (doc);
}
@@ -1107,7 +1201,7 @@ static void
document_loader_loading (GeditDocumentLoader *loader,
gboolean completed,
const GError *error,
- GeditDocument *doc)
+ GeditTextBuffer *doc)
{
if (completed)
{
@@ -1121,88 +1215,48 @@ document_loader_loading (GeditDocumentLoader *loader,
size = gedit_document_loader_get_file_size (loader);
read = gedit_document_loader_get_bytes_read (loader);
- g_signal_emit (doc,
- document_signals[LOADING],
- 0,
- read,
- size);
+ g_signal_emit_by_name (GEDIT_DOCUMENT (doc),
+ "loading",
+ read,
+ size);
}
}
static void
-gedit_document_load_real (GeditDocument *doc,
- const gchar *uri,
- const GeditEncoding *encoding,
- gint line_pos,
- gboolean create)
+gedit_text_buffer_load_real (GeditDocument *doc,
+ const gchar *uri,
+ const GeditEncoding *encoding,
+ gint line_pos,
+ gboolean create)
{
- g_return_if_fail (doc->priv->loader == NULL);
+ GeditTextBuffer *buf = GEDIT_TEXT_BUFFER (doc);
+
+ g_return_if_fail (buf->priv->loader == NULL);
gedit_debug_message (DEBUG_DOCUMENT, "load_real: uri = %s", uri);
/* create a loader. It will be destroyed when loading is completed */
- doc->priv->loader = gedit_document_loader_new (doc, uri, encoding);
+ buf->priv->loader = gedit_document_loader_new (doc, uri, encoding);
- g_signal_connect (doc->priv->loader,
+ g_signal_connect (buf->priv->loader,
"loading",
G_CALLBACK (document_loader_loading),
doc);
- doc->priv->create = create;
- doc->priv->requested_encoding = encoding;
- doc->priv->requested_line_pos = line_pos;
-
- set_uri (doc, uri, NULL);
+ buf->priv->create = create;
+ buf->priv->requested_encoding = encoding;
+ buf->priv->requested_line_pos = line_pos;
- gedit_document_loader_load (doc->priv->loader);
-}
-
-/**
- * gedit_document_load:
- * @doc: the #GeditDocument.
- * @uri: the uri where to load the document from.
- * @encoding: the #GeditEncoding to encode the document.
- * @line_pos: the line to show.
- * @create: whether the document should be created if it doesn't exist.
- *
- * Load a document. This results in the "load" signal to be emitted.
- */
-void
-gedit_document_load (GeditDocument *doc,
- const gchar *uri,
- const GeditEncoding *encoding,
- gint line_pos,
- gboolean create)
-{
- g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
- g_return_if_fail (uri != NULL);
- g_return_if_fail (gedit_utils_is_valid_uri (uri));
+ set_uri (buf, uri, NULL);
- g_signal_emit (doc, document_signals[LOAD], 0, uri, encoding, line_pos, create);
-}
-
-/**
- * gedit_document_load_cancel:
- * @doc: the #GeditDocument.
- *
- * Cancel load of a document.
- */
-gboolean
-gedit_document_load_cancel (GeditDocument *doc)
-{
- g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
-
- if (doc->priv->loader == NULL)
- return FALSE;
-
- return gedit_document_loader_cancel (doc->priv->loader);
+ gedit_document_loader_load (buf->priv->loader);
}
static void
document_saver_saving (GeditDocumentSaver *saver,
gboolean completed,
const GError *error,
- GeditDocument *doc)
+ GeditTextBuffer *doc)
{
gedit_debug (DEBUG_DOCUMENT);
@@ -1222,7 +1276,7 @@ document_saver_saving (GeditDocumentSaver *saver,
g_get_current_time (&doc->priv->time_of_last_save_or_load);
- gedit_document_set_readonly (doc, FALSE);
+ gedit_text_buffer_set_readonly (doc, FALSE);
gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (doc),
FALSE);
@@ -1234,10 +1288,9 @@ document_saver_saving (GeditDocumentSaver *saver,
TRUE);
}
- g_signal_emit (doc,
- document_signals[SAVED],
- 0,
- error);
+ g_signal_emit_by_name (GEDIT_DOCUMENT (doc),
+ "saved",
+ error);
/* the saver has been used, throw it away */
g_object_unref (doc->priv->saver);
@@ -1253,210 +1306,35 @@ document_saver_saving (GeditDocumentSaver *saver,
gedit_debug_message (DEBUG_DOCUMENT, "save progress: %" G_GINT64_FORMAT " of %" G_GINT64_FORMAT, written, size);
- g_signal_emit (doc,
- document_signals[SAVING],
- 0,
- written,
- size);
+ g_signal_emit_by_name (GEDIT_DOCUMENT (doc),
+ "saving",
+ written,
+ size);
}
}
static void
-gedit_document_save_real (GeditDocument *doc,
- const gchar *uri,
- const GeditEncoding *encoding,
- GeditDocumentSaveFlags flags)
+gedit_text_buffer_save_real (GeditDocument *doc,
+ const gchar *uri,
+ const GeditEncoding *encoding,
+ GeditDocumentSaveFlags flags)
{
- g_return_if_fail (doc->priv->saver == NULL);
+ GeditTextBuffer *buf = GEDIT_TEXT_BUFFER (doc);
+
+ g_return_if_fail (buf->priv->saver == NULL);
/* create a saver, it will be destroyed once saving is complete */
- doc->priv->saver = gedit_document_saver_new (doc, uri, encoding, flags);
+ buf->priv->saver = gedit_document_saver_new (doc, uri, encoding, flags);
- g_signal_connect (doc->priv->saver,
+ g_signal_connect (buf->priv->saver,
"saving",
G_CALLBACK (document_saver_saving),
doc);
- doc->priv->requested_encoding = encoding;
-
- gedit_document_saver_save (doc->priv->saver,
- doc->priv->mtime);
-}
-
-/**
- * gedit_document_save:
- * @doc: the #GeditDocument.
- * @flags: optionnal #GeditDocumentSaveFlags.
- *
- * Save the document to its previous location. This results in the "save"
- * signal to be emitted.
- */
-void
-gedit_document_save (GeditDocument *doc,
- GeditDocumentSaveFlags flags)
-{
- g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
- g_return_if_fail (doc->priv->uri != NULL);
-
- g_signal_emit (doc,
- document_signals[SAVE],
- 0,
- doc->priv->uri,
- doc->priv->encoding,
- flags);
-}
-
-/**
- * gedit_document_save_as:
- * @doc: the #GeditDocument.
- * @uri: the uri where to save the document.
- * @encoding: the #GeditEncoding to encode the document.
- * @flags: optionnal #GeditDocumentSaveFlags.
- *
- * Save the document to a new location. This results in the "save" signal
- * to be emitted.
- */
-void
-gedit_document_save_as (GeditDocument *doc,
- const gchar *uri,
- const GeditEncoding *encoding,
- GeditDocumentSaveFlags flags)
-{
- g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
- g_return_if_fail (uri != NULL);
- g_return_if_fail (encoding != NULL);
-
- /* priv->mtime refers to the the old uri (if any). Thus, it should be
- * ignored when saving as. */
- g_signal_emit (doc,
- document_signals[SAVE],
- 0,
- uri,
- encoding,
- flags | GEDIT_DOCUMENT_SAVE_IGNORE_MTIME);
-}
-
-gboolean
-gedit_document_insert_file (GeditDocument *doc,
- GtkTextIter *iter,
- const gchar *uri,
- const GeditEncoding *encoding)
-{
- g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
- g_return_val_if_fail (iter != NULL, FALSE);
- g_return_val_if_fail (gtk_text_iter_get_buffer (iter) ==
- GTK_TEXT_BUFFER (doc), FALSE);
-
- /* TODO */
-
- return FALSE;
-}
-
-gboolean
-gedit_document_is_untouched (GeditDocument *doc)
-{
- g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), TRUE);
-
- return (doc->priv->uri == NULL) &&
- (!gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (doc)));
-}
-
-gboolean
-gedit_document_is_untitled (GeditDocument *doc)
-{
- g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), TRUE);
-
- return (doc->priv->uri == NULL);
-}
-
-gboolean
-gedit_document_is_local (GeditDocument *doc)
-{
- g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
-
- if (doc->priv->uri == NULL)
- {
- return FALSE;
- }
-
- return gedit_utils_uri_has_file_scheme (doc->priv->uri);
-}
-
-gboolean
-gedit_document_get_deleted (GeditDocument *doc)
-{
- g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
-
- return doc->priv->uri && !gedit_utils_uri_exists (doc->priv->uri);
-}
-
-/*
- * If @line is bigger than the lines of the document, the cursor is moved
- * to the last line and FALSE is returned.
- */
-gboolean
-gedit_document_goto_line (GeditDocument *doc,
- gint line)
-{
- gboolean ret = TRUE;
- guint line_count;
- GtkTextIter iter;
-
- gedit_debug (DEBUG_DOCUMENT);
-
- g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
- g_return_val_if_fail (line >= -1, FALSE);
+ buf->priv->requested_encoding = encoding;
- line_count = gtk_text_buffer_get_line_count (GTK_TEXT_BUFFER (doc));
-
- if (line >= line_count)
- {
- ret = FALSE;
- gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (doc),
- &iter);
- }
- else
- {
- gtk_text_buffer_get_iter_at_line (GTK_TEXT_BUFFER (doc),
- &iter,
- line);
- }
-
- gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER (doc), &iter);
-
- return ret;
-}
-
-gboolean
-gedit_document_goto_line_offset (GeditDocument *doc,
- gint line,
- gint line_offset)
-{
- gboolean ret = TRUE;
- guint offset_count;
- GtkTextIter iter;
-
- g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
- g_return_val_if_fail (line >= -1, FALSE);
- g_return_val_if_fail (line_offset >= -1, FALSE);
-
- gtk_text_buffer_get_iter_at_line (GTK_TEXT_BUFFER (doc),
- &iter,
- line);
-
- offset_count = gtk_text_iter_get_chars_in_line (&iter);
- if (line_offset > offset_count)
- {
- ret = FALSE;
- }
- else
- {
- gtk_text_iter_set_line_offset (&iter, line_offset);
- }
-
- gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER (doc), &iter);
-
- return ret;
+ gedit_document_saver_save (buf->priv->saver,
+ buf->priv->mtime);
}
static gint
@@ -1489,15 +1367,15 @@ compute_num_of_lines (const gchar *text)
}
void
-gedit_document_set_search_text (GeditDocument *doc,
- const gchar *text,
- guint flags)
+gedit_text_buffer_set_search_text (GeditTextBuffer *doc,
+ const gchar *text,
+ guint flags)
{
gchar *converted_text;
gboolean notify = FALSE;
gboolean update_to_search_region = FALSE;
- g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
+ g_return_if_fail (GEDIT_IS_TEXT_BUFFER (doc));
g_return_if_fail ((text == NULL) || (doc->priv->search_text != text));
g_return_if_fail ((text == NULL) || g_utf8_validate (text, -1, NULL));
@@ -1508,12 +1386,12 @@ gedit_document_set_search_text (GeditDocument *doc,
if (*text != '\0')
{
converted_text = gedit_utils_unescape_search_text (text);
- notify = !gedit_document_get_can_search_again (doc);
+ notify = !gedit_text_buffer_get_can_search_again (doc);
}
else
{
- converted_text = g_strdup("");
- notify = gedit_document_get_can_search_again (doc);
+ converted_text = g_strdup ("");
+ notify = gedit_text_buffer_get_can_search_again (doc);
}
g_free (doc->priv->search_text);
@@ -1551,10 +1429,10 @@ gedit_document_set_search_text (GeditDocument *doc,
}
gchar *
-gedit_document_get_search_text (GeditDocument *doc,
- guint *flags)
+gedit_text_buffer_get_search_text (GeditTextBuffer *doc,
+ guint *flags)
{
- g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), NULL);
+ g_return_val_if_fail (GEDIT_IS_TEXT_BUFFER (doc), NULL);
if (flags != NULL)
*flags = doc->priv->search_flags;
@@ -1563,20 +1441,20 @@ gedit_document_get_search_text (GeditDocument *doc,
}
gboolean
-gedit_document_get_can_search_again (GeditDocument *doc)
+gedit_text_buffer_get_can_search_again (GeditTextBuffer *doc)
{
- g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
+ g_return_val_if_fail (GEDIT_IS_TEXT_BUFFER (doc), FALSE);
return ((doc->priv->search_text != NULL) &&
(*doc->priv->search_text != '\0'));
}
gboolean
-gedit_document_search_forward (GeditDocument *doc,
- const GtkTextIter *start,
- const GtkTextIter *end,
- GtkTextIter *match_start,
- GtkTextIter *match_end)
+gedit_text_buffer_search_forward (GeditTextBuffer *doc,
+ const GtkTextIter *start,
+ const GtkTextIter *end,
+ GtkTextIter *match_start,
+ GtkTextIter *match_end)
{
GtkTextIter iter;
GtkSourceSearchFlags search_flags;
@@ -1584,7 +1462,7 @@ gedit_document_search_forward (GeditDocument *doc,
GtkTextIter m_start;
GtkTextIter m_end;
- g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
+ g_return_val_if_fail (GEDIT_IS_TEXT_BUFFER (doc), FALSE);
g_return_val_if_fail ((start == NULL) ||
(gtk_text_iter_get_buffer (start) == GTK_TEXT_BUFFER (doc)), FALSE);
g_return_val_if_fail ((end == NULL) ||
@@ -1637,15 +1515,15 @@ gedit_document_search_forward (GeditDocument *doc,
if (found && (match_end != NULL))
*match_end = m_end;
- return found;
+ return found;
}
-
+
gboolean
-gedit_document_search_backward (GeditDocument *doc,
- const GtkTextIter *start,
- const GtkTextIter *end,
- GtkTextIter *match_start,
- GtkTextIter *match_end)
+gedit_text_buffer_search_backward (GeditTextBuffer *doc,
+ const GtkTextIter *start,
+ const GtkTextIter *end,
+ GtkTextIter *match_start,
+ GtkTextIter *match_end)
{
GtkTextIter iter;
GtkSourceSearchFlags search_flags;
@@ -1653,7 +1531,7 @@ gedit_document_search_backward (GeditDocument *doc,
GtkTextIter m_start;
GtkTextIter m_end;
- g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
+ g_return_val_if_fail (GEDIT_IS_TEXT_BUFFER (doc), FALSE);
g_return_val_if_fail ((start == NULL) ||
(gtk_text_iter_get_buffer (start) == GTK_TEXT_BUFFER (doc)), FALSE);
g_return_val_if_fail ((end == NULL) ||
@@ -1710,10 +1588,10 @@ gedit_document_search_backward (GeditDocument *doc,
}
gint
-gedit_document_replace_all (GeditDocument *doc,
- const gchar *find,
- const gchar *replace,
- guint flags)
+gedit_text_buffer_replace_all (GeditTextBuffer *doc,
+ const gchar *find,
+ const gchar *replace,
+ guint flags)
{
GtkTextIter iter;
GtkTextIter m_start;
@@ -1728,7 +1606,7 @@ gedit_document_replace_all (GeditDocument *doc,
gboolean brackets_highlighting;
gboolean search_highliting;
- g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), 0);
+ g_return_val_if_fail (GEDIT_IS_TEXT_BUFFER (doc), 0);
g_return_val_if_fail (replace != NULL, 0);
g_return_val_if_fail ((find != NULL) || (doc->priv->search_text != NULL), 0);
@@ -1763,8 +1641,8 @@ gedit_document_replace_all (GeditDocument *doc,
gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (buffer), FALSE);
/* and do search highliting later */
- search_highliting = gedit_document_get_enable_search_highlighting (doc);
- gedit_document_set_enable_search_highlighting (doc, FALSE);
+ search_highliting = gedit_text_buffer_get_enable_search_highlighting (doc);
+ gedit_text_buffer_set_enable_search_highlighting (doc, FALSE);
gtk_text_buffer_begin_user_action (buffer);
@@ -1818,7 +1696,7 @@ gedit_document_replace_all (GeditDocument *doc,
gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (buffer),
brackets_highlighting);
- gedit_document_set_enable_search_highlighting (doc, search_highliting);
+ gedit_text_buffer_set_enable_search_highlighting (doc, search_highliting);
g_free (search_text);
g_free (replace_text);
@@ -1827,50 +1705,28 @@ gedit_document_replace_all (GeditDocument *doc,
}
void
-gedit_document_set_language (GeditDocument *doc,
- GtkSourceLanguage *lang)
+gedit_text_buffer_set_language (GeditTextBuffer *doc,
+ GtkSourceLanguage *lang)
{
- g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
+ g_return_if_fail (GEDIT_IS_TEXT_BUFFER (doc));
set_language (doc, lang, TRUE);
}
GtkSourceLanguage *
-gedit_document_get_language (GeditDocument *doc)
+gedit_text_buffer_get_language (GeditTextBuffer *doc)
{
- g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), NULL);
+ g_return_val_if_fail (GEDIT_IS_TEXT_BUFFER (doc), NULL);
return gtk_source_buffer_get_language (GTK_SOURCE_BUFFER (doc));
}
-const GeditEncoding *
-gedit_document_get_encoding (GeditDocument *doc)
-{
- g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), NULL);
-
- return doc->priv->encoding;
-}
-
-glong
-_gedit_document_get_seconds_since_last_save_or_load (GeditDocument *doc)
-{
- GTimeVal current_time;
-
- gedit_debug (DEBUG_DOCUMENT);
-
- g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), -1);
-
- g_get_current_time (¤t_time);
-
- return (current_time.tv_sec - doc->priv->time_of_last_save_or_load.tv_sec);
-}
-
static void
-get_search_match_colors (GeditDocument *doc,
- gboolean *foreground_set,
- GdkColor *foreground,
- gboolean *background_set,
- GdkColor *background)
+get_search_match_colors (GeditTextBuffer *doc,
+ gboolean *foreground_set,
+ GdkColor *foreground,
+ gboolean *background_set,
+ GdkColor *background)
{
GtkSourceStyleScheme *style_scheme;
GtkSourceStyle *style;
@@ -1929,9 +1785,9 @@ get_search_match_colors (GeditDocument *doc,
}
static void
-sync_found_tag (GeditDocument *doc,
- GParamSpec *pspec,
- gpointer data)
+sync_found_tag (GeditTextBuffer *doc,
+ GParamSpec *pspec,
+ gpointer data)
{
GdkColor fg;
GdkColor bg;
@@ -1967,9 +1823,9 @@ text_tag_set_highest_priority (GtkTextTag *tag,
}
static void
-search_region (GeditDocument *doc,
- GtkTextIter *start,
- GtkTextIter *end)
+search_region (GeditTextBuffer *doc,
+ GtkTextIter *start,
+ GtkTextIter *end)
{
GtkTextIter iter;
GtkTextIter m_start;
@@ -2078,9 +1934,9 @@ search_region (GeditDocument *doc,
}
static void
-to_search_region_range (GeditDocument *doc,
- GtkTextIter *start,
- GtkTextIter *end)
+to_search_region_range (GeditTextBuffer *doc,
+ GtkTextIter *start,
+ GtkTextIter *end)
{
gedit_debug (DEBUG_DOCUMENT);
@@ -2106,15 +1962,15 @@ to_search_region_range (GeditDocument *doc,
}
void
-_gedit_document_search_region (GeditDocument *doc,
- const GtkTextIter *start,
- const GtkTextIter *end)
+_gedit_text_buffer_search_region (GeditTextBuffer *doc,
+ const GtkTextIter *start,
+ const GtkTextIter *end)
{
GeditTextRegion *region;
gedit_debug (DEBUG_DOCUMENT);
- g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
+ g_return_if_fail (GEDIT_IS_TEXT_BUFFER (doc));
g_return_if_fail (start != NULL);
g_return_if_fail (end != NULL);
@@ -2161,10 +2017,10 @@ _gedit_document_search_region (GeditDocument *doc,
}
static void
-insert_text_cb (GeditDocument *doc,
- GtkTextIter *pos,
- const gchar *text,
- gint length)
+insert_text_cb (GeditTextBuffer *doc,
+ GtkTextIter *pos,
+ const gchar *text,
+ gint length)
{
GtkTextIter start;
GtkTextIter end;
@@ -2186,9 +2042,9 @@ insert_text_cb (GeditDocument *doc,
}
static void
-delete_range_cb (GeditDocument *doc,
- GtkTextIter *start,
- GtkTextIter *end)
+delete_range_cb (GeditTextBuffer *doc,
+ GtkTextIter *start,
+ GtkTextIter *end)
{
GtkTextIter d_start;
GtkTextIter d_end;
@@ -2202,10 +2058,10 @@ delete_range_cb (GeditDocument *doc,
}
void
-gedit_document_set_enable_search_highlighting (GeditDocument *doc,
- gboolean enable)
+gedit_text_buffer_set_enable_search_highlighting (GeditTextBuffer *doc,
+ gboolean enable)
{
- g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
+ g_return_if_fail (GEDIT_IS_TEXT_BUFFER (doc));
enable = enable != FALSE;
@@ -2238,7 +2094,7 @@ gedit_document_set_enable_search_highlighting (GeditDocument *doc,
else
{
doc->priv->to_search_region = gedit_text_region_new (GTK_TEXT_BUFFER (doc));
- if (gedit_document_get_can_search_again (doc))
+ if (gedit_text_buffer_get_can_search_again (doc))
{
/* If search_text is not empty, highligth all its occurrences */
GtkTextIter begin;
@@ -2256,32 +2112,65 @@ gedit_document_set_enable_search_highlighting (GeditDocument *doc,
}
gboolean
-gedit_document_get_enable_search_highlighting (GeditDocument *doc)
+gedit_text_buffer_get_enable_search_highlighting (GeditTextBuffer *doc)
{
- g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
+ g_return_val_if_fail (GEDIT_IS_TEXT_BUFFER (doc), FALSE);
return (doc->priv->to_search_region != NULL);
}
+/* FIXME
void
-_gedit_document_set_mount_operation_factory (GeditDocument *doc,
- GeditMountOperationFactory callback,
- gpointer userdata)
+_gedit_text_buffer_set_mount_operation_factory (GeditTextBuffer *doc,
+ GeditMountOperationFactory callback,
+ gpointer userdata)
{
- g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
+ g_return_if_fail (GEDIT_IS_TEXT_BUFFER (doc));
doc->priv->mount_operation_factory = callback;
doc->priv->mount_operation_userdata = userdata;
}
GMountOperation *
-_gedit_document_create_mount_operation (GeditDocument *doc)
+_gedit_text_buffer_create_mount_operation (GeditTextBuffer *doc)
{
- g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), NULL);
+ g_return_val_if_fail (GEDIT_IS_TEXT_BUFFER (doc), NULL);
if (doc->priv->mount_operation_factory == NULL)
return g_mount_operation_new ();
else
return doc->priv->mount_operation_factory (doc,
doc->priv->mount_operation_userdata);
+}*/
+
+void
+gedit_text_buffer_get_cursor_position (GeditTextBuffer *buffer,
+ gint tab_size,
+ gint *row,
+ gint *col)
+{
+ GtkTextIter iter;
+ GtkTextIter start;
+
+ gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (buffer),
+ &iter,
+ gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (buffer)));
+
+ *row = gtk_text_iter_get_line (&iter);
+
+ start = iter;
+ gtk_text_iter_set_line_offset (&start, 0);
+ *col = 0;
+
+ while (!gtk_text_iter_equal (&start, &iter))
+ {
+ /* FIXME: Are we Unicode compliant here? */
+ if (gtk_text_iter_get_char (&start) == '\t')
+
+ *col += (tab_size - (*col % tab_size));
+ else
+ ++(*col);
+
+ gtk_text_iter_forward_char (&start);
+ }
}
diff --git a/gedit/gedit-text-buffer.h b/gedit/gedit-text-buffer.h
new file mode 100644
index 0000000..85eeba2
--- /dev/null
+++ b/gedit/gedit-text-buffer.h
@@ -0,0 +1,172 @@
+/*
+ * gedit-document.h
+ * This file is part of gedit
+ *
+ * Copyright (C) 1998, 1999 Alex Roberts, Evan Lawrence
+ * Copyright (C) 2000, 2001 Chema Celorio, Paolo Maggi
+ * Copyright (C) 2002-2005 Paolo Maggi
+ *
+ * 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., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Modified by the gedit Team, 1998-2005. See the AUTHORS file for a
+ * list of people on the gedit Team.
+ * See the ChangeLog files for a list of changes.
+ *
+ * $Id$
+ */
+
+#ifndef __GEDIT_TEXT_BUFFER_H__
+#define __GEDIT_TEXT_BUFFER_H__
+
+#include <gio/gio.h>
+#include <gtk/gtk.h>
+#include <gtksourceview/gtksourcebuffer.h>
+
+
+G_BEGIN_DECLS
+
+/*
+ * Type checking and casting macros
+ */
+#define GEDIT_TYPE_TEXT_BUFFER (gedit_text_buffer_get_type())
+#define GEDIT_TEXT_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GEDIT_TYPE_TEXT_BUFFER, GeditTextBuffer))
+#define GEDIT_TEXT_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GEDIT_TYPE_TEXT_BUFFER, GeditTextBufferClass))
+#define GEDIT_IS_TEXT_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GEDIT_TYPE_TEXT_BUFFER))
+#define GEDIT_IS_TEXT_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEDIT_TYPE_TEXT_BUFFER))
+#define GEDIT_TEXT_BUFFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GEDIT_TYPE_TEXT_BUFFER, GeditTextBufferClass))
+
+
+/* Private structure type */
+typedef struct _GeditTextBufferPrivate GeditTextBufferPrivate;
+
+/*
+ * Main object structure
+ */
+typedef struct _GeditTextBuffer GeditTextBuffer;
+
+struct _GeditTextBuffer
+{
+ GtkSourceBuffer buffer;
+
+ /*< private > */
+ GeditTextBufferPrivate *priv;
+};
+
+/*
+ * Class definition
+ */
+typedef struct _GeditTextBufferClass GeditTextBufferClass;
+
+struct _GeditTextBufferClass
+{
+ GtkSourceBufferClass parent_class;
+
+ /* signals */
+ void (* cursor_moved) (GeditTextBuffer *document);
+
+ void (* search_highlight_updated)
+ (GeditTextBuffer *document,
+ GtkTextIter *start,
+ GtkTextIter *end);
+};
+
+
+GType gedit_text_buffer_get_type (void) G_GNUC_CONST;
+
+GeditDocument *gedit_text_buffer_new (void);
+
+void gedit_text_buffer_set_search_text (GeditTextBuffer *doc,
+ const gchar *text,
+ guint flags);
+
+gchar *gedit_text_buffer_get_search_text (GeditTextBuffer *doc,
+ guint *flags);
+
+gboolean gedit_text_buffer_get_can_search_again (GeditTextBuffer *doc);
+
+gboolean gedit_text_buffer_search_forward (GeditTextBuffer *doc,
+ const GtkTextIter *start,
+ const GtkTextIter *end,
+ GtkTextIter *match_start,
+ GtkTextIter *match_end);
+
+gboolean gedit_text_buffer_search_backward (GeditTextBuffer *doc,
+ const GtkTextIter *start,
+ const GtkTextIter *end,
+ GtkTextIter *match_start,
+ GtkTextIter *match_end);
+
+gint gedit_text_buffer_replace_all (GeditTextBuffer *doc,
+ const gchar *find,
+ const gchar *replace,
+ guint flags);
+
+void gedit_text_buffer_set_language (GeditTextBuffer *doc,
+ GtkSourceLanguage *lang);
+GtkSourceLanguage
+ *gedit_text_buffer_get_language (GeditTextBuffer *doc);
+
+void gedit_text_buffer_set_enable_search_highlighting
+ (GeditTextBuffer *doc,
+ gboolean enable);
+
+gboolean gedit_text_buffer_get_enable_search_highlighting
+ (GeditTextBuffer *doc);
+
+void gedit_text_buffer_get_cursor_position (GeditTextBuffer *buffer,
+ gint tab_size,
+ gint *row,
+ gint *col);
+
+/*
+ * Non exported functions
+ */
+
+/* Note: this is a sync stat: use only on local files */
+void _gedit_text_buffer_search_region (GeditTextBuffer *doc,
+ const GtkTextIter *start,
+ const GtkTextIter *end);
+
+/* Search macros */
+#define GEDIT_SEARCH_IS_DONT_SET_FLAGS(sflags) ((sflags & GEDIT_SEARCH_DONT_SET_FLAGS) != 0)
+#define GEDIT_SEARCH_SET_DONT_SET_FLAGS(sflags,state) ((state == TRUE) ? \
+(sflags |= GEDIT_SEARCH_DONT_SET_FLAGS) : (sflags &= ~GEDIT_SEARCH_DONT_SET_FLAGS))
+
+#define GEDIT_SEARCH_IS_ENTIRE_WORD(sflags) ((sflags & GEDIT_SEARCH_ENTIRE_WORD) != 0)
+#define GEDIT_SEARCH_SET_ENTIRE_WORD(sflags,state) ((state == TRUE) ? \
+(sflags |= GEDIT_SEARCH_ENTIRE_WORD) : (sflags &= ~GEDIT_SEARCH_ENTIRE_WORD))
+
+#define GEDIT_SEARCH_IS_CASE_SENSITIVE(sflags) ((sflags & GEDIT_SEARCH_CASE_SENSITIVE) != 0)
+#define GEDIT_SEARCH_SET_CASE_SENSITIVE(sflags,state) ((state == TRUE) ? \
+(sflags |= GEDIT_SEARCH_CASE_SENSITIVE) : (sflags &= ~GEDIT_SEARCH_CASE_SENSITIVE))
+
+/* FIXME
+typedef GMountOperation *(*GeditMountOperationFactory)(GeditTextBuffer *doc,
+ gpointer userdata);
+
+void _gedit_text_buffer_set_mount_operation_factory
+ (GeditTextBuffer *doc,
+ GeditMountOperationFactory callback,
+ gpointer userdata);
+GMountOperation
+ *_gedit_text_buffer_create_mount_operation
+ (GeditTextBuffer *doc);*/
+
+G_END_DECLS
+
+#endif /* __GEDIT_TEXT_BUFFER_H__ */
diff --git a/gedit/gedit-view.c b/gedit/gedit-text-view.c
similarity index 80%
rename from gedit/gedit-view.c
rename to gedit/gedit-text-view.c
index b999d29..85aa822 100644
--- a/gedit/gedit-view.c
+++ b/gedit/gedit-text-view.c
@@ -41,7 +41,9 @@
#include <glib/gi18n.h>
-#include "gedit-view.h"
+#include "gedit-view-interface.h"
+#include "gedit-text-view.h"
+#include "gedit-text-buffer.h"
#include "gedit-debug.h"
#include "gedit-prefs-manager.h"
#include "gedit-prefs-manager-app.h"
@@ -49,12 +51,13 @@
#include "gedit-utils.h"
-#define GEDIT_VIEW_SCROLL_MARGIN 0.02
-#define GEDIT_VIEW_SEARCH_DIALOG_TIMEOUT (30*1000) /* 30 seconds */
+#define GEDIT_TEXT_VIEW_SCROLL_MARGIN 0.02
+#define GEDIT_TEXT_VIEW_SEARCH_DIALOG_TIMEOUT (30*1000) /* 30 seconds */
#define MIN_SEARCH_COMPLETION_KEY_LEN 3
+#define GEDIT_TEXT_VIEW_NAME _("Text Editor")
-#define GEDIT_VIEW_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), GEDIT_TYPE_VIEW, GeditViewPrivate))
+#define GEDIT_TEXT_VIEW_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), GEDIT_TYPE_TEXT_VIEW, GeditTextViewPrivate))
typedef enum
{
@@ -67,7 +70,7 @@ enum
TARGET_URI_LIST = 100
};
-struct _GeditViewPrivate
+struct _GeditTextViewPrivate
{
SearchMode search_mode;
@@ -100,50 +103,56 @@ struct _GeditViewPrivate
/* The search entry completion is shared among all the views */
GtkListStore *search_completion_model = NULL;
-static void gedit_view_destroy (GtkObject *object);
-static void gedit_view_finalize (GObject *object);
-static gint gedit_view_focus_out (GtkWidget *widget,
+static void gedit_text_view_destroy (GtkObject *object);
+static void gedit_text_view_finalize (GObject *object);
+static gint gedit_text_view_focus_out (GtkWidget *widget,
GdkEventFocus *event);
-static gboolean gedit_view_drag_motion (GtkWidget *widget,
+static gboolean gedit_text_view_drag_motion (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
guint timestamp);
-static void gedit_view_drag_data_received (GtkWidget *widget,
+static void gedit_text_view_drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *selection_data,
guint info,
guint timestamp);
-static gboolean gedit_view_drag_drop (GtkWidget *widget,
+static gboolean gedit_text_view_drag_drop (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
guint timestamp);
-static gboolean gedit_view_button_press_event (GtkWidget *widget,
+static gboolean gedit_text_view_button_press_event (GtkWidget *widget,
GdkEventButton *event);
-static gboolean start_interactive_search (GeditView *view);
-static gboolean start_interactive_goto_line (GeditView *view);
-static gboolean reset_searched_text (GeditView *view);
+static gboolean start_interactive_search (GeditTextView *view);
+static gboolean start_interactive_goto_line (GeditTextView *view);
+static gboolean reset_searched_text (GeditTextView *view);
-static void hide_search_window (GeditView *view,
+static void hide_search_window (GeditTextView *view,
gboolean cancel);
-static gint gedit_view_expose (GtkWidget *widget,
+static gint gedit_text_view_expose (GtkWidget *widget,
GdkEventExpose *event);
static void search_highlight_updated_cb (GeditDocument *doc,
GtkTextIter *start,
GtkTextIter *end,
- GeditView *view);
+ GeditTextView *view);
-static void gedit_view_delete_from_cursor (GtkTextView *text_view,
+static void gedit_text_view_delete_from_cursor (GtkTextView *text_view,
GtkDeleteType type,
gint count);
-G_DEFINE_TYPE(GeditView, gedit_view, GTK_TYPE_SOURCE_VIEW)
+static void gedit_text_view_iface_init (GeditViewIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (GeditTextView,
+ gedit_text_view,
+ GTK_TYPE_SOURCE_VIEW,
+ G_IMPLEMENT_INTERFACE (GEDIT_TYPE_VIEW,
+ gedit_text_view_iface_init))
/* Signals */
enum
@@ -151,7 +160,6 @@ enum
START_INTERACTIVE_SEARCH,
START_INTERACTIVE_GOTO_LINE,
RESET_SEARCHED_TEXT,
- DROP_URIS,
LAST_SIGNAL
};
@@ -166,7 +174,7 @@ typedef enum
static void
document_read_only_notify_handler (GeditDocument *document,
GParamSpec *pspec,
- GeditView *view)
+ GeditTextView *view)
{
gedit_debug (DEBUG_VIEW);
@@ -175,7 +183,7 @@ document_read_only_notify_handler (GeditDocument *document,
}
static void
-gedit_view_class_init (GeditViewClass *klass)
+gedit_text_view_class_init (GeditTextViewClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkObjectClass *gtkobject_class = GTK_OBJECT_CLASS (klass);
@@ -184,11 +192,11 @@ gedit_view_class_init (GeditViewClass *klass)
GtkBindingSet *binding_set;
- gtkobject_class->destroy = gedit_view_destroy;
- object_class->finalize = gedit_view_finalize;
+ gtkobject_class->destroy = gedit_text_view_destroy;
+ object_class->finalize = gedit_text_view_finalize;
- widget_class->focus_out_event = gedit_view_focus_out;
- widget_class->expose_event = gedit_view_expose;
+ widget_class->focus_out_event = gedit_text_view_focus_out;
+ widget_class->expose_event = gedit_text_view_expose;
/*
* Override the gtk_text_view_drag_motion and drag_drop
@@ -204,21 +212,21 @@ gedit_view_class_init (GeditViewClass *klass)
*
* See bug #89881 for details
*/
- widget_class->drag_motion = gedit_view_drag_motion;
- widget_class->drag_data_received = gedit_view_drag_data_received;
- widget_class->drag_drop = gedit_view_drag_drop;
- widget_class->button_press_event = gedit_view_button_press_event;
+ widget_class->drag_motion = gedit_text_view_drag_motion;
+ widget_class->drag_data_received = gedit_text_view_drag_data_received;
+ widget_class->drag_drop = gedit_text_view_drag_drop;
+ widget_class->button_press_event = gedit_text_view_button_press_event;
klass->start_interactive_search = start_interactive_search;
klass->start_interactive_goto_line = start_interactive_goto_line;
klass->reset_searched_text = reset_searched_text;
- text_view_class->delete_from_cursor = gedit_view_delete_from_cursor;
+ text_view_class->delete_from_cursor = gedit_text_view_delete_from_cursor;
view_signals[START_INTERACTIVE_SEARCH] =
g_signal_new ("start_interactive_search",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- G_STRUCT_OFFSET (GeditViewClass, start_interactive_search),
+ G_STRUCT_OFFSET (GeditTextViewClass, start_interactive_search),
NULL, NULL,
gedit_marshal_BOOLEAN__NONE,
G_TYPE_BOOLEAN, 0);
@@ -227,7 +235,7 @@ gedit_view_class_init (GeditViewClass *klass)
g_signal_new ("start_interactive_goto_line",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- G_STRUCT_OFFSET (GeditViewClass, start_interactive_goto_line),
+ G_STRUCT_OFFSET (GeditTextViewClass, start_interactive_goto_line),
NULL, NULL,
gedit_marshal_BOOLEAN__NONE,
G_TYPE_BOOLEAN, 0);
@@ -236,30 +244,12 @@ gedit_view_class_init (GeditViewClass *klass)
g_signal_new ("reset_searched_text",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- G_STRUCT_OFFSET (GeditViewClass, reset_searched_text),
+ G_STRUCT_OFFSET (GeditTextViewClass, reset_searched_text),
NULL, NULL,
gedit_marshal_BOOLEAN__NONE,
- G_TYPE_BOOLEAN, 0);
-
- /* A new signal DROP_URIS has been added to allow plugins to intercept
- * the default dnd behaviour of 'text/uri-list'. GeditView now handles
- * dnd in the default handlers of drag_drop, drag_motion and
- * drag_data_received. The view emits drop_uris from drag_data_received
- * if valid uris have been dropped. Plugins should connect to
- * drag_motion, drag_drop and drag_data_received to change this
- * default behaviour. They should _NOT_ use this signal because this
- * will not prevent gedit from loading the uri
- */
- view_signals[DROP_URIS] =
- g_signal_new ("drop_uris",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- G_STRUCT_OFFSET (GeditViewClass, drop_uris),
- NULL, NULL,
- g_cclosure_marshal_VOID__BOXED,
- G_TYPE_NONE, 1, G_TYPE_STRV);
+ G_TYPE_BOOLEAN, 0);
- g_type_class_add_private (klass, sizeof (GeditViewPrivate));
+ g_type_class_add_private (klass, sizeof (GeditTextViewPrivate));
binding_set = gtk_binding_set_by_class (klass);
@@ -286,8 +276,220 @@ gedit_view_class_init (GeditViewClass *klass)
G_TYPE_INT, 1);
}
+static const gchar *
+gedit_view_get_name_impl (GeditView *view)
+{
+ return GEDIT_TEXT_VIEW_NAME;
+}
+
+static GeditDocument *
+gedit_view_get_document_impl (GeditView *view)
+{
+ return GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
+}
+
+static void
+gedit_view_set_editable_impl (GeditView *view,
+ gboolean setting)
+{
+ gtk_text_view_set_editable (GTK_TEXT_VIEW (view), setting);
+}
+
+static gboolean
+gedit_view_get_editable_impl (GeditView *view)
+{
+ return gtk_text_view_get_editable (GTK_TEXT_VIEW (view));
+}
+
+static gboolean
+gedit_view_get_overwrite_impl (GeditView *view)
+{
+ return gtk_text_view_get_overwrite (GTK_TEXT_VIEW (view));
+}
+
+static void
+gedit_view_cut_clipboard_impl (GeditView *view)
+{
+ GtkTextBuffer *buffer;
+ GtkClipboard *clipboard;
+
+ gedit_debug (DEBUG_VIEW);
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
+ g_return_if_fail (buffer != NULL);
+
+ clipboard = gtk_widget_get_clipboard (GTK_WIDGET (view),
+ GDK_SELECTION_CLIPBOARD);
+
+ /* FIXME: what is default editability of a buffer? */
+ gtk_text_buffer_cut_clipboard (buffer,
+ clipboard,
+ !gedit_document_get_readonly (
+ GEDIT_DOCUMENT (buffer)));
+
+ gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (view),
+ gtk_text_buffer_get_insert (buffer),
+ GEDIT_TEXT_VIEW_SCROLL_MARGIN,
+ FALSE,
+ 0.0,
+ 0.0);
+}
+
+static void
+gedit_view_copy_clipboard_impl (GeditView *view)
+{
+ GtkTextBuffer *buffer;
+ GtkClipboard *clipboard;
+
+ gedit_debug (DEBUG_VIEW);
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
+ g_return_if_fail (buffer != NULL);
+
+ clipboard = gtk_widget_get_clipboard (GTK_WIDGET (view),
+ GDK_SELECTION_CLIPBOARD);
+
+ gtk_text_buffer_copy_clipboard (buffer, clipboard);
+
+ /* on copy do not scroll, we are already on screen */
+}
+
+static void
+gedit_view_paste_clipboard_impl (GeditView *view)
+{
+ GtkTextBuffer *buffer;
+ GtkClipboard *clipboard;
+
+ gedit_debug (DEBUG_VIEW);
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
+ g_return_if_fail (buffer != NULL);
+
+ clipboard = gtk_widget_get_clipboard (GTK_WIDGET (view),
+ GDK_SELECTION_CLIPBOARD);
+
+ /* FIXME: what is default editability of a buffer? */
+ gtk_text_buffer_paste_clipboard (buffer,
+ clipboard,
+ NULL,
+ !gedit_document_get_readonly (
+ GEDIT_DOCUMENT (buffer)));
+
+ gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (view),
+ gtk_text_buffer_get_insert (buffer),
+ GEDIT_TEXT_VIEW_SCROLL_MARGIN,
+ FALSE,
+ 0.0,
+ 0.0);
+}
+
+static void
+gedit_view_delete_selection_impl (GeditView *view)
+{
+ GtkTextBuffer *buffer = NULL;
+
+ gedit_debug (DEBUG_VIEW);
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
+ g_return_if_fail (buffer != NULL);
+
+ /* FIXME: what is default editability of a buffer? */
+ gtk_text_buffer_delete_selection (buffer,
+ TRUE,
+ !gedit_document_get_readonly (
+ GEDIT_DOCUMENT (buffer)));
+
+ gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (view),
+ gtk_text_buffer_get_insert (buffer),
+ GEDIT_TEXT_VIEW_SCROLL_MARGIN,
+ FALSE,
+ 0.0,
+ 0.0);
+}
+
+static void
+gedit_view_select_all_impl (GeditView *view)
+{
+ GtkTextBuffer *buffer = NULL;
+ GtkTextIter start, end;
+
+ gedit_debug (DEBUG_VIEW);
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
+ g_return_if_fail (buffer != NULL);
+
+ gtk_text_buffer_get_bounds (buffer, &start, &end);
+ gtk_text_buffer_select_range (buffer, &start, &end);
+}
+
+static void
+gedit_view_scroll_to_cursor_impl (GeditView *view)
+{
+ GtkTextBuffer* buffer = NULL;
+
+ gedit_debug (DEBUG_VIEW);
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
+ g_return_if_fail (buffer != NULL);
+
+ gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (view),
+ gtk_text_buffer_get_insert (buffer),
+ 0.25,
+ FALSE,
+ 0.0,
+ 0.0);
+}
+
+static void
+gedit_view_set_font_impl (GeditView *view,
+ gboolean def,
+ const gchar *font_name)
+{
+ PangoFontDescription *font_desc = NULL;
+
+ gedit_debug (DEBUG_VIEW);
+
+ if (def)
+ {
+ gchar *font;
+
+ font = gedit_prefs_manager_get_system_font ();
+ font_desc = pango_font_description_from_string (font);
+ g_free (font);
+ }
+ else
+ {
+ g_return_if_fail (font_name != NULL);
+
+ font_desc = pango_font_description_from_string (font_name);
+ }
+
+ g_return_if_fail (font_desc != NULL);
+
+ gtk_widget_modify_font (GTK_WIDGET (view), font_desc);
+
+ pango_font_description_free (font_desc);
+}
+
+static void
+gedit_text_view_iface_init (GeditViewIface *iface)
+{
+ iface->get_name = gedit_view_get_name_impl;
+ iface->get_document = gedit_view_get_document_impl;
+ iface->set_editable = gedit_view_set_editable_impl;
+ iface->get_editable = gedit_view_get_editable_impl;
+ iface->get_overwrite = gedit_view_get_overwrite_impl;
+ iface->cut_clipboard = gedit_view_cut_clipboard_impl;
+ iface->copy_clipboard = gedit_view_copy_clipboard_impl;
+ iface->paste_clipboard = gedit_view_paste_clipboard_impl;
+ iface->delete_selection = gedit_view_delete_selection_impl;
+ iface->select_all = gedit_view_select_all_impl;
+ iface->scroll_to_cursor = gedit_view_scroll_to_cursor_impl;
+ iface->set_font = gedit_view_set_font_impl;
+}
+
static void
-current_buffer_removed (GeditView *view)
+current_buffer_removed (GeditTextView *view)
{
if (view->priv->current_buffer)
{
@@ -304,7 +506,7 @@ current_buffer_removed (GeditView *view)
}
static void
-on_notify_buffer_cb (GeditView *view,
+on_notify_buffer_cb (GeditTextView *view,
GParamSpec *arg1,
gpointer userdata)
{
@@ -332,13 +534,13 @@ on_notify_buffer_cb (GeditView *view,
}
static void
-gedit_view_init (GeditView *view)
+gedit_text_view_init (GeditTextView *view)
{
GtkTargetList *tl;
gedit_debug (DEBUG_VIEW);
- view->priv = GEDIT_VIEW_GET_PRIVATE (view);
+ view->priv = GEDIT_TEXT_VIEW_GET_PRIVATE (view);
/*
* Set tab, fonts, wrap mode, colors, etc. according
@@ -350,13 +552,13 @@ gedit_view_init (GeditView *view)
editor_font = gedit_prefs_manager_get_editor_font ();
- gedit_view_set_font (view, FALSE, editor_font);
+ gedit_view_set_font (GEDIT_VIEW (view), FALSE, editor_font);
g_free (editor_font);
}
else
{
- gedit_view_set_font (view, TRUE, NULL);
+ gedit_view_set_font (GEDIT_VIEW (view), TRUE, NULL);
}
g_object_set (G_OBJECT (view),
@@ -389,11 +591,11 @@ gedit_view_init (GeditView *view)
}
static void
-gedit_view_destroy (GtkObject *object)
+gedit_text_view_destroy (GtkObject *object)
{
- GeditView *view;
+ GeditTextView *view;
- view = GEDIT_VIEW (object);
+ view = GEDIT_TEXT_VIEW (object);
if (view->priv->search_window != NULL)
{
@@ -414,27 +616,27 @@ gedit_view_destroy (GtkObject *object)
current_buffer_removed (view);
g_signal_handlers_disconnect_by_func (view, on_notify_buffer_cb, NULL);
- (* GTK_OBJECT_CLASS (gedit_view_parent_class)->destroy) (object);
+ (* GTK_OBJECT_CLASS (gedit_text_view_parent_class)->destroy) (object);
}
static void
-gedit_view_finalize (GObject *object)
+gedit_text_view_finalize (GObject *object)
{
- GeditView *view;
+ GeditTextView *view;
- view = GEDIT_VIEW (object);
+ view = GEDIT_TEXT_VIEW (object);
current_buffer_removed (view);
g_free (view->priv->old_search_text);
- (* G_OBJECT_CLASS (gedit_view_parent_class)->finalize) (object);
+ (* G_OBJECT_CLASS (gedit_text_view_parent_class)->finalize) (object);
}
static gint
-gedit_view_focus_out (GtkWidget *widget, GdkEventFocus *event)
+gedit_text_view_focus_out (GtkWidget *widget, GdkEventFocus *event)
{
- GeditView *view = GEDIT_VIEW (widget);
+ GeditTextView *view = GEDIT_TEXT_VIEW (widget);
gtk_widget_queue_draw (widget);
@@ -442,30 +644,30 @@ gedit_view_focus_out (GtkWidget *widget, GdkEventFocus *event)
if (view->priv->search_window != NULL)
hide_search_window (view, FALSE);
- (* GTK_WIDGET_CLASS (gedit_view_parent_class)->focus_out_event) (widget, event);
+ (* GTK_WIDGET_CLASS (gedit_text_view_parent_class)->focus_out_event) (widget, event);
return FALSE;
}
/**
- * gedit_view_new:
+ * gedit_text_view_new:
* @doc: a #GeditDocument
*
- * Creates a new #GeditView object displaying the @doc document.
+ * Creates a new #GeditTextView object displaying the @doc document.
* @doc cannot be NULL.
*
- * Return value: a new #GeditView
+ * Return value: a new #GeditTextView
**/
GtkWidget *
-gedit_view_new (GeditDocument *doc)
+gedit_text_view_new (GeditTextBuffer *doc)
{
GtkWidget *view;
gedit_debug_message (DEBUG_VIEW, "START");
+
+ g_return_val_if_fail (GEDIT_IS_TEXT_BUFFER (doc), NULL);
- g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), NULL);
-
- view = GTK_WIDGET (g_object_new (GEDIT_TYPE_VIEW, "buffer", doc, NULL));
+ view = GTK_WIDGET (g_object_new (GEDIT_TYPE_TEXT_VIEW, "buffer", doc, NULL));
gedit_debug_message (DEBUG_VIEW, "END: %d", G_OBJECT (view)->ref_count);
@@ -474,212 +676,6 @@ gedit_view_new (GeditDocument *doc)
return view;
}
-void
-gedit_view_cut_clipboard (GeditView *view)
-{
- GtkTextBuffer *buffer;
- GtkClipboard *clipboard;
-
- gedit_debug (DEBUG_VIEW);
-
- g_return_if_fail (GEDIT_IS_VIEW (view));
-
- buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
- g_return_if_fail (buffer != NULL);
-
- clipboard = gtk_widget_get_clipboard (GTK_WIDGET (view),
- GDK_SELECTION_CLIPBOARD);
-
- /* FIXME: what is default editability of a buffer? */
- gtk_text_buffer_cut_clipboard (buffer,
- clipboard,
- !gedit_document_get_readonly (
- GEDIT_DOCUMENT (buffer)));
-
- gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (view),
- gtk_text_buffer_get_insert (buffer),
- GEDIT_VIEW_SCROLL_MARGIN,
- FALSE,
- 0.0,
- 0.0);
-}
-
-void
-gedit_view_copy_clipboard (GeditView *view)
-{
- GtkTextBuffer *buffer;
- GtkClipboard *clipboard;
-
- gedit_debug (DEBUG_VIEW);
-
- g_return_if_fail (GEDIT_IS_VIEW (view));
-
- buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
- g_return_if_fail (buffer != NULL);
-
- clipboard = gtk_widget_get_clipboard (GTK_WIDGET (view),
- GDK_SELECTION_CLIPBOARD);
-
- gtk_text_buffer_copy_clipboard (buffer, clipboard);
-
- /* on copy do not scroll, we are already on screen */
-}
-
-void
-gedit_view_paste_clipboard (GeditView *view)
-{
- GtkTextBuffer *buffer;
- GtkClipboard *clipboard;
-
- gedit_debug (DEBUG_VIEW);
-
- g_return_if_fail (GEDIT_IS_VIEW (view));
-
- buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
- g_return_if_fail (buffer != NULL);
-
- clipboard = gtk_widget_get_clipboard (GTK_WIDGET (view),
- GDK_SELECTION_CLIPBOARD);
-
- /* FIXME: what is default editability of a buffer? */
- gtk_text_buffer_paste_clipboard (buffer,
- clipboard,
- NULL,
- !gedit_document_get_readonly (
- GEDIT_DOCUMENT (buffer)));
-
- gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (view),
- gtk_text_buffer_get_insert (buffer),
- GEDIT_VIEW_SCROLL_MARGIN,
- FALSE,
- 0.0,
- 0.0);
-}
-
-/**
- * gedit_view_delete_selection:
- * @view: a #GeditView
- *
- * Deletes the text currently selected in the #GtkTextBuffer associated
- * to the view and scroll to the cursor position.
- **/
-void
-gedit_view_delete_selection (GeditView *view)
-{
- GtkTextBuffer *buffer = NULL;
-
- gedit_debug (DEBUG_VIEW);
-
- g_return_if_fail (GEDIT_IS_VIEW (view));
-
- buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
- g_return_if_fail (buffer != NULL);
-
- /* FIXME: what is default editability of a buffer? */
- gtk_text_buffer_delete_selection (buffer,
- TRUE,
- !gedit_document_get_readonly (
- GEDIT_DOCUMENT (buffer)));
-
- gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (view),
- gtk_text_buffer_get_insert (buffer),
- GEDIT_VIEW_SCROLL_MARGIN,
- FALSE,
- 0.0,
- 0.0);
-}
-
-/**
- * gedit_view_select_all:
- * @view: a #GeditView
- *
- * Selects all the text displayed in the @view.
- **/
-void
-gedit_view_select_all (GeditView *view)
-{
- GtkTextBuffer *buffer = NULL;
- GtkTextIter start, end;
-
- gedit_debug (DEBUG_VIEW);
-
- g_return_if_fail (GEDIT_IS_VIEW (view));
-
- buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
- g_return_if_fail (buffer != NULL);
-
- gtk_text_buffer_get_bounds (buffer, &start, &end);
- gtk_text_buffer_select_range (buffer, &start, &end);
-}
-
-/**
- * gedit_view_scroll_to_cursor:
- * @view: a #GeditView
- *
- * Scrolls the @view to the cursor position.
- **/
-void
-gedit_view_scroll_to_cursor (GeditView *view)
-{
- GtkTextBuffer* buffer = NULL;
-
- gedit_debug (DEBUG_VIEW);
-
- g_return_if_fail (GEDIT_IS_VIEW (view));
-
- buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
- g_return_if_fail (buffer != NULL);
-
- gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (view),
- gtk_text_buffer_get_insert (buffer),
- 0.25,
- FALSE,
- 0.0,
- 0.0);
-}
-
-/**
- * gedit_view_set_font:
- * @view: a #GeditView
- * @def: whether to reset the default font
- * @font_name: the name of the font to use
- *
- * If @def is #TRUE, resets the font of the @view to the default font
- * otherwise sets it to @font_name.
- **/
-void
-gedit_view_set_font (GeditView *view,
- gboolean def,
- const gchar *font_name)
-{
- PangoFontDescription *font_desc = NULL;
-
- gedit_debug (DEBUG_VIEW);
-
- g_return_if_fail (GEDIT_IS_VIEW (view));
-
- if (def)
- {
- gchar *font;
-
- font = gedit_prefs_manager_get_system_font ();
- font_desc = pango_font_description_from_string (font);
- g_free (font);
- }
- else
- {
- g_return_if_fail (font_name != NULL);
-
- font_desc = pango_font_description_from_string (font_name);
- }
-
- g_return_if_fail (font_desc != NULL);
-
- gtk_widget_modify_font (GTK_WIDGET (view), font_desc);
-
- pango_font_description_free (font_desc);
-}
-
static void
add_search_completion_entry (const gchar *str)
{
@@ -701,7 +697,7 @@ add_search_completion_entry (const gchar *str)
g_return_if_fail (GTK_IS_TREE_MODEL (search_completion_model));
- model = GTK_TREE_MODEL (search_completion_model);
+ model = GTK_TREE_MODEL (search_completion_model);
/* Get the first iter in the list */
valid = gtk_tree_model_get_iter_first (model, &iter);
@@ -776,7 +772,7 @@ set_entry_background (GtkWidget *entry,
}
static gboolean
-run_search (GeditView *view,
+run_search (GeditTextView *view,
const gchar *entry_text,
gboolean search_backward,
gboolean wrap_around,
@@ -786,11 +782,11 @@ run_search (GeditView *view,
GtkTextIter match_start;
GtkTextIter match_end;
gboolean found = FALSE;
- GeditDocument *doc;
+ GeditTextBuffer *doc;
g_return_val_if_fail (view->priv->search_mode == SEARCH, FALSE);
- doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
+ doc = GEDIT_TEXT_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
start_iter = view->priv->start_search_iter;
@@ -809,12 +805,12 @@ run_search (GeditView *view,
}
/* run search */
- found = gedit_document_search_forward (doc,
- &start_iter,
- NULL,
- &match_start,
- &match_end);
- }
+ found = gedit_text_buffer_search_forward (doc,
+ &start_iter,
+ NULL,
+ &match_start,
+ &match_end);
+ }
else if (!typing)
{
/* backward and not typing */
@@ -823,11 +819,11 @@ run_search (GeditView *view,
&match_end);
/* run search */
- found = gedit_document_search_backward (doc,
- NULL,
- &start_iter,
- &match_start,
- &match_end);
+ found = gedit_text_buffer_search_backward (doc,
+ NULL,
+ &start_iter,
+ &match_start,
+ &match_end);
}
else
{
@@ -839,17 +835,17 @@ run_search (GeditView *view,
if (!found && wrap_around)
{
if (!search_backward)
- found = gedit_document_search_forward (doc,
- NULL,
- NULL, /* FIXME: set the end_inter */
- &match_start,
- &match_end);
+ found = gedit_text_buffer_search_forward (doc,
+ NULL,
+ NULL, /* FIXME: set the end_inter */
+ &match_start,
+ &match_end);
else
- found = gedit_document_search_backward (doc,
- NULL, /* FIXME: set the start_inter */
- NULL,
- &match_start,
- &match_end);
+ found = gedit_text_buffer_search_backward (doc,
+ NULL, /* FIXME: set the start_inter */
+ NULL,
+ &match_start,
+ &match_end);
}
}
else
@@ -857,7 +853,7 @@ run_search (GeditView *view,
gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc),
&start_iter,
NULL);
- }
+ }
if (found)
{
@@ -875,13 +871,13 @@ run_search (GeditView *view,
&view->priv->start_search_iter);
}
}
-
+
if (found || (*entry_text == '\0'))
{
- gedit_view_scroll_to_cursor (view);
+ gedit_view_scroll_to_cursor (GEDIT_VIEW (view));
set_entry_background (view->priv->search_entry,
- GEDIT_SEARCH_ENTRY_NORMAL);
+ GEDIT_SEARCH_ENTRY_NORMAL);
}
else
{
@@ -900,7 +896,7 @@ send_focus_change (GtkWidget *widget,
GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
g_object_ref (widget);
-
+
if (in)
GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);
else
@@ -909,9 +905,9 @@ send_focus_change (GtkWidget *widget,
fevent->focus_change.type = GDK_FOCUS_CHANGE;
fevent->focus_change.window = g_object_ref (widget->window);
fevent->focus_change.in = in;
-
+
gtk_widget_event (widget, fevent);
-
+
g_object_notify (G_OBJECT (widget), "has-focus");
g_object_unref (widget);
@@ -919,7 +915,7 @@ send_focus_change (GtkWidget *widget,
}
static void
-hide_search_window (GeditView *view, gboolean cancel)
+hide_search_window (GeditTextView *view, gboolean cancel)
{
if (view->priv->disable_popdown)
return;
@@ -929,7 +925,7 @@ hide_search_window (GeditView *view, gboolean cancel)
g_signal_handler_disconnect (view->priv->search_entry,
view->priv->search_entry_changed_id);
view->priv->search_entry_changed_id = 0;
- }
+ }
if (view->priv->typeselect_flush_timeout != 0)
{
@@ -949,7 +945,7 @@ hide_search_window (GeditView *view, gboolean cancel)
buffer = GTK_TEXT_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
gtk_text_buffer_place_cursor (buffer, &view->priv->start_search_iter);
- gedit_view_scroll_to_cursor (view);
+ gedit_view_scroll_to_cursor (GEDIT_VIEW (view));
}
/* make sure a focus event is sent for the edit area */
@@ -957,7 +953,7 @@ hide_search_window (GeditView *view, gboolean cancel)
}
static gboolean
-search_entry_flush_timeout (GeditView *view)
+search_entry_flush_timeout (GeditTextView *view)
{
GDK_THREADS_ENTER ();
@@ -970,7 +966,7 @@ search_entry_flush_timeout (GeditView *view)
}
static void
-update_search_window_position (GeditView *view)
+update_search_window_position (GeditTextView *view)
{
gint x, y;
gint view_x, view_y;
@@ -979,7 +975,7 @@ update_search_window_position (GeditView *view)
gtk_widget_realize (view->priv->search_window);
gdk_window_get_origin (view_window, &view_x, &view_y);
-
+
x = MAX (12, view_x + 12);
y = MAX (12, view_y - 12);
@@ -989,7 +985,7 @@ update_search_window_position (GeditView *view)
static gboolean
search_window_delete_event (GtkWidget *widget,
GdkEventAny *event,
- GeditView *view)
+ GeditTextView *view)
{
hide_search_window (view, FALSE);
@@ -999,7 +995,7 @@ search_window_delete_event (GtkWidget *widget,
static gboolean
search_window_button_press_event (GtkWidget *widget,
GdkEventButton *event,
- GeditView *view)
+ GeditTextView *view)
{
hide_search_window (view, FALSE);
@@ -1009,7 +1005,7 @@ search_window_button_press_event (GtkWidget *widget,
}
static void
-search_again (GeditView *view,
+search_again (GeditTextView *view,
gboolean search_backward)
{
const gchar *entry_text;
@@ -1022,7 +1018,7 @@ search_again (GeditView *view,
{
g_source_remove (view->priv->typeselect_flush_timeout);
view->priv->typeselect_flush_timeout =
- g_timeout_add (GEDIT_VIEW_SEARCH_DIALOG_TIMEOUT,
+ g_timeout_add (GEDIT_TEXT_VIEW_SEARCH_DIALOG_TIMEOUT,
(GSourceFunc)search_entry_flush_timeout,
view);
}
@@ -1041,7 +1037,7 @@ search_again (GeditView *view,
static gboolean
search_window_scroll_event (GtkWidget *widget,
GdkEventScroll *event,
- GeditView *view)
+ GeditTextView *view)
{
gboolean retval = FALSE;
@@ -1066,7 +1062,7 @@ search_window_scroll_event (GtkWidget *widget,
static gboolean
search_window_key_press_event (GtkWidget *widget,
GdkEventKey *event,
- GeditView *view)
+ GeditTextView *view)
{
gboolean retval = FALSE;
guint modifiers;
@@ -1085,13 +1081,13 @@ search_window_key_press_event (GtkWidget *widget,
{
if (view->priv->search_mode == SEARCH)
{
- GeditDocument *doc;
+ GeditTextBuffer *doc;
/* restore document search so that Find Next does the right thing */
- doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
- gedit_document_set_search_text (doc,
- view->priv->old_search_text,
- view->priv->old_search_flags);
+ doc = GEDIT_TEXT_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
+ gedit_text_buffer_set_search_text (doc,
+ view->priv->old_search_text,
+ view->priv->old_search_flags);
}
@@ -1137,21 +1133,21 @@ search_window_key_press_event (GtkWidget *widget,
static void
search_entry_activate (GtkEntry *entry,
- GeditView *view)
+ GeditTextView *view)
{
hide_search_window (view, FALSE);
}
static void
wrap_around_menu_item_toggled (GtkCheckMenuItem *checkmenuitem,
- GeditView *view)
+ GeditTextView *view)
{
view->priv->wrap_around = gtk_check_menu_item_get_active (checkmenuitem);
}
static void
match_entire_word_menu_item_toggled (GtkCheckMenuItem *checkmenuitem,
- GeditView *view)
+ GeditTextView *view)
{
GEDIT_SEARCH_SET_ENTIRE_WORD (view->priv->search_flags,
gtk_check_menu_item_get_active (checkmenuitem));
@@ -1159,7 +1155,7 @@ match_entire_word_menu_item_toggled (GtkCheckMenuItem *checkmenuitem,
static void
match_case_menu_item_toggled (GtkCheckMenuItem *checkmenuitem,
- GeditView *view)
+ GeditTextView *view)
{
GEDIT_SEARCH_SET_CASE_SENSITIVE (view->priv->search_flags,
gtk_check_menu_item_get_active (checkmenuitem));
@@ -1168,7 +1164,7 @@ match_case_menu_item_toggled (GtkCheckMenuItem *checkmenuitem,
static gboolean
real_search_enable_popdown (gpointer data)
{
- GeditView *view = (GeditView *)data;
+ GeditTextView *view = (GeditTextView *)data;
GDK_THREADS_ENTER ();
@@ -1181,7 +1177,7 @@ real_search_enable_popdown (gpointer data)
static void
search_enable_popdown (GtkWidget *widget,
- GeditView *view)
+ GeditTextView *view)
{
g_timeout_add (200, real_search_enable_popdown, view);
@@ -1190,7 +1186,7 @@ search_enable_popdown (GtkWidget *widget,
g_source_remove (view->priv->typeselect_flush_timeout);
view->priv->typeselect_flush_timeout =
- g_timeout_add (GEDIT_VIEW_SEARCH_DIALOG_TIMEOUT,
+ g_timeout_add (GEDIT_TEXT_VIEW_SEARCH_DIALOG_TIMEOUT,
(GSourceFunc)search_entry_flush_timeout,
view);
}
@@ -1198,7 +1194,7 @@ search_enable_popdown (GtkWidget *widget,
static void
search_entry_populate_popup (GtkEntry *entry,
GtkMenu *menu,
- GeditView *view)
+ GeditTextView *view)
{
GtkWidget *menu_item;
@@ -1250,7 +1246,7 @@ search_entry_insert_text (GtkEditable *editable,
const gchar *text,
gint length,
gint *position,
- GeditView *view)
+ GeditTextView *view)
{
if (view->priv->search_mode == GOTO_LINE)
{
@@ -1340,7 +1336,7 @@ search_entry_insert_text (GtkEditable *editable,
}
static void
-customize_for_search_mode (GeditView *view)
+customize_for_search_mode (GeditTextView *view)
{
if (view->priv->search_mode == SEARCH)
{
@@ -1371,7 +1367,7 @@ completion_func (GtkEntryCompletion *completion,
gchar *item = NULL;
gboolean ret = FALSE;
GtkTreeModel *model;
- GeditViewPrivate *priv = (GeditViewPrivate *)data;
+ GeditTextViewPrivate *priv = (GeditTextViewPrivate *)data;
const gchar *real_key;
if (priv->search_mode == GOTO_LINE)
@@ -1422,7 +1418,7 @@ completion_func (GtkEntryCompletion *completion,
}
static void
-ensure_search_window (GeditView *view)
+ensure_search_window (GeditTextView *view)
{
GtkWidget *frame;
GtkWidget *vbox;
@@ -1559,7 +1555,7 @@ get_selected_text (GtkTextBuffer *doc, gchar **selected_text, gint *len)
}
static void
-init_search_entry (GeditView *view)
+init_search_entry (GeditTextView *view)
{
GtkTextBuffer *buffer;
@@ -1592,8 +1588,8 @@ init_search_entry (GeditView *view)
g_free (view->priv->old_search_text);
- old_find_text = gedit_document_get_search_text (GEDIT_DOCUMENT (buffer),
- &old_find_flags);
+ old_find_text = gedit_text_buffer_get_search_text (GEDIT_TEXT_BUFFER (buffer),
+ &old_find_flags);
if (old_find_text != NULL)
{
view->priv->old_search_text = old_find_text;
@@ -1608,7 +1604,7 @@ init_search_entry (GeditView *view)
selection_exists = get_selected_text (buffer,
&find_text,
&sel_len);
-
+
if (selection_exists && (find_text != NULL) && (sel_len <= 160))
{
gtk_entry_set_text (GTK_ENTRY (view->priv->search_entry),
@@ -1626,9 +1622,9 @@ init_search_entry (GeditView *view)
static void
search_init (GtkWidget *entry,
- GeditView *view)
+ GeditTextView *view)
{
- GeditDocument *doc;
+ GeditTextBuffer *doc;
const gchar *entry_text;
/* renew the flush timeout */
@@ -1636,12 +1632,12 @@ search_init (GtkWidget *entry,
{
g_source_remove (view->priv->typeselect_flush_timeout);
view->priv->typeselect_flush_timeout =
- g_timeout_add (GEDIT_VIEW_SEARCH_DIALOG_TIMEOUT,
+ g_timeout_add (GEDIT_TEXT_VIEW_SEARCH_DIALOG_TIMEOUT,
(GSourceFunc)search_entry_flush_timeout,
view);
}
- doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
+ doc = GEDIT_TEXT_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
entry_text = gtk_entry_get_text (GTK_ENTRY (entry));
@@ -1650,15 +1646,15 @@ search_init (GtkWidget *entry,
gchar *search_text;
guint search_flags;
- search_text = gedit_document_get_search_text (doc, &search_flags);
+ search_text = gedit_text_buffer_get_search_text (doc, &search_flags);
if ((search_text == NULL) ||
(strcmp (search_text, entry_text) != 0) ||
search_flags != view->priv->search_flags)
{
- gedit_document_set_search_text (doc,
- entry_text,
- view->priv->search_flags);
+ gedit_text_buffer_set_search_text (doc,
+ entry_text,
+ view->priv->search_flags);
}
g_free (search_text);
@@ -1721,11 +1717,12 @@ search_init (GtkWidget *entry,
g_strfreev (split_text);
- moved = gedit_document_goto_line (doc, line);
- moved_offset = gedit_document_goto_line_offset (doc, line,
+ moved = gedit_document_goto_line (GEDIT_DOCUMENT (doc), line);
+ moved_offset = gedit_document_goto_line_offset (GEDIT_DOCUMENT (doc),
+ line,
line_offset);
- gedit_view_scroll_to_cursor (view);
+ gedit_view_scroll_to_cursor (GEDIT_VIEW (view));
if (!moved || !moved_offset)
set_entry_background (view->priv->search_entry,
@@ -1738,7 +1735,7 @@ search_init (GtkWidget *entry,
}
static gboolean
-start_interactive_search_real (GeditView *view)
+start_interactive_search_real (GeditTextView *view)
{
GtkTextBuffer *buffer;
@@ -1776,7 +1773,7 @@ start_interactive_search_real (GeditView *view)
init_search_entry (view);
view->priv->typeselect_flush_timeout =
- g_timeout_add (GEDIT_VIEW_SEARCH_DIALOG_TIMEOUT,
+ g_timeout_add (GEDIT_TEXT_VIEW_SEARCH_DIALOG_TIMEOUT,
(GSourceFunc) search_entry_flush_timeout,
view);
@@ -1789,19 +1786,19 @@ start_interactive_search_real (GeditView *view)
}
static gboolean
-reset_searched_text (GeditView *view)
+reset_searched_text (GeditTextView *view)
{
- GeditDocument *doc;
+ GeditTextBuffer *doc;
- doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
+ doc = GEDIT_TEXT_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
- gedit_document_set_search_text (doc, "", GEDIT_SEARCH_DONT_SET_FLAGS);
+ gedit_text_buffer_set_search_text (doc, "", GEDIT_SEARCH_DONT_SET_FLAGS);
return TRUE;
}
static gboolean
-start_interactive_search (GeditView *view)
+start_interactive_search (GeditTextView *view)
{
view->priv->search_mode = SEARCH;
@@ -1809,7 +1806,7 @@ start_interactive_search (GeditView *view)
}
static gboolean
-start_interactive_goto_line (GeditView *view)
+start_interactive_goto_line (GeditTextView *view)
{
view->priv->search_mode = GOTO_LINE;
@@ -1817,18 +1814,18 @@ start_interactive_goto_line (GeditView *view)
}
static gint
-gedit_view_expose (GtkWidget *widget,
+gedit_text_view_expose (GtkWidget *widget,
GdkEventExpose *event)
{
GtkTextView *text_view;
- GeditDocument *doc;
+ GeditTextBuffer *doc;
text_view = GTK_TEXT_VIEW (widget);
- doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (text_view));
+ doc = GEDIT_TEXT_BUFFER (gtk_text_view_get_buffer (text_view));
if ((event->window == gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT)) &&
- gedit_document_get_enable_search_highlighting (doc))
+ gedit_text_buffer_get_enable_search_highlighting (doc))
{
GdkRectangle visible_rect;
GtkTextIter iter1, iter2;
@@ -1841,12 +1838,12 @@ gedit_view_expose (GtkWidget *widget,
+ visible_rect.height, NULL);
gtk_text_iter_forward_line (&iter2);
- _gedit_document_search_region (doc,
- &iter1,
- &iter2);
+ _gedit_text_buffer_search_region (doc,
+ &iter1,
+ &iter2);
}
- return (* GTK_WIDGET_CLASS (gedit_view_parent_class)->expose_event)(widget, event);
+ return (* GTK_WIDGET_CLASS (gedit_text_view_parent_class)->expose_event)(widget, event);
}
static GdkAtom
@@ -1862,11 +1859,11 @@ drag_get_uri_target (GtkWidget *widget,
target = gtk_drag_dest_find_target (widget, context, tl);
gtk_target_list_unref (tl);
- return target;
+ return target;
}
static gboolean
-gedit_view_drag_motion (GtkWidget *widget,
+gedit_text_view_drag_motion (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
@@ -1877,7 +1874,7 @@ gedit_view_drag_motion (GtkWidget *widget,
/* Chain up to allow textview to scroll and position dnd mark, note
* that this needs to be checked if gtksourceview or gtktextview
* changes drag_motion behaviour */
- result = GTK_WIDGET_CLASS (gedit_view_parent_class)->drag_motion (widget, context, x, y, timestamp);
+ result = GTK_WIDGET_CLASS (gedit_text_view_parent_class)->drag_motion (widget, context, x, y, timestamp);
/* If this is a URL, deal with it here */
if (drag_get_uri_target (widget, context) != GDK_NONE)
@@ -1890,7 +1887,7 @@ gedit_view_drag_motion (GtkWidget *widget,
}
static void
-gedit_view_drag_data_received (GtkWidget *widget,
+gedit_text_view_drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
@@ -1907,7 +1904,7 @@ gedit_view_drag_data_received (GtkWidget *widget,
if (uri_list != NULL)
{
- g_signal_emit (widget, view_signals[DROP_URIS], 0, uri_list);
+ g_signal_emit_by_name (widget, "drop-uris", uri_list);
g_strfreev (uri_list);
gtk_drag_finish (context, TRUE, FALSE, timestamp);
@@ -1915,12 +1912,12 @@ gedit_view_drag_data_received (GtkWidget *widget,
}
else
{
- GTK_WIDGET_CLASS (gedit_view_parent_class)->drag_data_received (widget, context, x, y, selection_data, info, timestamp);
+ GTK_WIDGET_CLASS (gedit_text_view_parent_class)->drag_data_received (widget, context, x, y, selection_data, info, timestamp);
}
}
static gboolean
-gedit_view_drag_drop (GtkWidget *widget,
+gedit_text_view_drag_drop (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
@@ -1940,7 +1937,7 @@ gedit_view_drag_drop (GtkWidget *widget,
else
{
/* Chain up */
- result = GTK_WIDGET_CLASS (gedit_view_parent_class)->drag_drop (widget, context, x, y, timestamp);
+ result = GTK_WIDGET_CLASS (gedit_text_view_parent_class)->drag_drop (widget, context, x, y, timestamp);
}
return result;
@@ -1948,7 +1945,7 @@ gedit_view_drag_drop (GtkWidget *widget,
static void
show_line_numbers_toggled (GtkMenu *menu,
- GeditView *view)
+ GeditTextView *view)
{
gboolean show;
@@ -1995,7 +1992,7 @@ show_line_numbers_menu (GtkWidget *view,
}
static gboolean
-gedit_view_button_press_event (GtkWidget *widget, GdkEventButton *event)
+gedit_text_view_button_press_event (GtkWidget *widget, GdkEventButton *event)
{
if ((event->type == GDK_BUTTON_PRESS) &&
(event->button == 3) &&
@@ -2007,17 +2004,17 @@ gedit_view_button_press_event (GtkWidget *widget, GdkEventButton *event)
return TRUE;
}
- return GTK_WIDGET_CLASS (gedit_view_parent_class)->button_press_event (widget, event);
+ return GTK_WIDGET_CLASS (gedit_text_view_parent_class)->button_press_event (widget, event);
}
static void
search_highlight_updated_cb (GeditDocument *doc,
GtkTextIter *start,
GtkTextIter *end,
- GeditView *view)
+ GeditTextView *view)
{
GdkRectangle visible_rect;
- GdkRectangle updated_rect;
+ GdkRectangle updated_rect;
GdkRectangle redraw_rect;
gint y;
gint height;
@@ -2025,8 +2022,8 @@ search_highlight_updated_cb (GeditDocument *doc,
text_view = GTK_TEXT_VIEW (view);
- g_return_if_fail (gedit_document_get_enable_search_highlighting (
- GEDIT_DOCUMENT (gtk_text_view_get_buffer (text_view))));
+ g_return_if_fail (gedit_text_buffer_get_enable_search_highlighting (
+ GEDIT_TEXT_BUFFER (gtk_text_view_get_buffer (text_view))));
/* get visible area */
gtk_text_view_get_visible_rect (text_view, &visible_rect);
@@ -2161,7 +2158,7 @@ delete_line (GtkTextView *text_view,
}
static void
-gedit_view_delete_from_cursor (GtkTextView *text_view,
+gedit_text_view_delete_from_cursor (GtkTextView *text_view,
GtkDeleteType type,
gint count)
{
@@ -2175,7 +2172,7 @@ gedit_view_delete_from_cursor (GtkTextView *text_view,
delete_line (text_view, count);
break;
default:
- GTK_TEXT_VIEW_CLASS (gedit_view_parent_class)->delete_from_cursor(text_view, type, count);
+ GTK_TEXT_VIEW_CLASS (gedit_text_view_parent_class)->delete_from_cursor(text_view, type, count);
break;
}
}
diff --git a/gedit/gedit-text-view.h b/gedit/gedit-text-view.h
new file mode 100644
index 0000000..21404e3
--- /dev/null
+++ b/gedit/gedit-text-view.h
@@ -0,0 +1,93 @@
+/*
+ * gedit-view.h
+ * This file is part of gedit
+ *
+ * Copyright (C) 1998, 1999 Alex Roberts, Evan Lawrence
+ * Copyright (C) 2000, 2001 Chema Celorio, Paolo Maggi
+ * Copyright (C) 2002-2005 Paolo Maggi
+ *
+ * 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., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Modified by the gedit Team, 1998-2005. See the AUTHORS file for a
+ * list of people on the gedit Team.
+ * See the ChangeLog files for a list of changes.
+ */
+
+#ifndef __GEDIT_TEXT_VIEW_H__
+#define __GEDIT_TEXT_VIEW_H__
+
+#include <gtk/gtk.h>
+
+#include <gtksourceview/gtksourceview.h>
+#include "gedit-text-buffer.h"
+
+G_BEGIN_DECLS
+
+/*
+ * Type checking and casting macros
+ */
+#define GEDIT_TYPE_TEXT_VIEW (gedit_text_view_get_type ())
+#define GEDIT_TEXT_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GEDIT_TYPE_TEXT_VIEW, GeditTextView))
+#define GEDIT_TEXT_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GEDIT_TYPE_TEXT_VIEW, GeditTextViewClass))
+#define GEDIT_IS_TEXT_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GEDIT_TYPE_TEXT_VIEW))
+#define GEDIT_IS_TEXT_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEDIT_TYPE_TEXT_VIEW))
+#define GEDIT_TEXT_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GEDIT_TYPE_TEXT_VIEW, GeditTextViewClass))
+
+/* Private structure type */
+typedef struct _GeditTextViewPrivate GeditTextViewPrivate;
+
+/*
+ * Main object structure
+ */
+typedef struct _GeditTextView GeditTextView;
+
+struct _GeditTextView
+{
+ GtkSourceView view;
+
+ /*< private > */
+ GeditTextViewPrivate *priv;
+};
+
+/*
+ * Class definition
+ */
+typedef struct _GeditTextViewClass GeditTextViewClass;
+
+struct _GeditTextViewClass
+{
+ GtkSourceViewClass parent_class;
+
+ /* FIXME: Do we need placeholders ? */
+
+ /* Key bindings */
+ gboolean (* start_interactive_search) (GeditTextView *view);
+ gboolean (* start_interactive_goto_line)(GeditTextView *view);
+ gboolean (* reset_searched_text) (GeditTextView *view);
+};
+
+/*
+ * Public methods
+ */
+GType gedit_text_view_get_type (void) G_GNUC_CONST;
+
+GtkWidget *gedit_text_view_new (GeditTextBuffer *doc);
+
+G_END_DECLS
+
+#endif /* __GEDIT_TEXT_VIEW_H__ */
diff --git a/gedit/gedit-ui.h b/gedit/gedit-ui.h
index 121688e..13c0b0a 100644
--- a/gedit/gedit-ui.h
+++ b/gedit/gedit-ui.h
@@ -112,6 +112,15 @@ static const GtkActionEntry gedit_menu_entries[] =
/* View menu */
{ "ViewHighlightMode", NULL, N_("_Highlight Mode") },
+ { "ViewSplit", NULL, N_("S_plit") },
+ { "ViewSplitHorizontal", NULL, N_("Split _Horizontally"), NULL,
+ N_("Split Horizontally"), G_CALLBACK (_gedit_cmd_view_split_horizontally) },
+ { "ViewSplitVertical", NULL, N_("Split _Vertically"), NULL,
+ N_("Split Vertically"), G_CALLBACK (_gedit_cmd_view_split_vertically) },
+ { "ViewUnsplit", NULL, N_("_Unsplit"), NULL,
+ N_("Unsplit"), G_CALLBACK (_gedit_cmd_view_unsplit) },
+ { "ViewSwitchSplit", NULL, N_("_Switch Between Splits"), NULL,
+ N_("Switch between splits"), G_CALLBACK (_gedit_cmd_view_switch_split) },
/* Search menu */
{ "SearchFind", GTK_STOCK_FIND, N_("_Find..."), "<control>F",
diff --git a/gedit/gedit-ui.xml b/gedit/gedit-ui.xml
index 21c31a7..e235084 100644
--- a/gedit/gedit-ui.xml
+++ b/gedit/gedit-ui.xml
@@ -83,6 +83,14 @@
<separator/>
<menuitem name="ViewFullscreenMenu" action="ViewFullscreen"/>
<separator/>
+ <menu name="ViewSplitMenu" action="ViewSplit">
+ <menuitem name="ViewSplitVerticalMenu" action="ViewSplitVertical"/>
+ <menuitem name="ViewSplitHorizontalMenu" action="ViewSplitHorizontal"/>
+ <separator/>
+ <menuitem name="ViewUnsplitMenu" action="ViewUnsplit"/>
+ <menuitem name="ViewSwitchSplitMenu" action="ViewSwitchSplit"/>
+ </menu>
+ <separator/>
<menu name="ViewHighlightModeMenu" action="ViewHighlightMode">
<placeholder name="LanguagesMenuPlaceholder">
</placeholder>
diff --git a/gedit/gedit-utils.c b/gedit/gedit-utils.c
index e522b17..65eab6c 100644
--- a/gedit/gedit-utils.c
+++ b/gedit/gedit-utils.c
@@ -47,7 +47,7 @@
#include "gedit-utils.h"
-#include "gedit-document.h"
+#include "gedit-document-interface.h"
#include "gedit-prefs-manager.h"
#include "gedit-debug.h"
#include "gedit-convert.h"
diff --git a/gedit/gedit-view-container.c b/gedit/gedit-view-container.c
new file mode 100644
index 0000000..a1b4352
--- /dev/null
+++ b/gedit/gedit-view-container.c
@@ -0,0 +1,3049 @@
+/*
+ * gedit-view-container.c
+ * This file is part of gedit
+ *
+ * Copyright (C) 2005 - Paolo Maggi
+ *
+ * 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., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Modified by the gedit Team, 2005. See the AUTHORS file for a
+ * list of people on the gedit Team.
+ * See the ChangeLog files for a list of changes.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+
+#include "gedit-app.h"
+#include "gedit-notebook.h"
+#include "gedit-view-container.h"
+#include "gedit-utils.h"
+#include "gedit-io-error-message-area.h"
+#include "gedit-print-job.h"
+#include "gedit-print-preview.h"
+#include "gedit-progress-message-area.h"
+#include "gedit-debug.h"
+#include "gedit-prefs-manager-app.h"
+#include "gedit-convert.h"
+#include "gedit-enum-types.h"
+#include "gedit-text-view.h"
+#include "gedit-web-view.h"
+
+#if !GTK_CHECK_VERSION (2, 17, 1)
+#include "gedit-message-area.h"
+#endif
+
+#define GEDIT_VIEW_CONTAINER_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), GEDIT_TYPE_VIEW_CONTAINER,\
+ GeditViewContainerPrivate))
+
+#define GEDIT_VIEW_CONTAINER_KEY "GEDIT_VIEW_CONTAINER_KEY"
+
+struct _GeditViewContainerPrivate
+{
+ GeditViewContainerState state;
+ GeditViewContainerMode mode;
+
+ GeditDocument *doc;
+
+ GtkWidget *notebook;
+ GList *views;
+ GtkWidget *active_view;
+ GtkWidget *active_view_scrolled_window;
+
+ GtkWidget *message_area;
+ GtkWidget *print_preview;
+
+ GeditPrintJob *print_job;
+
+ /* tmp data for saving */
+ gchar *tmp_save_uri;
+
+ /* tmp data for loading */
+ gint tmp_line_pos;
+ const GeditEncoding *tmp_encoding;
+
+ GTimer *timer;
+ guint times_called;
+
+ GeditDocumentSaveFlags save_flags;
+
+ gint auto_save_interval;
+ guint auto_save_timeout;
+
+ gint not_editable : 1;
+ gint auto_save : 1;
+
+ gint ask_if_externally_modified : 1;
+};
+
+/* Signals */
+enum
+{
+ VIEW_ADDED,
+ VIEW_REMOVED,
+ ACTIVE_VIEW_CHANGED,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+G_DEFINE_TYPE(GeditViewContainer, gedit_view_container, GTK_TYPE_VBOX)
+
+enum
+{
+ PROP_0,
+ PROP_DOCUMENT,
+ PROP_MODE,
+ PROP_NAME,
+ PROP_STATE,
+ PROP_AUTO_SAVE,
+ PROP_AUTO_SAVE_INTERVAL
+};
+
+static gboolean gedit_view_container_auto_save (GeditViewContainer *container);
+
+static void
+install_auto_save_timeout (GeditViewContainer *container)
+{
+ gint timeout;
+
+ gedit_debug (DEBUG_VIEW_CONTAINER);
+
+ g_return_if_fail (container->priv->auto_save_timeout <= 0);
+ g_return_if_fail (container->priv->auto_save);
+ g_return_if_fail (container->priv->auto_save_interval > 0);
+
+ g_return_if_fail (container->priv->state != GEDIT_VIEW_CONTAINER_STATE_LOADING);
+ g_return_if_fail (container->priv->state != GEDIT_VIEW_CONTAINER_STATE_SAVING);
+ g_return_if_fail (container->priv->state != GEDIT_VIEW_CONTAINER_STATE_REVERTING);
+ g_return_if_fail (container->priv->state != GEDIT_VIEW_CONTAINER_STATE_LOADING_ERROR);
+ g_return_if_fail (container->priv->state != GEDIT_VIEW_CONTAINER_STATE_SAVING_ERROR);
+ g_return_if_fail (container->priv->state != GEDIT_VIEW_CONTAINER_STATE_SAVING_ERROR);
+ g_return_if_fail (container->priv->state != GEDIT_VIEW_CONTAINER_STATE_REVERTING_ERROR);
+
+ /* Add a new timeout */
+ timeout = g_timeout_add_seconds (container->priv->auto_save_interval * 60,
+ (GSourceFunc) gedit_view_container_auto_save,
+ container);
+
+ container->priv->auto_save_timeout = timeout;
+}
+
+static gboolean
+install_auto_save_timeout_if_needed (GeditViewContainer *container)
+{
+ GeditDocument *doc;
+
+ gedit_debug (DEBUG_VIEW_CONTAINER);
+
+ g_return_val_if_fail (container->priv->auto_save_timeout <= 0, FALSE);
+ g_return_val_if_fail ((container->priv->state == GEDIT_VIEW_CONTAINER_STATE_NORMAL) ||
+ (container->priv->state == GEDIT_VIEW_CONTAINER_STATE_SHOWING_PRINT_PREVIEW) ||
+ (container->priv->state == GEDIT_VIEW_CONTAINER_STATE_CLOSING), FALSE);
+
+ if (container->priv->state == GEDIT_VIEW_CONTAINER_STATE_CLOSING)
+ return FALSE;
+
+ doc = gedit_view_container_get_document (container);
+
+ if (container->priv->auto_save &&
+ !gedit_document_is_untitled (doc) &&
+ !gedit_document_get_readonly (doc))
+ {
+ install_auto_save_timeout (container);
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static void
+remove_auto_save_timeout (GeditViewContainer *container)
+{
+ gedit_debug (DEBUG_VIEW_CONTAINER);
+
+ /* FIXME: check sugli stati */
+
+ g_return_if_fail (container->priv->auto_save_timeout > 0);
+
+ g_source_remove (container->priv->auto_save_timeout);
+ container->priv->auto_save_timeout = 0;
+}
+
+static void
+gedit_view_container_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GeditViewContainer *container = GEDIT_VIEW_CONTAINER (object);
+
+ switch (prop_id)
+ {
+ case PROP_DOCUMENT:
+ g_value_take_object (value,
+ gedit_view_container_get_document (container));
+ break;
+ case PROP_MODE:
+ g_value_set_enum (value,
+ gedit_view_container_get_mode (container));
+ break;
+ case PROP_NAME:
+ g_value_take_string (value,
+ _gedit_view_container_get_name (container));
+ break;
+ case PROP_STATE:
+ g_value_set_enum (value,
+ gedit_view_container_get_state (container));
+ break;
+ case PROP_AUTO_SAVE:
+ g_value_set_boolean (value,
+ gedit_view_container_get_auto_save_enabled (container));
+ break;
+ case PROP_AUTO_SAVE_INTERVAL:
+ g_value_set_int (value,
+ gedit_view_container_get_auto_save_interval (container));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gedit_view_container_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GeditViewContainer *container = GEDIT_VIEW_CONTAINER (object);
+
+ switch (prop_id)
+ {
+ case PROP_AUTO_SAVE:
+ gedit_view_container_set_auto_save_enabled (container,
+ g_value_get_boolean (value));
+ break;
+ case PROP_AUTO_SAVE_INTERVAL:
+ gedit_view_container_set_auto_save_interval (container,
+ g_value_get_int (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gedit_view_container_finalize (GObject *object)
+{
+ GeditViewContainer *container = GEDIT_VIEW_CONTAINER (object);
+
+ if (container->priv->timer != NULL)
+ g_timer_destroy (container->priv->timer);
+
+ g_free (container->priv->tmp_save_uri);
+
+ if (container->priv->auto_save_timeout > 0)
+ remove_auto_save_timeout (container);
+
+ g_list_free (container->priv->views);
+
+ G_OBJECT_CLASS (gedit_view_container_parent_class)->finalize (object);
+}
+
+static void
+gedit_view_container_class_init (GeditViewContainerClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = gedit_view_container_finalize;
+ object_class->get_property = gedit_view_container_get_property;
+ object_class->set_property = gedit_view_container_set_property;
+
+ g_object_class_install_property (object_class,
+ PROP_DOCUMENT,
+ g_param_spec_object ("document",
+ "Document",
+ "The container's document",
+ GEDIT_TYPE_DOCUMENT,
+ G_PARAM_READABLE));
+
+ g_object_class_install_property (object_class,
+ PROP_MODE,
+ g_param_spec_enum ("mode",
+ "Mode",
+ "The container's mode",
+ GEDIT_TYPE_VIEW_CONTAINER_MODE,
+ GEDIT_VIEW_CONTAINER_MODE_TEXT,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class,
+ PROP_NAME,
+ g_param_spec_string ("name",
+ "Name",
+ "The container's name",
+ NULL,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class,
+ PROP_STATE,
+ g_param_spec_enum ("state",
+ "State",
+ "The container's state",
+ GEDIT_TYPE_VIEW_CONTAINER_STATE,
+ GEDIT_VIEW_CONTAINER_STATE_NORMAL,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class,
+ PROP_AUTO_SAVE,
+ g_param_spec_boolean ("autosave",
+ "Autosave",
+ "Autosave feature",
+ TRUE,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class,
+ PROP_AUTO_SAVE_INTERVAL,
+ g_param_spec_int ("autosave-interval",
+ "AutosaveInterval",
+ "Time between two autosaves",
+ 0,
+ G_MAXINT,
+ 0,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+
+ signals[VIEW_ADDED] =
+ g_signal_new ("view-added",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (GeditViewContainerClass, view_added),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE,
+ 1,
+ GEDIT_TYPE_VIEW);
+
+ signals[VIEW_ADDED] =
+ g_signal_new ("view-removed",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (GeditViewContainerClass, view_removed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE,
+ 1,
+ GEDIT_TYPE_VIEW);
+
+ signals[ACTIVE_VIEW_CHANGED] =
+ g_signal_new ("active-view-changed",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (GeditViewContainerClass, active_view_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE,
+ 1,
+ GEDIT_TYPE_VIEW);
+
+ g_type_class_add_private (object_class, sizeof (GeditViewContainerPrivate));
+}
+
+/**
+ * gedit_view_container_get_state:
+ * @container: a #GeditViewContainer
+ *
+ * Gets the #GeditViewContainerState of @container.
+ *
+ * Returns: the #GeditViewContainerState of @container
+ */
+GeditViewContainerState
+gedit_view_container_get_state (GeditViewContainer *container)
+{
+ g_return_val_if_fail (GEDIT_IS_VIEW_CONTAINER (container), GEDIT_VIEW_CONTAINER_STATE_NORMAL);
+
+ return container->priv->state;
+}
+
+GeditViewContainerMode
+gedit_view_container_get_mode (GeditViewContainer *container)
+{
+ g_return_val_if_fail (GEDIT_IS_VIEW_CONTAINER (container), GEDIT_VIEW_CONTAINER_MODE_TEXT);
+
+ return container->priv->mode;
+}
+
+static void
+set_cursor_according_to_state (GtkTextView *view,
+ GeditViewContainerState state)
+{
+ GdkCursor *cursor;
+ GdkWindow *text_window;
+ GdkWindow *left_window;
+
+ text_window = gtk_text_view_get_window (view, GTK_TEXT_WINDOW_TEXT);
+ left_window = gtk_text_view_get_window (view, GTK_TEXT_WINDOW_LEFT);
+
+ if ((state == GEDIT_VIEW_CONTAINER_STATE_LOADING) ||
+ (state == GEDIT_VIEW_CONTAINER_STATE_REVERTING) ||
+ (state == GEDIT_VIEW_CONTAINER_STATE_SAVING) ||
+ (state == GEDIT_VIEW_CONTAINER_STATE_PRINTING) ||
+ (state == GEDIT_VIEW_CONTAINER_STATE_PRINT_PREVIEWING) ||
+ (state == GEDIT_VIEW_CONTAINER_STATE_CLOSING))
+ {
+ cursor = gdk_cursor_new_for_display (
+ gtk_widget_get_display (GTK_WIDGET (view)),
+ GDK_WATCH);
+
+ if (text_window != NULL)
+ gdk_window_set_cursor (text_window, cursor);
+ if (left_window != NULL)
+ gdk_window_set_cursor (left_window, cursor);
+
+ gdk_cursor_unref (cursor);
+ }
+ else
+ {
+ cursor = gdk_cursor_new_for_display (
+ gtk_widget_get_display (GTK_WIDGET (view)),
+ GDK_XTERM);
+
+ if (text_window != NULL)
+ gdk_window_set_cursor (text_window, cursor);
+ if (left_window != NULL)
+ gdk_window_set_cursor (left_window, NULL);
+
+ gdk_cursor_unref (cursor);
+ }
+}
+
+static void
+view_realized (GtkWidget *view,
+ GeditViewContainer *container)
+{
+ /* FIXME: Maybe we should take care of all views? */
+ if (GTK_IS_TEXT_VIEW (view))
+ set_cursor_according_to_state (GTK_TEXT_VIEW (view), container->priv->state);
+}
+
+static void
+set_view_properties_according_to_state (GeditViewContainer *container,
+ GeditViewContainerState state)
+{
+ gboolean val;
+
+ val = ((state == GEDIT_VIEW_CONTAINER_STATE_NORMAL) &&
+ (container->priv->print_preview == NULL) &&
+ !container->priv->not_editable);
+ gedit_view_set_editable (GEDIT_VIEW (container->priv->active_view), val);
+
+ if (GEDIT_IS_TEXT_VIEW (GEDIT_TEXT_VIEW (container->priv->active_view)))
+ {
+ val = ((state != GEDIT_VIEW_CONTAINER_STATE_LOADING) &&
+ (state != GEDIT_VIEW_CONTAINER_STATE_CLOSING));
+ gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (container->priv->active_view), val);
+
+
+ val = ((state != GEDIT_VIEW_CONTAINER_STATE_LOADING) &&
+ (state != GEDIT_VIEW_CONTAINER_STATE_CLOSING) &&
+ (gedit_prefs_manager_get_highlight_current_line ()));
+ gtk_source_view_set_highlight_current_line (GTK_SOURCE_VIEW (container->priv->active_view), val);
+ }
+}
+
+static void
+gedit_view_container_set_state (GeditViewContainer *container,
+ GeditViewContainerState state)
+{
+ g_return_if_fail (GEDIT_IS_VIEW_CONTAINER (container));
+ g_return_if_fail ((state >= 0) && (state < GEDIT_VIEW_CONTAINER_NUM_OF_STATES));
+
+ if (container->priv->state == state)
+ return;
+
+ container->priv->state = state;
+
+ set_view_properties_according_to_state (container, state);
+
+ if ((state == GEDIT_VIEW_CONTAINER_STATE_LOADING_ERROR) || /* FIXME: add other states if needed */
+ (state == GEDIT_VIEW_CONTAINER_STATE_SHOWING_PRINT_PREVIEW))
+ {
+ gtk_widget_hide (container->priv->active_view_scrolled_window);
+ }
+ else
+ {
+ if (container->priv->print_preview == NULL)
+ gtk_widget_show (container->priv->active_view_scrolled_window);
+ }
+
+ /* FIXME: Should we take care of all views? */
+ if (GTK_IS_TEXT_VIEW (container->priv->active_view))
+ set_cursor_according_to_state (GTK_TEXT_VIEW (container->priv->active_view),
+ state);
+
+ g_object_notify (G_OBJECT (container), "state");
+}
+
+static void
+document_uri_notify_handler (GeditDocument *document,
+ GParamSpec *pspec,
+ GeditViewContainer *container)
+{
+ gedit_debug (DEBUG_VIEW_CONTAINER);
+
+ /* Notify the change in the URI */
+ g_object_notify (G_OBJECT (container), "name");
+}
+
+static void
+document_modified_changed (GtkTextBuffer *document,
+ GeditViewContainer *container)
+{
+ g_object_notify (G_OBJECT (container), "name");
+}
+
+static void
+set_message_area (GeditViewContainer *container,
+ GtkWidget *message_area)
+{
+ if (container->priv->message_area == message_area)
+ return;
+
+ if (container->priv->message_area != NULL)
+ gtk_widget_destroy (container->priv->message_area);
+
+ container->priv->message_area = message_area;
+
+ if (message_area == NULL)
+ return;
+
+ gtk_box_pack_start (GTK_BOX (container),
+ container->priv->message_area,
+ FALSE,
+ FALSE,
+ 0);
+
+ g_object_add_weak_pointer (G_OBJECT (container->priv->message_area),
+ (gpointer *)&container->priv->message_area);
+}
+
+/* FIXME: This can't be here when we add GeditPage */
+static void
+remove_container (GeditViewContainer *container)
+{
+ /*GeditNotebook *notebook;
+
+ notebook = GEDIT_NOTEBOOK (gtk_widget_get_parent (GTK_WIDGET (container)));
+
+ gedit_notebook_remove_page (notebook, container);*/
+}
+
+static void
+io_loading_error_message_area_response (GtkWidget *message_area,
+ gint response_id,
+ GeditViewContainer *container)
+{
+ if (response_id == GTK_RESPONSE_OK)
+ {
+ GeditDocument *doc;
+ gchar *uri;
+
+ doc = gedit_view_container_get_document (container);
+ g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
+
+ uri = gedit_document_get_uri (doc);
+ g_return_if_fail (uri != NULL);
+
+ set_message_area (container, NULL);
+ gedit_view_container_set_state (container, GEDIT_VIEW_CONTAINER_STATE_LOADING);
+
+ g_return_if_fail (container->priv->auto_save_timeout <= 0);
+
+ gedit_document_load (doc,
+ uri,
+ container->priv->tmp_encoding,
+ container->priv->tmp_line_pos,
+ FALSE);
+ }
+ else
+ {
+ remove_container (container);
+ }
+}
+
+static void
+conversion_loading_error_message_area_response (GtkWidget *message_area,
+ gint response_id,
+ GeditViewContainer *container)
+{
+ GeditDocument *doc;
+ gchar *uri;
+
+ doc = gedit_view_container_get_document (container);
+ g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
+
+ uri = gedit_document_get_uri (doc);
+ g_return_if_fail (uri != NULL);
+
+ if (response_id == GTK_RESPONSE_OK)
+ {
+ const GeditEncoding *encoding;
+
+ encoding = gedit_conversion_error_message_area_get_encoding (
+ GTK_WIDGET (message_area));
+
+ g_return_if_fail (encoding != NULL);
+
+ set_message_area (container, NULL);
+ gedit_view_container_set_state (container, GEDIT_VIEW_CONTAINER_STATE_LOADING);
+
+ container->priv->tmp_encoding = encoding;
+
+ g_return_if_fail (container->priv->auto_save_timeout <= 0);
+
+ gedit_document_load (doc,
+ uri,
+ encoding,
+ container->priv->tmp_line_pos,
+ FALSE);
+ }
+ else
+ {
+ _gedit_recent_remove (GEDIT_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (container))), uri);
+
+ remove_container (container);
+ }
+
+ g_free (uri);
+}
+
+static void
+file_already_open_warning_message_area_response (GtkWidget *message_area,
+ gint response_id,
+ GeditViewContainer *container)
+{
+ GeditView *view;
+
+ view = gedit_view_container_get_view (container);
+
+ if (response_id == GTK_RESPONSE_YES)
+ {
+ container->priv->not_editable = FALSE;
+
+ gedit_view_set_editable (GEDIT_VIEW (view),
+ TRUE);
+ }
+
+ gtk_widget_destroy (message_area);
+
+ gtk_widget_grab_focus (GTK_WIDGET (view));
+}
+
+static void
+load_cancelled (GtkWidget *area,
+ gint response_id,
+ GeditViewContainer *container)
+{
+ g_return_if_fail (GEDIT_IS_PROGRESS_MESSAGE_AREA (container->priv->message_area));
+
+ g_object_ref (container);
+ gedit_document_load_cancel (gedit_view_container_get_document (container));
+ g_object_unref (container);
+}
+
+static void
+unrecoverable_reverting_error_message_area_response (GtkWidget *message_area,
+ gint response_id,
+ GeditViewContainer *container)
+{
+ GeditView *view;
+
+ gedit_view_container_set_state (container,
+ GEDIT_VIEW_CONTAINER_STATE_NORMAL);
+
+ set_message_area (container, NULL);
+
+ view = gedit_view_container_get_view (container);
+
+ gtk_widget_grab_focus (GTK_WIDGET (view));
+
+ install_auto_save_timeout_if_needed (container);
+}
+
+#define MAX_MSG_LENGTH 100
+
+static void
+show_loading_message_area (GeditViewContainer *container)
+{
+ GtkWidget *area;
+ GeditDocument *doc = NULL;
+ gchar *name;
+ gchar *dirname = NULL;
+ gchar *msg = NULL;
+ gchar *name_markup;
+ gchar *dirname_markup;
+ gint len;
+
+ if (container->priv->message_area != NULL)
+ return;
+
+ gedit_debug (DEBUG_VIEW_CONTAINER);
+
+ doc = gedit_view_container_get_document (container);
+ g_return_if_fail (doc != NULL);
+
+ name = gedit_document_get_short_name_for_display (doc);
+ len = g_utf8_strlen (name, -1);
+
+ /* if the name is awfully long, truncate it and be done with it,
+ * otherwise also show the directory (ellipsized if needed)
+ */
+ if (len > MAX_MSG_LENGTH)
+ {
+ gchar *str;
+
+ str = gedit_utils_str_middle_truncate (name, MAX_MSG_LENGTH);
+ g_free (name);
+ name = str;
+ }
+ else
+ {
+ GFile *file;
+
+ file = gedit_document_get_location (doc);
+ if (file != NULL)
+ {
+ gchar *str;
+
+ str = gedit_utils_location_get_dirname_for_display (file);
+ g_object_unref (file);
+
+ /* use the remaining space for the dir, but use a min of 20 chars
+ * so that we do not end up with a dirname like "(a...b)".
+ * This means that in the worst case when the filename is long 99
+ * we have a title long 99 + 20, but I think it's a rare enough
+ * case to be accepcontainerle. It's justa darn title afterall :)
+ */
+ dirname = gedit_utils_str_middle_truncate (str,
+ MAX (20, MAX_MSG_LENGTH - len));
+ g_free (str);
+ }
+ }
+
+ name_markup = g_markup_printf_escaped ("<b>%s</b>", name);
+
+ if (container->priv->state == GEDIT_VIEW_CONTAINER_STATE_REVERTING)
+ {
+ if (dirname != NULL)
+ {
+ dirname_markup = g_markup_printf_escaped ("<b>%s</b>", dirname);
+
+ /* Translators: the first %s is a file name (e.g. test.txt) the second one
+ is a directory (e.g. ssh://master.gnome.org/home/users/paolo) */
+ msg = g_strdup_printf (_("Reverting %s from %s"),
+ name_markup,
+ dirname_markup);
+ g_free (dirname_markup);
+ }
+ else
+ {
+ msg = g_strdup_printf (_("Reverting %s"),
+ name_markup);
+ }
+
+ area = gedit_progress_message_area_new (GTK_STOCK_REVERT_TO_SAVED,
+ msg,
+ TRUE);
+ }
+ else
+ {
+ if (dirname != NULL)
+ {
+ dirname_markup = g_markup_printf_escaped ("<b>%s</b>", dirname);
+
+ /* Translators: the first %s is a file name (e.g. test.txt) the second one
+ is a directory (e.g. ssh://master.gnome.org/home/users/paolo) */
+ msg = g_strdup_printf (_("Loading %s from %s"),
+ name_markup,
+ dirname_markup);
+ g_free (dirname_markup);
+ }
+ else
+ {
+ msg = g_strdup_printf (_("Loading %s"),
+ name_markup);
+ }
+
+ area = gedit_progress_message_area_new (GTK_STOCK_OPEN,
+ msg,
+ TRUE);
+ }
+
+ g_signal_connect (area,
+ "response",
+ G_CALLBACK (load_cancelled),
+ container);
+
+ gtk_widget_show (area);
+
+ set_message_area (container, area);
+
+ g_free (msg);
+ g_free (name);
+ g_free (name_markup);
+ g_free (dirname);
+}
+
+static void
+show_saving_message_area (GeditViewContainer *container)
+{
+ GtkWidget *area;
+ GeditDocument *doc = NULL;
+ gchar *short_name;
+ gchar *from;
+ gchar *to = NULL;
+ gchar *from_markup;
+ gchar *to_markup;
+ gchar *msg = NULL;
+ gint len;
+
+ g_return_if_fail (container->priv->tmp_save_uri != NULL);
+
+ if (container->priv->message_area != NULL)
+ return;
+
+ gedit_debug (DEBUG_VIEW_CONTAINER);
+
+ doc = gedit_view_container_get_document (container);
+ g_return_if_fail (doc != NULL);
+
+ short_name = gedit_document_get_short_name_for_display (doc);
+
+ len = g_utf8_strlen (short_name, -1);
+
+ /* if the name is awfully long, truncate it and be done with it,
+ * otherwise also show the directory (ellipsized if needed)
+ */
+ if (len > MAX_MSG_LENGTH)
+ {
+ from = gedit_utils_str_middle_truncate (short_name,
+ MAX_MSG_LENGTH);
+ g_free (short_name);
+ }
+ else
+ {
+ gchar *str;
+
+ from = short_name;
+
+ to = gedit_utils_uri_for_display (container->priv->tmp_save_uri);
+
+ str = gedit_utils_str_middle_truncate (to,
+ MAX (20, MAX_MSG_LENGTH - len));
+ g_free (to);
+
+ to = str;
+ }
+
+ from_markup = g_markup_printf_escaped ("<b>%s</b>", from);
+
+ if (to != NULL)
+ {
+ to_markup = g_markup_printf_escaped ("<b>%s</b>", to);
+
+ /* Translators: the first %s is a file name (e.g. test.txt) the second one
+ is a directory (e.g. ssh://master.gnome.org/home/users/paolo) */
+ msg = g_strdup_printf (_("Saving %s to %s"),
+ from_markup,
+ to_markup);
+ g_free (to_markup);
+ }
+ else
+ {
+ msg = g_strdup_printf (_("Saving %s"), from_markup);
+ }
+
+ area = gedit_progress_message_area_new (GTK_STOCK_SAVE,
+ msg,
+ FALSE);
+
+ gtk_widget_show (area);
+
+ set_message_area (container, area);
+
+ g_free (msg);
+ g_free (to);
+ g_free (from);
+ g_free (from_markup);
+}
+
+static void
+message_area_set_progress (GeditViewContainer *container,
+ goffset size,
+ goffset total_size)
+{
+ if (container->priv->message_area == NULL)
+ return;
+
+ gedit_debug_message (DEBUG_VIEW_CONTAINER, "%" G_GUINT64_FORMAT "/%" G_GUINT64_FORMAT, size, total_size);
+
+ g_return_if_fail (GEDIT_IS_PROGRESS_MESSAGE_AREA (container->priv->message_area));
+
+ if (total_size == 0)
+ {
+ if (size != 0)
+ gedit_progress_message_area_pulse (
+ GEDIT_PROGRESS_MESSAGE_AREA (container->priv->message_area));
+ else
+ gedit_progress_message_area_set_fraction (
+ GEDIT_PROGRESS_MESSAGE_AREA (container->priv->message_area),
+ 0);
+ }
+ else
+ {
+ gdouble frac;
+
+ frac = (gdouble)size / (gdouble)total_size;
+
+ gedit_progress_message_area_set_fraction (
+ GEDIT_PROGRESS_MESSAGE_AREA (container->priv->message_area),
+ frac);
+ }
+}
+
+static void
+document_loading (GeditDocument *document,
+ goffset size,
+ goffset total_size,
+ GeditViewContainer *container)
+{
+ double et;
+
+ g_return_if_fail ((container->priv->state == GEDIT_VIEW_CONTAINER_STATE_LOADING) ||
+ (container->priv->state == GEDIT_VIEW_CONTAINER_STATE_REVERTING));
+
+ gedit_debug_message (DEBUG_VIEW_CONTAINER, "%" G_GUINT64_FORMAT "/%" G_GUINT64_FORMAT, size, total_size);
+
+ if (container->priv->timer == NULL)
+ {
+ g_return_if_fail (container->priv->times_called == 0);
+ container->priv->timer = g_timer_new ();
+ }
+
+ et = g_timer_elapsed (container->priv->timer, NULL);
+
+ if (container->priv->times_called == 1)
+ {
+ if ((total_size == 0) || (total_size > 51200UL) /* 50 KB */)
+ {
+ show_loading_message_area (container);
+ }
+ }
+ else
+ {
+ if ((container->priv->times_called == 3) && (total_size != 0))
+ {
+ gdouble total_time;
+
+ /* et : total_time = size : total_size */
+ total_time = (et * total_size)/size;
+
+ if ((total_time - et) > 3.0)
+ {
+ show_loading_message_area (container);
+ }
+ }
+ else
+ {
+ if (et > 3.0)
+ {
+ show_loading_message_area (container);
+ }
+ }
+ }
+
+ message_area_set_progress (container, size, total_size);
+
+ container->priv->times_called++;
+}
+
+static gboolean
+remove_container_idle (GeditViewContainer *container)
+{
+ remove_container (container);
+
+ return FALSE;
+}
+
+static void
+document_loaded (GeditDocument *document,
+ const GError *error,
+ GeditViewContainer *container)
+{
+ GtkWidget *emsg;
+ GFile *location;
+ gchar *uri;
+ const GeditEncoding *encoding;
+
+ g_return_if_fail ((container->priv->state == GEDIT_VIEW_CONTAINER_STATE_LOADING) ||
+ (container->priv->state == GEDIT_VIEW_CONTAINER_STATE_REVERTING));
+ g_return_if_fail (container->priv->auto_save_timeout <= 0);
+
+ if (container->priv->timer != NULL)
+ {
+ g_timer_destroy (container->priv->timer);
+ container->priv->timer = NULL;
+ }
+ container->priv->times_called = 0;
+
+ set_message_area (container, NULL);
+
+ location = gedit_document_get_location (document);
+ uri = gedit_document_get_uri (document);
+
+ if (error != NULL)
+ {
+ if (container->priv->state == GEDIT_VIEW_CONTAINER_STATE_LOADING)
+ gedit_view_container_set_state (container, GEDIT_VIEW_CONTAINER_STATE_LOADING_ERROR);
+ else
+ gedit_view_container_set_state (container, GEDIT_VIEW_CONTAINER_STATE_REVERTING_ERROR);
+
+ encoding = gedit_document_get_encoding (document);
+
+ if (error->domain == G_IO_ERROR &&
+ error->code == G_IO_ERROR_CANCELLED)
+ {
+ /* remove the container, but in an idle handler, since
+ * we are in the handler of doc loaded and we
+ * don't want doc and container to be finalized now.
+ */
+ g_idle_add ((GSourceFunc) remove_container_idle, container);
+
+ goto end;
+ }
+ else if (error->domain == G_IO_ERROR ||
+ error->domain == GEDIT_DOCUMENT_ERROR)
+ {
+ _gedit_recent_remove (GEDIT_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (container))), uri);
+
+ if (container->priv->state == GEDIT_VIEW_CONTAINER_STATE_LOADING_ERROR)
+ {
+ emsg = gedit_io_loading_error_message_area_new (uri,
+ error);
+ g_signal_connect (emsg,
+ "response",
+ G_CALLBACK (io_loading_error_message_area_response),
+ container);
+ }
+ else
+ {
+ g_return_if_fail (container->priv->state == GEDIT_VIEW_CONTAINER_STATE_REVERTING_ERROR);
+
+ emsg = gedit_unrecoverable_reverting_error_message_area_new (uri,
+ error);
+
+ g_signal_connect (emsg,
+ "response",
+ G_CALLBACK (unrecoverable_reverting_error_message_area_response),
+ container);
+ }
+
+ set_message_area (container, emsg);
+ }
+ else
+ {
+ g_return_if_fail ((error->domain == G_CONVERT_ERROR) ||
+ (error->domain == GEDIT_CONVERT_ERROR));
+
+ // TODO: different error messages if container->priv->state == GEDIT_VIEW_CONTAINER_STATE_REVERTING?
+ // note that while reverting encoding should be ok, so this is unlikely to happen
+ emsg = gedit_conversion_error_while_loading_message_area_new (
+ uri,
+ container->priv->tmp_encoding,
+ error);
+
+ set_message_area (container, emsg);
+
+ g_signal_connect (emsg,
+ "response",
+ G_CALLBACK (conversion_loading_error_message_area_response),
+ container);
+ }
+
+#if !GTK_CHECK_VERSION (2, 17, 1)
+ gedit_message_area_set_default_response (GEDIT_MESSAGE_AREA (emsg),
+ GTK_RESPONSE_CANCEL);
+#else
+ gtk_info_bar_set_default_response (GTK_INFO_BAR (emsg),
+ GTK_RESPONSE_CANCEL);
+#endif
+
+ gtk_widget_show (emsg);
+
+ g_object_unref (location);
+ g_free (uri);
+
+ return;
+ }
+ else
+ {
+ gchar *mime;
+ GList *all_documents;
+ GList *l;
+
+ g_return_if_fail (uri != NULL);
+
+ mime = gedit_document_get_mime_type (document);
+ _gedit_recent_add (GEDIT_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (container))),
+ uri,
+ mime);
+ g_free (mime);
+
+ /* Scroll to the cursor when the document is loaded */
+ for (l = container->priv->views; l != NULL; l = g_list_next (l))
+ {
+ gedit_view_scroll_to_cursor (GEDIT_VIEW (l->data));
+ }
+
+ all_documents = gedit_app_get_documents (gedit_app_get_default ());
+
+ for (l = all_documents; l != NULL; l = g_list_next (l))
+ {
+ GeditDocument *d = GEDIT_DOCUMENT (l->data);
+
+ if (d != document)
+ {
+ GFile *loc;
+
+ loc = gedit_document_get_location (d);
+
+ if ((loc != NULL) &&
+ g_file_equal (location, loc))
+ {
+ GtkWidget *w;
+ GeditView *view;
+
+ view = gedit_view_container_get_view (container);
+
+ container->priv->not_editable = TRUE;
+
+ w = gedit_file_already_open_warning_message_area_new (uri);
+
+ set_message_area (container, w);
+
+#if !GTK_CHECK_VERSION (2, 17, 1)
+ gedit_message_area_set_default_response (GEDIT_MESSAGE_AREA (w),
+ GTK_RESPONSE_CANCEL);
+#else
+ gtk_info_bar_set_default_response (GTK_INFO_BAR (w),
+ GTK_RESPONSE_CANCEL);
+#endif
+
+ gtk_widget_show (w);
+
+ g_signal_connect (w,
+ "response",
+ G_CALLBACK (file_already_open_warning_message_area_response),
+ container);
+
+ g_object_unref (loc);
+ break;
+ }
+
+ if (loc != NULL)
+ g_object_unref (loc);
+ }
+ }
+
+ g_list_free (all_documents);
+
+ gedit_view_container_set_state (container, GEDIT_VIEW_CONTAINER_STATE_NORMAL);
+
+ install_auto_save_timeout_if_needed (container);
+
+ container->priv->ask_if_externally_modified = TRUE;
+ }
+
+ end:
+ g_object_unref (location);
+ g_free (uri);
+
+ container->priv->tmp_line_pos = 0;
+ container->priv->tmp_encoding = NULL;
+}
+
+static void
+document_saving (GeditDocument *document,
+ goffset size,
+ goffset total_size,
+ GeditViewContainer *container)
+{
+ double et;
+
+ g_return_if_fail (container->priv->state == GEDIT_VIEW_CONTAINER_STATE_SAVING);
+
+ gedit_debug_message (DEBUG_VIEW_CONTAINER, "%" G_GUINT64_FORMAT "/%" G_GUINT64_FORMAT, size, total_size);
+
+
+ if (container->priv->timer == NULL)
+ {
+ g_return_if_fail (container->priv->times_called == 0);
+ container->priv->timer = g_timer_new ();
+ }
+
+ et = g_timer_elapsed (container->priv->timer, NULL);
+
+ if (container->priv->times_called == 1)
+ {
+ if ((total_size == 0) || (total_size > 51200UL) /* 50 KB */)
+ {
+ show_saving_message_area (container);
+ }
+ }
+ else
+ {
+ if ((container->priv->times_called == 3) && (total_size != 0))
+ {
+ gdouble total_time;
+
+ /* et : total_time = size : total_size */
+ total_time = (et * total_size)/size;
+
+ if ((total_time - et) > 3.0)
+ {
+ show_saving_message_area (container);
+ }
+ }
+ else
+ {
+ if (et > 3.0)
+ {
+ show_saving_message_area (container);
+ }
+ }
+ }
+
+ message_area_set_progress (container, size, total_size);
+
+ container->priv->times_called++;
+}
+
+static void
+end_saving (GeditViewContainer *container)
+{
+ /* Reset tmp data for saving */
+ g_free (container->priv->tmp_save_uri);
+ container->priv->tmp_save_uri = NULL;
+ container->priv->tmp_encoding = NULL;
+
+ install_auto_save_timeout_if_needed (container);
+}
+
+static void
+unrecoverable_saving_error_message_area_response (GtkWidget *message_area,
+ gint response_id,
+ GeditViewContainer *container)
+{
+ GeditView *view;
+
+ if (container->priv->print_preview != NULL)
+ gedit_view_container_set_state (container, GEDIT_VIEW_CONTAINER_STATE_SHOWING_PRINT_PREVIEW);
+ else
+ gedit_view_container_set_state (container, GEDIT_VIEW_CONTAINER_STATE_NORMAL);
+
+ end_saving (container);
+
+ set_message_area (container, NULL);
+
+ view = gedit_view_container_get_view (container);
+
+ gtk_widget_grab_focus (GTK_WIDGET (view));
+}
+
+static void
+no_backup_error_message_area_response (GtkWidget *message_area,
+ gint response_id,
+ GeditViewContainer *container)
+{
+ if (response_id == GTK_RESPONSE_YES)
+ {
+ GeditDocument *doc;
+
+ doc = gedit_view_container_get_document (container);
+ g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
+
+ set_message_area (container, NULL);
+
+ g_return_if_fail (container->priv->tmp_save_uri != NULL);
+ g_return_if_fail (container->priv->tmp_encoding != NULL);
+
+ gedit_view_container_set_state (container, GEDIT_VIEW_CONTAINER_STATE_SAVING);
+
+ /* don't bug the user again with this... */
+ container->priv->save_flags |= GEDIT_DOCUMENT_SAVE_IGNORE_BACKUP;
+
+ g_return_if_fail (container->priv->auto_save_timeout <= 0);
+
+ /* Force saving */
+ gedit_document_save (doc, container->priv->save_flags);
+ }
+ else
+ {
+ unrecoverable_saving_error_message_area_response (message_area,
+ response_id,
+ container);
+ }
+}
+
+static void
+externally_modified_error_message_area_response (GtkWidget *message_area,
+ gint response_id,
+ GeditViewContainer *container)
+{
+ if (response_id == GTK_RESPONSE_YES)
+ {
+ GeditDocument *doc;
+
+ doc = gedit_view_container_get_document (container);
+ g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
+
+ set_message_area (container, NULL);
+
+ g_return_if_fail (container->priv->tmp_save_uri != NULL);
+ g_return_if_fail (container->priv->tmp_encoding != NULL);
+
+ gedit_view_container_set_state (container, GEDIT_VIEW_CONTAINER_STATE_SAVING);
+
+ g_return_if_fail (container->priv->auto_save_timeout <= 0);
+
+ /* ignore mtime should not be persisted in save flags across saves */
+
+ /* Force saving */
+ gedit_document_save (doc, container->priv->save_flags | GEDIT_DOCUMENT_SAVE_IGNORE_MTIME);
+ }
+ else
+ {
+ unrecoverable_saving_error_message_area_response (message_area,
+ response_id,
+ container);
+ }
+}
+
+static void
+recoverable_saving_error_message_area_response (GtkWidget *message_area,
+ gint response_id,
+ GeditViewContainer *container)
+{
+ GeditDocument *doc;
+
+ doc = gedit_view_container_get_document (container);
+ g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
+
+ if (response_id == GTK_RESPONSE_OK)
+ {
+ const GeditEncoding *encoding;
+
+ encoding = gedit_conversion_error_message_area_get_encoding (
+ GTK_WIDGET (message_area));
+
+ g_return_if_fail (encoding != NULL);
+
+ set_message_area (container, NULL);
+
+ g_return_if_fail (container->priv->tmp_save_uri != NULL);
+
+ gedit_view_container_set_state (container, GEDIT_VIEW_CONTAINER_STATE_SAVING);
+
+ container->priv->tmp_encoding = encoding;
+
+ gedit_debug_message (DEBUG_VIEW_CONTAINER, "Force saving with URI '%s'", container->priv->tmp_save_uri);
+
+ g_return_if_fail (container->priv->auto_save_timeout <= 0);
+
+ gedit_document_save_as (doc,
+ container->priv->tmp_save_uri,
+ container->priv->tmp_encoding,
+ container->priv->save_flags);
+ }
+ else
+ {
+ unrecoverable_saving_error_message_area_response (message_area,
+ response_id,
+ container);
+ }
+}
+
+static void
+document_saved (GeditDocument *document,
+ const GError *error,
+ GeditViewContainer *container)
+{
+ GtkWidget *emsg;
+
+ g_return_if_fail (container->priv->state == GEDIT_VIEW_CONTAINER_STATE_SAVING);
+
+ g_return_if_fail (container->priv->tmp_save_uri != NULL);
+ g_return_if_fail (container->priv->tmp_encoding != NULL);
+ g_return_if_fail (container->priv->auto_save_timeout <= 0);
+
+ g_timer_destroy (container->priv->timer);
+ container->priv->timer = NULL;
+ container->priv->times_called = 0;
+
+ set_message_area (container, NULL);
+
+ if (error != NULL)
+ {
+ gedit_view_container_set_state (container, GEDIT_VIEW_CONTAINER_STATE_SAVING_ERROR);
+
+ if (error->domain == GEDIT_DOCUMENT_ERROR &&
+ error->code == GEDIT_DOCUMENT_ERROR_EXTERNALLY_MODIFIED)
+ {
+ /* This error is recoverable */
+ emsg = gedit_externally_modified_saving_error_message_area_new (
+ container->priv->tmp_save_uri,
+ error);
+ g_return_if_fail (emsg != NULL);
+
+ set_message_area (container, emsg);
+
+ g_signal_connect (emsg,
+ "response",
+ G_CALLBACK (externally_modified_error_message_area_response),
+ container);
+ }
+ else if ((error->domain == GEDIT_DOCUMENT_ERROR &&
+ error->code == GEDIT_DOCUMENT_ERROR_CANT_CREATE_BACKUP) ||
+ (error->domain == G_IO_ERROR &&
+ error->code == G_IO_ERROR_CANT_CREATE_BACKUP))
+ {
+ /* This error is recoverable */
+ emsg = gedit_no_backup_saving_error_message_area_new (
+ container->priv->tmp_save_uri,
+ error);
+ g_return_if_fail (emsg != NULL);
+
+ set_message_area (container, emsg);
+
+ g_signal_connect (emsg,
+ "response",
+ G_CALLBACK (no_backup_error_message_area_response),
+ container);
+ }
+ else if (error->domain == GEDIT_DOCUMENT_ERROR ||
+ error->domain == G_IO_ERROR)
+ {
+ /* These errors are _NOT_ recoverable */
+ _gedit_recent_remove (GEDIT_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (container))),
+ container->priv->tmp_save_uri);
+
+ emsg = gedit_unrecoverable_saving_error_message_area_new (container->priv->tmp_save_uri,
+ error);
+ g_return_if_fail (emsg != NULL);
+
+ set_message_area (container, emsg);
+
+ g_signal_connect (emsg,
+ "response",
+ G_CALLBACK (unrecoverable_saving_error_message_area_response),
+ container);
+ }
+ else
+ {
+ /* This error is recoverable */
+ g_return_if_fail (error->domain == G_CONVERT_ERROR);
+
+ emsg = gedit_conversion_error_while_saving_message_area_new (
+ container->priv->tmp_save_uri,
+ container->priv->tmp_encoding,
+ error);
+
+ set_message_area (container, emsg);
+
+ g_signal_connect (emsg,
+ "response",
+ G_CALLBACK (recoverable_saving_error_message_area_response),
+ container);
+ }
+
+#if !GTK_CHECK_VERSION (2, 17, 1)
+ gedit_message_area_set_default_response (GEDIT_MESSAGE_AREA (emsg),
+ GTK_RESPONSE_CANCEL);
+#else
+ gtk_info_bar_set_default_response (GTK_INFO_BAR (emsg),
+ GTK_RESPONSE_CANCEL);
+#endif
+
+ gtk_widget_show (emsg);
+ }
+ else
+ {
+ gchar *mime = gedit_document_get_mime_type (document);
+
+ _gedit_recent_add (GEDIT_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (container))),
+ container->priv->tmp_save_uri,
+ mime);
+ g_free (mime);
+
+ if (container->priv->print_preview != NULL)
+ gedit_view_container_set_state (container, GEDIT_VIEW_CONTAINER_STATE_SHOWING_PRINT_PREVIEW);
+ else
+ gedit_view_container_set_state (container, GEDIT_VIEW_CONTAINER_STATE_NORMAL);
+
+ container->priv->ask_if_externally_modified = TRUE;
+
+ end_saving (container);
+ }
+}
+
+static void
+externally_modified_notification_message_area_response (GtkWidget *message_area,
+ gint response_id,
+ GeditViewContainer *container)
+{
+ GeditView *view;
+
+ set_message_area (container, NULL);
+ view = gedit_view_container_get_view (container);
+
+ if (response_id == GTK_RESPONSE_OK)
+ {
+ _gedit_view_container_revert (container);
+ }
+ else
+ {
+ container->priv->ask_if_externally_modified = FALSE;
+
+ /* go back to normal state */
+ gedit_view_container_set_state (container, GEDIT_VIEW_CONTAINER_STATE_NORMAL);
+ }
+
+ gtk_widget_grab_focus (GTK_WIDGET (view));
+}
+
+static void
+display_externally_modified_notification (GeditViewContainer *container)
+{
+ GtkWidget *message_area;
+ GeditDocument *doc;
+ gchar *uri;
+ gboolean document_modified;
+
+ doc = gedit_view_container_get_document (container);
+ g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
+
+ /* uri cannot be NULL, we're here because
+ * the file we're editing changed on disk */
+ uri = gedit_document_get_uri (doc);
+ g_return_if_fail (uri != NULL);
+
+ document_modified = gedit_document_get_modified (doc);
+ message_area = gedit_externally_modified_message_area_new (uri, document_modified);
+ g_free (uri);
+
+ container->priv->message_area = NULL;
+ set_message_area (container, message_area);
+ gtk_widget_show (message_area);
+
+ g_signal_connect (message_area,
+ "response",
+ G_CALLBACK (externally_modified_notification_message_area_response),
+ container);
+}
+
+static gboolean
+view_focused_in (GtkWidget *widget,
+ GdkEventFocus *event,
+ GeditViewContainer *container)
+{
+ GeditDocument *doc;
+
+ g_return_val_if_fail (GEDIT_IS_VIEW_CONTAINER (container), FALSE);
+
+ /* we try to detect file changes only in the normal state */
+ if (container->priv->state != GEDIT_VIEW_CONTAINER_STATE_NORMAL)
+ {
+ return FALSE;
+ }
+
+ /* we already asked, don't bug the user again */
+ if (!container->priv->ask_if_externally_modified)
+ {
+ return FALSE;
+ }
+
+ doc = gedit_view_container_get_document (container);
+
+ /* If file was never saved or is remote we do not check */
+ if (!gedit_document_is_local (doc))
+ {
+ return FALSE;
+ }
+
+ if (gedit_document_check_externally_modified (doc))
+ {
+ gedit_view_container_set_state (container, GEDIT_VIEW_CONTAINER_STATE_EXTERNALLY_MODIFIED_NOTIFICATION);
+
+ display_externally_modified_notification (container);
+
+ return FALSE;
+ }
+
+ return FALSE;
+}
+/*
+static GMountOperation *
+container_mount_operation_factory (GeditDocument *doc,
+ gpointer userdata)
+{
+ GeditViewContainer *container = GEDIT_VIEW_CONTAINER (userdata);
+ GtkWidget *window;
+
+ window = gtk_widget_get_toplevel (GTK_WIDGET (container));
+ return gtk_mount_operation_new (GTK_WINDOW (window));
+}*/
+
+static void
+install_view (GeditViewContainer *container,
+ GtkWidget *view)
+{
+ GtkWidget *sw;
+
+ container->priv->views = g_list_append (container->priv->views, view);
+ if (!GTK_WIDGET_VISIBLE (view))
+ gtk_widget_show (view);
+
+ g_object_set_data (G_OBJECT (view), GEDIT_VIEW_CONTAINER_KEY, container);
+
+ /* FIXME: We need to know if we need viewport */
+ /* Create the scrolled window */
+ sw = gtk_scrolled_window_new (NULL, NULL);
+
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+
+ gtk_container_add (GTK_CONTAINER (sw), view);
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
+ GTK_SHADOW_IN);
+ gtk_widget_show (sw);
+
+ /* Add view to notebook */
+ gtk_notebook_append_page (GTK_NOTEBOOK (container->priv->notebook),
+ sw, NULL);
+
+ g_signal_connect_after (view,
+ "focus-in-event",
+ G_CALLBACK (view_focused_in),
+ container);
+
+ g_signal_connect_after (view,
+ "realize",
+ G_CALLBACK (view_realized),
+ container);
+
+ g_signal_emit (G_OBJECT (container),
+ signals[VIEW_ADDED],
+ 0,
+ view);
+}
+
+static void
+uninstall_view (GeditViewContainer *container,
+ GtkWidget *view)
+{
+ GtkWidget *sw;
+ gint page_num;
+
+ /* FIXME: Check that the parent is indeed a scrolled window */
+ sw = gtk_widget_get_parent (view);
+
+ page_num = gtk_notebook_page_num (GTK_NOTEBOOK (container->priv->notebook),
+ sw);
+
+ g_object_ref (view);
+
+ gtk_notebook_remove_page (GTK_NOTEBOOK (container->priv->notebook),
+ page_num);
+
+ g_signal_emit (G_OBJECT (container),
+ signals[VIEW_REMOVED],
+ 0,
+ view);
+
+ g_object_unref (view);
+}
+
+static void
+on_switch_page_cb (GtkNotebook *notebook,
+ GtkNotebookPage *page,
+ guint page_num,
+ GeditViewContainer *container)
+{
+ GtkWidget *sw;
+ GtkWidget *view;
+
+ sw = gtk_notebook_get_nth_page (notebook, page_num);
+
+ if (sw == container->priv->active_view_scrolled_window)
+ return;
+
+ view = gtk_bin_get_child (GTK_BIN (sw));
+
+ container->priv->active_view = view;
+ container->priv->active_view_scrolled_window = sw;
+
+ g_signal_emit (G_OBJECT (container),
+ signals[ACTIVE_VIEW_CHANGED],
+ 0,
+ container->priv->active_view);
+}
+
+static void
+gedit_view_container_init (GeditViewContainer *container)
+{
+ GeditLockdownMask lockdown;
+ GtkWidget *view;
+
+ container->priv = GEDIT_VIEW_CONTAINER_GET_PRIVATE (container);
+
+ container->priv->active_view = NULL;
+ container->priv->state = GEDIT_VIEW_CONTAINER_STATE_NORMAL;
+ container->priv->mode = GEDIT_VIEW_CONTAINER_MODE_TEXT;
+
+ container->priv->not_editable = FALSE;
+
+ container->priv->save_flags = 0;
+
+ container->priv->ask_if_externally_modified = TRUE;
+
+ /* Manage auto save data */
+ lockdown = gedit_app_get_lockdown (gedit_app_get_default ());
+ container->priv->auto_save = gedit_prefs_manager_get_auto_save () &&
+ !(lockdown & GEDIT_LOCKDOWN_SAVE_TO_DISK);
+ container->priv->auto_save = (container->priv->auto_save != FALSE);
+
+ container->priv->auto_save_interval = gedit_prefs_manager_get_auto_save_interval ();
+ if (container->priv->auto_save_interval <= 0)
+ container->priv->auto_save_interval = GPM_DEFAULT_AUTO_SAVE_INTERVAL;
+
+ /*FIXME
+ _gedit_document_set_mount_operation_factory (doc,
+ container_mount_operation_factory,
+ container);*/
+
+ /* Create the notebook */
+ container->priv->notebook = gtk_notebook_new ();
+ gtk_widget_show (container->priv->notebook);
+ gtk_box_pack_end (GTK_BOX (container),
+ container->priv->notebook,
+ TRUE, TRUE, 0);
+
+ g_signal_connect (container->priv->notebook,
+ "switch-page",
+ G_CALLBACK (on_switch_page_cb),
+ container);
+
+ /* Create the main document */
+ container->priv->doc = gedit_text_buffer_new ();
+
+ g_object_set_data (G_OBJECT (container->priv->doc),
+ GEDIT_VIEW_CONTAINER_KEY, container);
+
+ g_signal_connect (container->priv->doc,
+ "notify::uri",
+ G_CALLBACK (document_uri_notify_handler),
+ container);
+ g_signal_connect (container->priv->doc,
+ "modified_changed",
+ G_CALLBACK (document_modified_changed),
+ container);
+ g_signal_connect (container->priv->doc,
+ "loading",
+ G_CALLBACK (document_loading),
+ container);
+ g_signal_connect (container->priv->doc,
+ "loaded",
+ G_CALLBACK (document_loaded),
+ container);
+ g_signal_connect (container->priv->doc,
+ "saving",
+ G_CALLBACK (document_saving),
+ container);
+ g_signal_connect (container->priv->doc,
+ "saved",
+ G_CALLBACK (document_saved),
+ container);
+
+ /* Add the text view */
+ view = gedit_text_view_new (GEDIT_TEXT_BUFFER (container->priv->doc));
+ install_view (container, view);
+
+ /* FIXME: This is only for testing */
+ view = GTK_WIDGET (gedit_web_view_new ());
+ install_view (container, view);
+}
+
+GtkWidget *
+_gedit_view_container_new ()
+{
+ return GTK_WIDGET (g_object_new (GEDIT_TYPE_VIEW_CONTAINER, NULL));
+}
+
+/* Whether create is TRUE, creates a new empty document if location does
+ not refer to an existing file */
+GtkWidget *
+_gedit_view_container_new_from_uri (const gchar *uri,
+ const GeditEncoding *encoding,
+ gint line_pos,
+ gboolean create)
+{
+ GeditViewContainer *container;
+
+ g_return_val_if_fail (uri != NULL, NULL);
+
+ container = GEDIT_VIEW_CONTAINER (_gedit_view_container_new ());
+
+ _gedit_view_container_load (container,
+ uri,
+ encoding,
+ line_pos,
+ create);
+
+ return GTK_WIDGET (container);
+}
+
+/**
+ * gedit_view_container_get_view:
+ * @container: a #GeditViewContainer
+ *
+ * Gets the #GeditView inside @container.
+ *
+ * Returns: the #GeditView inside @container
+ */
+GeditView *
+gedit_view_container_get_view (GeditViewContainer *container)
+{
+ g_return_val_if_fail (GEDIT_IS_VIEW_CONTAINER (container), NULL);
+
+ return GEDIT_VIEW (container->priv->active_view);
+}
+
+GList *
+gedit_view_container_get_views (GeditViewContainer *container)
+{
+ g_return_val_if_fail (GEDIT_IS_VIEW_CONTAINER (container), NULL);
+
+ return container->priv->views;
+}
+
+/**
+ * gedit_view_container_get_document:
+ * @container: a #GeditViewContainer
+ *
+ * Gets the #GeditDocument associated to @container.
+ *
+ * Returns: the #GeditDocument associated to @container
+ */
+GeditDocument *
+gedit_view_container_get_document (GeditViewContainer *container)
+{
+ g_return_val_if_fail (GEDIT_IS_VIEW_CONTAINER (container), NULL);
+
+ return container->priv->doc;
+}
+
+#define MAX_DOC_NAME_LENGTH 40
+
+gchar *
+_gedit_view_container_get_name (GeditViewContainer *container)
+{
+ GeditDocument *doc;
+ gchar *name;
+ gchar *docname;
+ gchar *container_name;
+
+ g_return_val_if_fail (GEDIT_IS_VIEW_CONTAINER (container), NULL);
+
+ doc = gedit_view_container_get_document (container);
+
+ name = gedit_document_get_short_name_for_display (doc);
+
+ /* Truncate the name so it doesn't get insanely wide. */
+ docname = gedit_utils_str_middle_truncate (name, MAX_DOC_NAME_LENGTH);
+
+ if (gedit_document_get_modified (doc))
+ {
+ container_name = g_strdup_printf ("*%s", docname);
+ }
+ else
+ {
+ #if 0
+ if (gedit_document_get_readonly (doc))
+ {
+ container_name = g_strdup_printf ("%s [%s]", docname,
+ /*Read only*/ _("RO"));
+ }
+ else
+ {
+ container_name = g_strdup_printf ("%s", docname);
+ }
+#endif
+ container_name = g_strdup (docname);
+ }
+
+ g_free (docname);
+ g_free (name);
+
+ return container_name;
+}
+
+gchar *
+_gedit_view_container_get_tooltips (GeditViewContainer *container)
+{
+ GeditDocument *doc;
+ gchar *tip;
+ gchar *uri;
+ gchar *ruri;
+ gchar *ruri_markup;
+
+ g_return_val_if_fail (GEDIT_IS_VIEW_CONTAINER (container), NULL);
+
+ doc = gedit_view_container_get_document (container);
+
+ uri = gedit_document_get_uri_for_display (doc);
+ g_return_val_if_fail (uri != NULL, NULL);
+
+ ruri = gedit_utils_replace_home_dir_with_tilde (uri);
+ g_free (uri);
+
+ ruri_markup = g_markup_printf_escaped ("<i>%s</i>", ruri);
+
+ switch (container->priv->state)
+ {
+ gchar *content_type;
+ gchar *mime_type;
+ gchar *content_description;
+ gchar *content_full_description;
+ gchar *encoding;
+ const GeditEncoding *enc;
+
+ case GEDIT_VIEW_CONTAINER_STATE_LOADING_ERROR:
+ tip = g_strdup_printf (_("Error opening file %s"),
+ ruri_markup);
+ break;
+
+ case GEDIT_VIEW_CONTAINER_STATE_REVERTING_ERROR:
+ tip = g_strdup_printf (_("Error reverting file %s"),
+ ruri_markup);
+ break;
+
+ case GEDIT_VIEW_CONTAINER_STATE_SAVING_ERROR:
+ tip = g_strdup_printf (_("Error saving file %s"),
+ ruri_markup);
+ break;
+ default:
+ content_type = gedit_document_get_content_type (doc);
+ mime_type = gedit_document_get_mime_type (doc);
+ content_description = g_content_type_get_description (content_type);
+
+ if (content_description == NULL)
+ content_full_description = g_strdup (mime_type);
+ else
+ content_full_description = g_strdup_printf ("%s (%s)",
+ content_description, mime_type);
+
+ g_free (content_type);
+ g_free (mime_type);
+ g_free (content_description);
+
+ enc = gedit_document_get_encoding (doc);
+
+ if (enc == NULL)
+ encoding = g_strdup (_("Unicode (UTF-8)"));
+ else
+ encoding = gedit_encoding_to_string (enc);
+
+ tip = g_markup_printf_escaped ("<b>%s</b> %s\n\n"
+ "<b>%s</b> %s\n"
+ "<b>%s</b> %s",
+ _("Name:"), ruri,
+ _("MIME Type:"), content_full_description,
+ _("Encoding:"), encoding);
+
+ g_free (encoding);
+ g_free (content_full_description);
+
+ break;
+ }
+
+ g_free (ruri);
+ g_free (ruri_markup);
+
+ return tip;
+}
+
+static GdkPixbuf *
+resize_icon (GdkPixbuf *pixbuf,
+ gint size)
+{
+ gint width, height;
+
+ width = gdk_pixbuf_get_width (pixbuf);
+ height = gdk_pixbuf_get_height (pixbuf);
+
+ /* if the icon is larger than the nominal size, scale down */
+ if (MAX (width, height) > size)
+ {
+ GdkPixbuf *scaled_pixbuf;
+
+ if (width > height)
+ {
+ height = height * size / width;
+ width = size;
+ }
+ else
+ {
+ width = width * size / height;
+ height = size;
+ }
+
+ scaled_pixbuf = gdk_pixbuf_scale_simple (pixbuf,
+ width,
+ height,
+ GDK_INTERP_BILINEAR);
+ g_object_unref (pixbuf);
+ pixbuf = scaled_pixbuf;
+ }
+
+ return pixbuf;
+}
+
+static GdkPixbuf *
+get_stock_icon (GtkIconTheme *theme,
+ const gchar *stock,
+ gint size)
+{
+ GdkPixbuf *pixbuf;
+
+ pixbuf = gtk_icon_theme_load_icon (theme, stock, size, 0, NULL);
+ if (pixbuf == NULL)
+ return NULL;
+
+ return resize_icon (pixbuf, size);
+}
+
+static GdkPixbuf *
+get_icon (GtkIconTheme *theme,
+ GFile *location,
+ gint size)
+{
+ GdkPixbuf *pixbuf;
+ GtkIconInfo *icon_info;
+ GFileInfo *info;
+ GIcon *gicon;
+
+ if (location == NULL)
+ return get_stock_icon (theme, GTK_STOCK_FILE, size);
+
+ /* FIXME: Doing a sync stat is bad, this should be fixed */
+ info = g_file_query_info (location,
+ G_FILE_ATTRIBUTE_STANDARD_ICON,
+ G_FILE_QUERY_INFO_NONE,
+ NULL,
+ NULL);
+ if (info == NULL)
+ return get_stock_icon (theme, GTK_STOCK_FILE, size);
+
+ gicon = g_file_info_get_icon (info);
+
+ if (gicon == NULL)
+ {
+ g_object_unref (info);
+ return get_stock_icon (theme, GTK_STOCK_FILE, size);
+ }
+
+ icon_info = gtk_icon_theme_lookup_by_gicon (theme, gicon, size, 0);
+ g_object_unref (info);
+
+ if (icon_info == NULL)
+ return get_stock_icon (theme, GTK_STOCK_FILE, size);
+
+ pixbuf = gtk_icon_info_load_icon (icon_info, NULL);
+ gtk_icon_info_free (icon_info);
+
+ if (pixbuf == NULL)
+ return get_stock_icon (theme, GTK_STOCK_FILE, size);
+
+ return resize_icon (pixbuf, size);
+}
+
+/* FIXME: add support for theme changed. I think it should be as easy as
+ call g_object_notify (container, "name") when the icon theme changes */
+GdkPixbuf *
+_gedit_view_container_get_icon (GeditViewContainer *container)
+{
+ GdkPixbuf *pixbuf;
+ GtkIconTheme *theme;
+ GdkScreen *screen;
+ gint icon_size;
+
+ g_return_val_if_fail (GEDIT_IS_VIEW_CONTAINER (container), NULL);
+
+ screen = gtk_widget_get_screen (GTK_WIDGET (container));
+
+ theme = gtk_icon_theme_get_for_screen (screen);
+ g_return_val_if_fail (theme != NULL, NULL);
+
+ gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (GTK_WIDGET (container)),
+ GTK_ICON_SIZE_MENU,
+ NULL,
+ &icon_size);
+
+ switch (container->priv->state)
+ {
+ case GEDIT_VIEW_CONTAINER_STATE_LOADING:
+ pixbuf = get_stock_icon (theme,
+ GTK_STOCK_OPEN,
+ icon_size);
+ break;
+
+ case GEDIT_VIEW_CONTAINER_STATE_REVERTING:
+ pixbuf = get_stock_icon (theme,
+ GTK_STOCK_REVERT_TO_SAVED,
+ icon_size);
+ break;
+
+ case GEDIT_VIEW_CONTAINER_STATE_SAVING:
+ pixbuf = get_stock_icon (theme,
+ GTK_STOCK_SAVE,
+ icon_size);
+ break;
+
+ case GEDIT_VIEW_CONTAINER_STATE_PRINTING:
+ pixbuf = get_stock_icon (theme,
+ GTK_STOCK_PRINT,
+ icon_size);
+ break;
+
+ case GEDIT_VIEW_CONTAINER_STATE_PRINT_PREVIEWING:
+ case GEDIT_VIEW_CONTAINER_STATE_SHOWING_PRINT_PREVIEW:
+ pixbuf = get_stock_icon (theme,
+ GTK_STOCK_PRINT_PREVIEW,
+ icon_size);
+ break;
+
+ case GEDIT_VIEW_CONTAINER_STATE_LOADING_ERROR:
+ case GEDIT_VIEW_CONTAINER_STATE_REVERTING_ERROR:
+ case GEDIT_VIEW_CONTAINER_STATE_SAVING_ERROR:
+ case GEDIT_VIEW_CONTAINER_STATE_GENERIC_ERROR:
+ pixbuf = get_stock_icon (theme,
+ GTK_STOCK_DIALOG_ERROR,
+ icon_size);
+ break;
+
+ case GEDIT_VIEW_CONTAINER_STATE_EXTERNALLY_MODIFIED_NOTIFICATION:
+ pixbuf = get_stock_icon (theme,
+ GTK_STOCK_DIALOG_WARNING,
+ icon_size);
+ break;
+
+ default:
+ {
+ GFile *location;
+ GeditDocument *doc;
+
+ doc = gedit_view_container_get_document (container);
+
+ location = gedit_document_get_location (doc);
+ pixbuf = get_icon (theme, location, icon_size);
+
+ if (location)
+ g_object_unref (location);
+ }
+ }
+
+ return pixbuf;
+}
+
+/**
+ * gedit_view_container_get_from_document:
+ * @doc: a #GeditDocument
+ *
+ * Gets the #GeditViewContainer associated with @doc.
+ *
+ * Returns: the #GeditViewContainer associated with @doc
+ */
+GeditViewContainer *
+gedit_view_container_get_from_document (GeditDocument *doc)
+{
+ gpointer res;
+
+ g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), NULL);
+
+ res = g_object_get_data (G_OBJECT (doc), GEDIT_VIEW_CONTAINER_KEY);
+
+ return (res != NULL) ? GEDIT_VIEW_CONTAINER (res) : NULL;
+}
+
+GeditViewContainer *
+gedit_view_container_get_from_view (GeditView *view)
+{
+ gpointer res;
+
+ g_return_val_if_fail (GEDIT_IS_VIEW (view), NULL);
+
+ res = g_object_get_data (G_OBJECT (view), GEDIT_VIEW_CONTAINER_KEY);
+
+ return (res != NULL) ? GEDIT_VIEW_CONTAINER (res) : NULL;
+}
+
+void
+_gedit_view_container_load (GeditViewContainer *container,
+ const gchar *uri,
+ const GeditEncoding *encoding,
+ gint line_pos,
+ gboolean create)
+{
+ g_return_if_fail (GEDIT_IS_VIEW_CONTAINER (container));
+ g_return_if_fail (container->priv->state == GEDIT_VIEW_CONTAINER_STATE_NORMAL);
+
+ gedit_view_container_set_state (container, GEDIT_VIEW_CONTAINER_STATE_LOADING);
+
+ container->priv->tmp_line_pos = line_pos;
+ container->priv->tmp_encoding = encoding;
+
+ if (container->priv->auto_save_timeout > 0)
+ remove_auto_save_timeout (container);
+
+ gedit_document_load (container->priv->doc,
+ uri,
+ encoding,
+ line_pos,
+ create);
+}
+
+void
+_gedit_view_container_revert (GeditViewContainer *container)
+{
+ GeditDocument *doc;
+ gchar *uri;
+
+ g_return_if_fail (GEDIT_IS_VIEW_CONTAINER (container));
+ g_return_if_fail ((container->priv->state == GEDIT_VIEW_CONTAINER_STATE_NORMAL) ||
+ (container->priv->state == GEDIT_VIEW_CONTAINER_STATE_EXTERNALLY_MODIFIED_NOTIFICATION));
+
+ if (container->priv->state == GEDIT_VIEW_CONTAINER_STATE_EXTERNALLY_MODIFIED_NOTIFICATION)
+ {
+ set_message_area (container, NULL);
+ }
+
+ doc = gedit_view_container_get_document (container);
+ g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
+
+ gedit_view_container_set_state (container, GEDIT_VIEW_CONTAINER_STATE_REVERTING);
+
+ uri = gedit_document_get_uri (doc);
+ g_return_if_fail (uri != NULL);
+
+ container->priv->tmp_line_pos = 0;
+ container->priv->tmp_encoding = gedit_document_get_encoding (doc);
+
+ if (container->priv->auto_save_timeout > 0)
+ remove_auto_save_timeout (container);
+
+ gedit_document_load (doc,
+ uri,
+ container->priv->tmp_encoding,
+ 0,
+ FALSE);
+
+ g_free (uri);
+}
+
+void
+_gedit_view_container_save (GeditViewContainer *container)
+{
+ GeditDocument *doc;
+ GeditDocumentSaveFlags save_flags;
+
+ g_return_if_fail (GEDIT_IS_VIEW_CONTAINER (container));
+ g_return_if_fail ((container->priv->state == GEDIT_VIEW_CONTAINER_STATE_NORMAL) ||
+ (container->priv->state == GEDIT_VIEW_CONTAINER_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) ||
+ (container->priv->state == GEDIT_VIEW_CONTAINER_STATE_SHOWING_PRINT_PREVIEW));
+ g_return_if_fail (container->priv->tmp_save_uri == NULL);
+ g_return_if_fail (container->priv->tmp_encoding == NULL);
+
+ doc = gedit_view_container_get_document (container);
+ g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
+ g_return_if_fail (!gedit_document_is_untitled (doc));
+
+ if (container->priv->state == GEDIT_VIEW_CONTAINER_STATE_EXTERNALLY_MODIFIED_NOTIFICATION)
+ {
+ /* We already told the user about the external
+ * modification: hide the message area and set
+ * the save flag.
+ */
+
+ set_message_area (container, NULL);
+ save_flags = container->priv->save_flags | GEDIT_DOCUMENT_SAVE_IGNORE_MTIME;
+ }
+ else
+ {
+ save_flags = container->priv->save_flags;
+ }
+
+ gedit_view_container_set_state (container, GEDIT_VIEW_CONTAINER_STATE_SAVING);
+
+ /* uri used in error messages, will be freed in document_saved */
+ container->priv->tmp_save_uri = gedit_document_get_uri (doc);
+ container->priv->tmp_encoding = gedit_document_get_encoding (doc);
+
+ if (container->priv->auto_save_timeout > 0)
+ remove_auto_save_timeout (container);
+
+ gedit_document_save (doc, save_flags);
+}
+
+static gboolean
+gedit_view_container_auto_save (GeditViewContainer *container)
+{
+ GeditDocument *doc;
+
+ gedit_debug (DEBUG_VIEW_CONTAINER);
+
+ g_return_val_if_fail (container->priv->tmp_save_uri == NULL, FALSE);
+ g_return_val_if_fail (container->priv->tmp_encoding == NULL, FALSE);
+
+ doc = gedit_view_container_get_document (container);
+
+ g_return_val_if_fail (!gedit_document_is_untitled (doc), FALSE);
+ g_return_val_if_fail (!gedit_document_get_readonly (doc), FALSE);
+
+ g_return_val_if_fail (container->priv->auto_save_timeout > 0, FALSE);
+ g_return_val_if_fail (container->priv->auto_save, FALSE);
+ g_return_val_if_fail (container->priv->auto_save_interval > 0, FALSE);
+
+ if (!gedit_document_get_modified (doc))
+ {
+ gedit_debug_message (DEBUG_VIEW_CONTAINER, "Document not modified");
+
+ return TRUE;
+ }
+
+ if ((container->priv->state != GEDIT_VIEW_CONTAINER_STATE_NORMAL) &&
+ (container->priv->state != GEDIT_VIEW_CONTAINER_STATE_SHOWING_PRINT_PREVIEW))
+ {
+ /* Retry after 30 seconds */
+ guint timeout;
+
+ gedit_debug_message (DEBUG_VIEW_CONTAINER, "Retry after 30 seconds");
+
+ /* Add a new timeout */
+ timeout = g_timeout_add_seconds (30,
+ (GSourceFunc) gedit_view_container_auto_save,
+ container);
+
+ container->priv->auto_save_timeout = timeout;
+
+ /* Returns FALSE so the old timeout is "destroyed" */
+ return FALSE;
+ }
+
+ gedit_view_container_set_state (container, GEDIT_VIEW_CONTAINER_STATE_SAVING);
+
+ /* uri used in error messages, will be freed in document_saved */
+ container->priv->tmp_save_uri = gedit_document_get_uri (doc);
+ container->priv->tmp_encoding = gedit_document_get_encoding (doc);
+
+ /* Set auto_save_timeout to 0 since the timeout is going to be destroyed */
+ container->priv->auto_save_timeout = 0;
+
+ /* Since we are autosaving, we need to preserve the backup that was produced
+ the last time the user "manually" saved the file. In the case a recoverable
+ error happens while saving, the last backup is not preserved since the user
+ expressed his willing of saving the file */
+ gedit_document_save (doc, container->priv->save_flags | GEDIT_DOCUMENT_SAVE_PRESERVE_BACKUP);
+
+ gedit_debug_message (DEBUG_VIEW_CONTAINER, "Done");
+
+ /* Returns FALSE so the old timeout is "destroyed" */
+ return FALSE;
+}
+
+void
+_gedit_view_container_save_as (GeditViewContainer *container,
+ const gchar *uri,
+ const GeditEncoding *encoding)
+{
+ GeditDocument *doc;
+ GeditDocumentSaveFlags save_flags;
+
+ g_return_if_fail (GEDIT_IS_VIEW_CONTAINER (container));
+ g_return_if_fail ((container->priv->state == GEDIT_VIEW_CONTAINER_STATE_NORMAL) ||
+ (container->priv->state == GEDIT_VIEW_CONTAINER_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) ||
+ (container->priv->state == GEDIT_VIEW_CONTAINER_STATE_SHOWING_PRINT_PREVIEW));
+ g_return_if_fail (encoding != NULL);
+
+ g_return_if_fail (container->priv->tmp_save_uri == NULL);
+ g_return_if_fail (container->priv->tmp_encoding == NULL);
+
+ doc = gedit_view_container_get_document (container);
+ g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
+
+ /* reset the save flags, when saving as */
+ container->priv->save_flags = 0;
+
+ if (container->priv->state == GEDIT_VIEW_CONTAINER_STATE_EXTERNALLY_MODIFIED_NOTIFICATION)
+ {
+ /* We already told the user about the external
+ * modification: hide the message area and set
+ * the save flag.
+ */
+
+ set_message_area (container, NULL);
+ save_flags = container->priv->save_flags | GEDIT_DOCUMENT_SAVE_IGNORE_MTIME;
+ }
+ else
+ {
+ save_flags = container->priv->save_flags;
+ }
+
+ gedit_view_container_set_state (container, GEDIT_VIEW_CONTAINER_STATE_SAVING);
+
+ /* uri used in error messages... strdup because errors are async
+ * and the string can go away, will be freed in document_saved */
+ container->priv->tmp_save_uri = g_strdup (uri);
+ container->priv->tmp_encoding = encoding;
+
+ if (container->priv->auto_save_timeout > 0)
+ remove_auto_save_timeout (container);
+
+ gedit_document_save_as (doc, uri, encoding, container->priv->save_flags);
+}
+
+#define GEDIT_PAGE_SETUP_KEY "gedit-page-setup-key"
+#define GEDIT_PRINT_SETTINGS_KEY "gedit-print-settings-key"
+
+static GtkPageSetup *
+get_page_setup (GeditViewContainer *container)
+{
+ gpointer data;
+ GeditDocument *doc;
+
+ doc = gedit_view_container_get_document (container);
+
+ data = g_object_get_data (G_OBJECT (doc),
+ GEDIT_PAGE_SETUP_KEY);
+
+ if (data == NULL)
+ {
+ return _gedit_app_get_default_page_setup (gedit_app_get_default());
+ }
+ else
+ {
+ return gtk_page_setup_copy (GTK_PAGE_SETUP (data));
+ }
+}
+
+static GtkPrintSettings *
+get_print_settings (GeditViewContainer *container)
+{
+ gpointer data;
+ GeditDocument *doc;
+
+ doc = gedit_view_container_get_document (container);
+
+ data = g_object_get_data (G_OBJECT (doc),
+ GEDIT_PRINT_SETTINGS_KEY);
+
+ if (data == NULL)
+ {
+ return _gedit_app_get_default_print_settings (gedit_app_get_default());
+ }
+ else
+ {
+ return gtk_print_settings_copy (GTK_PRINT_SETTINGS (data));
+ }
+}
+
+/* FIXME: show the message area only if the operation will be "long" */
+static void
+printing_cb (GeditPrintJob *job,
+ GeditPrintJobStatus status,
+ GeditViewContainer *container)
+{
+ g_return_if_fail (GEDIT_IS_PROGRESS_MESSAGE_AREA (container->priv->message_area));
+
+ gtk_widget_show (container->priv->message_area);
+
+ gedit_progress_message_area_set_text (GEDIT_PROGRESS_MESSAGE_AREA (container->priv->message_area),
+ gedit_print_job_get_status_string (job));
+
+ gedit_progress_message_area_set_fraction (GEDIT_PROGRESS_MESSAGE_AREA (container->priv->message_area),
+ gedit_print_job_get_progress (job));
+}
+
+static void
+done_printing_cb (GeditPrintJob *job,
+ GeditPrintJobResult result,
+ const GError *error,
+ GeditViewContainer *container)
+{
+ GeditView *view;
+
+ g_return_if_fail (container->priv->state == GEDIT_VIEW_CONTAINER_STATE_PRINT_PREVIEWING ||
+ container->priv->state == GEDIT_VIEW_CONTAINER_STATE_SHOWING_PRINT_PREVIEW ||
+ container->priv->state == GEDIT_VIEW_CONTAINER_STATE_PRINTING);
+
+ if (container->priv->state == GEDIT_VIEW_CONTAINER_STATE_SHOWING_PRINT_PREVIEW)
+ {
+ /* print preview has been destroyed... */
+ container->priv->print_preview = NULL;
+ }
+ else
+ {
+ g_return_if_fail (GEDIT_IS_PROGRESS_MESSAGE_AREA (container->priv->message_area));
+
+ set_message_area (container, NULL); /* destroy the message area */
+ }
+
+ // TODO: check status and error
+
+ /* Save the print settings and the page setup */
+ if (result == GEDIT_PRINT_JOB_RESULT_OK)
+ {
+ GeditDocument *doc;
+ GtkPrintSettings *settings;
+ GtkPageSetup *page_setup;
+
+ doc = gedit_view_container_get_document (container);
+
+ settings = gedit_print_job_get_print_settings (job);
+
+ /* remember settings for this document */
+ g_object_set_data_full (G_OBJECT (doc),
+ GEDIT_PRINT_SETTINGS_KEY,
+ g_object_ref (settings),
+ (GDestroyNotify)g_object_unref);
+
+ /* make them the default */
+ _gedit_app_set_default_print_settings (gedit_app_get_default (),
+ settings);
+
+ page_setup = gedit_print_job_get_page_setup (job);
+
+ /* remember page setup for this document */
+ g_object_set_data_full (G_OBJECT (doc),
+ GEDIT_PAGE_SETUP_KEY,
+ g_object_ref (page_setup),
+ (GDestroyNotify)g_object_unref);
+
+ /* make it the default */
+ _gedit_app_set_default_page_setup (gedit_app_get_default (),
+ page_setup);
+ }
+
+#if 0
+ if (container->priv->print_preview != NULL)
+ {
+ /* If we were printing while showing the print preview,
+ see bug #352658 */
+ gtk_widget_destroy (container->priv->print_preview);
+ g_return_if_fail (container->priv->state == GEDIT_VIEW_CONTAINER_STATE_PRINTING);
+ }
+#endif
+
+ gedit_view_container_set_state (container, GEDIT_VIEW_CONTAINER_STATE_NORMAL);
+
+ view = gedit_view_container_get_view (container);
+ gtk_widget_grab_focus (GTK_WIDGET (view));
+
+ g_object_unref (container->priv->print_job);
+ container->priv->print_job = NULL;
+}
+
+#if 0
+static void
+print_preview_destroyed (GtkWidget *preview,
+ GeditViewContainer *container)
+{
+ container->priv->print_preview = NULL;
+
+ if (container->priv->state == GEDIT_VIEW_CONTAINER_STATE_SHOWING_PRINT_PREVIEW)
+ {
+ GeditView *view;
+
+ gedit_view_container_set_state (container, GEDIT_VIEW_CONTAINER_STATE_NORMAL);
+
+ view = gedit_view_container_get_view (container);
+ gtk_widget_grab_focus (GTK_WIDGET (view));
+ }
+ else
+ {
+ /* This should happen only when printing while showing the print
+ * preview. In this case let us continue whithout changing
+ * the state and show the document. See bug #352658 */
+ gtk_widget_show (container->priv->view_scrolled_window);
+
+ g_return_if_fail (container->priv->state == GEDIT_VIEW_CONTAINER_STATE_PRINTING);
+ }
+}
+#endif
+
+static void
+show_preview_cb (GeditPrintJob *job,
+ GeditPrintPreview *preview,
+ GeditViewContainer *container)
+{
+// g_return_if_fail (container->priv->state == GEDIT_VIEW_CONTAINER_STATE_PRINT_PREVIEWING);
+ g_return_if_fail (container->priv->print_preview == NULL);
+
+ set_message_area (container, NULL); /* destroy the message area */
+
+ container->priv->print_preview = GTK_WIDGET (preview);
+ gtk_box_pack_end (GTK_BOX (container),
+ container->priv->print_preview,
+ TRUE,
+ TRUE,
+ 0);
+ gtk_widget_show (container->priv->print_preview);
+ gtk_widget_grab_focus (container->priv->print_preview);
+
+/* when the preview gets destroyed we get "done" signal
+ g_signal_connect (container->priv->print_preview,
+ "destroy",
+ G_CALLBACK (print_preview_destroyed),
+ container);
+*/
+ gedit_view_container_set_state (container, GEDIT_VIEW_CONTAINER_STATE_SHOWING_PRINT_PREVIEW);
+}
+
+#if 0
+
+static void
+set_print_preview (GeditViewContainer *container,
+ GtkWidget *print_preview)
+{
+ if (container->priv->print_preview == print_preview)
+ return;
+
+ if (container->priv->print_preview != NULL)
+ gtk_widget_destroy (container->priv->print_preview);
+
+ container->priv->print_preview = print_preview;
+
+ gtk_box_pack_end (GTK_BOX (container),
+ container->priv->print_preview,
+ TRUE,
+ TRUE,
+ 0);
+
+ gtk_widget_grab_focus (container->priv->print_preview);
+
+ g_signal_connect (container->priv->print_preview,
+ "destroy",
+ G_CALLBACK (print_preview_destroyed),
+ container);
+}
+
+static void
+preview_finished_cb (GtkSourcePrintJob *pjob, GeditViewContainer *container)
+{
+ GnomePrintJob *gjob;
+ GtkWidget *preview = NULL;
+
+ g_return_if_fail (GEDIT_IS_PROGRESS_MESSAGE_AREA (container->priv->message_area));
+ set_message_area (container, NULL); /* destroy the message area */
+
+ gjob = gtk_source_print_job_get_print_job (pjob);
+
+ preview = gedit_print_job_preview_new (gjob);
+ g_object_unref (gjob);
+
+ set_print_preview (container, preview);
+
+ gtk_widget_show (preview);
+ g_object_unref (pjob);
+
+ gedit_view_container_set_state (container, GEDIT_VIEW_CONTAINER_STATE_SHOWING_PRINT_PREVIEW);
+}
+
+
+#endif
+
+static void
+print_cancelled (GtkWidget *area,
+ gint response_id,
+ GeditViewContainer *container)
+{
+ g_return_if_fail (GEDIT_IS_PROGRESS_MESSAGE_AREA (container->priv->message_area));
+
+ gedit_print_job_cancel (container->priv->print_job);
+
+ g_debug ("print_cancelled");
+}
+
+static void
+show_printing_message_area (GeditViewContainer *container,
+ gboolean preview)
+{
+ GtkWidget *area;
+
+ if (preview)
+ area = gedit_progress_message_area_new (GTK_STOCK_PRINT_PREVIEW,
+ "",
+ TRUE);
+ else
+ area = gedit_progress_message_area_new (GTK_STOCK_PRINT,
+ "",
+ TRUE);
+
+ g_signal_connect (area,
+ "response",
+ G_CALLBACK (print_cancelled),
+ container);
+
+ set_message_area (container, area);
+}
+
+#if !GTK_CHECK_VERSION (2, 17, 4)
+
+static void
+page_setup_done_cb (GtkPageSetup *setup,
+ GeditViewContainer *container)
+{
+ if (setup != NULL)
+ {
+ GeditDocument *doc;
+
+ doc = gedit_view_container_get_document (container);
+
+ /* remember it for this document */
+ g_object_set_data_full (G_OBJECT (doc),
+ GEDIT_PAGE_SETUP_KEY,
+ g_object_ref (setup),
+ (GDestroyNotify)g_object_unref);
+
+ /* make it the default */
+ _gedit_app_set_default_page_setup (gedit_app_get_default(),
+ setup);
+ }
+}
+
+void
+_gedit_view_container_page_setup (GeditViewContainer *container)
+{
+ GtkPageSetup *setup;
+ GtkPrintSettings *settings;
+
+ g_return_if_fail (GEDIT_IS_VIEW_CONTAINER (container));
+
+ setup = get_page_setup (container);
+ settings = get_print_settings (container);
+
+ gtk_print_run_page_setup_dialog_async (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (container))),
+ setup,
+ settings,
+ (GtkPageSetupDoneFunc) page_setup_done_cb,
+ container);
+
+ /* CHECK: should we unref setup and settings? */
+}
+
+#endif
+
+static void
+gedit_view_container_print_or_print_preview (GeditViewContainer *container,
+ GtkPrintOperationAction print_action)
+{
+ GeditView *view;
+ gboolean is_preview;
+ GtkPageSetup *setup;
+ GtkPrintSettings *settings;
+ GtkPrintOperationResult res;
+ GError *error = NULL;
+
+ g_return_if_fail (container->priv->print_job == NULL);
+ g_return_if_fail (container->priv->state == GEDIT_VIEW_CONTAINER_STATE_NORMAL);
+
+ view = gedit_view_container_get_view (container);
+
+ is_preview = (print_action == GTK_PRINT_OPERATION_ACTION_PREVIEW);
+
+ container->priv->print_job = gedit_print_job_new (view);
+ g_object_add_weak_pointer (G_OBJECT (container->priv->print_job),
+ (gpointer *) &container->priv->print_job);
+
+ show_printing_message_area (container, is_preview);
+
+ g_signal_connect (container->priv->print_job,
+ "printing",
+ G_CALLBACK (printing_cb),
+ container);
+ g_signal_connect (container->priv->print_job,
+ "show-preview",
+ G_CALLBACK (show_preview_cb),
+ container);
+ g_signal_connect (container->priv->print_job,
+ "done",
+ G_CALLBACK (done_printing_cb),
+ container);
+
+ if (is_preview)
+ gedit_view_container_set_state (container, GEDIT_VIEW_CONTAINER_STATE_PRINT_PREVIEWING);
+ else
+ gedit_view_container_set_state (container, GEDIT_VIEW_CONTAINER_STATE_PRINTING);
+
+ setup = get_page_setup (container);
+ settings = get_print_settings (container);
+
+ res = gedit_print_job_print (container->priv->print_job,
+ print_action,
+ setup,
+ settings,
+ GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (container))),
+ &error);
+
+ // TODO: manage res in the correct way
+ if (res == GTK_PRINT_OPERATION_RESULT_ERROR)
+ {
+ /* FIXME: go in error state */
+ gedit_view_container_set_state (container, GEDIT_VIEW_CONTAINER_STATE_NORMAL);
+ g_warning ("Async print preview failed (%s)", error->message);
+ g_object_unref (container->priv->print_job);
+ g_error_free (error);
+ }
+}
+
+void
+_gedit_view_container_print (GeditViewContainer *container)
+{
+ g_return_if_fail (GEDIT_IS_VIEW_CONTAINER (container));
+
+ /* FIXME: currently we can have just one printoperation going on
+ * at a given time, so before starting the print we close the preview.
+ * Would be nice to handle it properly though */
+ if (container->priv->state == GEDIT_VIEW_CONTAINER_STATE_SHOWING_PRINT_PREVIEW)
+ {
+ gtk_widget_destroy (container->priv->print_preview);
+ }
+
+ gedit_view_container_print_or_print_preview (container,
+ GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG);
+}
+
+void
+_gedit_view_container_print_preview (GeditViewContainer *container)
+{
+ g_return_if_fail (GEDIT_IS_VIEW_CONTAINER (container));
+
+ gedit_view_container_print_or_print_preview (container,
+ GTK_PRINT_OPERATION_ACTION_PREVIEW);
+}
+
+void
+_gedit_view_container_mark_for_closing (GeditViewContainer *container)
+{
+ g_return_if_fail (GEDIT_IS_VIEW_CONTAINER (container));
+ g_return_if_fail (container->priv->state == GEDIT_VIEW_CONTAINER_STATE_NORMAL);
+
+ gedit_view_container_set_state (container, GEDIT_VIEW_CONTAINER_STATE_CLOSING);
+}
+
+gboolean
+_gedit_view_container_can_close (GeditViewContainer *container)
+{
+ GeditDocument *doc;
+ GeditViewContainerState ts;
+
+ g_return_val_if_fail (GEDIT_IS_VIEW_CONTAINER (container), FALSE);
+
+ ts = gedit_view_container_get_state (container);
+
+ /* if we are loading or reverting, the container can be closed */
+ if ((ts == GEDIT_VIEW_CONTAINER_STATE_LOADING) ||
+ (ts == GEDIT_VIEW_CONTAINER_STATE_LOADING_ERROR) ||
+ (ts == GEDIT_VIEW_CONTAINER_STATE_REVERTING) ||
+ (ts == GEDIT_VIEW_CONTAINER_STATE_REVERTING_ERROR)) /* CHECK: I'm not sure this is the right behavior for REVERTING ERROR */
+ return TRUE;
+
+ /* Do not close container with saving errors */
+ if (ts == GEDIT_VIEW_CONTAINER_STATE_SAVING_ERROR)
+ return FALSE;
+
+ doc = gedit_view_container_get_document (container);
+
+ /* TODO: we need to save the file also if it has been externally
+ modified - Paolo (Oct 10, 2005) */
+
+ return (!gedit_document_get_modified (doc) &&
+ !gedit_document_get_deleted (doc));
+}
+
+/**
+ * gedit_view_container_get_auto_save_enabled:
+ * @container: a #GeditViewContainer
+ *
+ * Gets the current state for the autosave feature
+ *
+ * Return value: %TRUE if the autosave is enabled, else %FALSE
+ **/
+gboolean
+gedit_view_container_get_auto_save_enabled (GeditViewContainer *container)
+{
+ gedit_debug (DEBUG_VIEW_CONTAINER);
+
+ g_return_val_if_fail (GEDIT_IS_VIEW_CONTAINER (container), FALSE);
+
+ return container->priv->auto_save;
+}
+
+/**
+ * gedit_view_container_set_auto_save_enabled:
+ * @container: a #GeditViewContainer
+ * @enable: enable (%TRUE) or disable (%FALSE) auto save
+ *
+ * Enables or disables the autosave feature. It does not install an
+ * autosave timeout if the document is new or is read-only
+ **/
+void
+gedit_view_container_set_auto_save_enabled (GeditViewContainer *container,
+ gboolean enable)
+{
+ GeditDocument *doc = NULL;
+ GeditLockdownMask lockdown;
+
+ gedit_debug (DEBUG_VIEW_CONTAINER);
+
+ g_return_if_fail (GEDIT_IS_VIEW_CONTAINER (container));
+
+ /* Force disabling when lockdown is active */
+ lockdown = gedit_app_get_lockdown (gedit_app_get_default());
+ if (lockdown & GEDIT_LOCKDOWN_SAVE_TO_DISK)
+ enable = FALSE;
+
+ doc = gedit_view_container_get_document (container);
+
+ if (container->priv->auto_save == enable)
+ return;
+
+ container->priv->auto_save = enable;
+
+ if (enable &&
+ (container->priv->auto_save_timeout <=0) &&
+ !gedit_document_is_untitled (doc) &&
+ !gedit_document_get_readonly (doc))
+ {
+ if ((container->priv->state != GEDIT_VIEW_CONTAINER_STATE_LOADING) &&
+ (container->priv->state != GEDIT_VIEW_CONTAINER_STATE_SAVING) &&
+ (container->priv->state != GEDIT_VIEW_CONTAINER_STATE_REVERTING) &&
+ (container->priv->state != GEDIT_VIEW_CONTAINER_STATE_LOADING_ERROR) &&
+ (container->priv->state != GEDIT_VIEW_CONTAINER_STATE_SAVING_ERROR) &&
+ (container->priv->state != GEDIT_VIEW_CONTAINER_STATE_REVERTING_ERROR))
+ {
+ install_auto_save_timeout (container);
+ }
+ /* else: the timeout will be installed when loading/saving/reverting
+ will terminate */
+
+ return;
+ }
+
+ if (!enable && (container->priv->auto_save_timeout > 0))
+ {
+ remove_auto_save_timeout (container);
+
+ return;
+ }
+
+ g_return_if_fail ((!enable && (container->priv->auto_save_timeout <= 0)) ||
+ gedit_document_is_untitled (doc) || gedit_document_get_readonly (doc));
+}
+
+/**
+ * gedit_view_container_get_auto_save_interval:
+ * @container: a #GeditViewContainer
+ *
+ * Gets the current interval for the autosaves
+ *
+ * Return value: the value of the autosave
+ **/
+gint
+gedit_view_container_get_auto_save_interval (GeditViewContainer *container)
+{
+ gedit_debug (DEBUG_VIEW_CONTAINER);
+
+ g_return_val_if_fail (GEDIT_IS_VIEW_CONTAINER (container), 0);
+
+ return container->priv->auto_save_interval;
+}
+
+/**
+ * gedit_view_container_set_auto_save_interval:
+ * @container: a #GeditViewContainer
+ * @interval: the new interval
+ *
+ * Sets the interval for the autosave feature. It does nothing if the
+ * interval is the same as the one already present. It removes the old
+ * interval timeout and adds a new one with the autosave passed as
+ * argument.
+ **/
+void
+gedit_view_container_set_auto_save_interval (GeditViewContainer *container,
+ gint interval)
+{
+ GeditDocument *doc = NULL;
+
+ gedit_debug (DEBUG_VIEW_CONTAINER);
+
+ g_return_if_fail (GEDIT_IS_VIEW_CONTAINER (container));
+
+ doc = gedit_view_container_get_document (container);
+
+ g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
+ g_return_if_fail (interval > 0);
+
+ if (container->priv->auto_save_interval == interval)
+ return;
+
+ container->priv->auto_save_interval = interval;
+
+ if (!container->priv->auto_save)
+ return;
+
+ if (container->priv->auto_save_timeout > 0)
+ {
+ g_return_if_fail (!gedit_document_is_untitled (doc));
+ g_return_if_fail (!gedit_document_get_readonly (doc));
+
+ remove_auto_save_timeout (container);
+
+ install_auto_save_timeout (container);
+ }
+}
diff --git a/gedit/gedit-view-container.h b/gedit/gedit-view-container.h
new file mode 100644
index 0000000..5113b72
--- /dev/null
+++ b/gedit/gedit-view-container.h
@@ -0,0 +1,181 @@
+/*
+ * gedit-view-container.h
+ * This file is part of gedit
+ *
+ * Copyright (C) 2005 - Paolo Maggi
+ *
+ * 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., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Modified by the gedit Team, 2005. See the AUTHORS file for a
+ * list of people on the gedit Team.
+ * See the ChangeLog files for a list of changes.
+ *
+ * $Id$
+ */
+
+#ifndef __GEDIT_VIEW_CONTAINER_H__
+#define __GEDIT_VIEW_CONTAINER_H__
+
+#include <gtk/gtk.h>
+
+#include <gedit/gedit-view-interface.h>
+#include <gedit/gedit-document-interface.h>
+
+G_BEGIN_DECLS
+
+typedef enum
+{
+ GEDIT_VIEW_CONTAINER_STATE_NORMAL = 0,
+ GEDIT_VIEW_CONTAINER_STATE_LOADING,
+ GEDIT_VIEW_CONTAINER_STATE_REVERTING,
+ GEDIT_VIEW_CONTAINER_STATE_SAVING,
+ GEDIT_VIEW_CONTAINER_STATE_PRINTING,
+ GEDIT_VIEW_CONTAINER_STATE_PRINT_PREVIEWING,
+ GEDIT_VIEW_CONTAINER_STATE_SHOWING_PRINT_PREVIEW,
+ GEDIT_VIEW_CONTAINER_STATE_GENERIC_NOT_EDITABLE,
+ GEDIT_VIEW_CONTAINER_STATE_LOADING_ERROR,
+ GEDIT_VIEW_CONTAINER_STATE_REVERTING_ERROR,
+ GEDIT_VIEW_CONTAINER_STATE_SAVING_ERROR,
+ GEDIT_VIEW_CONTAINER_STATE_GENERIC_ERROR,
+ GEDIT_VIEW_CONTAINER_STATE_CLOSING,
+ GEDIT_VIEW_CONTAINER_STATE_EXTERNALLY_MODIFIED_NOTIFICATION,
+ GEDIT_VIEW_CONTAINER_NUM_OF_STATES /* This is not a valid state */
+} GeditViewContainerState;
+
+typedef enum
+{
+ GEDIT_VIEW_CONTAINER_MODE_TEXT = 0,
+ GEDIT_VIEW_CONTAINER_MODE_BINARY
+} GeditViewContainerMode;
+
+/*
+ * Type checking and casting macros
+ */
+#define GEDIT_TYPE_VIEW_CONTAINER (gedit_view_container_get_type())
+#define GEDIT_VIEW_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GEDIT_TYPE_VIEW_CONTAINER, GeditViewContainer))
+#define GEDIT_VIEW_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GEDIT_TYPE_VIEW_CONTAINER, GeditViewContainerClass))
+#define GEDIT_IS_VIEW_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GEDIT_TYPE_VIEW_CONTAINER))
+#define GEDIT_IS_VIEW_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEDIT_TYPE_VIEW_CONTAINER))
+#define GEDIT_VIEW_CONTAINER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GEDIT_TYPE_VIEW_CONTAINER, GeditViewContainerClass))
+
+/* Private structure type */
+typedef struct _GeditViewContainerPrivate GeditViewContainerPrivate;
+
+/*
+ * Main object structure
+ */
+typedef struct _GeditViewContainer GeditViewContainer;
+
+struct _GeditViewContainer
+{
+ GtkVBox vbox;
+
+ /*< private > */
+ GeditViewContainerPrivate *priv;
+};
+
+/*
+ * Class definition
+ */
+typedef struct _GeditViewContainerClass GeditViewContainerClass;
+
+struct _GeditViewContainerClass
+{
+ GtkVBoxClass parent_class;
+
+ void (* view_added) (GeditViewContainer *container,
+ GeditView *view);
+ void (* view_removed) (GeditViewContainer *container,
+ GeditView *view);
+ void (* active_view_changed) (GeditViewContainer *container,
+ GeditView *view);
+};
+
+/*
+ * Public methods
+ */
+GType gedit_view_container_get_type (void) G_GNUC_CONST;
+
+GeditView *gedit_view_container_get_view (GeditViewContainer *container);
+
+GList *gedit_view_container_get_views (GeditViewContainer *container);
+
+/* This is only an helper function */
+GeditDocument *gedit_view_container_get_document (GeditViewContainer *container);
+
+GeditViewContainer *gedit_view_container_get_from_view (GeditView *view);
+
+GeditViewContainer *gedit_view_container_get_from_document (GeditDocument *doc);
+
+GeditViewContainerState gedit_view_container_get_state (GeditViewContainer *container);
+
+GeditViewContainerMode gedit_view_container_get_mode (GeditViewContainer *container);
+
+gboolean gedit_view_container_get_auto_save_enabled
+ (GeditViewContainer *container);
+
+void gedit_view_container_set_auto_save_enabled
+ (GeditViewContainer *container,
+ gboolean enable);
+
+gint gedit_view_container_get_auto_save_interval
+ (GeditViewContainer *container);
+
+void gedit_view_container_set_auto_save_interval
+ (GeditViewContainer *container,
+ gint interval);
+
+/*
+ * Non exported methods
+ */
+GtkWidget *_gedit_view_container_new (void);
+
+/* Whether create is TRUE, creates a new empty document if location does
+ not refer to an existing file */
+GtkWidget *_gedit_view_container_new_from_uri (const gchar *uri,
+ const GeditEncoding *encoding,
+ gint line_pos,
+ gboolean create);
+gchar *_gedit_view_container_get_name (GeditViewContainer *container);
+gchar *_gedit_view_container_get_tooltips (GeditViewContainer *container);
+GdkPixbuf *_gedit_view_container_get_icon (GeditViewContainer *container);
+void _gedit_view_container_load (GeditViewContainer *container,
+ const gchar *uri,
+ const GeditEncoding *encoding,
+ gint line_pos,
+ gboolean create);
+void _gedit_view_container_revert (GeditViewContainer *container);
+void _gedit_view_container_save (GeditViewContainer *container);
+void _gedit_view_container_save_as (GeditViewContainer *container,
+ const gchar *uri,
+ const GeditEncoding *encoding);
+
+void _gedit_view_container_print (GeditViewContainer *container);
+void _gedit_view_container_print_preview (GeditViewContainer *container);
+
+void _gedit_view_container_mark_for_closing (GeditViewContainer *container);
+
+gboolean _gedit_view_container_can_close (GeditViewContainer *container);
+
+#if !GTK_CHECK_VERSION (2, 17, 4)
+void _gedit_view_container_page_setup (GeditViewContainer *container);
+#endif
+
+G_END_DECLS
+
+#endif /* __GEDIT_VIEW_CONTAINER_H__ */
diff --git a/gedit/gedit-view-interface.c b/gedit/gedit-view-interface.c
new file mode 100644
index 0000000..64b853b
--- /dev/null
+++ b/gedit/gedit-view-interface.c
@@ -0,0 +1,332 @@
+/*
+ * gedit-view.c
+ * This file is part of gedit
+ *
+ * Copyright (C) 2009 - Ignacio Casal Quinteiro
+ *
+ * gedit 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.
+ *
+ * gedit 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 gedit; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+
+#include "gedit-view-interface.h"
+#include <gtk/gtk.h>
+
+/* Signals */
+enum
+{
+ DROP_URIS,
+ LAST_SIGNAL
+};
+
+static guint view_signals [LAST_SIGNAL] = { 0 };
+
+/* Default implementation */
+static const gchar *
+gedit_view_get_name_default (GeditView *view)
+{
+ g_return_val_if_reached (NULL);
+}
+
+static GeditDocument *
+gedit_view_get_document_default (GeditView *view)
+{
+ g_return_val_if_reached (NULL);
+}
+
+static void
+gedit_view_set_editable_default (GeditView *view,
+ gboolean setting)
+{
+ g_return_if_reached ();
+}
+
+static gboolean
+gedit_view_get_editable_default (GeditView *view)
+{
+ g_return_val_if_reached (FALSE);
+}
+
+static gboolean
+gedit_view_get_overwrite_default (GeditView *view)
+{
+ g_return_val_if_reached (FALSE);
+}
+
+static void
+gedit_view_cut_clipboard_default (GeditView *view)
+{
+ g_return_if_reached ();
+}
+
+static void
+gedit_view_copy_clipboard_default (GeditView *view)
+{
+ g_return_if_reached ();
+}
+
+static void
+gedit_view_paste_clipboard_default (GeditView *view)
+{
+ g_return_if_reached ();
+}
+
+static void
+gedit_view_delete_selection_default (GeditView *view)
+{
+ g_return_if_reached ();
+}
+
+static void
+gedit_view_select_all_default (GeditView *view)
+{
+ g_return_if_reached ();
+}
+
+static void
+gedit_view_scroll_to_cursor_default (GeditView *view)
+{
+ g_return_if_reached ();
+}
+
+static void
+gedit_view_set_font_default (GeditView *view,
+ gboolean def,
+ const gchar *font_name)
+{
+ g_return_if_reached ();
+}
+
+static void
+gedit_view_init (GeditViewIface *iface)
+{
+ static gboolean initialized = FALSE;
+
+ iface->get_name = gedit_view_get_name_default;
+ iface->get_document = gedit_view_get_document_default;
+ iface->set_editable = gedit_view_set_editable_default;
+ iface->get_editable = gedit_view_get_editable_default;
+ iface->get_overwrite = gedit_view_get_overwrite_default;
+ iface->cut_clipboard = gedit_view_cut_clipboard_default;
+ iface->copy_clipboard = gedit_view_copy_clipboard_default;
+ iface->paste_clipboard = gedit_view_paste_clipboard_default;
+ iface->delete_selection = gedit_view_delete_selection_default;
+ iface->select_all = gedit_view_select_all_default;
+ iface->scroll_to_cursor = gedit_view_scroll_to_cursor_default;
+ iface->set_font = gedit_view_set_font_default;
+
+ if (!initialized)
+ {
+ initialized = TRUE;
+
+ g_object_interface_install_property (iface,
+ g_param_spec_boolean ("editable",
+ "Editable",
+ "Whether the text can be modified by the user",
+ TRUE,
+ G_PARAM_READWRITE));
+
+ /* A new signal DROP_URIS has been added to allow plugins to intercept
+ * the default dnd behaviour of 'text/uri-list'. GeditTextView now handles
+ * dnd in the default handlers of drag_drop, drag_motion and
+ * drag_data_received. The view emits drop_uris from drag_data_received
+ * if valid uris have been dropped. Plugins should connect to
+ * drag_motion, drag_drop and drag_data_received to change this
+ * default behaviour. They should _NOT_ use this signal because this
+ * will not prevent gedit from loading the uri
+ */
+ view_signals[DROP_URIS] =
+ g_signal_new ("drop_uris",
+ G_TYPE_FROM_INTERFACE (iface),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (GeditViewIface, drop_uris),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__BOXED,
+ G_TYPE_NONE, 1, G_TYPE_STRV);
+ }
+}
+
+GType
+gedit_view_get_type ()
+{
+ static GType gedit_view_type_id = 0;
+
+ if (!gedit_view_type_id)
+ {
+ static const GTypeInfo g_define_type_info =
+ {
+ sizeof (GeditViewIface),
+ (GBaseInitFunc) gedit_view_init,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ 0,
+ 0,
+ NULL
+ };
+
+ gedit_view_type_id =
+ g_type_register_static (G_TYPE_INTERFACE,
+ "GeditView",
+ &g_define_type_info,
+ 0);
+
+ g_type_interface_add_prerequisite (gedit_view_type_id,
+ GTK_TYPE_WIDGET);
+ }
+
+ return gedit_view_type_id;
+}
+
+/**
+ * gedit_view_get_name:
+ * @view: a #GeditView
+ *
+ * Gets a name for @view. For example: "Text Editor"
+ *
+ * Returns: a name for @view.
+ */
+const gchar *
+gedit_view_get_name (GeditView *view)
+{
+ g_return_val_if_fail (GEDIT_IS_VIEW (view), NULL);
+ return GEDIT_VIEW_GET_INTERFACE (view)->get_name (view);
+}
+
+/**
+ * gedit_view_get_document:
+ * @view: a #GeditView
+ */
+GeditDocument *
+gedit_view_get_document (GeditView *view)
+{
+ g_return_val_if_fail (GEDIT_IS_VIEW (view), NULL);
+
+ return GEDIT_VIEW_GET_INTERFACE (view)->get_document (view);
+}
+
+void
+gedit_view_set_editable (GeditView *view,
+ gboolean setting)
+{
+ g_return_if_fail (GEDIT_IS_VIEW (view));
+ GEDIT_VIEW_GET_INTERFACE (view)->set_editable (view, setting);
+}
+
+gboolean
+gedit_view_get_editable (GeditView *view)
+{
+ g_return_val_if_fail (GEDIT_IS_VIEW (view), FALSE);
+ return GEDIT_VIEW_GET_INTERFACE (view)->get_editable (view);
+}
+
+gboolean
+gedit_view_get_overwrite (GeditView *view)
+{
+ g_return_val_if_fail (GEDIT_IS_VIEW (view), FALSE);
+ return GEDIT_VIEW_GET_INTERFACE (view)->get_overwrite (view);
+}
+
+/**
+ * gedit_view_cut_clipboard:
+ * @view: a #GeditView
+ */
+void
+gedit_view_cut_clipboard (GeditView *view)
+{
+ g_return_if_fail (GEDIT_IS_VIEW (view));
+ GEDIT_VIEW_GET_INTERFACE (view)->cut_clipboard (view);
+}
+
+/**
+ * gedit_view_copy_clipboard:
+ * @view: a #GeditView
+ */
+void
+gedit_view_copy_clipboard (GeditView *view)
+{
+ g_return_if_fail (GEDIT_IS_VIEW (view));
+ GEDIT_VIEW_GET_INTERFACE (view)->copy_clipboard (view);
+}
+
+/**
+ * gedit_view_paste_clipboard:
+ * @view: a #GeditView
+ */
+void
+gedit_view_paste_clipboard (GeditView *view)
+{
+ g_return_if_fail (GEDIT_IS_VIEW (view));
+ GEDIT_VIEW_GET_INTERFACE (view)->paste_clipboard (view);
+}
+
+/**
+ * gedit_view_delete_selection:
+ * @view: a #GeditView
+ *
+ * Deletes the text currently selected in the #GtkTextBuffer associated
+ * to the view and scroll to the cursor position.
+ **/
+void
+gedit_view_delete_selection (GeditView *view)
+{
+ g_return_if_fail (GEDIT_IS_VIEW (view));
+ GEDIT_VIEW_GET_INTERFACE (view)->delete_selection (view);
+}
+
+/**
+ * gedit_view_select_all:
+ * @view: a #GeditView
+ *
+ * Selects all the text displayed in the @view.
+ **/
+void
+gedit_view_select_all (GeditView *view)
+{
+ g_return_if_fail (GEDIT_IS_VIEW (view));
+ GEDIT_VIEW_GET_INTERFACE (view)->select_all (view);
+}
+
+/**
+ * gedit_view_scroll_to_cursor:
+ * @view: a #GeditView
+ *
+ * Scrolls the @view to the cursor position.
+ **/
+void
+gedit_view_scroll_to_cursor (GeditView *view)
+{
+ g_return_if_fail (GEDIT_IS_VIEW (view));
+ GEDIT_VIEW_GET_INTERFACE (view)->scroll_to_cursor (view);
+}
+
+/**
+ * gedit_view_set_font:
+ * @view: a #GeditView
+ * @def: whether to reset the default font
+ * @font_name: the name of the font to use
+ *
+ * If @def is #TRUE, resets the font of the @view to the default font
+ * otherwise sets it to @font_name.
+ **/
+void
+gedit_view_set_font (GeditView *view,
+ gboolean def,
+ const gchar *font_name)
+{
+ g_return_if_fail (GEDIT_IS_VIEW (view));
+ GEDIT_VIEW_GET_INTERFACE (view)->set_font (view, def, font_name);
+}
diff --git a/gedit/gedit-view-interface.h b/gedit/gedit-view-interface.h
new file mode 100644
index 0000000..c5bd6b4
--- /dev/null
+++ b/gedit/gedit-view-interface.h
@@ -0,0 +1,97 @@
+/*
+ * gedit-view.h
+ * This file is part of gedit
+ *
+ * Copyright (C) 2009 - Ignacio Casal Quinteiro
+ *
+ * gedit 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.
+ *
+ * gedit 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 gedit; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+
+#ifndef __GEDIT_VIEW_H__
+#define __GEDIT_VIEW_H__
+
+#include <glib-object.h>
+#include "gedit-document-interface.h"
+
+G_BEGIN_DECLS
+
+#define GEDIT_TYPE_VIEW (gedit_view_get_type ())
+#define GEDIT_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_VIEW, GeditView))
+#define GEDIT_IS_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEDIT_TYPE_VIEW))
+#define GEDIT_VIEW_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GEDIT_TYPE_VIEW, GeditViewIface))
+
+typedef struct _GeditView GeditView;
+typedef struct _GeditViewIface GeditViewIface;
+
+struct _GeditViewIface
+{
+ GTypeInterface parent;
+
+ /* Signals */
+ void (* drop_uris) (GeditView *view,
+ gchar **uri_list);
+
+ /* Virtual Table */
+ const gchar * (*get_name) (GeditView *view);
+ GeditDocument * (*get_document) (GeditView *view);
+ void (*set_editable) (GeditView *view,
+ gboolean setting);
+ gboolean (*get_editable) (GeditView *view);
+ gboolean (*get_overwrite) (GeditView *view);
+ void (*cut_clipboard) (GeditView *view);
+ void (*copy_clipboard) (GeditView *view);
+ void (*paste_clipboard) (GeditView *view);
+ void (*delete_selection) (GeditView *view);
+ void (*select_all) (GeditView *view);
+ void (*scroll_to_cursor) (GeditView *view);
+ void (*set_font) (GeditView *view,
+ gboolean def,
+ const gchar *font_name);
+};
+
+GType gedit_view_get_type (void) G_GNUC_CONST;
+
+const gchar *gedit_view_get_name (GeditView *view);
+
+GeditDocument *gedit_view_get_document (GeditView *view);
+
+void gedit_view_set_editable (GeditView *view,
+ gboolean setting);
+
+gboolean gedit_view_get_editable (GeditView *view);
+
+gboolean gedit_view_get_overwrite (GeditView *view);
+
+void gedit_view_cut_clipboard (GeditView *view);
+
+void gedit_view_copy_clipboard (GeditView *view);
+
+void gedit_view_paste_clipboard (GeditView *view);
+
+void gedit_view_delete_selection (GeditView *view);
+
+void gedit_view_select_all (GeditView *view);
+
+void gedit_view_scroll_to_cursor (GeditView *view);
+
+void gedit_view_set_font (GeditView *view,
+ gboolean def,
+ const gchar *font_name);
+
+G_END_DECLS
+
+#endif /* __GEDIT_VIEW_H__ */
diff --git a/gedit/gedit-web-view.c b/gedit/gedit-web-view.c
new file mode 100644
index 0000000..35b1afc
--- /dev/null
+++ b/gedit/gedit-web-view.c
@@ -0,0 +1,158 @@
+/*
+ * gedit-web-view.c
+ * This file is part of gedit
+ *
+ * Copyright (C) 2009 - Ignacio Casal Quinteiro
+ *
+ * gedit 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.
+ *
+ * gedit 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 gedit; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+
+#include "gedit-web-view.h"
+#include "gedit-document-interface.h"
+#include <glib/gi18n.h>
+
+#define GEDIT_WEB_VIEW_NAME _("Web View")
+
+#define GEDIT_WEB_VIEW_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GEDIT_TYPE_WEB_VIEW, GeditWebViewPrivate))
+
+struct _GeditWebViewPrivate
+{
+};
+
+static void gedit_view_iface_init (GeditViewIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (GeditWebView,
+ gedit_web_view,
+ WEBKIT_TYPE_WEB_VIEW,
+ G_IMPLEMENT_INTERFACE (GEDIT_TYPE_VIEW,
+ gedit_view_iface_init))
+
+static void
+gedit_web_view_finalize (GObject *object)
+{
+ G_OBJECT_CLASS (gedit_web_view_parent_class)->finalize (object);
+}
+
+static void
+gedit_web_view_class_init (GeditWebViewClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = gedit_web_view_finalize;
+
+ /*g_type_class_add_private (object_class, sizeof (GeditWebViewPrivate));*/
+}
+
+static void
+gedit_web_view_init (GeditWebView *self)
+{
+ /*self->priv = GEDIT_WEB_VIEW_GET_PRIVATE (self);*/
+
+ webkit_web_view_load_uri (WEBKIT_WEB_VIEW (self), "about:blank");
+ webkit_web_view_load_uri (WEBKIT_WEB_VIEW (self), "http://www.gedit.org");
+}
+
+static const gchar *
+gedit_view_get_name_impl (GeditView *view)
+{
+ return GEDIT_WEB_VIEW_NAME;
+}
+
+static GeditDocument *
+gedit_view_get_document_impl (GeditView *view)
+{
+ return GEDIT_DOCUMENT (view);
+}
+
+static void
+gedit_view_set_editable_impl (GeditView *view,
+ gboolean setting)
+{
+ webkit_web_view_set_editable (WEBKIT_WEB_VIEW (view), setting);
+}
+
+static gboolean
+gedit_view_get_editable_impl (GeditView *view)
+{
+ return webkit_web_view_get_editable (WEBKIT_WEB_VIEW (view));
+}
+
+static gboolean
+gedit_view_get_overwrite_impl (GeditView *view)
+{
+ return FALSE;
+}
+
+static void
+gedit_view_cut_clipboard_impl (GeditView *view)
+{
+}
+
+static void
+gedit_view_copy_clipboard_impl (GeditView *view)
+{
+}
+
+static void
+gedit_view_paste_clipboard_impl (GeditView *view)
+{
+}
+
+static void
+gedit_view_delete_selection_impl (GeditView *view)
+{
+}
+
+static void
+gedit_view_select_all_impl (GeditView *view)
+{
+}
+
+static void
+gedit_view_scroll_to_cursor_impl (GeditView *view)
+{
+}
+
+static void
+gedit_view_set_font_impl (GeditView *view,
+ gboolean def,
+ const gchar *font_name)
+{
+}
+
+static void
+gedit_view_iface_init (GeditViewIface *iface)
+{
+ iface->get_name = gedit_view_get_name_impl;
+ iface->get_document = gedit_view_get_document_impl;
+ iface->set_editable = gedit_view_set_editable_impl;
+ iface->get_editable = gedit_view_get_editable_impl;
+ iface->get_overwrite = gedit_view_get_overwrite_impl;
+ iface->cut_clipboard = gedit_view_cut_clipboard_impl;
+ iface->copy_clipboard = gedit_view_copy_clipboard_impl;
+ iface->paste_clipboard = gedit_view_paste_clipboard_impl;
+ iface->delete_selection = gedit_view_delete_selection_impl;
+ iface->select_all = gedit_view_select_all_impl;
+ iface->scroll_to_cursor = gedit_view_scroll_to_cursor_impl;
+ iface->set_font = gedit_view_set_font_impl;
+}
+
+GeditView *
+gedit_web_view_new ()
+{
+ return GEDIT_VIEW (g_object_new (GEDIT_TYPE_WEB_VIEW, NULL));
+}
diff --git a/gedit/gedit-web-view.h b/gedit/gedit-web-view.h
new file mode 100644
index 0000000..088143c
--- /dev/null
+++ b/gedit/gedit-web-view.h
@@ -0,0 +1,62 @@
+/*
+ * gedit-web-view.h
+ * This file is part of gedit
+ *
+ * Copyright (C) 2009 - Ignacio Casal Quinteiro
+ *
+ * gedit 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.
+ *
+ * gedit 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 gedit; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+
+#ifndef __GEDIT_WEB_VIEW_H__
+#define __GEDIT_WEB_VIEW_H__
+
+#include <webkit/webkit.h>
+#include "gedit-view-interface.h"
+
+G_BEGIN_DECLS
+
+#define GEDIT_TYPE_WEB_VIEW (gedit_web_view_get_type ())
+#define GEDIT_WEB_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_WEB_VIEW, GeditWebView))
+#define GEDIT_WEB_VIEW_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_WEB_VIEW, GeditWebView const))
+#define GEDIT_WEB_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEDIT_TYPE_WEB_VIEW, GeditWebViewClass))
+#define GEDIT_IS_WEB_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEDIT_TYPE_WEB_VIEW))
+#define GEDIT_IS_WEB_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEDIT_TYPE_WEB_VIEW))
+#define GEDIT_WEB_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEDIT_TYPE_WEB_VIEW, GeditWebViewClass))
+
+typedef struct _GeditWebView GeditWebView;
+typedef struct _GeditWebViewClass GeditWebViewClass;
+typedef struct _GeditWebViewPrivate GeditWebViewPrivate;
+
+struct _GeditWebView
+{
+ WebKitWebView parent;
+
+ GeditWebViewPrivate *priv;
+};
+
+struct _GeditWebViewClass
+{
+ WebKitWebViewClass parent_class;
+};
+
+GType gedit_web_view_get_type (void) G_GNUC_CONST;
+GeditView *gedit_web_view_new (void);
+
+
+G_END_DECLS
+
+#endif /* __GEDIT_WEB_VIEW_H__ */
diff --git a/gedit/gedit-window-private.h b/gedit/gedit-window-private.h
index 0467d8e..819e659 100644
--- a/gedit/gedit-window-private.h
+++ b/gedit/gedit-window-private.h
@@ -52,7 +52,7 @@ struct _GeditWindowPrivate
GtkWidget *tab_width_combo;
GtkWidget *language_combo;
- GeditMessageBus *message_bus;
+ GeditMessageBus *message_bus;
/* Widgets for fullscreen mode */
GtkWidget *fullscreen_controls;
@@ -60,7 +60,7 @@ struct _GeditWindowPrivate
gboolean fullscreen_animation_enter;
/* statusbar and context ids for statusbar messages */
- GtkWidget *statusbar;
+ GtkWidget *statusbar;
guint generic_message_cid;
guint tip_message_cid;
guint tab_width_id;
@@ -85,13 +85,14 @@ struct _GeditWindowPrivate
guint recents_menu_ui_id;
gulong recents_handler_id;
- GeditTab *active_tab;
- gint num_tabs;
+ GeditPage *active_page;
+ GeditViewContainer *active_container;
+ gint num_pages;
- gint num_tabs_with_error;
+ gint num_pages_with_error;
gint width;
- gint height;
+ gint height;
GdkWindowState window_state;
gint side_panel_size;
@@ -105,7 +106,7 @@ struct _GeditWindowPrivate
GFile *default_location;
- gboolean removing_tabs : 1;
+ gboolean removing_pages : 1;
gboolean dispose_has_run : 1;
};
diff --git a/gedit/gedit-window.c b/gedit/gedit-window.c
index 680393c..14784ca 100644
--- a/gedit/gedit-window.c
+++ b/gedit/gedit-window.c
@@ -56,6 +56,8 @@
#include "gedit-enum-types.h"
#include "gedit-dirs.h"
#include "gedit-status-combo-box.h"
+#include "gedit-text-buffer.h"
+#include "gedit-text-view.h"
#define LANGUAGE_NONE (const gchar *)"LangNone"
#define GEDIT_UIFILE "gedit-ui.xml"
@@ -70,11 +72,11 @@
/* Signals */
enum
{
- TAB_ADDED,
- TAB_REMOVED,
- TABS_REORDERED,
- ACTIVE_TAB_CHANGED,
- ACTIVE_TAB_STATE_CHANGED,
+ PAGE_ADDED,
+ PAGE_REMOVED,
+ PAGES_REORDERED,
+ ACTIVE_PAGE_CHANGED,
+ ACTIVE_PAGE_STATE_CHANGED,
LAST_SIGNAL
};
@@ -320,8 +322,8 @@ gedit_window_key_press_event (GtkWidget *widget,
}
static void
-gedit_window_tab_removed (GeditWindow *window,
- GeditTab *tab)
+gedit_window_page_removed (GeditWindow *window,
+ GeditPage *page)
{
gedit_plugins_engine_garbage_collect (gedit_plugins_engine_get_default ());
}
@@ -332,7 +334,7 @@ gedit_window_class_init (GeditWindowClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
- klass->tab_removed = gedit_window_tab_removed;
+ klass->page_removed = gedit_window_page_removed;
object_class->dispose = gedit_window_dispose;
object_class->finalize = gedit_window_finalize;
@@ -342,54 +344,54 @@ gedit_window_class_init (GeditWindowClass *klass)
widget_class->configure_event = gedit_window_configure_event;
widget_class->key_press_event = gedit_window_key_press_event;
- signals[TAB_ADDED] =
- g_signal_new ("tab_added",
+ signals[PAGE_ADDED] =
+ g_signal_new ("page_added",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (GeditWindowClass, tab_added),
+ G_STRUCT_OFFSET (GeditWindowClass, page_added),
NULL, NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE,
1,
- GEDIT_TYPE_TAB);
- signals[TAB_REMOVED] =
- g_signal_new ("tab_removed",
+ GEDIT_TYPE_PAGE);
+ signals[PAGE_REMOVED] =
+ g_signal_new ("page_removed",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (GeditWindowClass, tab_removed),
+ G_STRUCT_OFFSET (GeditWindowClass, page_removed),
NULL, NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE,
1,
- GEDIT_TYPE_TAB);
- signals[TABS_REORDERED] =
- g_signal_new ("tabs_reordered",
+ GEDIT_TYPE_PAGE);
+ signals[PAGES_REORDERED] =
+ g_signal_new ("pages_reordered",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (GeditWindowClass, tabs_reordered),
+ G_STRUCT_OFFSET (GeditWindowClass, pages_reordered),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE,
0);
- signals[ACTIVE_TAB_CHANGED] =
- g_signal_new ("active_tab_changed",
+ signals[ACTIVE_PAGE_CHANGED] =
+ g_signal_new ("active_page_changed",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (GeditWindowClass, active_tab_changed),
+ G_STRUCT_OFFSET (GeditWindowClass, active_page_changed),
NULL, NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE,
1,
- GEDIT_TYPE_TAB);
- signals[ACTIVE_TAB_STATE_CHANGED] =
- g_signal_new ("active_tab_state_changed",
+ GEDIT_TYPE_PAGE);
+ signals[ACTIVE_PAGE_STATE_CHANGED] =
+ g_signal_new ("active_page_state_changed",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (GeditWindowClass, active_tab_state_changed),
+ G_STRUCT_OFFSET (GeditWindowClass, active_page_state_changed),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE,
- 0);
+ 0);
g_object_class_install_property (object_class,
PROP_STATE,
@@ -537,9 +539,9 @@ set_toolbar_style (GeditWindow *window,
static void
update_next_prev_doc_sensitivity (GeditWindow *window,
- GeditTab *tab)
+ GeditPage *page)
{
- gint tab_number;
+ gint page_number;
GtkNotebook *notebook;
GtkAction *action;
@@ -547,31 +549,31 @@ update_next_prev_doc_sensitivity (GeditWindow *window,
notebook = GTK_NOTEBOOK (_gedit_window_get_notebook (window));
- tab_number = gtk_notebook_page_num (notebook, GTK_WIDGET (tab));
- g_return_if_fail (tab_number >= 0);
+ page_number = gtk_notebook_page_num (notebook, GTK_WIDGET (page));
+ g_return_if_fail (page_number >= 0);
action = gtk_action_group_get_action (window->priv->action_group,
"DocumentsPreviousDocument");
- gtk_action_set_sensitive (action, tab_number != 0);
+ gtk_action_set_sensitive (action, page_number != 0);
action = gtk_action_group_get_action (window->priv->action_group,
"DocumentsNextDocument");
gtk_action_set_sensitive (action,
- tab_number < gtk_notebook_get_n_pages (notebook) - 1);
+ page_number < gtk_notebook_get_n_pages (notebook) - 1);
}
static void
update_next_prev_doc_sensitivity_per_window (GeditWindow *window)
{
- GeditTab *tab;
+ GeditPage *page;
GtkAction *action;
gedit_debug (DEBUG_WINDOW);
- tab = gedit_window_get_active_tab (window);
- if (tab != NULL)
+ page = gedit_window_get_active_page (window);
+ if (page != NULL)
{
- update_next_prev_doc_sensitivity (window, tab);
+ update_next_prev_doc_sensitivity (window, page);
return;
}
@@ -595,15 +597,17 @@ received_clipboard_contents (GtkClipboard *clipboard,
GtkAction *action;
/* getting clipboard contents is async, so we need to
- * get the current tab and its state */
+ * get the current page and its state */
- if (window->priv->active_tab != NULL)
+ if (window->priv->active_page != NULL)
{
- GeditTabState state;
+ GeditViewContainer *container;
+ GeditViewContainerState state;
gboolean state_normal;
- state = gedit_tab_get_state (window->priv->active_tab);
- state_normal = (state == GEDIT_TAB_STATE_NORMAL);
+ container = gedit_page_get_active_view_container (window->priv->active_page);
+ state = gedit_view_container_get_state (container);
+ state_normal = (state == GEDIT_VIEW_CONTAINER_STATE_NORMAL);
sens = state_normal &&
gtk_selection_data_targets_include_text (selection_data);
@@ -650,32 +654,93 @@ set_paste_sensitivity_according_to_clipboard (GeditWindow *window,
}
static void
-set_sensitivity_according_to_tab (GeditWindow *window,
- GeditTab *tab)
+set_sensitivity_for_search_items (GeditWindow *window,
+ GeditDocument *doc,
+ GeditViewContainerState state,
+ gboolean state_normal,
+ gboolean editable)
+{
+ GtkAction *action;
+ gboolean b;
+
+ /* FIXME: quick hack */
+ if (!GEDIT_IS_TEXT_BUFFER (doc))
+ state_normal = FALSE;
+ else
+ b = gedit_text_buffer_get_can_search_again (GEDIT_TEXT_BUFFER (doc));
+
+ action = gtk_action_group_get_action (window->priv->action_group,
+ "SearchFind");
+ gtk_action_set_sensitive (action,
+ (state_normal ||
+ state == GEDIT_VIEW_CONTAINER_STATE_EXTERNALLY_MODIFIED_NOTIFICATION));
+
+ action = gtk_action_group_get_action (window->priv->action_group,
+ "SearchIncrementalSearch");
+ gtk_action_set_sensitive (action,
+ (state_normal ||
+ state == GEDIT_VIEW_CONTAINER_STATE_EXTERNALLY_MODIFIED_NOTIFICATION));
+
+ action = gtk_action_group_get_action (window->priv->action_group,
+ "SearchReplace");
+ gtk_action_set_sensitive (action,
+ state_normal &&
+ editable);
+
+ action = gtk_action_group_get_action (window->priv->action_group,
+ "SearchFindNext");
+ gtk_action_set_sensitive (action,
+ (state_normal ||
+ state == GEDIT_VIEW_CONTAINER_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) && b);
+
+ action = gtk_action_group_get_action (window->priv->action_group,
+ "SearchFindPrevious");
+ gtk_action_set_sensitive (action,
+ (state_normal ||
+ state == GEDIT_VIEW_CONTAINER_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) && b);
+
+ action = gtk_action_group_get_action (window->priv->action_group,
+ "SearchClearHighlight");
+ gtk_action_set_sensitive (action,
+ (state_normal ||
+ state == GEDIT_VIEW_CONTAINER_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) && b);
+
+ action = gtk_action_group_get_action (window->priv->action_group,
+ "SearchGoToLine");
+ gtk_action_set_sensitive (action,
+ (state_normal ||
+ state == GEDIT_VIEW_CONTAINER_STATE_EXTERNALLY_MODIFIED_NOTIFICATION));
+}
+
+static void
+set_sensitivity_according_to_page (GeditWindow *window,
+ GeditPage *page)
{
+ GeditViewContainer *container;
GeditDocument *doc;
GeditView *view;
GtkAction *action;
- gboolean b;
gboolean state_normal;
gboolean editable;
- GeditTabState state;
+ GeditViewContainerState state;
GtkClipboard *clipboard;
GeditLockdownMask lockdown;
- g_return_if_fail (GEDIT_TAB (tab));
+ g_return_if_fail (GEDIT_PAGE (page));
gedit_debug (DEBUG_WINDOW);
+ container = gedit_page_get_active_view_container (page);
+
lockdown = gedit_app_get_lockdown (gedit_app_get_default ());
- state = gedit_tab_get_state (tab);
- state_normal = (state == GEDIT_TAB_STATE_NORMAL);
+ state = gedit_view_container_get_state (container);
+ state_normal = (state == GEDIT_VIEW_CONTAINER_STATE_NORMAL);
- view = gedit_tab_get_view (tab);
- editable = gtk_text_view_get_editable (GTK_TEXT_VIEW (view));
+ view = gedit_view_container_get_view (container);
+ editable = gedit_view_get_editable (view);
- doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
+ doc = gedit_view_container_get_document (container);
clipboard = gtk_widget_get_clipboard (GTK_WIDGET (window),
GDK_SELECTION_CLIPBOARD);
@@ -684,8 +749,8 @@ set_sensitivity_according_to_tab (GeditWindow *window,
"FileSave");
gtk_action_set_sensitive (action,
(state_normal ||
- (state == GEDIT_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) ||
- (state == GEDIT_TAB_STATE_SHOWING_PRINT_PREVIEW)) &&
+ (state == GEDIT_VIEW_CONTAINER_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) ||
+ (state == GEDIT_VIEW_CONTAINER_STATE_SHOWING_PRINT_PREVIEW)) &&
!gedit_document_get_readonly (doc) &&
!(lockdown & GEDIT_LOCKDOWN_SAVE_TO_DISK));
@@ -693,16 +758,16 @@ set_sensitivity_according_to_tab (GeditWindow *window,
"FileSaveAs");
gtk_action_set_sensitive (action,
(state_normal ||
- (state == GEDIT_TAB_STATE_SAVING_ERROR) ||
- (state == GEDIT_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) ||
- (state == GEDIT_TAB_STATE_SHOWING_PRINT_PREVIEW)) &&
+ (state == GEDIT_VIEW_CONTAINER_STATE_SAVING_ERROR) ||
+ (state == GEDIT_VIEW_CONTAINER_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) ||
+ (state == GEDIT_VIEW_CONTAINER_STATE_SHOWING_PRINT_PREVIEW)) &&
!(lockdown & GEDIT_LOCKDOWN_SAVE_TO_DISK));
action = gtk_action_group_get_action (window->priv->action_group,
"FileRevert");
gtk_action_set_sensitive (action,
(state_normal ||
- (state == GEDIT_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION)) &&
+ (state == GEDIT_VIEW_CONTAINER_STATE_EXTERNALLY_MODIFIED_NOTIFICATION)) &&
!gedit_document_is_untitled (doc));
action = gtk_action_group_get_action (window->priv->action_group,
@@ -715,45 +780,45 @@ set_sensitivity_according_to_tab (GeditWindow *window,
"FilePrint");
gtk_action_set_sensitive (action,
(state_normal ||
- (state == GEDIT_TAB_STATE_SHOWING_PRINT_PREVIEW)) &&
+ (state == GEDIT_VIEW_CONTAINER_STATE_SHOWING_PRINT_PREVIEW)) &&
!(lockdown & GEDIT_LOCKDOWN_PRINTING));
action = gtk_action_group_get_action (window->priv->action_group,
"FileClose");
gtk_action_set_sensitive (action,
- (state != GEDIT_TAB_STATE_CLOSING) &&
- (state != GEDIT_TAB_STATE_SAVING) &&
- (state != GEDIT_TAB_STATE_SHOWING_PRINT_PREVIEW) &&
- (state != GEDIT_TAB_STATE_PRINTING) &&
- (state != GEDIT_TAB_STATE_PRINT_PREVIEWING) &&
- (state != GEDIT_TAB_STATE_SAVING_ERROR));
+ (state != GEDIT_VIEW_CONTAINER_STATE_CLOSING) &&
+ (state != GEDIT_VIEW_CONTAINER_STATE_SAVING) &&
+ (state != GEDIT_VIEW_CONTAINER_STATE_SHOWING_PRINT_PREVIEW) &&
+ (state != GEDIT_VIEW_CONTAINER_STATE_PRINTING) &&
+ (state != GEDIT_VIEW_CONTAINER_STATE_PRINT_PREVIEWING) &&
+ (state != GEDIT_VIEW_CONTAINER_STATE_SAVING_ERROR));
action = gtk_action_group_get_action (window->priv->action_group,
"EditUndo");
gtk_action_set_sensitive (action,
state_normal &&
- gtk_source_buffer_can_undo (GTK_SOURCE_BUFFER (doc)));
+ gedit_document_can_undo (doc));
action = gtk_action_group_get_action (window->priv->action_group,
"EditRedo");
gtk_action_set_sensitive (action,
state_normal &&
- gtk_source_buffer_can_redo (GTK_SOURCE_BUFFER (doc)));
+ gedit_document_can_redo (doc));
action = gtk_action_group_get_action (window->priv->action_group,
"EditCut");
gtk_action_set_sensitive (action,
state_normal &&
editable &&
- gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER (doc)));
+ gedit_document_get_has_selection (doc));
action = gtk_action_group_get_action (window->priv->action_group,
"EditCopy");
gtk_action_set_sensitive (action,
(state_normal ||
- state == GEDIT_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) &&
- gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER (doc)));
+ state == GEDIT_VIEW_CONTAINER_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) &&
+ gedit_document_get_has_selection (doc));
action = gtk_action_group_get_action (window->priv->action_group,
"EditPaste");
@@ -772,61 +837,20 @@ set_sensitivity_according_to_tab (GeditWindow *window,
gtk_action_set_sensitive (action,
state_normal &&
editable &&
- gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER (doc)));
-
- action = gtk_action_group_get_action (window->priv->action_group,
- "SearchFind");
- gtk_action_set_sensitive (action,
- (state_normal ||
- state == GEDIT_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION));
-
- action = gtk_action_group_get_action (window->priv->action_group,
- "SearchIncrementalSearch");
- gtk_action_set_sensitive (action,
- (state_normal ||
- state == GEDIT_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION));
-
- action = gtk_action_group_get_action (window->priv->action_group,
- "SearchReplace");
- gtk_action_set_sensitive (action,
- state_normal &&
- editable);
-
- b = gedit_document_get_can_search_again (doc);
- action = gtk_action_group_get_action (window->priv->action_group,
- "SearchFindNext");
- gtk_action_set_sensitive (action,
- (state_normal ||
- state == GEDIT_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) && b);
-
- action = gtk_action_group_get_action (window->priv->action_group,
- "SearchFindPrevious");
- gtk_action_set_sensitive (action,
- (state_normal ||
- state == GEDIT_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) && b);
-
- action = gtk_action_group_get_action (window->priv->action_group,
- "SearchClearHighlight");
- gtk_action_set_sensitive (action,
- (state_normal ||
- state == GEDIT_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) && b);
-
- action = gtk_action_group_get_action (window->priv->action_group,
- "SearchGoToLine");
- gtk_action_set_sensitive (action,
- (state_normal ||
- state == GEDIT_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION));
+ gedit_document_get_has_selection (doc));
action = gtk_action_group_get_action (window->priv->action_group,
"ViewHighlightMode");
gtk_action_set_sensitive (action,
- (state != GEDIT_TAB_STATE_CLOSING) &&
+ (state != GEDIT_VIEW_CONTAINER_STATE_CLOSING) &&
gedit_prefs_manager_get_enable_syntax_highlighting ());
- update_next_prev_doc_sensitivity (window, tab);
+ set_sensitivity_for_search_items (window, doc, state, state_normal, editable);
+
+ update_next_prev_doc_sensitivity (window, page);
gedit_plugins_engine_update_plugins_ui (gedit_plugins_engine_get_default (),
- window);
+ window);
}
static void
@@ -841,7 +865,7 @@ language_toggled (GtkToggleAction *action,
return;
doc = gedit_window_get_active_document (window);
- if (doc == NULL)
+ if (doc == NULL && !GEDIT_IS_TEXT_BUFFER (doc))
return;
lang_id = gtk_action_get_name (GTK_ACTION (action));
@@ -862,7 +886,7 @@ language_toggled (GtkToggleAction *action,
}
}
- gedit_document_set_language (doc, lang);
+ gedit_text_buffer_set_language (GEDIT_TEXT_BUFFER (doc), lang);
}
static gchar *
@@ -1045,10 +1069,10 @@ update_languages_menu (GeditWindow *window)
const gchar *lang_id;
doc = gedit_window_get_active_document (window);
- if (doc == NULL)
+ if (doc == NULL && !GEDIT_TEXT_BUFFER (doc))
return;
- lang = gedit_document_get_language (doc);
+ lang = gedit_text_buffer_get_language (GEDIT_TEXT_BUFFER (doc));
if (lang != NULL)
lang_id = gtk_source_language_get_id (lang);
else
@@ -1604,14 +1628,16 @@ documents_list_menu_activate (GtkToggleAction *action,
}
static gchar *
-get_menu_tip_for_tab (GeditTab *tab)
+get_menu_tip_for_page (GeditPage *page)
{
+ GeditViewContainer *container;
GeditDocument *doc;
gchar *uri;
gchar *ruri;
gchar *tip;
- doc = gedit_tab_get_document (tab);
+ container = gedit_page_get_active_view_container (page);
+ doc = gedit_view_container_get_document (container);
uri = gedit_document_get_uri_for_display (doc);
ruri = gedit_utils_replace_home_dir_with_tilde (uri);
@@ -1658,15 +1684,17 @@ update_documents_list_menu (GeditWindow *window)
for (i = 0; i < n; i++)
{
- GtkWidget *tab;
+ GtkWidget *page;
+ GeditViewContainer *container;
GtkRadioAction *action;
gchar *action_name;
- gchar *tab_name;
+ gchar *page_name;
gchar *name;
gchar *tip;
gchar *accel;
- tab = gtk_notebook_get_nth_page (GTK_NOTEBOOK (p->notebook), i);
+ page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (p->notebook), i);
+ container = gedit_page_get_active_view_container (GEDIT_PAGE (page));
/* NOTE: the action is associated to the position of the tab in
* the notebook not to the tab itself! This is needed to work
@@ -1676,9 +1704,9 @@ update_documents_list_menu (GeditWindow *window)
* get the same accel.
*/
action_name = g_strdup_printf ("Tab_%d", i);
- tab_name = _gedit_tab_get_name (GEDIT_TAB (tab));
- name = gedit_utils_escape_underscores (tab_name, -1);
- tip = get_menu_tip_for_tab (GEDIT_TAB (tab));
+ page_name = _gedit_view_container_get_name (container);
+ name = gedit_utils_escape_underscores (page_name, -1);
+ tip = get_menu_tip_for_page (GEDIT_PAGE (page));
/* alt + 1, 2, 3... 0 to switch to the first ten tabs */
accel = (i < 10) ? g_strdup_printf ("<alt>%d", (i + 1) % 10) : NULL;
@@ -1711,13 +1739,13 @@ update_documents_list_menu (GeditWindow *window)
GTK_UI_MANAGER_MENUITEM,
FALSE);
- if (GEDIT_TAB (tab) == p->active_tab)
+ if (GEDIT_PAGE (page) == p->active_page)
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
g_object_unref (action);
g_free (action_name);
- g_free (tab_name);
+ g_free (page_name);
g_free (name);
g_free (tip);
g_free (accel);
@@ -1821,13 +1849,13 @@ language_combo_changed (GeditStatusComboBox *combo,
doc = gedit_window_get_active_document (window);
- if (!doc)
+ if (!doc && !GEDIT_TEXT_BUFFER (doc))
return;
language = GTK_SOURCE_LANGUAGE (g_object_get_data (G_OBJECT (item), LANGUAGE_DATA));
g_signal_handler_block (doc, window->priv->language_changed_id);
- gedit_document_set_language (doc, language);
+ gedit_text_buffer_set_language (GEDIT_TEXT_BUFFER (doc), language);
g_signal_handler_unblock (doc, window->priv->language_changed_id);
}
@@ -2051,45 +2079,24 @@ clone_window (GeditWindow *origin)
}
static void
-update_cursor_position_statusbar (GtkTextBuffer *buffer,
+update_cursor_position_statusbar (GeditDocument *doc,
GeditWindow *window)
{
gint row, col;
- GtkTextIter iter;
- GtkTextIter start;
guint tab_size;
GeditView *view;
gedit_debug (DEBUG_WINDOW);
-
- if (buffer != GTK_TEXT_BUFFER (gedit_window_get_active_document (window)))
- return;
-
- view = gedit_window_get_active_view (window);
-
- gtk_text_buffer_get_iter_at_mark (buffer,
- &iter,
- gtk_text_buffer_get_insert (buffer));
-
- row = gtk_text_iter_get_line (&iter);
-
- start = iter;
- gtk_text_iter_set_line_offset (&start, 0);
- col = 0;
+ if (doc != gedit_window_get_active_document (window)
+ || !GEDIT_IS_TEXT_BUFFER (doc))
+ return;
+
+ view = gedit_window_get_active_view (window);
tab_size = gtk_source_view_get_tab_width (GTK_SOURCE_VIEW (view));
-
- while (!gtk_text_iter_equal (&start, &iter))
- {
- /* FIXME: Are we Unicode compliant here? */
- if (gtk_text_iter_get_char (&start) == '\t')
-
- col += (tab_size - (col % tab_size));
- else
- ++col;
-
- gtk_text_iter_forward_char (&start);
- }
+
+ gedit_text_buffer_get_cursor_position (GEDIT_TEXT_BUFFER (doc),
+ tab_size, &row, &col);
gedit_statusbar_set_cursor_position (
GEDIT_STATUSBAR (window->priv->statusbar),
@@ -2098,19 +2105,19 @@ update_cursor_position_statusbar (GtkTextBuffer *buffer,
}
static void
-update_overwrite_mode_statusbar (GtkTextView *view,
+update_overwrite_mode_statusbar (GeditView *view,
GeditWindow *window)
{
- if (view != GTK_TEXT_VIEW (gedit_window_get_active_view (window)))
+ if (view != gedit_window_get_active_view (window))
return;
- /* Note that we have to use !gtk_text_view_get_overwrite since we
+ /* Note that we have to use !gedit_view_get_overwrite since we
are in the in the signal handler of "toggle overwrite" that is
G_SIGNAL_RUN_LAST
*/
gedit_statusbar_set_overwrite (
GEDIT_STATUSBAR (window->priv->statusbar),
- !gtk_text_view_get_overwrite (view));
+ !gedit_view_get_overwrite (view));
}
#define MAX_TITLE_LENGTH 100
@@ -2118,19 +2125,21 @@ update_overwrite_mode_statusbar (GtkTextView *view,
static void
set_title (GeditWindow *window)
{
+ GeditViewContainer *container;
GeditDocument *doc = NULL;
gchar *name;
gchar *dirname = NULL;
gchar *title = NULL;
gint len;
- if (window->priv->active_tab == NULL)
+ if (window->priv->active_page == NULL)
{
gtk_window_set_title (GTK_WINDOW (window), "gedit");
return;
}
- doc = gedit_tab_get_document (window->priv->active_tab);
+ container = gedit_page_get_active_view_container (window->priv->active_page);
+ doc = gedit_view_container_get_document (container);
g_return_if_fail (doc != NULL);
name = gedit_document_get_short_name_for_display (doc);
@@ -2173,7 +2182,7 @@ set_title (GeditWindow *window)
}
}
- if (gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (doc)))
+ if (gedit_document_get_modified (doc))
{
gchar *tmp_name;
@@ -2247,7 +2256,7 @@ spaces_instead_of_tabs_changed (GObject *object,
gtk_check_menu_item_set_active (item, active);
- g_list_free (children);
+ g_list_free (children);
}
static void
@@ -2349,48 +2358,134 @@ language_changed (GObject *object,
g_list_free (items);
}
+static void
+connect_per_container_properties (GeditWindow *window,
+ GeditViewContainer *container)
+{
+ GeditView *view;
+
+ view = gedit_view_container_get_view (container);
+
+ if (GEDIT_IS_TEXT_VIEW (view))
+ {
+ GeditDocument *doc;
+
+ /* update the syntax menu */
+ update_languages_menu (window);
+
+ doc = gedit_view_get_document (view);
+
+ /* sync the statusbar */
+ update_cursor_position_statusbar (doc,
+ window);
+ gedit_statusbar_set_overwrite (GEDIT_STATUSBAR (window->priv->statusbar),
+ gedit_view_get_overwrite (view));
+
+ gtk_widget_show (window->priv->tab_width_combo);
+ gtk_widget_show (window->priv->language_combo);
+
+ window->priv->tab_width_id =
+ g_signal_connect (view,
+ "notify::tab-width",
+ G_CALLBACK (tab_width_changed),
+ window);
+ window->priv->spaces_instead_of_tabs_id =
+ g_signal_connect (view,
+ "notify::insert-spaces-instead-of-tabs",
+ G_CALLBACK (spaces_instead_of_tabs_changed),
+ window);
+
+ window->priv->language_changed_id =
+ g_signal_connect (doc,
+ "notify::language",
+ G_CALLBACK (language_changed),
+ window);
+
+ /* call it for the first time */
+ tab_width_changed (G_OBJECT (view), NULL, window);
+ spaces_instead_of_tabs_changed (G_OBJECT (view), NULL, window);
+ language_changed (G_OBJECT (doc),
+ NULL, window);
+ }
+ else
+ {
+ /* Remove line and col info */
+ gedit_statusbar_set_cursor_position (
+ GEDIT_STATUSBAR (window->priv->statusbar),
+ -1,
+ -1);
+
+ gedit_statusbar_clear_overwrite (
+ GEDIT_STATUSBAR (window->priv->statusbar));
+
+ /* We don't need to show the combo boxes */
+ gtk_widget_hide (window->priv->tab_width_combo);
+ gtk_widget_hide (window->priv->language_combo);
+ }
+}
+
+static void
+disconnect_per_container_properties (GeditWindow *window,
+ GeditViewContainer *container)
+{
+ if (container)
+ {
+ GeditView *view;
+
+ view = gedit_view_container_get_view (container);
+
+ if (GEDIT_IS_TEXT_VIEW (view))
+ {
+ if (window->priv->tab_width_id)
+ {
+ g_signal_handler_disconnect (view,
+ window->priv->tab_width_id);
+
+ window->priv->tab_width_id = 0;
+ }
+
+ if (window->priv->spaces_instead_of_tabs_id)
+ {
+ g_signal_handler_disconnect (view,
+ window->priv->spaces_instead_of_tabs_id);
+
+ window->priv->spaces_instead_of_tabs_id = 0;
+ }
+ }
+ }
+}
+
static void
notebook_switch_page (GtkNotebook *book,
GtkNotebookPage *pg,
gint page_num,
GeditWindow *window)
{
- GeditView *view;
- GeditTab *tab;
+ GeditPage *page;
GtkAction *action;
gchar *action_name;
+ GeditViewContainer *container;
/* CHECK: I don't know why but it seems notebook_switch_page is called
two times every time the user change the active tab */
- tab = GEDIT_TAB (gtk_notebook_get_nth_page (book, page_num));
- if (tab == window->priv->active_tab)
+ page = GEDIT_PAGE (gtk_notebook_get_nth_page (book, page_num));
+ if (page == window->priv->active_page)
return;
- if (window->priv->active_tab)
+ if (window->priv->active_page)
{
- if (window->priv->tab_width_id)
- {
- g_signal_handler_disconnect (gedit_tab_get_view (window->priv->active_tab),
- window->priv->tab_width_id);
-
- window->priv->tab_width_id = 0;
- }
-
- if (window->priv->spaces_instead_of_tabs_id)
- {
- g_signal_handler_disconnect (gedit_tab_get_view (window->priv->active_tab),
- window->priv->spaces_instead_of_tabs_id);
-
- window->priv->spaces_instead_of_tabs_id = 0;
- }
+ disconnect_per_container_properties (window,
+ window->priv->active_container);
}
- /* set the active tab */
- window->priv->active_tab = tab;
+ /* set the active tab and container */
+ window->priv->active_page = page;
+ container = gedit_page_get_active_view_container (page);
+ window->priv->active_container = container;
set_title (window);
- set_sensitivity_according_to_tab (window, tab);
+ set_sensitivity_according_to_page (window, page);
/* activate the right item in the documents menu */
action_name = g_strdup_printf ("Tab_%d", page_num);
@@ -2405,44 +2500,13 @@ notebook_switch_page (GtkNotebook *book,
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
g_free (action_name);
-
- /* update the syntax menu */
- update_languages_menu (window);
-
- view = gedit_tab_get_view (tab);
-
- /* sync the statusbar */
- update_cursor_position_statusbar (GTK_TEXT_BUFFER (gedit_tab_get_document (tab)),
- window);
- gedit_statusbar_set_overwrite (GEDIT_STATUSBAR (window->priv->statusbar),
- gtk_text_view_get_overwrite (GTK_TEXT_VIEW (view)));
-
- gtk_widget_show (window->priv->tab_width_combo);
- gtk_widget_show (window->priv->language_combo);
-
- window->priv->tab_width_id = g_signal_connect (view,
- "notify::tab-width",
- G_CALLBACK (tab_width_changed),
- window);
- window->priv->spaces_instead_of_tabs_id = g_signal_connect (view,
- "notify::insert-spaces-instead-of-tabs",
- G_CALLBACK (spaces_instead_of_tabs_changed),
- window);
-
- window->priv->language_changed_id = g_signal_connect (gedit_tab_get_document (tab),
- "notify::language",
- G_CALLBACK (language_changed),
- window);
-
- /* call it for the first time */
- tab_width_changed (G_OBJECT (view), NULL, window);
- spaces_instead_of_tabs_changed (G_OBJECT (view), NULL, window);
- language_changed (G_OBJECT (gedit_tab_get_document (tab)), NULL, window);
-
- g_signal_emit (G_OBJECT (window),
- signals[ACTIVE_TAB_CHANGED],
- 0,
- window->priv->active_tab);
+
+ connect_per_container_properties (window, container);
+
+ g_signal_emit (G_OBJECT (window),
+ signals[ACTIVE_PAGE_CHANGED],
+ 0,
+ window->priv->active_page);
}
static void
@@ -2490,8 +2554,8 @@ set_sensitivity_according_to_window_state (GeditWindow *window)
gedit_notebook_set_close_buttons_sensitive (GEDIT_NOTEBOOK (window->priv->notebook),
!(window->priv->state & GEDIT_WINDOW_STATE_SAVING_SESSION));
- gedit_notebook_set_tab_drag_and_drop_enabled (GEDIT_NOTEBOOK (window->priv->notebook),
- !(window->priv->state & GEDIT_WINDOW_STATE_SAVING_SESSION));
+ gedit_notebook_set_page_drag_and_drop_enabled (GEDIT_NOTEBOOK (window->priv->notebook),
+ !(window->priv->state & GEDIT_WINDOW_STATE_SAVING_SESSION));
if ((window->priv->state & GEDIT_WINDOW_STATE_SAVING_SESSION) != 0)
{
@@ -2509,10 +2573,10 @@ set_sensitivity_according_to_window_state (GeditWindow *window)
{
if (!gtk_action_group_get_sensitive (window->priv->action_group))
gtk_action_group_set_sensitive (window->priv->action_group,
- window->priv->num_tabs > 0);
+ window->priv->num_pages > 0);
if (!gtk_action_group_get_sensitive (window->priv->quit_action_group))
gtk_action_group_set_sensitive (window->priv->quit_action_group,
- window->priv->num_tabs > 0);
+ window->priv->num_pages > 0);
}
}
@@ -2520,17 +2584,17 @@ static void
update_tab_autosave (GtkWidget *widget,
gpointer data)
{
- GeditTab *tab = GEDIT_TAB (widget);
+ GeditViewContainer *tab = GEDIT_VIEW_CONTAINER (widget);
gboolean *enabled = (gboolean *) data;
- gedit_tab_set_auto_save_enabled (tab, *enabled);
+ gedit_view_container_set_auto_save_enabled (tab, *enabled);
}
void
_gedit_window_set_lockdown (GeditWindow *window,
GeditLockdownMask lockdown)
{
- GeditTab *tab;
+ GeditPage *page;
GtkAction *action;
gboolean autosave;
@@ -2540,10 +2604,10 @@ _gedit_window_set_lockdown (GeditWindow *window,
update_tab_autosave,
&autosave);
- /* update menues wrt the current active tab */
- tab = gedit_window_get_active_tab (window);
+ /* update menues wrt the current active tab */
+ page = gedit_window_get_active_page (window);
- set_sensitivity_according_to_tab (window, tab);
+ set_sensitivity_according_to_page (window, page);
action = gtk_action_group_get_action (window->priv->action_group,
"FileSaveAll");
@@ -2560,39 +2624,40 @@ _gedit_window_set_lockdown (GeditWindow *window,
}
static void
-analyze_tab_state (GeditTab *tab,
+analyze_page_state (GeditViewContainer *tab,
GeditWindow *window)
{
- GeditTabState ts;
-
- ts = gedit_tab_get_state (tab);
+ GeditViewContainerState ts;
+#if 0
+ ts = gedit_view_container_get_state (tab);
switch (ts)
{
- case GEDIT_TAB_STATE_LOADING:
- case GEDIT_TAB_STATE_REVERTING:
+ case GEDIT_VIEW_CONTAINER_STATE_LOADING:
+ case GEDIT_VIEW_CONTAINER_STATE_REVERTING:
window->priv->state |= GEDIT_WINDOW_STATE_LOADING;
break;
- case GEDIT_TAB_STATE_SAVING:
+ case GEDIT_VIEW_CONTAINER_STATE_SAVING:
window->priv->state |= GEDIT_WINDOW_STATE_SAVING;
break;
- case GEDIT_TAB_STATE_PRINTING:
- case GEDIT_TAB_STATE_PRINT_PREVIEWING:
+ case GEDIT_VIEW_CONTAINER_STATE_PRINTING:
+ case GEDIT_VIEW_CONTAINER_STATE_PRINT_PREVIEWING:
window->priv->state |= GEDIT_WINDOW_STATE_PRINTING;
break;
- case GEDIT_TAB_STATE_LOADING_ERROR:
- case GEDIT_TAB_STATE_REVERTING_ERROR:
- case GEDIT_TAB_STATE_SAVING_ERROR:
- case GEDIT_TAB_STATE_GENERIC_ERROR:
+ case GEDIT_VIEW_CONTAINER_STATE_LOADING_ERROR:
+ case GEDIT_VIEW_CONTAINER_STATE_REVERTING_ERROR:
+ case GEDIT_VIEW_CONTAINER_STATE_SAVING_ERROR:
+ case GEDIT_VIEW_CONTAINER_STATE_GENERIC_ERROR:
window->priv->state |= GEDIT_WINDOW_STATE_ERROR;
- ++window->priv->num_tabs_with_error;
+ ++window->priv->num_pages_with_error;
default:
/* NOP */
- break;
+ break;
}
+#endif
}
static void
@@ -2604,17 +2669,17 @@ update_window_state (GeditWindow *window)
gedit_debug_message (DEBUG_WINDOW, "Old state: %x", window->priv->state);
old_ws = window->priv->state;
- old_num_of_errors = window->priv->num_tabs_with_error;
+ old_num_of_errors = window->priv->num_pages_with_error;
window->priv->state = old_ws & GEDIT_WINDOW_STATE_SAVING_SESSION;
- window->priv->num_tabs_with_error = 0;
+ window->priv->num_pages_with_error = 0;
gtk_container_foreach (GTK_CONTAINER (window->priv->notebook),
- (GtkCallback)analyze_tab_state,
+ (GtkCallback)analyze_page_state,
window);
- gedit_debug_message (DEBUG_WINDOW, "New state: %x", window->priv->state);
+ gedit_debug_message (DEBUG_WINDOW, "New state: %x", window->priv->state);
if (old_ws != window->priv->state)
{
@@ -2622,53 +2687,59 @@ update_window_state (GeditWindow *window)
gedit_statusbar_set_window_state (GEDIT_STATUSBAR (window->priv->statusbar),
window->priv->state,
- window->priv->num_tabs_with_error);
+ window->priv->num_pages_with_error);
g_object_notify (G_OBJECT (window), "state");
}
- else if (old_num_of_errors != window->priv->num_tabs_with_error)
+ else if (old_num_of_errors != window->priv->num_pages_with_error)
{
gedit_statusbar_set_window_state (GEDIT_STATUSBAR (window->priv->statusbar),
window->priv->state,
- window->priv->num_tabs_with_error);
+ window->priv->num_pages_with_error);
}
}
static void
-sync_state (GeditTab *tab,
- GParamSpec *pspec,
- GeditWindow *window)
+sync_state (GeditViewContainer *container,
+ GParamSpec *pspec,
+ GeditWindow *window)
{
+ GeditPage *page;
+
gedit_debug (DEBUG_WINDOW);
update_window_state (window);
+ page = gedit_page_get_from_container (container);
- if (tab != window->priv->active_tab)
+ if (page != window->priv->active_page)
return;
- set_sensitivity_according_to_tab (window, tab);
+ set_sensitivity_according_to_page (window, page);
- g_signal_emit (G_OBJECT (window), signals[ACTIVE_TAB_STATE_CHANGED], 0);
+ g_signal_emit (G_OBJECT (window), signals[ACTIVE_PAGE_STATE_CHANGED], 0);
}
static void
-sync_name (GeditTab *tab,
- GParamSpec *pspec,
- GeditWindow *window)
+sync_name (GeditViewContainer *container,
+ GParamSpec *pspec,
+ GeditWindow *window)
{
GtkAction *action;
gchar *action_name;
- gchar *tab_name;
+ gchar *page_name;
gchar *escaped_name;
gchar *tip;
gint n;
GeditDocument *doc;
+ GeditPage *page;
- if (tab == window->priv->active_tab)
+ page = gedit_page_get_from_container (container);
+
+ if (page == window->priv->active_page)
{
set_title (window);
- doc = gedit_tab_get_document (tab);
+ doc = gedit_view_container_get_document (container);
action = gtk_action_group_get_action (window->priv->action_group,
"FileRevert");
gtk_action_set_sensitive (action,
@@ -2677,26 +2748,26 @@ sync_name (GeditTab *tab,
/* sync the item in the documents list menu */
n = gtk_notebook_page_num (GTK_NOTEBOOK (window->priv->notebook),
- GTK_WIDGET (tab));
+ GTK_WIDGET (page));
action_name = g_strdup_printf ("Tab_%d", n);
action = gtk_action_group_get_action (window->priv->documents_list_action_group,
action_name);
g_return_if_fail (action != NULL);
- tab_name = _gedit_tab_get_name (tab);
- escaped_name = gedit_utils_escape_underscores (tab_name, -1);
- tip = get_menu_tip_for_tab (tab);
+ page_name = _gedit_view_container_get_name (container);
+ escaped_name = gedit_utils_escape_underscores (page_name, -1);
+ tip = get_menu_tip_for_page (page);
g_object_set (action, "label", escaped_name, NULL);
g_object_set (action, "tooltip", tip, NULL);
g_free (action_name);
- g_free (tab_name);
+ g_free (page_name);
g_free (escaped_name);
g_free (tip);
gedit_plugins_engine_update_plugins_ui (gedit_plugins_engine_get_default (),
- window);
+ window);
}
static GeditWindow *
@@ -2990,10 +3061,11 @@ can_search_again (GeditDocument *doc,
gboolean sensitive;
GtkAction *action;
- if (doc != gedit_window_get_active_document (window))
+ if (doc != gedit_window_get_active_document (window) ||
+ !GEDIT_TEXT_BUFFER (doc))
return;
- sensitive = gedit_document_get_can_search_again (doc);
+ sensitive = gedit_text_buffer_get_can_search_again (GEDIT_TEXT_BUFFER (doc));
action = gtk_action_group_get_action (window->priv->action_group,
"SearchFindNext");
@@ -3016,7 +3088,7 @@ can_undo (GeditDocument *doc,
GtkAction *action;
gboolean sensitive;
- sensitive = gtk_source_buffer_can_undo (GTK_SOURCE_BUFFER (doc));
+ sensitive = gedit_document_can_undo (doc);
if (doc != gedit_window_get_active_document (window))
return;
@@ -3034,7 +3106,7 @@ can_redo (GeditDocument *doc,
GtkAction *action;
gboolean sensitive;
- sensitive = gtk_source_buffer_can_redo (GTK_SOURCE_BUFFER (doc));
+ sensitive = gedit_document_can_redo (doc);
if (doc != gedit_window_get_active_document (window))
return;
@@ -3049,10 +3121,10 @@ selection_changed (GeditDocument *doc,
GParamSpec *pspec,
GeditWindow *window)
{
- GeditTab *tab;
+ GeditViewContainer *container;
GeditView *view;
GtkAction *action;
- GeditTabState state;
+ GeditViewContainerState state;
gboolean state_normal;
gboolean editable;
@@ -3061,36 +3133,36 @@ selection_changed (GeditDocument *doc,
if (doc != gedit_window_get_active_document (window))
return;
- tab = gedit_tab_get_from_document (doc);
- state = gedit_tab_get_state (tab);
- state_normal = (state == GEDIT_TAB_STATE_NORMAL);
+ container = gedit_view_container_get_from_document (doc);
+ state = gedit_view_container_get_state (container);
+ state_normal = (state == GEDIT_VIEW_CONTAINER_STATE_NORMAL);
- view = gedit_tab_get_view (tab);
- editable = gtk_text_view_get_editable (GTK_TEXT_VIEW (view));
+ view = gedit_view_container_get_view (container);
+ editable = gedit_view_get_editable (view);
action = gtk_action_group_get_action (window->priv->action_group,
"EditCut");
gtk_action_set_sensitive (action,
state_normal &&
editable &&
- gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER (doc)));
+ gedit_document_get_has_selection (doc));
action = gtk_action_group_get_action (window->priv->action_group,
"EditCopy");
gtk_action_set_sensitive (action,
(state_normal ||
- state == GEDIT_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) &&
- gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER (doc)));
+ state == GEDIT_VIEW_CONTAINER_STATE_EXTERNALLY_MODIFIED_NOTIFICATION) &&
+ gedit_document_get_has_selection (doc));
action = gtk_action_group_get_action (window->priv->action_group,
"EditDelete");
gtk_action_set_sensitive (action,
state_normal &&
editable &&
- gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER (doc)));
+ gedit_document_get_has_selection (doc));
gedit_plugins_engine_update_plugins_ui (gedit_plugins_engine_get_default (),
- window);
+ window);
}
static void
@@ -3109,57 +3181,44 @@ editable_changed (GeditView *view,
GeditWindow *window)
{
gedit_plugins_engine_update_plugins_ui (gedit_plugins_engine_get_default (),
- window);
+ window);
}
static void
-notebook_tab_added (GeditNotebook *notebook,
- GeditTab *tab,
- GeditWindow *window)
+connect_per_container_signals (GeditWindow *window,
+ GeditViewContainer *container)
{
- GeditView *view;
+ GList *views, *l;
GeditDocument *doc;
- GtkAction *action;
-
- gedit_debug (DEBUG_WINDOW);
-
- g_return_if_fail ((window->priv->state & GEDIT_WINDOW_STATE_SAVING_SESSION) == 0);
-
- ++window->priv->num_tabs;
-
- /* Set sensitivity */
- if (!gtk_action_group_get_sensitive (window->priv->action_group))
- gtk_action_group_set_sensitive (window->priv->action_group,
- TRUE);
-
- action = gtk_action_group_get_action (window->priv->action_group,
- "DocumentsMoveToNewWindow");
- gtk_action_set_sensitive (action,
- window->priv->num_tabs > 1);
- view = gedit_tab_get_view (tab);
- doc = gedit_tab_get_document (tab);
+ views = gedit_view_container_get_views (container);
+ doc = gedit_view_container_get_document (container);
- /* IMPORTANT: remember to disconnect the signal in notebook_tab_removed
- * if a new signal is connected here */
-
- g_signal_connect (tab,
+ g_signal_connect (container,
"notify::name",
- G_CALLBACK (sync_name),
+ G_CALLBACK (sync_name),
window);
- g_signal_connect (tab,
+ g_signal_connect (container,
"notify::state",
- G_CALLBACK (sync_state),
+ G_CALLBACK (sync_state),
window);
- g_signal_connect (doc,
- "cursor-moved",
- G_CALLBACK (update_cursor_position_statusbar),
- window);
- g_signal_connect (doc,
- "notify::can-search-again",
- G_CALLBACK (can_search_again),
- window);
+ if (GEDIT_IS_TEXT_BUFFER (doc))
+ {
+ g_signal_connect (doc,
+ "cursor-moved",
+ G_CALLBACK (update_cursor_position_statusbar),
+ window);
+ g_signal_connect (doc,
+ "notify::language",
+ G_CALLBACK (sync_languages_menu),
+ window);
+ g_signal_connect (doc,
+ "notify::can-search-again",
+ G_CALLBACK (can_search_again),
+ window);
+ }
+
g_signal_connect (doc,
"notify::can-undo",
G_CALLBACK (can_undo),
@@ -3172,108 +3231,226 @@ notebook_tab_added (GeditNotebook *notebook,
"notify::has-selection",
G_CALLBACK (selection_changed),
window);
- g_signal_connect (doc,
- "notify::language",
- G_CALLBACK (sync_languages_menu),
+
+ for (l = views; l != NULL; l = g_list_next (l))
+ {
+ GeditView *view = GEDIT_VIEW (l->data);
+
+ if (GEDIT_IS_TEXT_VIEW (view))
+ {
+ g_signal_connect (view,
+ "toggle_overwrite",
+ G_CALLBACK (update_overwrite_mode_statusbar),
+ window);
+ }
+ g_signal_connect (view,
+ "notify::editable",
+ G_CALLBACK (editable_changed),
+ window);
+
+ g_signal_connect (view,
+ "drop_uris",
+ G_CALLBACK (drop_uris_cb),
+ NULL);
+ }
+}
+
+static void
+disconnect_per_container_signals (GeditWindow *window,
+ GeditViewContainer *container)
+{
+ GList *views, *l;
+ GeditDocument *doc;
+
+ views = gedit_view_container_get_views (container);
+ doc = gedit_view_container_get_document (container);
+
+ g_signal_handlers_disconnect_by_func (container,
+ G_CALLBACK (sync_name),
+ window);
+ g_signal_handlers_disconnect_by_func (container,
+ G_CALLBACK (sync_state),
+ window);
+
+ if (GEDIT_IS_TEXT_BUFFER (doc))
+ {
+ g_signal_handlers_disconnect_by_func (doc,
+ G_CALLBACK (update_cursor_position_statusbar),
+ window);
+ g_signal_handlers_disconnect_by_func (doc,
+ G_CALLBACK (can_search_again),
+ window);
+ g_signal_handlers_disconnect_by_func (doc,
+ G_CALLBACK (sync_languages_menu),
+ window);
+ }
+ g_signal_handlers_disconnect_by_func (doc,
+ G_CALLBACK (can_undo),
+ window);
+ g_signal_handlers_disconnect_by_func (doc,
+ G_CALLBACK (can_redo),
+ window);
+ g_signal_handlers_disconnect_by_func (doc,
+ G_CALLBACK (selection_changed),
+ window);
+
+ for (l = views; l != NULL; l = g_list_next (l))
+ {
+ GeditView *view = GEDIT_VIEW (l->data);
+
+ if (GEDIT_IS_TEXT_VIEW (view))
+ {
+ g_signal_handlers_disconnect_by_func (view,
+ G_CALLBACK (update_overwrite_mode_statusbar),
+ window);
+ }
+ g_signal_handlers_disconnect_by_func (view,
+ G_CALLBACK (editable_changed),
+ window);
+ g_signal_handlers_disconnect_by_func (view,
+ G_CALLBACK (drop_uris_cb),
+ NULL);
+ }
+}
+
+static void
+on_container_added (GeditPage *page,
+ GeditViewContainer *container,
+ GeditWindow *window)
+{
+ connect_per_container_signals (window, container);
+}
+
+static void
+on_container_removed (GeditPage *page,
+ GeditViewContainer *container,
+ GeditWindow *window)
+{
+ if (window->priv->active_container == container)
+ {
+ window->priv->active_container = NULL;
+ }
+}
+
+static void
+on_active_container_changed (GeditPage *page,
+ GeditViewContainer *container,
+ GeditWindow *window)
+{
+ disconnect_per_container_properties (window, window->priv->active_container);
+
+ window->priv->active_container = container;
+
+ connect_per_container_properties (window, container);
+}
+
+static void
+notebook_page_added (GeditNotebook *notebook,
+ GeditPage *page,
+ GeditWindow *window)
+{
+ GList *containers, *l;
+ GtkAction *action;
+
+ gedit_debug (DEBUG_WINDOW);
+
+ g_return_if_fail ((window->priv->state & GEDIT_WINDOW_STATE_SAVING_SESSION) == 0);
+
+ ++window->priv->num_pages;
+
+ /* Set sensitivity */
+ if (!gtk_action_group_get_sensitive (window->priv->action_group))
+ gtk_action_group_set_sensitive (window->priv->action_group,
+ TRUE);
+
+ action = gtk_action_group_get_action (window->priv->action_group,
+ "DocumentsMoveToNewWindow");
+ gtk_action_set_sensitive (action,
+ window->priv->num_pages > 1);
+
+ containers = gedit_page_get_view_containers (page);
+
+ /* IMPORTANT: remember to disconnect the signal in notebook_page_removed
+ * if a new signal is connected here */
+
+ /* By default we have at least one container then we have to listen
+ * container-added to catch the new ones */
+ for (l = containers; l != NULL; l = g_list_next (l))
+ {
+ connect_per_container_signals (window, l->data);
+ }
+
+ g_signal_connect (page, "container-added",
+ G_CALLBACK (on_container_added),
window);
- g_signal_connect (view,
- "toggle_overwrite",
- G_CALLBACK (update_overwrite_mode_statusbar),
+ g_signal_connect (page, "container-removed",
+ G_CALLBACK (on_container_removed),
window);
- g_signal_connect (view,
- "notify::editable",
- G_CALLBACK (editable_changed),
+ g_signal_connect (page, "active-container-changed",
+ G_CALLBACK (on_active_container_changed),
window);
update_documents_list_menu (window);
-
- g_signal_connect (view,
- "drop_uris",
- G_CALLBACK (drop_uris_cb),
- NULL);
update_window_state (window);
- g_signal_emit (G_OBJECT (window), signals[TAB_ADDED], 0, tab);
+ g_signal_emit (G_OBJECT (window), signals[PAGE_ADDED], 0, page);
}
static void
-notebook_tab_removed (GeditNotebook *notebook,
- GeditTab *tab,
- GeditWindow *window)
+notebook_page_removed (GeditNotebook *notebook,
+ GeditPage *page,
+ GeditWindow *window)
{
- GeditView *view;
- GeditDocument *doc;
GtkAction *action;
+ GeditViewContainer *container;
+ GList *containers, *l;
+ GeditDocument *doc;
+ GeditView *view;
gedit_debug (DEBUG_WINDOW);
g_return_if_fail ((window->priv->state & GEDIT_WINDOW_STATE_SAVING_SESSION) == 0);
- --window->priv->num_tabs;
+ --window->priv->num_pages;
- view = gedit_tab_get_view (tab);
- doc = gedit_tab_get_document (tab);
+ /* FIXME: This sucks: One reason is that it produces warnings when disconnecting */
+ containers = gedit_page_get_view_containers (page);
+ container = gedit_page_get_active_view_container (page);
+ doc = gedit_view_container_get_document (container);
+ view = gedit_view_container_get_view (container);
- g_signal_handlers_disconnect_by_func (tab,
- G_CALLBACK (sync_name),
- window);
- g_signal_handlers_disconnect_by_func (tab,
- G_CALLBACK (sync_state),
- window);
- g_signal_handlers_disconnect_by_func (doc,
- G_CALLBACK (update_cursor_position_statusbar),
- window);
- g_signal_handlers_disconnect_by_func (doc,
- G_CALLBACK (can_search_again),
- window);
- g_signal_handlers_disconnect_by_func (doc,
- G_CALLBACK (can_undo),
- window);
- g_signal_handlers_disconnect_by_func (doc,
- G_CALLBACK (can_redo),
- window);
- g_signal_handlers_disconnect_by_func (doc,
- G_CALLBACK (selection_changed),
- window);
- g_signal_handlers_disconnect_by_func (doc,
- G_CALLBACK (sync_languages_menu),
- window);
- g_signal_handlers_disconnect_by_func (view,
- G_CALLBACK (update_overwrite_mode_statusbar),
- window);
- g_signal_handlers_disconnect_by_func (view,
- G_CALLBACK (editable_changed),
- window);
- g_signal_handlers_disconnect_by_func (view,
- G_CALLBACK (drop_uris_cb),
- NULL);
+ for (l = containers; l != NULL; l = g_list_next (l))
+ {
+ disconnect_per_container_signals (window, l->data);
+ }
- if (window->priv->tab_width_id && tab == gedit_window_get_active_tab (window))
+ if (window->priv->tab_width_id && page == gedit_window_get_active_page (window))
{
g_signal_handler_disconnect (view, window->priv->tab_width_id);
window->priv->tab_width_id = 0;
}
- if (window->priv->spaces_instead_of_tabs_id && tab == gedit_window_get_active_tab (window))
+ if (window->priv->spaces_instead_of_tabs_id && page == gedit_window_get_active_page (window))
{
g_signal_handler_disconnect (view, window->priv->spaces_instead_of_tabs_id);
window->priv->spaces_instead_of_tabs_id = 0;
}
- if (window->priv->language_changed_id && tab == gedit_window_get_active_tab (window))
+ if (window->priv->language_changed_id && page == gedit_window_get_active_page (window))
{
g_signal_handler_disconnect (doc, window->priv->language_changed_id);
window->priv->language_changed_id = 0;
}
- g_return_if_fail (window->priv->num_tabs >= 0);
- if (window->priv->num_tabs == 0)
+ g_return_if_fail (window->priv->num_pages >= 0);
+ if (window->priv->num_pages == 0)
{
- window->priv->active_tab = NULL;
-
+ window->priv->active_page = NULL;
+ window->priv->active_container = NULL;
+
set_title (window);
-
+
/* Remove line and col info */
gedit_statusbar_set_cursor_position (
GEDIT_STATUSBAR (window->priv->statusbar),
@@ -3288,14 +3465,14 @@ notebook_tab_removed (GeditNotebook *notebook,
gtk_widget_hide (window->priv->language_combo);
}
- if (!window->priv->removing_tabs)
+ if (!window->priv->removing_pages)
{
update_documents_list_menu (window);
update_next_prev_doc_sensitivity_per_window (window);
}
else
{
- if (window->priv->num_tabs == 0)
+ if (window->priv->num_pages == 0)
{
update_documents_list_menu (window);
update_next_prev_doc_sensitivity_per_window (window);
@@ -3303,7 +3480,7 @@ notebook_tab_removed (GeditNotebook *notebook,
}
/* Set sensitivity */
- if (window->priv->num_tabs == 0)
+ if (window->priv->num_pages == 0)
{
if (gtk_action_group_get_sensitive (window->priv->action_group))
gtk_action_group_set_sensitive (window->priv->action_group,
@@ -3314,10 +3491,10 @@ notebook_tab_removed (GeditNotebook *notebook,
gtk_action_set_sensitive (action, FALSE);
gedit_plugins_engine_update_plugins_ui (gedit_plugins_engine_get_default (),
- window);
+ window);
}
- if (window->priv->num_tabs <= 1)
+ if (window->priv->num_pages <= 1)
{
action = gtk_action_group_get_action (window->priv->action_group,
"DocumentsMoveToNewWindow");
@@ -3327,46 +3504,46 @@ notebook_tab_removed (GeditNotebook *notebook,
update_window_state (window);
- g_signal_emit (G_OBJECT (window), signals[TAB_REMOVED], 0, tab);
+ g_signal_emit (G_OBJECT (window), signals[PAGE_REMOVED], 0, page);
}
static void
-notebook_tabs_reordered (GeditNotebook *notebook,
- GeditWindow *window)
+notebook_pages_reordered (GeditNotebook *notebook,
+ GeditWindow *window)
{
update_documents_list_menu (window);
update_next_prev_doc_sensitivity_per_window (window);
- g_signal_emit (G_OBJECT (window), signals[TABS_REORDERED], 0);
+ g_signal_emit (G_OBJECT (window), signals[PAGES_REORDERED], 0);
}
static void
-notebook_tab_detached (GeditNotebook *notebook,
- GeditTab *tab,
- GeditWindow *window)
+notebook_page_detached (GeditNotebook *notebook,
+ GeditPage *page,
+ GeditWindow *window)
{
GeditWindow *new_window;
new_window = clone_window (window);
-
- gedit_notebook_move_tab (notebook,
- GEDIT_NOTEBOOK (_gedit_window_get_notebook (new_window)),
- tab, 0);
-
+
+ gedit_notebook_move_page (notebook,
+ GEDIT_NOTEBOOK (_gedit_window_get_notebook (new_window)),
+ page, 0);
+
gtk_window_set_position (GTK_WINDOW (new_window),
GTK_WIN_POS_MOUSE);
-
+
gtk_widget_show (GTK_WIDGET (new_window));
-}
+}
static void
-notebook_tab_close_request (GeditNotebook *notebook,
- GeditTab *tab,
- GtkWindow *window)
+notebook_page_close_request (GeditNotebook *notebook,
+ GeditPage *page,
+ GtkWindow *window)
{
/* Note: we are destroying the tab before the default handler
* seems to be ok, but we need to keep an eye on this. */
- _gedit_cmd_file_close_tab (tab, GEDIT_WINDOW (window));
+ _gedit_cmd_file_close_page (page, GEDIT_WINDOW (window));
}
static gboolean
@@ -3396,13 +3573,13 @@ show_notebook_popup_menu (GtkNotebook *notebook,
}
else
{
- GtkWidget *tab;
+ GtkWidget *page;
GtkWidget *tab_label;
- tab = GTK_WIDGET (gedit_window_get_active_tab (window));
- g_return_val_if_fail (tab != NULL, FALSE);
+ page = GTK_WIDGET (gedit_window_get_active_page (window));
+ g_return_val_if_fail (page != NULL, FALSE);
- tab_label = gtk_notebook_get_tab_label (notebook, tab);
+ tab_label = gtk_notebook_get_tab_label (notebook, page);
gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
gedit_utils_menu_position_under_widget, tab_label,
@@ -3522,9 +3699,14 @@ side_panel_visibility_changed (GtkWidget *side_panel,
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), visible);
/* focus the document */
- if (!visible && window->priv->active_tab != NULL)
+ if (!visible && window->priv->active_page != NULL)
+ {
+ GeditViewContainer *container;
+
+ container = gedit_page_get_active_view_container (window->priv->active_page);
gtk_widget_grab_focus (GTK_WIDGET (
- gedit_tab_get_view (GEDIT_TAB (window->priv->active_tab))));
+ gedit_view_container_get_view (container)));
+ }
}
static void
@@ -3576,9 +3758,14 @@ bottom_panel_visibility_changed (GeditPanel *bottom_panel,
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), visible);
/* focus the document */
- if (!visible && window->priv->active_tab != NULL)
+ if (!visible && window->priv->active_page != NULL)
+ {
+ GeditViewContainer *container;
+
+ container = gedit_page_get_active_view_container (window->priv->active_page);
gtk_widget_grab_focus (GTK_WIDGET (
- gedit_tab_get_view (GEDIT_TAB (window->priv->active_tab))));
+ gedit_view_container_get_view (container)));
+ }
}
static void
@@ -3757,9 +3944,10 @@ gedit_window_init (GeditWindow *window)
gedit_debug (DEBUG_WINDOW);
window->priv = GEDIT_WINDOW_GET_PRIVATE (window);
- window->priv->active_tab = NULL;
- window->priv->num_tabs = 0;
- window->priv->removing_tabs = FALSE;
+ window->priv->active_page = NULL;
+ window->priv->active_container = NULL;
+ window->priv->num_pages = 0;
+ window->priv->removing_pages = FALSE;
window->priv->state = GEDIT_WINDOW_STATE_NORMAL;
window->priv->dispose_has_run = FALSE;
window->priv->fullscreen_controls = NULL;
@@ -3781,7 +3969,7 @@ gedit_window_init (GeditWindow *window)
create_statusbar (window, main_box);
/* Add the main area */
- gedit_debug_message (DEBUG_WINDOW, "Add main area");
+ gedit_debug_message (DEBUG_WINDOW, "Add main area");
window->priv->hpaned = gtk_hpaned_new ();
gtk_box_pack_start (GTK_BOX (main_box),
window->priv->hpaned,
@@ -3797,11 +3985,11 @@ gedit_window_init (GeditWindow *window)
gedit_debug_message (DEBUG_WINDOW, "Create gedit notebook");
window->priv->notebook = gedit_notebook_new ();
- gtk_paned_pack1 (GTK_PANED (window->priv->vpaned),
+ gtk_paned_pack1 (GTK_PANED (window->priv->vpaned),
window->priv->notebook,
TRUE,
TRUE);
- gtk_widget_show (window->priv->notebook);
+ gtk_widget_show (window->priv->notebook);
/* side and bottom panels */
create_side_panel (window);
@@ -3852,24 +4040,24 @@ gedit_window_init (GeditWindow *window)
G_CALLBACK (notebook_switch_page),
window);
g_signal_connect (window->priv->notebook,
- "tab_added",
- G_CALLBACK (notebook_tab_added),
+ "gedit_page_added",
+ G_CALLBACK (notebook_page_added),
window);
g_signal_connect (window->priv->notebook,
- "tab_removed",
- G_CALLBACK (notebook_tab_removed),
+ "gedit_page_removed",
+ G_CALLBACK (notebook_page_removed),
window);
g_signal_connect (window->priv->notebook,
- "tabs_reordered",
- G_CALLBACK (notebook_tabs_reordered),
- window);
+ "pages_reordered",
+ G_CALLBACK (notebook_pages_reordered),
+ window);
g_signal_connect (window->priv->notebook,
- "tab_detached",
- G_CALLBACK (notebook_tab_detached),
+ "page_detached",
+ G_CALLBACK (notebook_page_detached),
window);
g_signal_connect (window->priv->notebook,
- "tab_close_request",
- G_CALLBACK (notebook_tab_close_request),
+ "page_close_request",
+ G_CALLBACK (notebook_page_close_request),
window);
g_signal_connect (window->priv->notebook,
"button-press-event",
@@ -3916,6 +4104,21 @@ gedit_window_init (GeditWindow *window)
gedit_debug_message (DEBUG_WINDOW, "END");
}
+GeditViewContainer *
+gedit_window_get_active_view_container (GeditWindow *window)
+{
+ GeditViewContainer *container;
+
+ g_return_val_if_fail (GEDIT_IS_WINDOW (window), NULL);
+
+ if (window->priv->active_page == NULL)
+ return NULL;
+
+ container = gedit_page_get_active_view_container (window->priv->active_page);
+
+ return container;
+}
+
/**
* gedit_window_get_active_view:
* @window: a #GeditWindow
@@ -3928,13 +4131,15 @@ GeditView *
gedit_window_get_active_view (GeditWindow *window)
{
GeditView *view;
+ GeditViewContainer *container;
g_return_val_if_fail (GEDIT_IS_WINDOW (window), NULL);
- if (window->priv->active_tab == NULL)
+ container = gedit_window_get_active_view_container (window);
+ if (container == NULL)
return NULL;
-
- view = gedit_tab_get_view (GEDIT_TAB (window->priv->active_tab));
+
+ view = gedit_view_container_get_view (container);
return view;
}
@@ -3950,15 +4155,15 @@ gedit_window_get_active_view (GeditWindow *window)
GeditDocument *
gedit_window_get_active_document (GeditWindow *window)
{
- GeditView *view;
+ GeditViewContainer *container;
g_return_val_if_fail (GEDIT_IS_WINDOW (window), NULL);
- view = gedit_window_get_active_view (window);
- if (view == NULL)
+ container = gedit_window_get_active_view_container (window);
+ if (container == NULL)
return NULL;
- return GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
+ return gedit_view_container_get_document (container);
}
GtkWidget *
@@ -3970,103 +4175,107 @@ _gedit_window_get_notebook (GeditWindow *window)
}
/**
- * gedit_window_create_tab:
+ * gedit_window_create_page:
* @window: a #GeditWindow
- * @jump_to: %TRUE to set the new #GeditTab as active
+ * @jump_to: %TRUE to set the new #GeditPage as active
*
- * Creates a new #GeditTab and adds the new tab to the #GeditNotebook.
- * In case @jump_to is %TRUE the #GeditNotebook switches to that new #GeditTab.
+ * Creates a new #GeditPage and adds the new page to the #GeditNotebook.
+ * In case @jump_to is %TRUE the #GeditNotebook switches to that new #GeditPage.
*
- * Returns: a new #GeditTab
+ * Returns: a new #GeditPage
*/
-GeditTab *
-gedit_window_create_tab (GeditWindow *window,
- gboolean jump_to)
+GeditPage *
+gedit_window_create_page (GeditWindow *window,
+ gboolean jump_to)
{
- GeditTab *tab;
+ GeditPage *page;
g_return_val_if_fail (GEDIT_IS_WINDOW (window), NULL);
- tab = GEDIT_TAB (_gedit_tab_new ());
- gtk_widget_show (GTK_WIDGET (tab));
+ page = GEDIT_PAGE (_gedit_page_new (NULL));
+ gtk_widget_show (GTK_WIDGET (page));
- gedit_notebook_add_tab (GEDIT_NOTEBOOK (window->priv->notebook),
- tab,
- -1,
- jump_to);
+ gedit_notebook_add_page (GEDIT_NOTEBOOK (window->priv->notebook),
+ page,
+ -1,
+ jump_to);
- return tab;
+ return page;
}
/**
- * gedit_window_create_tab_from_uri:
+ * gedit_window_create_page_from_uri:
* @window: a #GeditWindow
* @uri: the uri of the document
* @encoding: a #GeditEncoding
* @line_pos: the line position to visualize
* @create: %TRUE to create a new document in case @uri does exist
- * @jump_to: %TRUE to set the new #GeditTab as active
+ * @jump_to: %TRUE to set the new #GeditPage as active
*
- * Creates a new #GeditTab loading the document specified by @uri.
- * In case @jump_to is %TRUE the #GeditNotebook swithes to that new #GeditTab.
+ * Creates a new #GeditPage loading the document specified by @uri.
+ * In case @jump_to is %TRUE the #GeditNotebook swithes to that new #GeditPage.
* Whether @create is %TRUE, creates a new empty document if location does
* not refer to an existing file
*
- * Returns: a new #GeditTab
+ * Returns: a new #GeditPage
*/
-GeditTab *
-gedit_window_create_tab_from_uri (GeditWindow *window,
- const gchar *uri,
- const GeditEncoding *encoding,
- gint line_pos,
- gboolean create,
- gboolean jump_to)
+GeditPage *
+gedit_window_create_page_from_uri (GeditWindow *window,
+ const gchar *uri,
+ const GeditEncoding *encoding,
+ gint line_pos,
+ gboolean create,
+ gboolean jump_to)
{
- GtkWidget *tab;
+ GtkWidget *container;
+ GtkWidget *page;
g_return_val_if_fail (GEDIT_IS_WINDOW (window), NULL);
g_return_val_if_fail (uri != NULL, NULL);
- tab = _gedit_tab_new_from_uri (uri,
- encoding,
- line_pos,
- create);
- if (tab == NULL)
+ container = _gedit_view_container_new_from_uri (uri,
+ encoding,
+ line_pos,
+ create);
+ if (container == NULL)
return NULL;
- gtk_widget_show (tab);
-
- gedit_notebook_add_tab (GEDIT_NOTEBOOK (window->priv->notebook),
- GEDIT_TAB (tab),
- -1,
- jump_to);
-
- return GEDIT_TAB (tab);
-}
+ page = _gedit_page_new (GEDIT_VIEW_CONTAINER (container));
+ gtk_widget_show (page);
+
+ gedit_notebook_add_page (GEDIT_NOTEBOOK (window->priv->notebook),
+ GEDIT_PAGE (page),
+ -1,
+ jump_to);
+
+ return GEDIT_PAGE (page);
+}
/**
- * gedit_window_get_active_tab:
+ * gedit_window_get_active_page:
* @window: a GeditWindow
*
- * Gets the active #GeditTab in the @window.
+ * Gets the active #GeditPage in the @window.
*
- * Returns: the active #GeditTab in the @window.
+ * Returns: the active #GeditPage in the @window.
*/
-GeditTab *
-gedit_window_get_active_tab (GeditWindow *window)
+GeditPage *
+gedit_window_get_active_page (GeditWindow *window)
{
g_return_val_if_fail (GEDIT_IS_WINDOW (window), NULL);
- return (window->priv->active_tab == NULL) ?
- NULL : GEDIT_TAB (window->priv->active_tab);
+ return (window->priv->active_page == NULL) ?
+ NULL : GEDIT_PAGE (window->priv->active_page);
}
static void
-add_document (GeditTab *tab, GList **res)
+add_document (GeditPage *page, GList **res)
{
GeditDocument *doc;
+ GeditViewContainer *container;
- doc = gedit_tab_get_document (tab);
+ container = gedit_page_get_active_view_container (page);
+ doc = gedit_view_container_get_document (container);
*res = g_list_prepend (*res, doc);
}
@@ -4097,11 +4306,13 @@ gedit_window_get_documents (GeditWindow *window)
}
static void
-add_view (GeditTab *tab, GList **res)
+add_view (GeditPage *page, GList **res)
{
GeditView *view;
+ GeditViewContainer *container;
- view = gedit_tab_get_view (tab);
+ container = gedit_page_get_active_view_container (page);
+ view = gedit_view_container_get_view (container);
*res = g_list_prepend (*res, view);
}
@@ -4133,119 +4344,129 @@ gedit_window_get_views (GeditWindow *window)
/**
* gedit_window_close_tab:
* @window: a #GeditWindow
- * @tab: the #GeditTab to close
+ * @page: the #GeditPage to close
*
- * Closes the @tab.
+ * Closes the @page.
*/
void
-gedit_window_close_tab (GeditWindow *window,
- GeditTab *tab)
+gedit_window_close_page (GeditWindow *window,
+ GeditPage *page)
{
+ GList *containers, *l;
+
g_return_if_fail (GEDIT_IS_WINDOW (window));
- g_return_if_fail (GEDIT_IS_TAB (tab));
- g_return_if_fail ((gedit_tab_get_state (tab) != GEDIT_TAB_STATE_SAVING) &&
- (gedit_tab_get_state (tab) != GEDIT_TAB_STATE_SHOWING_PRINT_PREVIEW));
+ g_return_if_fail (GEDIT_IS_PAGE (page));
+
+ /* FIXME: This should go in split-removed ? */
+ containers = gedit_page_get_view_containers (page);
+ for (l = containers; l != NULL; l = g_list_next (l))
+ {
+ GeditViewContainer *c = GEDIT_VIEW_CONTAINER (l->data);
- gedit_notebook_remove_tab (GEDIT_NOTEBOOK (window->priv->notebook),
- tab);
+ g_return_if_fail ((gedit_view_container_get_state (c) != GEDIT_VIEW_CONTAINER_STATE_SAVING) &&
+ (gedit_view_container_get_state (c) != GEDIT_VIEW_CONTAINER_STATE_SHOWING_PRINT_PREVIEW));
+ }
+
+ gedit_notebook_remove_page (GEDIT_NOTEBOOK (window->priv->notebook),
+ page);
}
/**
- * gedit_window_close_all_tabs:
+ * gedit_window_close_all_pages:
* @window: a #GeditWindow
*
- * Closes all opened tabs.
+ * Closes all opened pages.
*/
void
-gedit_window_close_all_tabs (GeditWindow *window)
+gedit_window_close_all_pages (GeditWindow *window)
{
g_return_if_fail (GEDIT_IS_WINDOW (window));
g_return_if_fail (!(window->priv->state & GEDIT_WINDOW_STATE_SAVING) &&
!(window->priv->state & GEDIT_WINDOW_STATE_SAVING_SESSION));
- window->priv->removing_tabs = TRUE;
+ window->priv->removing_pages = TRUE;
- gedit_notebook_remove_all_tabs (GEDIT_NOTEBOOK (window->priv->notebook));
+ gedit_notebook_remove_all_pages (GEDIT_NOTEBOOK (window->priv->notebook));
- window->priv->removing_tabs = FALSE;
+ window->priv->removing_pages = FALSE;
}
/**
- * gedit_window_close_tabs:
+ * gedit_window_close_pages:
* @window: a #GeditWindow
- * @tabs: a list of #GeditTab
+ * @pages: a list of #GeditPage
*
- * Closes all tabs specified by @tabs.
+ * Closes all pages specified by @pages.
*/
void
-gedit_window_close_tabs (GeditWindow *window,
- const GList *tabs)
+gedit_window_close_pages (GeditWindow *window,
+ const GList *pages)
{
g_return_if_fail (GEDIT_IS_WINDOW (window));
g_return_if_fail (!(window->priv->state & GEDIT_WINDOW_STATE_SAVING) &&
!(window->priv->state & GEDIT_WINDOW_STATE_SAVING_SESSION));
- if (tabs == NULL)
+ if (pages == NULL)
return;
- window->priv->removing_tabs = TRUE;
+ window->priv->removing_pages = TRUE;
- while (tabs != NULL)
+ while (pages != NULL)
{
- if (tabs->next == NULL)
- window->priv->removing_tabs = FALSE;
+ if (pages->next == NULL)
+ window->priv->removing_pages = FALSE;
- gedit_notebook_remove_tab (GEDIT_NOTEBOOK (window->priv->notebook),
- GEDIT_TAB (tabs->data));
+ gedit_notebook_remove_page (GEDIT_NOTEBOOK (window->priv->notebook),
+ GEDIT_PAGE (pages->data));
- tabs = g_list_next (tabs);
+ pages = g_list_next (pages);
}
- g_return_if_fail (window->priv->removing_tabs == FALSE);
+ g_return_if_fail (window->priv->removing_pages == FALSE);
}
GeditWindow *
-_gedit_window_move_tab_to_new_window (GeditWindow *window,
- GeditTab *tab)
+_gedit_window_move_page_to_new_window (GeditWindow *window,
+ GeditPage *page)
{
GeditWindow *new_window;
g_return_val_if_fail (GEDIT_IS_WINDOW (window), NULL);
- g_return_val_if_fail (GEDIT_IS_TAB (tab), NULL);
+ g_return_val_if_fail (GEDIT_IS_PAGE (page), NULL);
g_return_val_if_fail (gtk_notebook_get_n_pages (
- GTK_NOTEBOOK (window->priv->notebook)) > 1,
+ GTK_NOTEBOOK (window->priv->notebook)) > 1,
NULL);
-
+
new_window = clone_window (window);
- gedit_notebook_move_tab (GEDIT_NOTEBOOK (window->priv->notebook),
- GEDIT_NOTEBOOK (new_window->priv->notebook),
- tab,
- -1);
-
+ gedit_notebook_move_page (GEDIT_NOTEBOOK (window->priv->notebook),
+ GEDIT_NOTEBOOK (new_window->priv->notebook),
+ page,
+ -1);
+
gtk_widget_show (GTK_WIDGET (new_window));
return new_window;
-}
+}
/**
- * gedit_window_set_active_tab:
+ * gedit_window_set_active_page:
* @window: a #GeditWindow
- * @tab: a #GeditTab
+ * @page: a #GeditPage
*
- * Switches to the tab that matches with @tab.
+ * Switches to the page that matches with @page.
*/
void
-gedit_window_set_active_tab (GeditWindow *window,
- GeditTab *tab)
+gedit_window_set_active_page (GeditWindow *window,
+ GeditPage *page)
{
gint page_num;
g_return_if_fail (GEDIT_IS_WINDOW (window));
- g_return_if_fail (GEDIT_IS_TAB (tab));
+ g_return_if_fail (GEDIT_IS_PAGE (page));
page_num = gtk_notebook_page_num (GTK_NOTEBOOK (window->priv->notebook),
- GTK_WIDGET (tab));
+ GTK_WIDGET (page));
g_return_if_fail (page_num != -1);
gtk_notebook_set_current_page (GTK_NOTEBOOK (window->priv->notebook),
@@ -4269,11 +4490,11 @@ gedit_window_get_group (GeditWindow *window)
}
gboolean
-_gedit_window_is_removing_tabs (GeditWindow *window)
+_gedit_window_is_removing_pages (GeditWindow *window)
{
g_return_val_if_fail (GEDIT_IS_WINDOW (window), FALSE);
- return window->priv->removing_tabs;
+ return window->priv->removing_pages;
}
/**
@@ -4395,32 +4616,32 @@ GList *
gedit_window_get_unsaved_documents (GeditWindow *window)
{
GList *unsaved_docs = NULL;
- GList *tabs;
+ GList *pages;
GList *l;
g_return_val_if_fail (GEDIT_IS_WINDOW (window), NULL);
- tabs = gtk_container_get_children (GTK_CONTAINER (window->priv->notebook));
+ pages = gtk_container_get_children (GTK_CONTAINER (window->priv->notebook));
- l = tabs;
+ l = pages;
while (l != NULL)
{
- GeditTab *tab;
+ GeditViewContainer *container;
- tab = GEDIT_TAB (l->data);
+ container = gedit_page_get_active_view_container (GEDIT_PAGE (l->data));
- if (!_gedit_tab_can_close (tab))
+ if (!_gedit_view_container_can_close (container))
{
GeditDocument *doc;
- doc = gedit_tab_get_document (tab);
+ doc = gedit_view_container_get_document (container);
unsaved_docs = g_list_prepend (unsaved_docs, doc);
}
l = g_list_next (l);
}
- g_list_free (tabs);
+ g_list_free (pages);
return g_list_reverse (unsaved_docs);
}
@@ -4540,17 +4761,17 @@ _gedit_window_is_fullscreen (GeditWindow *window)
* @window: a #GeditWindow
* @location: a #GFile
*
- * Gets the #GeditTab that matches with the given @location.
+ * Gets the #GeditViewContainer that matches with the given @location.
*
- * Returns: the #GeditTab that matches with the given @location.
+ * Returns: the #GeditViewContainer that matches with the given @location.
*/
-GeditTab *
-gedit_window_get_tab_from_location (GeditWindow *window,
- GFile *location)
+GeditViewContainer *
+gedit_window_get_view_container_from_location (GeditWindow *window,
+ GFile *location)
{
GList *tabs;
GList *l;
- GeditTab *ret = NULL;
+ GeditViewContainer *ret = NULL;
g_return_val_if_fail (GEDIT_IS_WINDOW (window), NULL);
g_return_val_if_fail (G_IS_FILE (location), NULL);
@@ -4560,15 +4781,15 @@ gedit_window_get_tab_from_location (GeditWindow *window,
for (l = tabs; l != NULL; l = g_list_next (l))
{
GeditDocument *d;
- GeditTab *t;
+ GeditViewContainer *t;
GFile *f;
- t = GEDIT_TAB (l->data);
- d = gedit_tab_get_document (t);
+ t = GEDIT_VIEW_CONTAINER (l->data);
+ d = gedit_view_container_get_document (t);
f = gedit_document_get_location (d);
- if ((f != NULL))
+ if (f != NULL)
{
gboolean found = g_file_equal (location, f);
@@ -4604,31 +4825,3 @@ gedit_window_get_message_bus (GeditWindow *window)
return window->priv->message_bus;
}
-/**
- * gedit_window_get_tab_from_uri:
- * @window: a #GeditWindow
- * @uri: the uri to get the #GeditTab
- *
- * Gets the #GeditTab that matches @uri.
- *
- * Returns: the #GeditTab associated with @uri.
- *
- * Deprecated: 2.24: Use gedit_window_get_tab_from_location() instead.
- */
-GeditTab *
-gedit_window_get_tab_from_uri (GeditWindow *window,
- const gchar *uri)
-{
- GFile *f;
- GeditTab *tab;
-
- g_return_val_if_fail (GEDIT_IS_WINDOW (window), NULL);
- g_return_val_if_fail (uri != NULL, NULL);
-
- f = g_file_new_for_uri (uri);
- tab = gedit_window_get_tab_from_location (window, f);
- g_object_unref (f);
-
- return tab;
-}
-
diff --git a/gedit/gedit-window.h b/gedit/gedit-window.h
index e8c7eef..639ef2f 100644
--- a/gedit/gedit-window.h
+++ b/gedit/gedit-window.h
@@ -34,7 +34,8 @@
#include <gio/gio.h>
#include <gtk/gtk.h>
-#include <gedit/gedit-tab.h>
+#include <gedit/gedit-view-container.h>
+#include <gedit/gedit-page.h>
#include <gedit/gedit-panel.h>
#include <gedit/gedit-message-bus.h>
@@ -86,14 +87,14 @@ struct _GeditWindowClass
GtkWindowClass parent_class;
/* Signals */
- void (* tab_added) (GeditWindow *window,
- GeditTab *tab);
- void (* tab_removed) (GeditWindow *window,
- GeditTab *tab);
- void (* tabs_reordered) (GeditWindow *window);
- void (* active_tab_changed) (GeditWindow *window,
- GeditTab *tab);
- void (* active_tab_state_changed)
+ void (* page_added) (GeditWindow *window,
+ GeditPage *page);
+ void (* page_removed) (GeditWindow *window,
+ GeditPage *page);
+ void (* pages_reordered) (GeditWindow *window);
+ void (* active_page_changed)(GeditWindow *window,
+ GeditPage *page);
+ void (* active_page_state_changed)
(GeditWindow *window);
};
@@ -102,30 +103,35 @@ struct _GeditWindowClass
*/
GType gedit_window_get_type (void) G_GNUC_CONST;
-GeditTab *gedit_window_create_tab (GeditWindow *window,
+GeditPage *gedit_window_create_page
+ (GeditWindow *window,
gboolean jump_to);
-
-GeditTab *gedit_window_create_tab_from_uri (GeditWindow *window,
+
+GeditPage *gedit_window_create_page_from_uri
+ (GeditWindow *window,
const gchar *uri,
const GeditEncoding *encoding,
gint line_pos,
gboolean create,
gboolean jump_to);
-void gedit_window_close_tab (GeditWindow *window,
- GeditTab *tab);
+void gedit_window_close_page (GeditWindow *window,
+ GeditPage *page);
-void gedit_window_close_all_tabs (GeditWindow *window);
+void gedit_window_close_all_pages (GeditWindow *window);
-void gedit_window_close_tabs (GeditWindow *window,
+void gedit_window_close_pages (GeditWindow *window,
const GList *tabs);
-GeditTab *gedit_window_get_active_tab (GeditWindow *window);
+GeditPage *gedit_window_get_active_page
+ (GeditWindow *window);
-void gedit_window_set_active_tab (GeditWindow *window,
- GeditTab *tab);
+void gedit_window_set_active_page (GeditWindow *window,
+ GeditPage *page);
/* Helper functions */
+GeditViewContainer *gedit_window_get_active_view_container
+ (GeditWindow *window);
GeditView *gedit_window_get_active_view (GeditWindow *window);
GeditDocument *gedit_window_get_active_document (GeditWindow *window);
@@ -151,10 +157,12 @@ GtkUIManager *gedit_window_get_ui_manager (GeditWindow *window);
GeditWindowState gedit_window_get_state (GeditWindow *window);
-GeditTab *gedit_window_get_tab_from_location (GeditWindow *window,
+GeditViewContainer *gedit_window_get_view_container_from_location
+ (GeditWindow *window,
GFile *location);
-GeditTab *gedit_window_get_tab_from_uri (GeditWindow *window,
+GeditViewContainer *gedit_window_get_view_container_from_uri
+ (GeditWindow *window,
const gchar *uri);
/* Message bus */
@@ -165,9 +173,9 @@ GeditMessageBus *gedit_window_get_message_bus (GeditWindow *window);
*/
GtkWidget *_gedit_window_get_notebook (GeditWindow *window);
-GeditWindow *_gedit_window_move_tab_to_new_window (GeditWindow *window,
- GeditTab *tab);
-gboolean _gedit_window_is_removing_tabs (GeditWindow *window);
+GeditWindow *_gedit_window_move_page_to_new_window (GeditWindow *window,
+ GeditPage *page);
+gboolean _gedit_window_is_removing_pages (GeditWindow *window);
GFile *_gedit_window_get_default_location (GeditWindow *window);
diff --git a/gedit/gedit.c b/gedit/gedit.c
index 03a1705..e912768 100644
--- a/gedit/gedit.c
+++ b/gedit/gedit.c
@@ -369,7 +369,7 @@ on_message_received (const char *message,
line_position);
if (new_document_option)
- gedit_window_create_tab (window, TRUE);
+ gedit_window_create_page (window, TRUE);
}
else
{
@@ -379,7 +379,7 @@ on_message_received (const char *message,
if (doc == NULL ||
!gedit_document_is_untouched (doc) ||
new_document_option)
- gedit_window_create_tab (window, TRUE);
+ gedit_window_create_page (window, TRUE);
}
/* set the proper interaction time on the window.
@@ -715,8 +715,8 @@ main (int argc, char *argv[])
}
else
{
- gedit_debug_message (DEBUG_APP, "Create tab");
- gedit_window_create_tab (window, TRUE);
+ gedit_debug_message (DEBUG_APP, "Create page");
+ gedit_window_create_page (window, TRUE);
}
gedit_debug_message (DEBUG_APP, "Show window");
@@ -725,7 +725,7 @@ main (int argc, char *argv[])
free_command_line_data ();
}
- gedit_debug_message (DEBUG_APP, "Start gtk-main");
+ gedit_debug_message (DEBUG_APP, "Start gtk-main");
gtk_main();
#ifndef G_OS_WIN32
diff --git a/plugin-loaders/Makefile.am b/plugin-loaders/Makefile.am
index bf1e964..f895e0f 100644
--- a/plugin-loaders/Makefile.am
+++ b/plugin-loaders/Makefile.am
@@ -1,7 +1,6 @@
SUBDIRS = c
if ENABLE_PYTHON
-SUBDIRS += python
endif
-include $(top_srcdir)/git.mk
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]