[gnome-builder] bring back html/markdown preview
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] bring back html/markdown preview
- Date: Tue, 24 Mar 2015 00:28:22 +0000 (UTC)
commit a4c75b2a70208386bc87b4504214ff7e5b9b28a7
Author: Christian Hergert <christian hergert me>
Date: Thu Mar 19 17:00:05 2015 -0700
bring back html/markdown preview
data/keybindings/default.css | 1 +
data/keybindings/emacs.css | 2 +
data/keybindings/vim.css | 1 +
data/ui/gb-view-stack.ui | 15 +++++
src/documents/gb-document.h | 2 +
src/editor/gb-editor-view-actions.c | 59 ++++++++++++++++++++
src/gnome-builder.mk | 8 ++--
src/html/gb-html-document.c | 17 +++---
src/html/gb-html-view.c | 101 +++++++++++++++-------------------
src/html/gb-html-view.h | 31 +----------
src/resources/ui/gb-html-view.ui | 5 +-
11 files changed, 143 insertions(+), 99 deletions(-)
---
diff --git a/data/keybindings/default.css b/data/keybindings/default.css
index 9722fa5..e18ea7b 100644
--- a/data/keybindings/default.css
+++ b/data/keybindings/default.css
@@ -16,6 +16,7 @@
/* toggle header/source */
bind "F4" { "action" ("view", "find-other-file", "") };
+ bind "F9" { "action" ("view", "preview", "") };
}
IdeSourceViewMode.default {
diff --git a/data/keybindings/emacs.css b/data/keybindings/emacs.css
index ce4779e..6f921b1 100644
--- a/data/keybindings/emacs.css
+++ b/data/keybindings/emacs.css
@@ -76,6 +76,8 @@
bind "<alt>7" { "append-to-count" (7) };
bind "<alt>8" { "append-to-count" (8) };
bind "<alt>9" { "append-to-count" (9) };
+
+ bind "F9" { "action" ("view", "preview", "") };
}
@binding-set builder-emacs-source-view-x
diff --git a/data/keybindings/vim.css b/data/keybindings/vim.css
index 4feee92..cf1195f 100644
--- a/data/keybindings/vim.css
+++ b/data/keybindings/vim.css
@@ -452,6 +452,7 @@
/* not vim perse, but common mapping */
bind "F4" { "action" ("view", "find-other-file", "") };
+ bind "F9" { "action" ("view", "preview", "") };
}
@binding-set builder-vim-source-view-normal-bracket
diff --git a/data/ui/gb-view-stack.ui b/data/ui/gb-view-stack.ui
index ebfabf7..806608d 100644
--- a/data/ui/gb-view-stack.ui
+++ b/data/ui/gb-view-stack.ui
@@ -263,6 +263,21 @@
<property name="visible">true</property>
<child>
<object class="GtkModelButton">
+ <property name="action-name">view.preview</property>
+ <property name="halign">fill</property>
+ <property name="hexpand">true</property>
+ <property name="text" translatable="yes">Preview</property>
+ <property name="visible">true</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkBox">
+ <property name="orientation">vertical</property>
+ <property name="visible">true</property>
+ <child>
+ <object class="GtkModelButton">
<property name="action-name">view.save</property>
<property name="halign">fill</property>
<property name="hexpand">true</property>
diff --git a/src/documents/gb-document.h b/src/documents/gb-document.h
index d6b0294..bc848df 100644
--- a/src/documents/gb-document.h
+++ b/src/documents/gb-document.h
@@ -31,6 +31,8 @@ G_BEGIN_DECLS
typedef struct _GbDocument GbDocument;
typedef struct _GbDocumentInterface GbDocumentInterface;
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (GbDocument, g_object_unref)
+
struct _GbDocumentInterface
{
GTypeInterface parent;
diff --git a/src/editor/gb-editor-view-actions.c b/src/editor/gb-editor-view-actions.c
index 7150913..922a6bd 100644
--- a/src/editor/gb-editor-view-actions.c
+++ b/src/editor/gb-editor-view-actions.c
@@ -24,6 +24,8 @@
#include "gb-editor-frame-private.h"
#include "gb-editor-view-actions.h"
#include "gb-editor-view-private.h"
+#include "gb-html-document.h"
+#include "gb-view-grid.h"
#include "gb-widget.h"
#include "gb-workbench.h"
@@ -390,12 +392,69 @@ gb_editor_view_actions_find_other_file (GSimpleAction *action,
g_task_run_in_thread (task, gb_editor_view_actions_find_other_file_worker);
}
+static void
+gb_editor_view_actions_preview (GSimpleAction *action,
+ GVariant *param,
+ gpointer user_data)
+{
+ GbEditorView *self = user_data;
+ GtkSourceLanguage *language;
+ const gchar *lang_id = NULL;
+ g_autoptr(GbDocument) document = NULL;
+
+ g_assert (GB_IS_EDITOR_VIEW (self));
+
+ language = gtk_source_buffer_get_language (GTK_SOURCE_BUFFER (self->document));
+ if (!language)
+ return;
+
+ lang_id = gtk_source_language_get_id (language);
+ if (!lang_id)
+ return;
+
+ if (g_str_equal (lang_id, "html"))
+ {
+ document = g_object_new (GB_TYPE_HTML_DOCUMENT,
+ "buffer", self->document,
+ NULL);
+ }
+ else if (g_str_equal (lang_id, "markdown"))
+ {
+ document = g_object_new (GB_TYPE_HTML_DOCUMENT,
+ "buffer", self->document,
+ NULL);
+ gb_html_document_set_transform_func (GB_HTML_DOCUMENT (document),
+ gb_html_markdown_transform);
+ }
+
+ if (document)
+ {
+ GtkWidget *parent = gtk_widget_get_parent (GTK_WIDGET (self));
+
+ while (parent && !GB_IS_VIEW_GRID (parent))
+ parent = gtk_widget_get_parent (parent);
+
+ if (parent == NULL)
+ {
+ while (parent && !GB_IS_VIEW_STACK (parent))
+ parent = gtk_widget_get_parent (parent);
+ g_assert (GB_IS_VIEW_STACK (parent));
+ gb_view_stack_focus_document (GB_VIEW_STACK (parent), document);
+ return;
+ }
+
+ g_assert (GB_IS_VIEW_GRID (parent));
+ gb_view_grid_focus_document (GB_VIEW_GRID (parent), document);
+ }
+}
+
static GActionEntry GbEditorViewActions[] = {
{ "auto-indent", NULL, NULL, "false", gb_editor_view_actions_auto_indent },
{ "close", gb_editor_view_actions_close },
{ "find-other-file", gb_editor_view_actions_find_other_file },
{ "highlight-current-line", NULL, NULL, "false", gb_editor_view_actions_highlight_current_line },
{ "language", NULL, "s", "''", gb_editor_view_actions_language },
+ { "preview", gb_editor_view_actions_preview },
{ "save", gb_editor_view_actions_save },
{ "show-line-numbers", NULL, NULL, "false", gb_editor_view_actions_show_line_numbers },
{ "show-right-margin", NULL, NULL, "false", gb_editor_view_actions_show_right_margin },
diff --git a/src/gnome-builder.mk b/src/gnome-builder.mk
index f4a4758..73167b2 100644
--- a/src/gnome-builder.mk
+++ b/src/gnome-builder.mk
@@ -55,6 +55,10 @@ libgnome_builder_la_SOURCES = \
src/gedit/gedit-close-button.h \
src/gedit/gedit-menu-stack-switcher.c \
src/gedit/gedit-menu-stack-switcher.h \
+ src/html/gb-html-document.c \
+ src/html/gb-html-document.h \
+ src/html/gb-html-view.c \
+ src/html/gb-html-view.h \
src/keybindings/gb-keybindings.c \
src/keybindings/gb-keybindings.h \
src/nautilus/nautilus-floating-bar.c \
@@ -141,10 +145,6 @@ disabled_files = \
src/editor/gb-source-formatter.h \
src/editor/gb-source-highlight-menu.c \
src/editor/gb-source-highlight-menu.h \
- src/html/gb-html-document.c \
- src/html/gb-html-document.h \
- src/html/gb-html-view.c \
- src/html/gb-html-view.h \
src/tree/gb-project-tree-builder.c \
src/tree/gb-project-tree-builder.h \
$(NULL)
diff --git a/src/html/gb-html-document.c b/src/html/gb-html-document.c
index 9c2b240..dade7ee 100644
--- a/src/html/gb-html-document.c
+++ b/src/html/gb-html-document.c
@@ -21,6 +21,7 @@
#include <glib.h>
#include <glib/gi18n.h>
#include <gtksourceview/gtksourcefile.h>
+#include <ide.h>
#include "gb-editor-document.h"
#include "gb-html-document.h"
@@ -108,14 +109,14 @@ gb_html_document_get_title (GbDocument *document)
static void
gb_html_document_notify_location (GbHtmlDocument *document,
GParamSpec *pspec,
- GtkSourceFile *file)
+ IdeFile *file)
{
GFile *location;
g_return_if_fail (GB_IS_HTML_DOCUMENT (document));
- g_return_if_fail (GTK_SOURCE_IS_FILE (file));
+ g_return_if_fail (IDE_IS_FILE (file));
- location = gtk_source_file_get_location (file);
+ location = ide_file_get_file (file);
g_clear_pointer (&document->priv->title, g_free);
@@ -139,11 +140,11 @@ gb_html_document_connect (GbHtmlDocument *document,
if (GB_IS_EDITOR_DOCUMENT (buffer))
{
- GtkSourceFile *file;
+ IdeFile *file;
- file = gb_editor_document_get_file (GB_EDITOR_DOCUMENT (buffer));
+ file = ide_buffer_get_file (IDE_BUFFER (buffer));
g_signal_connect_object (file,
- "notify::location",
+ "notify::file",
G_CALLBACK (gb_html_document_notify_location),
document,
G_CONNECT_SWAPPED);
@@ -160,9 +161,9 @@ gb_html_document_disconnect (GbHtmlDocument *document,
if (GB_IS_EDITOR_DOCUMENT (buffer))
{
- GtkSourceFile *file;
+ IdeFile *file;
- file = gb_editor_document_get_file (GB_EDITOR_DOCUMENT (buffer));
+ file = ide_buffer_get_file (IDE_BUFFER (buffer));
g_signal_handlers_disconnect_by_func (file,
G_CALLBACK (gb_html_document_notify_location),
document);
diff --git a/src/html/gb-html-view.c b/src/html/gb-html-view.c
index 7983b93..adaccdf 100644
--- a/src/html/gb-html-view.c
+++ b/src/html/gb-html-view.c
@@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#define G_LOG_DOMAIN "html-view"
+#define G_LOG_DOMAIN "gb-html-view"
#include <glib/gi18n.h>
#include <gtksourceview/gtksourcefile.h>
@@ -24,10 +24,14 @@
#include <webkit2/webkit2.h>
#include "gb-editor-document.h"
+#include "gb-html-document.h"
#include "gb-html-view.h"
+#include "gb-widget.h"
-struct _GbHtmlViewPrivate
+struct _GbHtmlView
{
+ GbView parent_instance;
+
/* Objects owned by view */
GbHtmlDocument *document;
@@ -35,7 +39,7 @@ struct _GbHtmlViewPrivate
WebKitWebView *web_view;
};
-G_DEFINE_TYPE_WITH_PRIVATE (GbHtmlView, gb_html_view, GB_TYPE_DOCUMENT_VIEW)
+G_DEFINE_TYPE (GbHtmlView, gb_html_view, GB_TYPE_VIEW)
enum {
PROP_0,
@@ -45,48 +49,37 @@ enum {
static GParamSpec *gParamSpecs [LAST_PROP];
-GtkWidget *
-gb_html_view_new (GbHtmlDocument *document)
-{
- return g_object_new (GB_TYPE_HTML_VIEW,
- "document", document,
- NULL);
-}
-
static void
-gb_html_view_changed (GbHtmlView *view,
+gb_html_view_changed (GbHtmlView *self,
GtkTextBuffer *buffer)
{
- GbHtmlViewPrivate *priv;
gchar *content;
gchar *base_uri = NULL;
IDE_ENTRY;
- g_return_if_fail (GB_IS_HTML_VIEW (view));
+ g_return_if_fail (GB_IS_HTML_VIEW (self));
g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
- priv = view->priv;
-
- if (GB_IS_EDITOR_DOCUMENT (view->priv->document))
+ if (GB_IS_EDITOR_DOCUMENT (self->document))
{
- GtkSourceFile *file;
+ IdeFile *file;
- file = gb_editor_document_get_file (GB_EDITOR_DOCUMENT (priv->document));
+ file = ide_buffer_get_file (IDE_BUFFER (self->document));
if (file)
{
GFile *location;
- location = gtk_source_file_get_location (file);
+ location = ide_file_get_file (file);
if (location)
base_uri = g_file_get_uri (location);
}
}
- content = gb_html_document_get_content (view->priv->document);
- webkit_web_view_load_html (view->priv->web_view, content, base_uri);
+ content = gb_html_document_get_content (self->document);
+ webkit_web_view_load_html (self->web_view, content, base_uri);
g_free (content);
g_free (base_uri);
@@ -95,12 +88,12 @@ gb_html_view_changed (GbHtmlView *view,
}
static void
-gb_html_view_connect (GbHtmlView *view,
+gb_html_view_connect (GbHtmlView *self,
GbHtmlDocument *document)
{
GtkTextBuffer *buffer;
- g_return_if_fail (GB_IS_HTML_VIEW (view));
+ g_return_if_fail (GB_IS_HTML_VIEW (self));
g_return_if_fail (GB_IS_HTML_DOCUMENT (document));
buffer = gb_html_document_get_buffer (document);
@@ -110,19 +103,19 @@ gb_html_view_connect (GbHtmlView *view,
g_signal_connect_object (buffer,
"changed",
G_CALLBACK (gb_html_view_changed),
- view,
+ self,
G_CONNECT_SWAPPED);
- gb_html_view_changed (view, buffer);
+ gb_html_view_changed (self, buffer);
}
static void
-gb_html_view_disconnect (GbHtmlView *view,
+gb_html_view_disconnect (GbHtmlView *self,
GbHtmlDocument *document)
{
GtkTextBuffer *buffer;
- g_return_if_fail (GB_IS_HTML_VIEW (view));
+ g_return_if_fail (GB_IS_HTML_VIEW (self));
g_return_if_fail (GB_IS_HTML_DOCUMENT (document));
buffer = gb_html_document_get_buffer (document);
@@ -131,24 +124,24 @@ gb_html_view_disconnect (GbHtmlView *view,
g_signal_handlers_disconnect_by_func (buffer,
G_CALLBACK (gb_html_view_changed),
- view);
+ self);
}
static GbDocument *
-gb_html_view_get_document (GbDocumentView *view)
+gb_html_view_get_document (GbView *view)
{
GbHtmlView *self = (GbHtmlView *)view;
g_return_val_if_fail (GB_IS_HTML_VIEW (self), NULL);
- return GB_DOCUMENT (self->priv->document);
+ return GB_DOCUMENT (self->document);
}
static void
-gb_html_view_set_document (GbHtmlView *view,
+gb_html_view_set_document (GbHtmlView *self,
GbDocument *document)
{
- g_return_if_fail (GB_IS_HTML_VIEW (view));
+ g_return_if_fail (GB_IS_HTML_VIEW (self));
g_return_if_fail (GB_IS_DOCUMENT (document));
if (!GB_IS_HTML_DOCUMENT (document))
@@ -159,21 +152,21 @@ gb_html_view_set_document (GbHtmlView *view,
return;
}
- if (document != (GbDocument *)view->priv->document)
+ if (document != (GbDocument *)self->document)
{
- if (view->priv->document)
+ if (self->document)
{
- gb_html_view_disconnect (view, view->priv->document);
- g_clear_object (&view->priv->document);
+ gb_html_view_disconnect (self, self->document);
+ g_clear_object (&self->document);
}
if (document)
{
- view->priv->document = g_object_ref (document);
- gb_html_view_connect (view, view->priv->document);
+ self->document = g_object_ref (document);
+ gb_html_view_connect (self, self->document);
}
- g_object_notify_by_pspec (G_OBJECT (view), gParamSpecs [PROP_DOCUMENT]);
+ g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_DOCUMENT]);
}
}
@@ -183,26 +176,26 @@ gb_html_view_refresh (GSimpleAction *action,
gpointer user_data)
{
GtkTextBuffer *buffer;
- GbHtmlView *view = user_data;
+ GbHtmlView *self = user_data;
- g_return_if_fail (GB_IS_HTML_VIEW (view));
+ g_return_if_fail (GB_IS_HTML_VIEW (self));
- if (!view->priv->document)
+ if (!self->document)
return;
- buffer = gb_html_document_get_buffer (view->priv->document);
+ buffer = gb_html_document_get_buffer (self->document);
if (!buffer)
return;
- gb_html_view_changed (view, buffer);
+ gb_html_view_changed (self, buffer);
}
static void
gb_html_view_finalize (GObject *object)
{
- GbHtmlViewPrivate *priv = GB_HTML_VIEW (object)->priv;
+ GbHtmlView *self = (GbHtmlView *)object;
- g_clear_object (&priv->document);
+ g_clear_object (&self->document);
G_OBJECT_CLASS (gb_html_view_parent_class)->finalize (object);
}
@@ -219,7 +212,7 @@ gb_html_view_get_property (GObject *object,
{
case PROP_DOCUMENT:
g_value_set_object (value,
- gb_html_view_get_document (GB_DOCUMENT_VIEW (self)));
+ gb_html_view_get_document (GB_VIEW (self)));
break;
default:
@@ -250,8 +243,7 @@ static void
gb_html_view_class_init (GbHtmlViewClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
- GbDocumentViewClass *view_class = GB_DOCUMENT_VIEW_CLASS (klass);
+ GbViewClass *view_class = GB_VIEW_CLASS (klass);
object_class->finalize = gb_html_view_finalize;
object_class->get_property = gb_html_view_get_property;
@@ -268,9 +260,8 @@ gb_html_view_class_init (GbHtmlViewClass *klass)
g_object_class_install_property (object_class, PROP_DOCUMENT,
gParamSpecs [PROP_DOCUMENT]);
- gtk_widget_class_set_template_from_resource (widget_class,
- "/org/gnome/builder/ui/gb-html-view.ui");
- gtk_widget_class_bind_template_child_private (widget_class, GbHtmlView, web_view);
+ GB_WIDGET_CLASS_TEMPLATE (klass, "gb-html-view.ui");
+ GB_WIDGET_CLASS_BIND (klass, GbHtmlView, web_view);
g_type_ensure (WEBKIT_TYPE_WEB_VIEW);
}
@@ -284,11 +275,9 @@ gb_html_view_init (GbHtmlView *self)
GSimpleActionGroup *actions;
GtkWidget *controls;
- self->priv = gb_html_view_get_instance_private (self);
-
gtk_widget_init_template (GTK_WIDGET (self));
- controls = gb_document_view_get_controls (GB_DOCUMENT_VIEW (self));
+ controls = gb_view_get_controls (GB_VIEW (self));
actions = g_simple_action_group_new ();
g_action_map_add_action_entries (G_ACTION_MAP (actions), entries,
diff --git a/src/html/gb-html-view.h b/src/html/gb-html-view.h
index 18a0ce8..4ccbea2 100644
--- a/src/html/gb-html-view.h
+++ b/src/html/gb-html-view.h
@@ -19,38 +19,13 @@
#ifndef GB_HTML_VIEW_H
#define GB_HTML_VIEW_H
-#include "gb-document-view.h"
-#include "gb-html-document.h"
+#include "gb-view.h"
G_BEGIN_DECLS
-#define GB_TYPE_HTML_VIEW (gb_html_view_get_type())
-#define GB_HTML_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GB_TYPE_HTML_VIEW, GbHtmlView))
-#define GB_HTML_VIEW_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GB_TYPE_HTML_VIEW, GbHtmlView
const))
-#define GB_HTML_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GB_TYPE_HTML_VIEW, GbHtmlViewClass))
-#define GB_IS_HTML_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GB_TYPE_HTML_VIEW))
-#define GB_IS_HTML_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GB_TYPE_HTML_VIEW))
-#define GB_HTML_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GB_TYPE_HTML_VIEW, GbHtmlViewClass))
+#define GB_TYPE_HTML_VIEW (gb_html_view_get_type())
-typedef struct _GbHtmlView GbHtmlView;
-typedef struct _GbHtmlViewClass GbHtmlViewClass;
-typedef struct _GbHtmlViewPrivate GbHtmlViewPrivate;
-
-struct _GbHtmlView
-{
- GbDocumentView parent;
-
- /*< private >*/
- GbHtmlViewPrivate *priv;
-};
-
-struct _GbHtmlViewClass
-{
- GbDocumentViewClass parent;
-};
-
-GType gb_html_view_get_type (void);
-GtkWidget *gb_html_view_new (GbHtmlDocument *document);
+G_DECLARE_FINAL_TYPE (GbHtmlView, gb_html_view, GB, HTML_VIEW, GbView)
G_END_DECLS
diff --git a/src/resources/ui/gb-html-view.ui b/src/resources/ui/gb-html-view.ui
index 6655725..8e6f4d2 100644
--- a/src/resources/ui/gb-html-view.ui
+++ b/src/resources/ui/gb-html-view.ui
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.14 -->
- <template class="GbHtmlView" parent="GbDocumentView">
+ <template class="GbHtmlView" parent="GbView">
<child internal-child="controls">
<object class="GtkBox">
<property name="visible">true</property>
@@ -14,8 +14,7 @@
<property name="action_name">html-view.refresh</property>
<style>
<class name="image-button"/>
- <class name="tab-control-first"/>
- <class name="tab-control-last"/>
+ <class name="flat"/>
</style>
<child>
<object class="GtkImage">
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]