summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorportix <portix@gmx.net>2011-06-25 17:32:01 +0200
committerportix <portix@gmx.net>2011-06-25 17:32:01 +0200
commita18ad5e7f326a84ade031c33a8cfd247eaa29a0f (patch)
treedf6aca357fbe2b6c6604724741337bc00b0cdc1a
parenta7702cab96a8828d5be9bfe59f9c990deafeb307 (diff)
downloaddwb-a18ad5e7f326a84ade031c33a8cfd247eaa29a0f.zip
New keyboard settings view and implementation
--HG-- branch : new_keys
-rw-r--r--lib/head.html10
-rw-r--r--lib/info.html3
-rw-r--r--src/commands.c30
-rw-r--r--src/dwb.c79
-rw-r--r--src/dwb.h1
-rw-r--r--src/html.c52
-rw-r--r--src/view.c23
7 files changed, 111 insertions, 87 deletions
diff --git a/lib/head.html b/lib/head.html
index 7da0e7f7..e2383a3d 100644
--- a/lib/head.html
+++ b/lib/head.html
@@ -74,6 +74,15 @@
.dwb_line1 {
background: #efefef;
}
+ .dwb_attr {
+ float: left;
+ font: bold 13px helvetica;
+ color: #326f32;
+ }
+ .dwb_desc {
+ font: normal 13px helvetica;
+ color: #909090;
+ }
#buttonbox {
float:left;
padding-top: 15px;
@@ -85,5 +94,6 @@
padding-left: 20px;
padding-top: 8px;
}
+
</style>
</head>
diff --git a/lib/info.html b/lib/info.html
index e4edcdea..a4c57c7e 100644
--- a/lib/info.html
+++ b/lib/info.html
@@ -5,11 +5,12 @@
<div class='dwb_button' ><a href="dwb://bookmarks">Bookmarks</a></div>
<div class='dwb_button' ><a href="dwb://quickmarks">Quickmarks</a></div>
<div class='dwb_button' ><a href="dwb://history">History</a></div>
+ <div class='dwb_button' ><a href="dwb://keys">Keys</a></div>
<!-- <div class='dwb_sbutton' ><a href="dwb://settings">Settings</a></div> -->
</div>
<!--content goes here-->
- <div class='dwb_infopanel'>
+ <div id='dwb_infopanel' class='dwb_infopanel'>
%s
</div>
</body>
diff --git a/src/commands.c b/src/commands.c
index 287cc471..37a44e9e 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -177,38 +177,8 @@ dwb_com_show_hints(KeyMap *km, Arg *arg) {
/* dwb_com_show_keys(KeyMap *km, Arg *arg){{{*/
gboolean
dwb_com_show_keys(KeyMap *km, Arg *arg) {
- View *v = dwb.state.fview->data;
-
-#if 0
dwb_html_load(CURRENT_WEBVIEW(), "dwb://keys");
return true;
-#endif
- GString *buffer = g_string_new(NULL);
- g_string_append_printf(buffer, SETTINGS_VIEW, "dwb - Keyboard configuration", dwb.color.settings_bg_color, dwb.color.settings_fg_color, dwb.misc.settings_border);
- g_string_append_printf(buffer, HTML_H2, "Keyboard Configuration", dwb.misc.profile);
-
- dwb.keymap = g_list_sort(dwb.keymap, (GCompareFunc)dwb_util_keymap_sort_first);
- g_string_append(buffer, HTML_BODY_START);
- g_string_append(buffer, HTML_FORM_START);
- for (GList *l = dwb.keymap; l; l=l->next) {
- KeyMap *m = l->data;
- Navigation n = m->map->n;
- g_string_append(buffer, HTML_DIV_START);
- g_string_append_printf(buffer, HTML_DIV_KEYS_TEXT, n.first);
- g_string_append_printf(buffer, HTML_DIV_KEYS_VALUE, n.first, dwb_modmask_to_string(m->mod), m->key ? m->key : "");
- g_string_append(buffer, HTML_DIV_END);
- }
- g_string_append(buffer, HTML_FORM_END);
- g_string_append(buffer, HTML_BODY_END);
- dwb_web_view_add_history_item(dwb.state.fview);
-
- if (v->status->scripts & SCRIPTS_BLOCKED) {
- g_object_set(webkit_web_view_get_settings(CURRENT_WEBVIEW()), "enable-scripts", true, NULL);
- }
- webkit_web_view_load_string(WEBKIT_WEB_VIEW(v->web), buffer->str, "text/html", NULL, KEY_SETTINGS);
- //webkit_web_frame_load_alternate_string(webkit_web_view_get_main_frame(WEBKIT_WEB_VIEW(v->web)), buffer->str, KEY_SETTINGS, KEY_SETTINGS);
- g_string_free(buffer, true);
- return true;
}/*}}}*/
/* dwb_com_show_settings(KeyMap *km, Arg *a) {{{*/
diff --git a/src/dwb.c b/src/dwb.c
index e53a9d85..cce8cd41 100644
--- a/src/dwb.c
+++ b/src/dwb.c
@@ -143,29 +143,29 @@ static FunctionMap FMAP [] = {
(Func)dwb_com_open, NULL, NEVER_SM, { .i = HTML_STRING, .n = OPEN_NORMAL, .p = NULL } },
{ { "load_html_nv", "Load html new view", }, 1,
(Func)dwb_com_open, NULL, NEVER_SM, { .i = HTML_STRING, .n = OPEN_NEW_VIEW, .p = NULL } },
- { { "open", "open", }, 1,
+ { { "open", "Open url", }, 1,
(Func)dwb_com_open, NULL, NEVER_SM, { .n = OPEN_NORMAL, .p = NULL } },
- { { "Open", "Open", }, 0,
+ { { "Open", "Open url, use current url", }, 0,
(Func)dwb_com_open, NULL, NEVER_SM, { .n = OPEN_NORMAL | SET_URL, .p = NULL } },
- { { "open_nv", "viewopen", }, 1,
+ { { "open_nv", "Open url in a new tab", }, 1,
(Func)dwb_com_open, NULL, NEVER_SM, { .n = OPEN_NEW_VIEW, .p = NULL } },
- { { "Open_nv", "Viewopen", }, 0,
+ { { "Open_nv", "Open in a new tab, use current url", }, 0,
(Func)dwb_com_open, NULL, NEVER_SM, { .n = OPEN_NEW_VIEW | SET_URL, .p = NULL } },
- { { "open_nw", "winopen", }, 1,
+ { { "open_nw", "Open in a new window", }, 1,
(Func)dwb_com_open, NULL, NEVER_SM, { .n = OPEN_NEW_WINDOW, .p = NULL } },
- { { "Open_nw", "Winopen", }, 0,
+ { { "Open_nw", "Open in a new window, use current url", }, 0,
(Func)dwb_com_open, NULL, NEVER_SM, { .n = OPEN_NEW_WINDOW | SET_URL, .p = NULL } },
- { { "open_quickmark", "Quickmark", }, 0,
+ { { "open_quickmark", "Open a quickmark", }, 0,
(Func)dwb_com_quickmark, NO_URL, NEVER_SM, { .n = QUICK_MARK_OPEN, .i=OPEN_NORMAL }, },
- { { "open_quickmark_nv", "Quickmark-new-view", }, 0,
+ { { "open_quickmark_nv", "Open a quickmark in a new tab", }, 0,
(Func)dwb_com_quickmark, NULL, NEVER_SM, { .n = QUICK_MARK_OPEN, .i=OPEN_NEW_VIEW }, },
- { { "open_quickmark_nw", "Quickmark-new-window", }, 0,
+ { { "open_quickmark_nw", "Open a quickmark in a new window", }, 0,
(Func)dwb_com_quickmark, NULL, NEVER_SM, { .n = QUICK_MARK_OPEN, .i=OPEN_NEW_WINDOW }, },
{ { "open_start_page", "Open startpage", }, 1,
(Func)dwb_com_open_startpage, "No startpage set", ALWAYS_SM, },
{ { "push_master", "Push to master area", }, 1,
(Func)dwb_com_push_master, "No other view", ALWAYS_SM, },
- { { "reload", "Reload", }, 1,
+ { { "reload", "Reload current page", }, 1,
(Func)dwb_com_reload, NULL, ALWAYS_SM, },
{ { "remove_view", "Close view", }, 1,
(Func)dwb_com_remove_view, NULL, ALWAYS_SM, },
@@ -205,7 +205,7 @@ static FunctionMap FMAP [] = {
(Func)dwb_com_show_settings, NULL, ALWAYS_SM, { .n = APPLY_GLOBAL } },
{ { "show_keys", "Key configuration", }, 1,
(Func)dwb_com_show_keys, NULL, ALWAYS_SM, },
- { { "show_settings", "Settings", }, 1,
+ { { "show_settings", "Settings configuration", }, 1,
(Func)dwb_com_show_settings, NULL, ALWAYS_SM, { .n = APPLY_PER_VIEW } },
{ { "toggle_bottomstack", "Toggle bottomstack", }, 1,
(Func)dwb_com_set_orientation, NULL, ALWAYS_SM, },
@@ -215,26 +215,26 @@ static FunctionMap FMAP [] = {
(Func)dwb_com_view_source, NULL, ALWAYS_SM, },
{ { "zoom_in", "Zoom in", }, 1,
(Func)dwb_com_zoom_in, "Cannot zoom in further", ALWAYS_SM, },
- { { "zoom_normal", "Zoom 100%", }, 1,
+ { { "zoom_normal", "Zoom to 100%", }, 1,
(Func)dwb_com_set_zoom_level, NULL, ALWAYS_SM, { .d = 1.0, .p = NULL } },
{ { "zoom_out", "Zoom out", }, 1,
(Func)dwb_com_zoom_out, "Cannot zoom out further", ALWAYS_SM, },
// yank and paste
- { { "yank", "Yank", }, 1,
+ { { "yank", "Yank current url", }, 1,
(Func)dwb_com_yank, NO_URL, POST_SM, { .p = GDK_NONE } },
- { { "yank_primary", "Yank to Primary selection", }, 1,
+ { { "yank_primary", "Yank current url to Primary selection", }, 1,
(Func)dwb_com_yank, NO_URL, POST_SM, { .p = GDK_SELECTION_PRIMARY } },
- { { "paste", "Paste", }, 1,
+ { { "paste", "Open url from clipboard", }, 1,
(Func)dwb_com_paste, "Clipboard is empty", ALWAYS_SM, { .n = OPEN_NORMAL, .p = GDK_NONE } },
- { { "paste_primary", "Paste primary selection", }, 1,
+ { { "paste_primary", "Open url from primary selection", }, 1,
(Func)dwb_com_paste, "No primary selection", ALWAYS_SM, { .n = OPEN_NORMAL, .p = GDK_SELECTION_PRIMARY } },
- { { "paste_nv", "Paste, new view", }, 1,
+ { { "paste_nv", "Open url from clipboard in a new tab", }, 1,
(Func)dwb_com_paste, "Clipboard is empty", ALWAYS_SM, { .n = OPEN_NEW_VIEW, .p = GDK_NONE } },
- { { "paste_primary_nv", "Paste primary selection, new view", }, 1,
+ { { "paste_primary_nv", "Open url from primary selection in a new window", }, 1,
(Func)dwb_com_paste, "No primary selection", ALWAYS_SM, { .n = OPEN_NEW_VIEW, .p = GDK_SELECTION_PRIMARY } },
- { { "paste_nw", "Paste, new window", }, 1,
+ { { "paste_nw", "Open url from clipboard in a new window", }, 1,
(Func)dwb_com_paste, "Clipboard is empty", ALWAYS_SM, { .n = OPEN_NEW_WINDOW, .p = GDK_NONE } },
- { { "paste_primary_nw", "Paste primary selection, new window", }, 1,
+ { { "paste_primary_nw", "Open url from primary selection in a new window", }, 1,
(Func)dwb_com_paste, "No primary selection", ALWAYS_SM, { .n = OPEN_NEW_WINDOW, .p = GDK_SELECTION_PRIMARY } },
{ { "save_session", "Save current session", }, 1,
@@ -249,21 +249,21 @@ static FunctionMap FMAP [] = {
(Func)dwb_com_web_inspector, "Enable developer extras for the webinspector", POST_SM },
//Entry editing
- { { "entry_delete_word", "Delete word", }, 0,
+ { { "entry_delete_word", "Command line: Delete word in", }, 0,
(Func)dwb_com_entry_delete_word, NULL, ALWAYS_SM, { 0 }, true, },
- { { "entry_delete_letter", "Delete a single letter", }, 0,
+ { { "entry_delete_letter", "Command line: Delete a single letter", }, 0,
(Func)dwb_com_entry_delete_letter, NULL, ALWAYS_SM, { 0 }, true, },
- { { "entry_delete_line", "Delete to beginning of the line", }, 0,
+ { { "entry_delete_line", "Command line: Delete to beginning of the line", }, 0,
(Func)dwb_com_entry_delete_line, NULL, ALWAYS_SM, { 0 }, true, },
- { { "entry_word_forward", "Move cursor forward on word", }, 0,
+ { { "entry_word_forward", "Command line: Move cursor forward on word", }, 0,
(Func)dwb_com_entry_word_forward, NULL, ALWAYS_SM, { 0 }, true, },
- { { "entry_word_back", "Move cursor back on word", }, 0,
+ { { "entry_word_back", "Command line: Move cursor back on word", }, 0,
(Func)dwb_com_entry_word_back, NULL, ALWAYS_SM, { 0 }, true, },
- { { "entry_history_back", "Command history back", }, 0,
+ { { "entry_history_back", "Command line: Command history back", }, 0,
(Func)dwb_com_entry_history_back, NULL, ALWAYS_SM, { 0 }, true, },
- { { "entry_history_forward", "Command history forward", }, 0,
+ { { "entry_history_forward", "Command line: Command history forward", }, 0,
(Func)dwb_com_entry_history_forward, NULL, ALWAYS_SM, { 0 }, true, },
- { { "download_set_execute", "Complete binaries", }, 0,
+ { { "download_set_execute", "Downloads: toggle between spawning application/download path", }, 0,
(Func)dwb_dl_set_execute, NULL, ALWAYS_SM, { 0 }, true, },
{ { "complete_history", "Complete browsing history", }, 0,
(Func)dwb_com_complete_type, NULL, ALWAYS_SM, { .n = COMP_HISTORY }, true, },
@@ -328,7 +328,7 @@ static FunctionMap FMAP [] = {
(Func) dwb_com_toggle_scripts, NULL, POST_SM, { .n = ALLOW_URI } },
{ { "toggle_hidden_files", "Toggle hidden files in directory listing" }, 1,
(Func) dwb_com_toggle_hidden_files, NULL, ALWAYS_SM, { 0 } },
- { { "print", "Print page" }, 1,
+ { { "print", "Print current page" }, 1,
(Func) dwb_com_print, NULL, POST_SM, { 0 } },
{ { "execute_userscript", "Execute userscript" }, 1,
(Func) dwb_com_execute_userscript, "No userscripts available", NEVER_SM, { 0 } },
@@ -936,6 +936,27 @@ dwb_update_status_text(GList *gl, GtkAdjustment *a) {
/* FUNCTIONS {{{*/
+/* dwb_set_key(const char *prop, char *val) {{{*/
+void
+dwb_set_key(const char *prop, char *val) {
+ KeyValue value;
+
+ value.id = g_strdup(prop);
+ if (val)
+ value.key = dwb_str_to_key(val);
+ else {
+ Key key = { NULL, 0 };
+ value.key = key;
+ }
+
+ dwb_set_normal_message(dwb.state.fview, true, "Saved key for command %s: %s", prop, val ? val : "");
+
+ dwb.keymap = dwb_keymap_add(dwb.keymap, value);
+ dwb.keymap = g_list_sort(dwb.keymap, (GCompareFunc)dwb_util_keymap_sort_second);
+
+ dwb_normal_mode(false);
+}/*}}}*/
+
/* dwb_get_host(WebKitWebView *) {{{*/
char *
dwb_get_host(WebKitWebView *web) {
diff --git a/src/dwb.h b/src/dwb.h
index 74c67b94..822d3bf0 100644
--- a/src/dwb.h
+++ b/src/dwb.h
@@ -686,5 +686,6 @@ gboolean dwb_toggle_allowed(const char *, const char *);
char * dwb_get_host(WebKitWebView *);
void dwb_focus_view(GList *);
void dwb_clean_key_buffer(void);
+void dwb_set_key(const char *, char *);
#endif
diff --git a/src/html.c b/src/html.c
index 9db1fa24..94b33787 100644
--- a/src/html.c
+++ b/src/html.c
@@ -35,8 +35,13 @@ void
dwb_html_load_page(WebKitWebView *wv, HtmlTable *t, char *panel) {
char *filecontent;
GString *content = g_string_new(NULL);
+#if 0
char *path = dwb_util_get_data_file(t->file);
char *headpath = dwb_util_get_data_file(HEAD_FILE);
+#else
+ char *path = g_strdup("../lib/info.html");
+ char *headpath = g_strdup("../lib/head.html");
+#endif
if (path && headpath) {
/* load head */
g_file_get_contents(headpath, &filecontent, NULL, NULL);
@@ -45,7 +50,8 @@ dwb_html_load_page(WebKitWebView *wv, HtmlTable *t, char *panel) {
FREE(headpath);
/* load content */
g_file_get_contents(path, &filecontent, NULL, NULL);
- g_string_append_printf(content, filecontent, panel);
+ if (panel)
+ g_string_append_printf(content, filecontent, panel);
webkit_web_frame_load_alternate_string(webkit_web_view_get_main_frame(wv), content->str, t->uri, "about:blank");
g_string_free(content, true);
g_free(filecontent);
@@ -76,22 +82,56 @@ void
dwb_html_settings(WebKitWebView *wv, HtmlTable *table) {
//dwb_html_load_page(wv, table, "blub");
}
+
+gboolean
+key_changed_cb(WebKitDOMElement *target, WebKitDOMEvent *e, gpointer data) {
+ char *value = webkit_dom_html_input_element_get_value(WEBKIT_DOM_HTML_INPUT_ELEMENT(target));
+ char *id = webkit_dom_html_element_get_id(WEBKIT_DOM_HTML_ELEMENT(target));
+ dwb_set_key(id, value);
+ return true;
+}
void
dwb_html_keys_load_cb(WebKitWebView *wv, GParamSpec *p, HtmlTable *table) {
- PRINT_DEBUG("url: %s", webkit_web_view_get_uri(wv));
+ KeyMap *km;
+ Navigation n;
+ WebKitDOMElement *input;
+
if (webkit_web_view_get_load_status(wv) == WEBKIT_LOAD_FINISHED) {
WebKitDOMDocument *doc = webkit_web_view_get_dom_document(wv);
- WebKitDOMElement *panel = webkit_dom_document_get_element_by_id(doc, "panel");
- if (panel)
- puts(webkit_dom_element_get_attribute(panel, "innerHTML"));
+ for (GList *l = dwb.keymap; l; l=l->next) {
+ km = l->data;
+ n = km->map->n;
+ input = webkit_dom_document_get_element_by_id(doc, n.first);
+ webkit_dom_event_target_add_event_listener(WEBKIT_DOM_EVENT_TARGET(input), "change", G_CALLBACK(key_changed_cb), false, wv);
+ }
g_signal_handlers_disconnect_by_func(wv, dwb_html_keys_load_cb, table);
}
}
void
dwb_html_keys(WebKitWebView *wv, HtmlTable *table) {
+ GString *buffer = g_string_new(NULL);
+ int i = 0;
+ KeyMap *km;
+ Navigation n;
+ for (GList *l = dwb.keymap; l; l=l->next, i++, i%=2) {
+ km = l->data;
+ n = km->map->n;
+ g_string_append_printf(buffer,
+ "<div class='dwb_line%d'>\
+ <div class='dwb_attr'>%s</div>\
+ <div style='float:right;'>\
+ <label class='dwb_desc' for='%s'>%s</lable>\
+ <input id='%s' type='text' value='%s %s'>\
+ </div>\
+ <div style='clear:both;'></div>\
+ </div>", i, n.second, n.first, n.first, n.first, dwb_modmask_to_string(km->mod), km->key ? km->key : "");
+
+ }
+ PRINT_DEBUG("%s", buffer->str);
g_signal_connect(wv, "notify::load-status", G_CALLBACK(dwb_html_keys_load_cb), table);
- dwb_html_load_page(wv, table, "blaljlkfds");
+ dwb_html_load_page(wv, table, buffer->str);
+ g_string_free(buffer, true);
}
void
dwb_html_quickmarks(WebKitWebView *wv, HtmlTable *table) {
diff --git a/src/view.c b/src/view.c
index 8cbf692c..0f8ed4fb 100644
--- a/src/view.c
+++ b/src/view.c
@@ -123,10 +123,7 @@ dwb_web_view_close_web_view_cb(WebKitWebView *web, GList *gl) {
/* dwb_web_view_console_message_cb(WebKitWebView *web, char *message, int line, char *sourceid, GList *gl) {{{*/
static gboolean
dwb_web_view_console_message_cb(WebKitWebView *web, char *message, int line, char *sourceid, GList *gl) {
- if (!strcmp(sourceid, KEY_SETTINGS)) {
- dwb_parse_key_setting(message);
- }
- else if (!(strcmp(sourceid, SETTINGS))) {
+ if (!(strcmp(sourceid, SETTINGS))) {
dwb_parse_setting(message);
}
else if (gl == dwb.state.fview && !(strcmp(message, "_dwb_input_mode_"))) {
@@ -1031,24 +1028,8 @@ void
dwb_parse_key_setting(const char *text) {
KeyValue value;
char **token = g_strsplit(text, " ", 2);
-
- value.id = g_strdup(token[0]);
-
- if (token[1]) {
- value.key = dwb_str_to_key(token[1]);
- }
- else {
- Key key = { NULL, 0 };
- value.key = key;
- }
-
- dwb_set_normal_message(dwb.state.fview, true, "Saved key for command %s: %s", token[0], token[1] ? token[1] : "");
-
- dwb.keymap = dwb_keymap_add(dwb.keymap, value);
- dwb.keymap = g_list_sort(dwb.keymap, (GCompareFunc)dwb_util_keymap_sort_second);
-
+ dwb_set_key(token[0], token[1]);
g_strfreev(token);
- dwb_normal_mode(false);
}/*}}}*/
/* dwb_apply_settings(WebSettings *s) {{{*/