mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-28 12:39:41 +00:00
Add buttons to search for next and previous occurrence
This commit is contained in:
parent
63659224fd
commit
b80556b5af
3 changed files with 49 additions and 11 deletions
|
@ -27,6 +27,8 @@
|
|||
#include "../mwworld/class.hpp"
|
||||
#include "../mwworld/esmstore.hpp"
|
||||
|
||||
#include <MyGUI_Button.h>
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
class ConsoleInterpreterContext : public MWScript::InterpreterContext
|
||||
|
@ -145,13 +147,17 @@ namespace MWGui
|
|||
getWidget(mCommandLine, "edit_Command");
|
||||
getWidget(mHistory, "list_History");
|
||||
getWidget(mSearchTerm, "edit_SearchTerm");
|
||||
getWidget(mNextButton, "button_Next");
|
||||
getWidget(mPreviousButton, "button_Previous");
|
||||
|
||||
// Set up the command line box
|
||||
mCommandLine->eventEditSelectAccept += newDelegate(this, &Console::acceptCommand);
|
||||
mCommandLine->eventKeyButtonPressed += newDelegate(this, &Console::commandBoxKeyPress);
|
||||
|
||||
// Set up the search term box
|
||||
mSearchTerm->eventKeyButtonReleased += newDelegate(this, &Console::searchTermBoxKeyRelease);
|
||||
mSearchTerm->eventEditSelectAccept += newDelegate(this, &Console::acceptSearchTerm);
|
||||
mNextButton->eventMouseButtonClick += newDelegate(this, &Console::findNextOccurrence);
|
||||
mPreviousButton->eventMouseButtonClick += newDelegate(this, &Console::findPreviousOccurence);
|
||||
|
||||
// Set up the log window
|
||||
mHistory->setOverflowToTheLeft(true);
|
||||
|
@ -347,13 +353,6 @@ namespace MWGui
|
|||
}
|
||||
}
|
||||
|
||||
void Console::searchTermBoxKeyRelease(MyGUI::Widget* _sender, MyGUI::KeyCode key)
|
||||
{
|
||||
const std::string& searchTerm = mSearchTerm->getOnlyText();
|
||||
if (searchTerm.empty())
|
||||
return;
|
||||
}
|
||||
|
||||
void Console::acceptCommand(MyGUI::EditBox* _sender)
|
||||
{
|
||||
const std::string& cm = mCommandLine->getOnlyText();
|
||||
|
@ -381,6 +380,31 @@ namespace MWGui
|
|||
execute(cm);
|
||||
}
|
||||
|
||||
void Console::acceptSearchTerm(MyGUI::EditBox* _sender)
|
||||
{
|
||||
const std::string& searchTerm = mSearchTerm->getOnlyText();
|
||||
if (searchTerm.length() <= 3)
|
||||
return;
|
||||
|
||||
auto result = mHistory->getOnlyText().find(searchTerm);
|
||||
|
||||
// result ist nur der Index des Chars
|
||||
// gescrollt wird aber mit Pixelwerten
|
||||
// also muss man irgendwie umrechnen, welche Zeile welchem Pixelwert entspricht
|
||||
mHistory->setTextSelection(result, result + searchTerm.length());
|
||||
mHistory->setVScrollPosition(result);
|
||||
}
|
||||
|
||||
void Console::findNextOccurrence(MyGUI::Widget* _sender)
|
||||
{
|
||||
print("Next");
|
||||
}
|
||||
|
||||
void Console::findPreviousOccurence(MyGUI::Widget* _sender)
|
||||
{
|
||||
print("Prev");
|
||||
}
|
||||
|
||||
std::string Console::complete(std::string input, std::vector<std::string>& matches)
|
||||
{
|
||||
std::string output = input;
|
||||
|
|
|
@ -29,6 +29,8 @@ namespace MWGui
|
|||
MyGUI::EditBox* mCommandLine;
|
||||
MyGUI::EditBox* mHistory;
|
||||
MyGUI::EditBox* mSearchTerm;
|
||||
MyGUI::Button* mNextButton;
|
||||
MyGUI::Button* mPreviousButton;
|
||||
|
||||
typedef std::list<std::string> StringList;
|
||||
|
||||
|
@ -79,10 +81,12 @@ namespace MWGui
|
|||
void updateConsoleTitle();
|
||||
|
||||
void commandBoxKeyPress(MyGUI::Widget* _sender, MyGUI::KeyCode key, MyGUI::Char _char);
|
||||
void searchTermBoxKeyRelease(MyGUI::Widget* _sender, MyGUI::KeyCode key);
|
||||
|
||||
void acceptCommand(MyGUI::EditBox* _sender);
|
||||
|
||||
void acceptSearchTerm(MyGUI::EditBox* _sender);
|
||||
void findNextOccurrence(MyGUI::Widget* _sender);
|
||||
void findPreviousOccurence(MyGUI::Widget* _sender);
|
||||
|
||||
std::string complete(std::string input, std::vector<std::string>& matches);
|
||||
|
||||
Compiler::Extensions mExtensions;
|
||||
|
|
|
@ -24,9 +24,19 @@
|
|||
</Widget>
|
||||
|
||||
<!-- Search box -->
|
||||
<Widget type="EditBox" skin="MW_ConsoleCommand" position="264 0 120 28" align="Top Right" name="edit_SearchTerm">
|
||||
<Widget type="EditBox" skin="MW_ConsoleCommand" position="250 1 115 28" align="Top Right" name="edit_SearchTerm">
|
||||
<Property key="InvertSelected" value="false"/>
|
||||
</Widget>
|
||||
|
||||
<!-- "Next" button -->
|
||||
<Widget type="Button" skin="MW_Button" position="220 0 28 28" name="button_Next" align="Top Right">
|
||||
<Property key="Caption" value=">"/>
|
||||
</Widget>
|
||||
|
||||
<!-- "Previous" button -->
|
||||
<Widget type="Button" skin="MW_Button" position="190 0 28 28" name="button_Previous" align="Top Right">
|
||||
<Property key="Caption" value="<"/>
|
||||
</Widget>
|
||||
|
||||
</Widget>
|
||||
</MyGUI>
|
||||
|
|
Loading…
Reference in a new issue