1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
|
/* File: gui_search_request.c; Copyright and License: see below */
#include "gui_search_request.h"
#include "set/data_full_id.h"
#include "entity/data_id.h"
#include "utf8stringbuf/utf8string.h"
#include "u8/u8_trace.h"
#include "u8/u8_log.h"
#include <assert.h>
void gui_search_request_init ( gui_search_request_t *this_,
GtkWidget *search_label,
GtkWidget *search_entry,
GtkWidget *search_button,
gui_marked_set_t *marked_set,
gui_search_runner_t *search_runner )
{
U8_TRACE_BEGIN();
assert ( search_label != NULL );
assert ( search_entry != NULL );
assert ( search_button != NULL );
assert ( marked_set != NULL );
assert ( search_runner != NULL );
(*this_).search_label = search_label;
(*this_).search_entry = search_entry;
(*this_).search_button = search_button;
(*this_).marked_set = marked_set;
(*this_).search_runner = search_runner;
U8_TRACE_END();
}
void gui_search_request_destroy ( gui_search_request_t *this_ )
{
U8_TRACE_BEGIN();
(*this_).search_label = NULL;
(*this_).search_entry = NULL;
(*this_).search_button = NULL;
(*this_).marked_set = NULL;
(*this_).search_runner = NULL;
U8_TRACE_END();
}
void gui_search_request_show ( gui_search_request_t *this_ )
{
U8_TRACE_BEGIN();
gtk_widget_set_visible( GTK_WIDGET ( (*this_).search_label ), TRUE );
gtk_widget_set_visible( GTK_WIDGET ( (*this_).search_entry ), TRUE );
gtk_widget_set_visible( GTK_WIDGET ( (*this_).search_button ), TRUE );
U8_TRACE_END();
}
void gui_search_request_hide ( gui_search_request_t *this_ )
{
U8_TRACE_BEGIN();
gtk_widget_set_visible( GTK_WIDGET ( (*this_).search_label ), FALSE );
gtk_widget_set_visible( GTK_WIDGET ( (*this_).search_entry ), FALSE );
gtk_widget_set_visible( GTK_WIDGET ( (*this_).search_button ), FALSE );
U8_TRACE_END();
}
void gui_search_request_tool_changed_callback( GtkWidget *widget, gui_tool_t tool, gpointer data )
{
U8_TRACE_BEGIN();
gui_search_request_t *this_ = data;
assert( NULL != this_ );
/* info: This function is called once for activating a tool and once for deactiaving it! */
switch ( tool )
{
case GUI_TOOL_NAVIGATE:
{
U8_TRACE_INFO("GUI_TOOL_NAVIGATE");
gui_search_request_hide( this_ );
}
break;
case GUI_TOOL_EDIT:
{
U8_TRACE_INFO("GUI_TOOL_EDIT");
gui_search_request_hide( this_ );
}
break;
case GUI_TOOL_SEARCH:
{
U8_TRACE_INFO("GUI_TOOL_SEARCH");
gui_search_request_show( this_ );
}
break;
case GUI_TOOL_CREATE:
{
U8_TRACE_INFO("GUI_TOOL_CREATE");
gui_search_request_hide( this_ );
}
break;
default:
{
U8_LOG_ERROR("selected_tool is out of range");
}
break;
}
U8_TRACE_END();
}
void gui_search_request_search_start_callback( GtkWidget* trigger_widget, gpointer data )
{
U8_TRACE_BEGIN();
gui_search_request_t *this_ = data;
assert( NULL != this_ );
/* note: button may bei either the text entry widget or the search button widget */
const char* text;
GtkEntryBuffer *const search_buf = gtk_entry_get_buffer( GTK_ENTRY( (*this_).search_entry ) );
text = gtk_entry_buffer_get_text( search_buf );
if ( text != NULL )
{
gui_search_runner_run ( (*this_).search_runner, text );
}
else
{
assert(false);
}
U8_TRACE_END();
}
void gui_search_request_id_search_callback ( GtkWidget *widget, gpointer user_data )
{
U8_TRACE_BEGIN();
gui_search_request_t *this_;
this_ = (gui_search_request_t*) user_data;
assert ( NULL != this_ );
data_full_id_t focused_id = gui_marked_set_get_focused ( (*this_).marked_set );
if ( data_full_id_is_valid( &focused_id ) )
{
/* get the primary id unless it is a DIAGRAMELEMENT, then take the secondary id */
const data_id_t *const vis_id = data_full_id_get_primary_id_const( &focused_id );
const data_id_t *const model_id
= (DATA_TABLE_DIAGRAMELEMENT == data_id_get_table( vis_id ))
? data_full_id_get_secondary_id_const( &focused_id )
: vis_id;
char focused_id_buf[DATA_ID_MAX_UTF8STRING_LENGTH] = "";
utf8stringbuf_t focused_id_str = UTF8STRINGBUF(focused_id_buf);
const utf8error_t id_err = data_id_to_utf8stringbuf( model_id, focused_id_str );
if ( id_err == UTF8ERROR_SUCCESS )
{
GtkEntryBuffer *const name_buf = gtk_entry_get_buffer( GTK_ENTRY( (*this_).search_entry ) );
gtk_entry_buffer_set_text( name_buf, utf8stringbuf_get_string( &focused_id_str ), -1 /* = n_chars */ );
gui_search_runner_run ( (*this_).search_runner, utf8stringbuf_get_string( &focused_id_str ) );
}
}
U8_TRACE_TIMESTAMP();
U8_TRACE_END();
}
void gui_search_request_data_changed_callback( GtkWidget *widget, data_change_message_t *msg, gpointer user_data )
{
U8_TRACE_BEGIN();
assert( NULL != msg );
gui_search_request_t *this_ = user_data;
assert( NULL != this_ );
assert ( NULL != widget );
data_change_event_type_t evt_type;
evt_type = data_change_message_get_event ( msg );
if ( evt_type == DATA_CHANGE_EVENT_TYPE_DB_OPENED )
{
GtkEntryBuffer *const search_buf = gtk_entry_get_buffer( GTK_ENTRY( (*this_).search_entry ) );
gtk_entry_buffer_set_text ( search_buf, "", 0 /* = n_chars */ );
}
U8_TRACE_END();
}
/*
Copyright 2019-2025 Andreas Warnke
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
|