Skip to content

Commit

Permalink
Traktor: Minor fix in Path class when concatenating two paths. Also c…
Browse files Browse the repository at this point in the history
…leaning up in FileDialog.
  • Loading branch information
apistol78 committed Mar 6, 2024
1 parent 304145f commit 5ffc316
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
17 changes: 10 additions & 7 deletions code/Core/Io/Path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,12 @@ Path Path::operator + (const Path& rh) const
return rh;
if (empty())
return rh;
return Path(getPathName() + L"/" + rh.getPathName());

const std::wstring lh = getPathName();
if (!lh.empty() && lh.back() == L'/')
return Path(lh + rh.getPathName());
else
return Path(lh + L"/" + rh.getPathName());
}

bool Path::operator == (const Path& rh) const
Expand Down Expand Up @@ -230,15 +235,15 @@ void Path::resolve()

for (;;)
{
size_t s = tmp.find(L"$(");
const size_t s = tmp.find(L"$(");
if (s == std::string::npos)
break;

size_t e = tmp.find(L")", s + 2);
const size_t e = tmp.find(L")", s + 2);
if (e == std::string::npos)
break;

std::wstring name = tmp.substr(s + 2, e - s - 2);
const std::wstring name = tmp.substr(s + 2, e - s - 2);

if (OS::getInstance().getEnvironment(name, env))
tmp = tmp.substr(0, s) + replaceAll(env, L'\\', L'/') + tmp.substr(e + 1);
Expand All @@ -256,13 +261,11 @@ void Path::resolve()
m_relative = true;
while (!tmp.empty())
{
if (tmp[0] == L'/')
if (tmp[0] == L'/' || tmp[0] == L'~')
{
m_relative = false;
tmp = tmp.substr(1);
}
else if (tmp[0] == L'~')
m_relative = false;
else
break;
}
Expand Down
20 changes: 10 additions & 10 deletions code/Ui/FileDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,26 @@ bool FileDialog::create(Widget* parent, const std::wstring& key, const std::wstr

// Sort by directory first then name.
m_gridFiles->setSort([](const GridRow* r1, const GridRow* r2) -> bool {
auto f1 = r1->getData< File >(L"FILE");
const auto f1 = r1->getData< File >(L"FILE");
T_FATAL_ASSERT(f1 != nullptr);
auto f2 = r2->getData< File >(L"FILE");
const auto f2 = r2->getData< File >(L"FILE");
T_FATAL_ASSERT(f2 != nullptr);

if (f1->isDirectory() && !f2->isDirectory())
return true;
if (!f1->isDirectory() && f2->isDirectory())
return false;

auto fn1 = f1->getPath().getFileNameNoExtension();
auto fn2 = f2->getPath().getFileNameNoExtension();
const std::wstring fn1 = f1->getPath().getFileNameNoExtension();
const std::wstring fn2 = f2->getPath().getFileNameNoExtension();
return compareIgnoreCase(fn1, fn2) < 0;
});

m_gridFiles->addEventHandler< SelectionChangeEvent >([&](SelectionChangeEvent* event) {
auto selectedRow = m_gridFiles->getSelectedRow();
if (selectedRow)
{
auto file = selectedRow->getData< File >(L"FILE");
const auto file = selectedRow->getData< File >(L"FILE");
T_FATAL_ASSERT(file != nullptr);

if (!file->isDirectory())
Expand All @@ -90,7 +90,7 @@ bool FileDialog::create(Widget* parent, const std::wstring& key, const std::wstr
});

m_gridFiles->addEventHandler< GridRowDoubleClickEvent >([&](GridRowDoubleClickEvent* event) {
auto file = event->getRow()->getData< File >(L"FILE");
const auto file = event->getRow()->getData< File >(L"FILE");
T_FATAL_ASSERT(file != nullptr);

if (file->isDirectory())
Expand Down Expand Up @@ -149,11 +149,11 @@ DialogResult FileDialog::showModal(Path& outPath)

if (!m_editFileName)
{
auto selectedRow = m_gridFiles->getSelectedRow();
const auto selectedRow = m_gridFiles->getSelectedRow();
if (selectedRow == nullptr)
return DialogResult::Cancel;

auto file = selectedRow->getData< File >(L"FILE");
const auto file = selectedRow->getData< File >(L"FILE");
T_FATAL_ASSERT(file != nullptr);

if (file->isDirectory())
Expand Down Expand Up @@ -191,7 +191,7 @@ DialogResult FileDialog::showModal(std::vector< Path >& outPaths)

for (auto row : m_gridFiles->getRows(ui::GridView::GfSelectedOnly))
{
auto file = row->getData< File >(L"FILE");
const auto file = row->getData< File >(L"FILE");
T_FATAL_ASSERT(file != nullptr);

if (file->isDirectory())
Expand Down Expand Up @@ -266,7 +266,7 @@ void FileDialog::updateFiles()
m_gridFiles->removeAllRows();
for (auto file : files)
{
auto fn = file->getPath().getFileName();
const std::wstring fn = file->getPath().getFileName();
if (fn == L"." || fn == L".." || file->isHidden())
continue;

Expand Down

0 comments on commit 5ffc316

Please sign in to comment.