Skip to content

Commit

Permalink
Implemented search for resource
Browse files Browse the repository at this point in the history
  • Loading branch information
TcT2k committed Mar 21, 2015
1 parent c64ccbd commit 9b7965d
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 6 deletions.
100 changes: 94 additions & 6 deletions ExploreFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ ExploreFrame::ExploreFrame( wxWindow* parent ):
m_menubar->Enable(ID_EXTRACT, false);
m_menubar->Enable(wxID_SAVE, false);
m_menubar->Enable(wxID_SAVEAS, false);
m_menubar->Enable(wxID_FIND, false);
m_menubar->Enable(ID_PATCH_APPLY, false);
m_menubar->Enable(ID_PATCH_PREPARE, false);
m_menubar->Enable(ID_PATCH_CREATE, false);
Expand Down Expand Up @@ -127,11 +128,90 @@ ExploreFrame::ExploreFrame( wxWindow* parent ):

m_preparingPatch = false;

// Init find
m_findData.reset(new wxFindReplaceData(wxFR_DOWN));
m_findDialog = NULL;
Bind(wxEVT_FIND, &ExploreFrame::OnFind, this);
Bind(wxEVT_FIND_NEXT, &ExploreFrame::OnFindNext, this);
Bind(wxEVT_FIND_CLOSE, &ExploreFrame::OnFindClose, this);

Bind(wxEVT_MENU, &ExploreFrame::OnRecentFileClicked, this, wxID_FILE1, wxID_FILE9);

wxPersistenceManager::Get().RegisterAndRestore(this);
}

ExploreFrame::~ExploreFrame()
{
wxDELETE(m_findDialog);
}

void ExploreFrame::SelectItem(size_t index)
{
wxDataViewItem item((void*)(index + 1));
m_fileListCtrl->UnselectAll();
m_fileListCtrl->Select(item);
m_fileListCtrl->EnsureVisible(item);
wxDataViewEvent evt;
OnFileListSelectionChanged(evt);
}

bool ExploreFrame::ItemMatches(size_t index, const wxFindReplaceData& findReplaceData)
{
wxString entryFN = m_archive->GetEntry(index).GetFileName();
wxString findStr = findReplaceData.GetFindString();
if (!(findReplaceData.GetFlags() & wxFR_MATCHCASE))
{
entryFN.MakeLower();
findStr.MakeLower();
}

return entryFN.Find(findStr) != wxNOT_FOUND;
}

void ExploreFrame::OnFindNext(wxFindDialogEvent& event)
{
int matchIndex = wxNOT_FOUND;
size_t startIndex = (size_t)m_fileListCtrl->GetSelection().GetID() - 1;
if (event.GetFlags() & wxFR_DOWN)
{
for (size_t index = startIndex + 1; index < m_archive->GetEntryCount(); index++)
{
if (ItemMatches(index, *event.GetDialog()->GetData()))
{
matchIndex = index;
break;
}
}
} else {
for (size_t index = startIndex - 1; index > 0; index--)
{
if (ItemMatches(index, *event.GetDialog()->GetData()))
{
matchIndex = index;
break;
}
}
}
if (matchIndex == wxNOT_FOUND)
{
wxMessageBox(_("Entry not found"), _("Warning"), wxICON_WARNING | wxOK, event.GetDialog());
} else {
SelectItem(matchIndex);
}
}

void ExploreFrame::OnFind(wxFindDialogEvent& event)
{
SelectItem(0);
OnFindNext(event);
}

void ExploreFrame::OnFindClose(wxFindDialogEvent& event)
{
m_findDialog = NULL;
event.GetDialog()->Destroy();
}

void ExploreFrame::OnAboutClicked( wxCommandEvent& event )
{
wxAboutDialogInfo aboutInfo;
Expand Down Expand Up @@ -222,16 +302,13 @@ void ExploreFrame::OpenFile(const wxString& filename)
m_menubar->Enable(wxID_ADD, true);
m_menubar->Enable(wxID_SAVE, true);
m_menubar->Enable(wxID_SAVEAS, true);
m_menubar->Enable(wxID_FIND, true);
m_menubar->Enable(ID_PATCH_APPLY, true);
m_menubar->Enable(ID_PATCH_PREPARE, true);
UpdateTitle();
CheckBackup();
if (m_archive->GetEntryCount() > 0)
{
m_fileListCtrl->Select(wxDataViewItem((void*)1));
wxDataViewEvent evt;
OnFileListSelectionChanged(evt);
}
SelectItem(0);

m_fileHistory.AddFileToHistory(filename);
m_fileHistory.Save(*wxConfigBase::Get());
Expand Down Expand Up @@ -396,6 +473,17 @@ void ExploreFrame::OnReplaceClicked( wxCommandEvent& event )
}
}

void ExploreFrame::OnFindClicked(wxCommandEvent& event)
{
if (!m_findDialog)
{
m_findDialog = new wxFindReplaceDialog(this, m_findData.get(), _("Find"), wxFR_NOWHOLEWORD);
m_findDialog->Show();
}
else
m_findDialog->SetFocus();
}

void ExploreFrame::OnAddClicked( wxCommandEvent& event )
{
wxFileDialog fileDlg(this, _("Select file to add"), wxString(), wxString(), "*.*", wxFD_DEFAULT_STYLE | wxFD_FILE_MUST_EXIST);
Expand Down Expand Up @@ -445,7 +533,7 @@ void ExploreFrame::OnFileListSelectionChanged( wxDataViewEvent& event )

if (m_fileListCtrl->GetSelectedItemsCount() != 1)
return;

wxBusyCursor busyCursor;

size_t index = (size_t)m_fileListCtrl->GetSelection().GetID() - 1;
Expand Down
13 changes: 13 additions & 0 deletions ExploreFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Subclass of BaseExploreFrame, which is generated by wxFormBuilder.
#include "WADArchive.h"
#include <wx/sharedptr.h>
#include <wx/filehistory.h>
#include <wx/fdrepdlg.h>
#include <set>

/** Implementing BaseExploreFrame */
Expand All @@ -34,6 +35,7 @@ class ExploreFrame : public BaseExploreFrame
void OnRestoreClicked( wxCommandEvent& event );
void OnExtractClicked( wxCommandEvent& event );
void OnReplaceClicked( wxCommandEvent& event );
void OnFindClicked(wxCommandEvent& event);
void OnAddClicked( wxCommandEvent& event );
void OnDeleteClicked( wxCommandEvent& event );
void OnQuitClicked( wxCommandEvent& event );
Expand All @@ -44,10 +46,15 @@ class ExploreFrame : public BaseExploreFrame
void OnPatchApplyClicked(wxCommandEvent& event);
void OnPatchPrepareClicked(wxCommandEvent& event);
void OnPatchCreateClicked(wxCommandEvent& event);

void OnFind(wxFindDialogEvent& event);
void OnFindNext(wxFindDialogEvent& event);
void OnFindClose(wxFindDialogEvent& event);
public:
/** Constructor */
ExploreFrame( wxWindow* parent );
//// end generated class members
~ExploreFrame();

private:
friend class FileDataModel;
Expand All @@ -58,6 +65,8 @@ class ExploreFrame : public BaseExploreFrame
bool m_preparingPatch;
std::set<size_t> m_patchEntries;
wxDataViewColumn* m_fileListToggleColumn;
wxSharedPtr<wxFindReplaceData> m_findData;
wxFindReplaceDialog* m_findDialog;

const WADArchiveEntry& GetSelectedEntry() const;

Expand All @@ -70,6 +79,10 @@ class ExploreFrame : public BaseExploreFrame
void CheckBackup();

wxString GetGameBasePath() const;

bool ItemMatches(size_t index, const wxFindReplaceData& findReplaceData);

void SelectItem(size_t index);
};

#endif // __ExploreFrame__
19 changes: 19 additions & 0 deletions HLMWADExplorer.fbp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,25 @@
<event name="OnMenuSelection">OnReplaceClicked</event>
<event name="OnUpdateUI"></event>
</object>
<object class="separator" expanded="1">
<property name="name">m_separator5</property>
<property name="permission">none</property>
</object>
<object class="wxMenuItem" expanded="1">
<property name="bitmap"></property>
<property name="checked">0</property>
<property name="enabled">1</property>
<property name="help"></property>
<property name="id">wxID_FIND</property>
<property name="kind">wxITEM_NORMAL</property>
<property name="label"></property>
<property name="name">find</property>
<property name="permission">none</property>
<property name="shortcut"></property>
<property name="unchecked_bitmap"></property>
<event name="OnMenuSelection">OnFindClicked</event>
<event name="OnUpdateUI"></event>
</object>
<object class="separator" expanded="1">
<property name="name">m_separator2</property>
<property name="permission">none</property>
Expand Down
8 changes: 8 additions & 0 deletions HLMWADFrames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ BaseExploreFrame::BaseExploreFrame( wxWindow* parent, wxWindowID id, const wxStr

resource->AppendSeparator();

wxMenuItem* find;
find = new wxMenuItem( resource, wxID_FIND, wxString( wxEmptyString ) , wxEmptyString, wxITEM_NORMAL );
resource->Append( find );

resource->AppendSeparator();

wxMenuItem* add;
add = new wxMenuItem( resource, wxID_ADD, wxString( _("&Add...") ) + wxT('\t') + wxT("Ctrl+A"), wxEmptyString, wxITEM_NORMAL );
resource->Append( add );
Expand Down Expand Up @@ -140,6 +146,7 @@ BaseExploreFrame::BaseExploreFrame( wxWindow* parent, wxWindowID id, const wxStr
this->Connect( quit->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( BaseExploreFrame::OnQuitClicked ) );
this->Connect( extract->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( BaseExploreFrame::OnExtractClicked ) );
this->Connect( replace->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( BaseExploreFrame::OnReplaceClicked ) );
this->Connect( find->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( BaseExploreFrame::OnFindClicked ) );
this->Connect( add->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( BaseExploreFrame::OnAddClicked ) );
this->Connect( deleteMenuItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( BaseExploreFrame::OnDeleteClicked ) );
this->Connect( apply->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( BaseExploreFrame::OnPatchApplyClicked ) );
Expand All @@ -161,6 +168,7 @@ BaseExploreFrame::~BaseExploreFrame()
this->Disconnect( wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( BaseExploreFrame::OnQuitClicked ) );
this->Disconnect( ID_EXTRACT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( BaseExploreFrame::OnExtractClicked ) );
this->Disconnect( ID_REPLACE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( BaseExploreFrame::OnReplaceClicked ) );
this->Disconnect( wxID_FIND, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( BaseExploreFrame::OnFindClicked ) );
this->Disconnect( wxID_ADD, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( BaseExploreFrame::OnAddClicked ) );
this->Disconnect( wxID_DELETE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( BaseExploreFrame::OnDeleteClicked ) );
this->Disconnect( ID_PATCH_APPLY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( BaseExploreFrame::OnPatchApplyClicked ) );
Expand Down
1 change: 1 addition & 0 deletions HLMWADFrames.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class BaseExploreFrame : public wxFrame
virtual void OnQuitClicked( wxCommandEvent& event ) { event.Skip(); }
virtual void OnExtractClicked( wxCommandEvent& event ) { event.Skip(); }
virtual void OnReplaceClicked( wxCommandEvent& event ) { event.Skip(); }
virtual void OnFindClicked( wxCommandEvent& event ) { event.Skip(); }
virtual void OnAddClicked( wxCommandEvent& event ) { event.Skip(); }
virtual void OnDeleteClicked( wxCommandEvent& event ) { event.Skip(); }
virtual void OnPatchApplyClicked( wxCommandEvent& event ) { event.Skip(); }
Expand Down

0 comments on commit 9b7965d

Please sign in to comment.