prevent multiple search dialogs from being open
This commit is contained in:
parent
27544b4031
commit
ed504d7092
27
termite.c
27
termite.c
|
@ -1,5 +1,3 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#include <gdk/gdkkeysyms.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <vte/vte.h>
|
||||
|
@ -19,6 +17,7 @@ typedef struct search_dialog_info {
|
|||
GtkWidget *vte;
|
||||
GtkWidget *entry;
|
||||
enum search_direction direction;
|
||||
bool open;
|
||||
} search_dialog_info;
|
||||
|
||||
static void search_response_cb(GtkDialog *dialog, gint response_id, search_dialog_info *info) {
|
||||
|
@ -35,16 +34,20 @@ static void search_response_cb(GtkDialog *dialog, gint response_id, search_dialo
|
|||
}
|
||||
}
|
||||
|
||||
free(info);
|
||||
gtk_widget_destroy(GTK_WIDGET(dialog));
|
||||
info->open = false;
|
||||
}
|
||||
|
||||
static void open_search_dialog(GtkWidget *vte, enum search_direction direction) {
|
||||
search_dialog_info *info = malloc(sizeof (info));
|
||||
info->vte = vte;
|
||||
info->entry = gtk_entry_new();
|
||||
static void open_search_dialog(GtkWidget *vte, enum search_direction direction, search_dialog_info *info) {
|
||||
info->direction = direction;
|
||||
|
||||
if (info->open) {
|
||||
return;
|
||||
}
|
||||
|
||||
info->open = true;
|
||||
info->entry = gtk_entry_new();
|
||||
|
||||
GtkWidget *dialog, *content_area;
|
||||
dialog = gtk_dialog_new_with_buttons("Search",
|
||||
GTK_WINDOW(gtk_widget_get_toplevel(vte)),
|
||||
|
@ -63,7 +66,7 @@ static void open_search_dialog(GtkWidget *vte, enum search_direction direction)
|
|||
gtk_widget_grab_focus(GTK_WIDGET(info->entry));
|
||||
}
|
||||
|
||||
static gboolean key_press_cb(GtkWidget *vte, GdkEventKey *event) {
|
||||
static gboolean key_press_cb(GtkWidget *vte, GdkEventKey *event, search_dialog_info *info) {
|
||||
const GdkModifierType modifiers = event->state & gtk_accelerator_get_default_mod_mask();
|
||||
|
||||
if (modifiers == (GDK_CONTROL_MASK|GDK_SHIFT_MASK)) {
|
||||
|
@ -75,12 +78,12 @@ static gboolean key_press_cb(GtkWidget *vte, GdkEventKey *event) {
|
|||
vte_terminal_search_find_next(VTE_TERMINAL(vte));
|
||||
return TRUE;
|
||||
case GDK_question:
|
||||
open_search_dialog(vte, search_backward);
|
||||
open_search_dialog(vte, search_backward, info);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
if (modifiers == GDK_CONTROL_MASK && event->keyval == GDK_slash) {
|
||||
open_search_dialog(vte, search_forward);
|
||||
open_search_dialog(vte, search_forward, info);
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
|
@ -215,9 +218,11 @@ int main(int argc, char **argv) {
|
|||
|
||||
vte_terminal_set_colors(VTE_TERMINAL(vte), &foreground, &background, palette, 16);
|
||||
|
||||
search_dialog_info info = { .vte = vte, .open = false };
|
||||
|
||||
g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
|
||||
g_signal_connect(vte, "button-press-event", G_CALLBACK(button_press_cb), NULL);
|
||||
g_signal_connect(vte, "key-press-event", G_CALLBACK(key_press_cb), NULL);
|
||||
g_signal_connect(vte, "key-press-event", G_CALLBACK(key_press_cb), &info);
|
||||
|
||||
#ifdef URGENT_ON_BEEP
|
||||
if (g_signal_lookup("beep", G_TYPE_FROM_INSTANCE(G_OBJECT(vte)))) {
|
||||
|
|
Loading…
Reference in New Issue