PageRenderTime 91ms CodeModel.GetById 20ms app.highlight 62ms RepoModel.GetById 1ms app.codeStats 1ms

/jEdit/tags/jedit-4-2-pre4/org/gjt/sp/jedit/search/SearchDialog.java

#
Java | 903 lines | 645 code | 143 blank | 115 comment | 106 complexity | f28612d7f0210c9cd09747f7ac025700 MD5 | raw file
  1/*
  2 * SearchDialog.java - Search and replace dialog
  3 * :tabSize=8:indentSize=8:noTabs=false:
  4 * :folding=explicit:collapseFolds=1:
  5 *
  6 * Copyright (C) 1998, 2003 Slava Pestov
  7 *
  8 * This program is free software; you can redistribute it and/or
  9 * modify it under the terms of the GNU General Public License
 10 * as published by the Free Software Foundation; either version 2
 11 * of the License, or any later version.
 12 *
 13 * This program is distributed in the hope that it will be useful,
 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16 * GNU General Public License for more details.
 17 *
 18 * You should have received a copy of the GNU General Public License
 19 * along with this program; if not, write to the Free Software
 20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 21 */
 22
 23package org.gjt.sp.jedit.search;
 24
 25//{{{ Imports
 26import javax.swing.border.*;
 27import javax.swing.*;
 28import java.awt.*;
 29import java.awt.event.*;
 30import java.io.File;
 31import java.util.HashMap;
 32import org.gjt.sp.jedit.browser.VFSBrowser;
 33import org.gjt.sp.jedit.gui.*;
 34import org.gjt.sp.jedit.io.*;
 35import org.gjt.sp.jedit.msg.SearchSettingsChanged;
 36import org.gjt.sp.jedit.msg.ViewUpdate;
 37import org.gjt.sp.jedit.*;
 38//}}}
 39
 40/**
 41 * Search and replace dialog.
 42 * @author Slava Pestov
 43 * @version $Id: SearchDialog.java 4808 2003-06-22 21:23:33Z spestov $
 44 */
 45public class SearchDialog extends EnhancedDialog implements EBComponent
 46{
 47	//{{{ Constants
 48	/**
 49	 * Default file set.
 50	 * @since jEdit 3.2pre2
 51	 */
 52	public static final int CURRENT_BUFFER = 0;
 53	public static final int ALL_BUFFERS = 1;
 54	public static final int DIRECTORY = 2;
 55	//}}}
 56
 57	//{{{ getSearchDialog() method
 58	public static SearchDialog getSearchDialog(View view)
 59	{
 60		return (SearchDialog)viewHash.get(view);
 61	} //}}}
 62
 63	//{{{ preloadSearchDialog() method
 64	/**
 65	 * Preloads the search dialog for the given for so that it can be
 66	 * quickly displayed later.
 67	 * @since jEdit 4.2pre3
 68	 */
 69	public static void preloadSearchDialog(View view)
 70	{
 71		SearchDialog dialog = new SearchDialog(view);
 72		viewHash.put(view,dialog);
 73	} //}}}
 74
 75	//{{{ showSearchDialog() method
 76	/**
 77	 * Displays a search and replace dialog box, reusing an existing one
 78	 * if necessary.
 79	 * @param view The view
 80	 * @param searchString The search string
 81	 * @param searchIn One of CURRENT_BUFFER, ALL_BUFFERS, or DIRECTORY
 82	 * @since jEdit 4.0pre6
 83	 */
 84	public static void showSearchDialog(View view, String searchString,
 85		int searchIn)
 86	{
 87		SearchDialog dialog = (SearchDialog)viewHash.get(view);
 88
 89		dialog.setSearchString(searchString,searchIn);
 90		GUIUtilities.requestFocus(dialog,dialog.find);
 91
 92		// ugly workaround
 93		if(OperatingSystem.isUnix() && !OperatingSystem.isMacOS())
 94			dialog.setVisible(false);
 95
 96		dialog.setVisible(true);
 97		dialog.toFront();
 98		dialog.requestFocus();
 99	} //}}}
100
101	//{{{ setSearchString() method
102	/**
103	 * Sets the search string.
104	 * @since jEdit 4.0pre5
105	 */
106	public void setSearchString(String searchString, int searchIn)
107	{
108		if(searchString == null)
109			find.setText(null);
110		else
111		{
112			if(searchString.indexOf('\n') == -1)
113			{
114				find.setText(searchString);
115				find.selectAll();
116			}
117			else if(searchIn == CURRENT_BUFFER)
118			{
119				searchSelection.setSelected(true);
120				hyperSearch.setSelected(true);
121			}
122		}
123
124		if(searchIn == CURRENT_BUFFER)
125		{
126			if(!searchSelection.isSelected())
127			{
128				// might be already selected, see above.
129				searchCurrentBuffer.setSelected(true);
130
131				/* this property is only loaded and saved if
132				 * the 'current buffer' file set is selected.
133				 * otherwise, it defaults to on. */
134				hyperSearch.setSelected(jEdit.getBooleanProperty(
135					"search.hypersearch.toggle"));
136			}
137		}
138		else if(searchIn == ALL_BUFFERS)
139		{
140			searchAllBuffers.setSelected(true);
141			hyperSearch.setSelected(true);
142		}
143		else if(searchIn == DIRECTORY)
144		{
145			hyperSearch.setSelected(true);
146			searchDirectory.setSelected(true);
147		}
148
149		updateEnabled();
150	} //}}}
151
152	//{{{ ok() method
153	public void ok()
154	{
155		try
156		{
157			setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
158
159			if(!save(false))
160				return;
161
162			if(searchSelection.isSelected()
163				&& view.getTextArea().getSelectionCount() == 0)
164			{
165				GUIUtilities.error(view,"search-no-selection",null);
166				return;
167			}
168
169			if(hyperSearch.isSelected() || searchSelection.isSelected())
170			{
171				if(SearchAndReplace.hyperSearch(view,
172					searchSelection.isSelected()))
173					closeOrKeepDialog();
174			}
175			else
176			{
177				if(SearchAndReplace.find(view))
178					closeOrKeepDialog();
179				else
180				{
181					toFront();
182					requestFocus();
183					find.requestFocus();
184				}
185			}
186		}
187		finally
188		{
189			setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
190		}
191	} //}}}
192
193	//{{{ cancel() method
194	public void cancel()
195	{
196		save(true);
197		GUIUtilities.saveGeometry(this,"search");
198		setVisible(false);
199	} //}}}
200
201	//{{{ handleMessage() method
202	public void handleMessage(EBMessage msg)
203	{
204		if(msg instanceof SearchSettingsChanged)
205		{
206			load();
207		}
208	} //}}}
209
210	//{{{ dispose() method
211	public void dispose()
212	{
213		EditBus.removeFromBus(this);
214		viewHash.remove(view);
215		super.dispose();
216	} //}}}
217
218	//{{{ Private members
219
220	private static HashMap viewHash = new HashMap();
221
222	//{{{ Instance variables
223	private View view;
224
225	// fields
226	private HistoryTextField find, replace;
227
228	private JRadioButton stringReplace, beanShellReplace;
229
230	// search settings
231	private JCheckBox keepDialog, ignoreCase, regexp, hyperSearch,
232		wrap;
233	private JRadioButton searchBack, searchForward;
234	private JRadioButton searchSelection, searchCurrentBuffer, searchAllBuffers,
235		searchDirectory;
236
237	// multifile settings
238	private HistoryTextField filter, directory;
239	private JCheckBox searchSubDirectories;
240	private JButton choose;
241
242	// buttons
243	private JButton findBtn, /* replaceBtn, */ replaceAndFindBtn, replaceAllBtn,
244		closeBtn;
245	//}}}
246
247	//{{{ SearchDialog constructor
248	/**
249	 * Creates a new search and replace dialog box.
250	 * @param view The view
251	 * @param searchString The search string
252	 */
253	private SearchDialog(View view)
254	{
255		super(view,jEdit.getProperty("search.title"),false);
256
257		this.view = view;
258
259		JPanel content = new JPanel(new BorderLayout());
260		content.setBorder(new EmptyBorder(0,12,12,12));
261		setContentPane(content);
262
263		JPanel centerPanel = new JPanel(new BorderLayout());
264		centerPanel.add(BorderLayout.NORTH,createFieldPanel());
265		centerPanel.add(BorderLayout.CENTER,createSearchSettingsPanel());
266		content.add(BorderLayout.CENTER,centerPanel);
267		content.add(BorderLayout.SOUTH,createMultiFilePanel());
268
269		content.add(BorderLayout.EAST,createButtonsPanel());
270
271		pack();
272		jEdit.unsetProperty("search.width");
273		jEdit.unsetProperty("search.d-width");
274		jEdit.unsetProperty("search.height");
275		jEdit.unsetProperty("search.d-height");
276		GUIUtilities.loadGeometry(this,"search");
277
278		load();
279
280		EditBus.addToBus(this);
281	} //}}}
282
283	//{{{ createFieldPanel() method
284	private JPanel createFieldPanel()
285	{
286		ButtonActionHandler actionHandler = new ButtonActionHandler();
287
288		JPanel fieldPanel = new JPanel(new VariableGridLayout(
289			VariableGridLayout.FIXED_NUM_COLUMNS,1));
290		fieldPanel.setBorder(new EmptyBorder(0,0,12,12));
291
292		JLabel label = new JLabel(jEdit.getProperty("search.find"));
293		label.setDisplayedMnemonic(jEdit.getProperty("search.find.mnemonic")
294			.charAt(0));
295		find = new HistoryTextField("find");
296		find.setColumns(25);
297
298		find.addActionListener(actionHandler);
299		label.setLabelFor(find);
300		label.setBorder(new EmptyBorder(12,0,2,0));
301		fieldPanel.add(label);
302		fieldPanel.add(find);
303
304		label = new JLabel(jEdit.getProperty("search.replace"));
305		label.setDisplayedMnemonic(jEdit.getProperty("search.replace.mnemonic")
306			.charAt(0));
307		label.setBorder(new EmptyBorder(12,0,0,0));
308		fieldPanel.add(label);
309
310		ButtonGroup grp = new ButtonGroup();
311		ReplaceActionHandler replaceActionHandler = new ReplaceActionHandler();
312
313		// we use a custom JRadioButton subclass that returns
314		// false for isFocusTraversable() so that the user can
315		// tab from the search field to the replace field with
316		// one keystroke
317
318		Box replaceModeBox = new Box(BoxLayout.X_AXIS);
319		stringReplace = new MyJRadioButton(jEdit.getProperty(
320			"search.string-replace-btn"));
321		stringReplace.addActionListener(replaceActionHandler);
322		grp.add(stringReplace);
323		replaceModeBox.add(stringReplace);
324
325		replaceModeBox.add(Box.createHorizontalStrut(12));
326
327		beanShellReplace = new MyJRadioButton(jEdit.getProperty(
328			"search.beanshell-replace-btn"));
329		beanShellReplace.addActionListener(replaceActionHandler);
330		grp.add(beanShellReplace);
331		replaceModeBox.add(beanShellReplace);
332
333		fieldPanel.add(replaceModeBox);
334
335		fieldPanel.add(Box.createVerticalStrut(3));
336
337		replace = new HistoryTextField("replace");
338		replace.addActionListener(actionHandler);
339		label.setLabelFor(replace);
340		fieldPanel.add(replace);
341
342		return fieldPanel;
343	} //}}}
344
345	//{{{ createSearchSettingsPanel() method
346	private JPanel createSearchSettingsPanel()
347	{
348		JPanel searchSettings = new JPanel(new VariableGridLayout(
349			VariableGridLayout.FIXED_NUM_COLUMNS,3));
350		searchSettings.setBorder(new EmptyBorder(0,0,12,12));
351
352		SettingsActionHandler actionHandler = new SettingsActionHandler();
353		ButtonGroup fileset = new ButtonGroup();
354		ButtonGroup direction = new ButtonGroup();
355
356		searchSettings.add(new JLabel(jEdit.getProperty("search.fileset")));
357
358		searchSettings.add(new JLabel(jEdit.getProperty("search.settings")));
359
360		searchSettings.add(new JLabel(jEdit.getProperty("search.direction")));
361
362		searchSelection = new JRadioButton(jEdit.getProperty("search.selection"));
363		searchSelection.setMnemonic(jEdit.getProperty("search.selection.mnemonic")
364			.charAt(0));
365		fileset.add(searchSelection);
366		searchSettings.add(searchSelection);
367		searchSelection.addActionListener(actionHandler);
368
369		keepDialog = new JCheckBox(jEdit.getProperty("search.keep"));
370		keepDialog.setMnemonic(jEdit.getProperty("search.keep.mnemonic")
371			.charAt(0));
372		searchSettings.add(keepDialog);
373
374		searchBack = new JRadioButton(jEdit.getProperty("search.back"));
375		searchBack.setMnemonic(jEdit.getProperty("search.back.mnemonic")
376			.charAt(0));
377		direction.add(searchBack);
378		searchSettings.add(searchBack);
379		searchBack.addActionListener(actionHandler);
380
381		searchCurrentBuffer = new JRadioButton(jEdit.getProperty("search.current"));
382		searchCurrentBuffer.setMnemonic(jEdit.getProperty("search.current.mnemonic")
383			.charAt(0));
384		fileset.add(searchCurrentBuffer);
385		searchSettings.add(searchCurrentBuffer);
386		searchCurrentBuffer.addActionListener(actionHandler);
387
388		ignoreCase = new JCheckBox(jEdit.getProperty("search.case"));
389		ignoreCase.setMnemonic(jEdit.getProperty("search.case.mnemonic")
390			.charAt(0));
391		searchSettings.add(ignoreCase);
392		ignoreCase.addActionListener(actionHandler);
393
394		searchForward = new JRadioButton(jEdit.getProperty("search.forward"));
395		searchForward.setMnemonic(jEdit.getProperty("search.forward.mnemonic")
396			.charAt(0));
397		direction.add(searchForward);
398		searchSettings.add(searchForward);
399		searchForward.addActionListener(actionHandler);
400
401		searchAllBuffers = new JRadioButton(jEdit.getProperty("search.all"));
402		searchAllBuffers.setMnemonic(jEdit.getProperty("search.all.mnemonic")
403			.charAt(0));
404		fileset.add(searchAllBuffers);
405		searchSettings.add(searchAllBuffers);
406		searchAllBuffers.addActionListener(actionHandler);
407
408		regexp = new JCheckBox(jEdit.getProperty("search.regexp"));
409		regexp.setMnemonic(jEdit.getProperty("search.regexp.mnemonic")
410			.charAt(0));
411		searchSettings.add(regexp);
412		regexp.addActionListener(actionHandler);
413
414		wrap = new JCheckBox(jEdit.getProperty("search.wrap"));
415		wrap.setMnemonic(jEdit.getProperty("search.wrap.mnemonic")
416			.charAt(0));
417		searchSettings.add(wrap);
418		wrap.addActionListener(actionHandler);
419
420		searchDirectory = new JRadioButton(jEdit.getProperty("search.directory"));
421		searchDirectory.setMnemonic(jEdit.getProperty("search.directory.mnemonic")
422			.charAt(0));
423		fileset.add(searchDirectory);
424		searchSettings.add(searchDirectory);
425		searchDirectory.addActionListener(actionHandler);
426
427		hyperSearch = new JCheckBox(jEdit.getProperty("search.hypersearch"));
428		hyperSearch.setMnemonic(jEdit.getProperty("search.hypersearch.mnemonic")
429			.charAt(0));
430		searchSettings.add(hyperSearch);
431		hyperSearch.addActionListener(actionHandler);
432
433		return searchSettings;
434	} //}}}
435
436	//{{{ createMultiFilePanel() method
437	private JPanel createMultiFilePanel()
438	{
439		JPanel multifile = new JPanel();
440
441		GridBagLayout layout = new GridBagLayout();
442		multifile.setLayout(layout);
443
444		GridBagConstraints cons = new GridBagConstraints();
445		cons.gridy = cons.gridwidth = cons.gridheight = 1;
446		cons.anchor = GridBagConstraints.WEST;
447		cons.fill = GridBagConstraints.HORIZONTAL;
448
449		MultiFileActionHandler actionListener = new MultiFileActionHandler();
450		filter = new HistoryTextField("search.filter");
451		filter.addActionListener(actionListener);
452
453		cons.insets = new Insets(0,0,3,0);
454
455		JLabel label = new JLabel(jEdit.getProperty("search.filterField"),
456			SwingConstants.RIGHT);
457		label.setBorder(new EmptyBorder(0,0,0,12));
458		label.setDisplayedMnemonic(jEdit.getProperty("search.filterField.mnemonic")
459			.charAt(0));
460		label.setLabelFor(filter);
461		cons.weightx = 0.0f;
462		layout.setConstraints(label,cons);
463		multifile.add(label);
464
465		cons.insets = new Insets(0,0,3,6);
466		cons.weightx = 1.0f;
467		layout.setConstraints(filter,cons);
468		multifile.add(filter);
469
470		cons.gridy++;
471
472		directory = new HistoryTextField("search.directory");
473		directory.setColumns(25);
474		directory.addActionListener(actionListener);
475
476		label = new JLabel(jEdit.getProperty("search.directoryField"),
477			SwingConstants.RIGHT);
478		label.setBorder(new EmptyBorder(0,0,0,12));
479
480		label.setDisplayedMnemonic(jEdit.getProperty("search.directoryField.mnemonic")
481			.charAt(0));
482		label.setLabelFor(directory);
483		cons.insets = new Insets(0,0,3,0);
484		cons.weightx = 0.0f;
485		layout.setConstraints(label,cons);
486		multifile.add(label);
487
488		cons.insets = new Insets(0,0,3,6);
489		cons.weightx = 1.0f;
490		cons.gridwidth = 2;
491		layout.setConstraints(directory,cons);
492		multifile.add(directory);
493
494		choose = new JButton(jEdit.getProperty("search.choose"));
495		choose.setMnemonic(jEdit.getProperty("search.choose.mnemonic")
496			.charAt(0));
497		cons.insets = new Insets(0,0,3,0);
498		cons.weightx = 0.0f;
499		cons.gridwidth = 1;
500		layout.setConstraints(choose,cons);
501		multifile.add(choose);
502		choose.addActionListener(actionListener);
503
504		cons.insets = new Insets(0,0,0,0);
505		cons.gridy++;
506		cons.gridwidth = 4;
507
508		searchSubDirectories = new JCheckBox(jEdit.getProperty(
509			"search.subdirs"));
510		searchSubDirectories.setMnemonic(jEdit.getProperty("search.subdirs.mnemonic")
511			.charAt(0));
512		layout.setConstraints(searchSubDirectories,cons);
513		multifile.add(searchSubDirectories);
514
515		return multifile;
516	} //}}}
517
518	//{{{ createButtonsPanel() method
519	private Box createButtonsPanel()
520	{
521		Box box = new Box(BoxLayout.Y_AXIS);
522
523		ButtonActionHandler actionHandler = new ButtonActionHandler();
524
525		box.add(Box.createVerticalStrut(12));
526
527		JPanel grid = new JPanel(new GridLayout(5,1,0,12));
528
529		findBtn = new JButton(jEdit.getProperty("search.findBtn"));
530		getRootPane().setDefaultButton(findBtn);
531		grid.add(findBtn);
532		findBtn.addActionListener(actionHandler);
533
534		/* replaceBtn = new JButton(jEdit.getProperty("search.replaceBtn"));
535		replaceBtn.setMnemonic(jEdit.getProperty("search.replaceBtn.mnemonic")
536			.charAt(0));
537		grid.add(replaceBtn);
538		replaceBtn.addActionListener(actionHandler); */
539
540		replaceAndFindBtn = new JButton(jEdit.getProperty("search.replaceAndFindBtn"));
541		replaceAndFindBtn.setMnemonic(jEdit.getProperty("search.replaceAndFindBtn.mnemonic")
542			.charAt(0));
543		grid.add(replaceAndFindBtn);
544		replaceAndFindBtn.addActionListener(actionHandler);
545
546		replaceAllBtn = new JButton(jEdit.getProperty("search.replaceAllBtn"));
547		replaceAllBtn.setMnemonic(jEdit.getProperty("search.replaceAllBtn.mnemonic")
548			.charAt(0));
549		grid.add(replaceAllBtn);
550		replaceAllBtn.addActionListener(actionHandler);
551
552		closeBtn = new JButton(jEdit.getProperty("common.close"));
553		grid.add(closeBtn);
554		closeBtn.addActionListener(actionHandler);
555
556		grid.setMaximumSize(grid.getPreferredSize());
557
558		box.add(grid);
559		box.add(Box.createGlue());
560
561		return box;
562	} //}}}
563
564	//{{{ updateEnabled() method
565	private void updateEnabled()
566	{
567		wrap.setEnabled(!hyperSearch.isSelected()
568			&& !searchSelection.isSelected());
569
570		boolean reverseEnabled = !hyperSearch.isSelected()
571			&& searchCurrentBuffer.isSelected()
572			&& !regexp.isSelected();
573		searchBack.setEnabled(reverseEnabled);
574		searchForward.setEnabled(reverseEnabled);
575		if(!reverseEnabled)
576			searchForward.setSelected(true);
577
578		filter.setEnabled(searchAllBuffers.isSelected()
579			|| searchDirectory.isSelected());
580
581		boolean directoryEnabled = searchDirectory.isSelected();
582
583		directory.setEnabled(directoryEnabled);
584		choose.setEnabled(directoryEnabled);
585		searchSubDirectories.setEnabled(directoryEnabled);
586
587		findBtn.setEnabled(!searchSelection.isSelected()
588			|| hyperSearch.isSelected());
589		replaceAndFindBtn.setEnabled(!hyperSearch.isSelected()
590			&& !searchSelection.isSelected());
591	} //}}}
592
593	//{{{ save() method
594	/**
595	 * @param cancel If true, we don't bother the user with warning messages
596	 */
597	private boolean save(boolean cancel)
598	{
599		String filter = this.filter.getText();
600		this.filter.addCurrentToHistory();
601		if(filter.length() == 0)
602			filter = "*";
603
604		SearchFileSet fileset = SearchAndReplace.getSearchFileSet();
605
606		if(searchSelection.isSelected())
607			fileset = new CurrentBufferSet();
608		else if(searchCurrentBuffer.isSelected())
609		{
610			fileset = new CurrentBufferSet();
611
612			jEdit.setBooleanProperty("search.hypersearch.toggle",
613				hyperSearch.isSelected());
614		}
615		else if(searchAllBuffers.isSelected())
616			fileset = new AllBufferSet(filter);
617		else if(searchDirectory.isSelected())
618		{
619			String directory = this.directory.getText();
620			this.directory.addCurrentToHistory();
621			directory = MiscUtilities.constructPath(
622				view.getBuffer().getDirectory(),directory);
623
624			if((VFSManager.getVFSForPath(directory).getCapabilities()
625				& VFS.LOW_LATENCY_CAP) == 0)
626			{
627				if(cancel)
628					return false;
629
630				int retVal = GUIUtilities.confirm(
631					SearchDialog.this,"remote-dir-search",
632					null,JOptionPane.YES_NO_OPTION,
633					JOptionPane.WARNING_MESSAGE);
634				if(retVal != JOptionPane.YES_OPTION)
635					return false;
636			}
637
638			boolean recurse = searchSubDirectories.isSelected();
639
640			if(fileset instanceof DirectoryListSet)
641			{
642				DirectoryListSet dset = (DirectoryListSet)fileset;
643				dset.setDirectory(directory);
644				dset.setFileFilter(filter);
645				dset.setRecursive(recurse);
646				EditBus.send(new SearchSettingsChanged(null));
647			}
648			else
649				fileset = new DirectoryListSet(directory,filter,recurse);
650		}
651		else
652		{
653			// can't happen
654			fileset = null;
655		}
656
657		jEdit.setBooleanProperty("search.keepDialog.toggle",
658			keepDialog.isSelected());
659
660		boolean ok = true;
661
662		SearchAndReplace.setSearchFileSet(fileset);
663
664		if(find.getText().length() != 0)
665		{
666			find.addCurrentToHistory();
667			SearchAndReplace.setSearchString(find.getText());
668			replace.addCurrentToHistory();
669
670			SearchAndReplace.setReplaceString(replace.getText());
671		}
672		else
673			ok = false;
674
675		return ok;
676	} //}}}
677
678	//{{{ closeOrKeepDialog() method
679	private void closeOrKeepDialog()
680	{
681		if(keepDialog.isSelected())
682		{
683			// Windows bug workaround in case a YES/NO confirm
684			// was shown
685
686			// ... but if HyperSearch results window is floating,
687			// the workaround causes problems!
688			if(!hyperSearch.isSelected())
689			{
690				toFront();
691				requestFocus();
692				find.requestFocus();
693			}
694			return;
695		}
696		else
697		{
698			GUIUtilities.saveGeometry(this,"search");
699			setVisible(false);
700		}
701	} //}}}
702
703	//{{{ load() method
704	private void load()
705	{
706		ignoreCase.setSelected(SearchAndReplace.getIgnoreCase());
707		regexp.setSelected(SearchAndReplace.getRegexp());
708		wrap.setSelected(SearchAndReplace.getAutoWrapAround());
709
710		if(SearchAndReplace.getReverseSearch())
711			searchBack.setSelected(true);
712		else
713			searchForward.setSelected(true);
714
715		if(SearchAndReplace.getBeanShellReplace())
716		{
717			replace.setModel("replace.script");
718			beanShellReplace.setSelected(true);
719		}
720		else
721		{
722			replace.setModel("replace");
723			stringReplace.setSelected(true);
724		}
725
726		SearchFileSet fileset = SearchAndReplace.getSearchFileSet();
727
728		if(fileset instanceof DirectoryListSet)
729		{
730			filter.setText(((DirectoryListSet)fileset)
731				.getFileFilter());
732			directory.setText(((DirectoryListSet)fileset)
733				.getDirectory());
734			searchSubDirectories.setSelected(((DirectoryListSet)fileset)
735				.isRecursive());
736		}
737		else
738		{
739			directory.setText(view.getBuffer().getDirectory());
740
741			if(fileset instanceof AllBufferSet)
742			{
743				filter.setText(((AllBufferSet)fileset)
744					.getFileFilter());
745			}
746			else
747			{
748				filter.setText("*" + MiscUtilities
749					.getFileExtension(view.getBuffer()
750					.getName()));
751			}
752
753			searchSubDirectories.setSelected(true);
754		}
755
756		directory.addCurrentToHistory();
757
758		keepDialog.setSelected(jEdit.getBooleanProperty(
759			"search.keepDialog.toggle"));
760	} //}}}
761
762	//}}}
763
764	//{{{ Inner classes
765
766	//{{{ MyJRadioButton class
767
768	// used for the stringReplace and beanShell replace radio buttons,
769	// so that the user can press tab to go from the find field to the
770	// replace field in one go
771	class MyJRadioButton extends JRadioButton
772	{
773		MyJRadioButton(String label)
774		{
775			super(label);
776		}
777
778		public boolean isFocusTraversable()
779		{
780			return false;
781		}
782	} //}}}
783
784	//{{{ ReplaceActionHandler class
785	class ReplaceActionHandler implements ActionListener
786	{
787		public void actionPerformed(ActionEvent evt)
788		{
789			replace.setModel(beanShellReplace.isSelected()
790				? "replace.script"
791				: "replace");
792			SearchAndReplace.setBeanShellReplace(
793				beanShellReplace.isSelected());
794		}
795	} //}}}
796
797	//{{{ SettingsActionHandler class
798	class SettingsActionHandler implements ActionListener
799	{
800		public void actionPerformed(ActionEvent evt)
801		{
802			Object source = evt.getSource();
803
804			if(source == ignoreCase)
805				SearchAndReplace.setIgnoreCase(ignoreCase.isSelected());
806			else if(source == regexp)
807				SearchAndReplace.setRegexp(regexp.isSelected());
808			else if(source == searchBack || source == searchForward)
809				SearchAndReplace.setReverseSearch(searchBack.isSelected());
810			else if(source == wrap)
811				SearchAndReplace.setAutoWrapAround(wrap.isSelected());
812			else if(source == searchCurrentBuffer)
813				hyperSearch.setSelected(false);
814			else if(source == searchSelection
815				|| source == searchAllBuffers
816				|| source == searchDirectory)
817				hyperSearch.setSelected(true);
818
819			updateEnabled();
820		}
821	} //}}}
822
823	//{{{ MultiFileActionHandler class
824	class MultiFileActionHandler implements ActionListener
825	{
826		public void actionPerformed(ActionEvent evt)
827		{
828			if(evt.getSource() == choose)
829			{
830				String[] dirs = GUIUtilities.showVFSFileDialog(
831					view,directory.getText(),
832					VFSBrowser.CHOOSE_DIRECTORY_DIALOG,
833					false);
834				if(dirs != null)
835					directory.setText(dirs[0]);
836			}
837			else // source is directory or filter field
838			{
839				// just as if Enter was pressed in another
840				// text field
841				ok();
842			}
843		}
844	} //}}}
845
846	//{{{ ButtonActionHandler class
847	class ButtonActionHandler implements ActionListener
848	{
849		public void actionPerformed(ActionEvent evt)
850		{
851			Object source = evt.getSource();
852
853			if(source == closeBtn)
854				cancel();
855			else if(source == findBtn || source == find
856				|| source == replace)
857			{
858				ok();
859			}
860			else if(source == replaceAndFindBtn)
861			{
862				save(false);
863				if(SearchAndReplace.replace(view))
864					ok();
865				else
866					getToolkit().beep();
867			}
868			else if(source == replaceAllBtn)
869			{
870				if(searchSelection.isSelected() &&
871					view.getTextArea().getSelectionCount()
872					== 0)
873				{
874					GUIUtilities.error(view,"search-no-selection",null);
875					return;
876				}
877
878				setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
879
880				save(false);
881
882				if(searchSelection.isSelected())
883				{
884					if(SearchAndReplace.replace(view))
885						closeOrKeepDialog();
886					else
887						getToolkit().beep();
888				}
889				else
890				{
891					if(SearchAndReplace.replaceAll(view))
892						closeOrKeepDialog();
893					else
894						getToolkit().beep();
895				}
896
897				setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
898			}
899		}
900	} //}}}
901
902	//}}}
903}