Search is back
This commit is contained in:
@@ -31,221 +31,175 @@
|
||||
#include "MainWindows.h"
|
||||
#include "appl/globalMsg.h"
|
||||
|
||||
#include <ewol/widget/Button.h>
|
||||
#include <ewol/widget/CheckBox.h>
|
||||
#include <ewol/widget/SizerHori.h>
|
||||
#include <ewol/widget/SizerVert.h>
|
||||
#include <ewol/widget/Label.h>
|
||||
#include <ewol/widget/Entry.h>
|
||||
#include <ewol/widget/List.h>
|
||||
#include <ewol/widget/ContextMenu.h>
|
||||
#include <ewol/widget/PopUp.h>
|
||||
#include <ewol/widget/Spacer.h>
|
||||
#include <ewol/widget/Menu.h>
|
||||
#include <ewol/widgetMeta/FileChooser.h>
|
||||
#include <ewol/WidgetManager.h>
|
||||
#include <ewol/EObject.h>
|
||||
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "Search"
|
||||
|
||||
extern const char * const TYPE_EOBJECT_APPL_SEARCH = __class__;
|
||||
|
||||
|
||||
const char* const l_eventSearchEntry = "appl-search-entry";
|
||||
const char* const l_eventReplaceEntry = "appl-replace-entry";
|
||||
const char* const l_eventSearchBt = "appl-search-button";
|
||||
const char* const l_eventReplaceBt = "appl-replace-button";
|
||||
const char* const l_eventCaseCb = "appl-case-sensitive-CheckBox";
|
||||
const char* const l_eventWrapCb = "appl-wrap-CheckBox";
|
||||
const char* const l_eventForwardCb = "appl-forward-CheckBox";
|
||||
const char* const l_eventHideBt = "appl-hide-button";
|
||||
|
||||
Search::Search(void)
|
||||
/*: m_localDialog(NULL),
|
||||
m_searchLabel(NULL),
|
||||
m_searchEntry(NULL),
|
||||
m_replaceLabel(NULL),
|
||||
m_replaceEntry(NULL),
|
||||
m_CkMatchCase(NULL),
|
||||
m_CkWrapAround(NULL) */
|
||||
{
|
||||
// nothing to do ...
|
||||
m_forward = false;
|
||||
|
||||
ewol::Entry * myEntry = NULL;
|
||||
ewol::Button * myButton = NULL;
|
||||
ewol::CheckBox * mycheckbox = NULL;
|
||||
|
||||
myEntry = new ewol::Entry();
|
||||
myEntry->RegisterOnEvent(this, ewolEventEntryModify, l_eventSearchEntry);
|
||||
myEntry->SetExpendX(true);
|
||||
myEntry->SetFillX(true);
|
||||
SubWidgetAdd(myEntry);
|
||||
|
||||
myEntry = new ewol::Entry();
|
||||
myEntry->RegisterOnEvent(this, ewolEventEntryModify, l_eventReplaceEntry);
|
||||
myEntry->SetExpendX(true);
|
||||
myEntry->SetFillX(true);
|
||||
SubWidgetAdd(myEntry);
|
||||
|
||||
myButton = new ewol::Button("Search");
|
||||
myButton->RegisterOnEvent(this, ewolEventButtonPressed, l_eventSearchBt);
|
||||
SubWidgetAdd(myButton);
|
||||
|
||||
myButton = new ewol::Button("Replace");
|
||||
myButton->RegisterOnEvent(this, ewolEventButtonPressed, l_eventReplaceBt);
|
||||
SubWidgetAdd(myButton);
|
||||
|
||||
mycheckbox = new ewol::CheckBox("Aa");
|
||||
mycheckbox->RegisterOnEvent(this, ewolEventCheckBoxClicked, l_eventCaseCb);
|
||||
SubWidgetAdd(mycheckbox);
|
||||
|
||||
mycheckbox = new ewol::CheckBox("Wrap");
|
||||
mycheckbox->RegisterOnEvent(this, ewolEventCheckBoxClicked, l_eventWrapCb);
|
||||
SubWidgetAdd(mycheckbox);
|
||||
|
||||
mycheckbox = new ewol::CheckBox("Forward");
|
||||
mycheckbox->RegisterOnEvent(this, ewolEventCheckBoxClicked, l_eventForwardCb);
|
||||
SubWidgetAdd(mycheckbox);
|
||||
|
||||
myButton = new ewol::Button("Hide");
|
||||
myButton->RegisterOnEvent(this, ewolEventButtonPressed, l_eventHideBt);
|
||||
SubWidgetAdd(myButton);
|
||||
|
||||
RegisterMultiCast(ednMsgGuiSearch);
|
||||
RegisterMultiCast(ednMsgGuiReplace);
|
||||
|
||||
|
||||
}
|
||||
|
||||
Search::~Search(void)
|
||||
{
|
||||
/*
|
||||
if (NULL!=m_localDialog) {
|
||||
gtk_widget_hide(m_localDialog);
|
||||
gtk_widget_destroy(m_localDialog);
|
||||
m_localDialog = NULL;
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
/*
|
||||
void Search::Display(GtkWindow *parent)
|
||||
|
||||
/**
|
||||
* @brief Check if the object has the specific type.
|
||||
* @note In Embended platforme, it is many time no -rtti flag, then it is not possible to use dynamic cast ==> this will replace it
|
||||
* @param[in] objectType type of the object we want to check
|
||||
* @return true if the object is compatible, otherwise false
|
||||
*/
|
||||
bool Search::CheckObjectType(const char * const objectType)
|
||||
{
|
||||
if(NULL == m_localDialog) {
|
||||
m_localDialog = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
// set dialog not resisable
|
||||
gtk_window_set_resizable(GTK_WINDOW(m_localDialog), FALSE);
|
||||
// set the windows alwais on top of every all system windows
|
||||
//gtk_window_set_keep_above(GTK_WINDOW(m_localDialog), TRUE);
|
||||
// Set the dialog on top of the selected windows
|
||||
gtk_window_set_transient_for(GTK_WINDOW(m_localDialog), parent);
|
||||
// set the dialog on the top right
|
||||
gtk_window_set_gravity(GTK_WINDOW(m_localDialog), GDK_GRAVITY_NORTH_EAST);
|
||||
// Remove the dialogue from the task bar
|
||||
gtk_window_set_skip_taskbar_hint(GTK_WINDOW(m_localDialog), TRUE);
|
||||
// this element did not apear in the miniature of the windows
|
||||
gtk_window_set_skip_pager_hint(GTK_WINDOW(m_localDialog), TRUE);
|
||||
// select the program icone
|
||||
//gtk_window_set_default_icon_name("Replace");
|
||||
|
||||
// set default title :
|
||||
gtk_window_set_title(GTK_WINDOW(m_localDialog), "Search / Replace");
|
||||
|
||||
// Default size open windows
|
||||
//gtk_window_set_default_size(GTK_WINDOW(m_localDialog), 300, 400);
|
||||
|
||||
// enable the close signal of the windows
|
||||
g_signal_connect(G_OBJECT(m_localDialog), "destroy", G_CALLBACK(OnButtonQuit), this);
|
||||
|
||||
// Create a vertical box for stacking the menu and editor widgets in.
|
||||
GtkWidget *vbox = gtk_vbox_new (FALSE, 0);
|
||||
gtk_container_add(GTK_CONTAINER(m_localDialog), vbox);
|
||||
|
||||
// Set key Accelerator :
|
||||
//AccelKey::getInstance()->LinkCommonAccel(GTK_WINDOW(m_localDialog));
|
||||
|
||||
// **********************************************************
|
||||
// * Search Entry
|
||||
// **********************************************************
|
||||
{
|
||||
GtkWidget *hbox = gtk_hbox_new (FALSE, 0);
|
||||
gtk_container_add(GTK_CONTAINER (vbox), hbox);
|
||||
// search label
|
||||
m_searchLabel = gtk_label_new("Search ");
|
||||
gtk_box_pack_start(GTK_BOX(hbox), m_searchLabel, FALSE, TRUE, 0);
|
||||
// Search entry
|
||||
m_searchEntry = gtk_entry_new();
|
||||
gtk_box_pack_start(GTK_BOX(hbox), m_searchEntry, TRUE, TRUE, 0);
|
||||
// Connect signals :
|
||||
g_signal_connect(G_OBJECT(m_searchEntry), "activate", G_CALLBACK(OnButtonNext), this);
|
||||
g_signal_connect(G_OBJECT(m_searchEntry), "changed", G_CALLBACK(OnEntrySearchChange), this);
|
||||
}
|
||||
// **********************************************************
|
||||
// * Replace Entry
|
||||
// **********************************************************
|
||||
{
|
||||
GtkWidget *hbox = gtk_hbox_new (FALSE, 0);
|
||||
gtk_container_add(GTK_CONTAINER (vbox), hbox);
|
||||
// search label
|
||||
m_replaceLabel = gtk_label_new("Replace");
|
||||
gtk_box_pack_start(GTK_BOX(hbox), m_replaceLabel, FALSE, TRUE, 0);
|
||||
// Search entry
|
||||
m_replaceEntry = gtk_entry_new();
|
||||
gtk_box_pack_start(GTK_BOX(hbox), m_replaceEntry, TRUE, TRUE, 0);
|
||||
// Connect signals :
|
||||
g_signal_connect(G_OBJECT(m_replaceEntry), "changed", G_CALLBACK(OnEntryReplaceChange), this);
|
||||
}
|
||||
|
||||
// **********************************************************
|
||||
// * mode Selection
|
||||
// **********************************************************
|
||||
m_CkMatchCase = gtk_check_button_new_with_label("Case Sensitive");
|
||||
gtk_container_add(GTK_CONTAINER (vbox), m_CkMatchCase);
|
||||
m_CkWrapAround = gtk_check_button_new_with_label("Wrap arround");
|
||||
gtk_container_add(GTK_CONTAINER (vbox), m_CkWrapAround);
|
||||
m_CkRegularExpression = gtk_check_button_new_with_label("Regular Expression");
|
||||
gtk_container_add(GTK_CONTAINER (vbox), m_CkRegularExpression);
|
||||
|
||||
// connect signals :
|
||||
g_signal_connect(G_OBJECT(m_CkMatchCase), "activate", G_CALLBACK(OnCheckBoxEventCase), this);
|
||||
g_signal_connect(G_OBJECT(m_CkMatchCase), "clicked", G_CALLBACK(OnCheckBoxEventCase), this);
|
||||
g_signal_connect(G_OBJECT(m_CkWrapAround), "activate", G_CALLBACK(OnCheckBoxEventWrap), this);
|
||||
g_signal_connect(G_OBJECT(m_CkWrapAround), "clicked", G_CALLBACK(OnCheckBoxEventWrap), this);
|
||||
g_signal_connect(G_OBJECT(m_CkRegularExpression), "activate", G_CALLBACK(OnCheckBoxEventRegExp), this);
|
||||
g_signal_connect(G_OBJECT(m_CkRegularExpression), "clicked", G_CALLBACK(OnCheckBoxEventRegExp), this);
|
||||
|
||||
|
||||
// **********************************************************
|
||||
// * Search / Replace button
|
||||
// **********************************************************
|
||||
{
|
||||
GtkWidget *hbox = gtk_hbox_new (FALSE, 0);
|
||||
gtk_container_add(GTK_CONTAINER (vbox), hbox);
|
||||
// Find previous
|
||||
m_BtPrevious = gtk_button_new_with_label("Previous");
|
||||
gtk_container_add(GTK_CONTAINER (hbox), m_BtPrevious);
|
||||
// Find Next
|
||||
m_BtNext = gtk_button_new_with_label("Next");
|
||||
gtk_container_add(GTK_CONTAINER (hbox), m_BtNext);
|
||||
// Replace
|
||||
m_BtReplace = gtk_button_new_with_label("Replace");
|
||||
gtk_container_add(GTK_CONTAINER (hbox), m_BtReplace);
|
||||
// Replace & next
|
||||
m_BtReplaceAndNext = gtk_button_new_with_label("Replace & Find");
|
||||
gtk_container_add(GTK_CONTAINER (hbox), m_BtReplaceAndNext);
|
||||
// Exit
|
||||
m_BtQuit = gtk_button_new_with_label("Close");
|
||||
gtk_container_add(GTK_CONTAINER (hbox), m_BtQuit);
|
||||
|
||||
// Connect signals :
|
||||
g_signal_connect(G_OBJECT(m_BtPrevious), "activate", G_CALLBACK(OnButtonPrevious), this);
|
||||
g_signal_connect(G_OBJECT(m_BtPrevious), "released", G_CALLBACK(OnButtonPrevious), this);
|
||||
g_signal_connect(G_OBJECT(m_BtNext), "activate", G_CALLBACK(OnButtonNext), this);
|
||||
g_signal_connect(G_OBJECT(m_BtNext), "released", G_CALLBACK(OnButtonNext), this);
|
||||
g_signal_connect(G_OBJECT(m_BtReplace), "activate", G_CALLBACK(OnButtonReplace), this);
|
||||
g_signal_connect(G_OBJECT(m_BtReplace), "released", G_CALLBACK(OnButtonReplace), this);
|
||||
g_signal_connect(G_OBJECT(m_BtReplaceAndNext), "activate", G_CALLBACK(OnButtonReplaceAndNext), this);
|
||||
g_signal_connect(G_OBJECT(m_BtReplaceAndNext), "released", G_CALLBACK(OnButtonReplaceAndNext), this);
|
||||
g_signal_connect(G_OBJECT(m_BtQuit), "activate", G_CALLBACK(OnButtonQuit), this);
|
||||
g_signal_connect(G_OBJECT(m_BtQuit), "released", G_CALLBACK(OnButtonQuit), this);
|
||||
}
|
||||
|
||||
// recursive version of gtk_widget_show
|
||||
gtk_widget_show_all(m_localDialog);
|
||||
if (NULL == objectType) {
|
||||
APPL_ERROR("check error : \"" << TYPE_EOBJECT_APPL_SEARCH << "\" != NULL(pointer) ");
|
||||
return false;
|
||||
}
|
||||
if(NULL == m_localDialog) {
|
||||
APPL_ERROR("No search-dialog instance");
|
||||
if (objectType == TYPE_EOBJECT_APPL_SEARCH) {
|
||||
return true;
|
||||
} else {
|
||||
// update datas :
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_CkWrapAround), SearchData::GetWrap());
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_CkMatchCase), SearchData::GetCase());
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_CkRegularExpression), SearchData::GetRegExp());
|
||||
if (true == SearchData::GetRegExp()) {
|
||||
gtk_widget_set_sensitive(m_CkMatchCase, false);
|
||||
} else {
|
||||
gtk_widget_set_sensitive(m_CkMatchCase, true);
|
||||
if(true == ewol::SizerHori::CheckObjectType(objectType)) {
|
||||
return true;
|
||||
}
|
||||
// Remove data form the search
|
||||
etk::UString myDataString = "";
|
||||
SearchData::SetSearch(myDataString);
|
||||
gtk_entry_set_text(GTK_ENTRY(m_searchEntry), myDataString.c_str());
|
||||
if (0 == strlen(myDataString.c_str())) {
|
||||
m_haveSearchData = false;
|
||||
} else {
|
||||
m_haveSearchData = true;
|
||||
}
|
||||
|
||||
SearchData::GetReplace(myDataString);
|
||||
gtk_entry_set_text(GTK_ENTRY(m_replaceEntry), myDataString.c_str());
|
||||
if (0 == strlen(myDataString.c_str())) {
|
||||
m_haveReplaceData = false;
|
||||
} else {
|
||||
m_haveReplaceData = true;
|
||||
}
|
||||
|
||||
gtk_widget_set_sensitive(m_BtPrevious, m_haveSearchData);
|
||||
gtk_widget_set_sensitive(m_BtNext, m_haveSearchData);
|
||||
// basic no search data
|
||||
gtk_widget_set_sensitive(m_BtReplace, false);
|
||||
gtk_widget_set_sensitive(m_BtReplaceAndNext, false);
|
||||
|
||||
|
||||
// set focus on a specific widget :
|
||||
//gtk_window_set_focus(parent, m_searchEntry);
|
||||
gtk_widget_grab_focus(m_searchEntry);
|
||||
|
||||
// display the dialogue box
|
||||
gtk_widget_show_all(m_localDialog);
|
||||
|
||||
// hide regular expression
|
||||
gtk_widget_hide(m_CkRegularExpression);
|
||||
APPL_ERROR("check error : \"" << TYPE_EOBJECT_APPL_SEARCH << "\" != \"" << objectType << "\"");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
void Search::Destroy(void)
|
||||
/**
|
||||
* @brief Get the current Object type of the EObject
|
||||
* @note In Embended platforme, it is many time no -rtti flag, then it is not possible to use dynamic cast ==> this will replace it
|
||||
* @param[in] objectType type description
|
||||
* @return true if the object is compatible, otherwise false
|
||||
*/
|
||||
const char * const Search::GetObjectType(void)
|
||||
{
|
||||
/*
|
||||
if (NULL!=m_localDialog) {
|
||||
gtk_widget_destroy(m_localDialog);
|
||||
m_localDialog = NULL;
|
||||
}
|
||||
*/
|
||||
return TYPE_EOBJECT_APPL_SEARCH;
|
||||
}
|
||||
|
||||
|
||||
void Search::Hide(void)
|
||||
/**
|
||||
* @brief Receive a message from an other EObject with a specific eventId and data
|
||||
* @param[in] CallerObject Pointer on the EObject that information came from
|
||||
* @param[in] eventId Message registered by this class
|
||||
* @param[in] data Data registered by this class
|
||||
* @return ---
|
||||
*/
|
||||
void Search::OnReceiveMessage(ewol::EObject * CallerObject, const char * eventId, etk::UString data)
|
||||
{
|
||||
//gtk_widget_hide(m_localDialog);
|
||||
ewol::SizerHori::OnReceiveMessage(CallerObject, eventId, data);
|
||||
//APPL_INFO("Search receive message : \"" << eventId << "\" data=\"" << data << "\"");
|
||||
if ( eventId == l_eventSearchEntry) {
|
||||
SearchData::SetSearch(data);
|
||||
} else if ( eventId == l_eventReplaceEntry) {
|
||||
SearchData::SetReplace(data);
|
||||
} else if ( eventId == l_eventSearchBt) {
|
||||
if (true==m_forward) {
|
||||
SendMultiCast(ednMsgGuiFind, "Previous");
|
||||
} else {
|
||||
SendMultiCast(ednMsgGuiFind, "Next");
|
||||
}
|
||||
} else if ( eventId == l_eventReplaceBt) {
|
||||
SendMultiCast(ednMsgGuiReplace, "Normal");
|
||||
if (true==m_forward) {
|
||||
SendMultiCast(ednMsgGuiFind, "Previous");
|
||||
} else {
|
||||
SendMultiCast(ednMsgGuiFind, "Next");
|
||||
}
|
||||
} else if ( eventId == l_eventCaseCb) {
|
||||
if (data == "true") {
|
||||
SearchData::SetCase(true);
|
||||
} else {
|
||||
SearchData::SetCase(false);
|
||||
}
|
||||
} else if ( eventId == l_eventWrapCb) {
|
||||
if (data == "true") {
|
||||
SearchData::SetWrap(true);
|
||||
} else {
|
||||
SearchData::SetWrap(false);
|
||||
}
|
||||
} else if ( eventId == l_eventForwardCb) {
|
||||
if (data == "true") {
|
||||
m_forward = true;
|
||||
} else {
|
||||
m_forward = false;
|
||||
}
|
||||
} else if ( eventId == l_eventHideBt) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user