Hi,

Today's gtk+ improvement: a find/replace dialog.  Thanks to Angus for
his help earlier, it was spot on.

Known deficiency: the dialog isn't always-on-top, but I think that's
something that will be solved more generally when I work it out, rather
than as a specific case for this dialog.  Besides, the xforms frontend
doesn't seem to do always-on-top either (the qt frontend does).

  * GSearch.[Ch]: new files
  * Dialogs.C: move from formsearch to gsearch
  * Makefile.am: move from formsearch to gsearch, alphabetically
  sort list of libgtk_la_SOURCES
  * glade/search.glade: s/Backwords/Backwards/, accelerator escape
  for close button, gtk stock buttons for find and replace.

Cheers,
John

P.S. Looks like my earlier presumed-lost messages are starting to come
through now, sorry for the spam.
Index: ChangeLog
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/frontends/gtk/ChangeLog,v
retrieving revision 1.53
diff -u -3 -p -u -p -r1.53 ChangeLog
--- ChangeLog	2004/09/24 06:32:22	1.53
+++ ChangeLog	2004/09/24 19:42:55
@@ -1,3 +1,12 @@
+2004-09-24  John Spray  <[EMAIL PROTECTED]>
+
+	* GSearch.[Ch]: new files
+	* Dialogs.C: move from formsearch to gsearch
+	* Makefile.am: move from formsearch to gsearch, alphabetically
+	sort list of libgtk_la_SOURCES
+	* glade/search.glade: s/Backwords/Backwards/, accelerator escape
+	for close button, gtk stock buttons for find and replace.
+	
 2004-09-23  John Spray  <[EMAIL PROTECTED]>
 
 	* GWorkArea.[Ch]: Add GWorkArea::onScrollWheel to implement
Index: Dialogs.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/frontends/gtk/Dialogs.C,v
retrieving revision 1.18
diff -u -3 -p -u -p -r1.18 Dialogs.C
--- Dialogs.C	2004/05/19 15:11:32	1.18
+++ Dialogs.C	2004/09/24 19:42:55
@@ -78,7 +78,7 @@
 #include "FormPreferences.h"
 #include "FormPrint.h"
 #include "FormRef.h"
-#include "FormSearch.h"
+#include "GSearch.h"
 #include "FormSendto.h"
 #include "FormTabular.h"
 #include "FormTexinfo.h"
@@ -226,8 +226,9 @@ Dialogs::DialogPtr Dialogs::build(string
 		dialog->setView(new FormShowFile(*dialog));
 		dialog->bc().bp(new OkCancelPolicy);
 	} else if (name == "findreplace") {
+		dialog->bc().view(new GBC(dialog->bc()));
 		dialog->setController(new ControlSearch(*dialog));
-		dialog->setView(new FormSearch(*dialog));
+		dialog->setView(new GSearch(*dialog));
 		dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
 	} else if (name == "float") {
 		dialog->setController(new ControlFloat(*dialog));
Index: Makefile.am
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/frontends/gtk/Makefile.am,v
retrieving revision 1.16
diff -u -3 -p -u -p -r1.16 Makefile.am
--- Makefile.am	2004/07/22 13:44:39	1.16
+++ Makefile.am	2004/09/24 19:42:57
@@ -15,62 +15,65 @@ libgtk_la_LIBADD = $(xforms_objects) ../
 
 # Alphabetical order please.  It makes it easier to figure out what's missing.
 libgtk_la_SOURCES = \
-	ghelpers.C \
-	ghelpers.h \
-	lyx_gui.C \
-	GtkmmX.h \
-	xftFontLoader.C \
-	xftFontLoader.h \
-	codeConvert.h \
-	xftFontMetrics.C \
-	GScreen.C \
-	GScreen.h \
-	LyXScreenFactory.C \
+	Alert_pimpl.C \
+	Dialogs.C \
+	FileDialog.C \
+	FileDialogPrivate.C \
+	FileDialogPrivate.h \
+	GAboutlyx.C \
+	GAboutlyx.h \
+	GBC.C \
+	GBC.h \
+	GLyXKeySym.C \
+	GLyXKeySym.h \
+	GMathDelim.C \
+	GMathDelim.h \
+	GMathPanel.C \
+	GMathPanel.h \
 	GMenubar.C \
 	GMenubar.h \
-	GTimeout.C \
-	GTimeout.h \
-	GToolbar.C \
-	GToolbar.h \
-	WorkAreaFactory.C \
 	GMiniBuffer.C \
 	GMiniBuffer.h \
 	GPainter.C \
 	GPainter.h \
-	GWorkArea.h \
-	GWorkArea.C \
-	GLyXKeySym.h \
-	GLyXKeySym.C \
-	LyXKeySymFactory.C \
-	Alert_pimpl.C \
-	GView.h \
-	GView.C \
-	IdSc.h \
-	IdSc.C \
-	io_callback.h \
-	io_callback.C \
-	Dialogs.C \
-	GAboutlyx.h \
-	GAboutlyx.C \
-	GViewBase.h \
-	GViewBase.C \
-	GBC.h \
-	GBC.C \
-	FileDialogPrivate.h \
-	FileDialogPrivate.C \
-	FileDialog.C \
-	GText.h \
+	GScreen.C \
+	GScreen.h \
+	GSearch.C \
+	GSearch.h \
+	GTableCreate.C \
+	GTableCreate.h \
 	GText.C \
-	GUrl.h \
+	GText.h \
+	GTimeout.C \
+	GTimeout.h \
+	GToolbar.C \
+	GToolbar.h \
 	GUrl.C \
-	GTableCreate.h \
-	GTableCreate.C \
-	GMathPanel.h \
-	GMathPanel.C \
-	GXpmBtnTbl.h \
+	GUrl.h \
+	GView.C \
+	GView.h \
+	GViewBase.C \
+	GViewBase.h \
+	GWorkArea.C \
+	GWorkArea.h \
 	GXpmBtnTbl.C \
-	GMathDelim.h \
-	GMathDelim.C
+	GXpmBtnTbl.h \
+	GtkmmX.h \
+	IdSc.C \
+	IdSc.h \
+	LyXKeySymFactory.C \
+	LyXScreenFactory.C \
+	WorkAreaFactory.C \
+	codeConvert.h \
+	ghelpers.C \
+	ghelpers.h \
+	io_callback.C \
+	io_callback.h \
+	lyx_gui.C \
+	xftFontLoader.C \
+	xftFontLoader.h \
+	xftFontMetrics.C 
+
 
 #	GPrint.h
 #	GPrint.C
@@ -111,7 +114,6 @@ xforms_objects = \
 	../xforms/FormPreferences.lo \
 	../xforms/FormPrint.lo \
 	../xforms/FormRef.lo \
-	../xforms/FormSearch.lo \
 	../xforms/FormSendto.lo \
 	../xforms/forms_gettext.lo \
 	../xforms/FormShowFile.lo \
Index: glade/search.glade
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/frontends/gtk/glade/search.glade,v
retrieving revision 1.1
diff -u -3 -p -u -p -r1.1 search.glade
--- glade/search.glade	2003/10/28 16:45:09	1.1
+++ glade/search.glade	2004/09/24 19:42:57
@@ -5,12 +5,18 @@
 
 <widget class="GtkWindow" id="dialog">
   <property name="visible">True</property>
-  <property name="title" translatable="yes">LyX: Find and Replace</property>
+  <property name="title" translatable="yes">Find and Replace</property>
   <property name="type">GTK_WINDOW_TOPLEVEL</property>
   <property name="window_position">GTK_WIN_POS_NONE</property>
   <property name="modal">False</property>
-  <property name="resizable">True</property>
+  <property name="default_width">450</property>
+  <property name="resizable">False</property>
   <property name="destroy_with_parent">False</property>
+  <property name="decorated">True</property>
+  <property name="skip_taskbar_hint">False</property>
+  <property name="skip_pager_hint">False</property>
+  <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
+  <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
 
   <child>
     <widget class="GtkTable" id="table1">
@@ -20,12 +26,12 @@
       <property name="n_columns">3</property>
       <property name="homogeneous">False</property>
       <property name="row_spacing">2</property>
-      <property name="column_spacing">2</property>
+      <property name="column_spacing">4</property>
 
       <child>
 	<widget class="GtkLabel" id="label1">
 	  <property name="visible">True</property>
-	  <property name="label" translatable="yes">Find:</property>
+	  <property name="label" translatable="yes">Find what:</property>
 	  <property name="use_underline">False</property>
 	  <property name="use_markup">False</property>
 	  <property name="justify">GTK_JUSTIFY_RIGHT</property>
@@ -80,7 +86,7 @@
 	  <property name="text" translatable="yes"></property>
 	  <property name="has_frame">True</property>
 	  <property name="invisible_char" translatable="yes">*</property>
-	  <property name="activates_default">False</property>
+	  <property name="activates_default">True</property>
 	</widget>
 	<packing>
 	  <property name="left_attach">1</property>
@@ -115,12 +121,14 @@
       <child>
 	<widget class="GtkButton" id="FindNext">
 	  <property name="visible">True</property>
+	  <property name="sensitive">False</property>
 	  <property name="can_default">True</property>
 	  <property name="has_default">True</property>
 	  <property name="can_focus">True</property>
-	  <property name="label" translatable="yes">Find next</property>
-	  <property name="use_underline">True</property>
+	  <property name="label">gtk-find</property>
+	  <property name="use_stock">True</property>
 	  <property name="relief">GTK_RELIEF_NORMAL</property>
+	  <property name="focus_on_click">True</property>
 	</widget>
 	<packing>
 	  <property name="left_attach">2</property>
@@ -135,10 +143,12 @@
       <child>
 	<widget class="GtkButton" id="Replace">
 	  <property name="visible">True</property>
+	  <property name="sensitive">False</property>
 	  <property name="can_focus">True</property>
-	  <property name="label" translatable="yes">_Replace</property>
-	  <property name="use_underline">True</property>
+	  <property name="label">gtk-find-and-replace</property>
+	  <property name="use_stock">True</property>
 	  <property name="relief">GTK_RELIEF_NORMAL</property>
+	  <property name="focus_on_click">True</property>
 	</widget>
 	<packing>
 	  <property name="left_attach">2</property>
@@ -151,30 +161,14 @@
       </child>
 
       <child>
-	<widget class="GtkButton" id="ReplaceAll">
-	  <property name="visible">True</property>
-	  <property name="can_focus">True</property>
-	  <property name="label" translatable="yes">Repl_ace all</property>
-	  <property name="use_underline">True</property>
-	  <property name="relief">GTK_RELIEF_NORMAL</property>
-	</widget>
-	<packing>
-	  <property name="left_attach">2</property>
-	  <property name="right_attach">3</property>
-	  <property name="top_attach">2</property>
-	  <property name="bottom_attach">3</property>
-	  <property name="x_options">fill</property>
-	  <property name="y_options"></property>
-	</packing>
-      </child>
-
-      <child>
 	<widget class="GtkButton" id="Cancel">
 	  <property name="visible">True</property>
 	  <property name="can_focus">True</property>
-	  <property name="label" translatable="yes">Cancel</property>
-	  <property name="use_underline">True</property>
+	  <property name="label">gtk-close</property>
+	  <property name="use_stock">True</property>
 	  <property name="relief">GTK_RELIEF_NORMAL</property>
+	  <property name="focus_on_click">True</property>
+	  <accelerator key="Escape" modifiers="0" signal="clicked"/>
 	</widget>
 	<packing>
 	  <property name="left_attach">2</property>
@@ -199,6 +193,7 @@
 	      <property name="label" translatable="yes">_Case sensitive</property>
 	      <property name="use_underline">True</property>
 	      <property name="relief">GTK_RELIEF_NORMAL</property>
+	      <property name="focus_on_click">True</property>
 	      <property name="active">False</property>
 	      <property name="inconsistent">False</property>
 	      <property name="draw_indicator">True</property>
@@ -217,6 +212,7 @@
 	      <property name="label" translatable="yes">_Match word</property>
 	      <property name="use_underline">True</property>
 	      <property name="relief">GTK_RELIEF_NORMAL</property>
+	      <property name="focus_on_click">True</property>
 	      <property name="active">False</property>
 	      <property name="inconsistent">False</property>
 	      <property name="draw_indicator">True</property>
@@ -245,12 +241,13 @@
 	  <property name="spacing">0</property>
 
 	  <child>
-	    <widget class="GtkCheckButton" id="SearchBackwords">
+	    <widget class="GtkCheckButton" id="SearchBackwards">
 	      <property name="visible">True</property>
 	      <property name="can_focus">True</property>
 	      <property name="label" translatable="yes">_Search backwards</property>
 	      <property name="use_underline">True</property>
 	      <property name="relief">GTK_RELIEF_NORMAL</property>
+	      <property name="focus_on_click">True</property>
 	      <property name="active">False</property>
 	      <property name="inconsistent">False</property>
 	      <property name="draw_indicator">True</property>
@@ -269,6 +266,26 @@
 	  <property name="bottom_attach">4</property>
 	  <property name="x_options">fill</property>
 	  <property name="y_options">fill</property>
+	</packing>
+      </child>
+
+      <child>
+	<widget class="GtkButton" id="ReplaceAll">
+	  <property name="visible">True</property>
+	  <property name="sensitive">False</property>
+	  <property name="can_focus">True</property>
+	  <property name="label" translatable="yes">Repl_ace all</property>
+	  <property name="use_underline">True</property>
+	  <property name="relief">GTK_RELIEF_NORMAL</property>
+	  <property name="focus_on_click">True</property>
+	</widget>
+	<packing>
+	  <property name="left_attach">2</property>
+	  <property name="right_attach">3</property>
+	  <property name="top_attach">2</property>
+	  <property name="bottom_attach">3</property>
+	  <property name="x_options">fill</property>
+	  <property name="y_options"></property>
 	</packing>
       </child>
     </widget>
/**
 * \file GSearch.C
 * This file is part of LyX, the document processor.
 * Licence details can be found in the file COPYING.
 *
 * \author John Spray
 *
 * Full author contact details are available in file CREDITS.
 */

#include <config.h>
#include <gtkmm.h>

#include "GSearch.h"
#include "ControlSearch.h"
#include "ghelpers.h"
#include <libglademm.h>

using std::string;

namespace lyx {
namespace frontend {

typedef GViewCB<ControlSearch, GViewGladeB> base_class;

GSearch::GSearch(Dialog & parent)
	: base_class(parent, _("Find and Replace"), false)
{}


void GSearch::doBuild()
{
	string const gladeName = findGladeFile("search");
	xml_ = Gnome::Glade::Xml::create(gladeName);
	
	Gtk::Button * cancelbutton;
	xml_->get_widget("Cancel", cancelbutton);
	setCancel(cancelbutton);

	xml_->get_widget("FindNext", findnextbutton);
	xml_->get_widget("Replace", replacebutton);
	xml_->get_widget("ReplaceAll", replaceallbutton);	
	xml_->get_widget("FindEntry", findentry);
	xml_->get_widget("ReplaceEntry", replaceentry);
	xml_->get_widget("CaseSensitive", casecheck);
	xml_->get_widget("MatchWord", matchwordcheck);
	xml_->get_widget("SearchBackwards", backwardscheck);

	findnextbutton->signal_clicked().connect(
		SigC::slot(*this, &GSearch::onFindNext));
	replacebutton->signal_clicked().connect(
		SigC::slot(*this, &GSearch::onReplace));
	replaceallbutton->signal_clicked().connect(
		SigC::slot(*this, &GSearch::onReplaceAll));
	findentry->signal_changed().connect(
		SigC::slot(*this,&GSearch::onFindEntryChanged));	

	bcview().addReadOnly(replaceentry);
	bcview().addReadOnly(replacebutton);
	bcview().addReadOnly(replaceallbutton);
}

void GSearch::onFindNext()
{
	controller().find(findentry->get_text(),
	                  casecheck->get_active(),
	                  matchwordcheck->get_active(),
	                  !backwardscheck->get_active());
}

void GSearch::onReplace()
{
	controller().replace(findentry->get_text(),
	                     replaceentry->get_text(),
	                     casecheck->get_active(),
	                     matchwordcheck->get_active(),
	                     !backwardscheck->get_active(),
	                     false);			     
}

void GSearch::onReplaceAll()
{
	controller().replace(findentry->get_text(),
	                     replaceentry->get_text(),
	                     casecheck->get_active(),
	                     matchwordcheck->get_active(),
	                     !backwardscheck->get_active(),
	                     true);			     
}

void GSearch::onFindEntryChanged()
{
	if (findentry->get_text().empty()) {
		findnextbutton->set_sensitive(false);
		replacebutton->set_sensitive(false);
		replaceallbutton->set_sensitive(false);	
	} else {
		findnextbutton->set_sensitive(true);
		replacebutton->set_sensitive(true);
		replaceallbutton->set_sensitive(true);	
	}
}

} // namespace frontend
} // namespace lyx
// -*- C++ -*-
/**
 * \file GSearch.h
 * This file is part of LyX, the document processor.
 * Licence details can be found in the file COPYING.
 *
 * \author John Spray
 *
 * Full author contact details are available in file CREDITS.
 */

#ifndef GSEARCH_H
#define GSEARCH_H

#include "GViewBase.h"

namespace lyx {
namespace frontend {

class ControlSearch;

/** This class provides a GTK+ implementation of the FormSearch Dialog.
 */
class GSearch : public GViewCB<ControlSearch, GViewGladeB>
{
public:
	GSearch(Dialog & parent);
private:
	virtual void apply() {}
	virtual void doBuild();
	virtual void update() {}
	
	void onFindNext();
	void onReplace();
	void onReplaceAll();
	void onFindEntryChanged();		
	
	Gtk::Button * findnextbutton;
	Gtk::Button * replacebutton;
	Gtk::Button * replaceallbutton;		
	Gtk::Entry * findentry;
	Gtk::Entry * replaceentry;
	Gtk::CheckButton * casecheck;
	Gtk::CheckButton * matchwordcheck;
	Gtk::CheckButton * backwardscheck;		
};

} // namespace frontend
} // namespace lyx

#endif // GSEARCH_H

Reply via email to