* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include "main.h"
#include "logwindow.h"
+#include <algorithm>
+#include <cstring>
+#include <deque>
+#include <string>
+
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gdk/gdk.h>
+#include <glib-object.h>
+#include <gtk/gtk.h>
+
+#include <config.h>
+
+#include "compat.h"
+#include "debug.h"
+#include "intl.h"
+#include "layout.h"
+#include "main-defines.h"
#include "misc.h"
+#include "options.h"
#include "ui-misc.h"
#include "window.h"
{
}
-static gboolean iter_char_search_cb(gunichar ch, gpointer data)
-{
- gboolean ret;
-
- if (ch == GPOINTER_TO_UINT(data))
- {
- ret = TRUE;
- }
- else
- {
- ret = FALSE;
- }
-
- return ret;
-}
-
/**
* @brief Handle escape and F1 keys
* @param UNUSED
* @returns
*
* If escape key pressed, hide log window. \n
- * If no text selected, form a selection bounded by space characters or
- * start and end of line. \n
+ * If no text selected, select the entire line. \n
* If F1 pressed, execute command line program: \n
* <options->log_window.action> <selected text>
*
*/
static gboolean key_pressed(GtkWidget *, GdkEventKey *event, LogWindow *logwin)
{
+ gchar *cmd_line;
+ gchar *sel_text;
GtkTextBuffer *buffer;
GtkTextIter chr_end;
+ GtkTextIter chr_marker;
GtkTextIter chr_start;
GtkTextIter cursor_iter;
GtkTextIter line_end;
GtkTextIter line_start;
GtkTextMark *cursor_mark;
- gchar *cmd_line;
- gchar *sel_text;
if (event && event->keyval == GDK_KEY_Escape)
gtk_widget_hide(logwin->window);
gtk_text_iter_set_line_offset(&line_start, 0);
line_end = cursor_iter;
gtk_text_iter_forward_to_line_end(&line_end);
-
- chr_start = cursor_iter;
- gtk_text_iter_backward_find_char(&chr_start, static_cast<GtkTextCharPredicate>(iter_char_search_cb), GUINT_TO_POINTER(' '), &line_start);
-
- chr_end = cursor_iter;
- gtk_text_iter_forward_find_char(&chr_end, static_cast<GtkTextCharPredicate>(iter_char_search_cb), GUINT_TO_POINTER(' '), &line_end);
-
- gtk_text_buffer_select_range(buffer, &chr_start, &chr_end);
+ chr_marker = line_end;
+ gtk_text_buffer_select_range(buffer, &line_start, &line_end);
}
if (gtk_text_buffer_get_selection_bounds(gtk_text_view_get_buffer(GTK_TEXT_VIEW(logwin->text)), &chr_start, &chr_end))
{
sel_text = gtk_text_buffer_get_text( gtk_text_view_get_buffer(GTK_TEXT_VIEW(logwin->text)), &chr_start, &chr_end, FALSE);
- cmd_line = g_strconcat(options->log_window.action, " ", sel_text, NULL);
+ cmd_line = g_strconcat(options->log_window.action, " \"", sel_text, "\"", NULL);
runcmd(cmd_line);
{
gchar *new_regexp;
- new_regexp = g_strdup(gtk_entry_get_text(GTK_ENTRY(text_entry)));
+ new_regexp = g_strdup(gq_gtk_entry_get_text(GTK_ENTRY(text_entry)));
set_regexp(new_regexp);
g_free(new_regexp);
}
gchar *tag_name;
gint offset;
- text = gtk_entry_get_text(GTK_ENTRY(logwin->search_entry_box));
+ text = gq_gtk_entry_get_text(GTK_ENTRY(logwin->search_entry_box));
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(logwin->text));
gtk_text_buffer_get_start_iter(buffer, &start_find);
gint offset;
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(logwin->text));
- text = gtk_entry_get_text(GTK_ENTRY(logwin->search_entry_box));
+ text = gq_gtk_entry_get_text(GTK_ENTRY(logwin->search_entry_box));
if (logwin->highlight_all)
{
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(logwin->text));
gtk_text_buffer_get_start_iter(buffer, &start_find);
- text = gtk_entry_get_text(GTK_ENTRY(logwin->search_entry_box));
+ text = gq_gtk_entry_get_text(GTK_ENTRY(logwin->search_entry_box));
if (strlen(text) == 0)
{
selected = gtk_text_buffer_get_selection_bounds(buffer, &start_sel, &end_sel);
if (selected)
{
text = gtk_text_buffer_get_text(buffer, &start_sel, &end_sel, FALSE);
- gtk_entry_set_text(GTK_ENTRY(logwin->search_entry_box), text);
+ gq_gtk_entry_set_text(GTK_ENTRY(logwin->search_entry_box), text);
}
}
if (pos == GTK_ENTRY_ICON_SECONDARY)
{
- gtk_entry_set_text(GTK_ENTRY(logwin->search_entry_box), "");
+ gq_gtk_entry_set_text(GTK_ENTRY(logwin->search_entry_box), "");
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(logwin->text));
gtk_text_buffer_get_start_iter(buffer, &start_find);
static void filter_entry_icon_cb(GtkEntry *entry, GtkEntryIconPosition, GdkEvent *, gpointer)
{
const gchar *blank = "";
- gtk_entry_set_text(entry, blank);
+ gq_gtk_entry_set_text(entry, blank);
set_regexp(blank);
}
logwin = g_new0(LogWindow, 1);
- window = window_new(GTK_WINDOW_TOPLEVEL, "log", nullptr, nullptr, _("Log"));
+ window = window_new("log", nullptr, nullptr, _("Log"));
DEBUG_NAME(window);
win_vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, PREF_PAD_SPACE);
- gtk_container_add(GTK_CONTAINER(window), win_vbox);
+ gq_gtk_container_add(GTK_WIDGET(window), win_vbox);
gtk_widget_show(win_vbox);
- gtk_window_resize(GTK_WINDOW(window), lw->options.log_window.w,
- lw->options.log_window.h);
- gtk_window_move(GTK_WINDOW(window), lw->options.log_window.x, lw->options.log_window.y);
+ gtk_window_resize(GTK_WINDOW(window), lw->options.log_window.width, lw->options.log_window.height);
+ gq_gtk_window_move(GTK_WINDOW(window), lw->options.log_window.x, lw->options.log_window.y);
g_signal_connect(G_OBJECT(window), "delete_event",
G_CALLBACK(gtk_widget_hide_on_delete), NULL);
G_CALLBACK(hide_cb), logwin);
gtk_widget_realize(window);
- scrolledwin = gtk_scrolled_window_new(nullptr, nullptr);
+ scrolledwin = gq_gtk_scrolled_window_new(nullptr, nullptr);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
- gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
+ gq_gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
GTK_SHADOW_IN);
- gtk_box_pack_start(GTK_BOX(win_vbox), scrolledwin, TRUE, TRUE, 0);
+ gq_gtk_box_pack_start(GTK_BOX(win_vbox), scrolledwin, TRUE, TRUE, 0);
gtk_widget_show(scrolledwin);
text = gtk_text_view_new();
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
gtk_text_buffer_get_start_iter(buffer, &iter);
gtk_text_buffer_create_mark(buffer, "end", &iter, FALSE);
- gtk_container_add(GTK_CONTAINER(scrolledwin), text);
+ gq_gtk_container_add(GTK_WIDGET(scrolledwin), text);
gtk_widget_show(text);
#ifdef DEBUG
logwin->pause = gtk_toggle_button_new();
label = gtk_label_new("Pause");
gtk_widget_set_tooltip_text(GTK_WIDGET(logwin->pause), _("Pause scrolling"));
- gtk_container_add(GTK_CONTAINER(logwin->pause), label) ;
- gtk_box_pack_start(GTK_BOX(hbox),logwin->pause, FALSE, FALSE, 0) ;
+ gq_gtk_container_add(GTK_WIDGET(logwin->pause), label) ;
+ gq_gtk_box_pack_start(GTK_BOX(hbox),logwin->pause, FALSE, FALSE, 0) ;
g_signal_connect(logwin->pause, "toggled", G_CALLBACK(log_window_pause_cb), logwin);
gtk_widget_show_all(logwin->pause);
logwin->wrap = gtk_toggle_button_new();
label = gtk_label_new("Wrap");
gtk_widget_set_tooltip_text(GTK_WIDGET(logwin->wrap), _("Enable line wrap"));
- gtk_container_add(GTK_CONTAINER(logwin->wrap), label) ;
- gtk_box_pack_start(GTK_BOX(hbox),logwin->wrap, FALSE, FALSE, 0) ;
+ gq_gtk_container_add(GTK_WIDGET(logwin->wrap), label) ;
+ gq_gtk_box_pack_start(GTK_BOX(hbox),logwin->wrap, FALSE, FALSE, 0) ;
g_signal_connect(logwin->wrap, "toggled", G_CALLBACK(log_window_line_wrap_cb), logwin);
gtk_widget_show_all(logwin->wrap);
logwin->timer_data = gtk_toggle_button_new();
- label = gtk_label_new("Timer");
+ label = gtk_label_new(_("Timer"));
gtk_widget_set_tooltip_text(GTK_WIDGET(logwin->timer_data), _("Enable timer data"));
- gtk_container_add(GTK_CONTAINER(logwin->timer_data), label) ;
- gtk_box_pack_start(GTK_BOX(hbox),logwin->timer_data, FALSE, FALSE, 0) ;
+ gq_gtk_container_add(GTK_WIDGET(logwin->timer_data), label) ;
+ gq_gtk_box_pack_start(GTK_BOX(hbox),logwin->timer_data, FALSE, FALSE, 0) ;
if (options->log_window.timer_data)
{
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(logwin->timer_data), TRUE);
gtk_widget_show_all(logwin->timer_data);
search_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
- gtk_container_add(GTK_CONTAINER(hbox), search_box);
+ gq_gtk_container_add(GTK_WIDGET(hbox), search_box);
gtk_widget_show(search_box);
logwin->search_entry_box = gtk_entry_new();
- gtk_box_pack_start(GTK_BOX(search_box), logwin->search_entry_box, FALSE, FALSE, 0);
+ gq_gtk_box_pack_start(GTK_BOX(search_box), logwin->search_entry_box, FALSE, FALSE, 0);
gtk_widget_show(logwin->search_entry_box);
- gtk_entry_set_icon_from_icon_name(GTK_ENTRY(logwin->search_entry_box), GTK_ENTRY_ICON_PRIMARY, "edit-find");
- gtk_entry_set_icon_from_icon_name(GTK_ENTRY(logwin->search_entry_box), GTK_ENTRY_ICON_SECONDARY, "edit-clear");
+ gtk_entry_set_icon_from_icon_name(GTK_ENTRY(logwin->search_entry_box), GTK_ENTRY_ICON_PRIMARY, GQ_ICON_FIND);
+ gtk_entry_set_icon_from_icon_name(GTK_ENTRY(logwin->search_entry_box), GTK_ENTRY_ICON_SECONDARY, GQ_ICON_CLEAR);
gtk_widget_show(search_box);
gtk_widget_set_tooltip_text(logwin->search_entry_box, _("Search for text in log window"));
g_signal_connect(logwin->search_entry_box, "icon-press", G_CALLBACK(search_entry_icon_cb), logwin);
g_signal_connect(logwin->search_entry_box, "activate", G_CALLBACK(search_activate_event), logwin);
theme = gtk_icon_theme_get_default();
- pixbuf = gtk_icon_theme_load_icon(theme, "pan-up-symbolic", 20, GTK_ICON_LOOKUP_GENERIC_FALLBACK, nullptr);
+ pixbuf = gtk_icon_theme_load_icon(theme, GQ_ICON_PAN_UP, 20, GTK_ICON_LOOKUP_GENERIC_FALLBACK, nullptr);
image = gtk_image_new_from_pixbuf(pixbuf);
backwards_button = gtk_button_new();
gtk_button_set_image(GTK_BUTTON(backwards_button), GTK_WIDGET(image));
gtk_widget_set_tooltip_text(backwards_button, _("Search backwards"));
- gtk_box_pack_start(GTK_BOX(search_box), backwards_button, FALSE, FALSE, 0);
+ gq_gtk_box_pack_start(GTK_BOX(search_box), backwards_button, FALSE, FALSE, 0);
gtk_widget_show(backwards_button);
g_signal_connect(backwards_button, "button_release_event", G_CALLBACK(backwards_keypress_event_cb), logwin);
g_object_unref(pixbuf);
- pixbuf = gtk_icon_theme_load_icon(theme, "pan-down-symbolic", 20, GTK_ICON_LOOKUP_GENERIC_FALLBACK, nullptr);
+ pixbuf = gtk_icon_theme_load_icon(theme, GQ_ICON_PAN_DOWN, 20, GTK_ICON_LOOKUP_GENERIC_FALLBACK, nullptr);
image = gtk_image_new_from_pixbuf(pixbuf);
forwards_button = gtk_button_new();
gtk_button_set_image(GTK_BUTTON(forwards_button), GTK_WIDGET(image));
gtk_widget_set_tooltip_text(forwards_button, _("Search forwards"));
- gtk_box_pack_start(GTK_BOX(search_box), forwards_button, FALSE, FALSE, 0);
+ gq_gtk_box_pack_start(GTK_BOX(search_box), forwards_button, FALSE, FALSE, 0);
gtk_widget_show(forwards_button);
g_signal_connect(forwards_button, "button_release_event", G_CALLBACK(forwards_keypress_event_cb), logwin);
g_object_unref(pixbuf);
all_button = gtk_toggle_button_new();
gtk_button_set_image(GTK_BUTTON(all_button), GTK_WIDGET(image));
gtk_widget_set_tooltip_text(GTK_WIDGET(all_button), _("Highlight all"));
- gtk_box_pack_start(GTK_BOX(search_box), all_button, FALSE, FALSE, 0) ;
+ gq_gtk_box_pack_start(GTK_BOX(search_box), all_button, FALSE, FALSE, 0) ;
g_signal_connect(all_button, "toggled", G_CALLBACK(all_keypress_event_cb), logwin);
gtk_widget_show_all(all_button);
g_object_unref(pixbuf);
pref_label_new(hbox, _("Filter regexp"));
textbox = gtk_entry_new();
- gtk_box_pack_start(GTK_BOX(hbox), textbox, FALSE, FALSE, 0);
- gtk_entry_set_icon_from_icon_name(GTK_ENTRY(textbox), GTK_ENTRY_ICON_SECONDARY, "edit-clear");
+ gq_gtk_box_pack_start(GTK_BOX(hbox), textbox, FALSE, FALSE, 0);
+ gtk_entry_set_icon_from_icon_name(GTK_ENTRY(textbox), GTK_ENTRY_ICON_SECONDARY, GQ_ICON_CLEAR);
gtk_widget_show(textbox);
g_signal_connect(G_OBJECT(textbox), "activate",
G_CALLBACK(log_window_regexp_cb), logwin);
regexp = g_strdup(get_regexp());
if (regexp != nullptr)
{
- gtk_entry_set_text(GTK_ENTRY(logwin->regexp_box), regexp);
+ gq_gtk_entry_set_text(GTK_ENTRY(logwin->regexp_box), regexp);
g_free(regexp);
}
}
}
struct LogMsg {
- gchar *text;
+ LogMsg() = default;
+ LogMsg(const gchar *text, LogType type)
+ : text(text)
+ , type(type)
+ {}
+ std::string text;
LogType type;
};
GtkTextView *text;
GtkTextBuffer *buffer;
GtkTextIter iter;
- static GList *memory = nullptr;
+ static std::deque<LogMsg> memory;
if (logwindow == nullptr)
{
- if (*str) {
- auto msg = g_new(LogMsg, 1);
-
- msg->text = g_strdup(str);
- msg->type = type;
-
- memory = g_list_prepend(memory, msg);
+ if (*str)
+ {
+ memory.emplace_front(str, type);
- while (g_list_length(memory) >= static_cast<guint>(options->log_window_lines))
+ if (memory.size() >= static_cast<guint>(options->log_window_lines))
{
- GList *work = g_list_last(memory);
- auto oldest_msg = static_cast<LogMsg *>(work->data);
+ const auto count = std::max(options->log_window_lines - 1, 0);
- g_free(oldest_msg->text);
- memory = g_list_delete_link(memory, work);
+ memory.resize(count);
}
}
return;
if (options->log_window_lines > 0 && logwindow->lines >= options->log_window_lines)
{
- GtkTextIter start, end;
+ GtkTextIter start;
+ GtkTextIter end;
gtk_text_buffer_get_start_iter(buffer, &start);
end = start;
gtk_text_buffer_get_end_iter(buffer, &iter);
- {
- GList *work = g_list_last(memory);
-
- while (work)
+ std::for_each(memory.crbegin(), memory.crend(), [buffer, &iter](const LogMsg &oldest_msg)
{
- GList *prev;
- auto oldest_msg = static_cast<LogMsg *>(work->data);
-
- log_window_insert_text(buffer, &iter, oldest_msg->text,
- logwindow->color_tags[oldest_msg->type]);
-
- prev = work->prev;
- memory = g_list_delete_link(memory, work);
- work = prev;
- }
- }
+ log_window_insert_text(buffer, &iter, oldest_msg.text.c_str(), logwindow->color_tags[oldest_msg.type]);
+ });
+ memory.clear();
log_window_insert_text(buffer, &iter, str, logwindow->color_tags[type]);