From 7c6943575542e22e2276e187704d072b1b799417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 19 Feb 2010 17:22:54 +0000 Subject: [PATCH] * Applied patch by idefix that disables the "Initialize" button if the name field is empty. This is part of ticket #4123. * The message constants should be moved into their own shared header, though; added a TODO for this. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35524 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../bfs/InitializeParameterEditor.cpp | 2 ++ src/apps/drivesetup/InitParamsPanel.cpp | 28 +++++++++++++++---- src/apps/drivesetup/InitParamsPanel.h | 1 + 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/add-ons/disk_systems/bfs/InitializeParameterEditor.cpp b/src/add-ons/disk_systems/bfs/InitializeParameterEditor.cpp index 1e2c045dc6..c758d50ab0 100644 --- a/src/add-ons/disk_systems/bfs/InitializeParameterEditor.cpp +++ b/src/add-ons/disk_systems/bfs/InitializeParameterEditor.cpp @@ -24,6 +24,7 @@ static uint32 MSG_BLOCK_SIZE = 'blsz'; +static uint32 MSG_NAME_CHANGED = 'nmch'; InitializeBFSEditor::InitializeBFSEditor() @@ -95,6 +96,7 @@ void InitializeBFSEditor::_CreateViewControls() { fNameTC = new BTextControl("Name:", "Haiku", NULL); + fNameTC->SetModificationMessage(new BMessage(MSG_NAME_CHANGED)); // TODO find out what is the max length for this specific FS partition name fNameTC->TextView()->SetMaxBytes(31); diff --git a/src/apps/drivesetup/InitParamsPanel.cpp b/src/apps/drivesetup/InitParamsPanel.cpp index d124cd3efc..2a59c8ce35 100644 --- a/src/apps/drivesetup/InitParamsPanel.cpp +++ b/src/apps/drivesetup/InitParamsPanel.cpp @@ -4,9 +4,10 @@ * * Authors: * Stephan Aßmus -* Karsten Heimrich. + * Karsten Heimrich. */ + #include "InitParamsPanel.h" #include @@ -20,6 +21,7 @@ #include #include #include +#include #define TR_CONTEXT "InitParamsPanel" @@ -67,10 +69,13 @@ private: // #pragma mark - +// TODO: MSG_NAME_CHANGED is shared with the disk system add-ons, so it should +// be in some private shared header. +// TODO: there is already B_CANCEL, why not use that one? enum { MSG_OK = 'okok', MSG_CANCEL = 'cncl', - MSG_BLOCK_SIZE = 'blsz' + MSG_NAME_CHANGED = 'nmch' }; @@ -87,7 +92,7 @@ InitParamsPanel::InitParamsPanel(BWindow* window, const BString& diskSystem, { AddCommonFilter(fEscapeFilter); - BButton* okButton = new BButton(TR("Initialize"), new BMessage(MSG_OK)); + fOkButton = new BButton(TR("Initialize"), new BMessage(MSG_OK)); partition->GetInitializationParameterEditor(diskSystem.String(), &fEditor); @@ -99,12 +104,12 @@ InitParamsPanel::InitParamsPanel(BWindow* window, const BString& diskSystem, .AddGroup(B_HORIZONTAL, spacing) .AddGlue() .Add(new BButton(TR("Cancel"), new BMessage(MSG_CANCEL))) - .Add(okButton) + .Add(fOkButton) .End() .SetInsets(spacing, spacing, spacing, spacing) ); - SetDefaultButton(okButton); + SetDefaultButton(fOkButton); // If the partition had a previous name, set to that name. BString name = partition->ContentName(); @@ -145,6 +150,19 @@ InitParamsPanel::MessageReceived(BMessage* message) release_sem(fExitSemaphore); break; + case MSG_NAME_CHANGED: + // message comes from fEditor's BTextControl + BTextControl* control; + if (message->FindPointer("source", (void**)&control) != B_OK) + break; + if (control->TextView()->TextLength() == 0 + && fOkButton->IsEnabled()) + fOkButton->SetEnabled(false); + else if (control->TextView()->TextLength() > 0 + && !fOkButton->IsEnabled()) + fOkButton->SetEnabled(true); + break; + default: BWindow::MessageReceived(message); } diff --git a/src/apps/drivesetup/InitParamsPanel.h b/src/apps/drivesetup/InitParamsPanel.h index 9f625acdef..98b1022446 100644 --- a/src/apps/drivesetup/InitParamsPanel.h +++ b/src/apps/drivesetup/InitParamsPanel.h @@ -36,6 +36,7 @@ private: EscapeFilter* fEscapeFilter; sem_id fExitSemaphore; BWindow* fWindow; + BButton* fOkButton; int32 fReturnValue; BPartitionParameterEditor* fEditor;