refactor toggle bar code.

min
NunoSempere 2 months ago
parent 38eee1eb44
commit 5c56652e87

@ -1,7 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#define STYLE_N 7274 + 1000 #define STYLE_N 7624 + 1000
void read_style_js(char* string) void read_style_js(char* string)
{ {

@ -1,7 +1,7 @@
#ifndef STYLE #ifndef STYLE
#define STYLE #define STYLE
#define STYLE_N 7274 + 1000 #define STYLE_N 7624 + 1000
void read_style_js(char* string); void read_style_js(char* string);

Binary file not shown.

@ -1,7 +1,7 @@
#include <gdk/gdk.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <webkit2/webkit2.h> #include <webkit2/webkit2.h>
#include <gdk/gdk.h>
#include "config.h" #include "config.h"
#include "plugins/plugins.h" #include "plugins/plugins.h"
@ -28,13 +28,13 @@ WebKitWebView* notebook_get_webview(GtkNotebook* notebook)
/* Load content*/ /* Load content*/
void show_bar(GtkNotebook* notebook); void toggle_bar(GtkNotebook* notebook);
void load_uri(WebKitWebView* view, const char* uri) void load_uri(WebKitWebView* view, const char* uri)
{ {
if (strlen(uri) == 0) { if (strlen(uri) == 0) {
webkit_web_view_load_uri(view, ""); webkit_web_view_load_uri(view, "");
bar.entry_mode = _SEARCH; bar.entry_mode = _SEARCH;
show_bar(notebook); toggle_bar(notebook);
} else if (g_str_has_prefix(uri, "http://") || g_str_has_prefix(uri, "https://") || g_str_has_prefix(uri, "file://") || g_str_has_prefix(uri, "about:")) { } else if (g_str_has_prefix(uri, "http://") || g_str_has_prefix(uri, "https://") || g_str_has_prefix(uri, "file://") || g_str_has_prefix(uri, "about:")) {
webkit_web_view_load_uri(view, uri); webkit_web_view_load_uri(view, uri);
@ -210,17 +210,17 @@ void notebook_create_new_tab(GtkNotebook* notebook, const char* uri)
} }
/* Top bar */ /* Top bar */
void show_bar(GtkNotebook* notebook) void toggle_bar(GtkNotebook* notebook)
{ {
if (bar.entry_mode == _SEARCH) { switch (bar.entry_mode) {
case _SEARCH:
const char* url = webkit_web_view_get_uri(notebook_get_webview(notebook)); const char* url = webkit_web_view_get_uri(notebook_get_webview(notebook));
gtk_entry_set_placeholder_text(bar.line, "Search"); gtk_entry_set_placeholder_text(bar.line, "Search");
gtk_entry_buffer_set_text(bar.line_text, url, strlen(url)); gtk_entry_buffer_set_text(bar.line_text, url, strlen(url));
gtk_widget_show(GTK_WIDGET(bar.widget)); gtk_widget_show(GTK_WIDGET(bar.widget));
gtk_window_set_focus(window, GTK_WIDGET(bar.line)); gtk_window_set_focus(window, GTK_WIDGET(bar.line));
} else if (bar.entry_mode == _HIDDEN) { break;
gtk_widget_hide(GTK_WIDGET(bar.widget)); case _FIND:
} else {
const char* search_text = webkit_find_controller_get_search_text( const char* search_text = webkit_find_controller_get_search_text(
webkit_web_view_get_find_controller(notebook_get_webview(notebook))); webkit_web_view_get_find_controller(notebook_get_webview(notebook)));
@ -230,6 +230,12 @@ void show_bar(GtkNotebook* notebook)
gtk_entry_set_placeholder_text(bar.line, "Find"); gtk_entry_set_placeholder_text(bar.line, "Find");
gtk_widget_show(GTK_WIDGET(bar.widget)); gtk_widget_show(GTK_WIDGET(bar.widget));
gtk_window_set_focus(window, GTK_WIDGET(bar.line)); gtk_window_set_focus(window, GTK_WIDGET(bar.line));
break;
default:
// fallthrough
case _HIDDEN:
gtk_widget_hide(GTK_WIDGET(bar.widget));
break; // not needed now, but might reorder
} }
} }
// Handle what happens when the user is on the bar and presses enter // Handle what happens when the user is on the bar and presses enter
@ -332,12 +338,12 @@ int handle_shortcut(func id, GtkNotebook* notebook)
case show_searchbar: case show_searchbar:
bar.entry_mode = _SEARCH; bar.entry_mode = _SEARCH;
show_bar(notebook); toggle_bar(notebook);
break; break;
case show_finder: case show_finder:
bar.entry_mode = _FIND; bar.entry_mode = _FIND;
show_bar(notebook); toggle_bar(notebook);
break; break;
case finder_next: case finder_next:
@ -354,12 +360,12 @@ int handle_shortcut(func id, GtkNotebook* notebook)
notebook_create_new_tab(notebook, NULL); notebook_create_new_tab(notebook, NULL);
gtk_notebook_set_show_tabs(notebook, true); gtk_notebook_set_show_tabs(notebook, true);
bar.entry_mode = _SEARCH; bar.entry_mode = _SEARCH;
show_bar(notebook); toggle_bar(notebook);
break; break;
case hide_bar: case hide_bar:
bar.entry_mode = _HIDDEN; bar.entry_mode = _HIDDEN;
show_bar(notebook); toggle_bar(notebook);
break; break;
case prettify: { case prettify: {

Loading…
Cancel
Save