mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-11 21:27:01 -04:00
find/replace kind of working
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@299 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -17,6 +17,8 @@
|
||||
#include <data/card.hpp>
|
||||
#include <data/action/set.hpp>
|
||||
#include <data/settings.hpp>
|
||||
#include <util/find_replace.hpp>
|
||||
#include <util/tagged_string.hpp>
|
||||
#include <util/window_id.hpp>
|
||||
#include <wx/splitter.h>
|
||||
|
||||
@@ -266,6 +268,61 @@ void CardsPanel::doPaste() { CUT_COPY_PASTE(doPaste, ;) }
|
||||
|
||||
// ----------------------------------------------------------------------------- : Searching
|
||||
|
||||
class CardsPanel::SearchFindInfo : public FindInfo {
|
||||
public:
|
||||
SearchFindInfo(CardsPanel& panel, wxFindReplaceData& what) : FindInfo(what), panel(panel) {}
|
||||
virtual bool handle(const CardP& card, const TextValueP& value, size_t pos) {
|
||||
// Select the card
|
||||
panel.card_list->setCard(card);
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
CardsPanel& panel;
|
||||
};
|
||||
|
||||
class CardsPanel::ReplaceFindInfo : public FindInfo {
|
||||
public:
|
||||
ReplaceFindInfo(CardsPanel& panel, wxFindReplaceData& what) : FindInfo(what), panel(panel) {}
|
||||
virtual bool handle(const CardP& card, const TextValueP& value, size_t pos) {
|
||||
// Select the card
|
||||
panel.card_list->setCard(card);
|
||||
// Replace
|
||||
panel.editor->insert(escape(what.GetReplaceString()), _("Replace"));
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
CardsPanel& panel;
|
||||
};
|
||||
|
||||
bool CardsPanel::doFind(wxFindReplaceData& what) {
|
||||
SearchFindInfo find(*this, what);
|
||||
return search(find, false);
|
||||
}
|
||||
bool CardsPanel::doReplace(wxFindReplaceData& what) {
|
||||
ReplaceFindInfo find(*this, what);
|
||||
return search(find, false);
|
||||
}
|
||||
bool CardsPanel::doReplaceAll(wxFindReplaceData& what) {
|
||||
return false; // TODO
|
||||
}
|
||||
|
||||
bool CardsPanel::search(FindInfo& find, bool from_start) {
|
||||
bool include = from_start;
|
||||
CardP current = card_list->getCard();
|
||||
for (size_t i = 0 ; i < set->cards.size() ; ++i) {
|
||||
CardP card = card_list->getCard( (long) (find.forward() ? i : set->cards.size() - i - 1) );
|
||||
if (card == current) include = true;
|
||||
if (include) {
|
||||
editor->setCard(card);
|
||||
if (editor->search(find, from_start || card != current)) {
|
||||
return true; // done
|
||||
}
|
||||
}
|
||||
}
|
||||
editor->setCard(current);
|
||||
return false;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Selection
|
||||
|
||||
CardP CardsPanel::selectedCard() const {
|
||||
|
||||
+13
-33
@@ -18,6 +18,7 @@ class DataEditor;
|
||||
class TextCtrl;
|
||||
class IconMenu;
|
||||
class HoverButton;
|
||||
class FindInfo;
|
||||
|
||||
// ----------------------------------------------------------------------------- : CardsPanel
|
||||
|
||||
@@ -39,7 +40,6 @@ class CardsPanel : public SetWindowPanel {
|
||||
// --------------------------------------------------- : Actions
|
||||
|
||||
virtual bool wantsToHandle(const Action&, bool undone) const;
|
||||
public:
|
||||
|
||||
// --------------------------------------------------- : Clipboard
|
||||
virtual bool canCut() const;
|
||||
@@ -50,39 +50,19 @@ class CardsPanel : public SetWindowPanel {
|
||||
virtual void doPaste();
|
||||
|
||||
// --------------------------------------------------- : Searching (find/replace)
|
||||
#if 0
|
||||
virtual bool canFind() const;
|
||||
virtual bool canReplace() const;
|
||||
virtual bool doFind(wxFindReplaceData& what);
|
||||
virtual bool doReplace(wxFindReplaceData& what);
|
||||
|
||||
virtual bool canFind() const { return true; }
|
||||
virtual bool canReplace() const { return true; }
|
||||
virtual bool doFind (wxFindReplaceData&);
|
||||
virtual bool doReplace (wxFindReplaceData&);
|
||||
virtual bool doReplaceAll(wxFindReplaceData&);
|
||||
private:
|
||||
// Functions that handle finding
|
||||
typedef void (CardsPanel::*FindHandler)(const CardP&, const TextValueP&, const size_t, const size_t, wxFindReplaceData&);
|
||||
|
||||
/// Execute a find (or replace), and start with the currently selected card and value
|
||||
/** if findSame==true then find will also find the currently highlighted word
|
||||
* Returns true if found
|
||||
*/
|
||||
bool find(FindReplaceData& what, const FindHandler& handler, bool findSame = false);
|
||||
|
||||
/// find handler : select found value
|
||||
void handleFind(const CardP& card, const TextValueP& value, size_t start, size_t end, FindReplaceData& what);
|
||||
|
||||
/// replace handler : replace found value, move selection to end
|
||||
void handleReplace(const CardP& card, const TextValueP& value, size_t start, size_t end, FindReplaceData& what);
|
||||
|
||||
/// Find in all cards
|
||||
/** NOTE: this function is essentially the same as findInCard */
|
||||
bool findInCards(const CardP& firstCard, const ValueP& firstValue, int firstChar, FindReplaceData& what, const FindHandler& handler);
|
||||
|
||||
/// Find in a card, if firstValue is specified start searching there
|
||||
/** NOTE: this function is essentially the same as findInCards */
|
||||
bool findInCard(const CardP& card, const ValueP& firstValue, int firstChar, FindReplaceData& what, const FindHandler& handler);
|
||||
|
||||
/// Find the current search string in the specified value
|
||||
/** if searchDir = up searches from the end and only before firstChar, unless firstChar == -1 */
|
||||
bool findInValue(const CardP& crd_, virtual const ValueP& value, int firstChar, FindReplaceData& what, const FindHandler& handler);
|
||||
#endif
|
||||
/// Do a search or replace action for the given FindInfo in all cards
|
||||
bool search(FindInfo& find, bool from_start);
|
||||
class SearchFindInfo;
|
||||
class ReplaceFindInfo;
|
||||
friend class CardsPanel::SearchFindInfo;
|
||||
friend class CardsPanel::ReplaceFindInfo;
|
||||
public:
|
||||
|
||||
// --------------------------------------------------- : Selection
|
||||
|
||||
@@ -61,8 +61,9 @@ class SetWindowPanel : public wxPanel, public SetView {
|
||||
// --------------------------------------------------- : Searching (find/replace)
|
||||
virtual bool canFind() const { return false; } ///< Is finding possible?
|
||||
virtual bool canReplace() const { return false; } ///< Is replacing possible?
|
||||
virtual bool doFind(wxFindReplaceData&) { return false; } ///< Find the next math
|
||||
virtual bool doReplace(wxFindReplaceData&) { return false; } ///< Replace the next match
|
||||
virtual bool doFind (wxFindReplaceData&) { return false; } ///< Find the next math
|
||||
virtual bool doReplace (wxFindReplaceData&) { return false; } ///< Replace the next match
|
||||
virtual bool doReplaceAll(wxFindReplaceData&) { return false; } ///< Replace all matches
|
||||
|
||||
// --------------------------------------------------- : Selection
|
||||
virtual CardP selectedCard() const { return CardP(); } ///< Return the currently selected card, or CardP()
|
||||
|
||||
@@ -43,6 +43,7 @@ SetWindow::SetWindow(Window* parent, const SetP& set)
|
||||
: wxFrame(parent, wxID_ANY, _TITLE_("magic set editor"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE)
|
||||
, current_panel(nullptr)
|
||||
, find_dialog(nullptr)
|
||||
, find_data(wxFR_DOWN)
|
||||
, number_of_recent_sets(0)
|
||||
{
|
||||
SetIcon(load_resource_icon(_("app")));
|
||||
@@ -537,7 +538,7 @@ void SetWindow::onReplace (wxFindDialogEvent&) {
|
||||
current_panel->doReplace(find_data);
|
||||
}
|
||||
void SetWindow::onReplaceAll(wxFindDialogEvent&) {
|
||||
// todo
|
||||
current_panel->doReplaceAll(find_data);
|
||||
}
|
||||
|
||||
void SetWindow::onEditPreferences(wxCommandEvent&) {
|
||||
@@ -627,10 +628,10 @@ BEGIN_EVENT_TABLE(SetWindow, wxFrame)
|
||||
EVT_GALLERY_SELECT (ID_FIELD_LIST, SetWindow::onChildMenu) // for StatsPanel, because it is not a EVT_TOOL
|
||||
|
||||
EVT_UPDATE_UI (wxID_ANY, SetWindow::onUpdateUI)
|
||||
// EVT_FIND (wxID_ANY, SetWindow::onFind)
|
||||
// EVT_FIND_NEXT (wxID_ANY, SetWindow::onFindNext)
|
||||
// EVT_FIND_REPLACE (wxID_ANY, SetWindow::onReplace)
|
||||
// EVT_FIND_REPLACE_ALL(wxID_ANY, SetWindow::onReplaceAll)
|
||||
EVT_FIND (wxID_ANY, SetWindow::onFind)
|
||||
EVT_FIND_NEXT (wxID_ANY, SetWindow::onFindNext)
|
||||
EVT_FIND_REPLACE (wxID_ANY, SetWindow::onReplace)
|
||||
EVT_FIND_REPLACE_ALL(wxID_ANY, SetWindow::onReplaceAll)
|
||||
EVT_CLOSE ( SetWindow::onClose)
|
||||
EVT_IDLE ( SetWindow::onIdle)
|
||||
EVT_CARD_SELECT (wxID_ANY, SetWindow::onCardSelect)
|
||||
|
||||
Reference in New Issue
Block a user