1340: Editor fixes r=def- a=Learath2

Address #1331 and also fix the scrollbar enabling when there isn't enough elements.

Co-authored-by: Learath <learath2@gmail.com>
This commit is contained in:
bors[bot] 2018-10-29 14:16:38 +00:00
commit 25bd83225f
2 changed files with 42 additions and 7 deletions

View file

@ -4126,6 +4126,7 @@ void CEditor::RenderFileDialog()
static float s_SearchBoxID = 0; static float s_SearchBoxID = 0;
UI()->DoLabel(&FileBoxLabel, "Search:", 10.0f, -1, -1); UI()->DoLabel(&FileBoxLabel, "Search:", 10.0f, -1, -1);
str_copy(m_aFileDialogPrevSearchText, m_aFileDialogSearchText, sizeof(m_aFileDialogPrevSearchText));
DoEditBox(&s_SearchBoxID, &FileBox, m_aFileDialogSearchText, sizeof(m_aFileDialogSearchText), 10.0f, &s_SearchBoxID,false,CUI::CORNER_L); DoEditBox(&s_SearchBoxID, &FileBox, m_aFileDialogSearchText, sizeof(m_aFileDialogSearchText), 10.0f, &s_SearchBoxID,false,CUI::CORNER_L);
// clearSearchbox button // clearSearchbox button
@ -4139,6 +4140,9 @@ void CEditor::RenderFileDialog()
UI()->SetActiveItem(&s_SearchBoxID); UI()->SetActiveItem(&s_SearchBoxID);
} }
} }
if(str_comp(m_aFileDialogPrevSearchText, m_aFileDialogSearchText))
m_FileDialogScrollValue = 0.0f;
} }
int Num = (int)(View.h/17.0f)+1; int Num = (int)(View.h/17.0f)+1;
@ -4146,7 +4150,19 @@ void CEditor::RenderFileDialog()
Scroll.HMargin(5.0f, &Scroll); Scroll.HMargin(5.0f, &Scroll);
m_FileDialogScrollValue = UiDoScrollbarV(&ScrollBar, &Scroll, m_FileDialogScrollValue); m_FileDialogScrollValue = UiDoScrollbarV(&ScrollBar, &Scroll, m_FileDialogScrollValue);
int ScrollNum = m_FileList.size()-Num+1; int ScrollNum = 0;
for(int i = 0; i < m_FileList.size(); i++)
{
m_FileList[i].m_IsVisible = false;
if(!m_aFileDialogSearchText[0] || str_find_nocase(m_FileList[i].m_aName, m_aFileDialogSearchText))
{
AddFileDialogEntry(i, &View);
m_FileList[i].m_IsVisible = true;
ScrollNum++;
}
}
ScrollNum -= Num - 1;
if(ScrollNum > 0) if(ScrollNum > 0)
{ {
if(Input()->KeyPress(KEY_MOUSE_WHEEL_UP)) if(Input()->KeyPress(KEY_MOUSE_WHEEL_UP))
@ -4157,6 +4173,11 @@ void CEditor::RenderFileDialog()
else else
ScrollNum = 0; ScrollNum = 0;
if(!m_FileList[m_FilesSelectedIndex].m_IsVisible)
{
m_FilesSelectedIndex = 0;
}
if(m_FilesSelectedIndex > -1) if(m_FilesSelectedIndex > -1)
{ {
for(int i = 0; i < Input()->NumEvents(); i++) for(int i = 0; i < Input()->NumEvents(); i++)
@ -4164,8 +4185,24 @@ void CEditor::RenderFileDialog()
int NewIndex = -1; int NewIndex = -1;
if(Input()->GetEvent(i).m_Flags&IInput::FLAG_PRESS) if(Input()->GetEvent(i).m_Flags&IInput::FLAG_PRESS)
{ {
if(Input()->GetEvent(i).m_Key == KEY_DOWN) NewIndex = m_FilesSelectedIndex + 1; if(Input()->GetEvent(i).m_Key == KEY_DOWN)
if(Input()->GetEvent(i).m_Key == KEY_UP) NewIndex = m_FilesSelectedIndex - 1; {
for(NewIndex = m_FilesSelectedIndex + 1; NewIndex < m_FileList.size(); NewIndex++)
{
if(m_FileList[NewIndex].m_IsVisible)
break;
}
dbg_msg("DEBUG", "NewIndex='%d'", NewIndex);
}
if(Input()->GetEvent(i).m_Key == KEY_UP)
{
for(NewIndex = m_FilesSelectedIndex - 1; NewIndex >= 0; NewIndex--)
{
if(m_FileList[NewIndex].m_IsVisible)
break;
}
dbg_msg("DEBUG", "NewIndex='%d'", NewIndex);
}
} }
if(NewIndex > -1 && NewIndex < m_FileList.size()) if(NewIndex > -1 && NewIndex < m_FileList.size())
{ {
@ -4250,10 +4287,6 @@ void CEditor::RenderFileDialog()
// set clipping // set clipping
UI()->ClipEnable(&View); UI()->ClipEnable(&View);
for(int i = 0; i < m_FileList.size(); i++)
if(!m_aFileDialogSearchText[0] || str_find_nocase (m_FileList[i].m_aName, m_aFileDialogSearchText))
AddFileDialogEntry(i, &View);
// disable clipping again // disable clipping again
UI()->ClipDisable(); UI()->ClipDisable();

View file

@ -840,6 +840,7 @@ public:
char m_aFileDialogCurrentFolder[MAX_PATH_LENGTH]; char m_aFileDialogCurrentFolder[MAX_PATH_LENGTH];
char m_aFileDialogCurrentLink[MAX_PATH_LENGTH]; char m_aFileDialogCurrentLink[MAX_PATH_LENGTH];
char m_aFileDialogSearchText[64]; char m_aFileDialogSearchText[64];
char m_aFileDialogPrevSearchText[64];
char *m_pFileDialogPath; char *m_pFileDialogPath;
bool m_aFileDialogActivate; bool m_aFileDialogActivate;
int m_FileDialogFileType; int m_FileDialogFileType;
@ -858,6 +859,7 @@ public:
bool m_IsDir; bool m_IsDir;
bool m_IsLink; bool m_IsLink;
int m_StorageType; int m_StorageType;
bool m_IsVisible;
bool operator<(const CFilelistItem &Other) { return !str_comp(m_aFilename, "..") ? true : !str_comp(Other.m_aFilename, "..") ? false : bool operator<(const CFilelistItem &Other) { return !str_comp(m_aFilename, "..") ? true : !str_comp(Other.m_aFilename, "..") ? false :
m_IsDir && !Other.m_IsDir ? true : !m_IsDir && Other.m_IsDir ? false : m_IsDir && !Other.m_IsDir ? true : !m_IsDir && Other.m_IsDir ? false :