From 950eeadd92fb9320bc052d7ad87c66bc673aab26 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Wed, 22 Oct 2008 13:54:30 +0000 Subject: [PATCH] Factor out a ValidateDest() function that checks if the destination is valid and throws up a BAlert if not. Reuse this when the user clicks expand to check for and grab the destination path. This fixes the problem that if the user manually types in or pastes a destination path and then immediately clicks Expand, the actual destination path used is never updated. Thanks to Daniel Teixeira for reporting. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28283 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/expander/ExpanderWindow.cpp | 28 ++++++++++++++++++---------- src/apps/expander/ExpanderWindow.h | 1 + 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/apps/expander/ExpanderWindow.cpp b/src/apps/expander/ExpanderWindow.cpp index d264b89319..408060db7b 100644 --- a/src/apps/expander/ExpanderWindow.cpp +++ b/src/apps/expander/ExpanderWindow.cpp @@ -179,6 +179,21 @@ ExpanderWindow::~ExpanderWindow() delete fSourcePanel; } +bool +ExpanderWindow::ValidateDest() +{ + BEntry entry(fDestText->Text(), true); + if (!entry.Exists()) { + BAlert *alert = new BAlert("destAlert", "The destination" + " directory does not exist.", "Cancel", NULL, NULL, + B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_WARNING_ALERT); + alert->Go(); + return false; + } else { + entry.GetRef(&fDestRef); + return true; + } +} void ExpanderWindow::FrameResized(float width, float height) @@ -233,6 +248,8 @@ ExpanderWindow::MessageReceived(BMessage *msg) break; case MSG_EXPAND: + if (!ValidateDest()) + break; if (!fExpandingStarted) { StartExpanding(); break; @@ -309,16 +326,7 @@ ExpanderWindow::MessageReceived(BMessage *msg) break; case MSG_DESTTEXT: { - BEntry entry(fDestText->Text(), true); - if (!entry.Exists()) { - BAlert *alert = new BAlert("destAlert", "The directory was either moved, renamed or not\n" - "supported.", - "Cancel", NULL, NULL, - B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_WARNING_ALERT); - alert->Go(); - break; - } - entry.GetRef(&fDestRef); + ValidateDest(); } break; case MSG_PREFERENCES: diff --git a/src/apps/expander/ExpanderWindow.h b/src/apps/expander/ExpanderWindow.h index 58f73fb3e9..96b34091ee 100644 --- a/src/apps/expander/ExpanderWindow.h +++ b/src/apps/expander/ExpanderWindow.h @@ -49,6 +49,7 @@ class ExpanderWindow : public BWindow { void _UpdateWindowSize(bool showContents); void StartListing(); void StopListing(); + bool ValidateDest(); BFilePanel *fSourcePanel; DirectoryFilePanel *fDestPanel;