]> OzVa Git service - gn-editor/commitdiff
Working webkit2gtk preview
authorNil Gradisnik <nil@layer.com>
Fri, 5 Jan 2018 23:34:42 +0000 (15:34 -0800)
committerNil Gradisnik <nil@layer.com>
Fri, 5 Jan 2018 23:34:42 +0000 (15:34 -0800)
Cargo.lock
Cargo.toml
src/gtk-ui.glade
src/main.rs
src/preview.rs

index b6d900f2cc117e51cc3378966c0337b0de841290..b7401a0941d1f6ee98019e6e9e5a88f239648300 100644 (file)
@@ -367,6 +367,23 @@ name = "itoa"
 version = "0.3.4"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
+[[package]]
+name = "javascriptcore-rs"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "glib 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "javascriptcore-rs-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "javascriptcore-rs-sys"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
 [[package]]
 name = "kernel32-sys"
 version = "0.2.2"
@@ -396,6 +413,7 @@ dependencies = [
  "gtk 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "horrorshow 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "sourceview 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "webkit2gtk 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -548,6 +566,19 @@ dependencies = [
  "serde 1.0.23 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
+[[package]]
+name = "soup-sys"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "gio-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "glib-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "gobject-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)",
+ "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
 [[package]]
 name = "sourceview"
 version = "0.3.0"
@@ -703,6 +734,48 @@ name = "void"
 version = "1.0.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
+[[package]]
+name = "webkit2gtk"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cairo-rs 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "gdk 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "gdk-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "gio 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "gio-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "glib 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "glib-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "gobject-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "gtk 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "gtk-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "javascriptcore-rs 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)",
+ "webkit2gtk-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "webkit2gtk-sys"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "atk-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cairo-sys-rs 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "gdk-pixbuf-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "gdk-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "gio-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "glib-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "gobject-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "gtk-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "javascriptcore-rs-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)",
+ "pango-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
+ "soup-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
 [[package]]
 name = "winapi"
 version = "0.2.8"
@@ -749,6 +822,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 "checksum if_chain 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "61bb90bdd39e3af69b0172dfc6130f6cd6332bf040fbb9bdd4401d37adbd48b8"
 "checksum itertools 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d3f2be4da1690a039e9ae5fd575f706a63ad5a2120f161b1d653c9da3930dd21"
 "checksum itoa 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8324a32baf01e2ae060e9de58ed0bc2320c9a2833491ee36cd3b4c414de4db8c"
+"checksum javascriptcore-rs 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "25753bc0f02e8123447441d40ef5516aec678769a58db60fac2e19375439a6a5"
+"checksum javascriptcore-rs-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3fae3b8197de3f21279a7b74c2f3a8d951e51e4c1c19f030de1122b39d86a58c"
 "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
 "checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73"
 "checksum libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)" = "36fbc8a8929c632868295d0178dd8f63fc423fd7537ad0738372bd010b3ac9b0"
@@ -772,6 +847,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 "checksum serde_derive 1.0.23 (registry+https://github.com/rust-lang/crates.io-index)" = "0672de7300b02bac3f3689f8faea813c4a1ea9fe0cb49e80f714231d267518a2"
 "checksum serde_derive_internals 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)" = "32f1926285523b2db55df263d2aa4eb69ddcfa7a7eade6430323637866b513ab"
 "checksum serde_json 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "ea28ea0cca944668919bec6af209864a8dfe769fd2b0b723f36b22e20c1bf69f"
+"checksum soup-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "11c783e6dec746da651ce72bb9c24f39e8c89f01af2f1e41ecb1d1df13891e31"
 "checksum sourceview 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "673844d773083b34c3cb3dab036c75eebb7b223343724f167915980a4586912e"
 "checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694"
 "checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
@@ -792,5 +868,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 "checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122"
 "checksum vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "887b5b631c2ad01628bbbaa7dd4c869f80d3186688f8d0b6f58774fbe324988c"
 "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
+"checksum webkit2gtk 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f17004b7c76cee4e82041bbebbb1caec1dacaab7838ed7da72e2e46bc05c24d7"
+"checksum webkit2gtk-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c42e3815b8d0ca4ca5fa13cb4ba068678b29ec642a7aa6e253d4e3ea862b3ca7"
 "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
 "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
index 8c4f514e04025a75a6f0aef4d0eea3b312ffacd3..a743a7e6f0df3e081b1b9437050f12dc4df88126 100644 (file)
@@ -12,6 +12,7 @@ gio = "0.3"
 sourceview = "0.3"
 comrak = "0.2"
 horrorshow = "0.6"
+webkit2gtk = "0.3"
 
 [dependencies.gtk]
 version = "0.3"
index 28e83a818070b0073226c56fb9b0e774044f0443..c4c0fc53ebb432984348fc9bd9bafb01c2d8e16b 100644 (file)
@@ -101,18 +101,7 @@ Author: Nil Gradisnik
                 <property name="shadow_type">in</property>
                 <property name="min_content_width">200</property>
                 <child>
-                  <object class="GtkTextView" id="markdown_view">
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="editable">False</property>
-                    <property name="wrap_mode">word</property>
-                    <property name="left_margin">4</property>
-                    <property name="right_margin">4</property>
-                    <property name="top_margin">4</property>
-                    <property name="bottom_margin">4</property>
-                    <property name="indent">2</property>
-                    <property name="monospace">True</property>
-                  </object>
+                  <placeholder/>
                 </child>
               </object>
               <packing>
index 180e28129744f305ad8984fe6217af4feb3983f0..46bdd40c4a428ff185292e0d610c5bfbba319ecf 100644 (file)
@@ -6,6 +6,7 @@ extern crate gtk;
 #[macro_use]
 extern crate horrorshow;
 extern crate sourceview;
+extern crate webkit2gtk;
 
 mod preview;
 mod utils;
@@ -15,6 +16,8 @@ use gtk::prelude::*;
 use gtk::Builder;
 use gio::MenuExt;
 
+use webkit2gtk::*;
+
 use std::env::args;
 
 use utils::{buffer_to_string, configure_sourceview, open_file, set_title};
@@ -51,7 +54,11 @@ fn build_system_menu(application: &gtk::Application) {
     application.set_app_menu(&menu);
 }
 
-fn add_actions(application: &gtk::Application, window: &gtk::ApplicationWindow, about_dialog: &gtk::AboutDialog) {
+fn add_actions(
+    application: &gtk::Application,
+    window: &gtk::ApplicationWindow,
+    about_dialog: &gtk::AboutDialog,
+) {
     let quit = gio::SimpleAction::new("quit", None);
     quit.connect_activate(clone!(window => move |_, _| {
         window.destroy();
@@ -85,7 +92,10 @@ fn build_ui(application: &gtk::Application) {
     let text_buffer: sourceview::Buffer = builder.get_object("text_buffer").unwrap();
     configure_sourceview(&text_buffer);
 
-    let markdown_view: gtk::TextView = builder.get_object("markdown_view").unwrap();
+    let context = WebContext::get_default().unwrap();
+    let preview = WebView::new_with_context(&context);
+    let markdown_view: gtk::ScrolledWindow = builder.get_object("scrolled_window_right").unwrap();
+    markdown_view.add(&preview);
 
     let file_chooser: gtk::FileChooserDialog = builder.get_object("file_chooser").unwrap();
     file_chooser.add_buttons(&[
@@ -99,7 +109,7 @@ fn build_ui(application: &gtk::Application) {
     about_dialog.set_authors(&[AUTHORS]);
     about_dialog.set_comments(DESCRIPTION);
 
-    open_button.connect_clicked(clone!(header_bar, text_buffer, markdown_view => move |_| {
+    open_button.connect_clicked(clone!(header_bar, text_buffer, preview => move |_| {
         file_chooser.show();
 
         if file_chooser.run() == gtk::ResponseType::Ok.into() {
@@ -109,15 +119,15 @@ fn build_ui(application: &gtk::Application) {
             set_title(&header_bar, &filename);
 
             text_buffer.set_text(&contents);
-            markdown_view.get_buffer().unwrap().set_text(&preview::render(&contents));
+            preview.load_html(&preview::render(&contents), None);
         }
 
         file_chooser.hide();
     }));
 
-    text_view.connect_key_release_event(clone!(text_buffer, markdown_view => move |_, _| {
+    text_view.connect_key_release_event(clone!(text_buffer, preview => move |_, _| {
         let markdown = buffer_to_string(&text_buffer).unwrap();
-        markdown_view.get_buffer().unwrap().set_text(&preview::render(&markdown));
+        preview.load_html(&preview::render(&markdown), None);
         Inhibit(true)
     }));
 
index cce88dcb46284bba4629e4ffaa8fc8dba08cc463..49e7cfc68da40d0429879b53365299bf4c94a43c 100644 (file)
@@ -30,8 +30,8 @@ pub fn render(markdown: &str) -> String {
                         : Raw("hljs.initHighlightingOnLoad()")
                     }
                     style {
-                        : "body { width: 80%; margin: 0 auto }";
-                        : "img { max-width: 80% }"
+                        : "body { width: 90%; margin: 0 auto }";
+                        : "img { max-width: 90% }"
                     }
                 }
                 body {