Commit 37e39230 authored by Christian Hergert's avatar Christian Hergert

terminal: port terminal search to libide

This migrates the GbTerminalSearch to be part of libide as
IdeTerminalSearch.
parent c2a5a04a
......@@ -173,6 +173,7 @@ G_BEGIN_DECLS
#include "testing/ide-test-provider.h"
#include "threading/ide-thread-pool.h"
#include "terminal/ide-terminal.h"
#include "terminal/ide-terminal-search.h"
#include "transfers/ide-pkcon-transfer.h"
#include "transfers/ide-transfer.h"
#include "transfers/ide-transfer-button.h"
......
......@@ -82,6 +82,7 @@
<file preprocess="xml-stripblanks" alias="ide-preferences-window.ui">preferences/ide-preferences-window.ui</file>
<file preprocess="xml-stripblanks" alias="ide-run-button.ui">runner/ide-run-button.ui</file>
<file preprocess="xml-stripblanks" alias="ide-test-panel.ui">testing/ide-test-panel.ui</file>
<file preprocess="xml-stripblanks" alias="ide-terminal-search.ui">terminal/ide-terminal-search.ui</file>
<file preprocess="xml-stripblanks" alias="ide-transfer-row.ui">transfers/ide-transfer-row.ui</file>
<file preprocess="xml-stripblanks" alias="ide-transfers-button.ui">transfers/ide-transfers-button.ui</file>
<file preprocess="xml-stripblanks" alias="ide-shortcuts-window.ui">keybindings/ide-shortcuts-window.ui</file>
......
......@@ -18,12 +18,13 @@
#pragma once
#include <ide.h>
#include <vte/vte.h>
#include <gtk/gtk.h>
#include "search/ide-tagged-entry.h"
G_BEGIN_DECLS
struct _GbTerminalSearch
struct _IdeTerminalSearch
{
GtkBin parent_instance;
......
/* gb-terminal-search.c
/* ide-terminal-search.c
*
* Copyright © 2015 Christian Hergert <christian@hergert.me>
*
......@@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define G_LOG_DOMAIN "gb-terminal-search"
#define G_LOG_DOMAIN "ide-terminal-search"
#define PCRE2_CODE_UNIT_WIDTH 0
#include "config.h"
......@@ -29,10 +29,10 @@
#include <vte/vte.h>
#include <unistd.h>
#include "gb-terminal-search.h"
#include "gb-terminal-search-private.h"
#include "terminal/ide-terminal-search.h"
#include "terminal/ide-terminal-search-private.h"
G_DEFINE_TYPE (GbTerminalSearch, gb_terminal_search, GTK_TYPE_BIN)
G_DEFINE_TYPE (IdeTerminalSearch, ide_terminal_search, GTK_TYPE_BIN)
enum {
PROP_0,
......@@ -50,7 +50,7 @@ static guint signals[LAST_SIGNAL];
static GParamSpec *properties[LAST_PROP];
static void
update_sensitivity (GbTerminalSearch *self)
update_sensitivity (IdeTerminalSearch *self)
{
gboolean can_search;
......@@ -61,10 +61,10 @@ update_sensitivity (GbTerminalSearch *self)
}
static void
perform_search (GbTerminalSearch *self,
perform_search (IdeTerminalSearch *self,
gboolean backward)
{
g_assert (GB_IS_TERMINAL_SEARCH (self));
g_assert (IDE_IS_TERMINAL_SEARCH (self));
if (self->regex == NULL)
return;
......@@ -74,31 +74,31 @@ perform_search (GbTerminalSearch *self,
static void
close_clicked_cb (GtkButton *button,
GbTerminalSearch *self)
IdeTerminalSearch *self)
{
g_assert (GB_IS_TERMINAL_SEARCH (self));
g_assert (IDE_IS_TERMINAL_SEARCH (self));
gtk_revealer_set_reveal_child(self->search_revealer, FALSE);
}
static void
search_button_clicked_cb (GtkButton *button,
GbTerminalSearch *self)
IdeTerminalSearch *self)
{
g_assert (GB_IS_TERMINAL_SEARCH (self));
g_assert (IDE_IS_TERMINAL_SEARCH (self));
perform_search (self, button == self->search_prev_button);
}
static void
update_regex (GbTerminalSearch *self)
update_regex (IdeTerminalSearch *self)
{
const char *search_text;
gboolean caseless;
g_autofree gchar *pattern = NULL;
g_autoptr(GError) error = NULL;
g_assert (GB_IS_TERMINAL_SEARCH (self));
g_assert (IDE_IS_TERMINAL_SEARCH (self));
search_text = gtk_entry_get_text (GTK_ENTRY (self->search_entry));
caseless = !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->match_case_checkbutton));
......@@ -150,30 +150,30 @@ update_regex (GbTerminalSearch *self)
static void
search_text_changed_cb (IdeTaggedEntry *search_entry,
GbTerminalSearch *self)
IdeTerminalSearch *self)
{
update_regex (self);
}
static void
search_parameters_changed_cb (GtkToggleButton *button,
GbTerminalSearch *self)
IdeTerminalSearch *self)
{
update_regex (self);
}
static void
wrap_around_toggled_cb (GtkToggleButton *button,
GbTerminalSearch *self)
IdeTerminalSearch *self)
{
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_WRAP_AROUND]);
}
static void
reveal_options_changed_cb (GtkToggleButton *button,
GbTerminalSearch *self)
IdeTerminalSearch *self)
{
g_assert (GB_IS_TERMINAL_SEARCH (self));
g_assert (IDE_IS_TERMINAL_SEARCH (self));
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->reveal_button)))
gtk_widget_set_visible (GTK_WIDGET (self->search_options), TRUE);
......@@ -184,35 +184,35 @@ reveal_options_changed_cb (GtkToggleButton *button,
static void
search_overlay_notify_regex_cb (VteTerminal *terminal,
GParamSpec *pspec G_GNUC_UNUSED,
GbTerminalSearch *self)
IdeTerminalSearch *self)
{
VteRegex *regex;
g_assert (GB_IS_TERMINAL_SEARCH (self));
g_assert (IDE_IS_TERMINAL_SEARCH (self));
g_assert (VTE_IS_TERMINAL (terminal));
regex = gb_terminal_search_get_regex (self);
regex = ide_terminal_search_get_regex (self);
vte_terminal_search_set_regex (VTE_TERMINAL (terminal), regex, 0);
}
static void
search_overlay_notify_wrap_around_cb (VteTerminal *terminal,
GParamSpec *pspec G_GNUC_UNUSED,
GbTerminalSearch *self)
IdeTerminalSearch *self)
{
gboolean wrap;
g_assert (GB_IS_TERMINAL_SEARCH (self));
g_assert (IDE_IS_TERMINAL_SEARCH (self));
g_assert (VTE_IS_TERMINAL (terminal));
wrap = gb_terminal_search_get_wrap_around (self);
wrap = ide_terminal_search_get_wrap_around (self);
vte_terminal_search_set_wrap_around (terminal, wrap);
}
static void
search_overlay_search_cb (VteTerminal *terminal,
gboolean backward,
GbTerminalSearch *self)
IdeTerminalSearch *self)
{
g_assert (VTE_IS_TERMINAL (terminal));
......@@ -225,9 +225,9 @@ search_overlay_search_cb (VteTerminal *terminal,
static void
search_revealer_cb (GtkRevealer *search_revealer,
GParamSpec *pspec G_GNUC_UNUSED,
GbTerminalSearch *self)
IdeTerminalSearch *self)
{
g_assert (GB_IS_TERMINAL_SEARCH (self));
g_assert (IDE_IS_TERMINAL_SEARCH (self));
if (gtk_revealer_get_child_revealed (search_revealer))
{
......@@ -246,7 +246,7 @@ search_revealer_cb (GtkRevealer *search_revealer,
}
static void
gb_terminal_search_connect_terminal (GbTerminalSearch *self)
ide_terminal_search_connect_terminal (IdeTerminalSearch *self)
{
g_signal_connect_object (self,
"notify::regex",
......@@ -268,21 +268,21 @@ gb_terminal_search_connect_terminal (GbTerminalSearch *self)
}
static void
gb_terminal_search_get_property (GObject *object,
ide_terminal_search_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GbTerminalSearch *self = GB_TERMINAL_SEARCH (object);
IdeTerminalSearch *self = IDE_TERMINAL_SEARCH (object);
switch (prop_id)
{
case PROP_REGEX:
g_value_set_boxed (value, gb_terminal_search_get_regex (self));
g_value_set_boxed (value, ide_terminal_search_get_regex (self));
break;
case PROP_WRAP_AROUND:
g_value_set_boolean (value, gb_terminal_search_get_wrap_around (self));
g_value_set_boolean (value, ide_terminal_search_get_wrap_around (self));
break;
default:
......@@ -291,26 +291,25 @@ gb_terminal_search_get_property (GObject *object,
}
static void
gb_terminal_search_class_init (GbTerminalSearchClass *klass)
ide_terminal_search_class_init (IdeTerminalSearchClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->get_property = gb_terminal_search_get_property;
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/builder/plugins/terminal/gb-terminal-search.ui");
gtk_widget_class_bind_template_child (widget_class, GbTerminalSearch, search_prev_button);
gtk_widget_class_bind_template_child (widget_class, GbTerminalSearch, search_next_button);
gtk_widget_class_bind_template_child (widget_class, GbTerminalSearch, close_button);
gtk_widget_class_bind_template_child (widget_class, GbTerminalSearch, search_entry);
gtk_widget_class_bind_template_child (widget_class, GbTerminalSearch, match_case_checkbutton);
gtk_widget_class_bind_template_child (widget_class, GbTerminalSearch, entire_word_checkbutton);
gtk_widget_class_bind_template_child (widget_class, GbTerminalSearch, regex_checkbutton);
gtk_widget_class_bind_template_child (widget_class, GbTerminalSearch, wrap_around_checkbutton);
gtk_widget_class_bind_template_child (widget_class, GbTerminalSearch, reveal_button);
gtk_widget_class_bind_template_child (widget_class, GbTerminalSearch, search_revealer);
gtk_widget_class_bind_template_child (widget_class, GbTerminalSearch, search_options);
object_class->get_property = ide_terminal_search_get_property;
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/builder/ui/ide-terminal-search.ui");
gtk_widget_class_bind_template_child (widget_class, IdeTerminalSearch, search_prev_button);
gtk_widget_class_bind_template_child (widget_class, IdeTerminalSearch, search_next_button);
gtk_widget_class_bind_template_child (widget_class, IdeTerminalSearch, close_button);
gtk_widget_class_bind_template_child (widget_class, IdeTerminalSearch, search_entry);
gtk_widget_class_bind_template_child (widget_class, IdeTerminalSearch, match_case_checkbutton);
gtk_widget_class_bind_template_child (widget_class, IdeTerminalSearch, entire_word_checkbutton);
gtk_widget_class_bind_template_child (widget_class, IdeTerminalSearch, regex_checkbutton);
gtk_widget_class_bind_template_child (widget_class, IdeTerminalSearch, wrap_around_checkbutton);
gtk_widget_class_bind_template_child (widget_class, IdeTerminalSearch, reveal_button);
gtk_widget_class_bind_template_child (widget_class, IdeTerminalSearch, search_revealer);
gtk_widget_class_bind_template_child (widget_class, IdeTerminalSearch, search_options);
signals[SEARCH] =
g_signal_new ("search",
......@@ -336,7 +335,7 @@ gb_terminal_search_class_init (GbTerminalSearchClass *klass)
}
static void
gb_terminal_search_init (GbTerminalSearch *self)
ide_terminal_search_init (IdeTerminalSearch *self)
{
self->regex_caseless = FALSE;
self->regex_pattern = 0;
......@@ -357,37 +356,67 @@ gb_terminal_search_init (GbTerminalSearch *self)
g_signal_connect (self->search_revealer, "notify::child-revealed", G_CALLBACK (search_revealer_cb), self);
}
/**
* ide_terminal_search_set_terminal:
* @self: a #IdeTerminalSearch
*
* Since: 3.28
*/
void
gb_terminal_search_set_terminal (GbTerminalSearch *self,
ide_terminal_search_set_terminal (IdeTerminalSearch *self,
VteTerminal *terminal)
{
g_assert (GB_IS_TERMINAL_SEARCH (self));
g_assert (IDE_IS_TERMINAL_SEARCH (self));
self->terminal = terminal;
gb_terminal_search_connect_terminal (self);
ide_terminal_search_connect_terminal (self);
}
/**
* ide_terminal_search_get_regex:
* @self: a #IdeTerminalSearch
*
* Returns: (transfer none) (nullable): a #VteRegex or %NULL.
*
* Since: 3.28
*/
VteRegex *
gb_terminal_search_get_regex (GbTerminalSearch *self)
ide_terminal_search_get_regex (IdeTerminalSearch *self)
{
g_return_val_if_fail (GB_IS_TERMINAL_SEARCH (self), NULL);
g_return_val_if_fail (IDE_IS_TERMINAL_SEARCH (self), NULL);
return self->regex;
}
/**
* ide_terminal_search_get_wrap_around:
* @self: a #IdeTerminalSearch
*
*
* Since: 3.28
*/
gboolean
gb_terminal_search_get_wrap_around (GbTerminalSearch *self)
ide_terminal_search_get_wrap_around (IdeTerminalSearch *self)
{
g_return_val_if_fail (GB_IS_TERMINAL_SEARCH (self), FALSE);
g_return_val_if_fail (IDE_IS_TERMINAL_SEARCH (self), FALSE);
return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->wrap_around_checkbutton));
}
/**
* ide_terminal_search_get_revealer:
* @self: a #IdeTerminalSearch
*
* Gets the revealer widget used for the terminal search.
*
* Returns: (transfer none): a #GtkRevealer
*
* Since: 3.28
*/
GtkRevealer *
gb_terminal_search_get_revealer (GbTerminalSearch *self)
ide_terminal_search_get_revealer (IdeTerminalSearch *self)
{
g_return_val_if_fail (GB_IS_TERMINAL_SEARCH (self), FALSE);
g_return_val_if_fail (IDE_IS_TERMINAL_SEARCH (self), FALSE);
return self->search_revealer;
}
......@@ -18,19 +18,24 @@
#pragma once
#include <ide.h>
#include <vte/vte.h>
#include "ide-version-macros.h"
G_BEGIN_DECLS
#define GB_TYPE_TERMINAL_SEARCH (gb_terminal_search_get_type())
#define IDE_TYPE_TERMINAL_SEARCH (ide_terminal_search_get_type())
G_DECLARE_FINAL_TYPE (GbTerminalSearch, gb_terminal_search, GB, TERMINAL_SEARCH, GtkBin)
G_DECLARE_FINAL_TYPE (IdeTerminalSearch, ide_terminal_search, IDE, TERMINAL_SEARCH, GtkBin)
VteRegex *gb_terminal_search_get_regex (GbTerminalSearch *self);
gboolean gb_terminal_search_get_wrap_around (GbTerminalSearch *self);
void gb_terminal_search_set_terminal (GbTerminalSearch *self,
VteTerminal *terminal);
GtkRevealer *gb_terminal_search_get_revealer (GbTerminalSearch *self);
IDE_AVAILABLE_IN_3_28
VteRegex *ide_terminal_search_get_regex (IdeTerminalSearch *self);
IDE_AVAILABLE_IN_3_28
gboolean ide_terminal_search_get_wrap_around (IdeTerminalSearch *self);
IDE_AVAILABLE_IN_3_28
void ide_terminal_search_set_terminal (IdeTerminalSearch *self,
VteTerminal *terminal);
IDE_AVAILABLE_IN_3_28
GtkRevealer *ide_terminal_search_get_revealer (IdeTerminalSearch *self);
G_END_DECLS
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- <template class="GbTerminalSearch" parent="GtkBin">
<child> -->
<!--template class="IdeTerminalSearch" parent="GtkBin">
<child-->
<object class="GtkRevealer" id="search_revealer">
<property name="halign">end</property>
<property name="valign">start</property>
......@@ -215,6 +215,6 @@
</object>
</child>
</object>
<!-- </child>
</template> -->
<!--/child>
</template-->
</interface>
terminal_headers = [
'ide-terminal.h',
'ide-terminal-search.h',
]
terminal_sources = [
'ide-terminal.c',
'ide-terminal-search.c',
]
libide_public_headers += files(terminal_headers)
......
......@@ -21,9 +21,6 @@
#include <ide.h>
#include <vte/vte.h>
#include "gb-terminal-search.h"
#include "gb-terminal-search-private.h"
G_BEGIN_DECLS
struct _GbTerminalView
......@@ -44,8 +41,7 @@ struct _GbTerminalView
GtkScrollbar *top_scrollbar;
GbTerminalSearch *tsearch;
GbTerminalSearch *bsearch;
IdeTerminalSearch *tsearch;
GFile *save_as_file_top;
......
......@@ -736,8 +736,8 @@ gb_terminal_view_init (GbTerminalView *self)
self->run_on_host = TRUE;
self->manage_spawn = TRUE;
self->tsearch = g_object_new (GB_TYPE_TERMINAL_SEARCH, NULL);
self->search_revealer_top = gb_terminal_search_get_revealer (self->tsearch);
self->tsearch = g_object_new (IDE_TYPE_TERMINAL_SEARCH, NULL);
self->search_revealer_top = ide_terminal_search_get_revealer (self->tsearch);
gtk_widget_init_template (GTK_WIDGET (self));
......@@ -750,7 +750,7 @@ gb_terminal_view_init (GbTerminalView *self)
gb_terminal_view_connect_terminal (self, self->terminal_top);
gb_terminal_search_set_terminal (self->tsearch, self->terminal_top);
ide_terminal_search_set_terminal (self->tsearch, self->terminal_top);
gb_terminal_view_actions_init (self);
......
......@@ -14,9 +14,6 @@ terminal_sources = [
'gb-terminal-view-private.h',
'gb-terminal-view-actions.c',
'gb-terminal-view-actions.h',
'gb-terminal-search.c',
'gb-terminal-search.h',
'gb-terminal-search-private.h',
'gb-terminal-workbench-addin.c',
'gb-terminal-workbench-addin.h',
]
......
......@@ -5,7 +5,6 @@
</gresource>
<gresource prefix="/org/gnome/builder/plugins/terminal">
<file>gb-terminal-view.ui</file>
<file>gb-terminal-search.ui</file>
<file>gtk/menus.ui</file>
<file>themes/shared.css</file>
</gresource>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment