Ticket #4123: drivesetupdisablebutton.patch

File drivesetupdisablebutton.patch, 2.9 KB (added by idefix, 14 years ago)

Patch to prevent DriveSetup initialise volumes without a name by disabling the Initialize button

  • src/add-ons/disk_systems/bfs/InitializeParameterEditor.cpp

     
    2121
    2222
    2323static uint32 MSG_BLOCK_SIZE = 'blsz';
     24static uint32 MSG_NAME_CHANGED = 'nmch';
    2425
    2526
     27
    2628InitializeBFSEditor::InitializeBFSEditor()
    2729    :
    2830    BPartitionParameterEditor(),
     
    8890InitializeBFSEditor::_CreateViewControls()
    8991{
    9092    fNameTC = new BTextControl("Name", "Haiku", NULL);
     93    fNameTC->SetModificationMessage(new BMessage(MSG_NAME_CHANGED));
    9194    // TODO find out what is the max length for this specific FS partition name
    9295    fNameTC->TextView()->SetMaxBytes(31);
    9396
  • src/apps/drivesetup/InitParamsPanel.cpp

     
    6969enum {
    7070    MSG_OK                      = 'okok',
    7171    MSG_CANCEL                  = 'cncl',
    72     MSG_BLOCK_SIZE              = 'blsz'
     72    MSG_NAME_CHANGED            = 'nmch'
    7373};
    7474
    7575
     
    8585{
    8686    AddCommonFilter(fEscapeFilter);
    8787
    88     BButton* okButton = new BButton("Initialize", new BMessage(MSG_OK));
     88    fOkButton = new BButton("Initialize", new BMessage(MSG_OK));
    8989    BButton* cancelButton = new BButton("Cancel", new BMessage(MSG_CANCEL));
    9090
    9191    partition->GetInitializationParameterEditor(diskSystem.String(),
     
    102102            .Add(BSpaceLayoutItem::CreateHorizontalStrut(5))
    103103            .AddGlue()
    104104            .Add(cancelButton)
    105             .Add(okButton)
     105            .Add(fOkButton)
    106106            .Add(BSpaceLayoutItem::CreateHorizontalStrut(5))
    107107        .End()
    108108
     
    111111
    112112    SetLayout(new BGroupLayout(B_HORIZONTAL));
    113113    AddChild(rootView);
    114     SetDefaultButton(okButton);
     114    SetDefaultButton(fOkButton);
    115115
    116116    // If the partition had a previous name, set to that name.
    117117    BString name = partition->ContentName();
     
    152152            release_sem(fExitSemaphore);
    153153            break;
    154154
     155        case MSG_NAME_CHANGED:
     156            // message comes from fEditor's BTextControl
     157            BTextControl* control;
     158            if (message->FindPointer("source", (void**)&control) != B_OK)
     159                break;
     160            if (control->TextView()->TextLength() == 0
     161                && fOkButton->IsEnabled())
     162                fOkButton->SetEnabled(false);
     163            else if (control->TextView()->TextLength() > 0
     164                && !fOkButton->IsEnabled())
     165                fOkButton->SetEnabled(true);
     166            break;
     167
    155168        default:
    156169            BWindow::MessageReceived(message);
    157170    }
  • src/apps/drivesetup/InitParamsPanel.h

     
    3636            EscapeFilter*       fEscapeFilter;
    3737            sem_id              fExitSemaphore;
    3838            BWindow*            fWindow;
     39            BButton*            fOkButton;
    3940            int32               fReturnValue;
    4041
    4142            BPartitionParameterEditor*  fEditor;