[gitg/wip/commit: 17/28] Send diff settings in uri
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg/wip/commit: 17/28] Send diff settings in uri
- Date: Wed, 3 Jul 2013 14:54:55 +0000 (UTC)
commit 5c1b7f9f0a65c7e6d6f3c5af76b37d96ac2d7e34
Author: Jesse van den Kieboom <jessevdk gmail com>
Date: Wed Jul 3 16:37:58 2013 +0200
Send diff settings in uri
libgitg/gitg-diff-view.vala | 50 ++++++++++++++++++++++++---------------
libgitg/resources/diff-view.js | 8 ++++-
2 files changed, 37 insertions(+), 21 deletions(-)
---
diff --git a/libgitg/gitg-diff-view.vala b/libgitg/gitg-diff-view.vala
index 4694b1e..41aa7b7 100644
--- a/libgitg/gitg-diff-view.vala
+++ b/libgitg/gitg-diff-view.vala
@@ -60,6 +60,11 @@ namespace Gitg
}
}
+ public bool wrap { get; set; default = true; }
+ public bool staged { get; set; default = false; }
+ public bool unstaged { get; set; default = false; }
+ public int tab_width { get; set; default = 4; }
+
static construct
{
s_diffmap = new Gee.HashMap<string, DiffView>();
@@ -68,6 +73,28 @@ namespace Gitg
context.register_uri_scheme("gitg-diff", gitg_diff_request);
}
+ private string json_settings()
+ {
+ var o = new Json.Object();
+
+ o.set_boolean_member("wrap", wrap);
+ o.set_int_member("tab_width", tab_width);
+ o.set_boolean_member("staged", staged);
+ o.set_boolean_member("unstaged", unstaged);
+ o.set_boolean_member("debug", Environment.get_variable("GITG_GTK_DIFF_VIEW_DEBUG") !=
null);
+
+ var gen = new Json.Generator();
+
+ var node = new Json.Node(Json.NodeType.OBJECT);
+ node.set_object(o);
+
+ gen.set_root(node);
+
+ size_t l;
+ var ret = gen.to_data(out l);
+ return ret[0:(long)l];
+ }
+
private static DiffViewRequest? parse_request(WebKit.URISchemeRequest request)
{
var uri = new Soup.URI(request.get_uri());
@@ -238,31 +265,16 @@ namespace Gitg
// Load the diff base html
var uri = "gitg-diff:///resource/org/gnome/gitg/gtk/diff-view/diff-view.html?viewid="
+ s_diff_id.to_string();
- // Add custom js as a query parameter
- if (custom_js != null)
- {
- uri += "&js=" + Soup.URI.encode(custom_js.get_uri(), null);
- }
-
- // Add custom css as a query parameter
- if (custom_css != null)
- {
- uri += "&css=" + Soup.URI.encode(custom_css.get_uri(), null);
- }
-
- if (dbg)
- {
- uri += "&debug=true";
- }
+ uri += "&settings=" + Soup.URI.encode(json_settings(), null);
d_loaded = false;
load_uri(uri);
}
- public DiffView(File? custom_js)
+ public DiffView()
{
- Object(custom_js: custom_js);
+ Object();
}
private void update()
@@ -285,7 +297,7 @@ namespace Gitg
if (d_diff != null)
{
- run_javascript.begin("update_diff(%lu);".printf(d_diffid), d_cancellable,
(obj, res) => {
+ run_javascript.begin("update_diff(%lu, %s);".printf(d_diffid,
json_settings()), d_cancellable, (obj, res) => {
try
{
run_javascript.end(res);
diff --git a/libgitg/resources/diff-view.js b/libgitg/resources/diff-view.js
index 1b4ef80..1b6b159 100644
--- a/libgitg/resources/diff-view.js
+++ b/libgitg/resources/diff-view.js
@@ -19,11 +19,13 @@ var settings = {
wrap: true,
tab_width: 4,
debug: false,
+ staged: false,
+ unstaged: false,
};
if ('settings' in params)
{
- settings = $.merge(settings, JSON.parse(params.setttings));
+ $.extend(settings, JSON.parse(params.settings));
}
var templates = {};
@@ -116,8 +118,10 @@ function write_commit(commit)
var html_builder_worker = 0;
var html_builder_tick = 0;
-function update_diff(id)
+function update_diff(id, lsettings)
{
+ $.extend(settings, lsettings);
+
if (html_builder_worker)
{
html_builder_worker.terminate();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]