|
|
@@ -42,9 +42,6 @@
|
|
|
|
|
|
#include "../DebugNew.h"
|
|
|
|
|
|
-#include <algorithm>
|
|
|
-#include <vector>
|
|
|
-
|
|
|
namespace Urho3D
|
|
|
{
|
|
|
|
|
|
@@ -56,7 +53,8 @@ Console::Console(Context* context) :
|
|
|
autoVisibleOnError_(false),
|
|
|
historyRows_(DEFAULT_HISTORY_SIZE),
|
|
|
historyPosition_(0),
|
|
|
- historyOrAutoCompleteChange(false),
|
|
|
+ autoCompletePosition_(0),
|
|
|
+ historyOrAutoCompleteChange_(false),
|
|
|
printing_(false)
|
|
|
{
|
|
|
UI* ui = GetSubsystem<UI>();
|
|
|
@@ -241,6 +239,25 @@ void Console::SetFocusOnShow(bool enable)
|
|
|
focusOnShow_ = enable;
|
|
|
}
|
|
|
|
|
|
+void Console::AddAutoComplete(const String& option)
|
|
|
+{
|
|
|
+ // Sorted insertion
|
|
|
+ Vector<String>::Iterator iter = UpperBound(autoComplete_.Begin(), autoComplete_.End(), option);
|
|
|
+ if (!iter.ptr_)
|
|
|
+ autoComplete_.Push(option);
|
|
|
+ // Make sure it isn't a duplicate
|
|
|
+ else if (iter == autoComplete_.Begin() || *(iter - 1) != option)
|
|
|
+ autoComplete_.Insert(iter, option);
|
|
|
+}
|
|
|
+
|
|
|
+void Console::RemoveAutoComplete(const String& option)
|
|
|
+{
|
|
|
+ // Erase and keep ordered
|
|
|
+ autoComplete_.Erase(LowerBound(autoComplete_.Begin(), autoComplete_.End(), option));
|
|
|
+ if (autoCompletePosition_ > autoComplete_.Size())
|
|
|
+ autoCompletePosition_ = autoComplete_.Size();
|
|
|
+}
|
|
|
+
|
|
|
void Console::UpdateElements()
|
|
|
{
|
|
|
int width = GetSubsystem<UI>()->GetRoot()->GetWidth();
|
|
|
@@ -279,23 +296,6 @@ const String& Console::GetHistoryRow(unsigned index) const
|
|
|
return index < history_.Size() ? history_[index] : String::EMPTY;
|
|
|
}
|
|
|
|
|
|
-void Console::AddAutoComplete(const String & option)
|
|
|
-{
|
|
|
- // sorted insertion
|
|
|
- Vector<String>::Iterator iter = UpperBound(autoComplete_.Begin(), autoComplete_.End(), option);
|
|
|
- if(!iter.ptr_)
|
|
|
- autoComplete_.Push(option);
|
|
|
- // make sure it isn't a duplicate
|
|
|
- else if(iter == autoComplete_.Begin() || *(iter-1) != option)
|
|
|
- autoComplete_.Insert(iter, option);
|
|
|
-}
|
|
|
-
|
|
|
-void Console::RemoveAutoComplete(const String & option)
|
|
|
-{
|
|
|
- // erase and keep ordered
|
|
|
- autoComplete_.Erase(LowerBound(autoComplete_.Begin(), autoComplete_.End(), option));
|
|
|
-}
|
|
|
-
|
|
|
bool Console::PopulateInterpreter()
|
|
|
{
|
|
|
interpreters_->RemoveAllItems();
|
|
|
@@ -351,10 +351,10 @@ void Console::HandleTextChanged(StringHash eventType, VariantMap & eventData)
|
|
|
{
|
|
|
// Save the original line
|
|
|
// Make sure the change isn't caused by auto complete or history
|
|
|
- if (!historyOrAutoCompleteChange)
|
|
|
+ if (!historyOrAutoCompleteChange_)
|
|
|
autoCompleteLine_ = eventData[TextEntry::P_TEXT].GetString();
|
|
|
|
|
|
- historyOrAutoCompleteChange = false;
|
|
|
+ historyOrAutoCompleteChange_ = false;
|
|
|
}
|
|
|
|
|
|
void Console::HandleTextFinished(StringHash eventType, VariantMap& eventData)
|
|
|
@@ -385,9 +385,8 @@ void Console::HandleTextFinished(StringHash eventType, VariantMap& eventData)
|
|
|
history_.Erase(history_.Begin());
|
|
|
}
|
|
|
|
|
|
- historyPosition_ = history_.Size(); // reset
|
|
|
-
|
|
|
- autoCompleteIter_ = autoComplete_.End(); // reset
|
|
|
+ historyPosition_ = history_.Size(); // Reset
|
|
|
+ autoCompletePosition_ = autoComplete_.Size(); // Reset
|
|
|
|
|
|
currentRow_.Clear();
|
|
|
lineEdit_->SetText(currentRow_);
|
|
|
@@ -406,37 +405,35 @@ void Console::HandleLineEditKey(StringHash eventType, VariantMap& eventData)
|
|
|
switch (eventData[P_KEY].GetInt())
|
|
|
{
|
|
|
case KEY_UP:
|
|
|
- if (autoCompleteIter_ == autoComplete_.Begin())
|
|
|
- autoCompleteIter_ = autoComplete_.End();
|
|
|
+ if (autoCompletePosition_ == 0)
|
|
|
+ autoCompletePosition_ = autoComplete_.Size();
|
|
|
|
|
|
- if (autoCompleteIter_ != autoComplete_.End())
|
|
|
+ if (autoCompletePosition_ < autoComplete_.Size())
|
|
|
{
|
|
|
- Vector<String>::Iterator before_begin = --autoComplete_.Begin();
|
|
|
-
|
|
|
// Search for auto completion that contains the contents of the line
|
|
|
- for (--autoCompleteIter_; autoCompleteIter_ != before_begin; --autoCompleteIter_)
|
|
|
+ for (--autoCompletePosition_; autoCompletePosition_ != M_MAX_UNSIGNED; --autoCompletePosition_)
|
|
|
{
|
|
|
- if (autoCompleteIter_->StartsWith(autoCompleteLine_))
|
|
|
+ const String& current = autoComplete_[autoCompletePosition_];
|
|
|
+ if (current.StartsWith(autoCompleteLine_))
|
|
|
{
|
|
|
- historyOrAutoCompleteChange = true;
|
|
|
- lineEdit_->SetText(*autoCompleteIter_);
|
|
|
+ historyOrAutoCompleteChange_ = true;
|
|
|
+ lineEdit_->SetText(current);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// If not found
|
|
|
- if (autoCompleteIter_ == before_begin)
|
|
|
+ if (autoCompletePosition_ == M_MAX_UNSIGNED)
|
|
|
{
|
|
|
- // Reset the iterator
|
|
|
- autoCompleteIter_ = autoComplete_.End();
|
|
|
+ // Reset the position
|
|
|
+ autoCompletePosition_ = autoComplete_.Size();
|
|
|
// Reset history position
|
|
|
historyPosition_ = history_.Size();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// If no more auto complete options and history options left
|
|
|
- if (autoCompleteIter_ == autoComplete_.End() &&
|
|
|
- historyPosition_ > 0)
|
|
|
+ if (autoCompletePosition_ == autoComplete_.Size() && historyPosition_ > 0)
|
|
|
{
|
|
|
// If line text is not a history, save the current text value to be restored later
|
|
|
if (historyPosition_ == history_.Size())
|
|
|
@@ -458,33 +455,35 @@ void Console::HandleLineEditKey(StringHash eventType, VariantMap& eventData)
|
|
|
else
|
|
|
{
|
|
|
// Loop over
|
|
|
- if (autoCompleteIter_ == autoComplete_.End() || !autoCompleteIter_.ptr_)
|
|
|
- autoCompleteIter_ = autoComplete_.Begin();
|
|
|
+ if (autoCompletePosition_ >= autoComplete_.Size())
|
|
|
+ autoCompletePosition_ = 0;
|
|
|
else
|
|
|
- ++autoCompleteIter_; // If not starting over, skip checking the currently found completion
|
|
|
+ ++autoCompletePosition_; // If not starting over, skip checking the currently found completion
|
|
|
|
|
|
- Vector<String>::Iterator start_iter = autoCompleteIter_;
|
|
|
+ unsigned startPosition = autoCompletePosition_;
|
|
|
|
|
|
// Search for auto completion that contains the contents of the line
|
|
|
- for (; autoCompleteIter_ != autoComplete_.End(); ++autoCompleteIter_)
|
|
|
+ for (; autoCompletePosition_ < autoComplete_.Size(); ++autoCompletePosition_)
|
|
|
{
|
|
|
- if (autoCompleteIter_->StartsWith(autoCompleteLine_))
|
|
|
+ const String& current = autoComplete_[autoCompletePosition_];
|
|
|
+ if (current.StartsWith(autoCompleteLine_))
|
|
|
{
|
|
|
- historyOrAutoCompleteChange = true;
|
|
|
- lineEdit_->SetText(*autoCompleteIter_);
|
|
|
+ historyOrAutoCompleteChange_ = true;
|
|
|
+ lineEdit_->SetText(current);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// Continue to search the complete range
|
|
|
- if (autoCompleteIter_ == autoComplete_.End())
|
|
|
+ if (autoCompletePosition_ == autoComplete_.Size())
|
|
|
{
|
|
|
- for (autoCompleteIter_ = autoComplete_.Begin(); autoCompleteIter_ != start_iter; ++autoCompleteIter_)
|
|
|
+ for (autoCompletePosition_ = 0; autoCompletePosition_ != startPosition; ++autoCompletePosition_)
|
|
|
{
|
|
|
- if (autoCompleteIter_->StartsWith(autoCompleteLine_))
|
|
|
+ const String& current = autoComplete_[autoCompletePosition_];
|
|
|
+ if (current.StartsWith(autoCompleteLine_))
|
|
|
{
|
|
|
- historyOrAutoCompleteChange = true;
|
|
|
- lineEdit_->SetText(*autoCompleteIter_);
|
|
|
+ historyOrAutoCompleteChange_ = true;
|
|
|
+ lineEdit_->SetText(current);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
@@ -497,16 +496,16 @@ void Console::HandleLineEditKey(StringHash eventType, VariantMap& eventData)
|
|
|
|
|
|
if (changed)
|
|
|
{
|
|
|
- historyOrAutoCompleteChange = true;
|
|
|
+ historyOrAutoCompleteChange_ = true;
|
|
|
// Set text to history option
|
|
|
if (historyPosition_ < history_.Size())
|
|
|
lineEdit_->SetText(history_[historyPosition_]);
|
|
|
else // restore the original line value before it was set to history values
|
|
|
{
|
|
|
lineEdit_->SetText(currentRow_);
|
|
|
- // Set the auto complete iterator according to the currentRow
|
|
|
- for (autoCompleteIter_ = autoComplete_.Begin(); autoCompleteIter_ != autoComplete_.End(); ++autoCompleteIter_)
|
|
|
- if (autoCompleteIter_->StartsWith(currentRow_))
|
|
|
+ // Set the auto complete position according to the currentRow
|
|
|
+ for (autoCompletePosition_ = 0; autoCompletePosition_ < autoComplete_.Size(); ++autoCompletePosition_)
|
|
|
+ if (autoComplete_[autoCompletePosition_].StartsWith(currentRow_))
|
|
|
break;
|
|
|
}
|
|
|
}
|