summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorportix <none@none>2013-01-09 02:36:08 +0100
committerportix <none@none>2013-01-09 02:36:08 +0100
commit44f7f6e24688cdf70d77204548a9cae92de333d1 (patch)
treea15794cefa87baeda6e9f4db8283ec22d31c1f00 /src
parent541db868ce3df6d1890d4031426d6505b077226b (diff)
downloaddwb-44f7f6e24688cdf70d77204548a9cae92de333d1.zip
Remove scratchpad
Diffstat (limited to 'src')
-rw-r--r--src/dwb.c2
-rw-r--r--src/scratchpad.c110
-rw-r--r--src/scratchpad.h28
-rw-r--r--src/scripts.c109
-rw-r--r--src/scripts.h3
5 files changed, 14 insertions, 238 deletions
diff --git a/src/dwb.c b/src/dwb.c
index e6643ea3..d6000b94 100644
--- a/src/dwb.c
+++ b/src/dwb.c
@@ -47,7 +47,6 @@
#include "domain.h"
#include "application.h"
#include "scripts.h"
-#include "scratchpad.h"
/* DECLARATIONS {{{*/
static DwbStatus dwb_webkit_setting(GList *, WebSettings *);
@@ -4262,7 +4261,6 @@ dwb_init_gui()
gtk_box_pack_start(GTK_BOX(dwb.gui.status_hbox), dwb.gui.urilabel, true, true, 0);
gtk_box_pack_start(GTK_BOX(dwb.gui.status_hbox), dwb.gui.rstatus, false, false, 0);
gtk_container_add(GTK_CONTAINER(dwb.gui.statusbox), dwb.gui.alignment);
- gtk_box_pack_end(GTK_BOX(dwb.gui.vbox), scratchpad_get(), false, false, 0);
gtk_container_add(GTK_CONTAINER(dwb.gui.window), dwb.gui.vbox);
diff --git a/src/scratchpad.c b/src/scratchpad.c
deleted file mode 100644
index 11028c33..00000000
--- a/src/scratchpad.c
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright (c) 2010-2012 Stefan Bolte <portix@gmx.net>
- *
- * 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 3 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.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include "dwb.h"
-#include "js.h"
-#include "scripts.h"
-#include <JavaScriptCore/JavaScript.h>
-
-GtkWidget *s_scratchpad;
-static gboolean
-navigation_cb(WebKitWebView *wv, WebKitWebFrame *frame, WebKitNetworkRequest *request,
- WebKitWebNavigationAction *action, WebKitWebPolicyDecision *decision)
-{
- const char *uri = webkit_network_request_get_uri(request);
- if (g_strcmp0("scratchpad", uri) && ! g_str_has_prefix(uri, "file://"))
- {
- webkit_web_policy_decision_ignore(decision);
- return true;
- }
- return false;
-}
-
-
-static JSValueRef
-sp_send(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
-{
- if (argc > 0)
- scripts_scratchpad_send(ctx, argv[0]);
- return JSValueMakeUndefined(ctx);
-}
-
-static JSValueRef
-sp_get(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc)
-{
- scripts_scratchpad_get(ctx, function, this, argc, argv, exc);
- return JSValueMakeUndefined(ctx);
-}
-
-static void
-window_object_cb(WebKitWebView *wv, WebKitWebFrame *frame, JSContextRef ctx, JSObjectRef window)
-{
- if (frame == webkit_web_view_get_main_frame(wv))
- {
- JSObjectRef func = JSObjectMakeFunctionWithCallback(ctx, NULL, sp_get);
- js_set_property(ctx, window, "dwbGet", func,
- kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly, NULL);
- func = JSObjectMakeFunctionWithCallback(ctx, NULL, sp_send);
- js_set_property(ctx, window, "dwbSend", func,
- kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly, NULL);
- }
-}
-
-void
-scratchpad_load(const char *text)
-{
- if (g_str_has_prefix(text, "file://"))
- webkit_web_view_load_uri(WEBKIT_WEB_VIEW(s_scratchpad), text);
- else
- {
- char *basepath = g_strconcat("file://", g_getenv("HOME"), NULL);
- webkit_web_view_load_string(WEBKIT_WEB_VIEW(s_scratchpad), text, NULL, NULL, basepath);
- g_free(basepath);
- }
-}
-
-void
-scratchpad_show(void)
-{
- gtk_widget_show(s_scratchpad);
- gtk_widget_grab_focus(s_scratchpad);
-}
-
-void
-scratchpad_hide(void)
-{
- gtk_widget_hide(s_scratchpad);
- dwb_focus_scroll(dwb.state.fview);
-}
-
-static void
-scratchpad_init(void)
-{
- s_scratchpad = webkit_web_view_new();
- g_signal_connect(s_scratchpad, "navigation-policy-decision-requested", G_CALLBACK(navigation_cb), NULL);
- g_signal_connect(s_scratchpad, "window-object-cleared", G_CALLBACK(window_object_cb), NULL);
- gtk_widget_set_size_request(s_scratchpad, -1, 200);
-}
-
-GtkWidget *
-scratchpad_get(void)
-{
- if (s_scratchpad == NULL)
- scratchpad_init();
- return s_scratchpad;
-}
diff --git a/src/scratchpad.h b/src/scratchpad.h
deleted file mode 100644
index 8e1da0cb..00000000
--- a/src/scratchpad.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (c) 2010-2012 Stefan Bolte <portix@gmx.net>
- *
- * 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 3 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.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#ifndef SCRATCHPAD_H
-#define SCRATCHPAD_H
-
-GtkWidget * scratchpad_init(void);
-void scratchpad_show(void);
-void scratchpad_hide(void);
-void scratchpad_load(const char *);
-GtkWidget * scratchpad_get(void);
-
-#endif
diff --git a/src/scripts.c b/src/scripts.c
index f61c2e9a..89d81e03 100644
--- a/src/scripts.c
+++ b/src/scripts.c
@@ -32,7 +32,6 @@
#include "application.h"
#include "completion.h"
#include "entry.h"
-#include "scratchpad.h"
//#define kJSDefaultFunction (kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete )
#define kJSDefaultProperty (kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly )
#define kJSDefaultAttributes (kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly )
@@ -165,11 +164,6 @@ static JSStaticValue message_values[] = {
{ "firstParty", message_get_first_party, NULL, kJSDefaultAttributes },
{ 0, 0, 0, 0 },
};
-static JSValueRef sp_show(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc);
-static JSValueRef sp_hide(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc);
-static JSValueRef sp_load(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc);
-static JSValueRef sp_get(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc);
-static JSValueRef sp_send(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc);
static JSValueRef frame_inject(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc);
static JSStaticFunction frame_functions[] = {
@@ -215,11 +209,10 @@ static JSClassRef s_gobject_class, s_webview_class, s_frame_class, s_download_cl
static gboolean s_commandline = false;
static JSObjectRef s_array_contructor;
static JSObjectRef s_completion_callback;
-static JSObjectRef s_sp_scripts_cb;
-static JSObjectRef s_sp_scratchpad_cb;
static GQuark s_ref_quark;
static JSObjectRef s_init_before, s_init_after;
static JSObjectRef s_constructors[CONSTRUCTOR_LAST];
+static gboolean s_opt_force = false;
/* Only defined once */
static JSValueRef UNDEFINED, NIL;
@@ -725,76 +718,6 @@ wv_get_scrolled_window(JSContextRef ctx, JSObjectRef object, JSStringRef js_name
/*}}}*/
-static JSValueRef
-sp_show(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc)
-{
- scratchpad_show();
- return UNDEFINED;
-}
-static JSValueRef
-sp_hide(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc)
-{
- scratchpad_hide();
- return UNDEFINED;
-}
-static JSValueRef
-sp_load(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc)
-{
- char *text;
- if (argc > 0 && (text = js_value_to_char(ctx, argv[0], -1, exc)) != NULL)
- {
- scratchpad_load(text);
- g_free(text);
- }
- return UNDEFINED;
-}
-static JSObjectRef
-sp_callback_create(JSContextRef ctx, size_t argc, const JSValueRef argv[], JSValueRef *exc)
-{
- JSObjectRef ret = NULL;
- if (argc > 0)
- {
- ret = js_value_to_function(ctx, argv[0], exc);
- }
- return ret;
-}
-static JSValueRef
-sp_get(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc)
-{
- s_sp_scripts_cb = sp_callback_create(ctx, argc, argv, exc);
- return UNDEFINED;
-}
-void
-scripts_scratchpad_get(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc)
-{
- s_sp_scratchpad_cb = sp_callback_create(ctx, argc, argv, exc);
-}
-void
-sp_context_change(JSContextRef src_ctx, JSContextRef dest_ctx, JSObjectRef func, JSValueRef val)
-{
- if (func != NULL)
- {
- JSValueRef val_changed = js_context_change(src_ctx, dest_ctx, val, NULL);
- JSValueRef argv[] = { val_changed == 0 ? NIL : val_changed };
- JSObjectCallAsFunction(dest_ctx, func, NULL, 1, argv, NULL);
- }
-}
-// send from scripts context to scratchpad context
-static JSValueRef
-sp_send(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc)
-{
- if (argc > 0)
- sp_context_change(s_global_context, webkit_web_frame_get_global_context(webkit_web_view_get_main_frame(WEBKIT_WEB_VIEW(scratchpad_get()))), s_sp_scratchpad_cb, argv[0]);
-
- return UNDEFINED;
-}
-// send from scratchpad context to script context
-void
-scripts_scratchpad_send(JSContextRef ctx, JSValueRef val)
-{
- sp_context_change(ctx, s_global_context, s_sp_scripts_cb, val);
-}
-
/* SOUP_MESSAGE {{{*/
static JSValueRef
get_soup_uri(JSContextRef ctx, JSObjectRef object, SoupURI * (*func)(SoupMessage *), JSValueRef *exception)
@@ -2817,24 +2740,6 @@ create_global_object()
s_download_class = JSClassCreate(&cd);
s_constructors[CONSTRUCTOR_DOWNLOAD] = create_constructor(s_global_context, "Download", s_download_class, download_constructor_cb, NULL);
-
- JSStaticFunction scratchpad_functions[] = {
- { "show", sp_show, kJSDefaultAttributes },
- { "hide", sp_hide, kJSDefaultAttributes },
- { "load", sp_load, kJSDefaultAttributes },
- { "get", sp_get, kJSDefaultAttributes },
- { "send", sp_send, kJSDefaultAttributes },
- { 0, 0, 0 },
- };
- cd.className = "Scratchpad";
- cd.staticFunctions = scratchpad_functions;
- cd.staticValues = NULL;
- cd.parentClass = s_gobject_class;
- class = JSClassCreate(&cd);
-
-
- JSObjectRef o = make_object_for_class(s_global_context, class, G_OBJECT(scratchpad_get()), true);
- js_set_property(s_global_context, global_object, "scratchpad", o, kJSDefaultAttributes, NULL);
}/*}}}*/
/*}}}*/
@@ -2963,6 +2868,7 @@ void
scripts_init(gboolean force)
{
dwb.misc.script_signals = 0;
+ s_opt_force = force;
if (s_global_context == NULL)
{
if (force)
@@ -3013,6 +2919,17 @@ scripts_unbind(JSObjectRef obj)
if (obj != NULL)
JSValueUnprotect(s_global_context, obj);
}
+//void
+//scripts_reinit()
+//{
+// if (s_global_context || s_opt_force)
+// {
+// scripts_init(s_opt_force);
+// apply_scripts();
+// for (GList *gl = dwb.state.views; gl; gl=gl->next)
+// VIEW(gl)->script_wv = make_object(s_global_context, G_OBJECT(VIEW(gl)->web));
+// }
+//}
/* scripts_end {{{*/
void
diff --git a/src/scripts.h b/src/scripts.h
index e607635e..16767f0a 100644
--- a/src/scripts.h
+++ b/src/scripts.h
@@ -67,12 +67,11 @@ void scripts_remove_tab(JSObjectRef );
void scripts_end(void);
void scripts_init_script(const char *, const char *);
void scripts_init(gboolean);
+void scripts_reinit();
void scripts_unbind(JSObjectRef);
DwbStatus scripts_eval_key(KeyMap *m, Arg *arg);
gboolean scripts_execute_one(const char *script);
void scripts_completion_activate(void);
-void scripts_scratchpad_send(JSContextRef ctx, JSValueRef val);
-void scripts_scratchpad_get(JSContextRef, JSObjectRef, JSObjectRef, size_t, const JSValueRef[], JSValueRef* );
#define EMIT_SCRIPT(sig) ((dwb.misc.script_signals & (1<<SCRIPTS_SIG_##sig)))
#define SCRIPTS_EMIT_RETURN(signal, json, val) G_STMT_START \