Factor out a GeditViewFrame class.

This class contains the sw, the view and the document.
parent 8bb0d026
......@@ -124,6 +124,7 @@ NOINST_H_FILES = \
gedit-tab-label.h \
gedittextregion.h \
gedit-ui.h \
gedit-view-frame.h \
gedit-window-private.h
INST_H_FILES = \
......@@ -207,6 +208,7 @@ libgedit_c_files = \
gedit-tab-label.c \
gedit-utils.c \
gedit-view.c \
gedit-view-frame.c \
gedit-window.c \
gedittextregion.c
......
......@@ -44,6 +44,7 @@
#include "gedit-debug.h"
#include "gedit-enum-types.h"
#include "gedit-settings.h"
#include "gedit-view-frame.h"
#define GEDIT_TAB_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), GEDIT_TYPE_TAB, GeditTabPrivate))
......@@ -54,8 +55,7 @@ struct _GeditTabPrivate
GSettings *editor;
GeditTabState state;
GtkWidget *view;
GtkWidget *view_scrolled_window;
GeditViewFrame *frame;
GtkWidget *info_bar;
GtkWidget *print_preview;
......@@ -419,25 +419,28 @@ static void
set_view_properties_according_to_state (GeditTab *tab,
GeditTabState state)
{
GeditView *view;
gboolean val;
gboolean hl_current_line;
hl_current_line = g_settings_get_boolean (tab->priv->editor,
GEDIT_SETTINGS_HIGHLIGHT_CURRENT_LINE);
view = gedit_view_frame_get_view (tab->priv->frame);
val = ((state == GEDIT_TAB_STATE_NORMAL) &&
(tab->priv->print_preview == NULL) &&
!tab->priv->not_editable);
gtk_text_view_set_editable (GTK_TEXT_VIEW (tab->priv->view), val);
gtk_text_view_set_editable (GTK_TEXT_VIEW (view), val);
val = ((state != GEDIT_TAB_STATE_LOADING) &&
(state != GEDIT_TAB_STATE_CLOSING));
gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (tab->priv->view), val);
gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view), val);
val = ((state != GEDIT_TAB_STATE_LOADING) &&
(state != GEDIT_TAB_STATE_CLOSING) &&
(hl_current_line));
gtk_source_view_set_highlight_current_line (GTK_SOURCE_VIEW (tab->priv->view), val);
gtk_source_view_set_highlight_current_line (GTK_SOURCE_VIEW (view), val);
}
static void
......@@ -457,15 +460,15 @@ gedit_tab_set_state (GeditTab *tab,
if ((state == GEDIT_TAB_STATE_LOADING_ERROR) || /* FIXME: add other states if needed */
(state == GEDIT_TAB_STATE_SHOWING_PRINT_PREVIEW))
{
gtk_widget_hide (tab->priv->view_scrolled_window);
gtk_widget_hide (GTK_WIDGET (tab->priv->frame));
}
else
{
if (tab->priv->print_preview == NULL)
gtk_widget_show (tab->priv->view_scrolled_window);
gtk_widget_show (GTK_WIDGET (tab->priv->frame));
}
set_cursor_according_to_state (GTK_TEXT_VIEW (tab->priv->view),
set_cursor_according_to_state (GTK_TEXT_VIEW (gedit_view_frame_get_view (tab->priv->frame)),
state);
g_object_notify (G_OBJECT (tab), "state");
......@@ -1069,7 +1072,7 @@ document_loaded (GeditDocument *document,
}
/* Scroll to the cursor when the document is loaded */
gedit_view_scroll_to_cursor (GEDIT_VIEW (tab->priv->view));
gedit_view_scroll_to_cursor (gedit_view_frame_get_view (tab->priv->frame));
all_documents = gedit_app_get_documents (gedit_app_get_default ());
......@@ -1551,25 +1554,14 @@ on_drop_uris (GeditView *view,
g_signal_emit (G_OBJECT (tab), signals[DROP_URIS], 0, uri_list);
}
static GMountOperation *
tab_mount_operation_factory (GeditDocument *doc,
gpointer userdata)
{
GeditTab *tab = GEDIT_TAB (userdata);
GtkWidget *window;
window = gtk_widget_get_toplevel (GTK_WIDGET (tab));
return gtk_mount_operation_new (GTK_WINDOW (window));
}
static void
gedit_tab_init (GeditTab *tab)
{
GtkWidget *sw;
GeditDocument *doc;
GeditLockdownMask lockdown;
gboolean auto_save;
gint auto_save_interval;
GeditDocument *doc;
GeditView *view;
tab->priv = GEDIT_TAB_GET_PRIVATE (tab);
......@@ -1583,14 +1575,6 @@ gedit_tab_init (GeditTab *tab)
tab->priv->ask_if_externally_modified = TRUE;
/* Create the scrolled window */
sw = gtk_scrolled_window_new (NULL, NULL);
tab->priv->view_scrolled_window = sw;
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
/* Manage auto save data */
auto_save = g_settings_get_boolean (tab->priv->editor,
GEDIT_SETTINGS_AUTO_SAVE);
......@@ -1603,28 +1587,19 @@ gedit_tab_init (GeditTab *tab)
tab->priv->auto_save = (tab->priv->auto_save != FALSE);
tab->priv->auto_save_interval = auto_save_interval;
/* FIXME
if (tab->priv->auto_save_interval <= 0)
tab->priv->auto_save_interval = GPM_DEFAULT_AUTO_SAVE_INTERVAL;*/
/* Create the view */
doc = gedit_document_new ();
g_object_set_data (G_OBJECT (doc), GEDIT_TAB_KEY, tab);
/* Create the frame */
tab->priv->frame = gedit_view_frame_new ();
gtk_widget_show (GTK_WIDGET (tab->priv->frame));
_gedit_document_set_mount_operation_factory (doc,
tab_mount_operation_factory,
tab);
gtk_box_pack_end (GTK_BOX (tab), GTK_WIDGET (tab->priv->frame),
TRUE, TRUE, 0);
tab->priv->view = gedit_view_new (doc);
g_object_unref (doc);
gtk_widget_show (tab->priv->view);
g_object_set_data (G_OBJECT (tab->priv->view), GEDIT_TAB_KEY, tab);
doc = gedit_view_frame_get_document (tab->priv->frame);
g_object_set_data (G_OBJECT (doc), GEDIT_TAB_KEY, tab);
gtk_box_pack_end (GTK_BOX (tab), sw, TRUE, TRUE, 0);
gtk_container_add (GTK_CONTAINER (sw), tab->priv->view);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
GTK_SHADOW_IN);
gtk_widget_show (sw);
view = gedit_view_frame_get_view (tab->priv->frame);
g_object_set_data (G_OBJECT (view), GEDIT_TAB_KEY, tab);
g_signal_connect (doc,
"notify::location",
......@@ -1655,17 +1630,17 @@ gedit_tab_init (GeditTab *tab)
G_CALLBACK (document_saved),
tab);
g_signal_connect_after (tab->priv->view,
g_signal_connect_after (view,
"focus-in-event",
G_CALLBACK (view_focused_in),
tab);
g_signal_connect_after (tab->priv->view,
g_signal_connect_after (view,
"realize",
G_CALLBACK (view_realized),
tab);
g_signal_connect (tab->priv->view,
g_signal_connect (view,
"drop-uris",
G_CALLBACK (on_drop_uris),
tab);
......@@ -1737,7 +1712,7 @@ gedit_tab_get_view (GeditTab *tab)
{
g_return_val_if_fail (GEDIT_IS_TAB (tab), NULL);
return GEDIT_VIEW (tab->priv->view);
return gedit_view_frame_get_view (tab->priv->frame);
}
/**
......@@ -1753,8 +1728,7 @@ gedit_tab_get_document (GeditTab *tab)
{
g_return_val_if_fail (GEDIT_IS_TAB (tab), NULL);
return GEDIT_DOCUMENT (gtk_text_view_get_buffer (
GTK_TEXT_VIEW (tab->priv->view)));
return gedit_view_frame_get_document (tab->priv->frame);
}
#define MAX_DOC_NAME_LENGTH 40
......
/*
* gedit-view-frame.c
* This file is part of gedit
*
* Copyright (C) 2010 - 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-frame.h"
#define GEDIT_VIEW_FRAME_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GEDIT_TYPE_VIEW_FRAME, GeditViewFramePrivate))
struct _GeditViewFramePrivate
{
GtkWidget *view;
};
enum
{
PROP_0,
PROP_DOCUMENT,
PROP_VIEW
};
G_DEFINE_TYPE (GeditViewFrame, gedit_view_frame, GTK_TYPE_VBOX)
static void
gedit_view_frame_finalize (GObject *object)
{
G_OBJECT_CLASS (gedit_view_frame_parent_class)->finalize (object);
}
static void
gedit_view_frame_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GeditViewFrame *frame = GEDIT_VIEW_FRAME (object);
switch (prop_id)
{
case PROP_DOCUMENT:
g_value_set_object (value,
gedit_view_frame_get_document (frame));
break;
case PROP_VIEW:
g_value_set_object (value,
gedit_view_frame_get_view (frame));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gedit_view_frame_class_init (GeditViewFrameClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gedit_view_frame_finalize;
object_class->get_property = gedit_view_frame_get_property;
g_object_class_install_property (object_class, PROP_DOCUMENT,
g_param_spec_object ("document",
"Document",
"The Document",
GEDIT_TYPE_DOCUMENT,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class, PROP_VIEW,
g_param_spec_object ("view",
"View",
"The View",
GEDIT_TYPE_VIEW,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
g_type_class_add_private (object_class, sizeof (GeditViewFramePrivate));
}
static GMountOperation *
view_frame_mount_operation_factory (GeditDocument *doc,
gpointer user_data)
{
GeditViewFrame *frame = GEDIT_VIEW_FRAME (user_data);
GtkWidget *window;
window = gtk_widget_get_toplevel (GTK_WIDGET (frame));
return gtk_mount_operation_new (GTK_WINDOW (window));
}
static void
gedit_view_frame_init (GeditViewFrame *frame)
{
GeditDocument *doc;
GtkWidget *sw;
frame->priv = GEDIT_VIEW_FRAME_GET_PRIVATE (frame);
doc = gedit_document_new ();
_gedit_document_set_mount_operation_factory (doc,
view_frame_mount_operation_factory,
frame);
frame->priv->view = gedit_view_new (doc);
gtk_widget_show (frame->priv->view);
g_object_unref (doc);
/* 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), frame->priv->view);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
GTK_SHADOW_IN);
gtk_widget_show (sw);
gtk_box_pack_start (GTK_BOX (frame), sw, TRUE, TRUE, 0);
}
GeditViewFrame *
gedit_view_frame_new ()
{
return g_object_new (GEDIT_TYPE_VIEW_FRAME, NULL);
}
GeditDocument *
gedit_view_frame_get_document (GeditViewFrame *frame)
{
g_return_val_if_fail (GEDIT_IS_VIEW_FRAME (frame), NULL);
return GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (frame->priv->view)));
}
GeditView *
gedit_view_frame_get_view (GeditViewFrame *frame)
{
g_return_val_if_fail (GEDIT_IS_VIEW_FRAME (frame), NULL);
return GEDIT_VIEW (frame->priv->view);
}
/*
* gedit-view-frame.h
* This file is part of gedit
*
* Copyright (C) 2010 - 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_FRAME_H__
#define __GEDIT_VIEW_FRAME_H__
#include <gtk/gtk.h>
#include "gedit-document.h"
#include "gedit-view.h"
G_BEGIN_DECLS
#define GEDIT_TYPE_VIEW_FRAME (gedit_view_frame_get_type ())
#define GEDIT_VIEW_FRAME(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_VIEW_FRAME, GeditViewFrame))
#define GEDIT_VIEW_FRAME_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_VIEW_FRAME, GeditViewFrame const))
#define GEDIT_VIEW_FRAME_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEDIT_TYPE_VIEW_FRAME, GeditViewFrameClass))
#define GEDIT_IS_VIEW_FRAME(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEDIT_TYPE_VIEW_FRAME))
#define GEDIT_IS_VIEW_FRAME_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEDIT_TYPE_VIEW_FRAME))
#define GEDIT_VIEW_FRAME_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEDIT_TYPE_VIEW_FRAME, GeditViewFrameClass))
typedef struct _GeditViewFrame GeditViewFrame;
typedef struct _GeditViewFrameClass GeditViewFrameClass;
typedef struct _GeditViewFramePrivate GeditViewFramePrivate;
struct _GeditViewFrame
{
GtkVBox parent;
GeditViewFramePrivate *priv;
};
struct _GeditViewFrameClass
{
GtkVBoxClass parent_class;
};
GType gedit_view_frame_get_type (void) G_GNUC_CONST;
GeditViewFrame *gedit_view_frame_new (void);
GeditDocument *gedit_view_frame_get_document (GeditViewFrame *frame);
GeditView *gedit_view_frame_get_view (GeditViewFrame *frame);
G_END_DECLS
#endif /* __GEDIT_VIEW_FRAME_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment