[haiku-commits] r42759 - haiku/trunk/src/apps/drivesetup

  • From: superstippi@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 19 Sep 2011 22:01:38 +0200 (CEST)

Author: stippi
Date: 2011-09-19 22:01:38 +0200 (Mon, 19 Sep 2011)
New Revision: 42759
Changeset: https://dev.haiku-os.org/changeset/42759
Ticket: https://dev.haiku-os.org/ticket/7991

Modified:
   haiku/trunk/src/apps/drivesetup/CreateParamsPanel.cpp
   haiku/trunk/src/apps/drivesetup/CreateParamsPanel.h
   haiku/trunk/src/apps/drivesetup/Support.cpp
   haiku/trunk/src/apps/drivesetup/Support.h
Log:
Patch by "jwlh172": Added a text control to the partition
creation panel of DriveSetup, to enter the partition size
manually. Closes ticket #7991. Changes by myself: I've
refactored updating the text control from the size slider
and used that method also when the user somehow entered
invalid input into the text control (untested).


Modified: haiku/trunk/src/apps/drivesetup/CreateParamsPanel.cpp
===================================================================
--- haiku/trunk/src/apps/drivesetup/CreateParamsPanel.cpp       2011-09-18 
16:47:47 UTC (rev 42758)
+++ haiku/trunk/src/apps/drivesetup/CreateParamsPanel.cpp       2011-09-19 
20:01:38 UTC (rev 42759)
@@ -77,7 +77,9 @@
 enum {
        MSG_OK                                          = 'okok',
        MSG_CANCEL                                      = 'cncl',
-       MSG_PARTITION_TYPE                      = 'type'
+       MSG_PARTITION_TYPE                      = 'type',
+       MSG_SIZE_SLIDER                         = 'ssld',
+       MSG_SIZE_TEXTCONTROL            = 'stct'
 };
 
 
@@ -138,6 +140,22 @@
                                fEditor->PartitionTypeChanged(type);
                        }
                        break;
+               
+               case MSG_SIZE_SLIDER:
+                       _UpdateTextControl();
+                       break;
+                       
+               case MSG_SIZE_TEXTCONTROL:
+               {
+                       BString sizeString;
+                       sizeString = fSizeTextControl->Text();
+                       int32 sizeInt = atoi(sizeString.String());
+                       if (sizeInt >= 0 && sizeInt <= 
fSizeSlider->MaxPartitionSize())
+                               fSizeSlider->SetValue(sizeInt);
+                       else
+                               _UpdateTextControl();
+                       break;
+               }
 
                default:
                        BWindow::MessageReceived(message);
@@ -225,6 +243,17 @@
        fSizeSlider = new SizeSlider("Slider", B_TRANSLATE("Partition size"), 
NULL,
                offset, offset + size);
        fSizeSlider->SetPosition(1.0);
+       fSizeSlider->SetModificationMessage(new BMessage(MSG_SIZE_SLIDER));
+       
+       BString sizeText;
+       sizeText << fSizeSlider->Value();
+       fSizeTextControl = new BTextControl("Size Control",
+               "", sizeText.String(), NULL);
+       for(int32 i = 0; i < 256; i++)
+               fSizeTextControl->TextView()->DisallowChar(i);
+       for(int32 i = '0'; i <= '9'; i++)
+               fSizeTextControl->TextView()->AllowChar(i);
+       fSizeTextControl->SetModificationMessage(new 
BMessage(MSG_SIZE_TEXTCONTROL));
 
        fNameTextControl = new BTextControl("Name Control",
                B_TRANSLATE("Partition name:"), "", NULL);
@@ -257,6 +286,7 @@
 
        AddChild(BGroupLayoutBuilder(B_VERTICAL, spacing)
                .Add(fSizeSlider)
+               .Add(fSizeTextControl)
                .Add(BGridLayoutBuilder(0.0, 5.0)
                        .Add(fNameTextControl->CreateLabelLayoutItem(), 0, 0)
                        .Add(fNameTextControl->CreateTextViewLayoutItem(), 1, 0)
@@ -284,3 +314,11 @@
        layout->View()->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
 }
 
+
+void
+CreateParamsPanel::_UpdateTextControl()
+{
+       BString sizeString;
+       sizeString << fSizeSlider->Value();
+       fSizeTextControl->SetText(sizeString.String());
+}

Modified: haiku/trunk/src/apps/drivesetup/CreateParamsPanel.h
===================================================================
--- haiku/trunk/src/apps/drivesetup/CreateParamsPanel.h 2011-09-18 16:47:47 UTC 
(rev 42758)
+++ haiku/trunk/src/apps/drivesetup/CreateParamsPanel.h 2011-09-19 20:01:38 UTC 
(rev 42759)
@@ -38,6 +38,8 @@
                        void                            
_CreateViewControls(BPartition* parent,
                                                                        off_t 
offset, off_t size);
 
+                       void                            _UpdateTextControl();
+
        class EscapeFilter;
                        EscapeFilter*           fEscapeFilter;
                        sem_id                          fExitSemaphore;
@@ -50,6 +52,7 @@
                        BMenuField*                     fTypeMenuField;
                        BTextControl*           fNameTextControl;
                        SizeSlider*                     fSizeSlider;
+                       BTextControl*           fSizeTextControl;
 };
 
 #endif // CREATE_PARAMS_PANEL_H

Modified: haiku/trunk/src/apps/drivesetup/Support.cpp
===================================================================
--- haiku/trunk/src/apps/drivesetup/Support.cpp 2011-09-18 16:47:47 UTC (rev 
42758)
+++ haiku/trunk/src/apps/drivesetup/Support.cpp 2011-09-19 20:01:38 UTC (rev 
42759)
@@ -99,7 +99,8 @@
        BSlider(name, label, message, minValue, maxValue,
        B_HORIZONTAL, B_TRIANGLE_THUMB),
        fStartOffset(minValue),
-       fEndOffset(maxValue)
+       fEndOffset(maxValue),
+       fMaxPartitionSize(maxValue)
 {
        SetBarColor((rgb_color){ 0, 80, 255, 255 });
        char minString[64];
@@ -143,3 +144,9 @@
        // headed slider is implemented.
        return fStartOffset;
 }
+
+int32
+SizeSlider::MaxPartitionSize()
+{
+       return fMaxPartitionSize;
+}

Modified: haiku/trunk/src/apps/drivesetup/Support.h
===================================================================
--- haiku/trunk/src/apps/drivesetup/Support.h   2011-09-18 16:47:47 UTC (rev 
42758)
+++ haiku/trunk/src/apps/drivesetup/Support.h   2011-09-19 20:01:38 UTC (rev 
42759)
@@ -51,10 +51,12 @@
        virtual const char*                     UpdateText() const;
                        int32                           Size();
                        int32                           Offset();
+                       int32                           MaxPartitionSize();
 
 private:
                        off_t                           fStartOffset;
                        off_t                           fEndOffset;
+                       off_t                           fMaxPartitionSize;
        mutable char                            fStatusLabel[64];
 };
 


Other related posts:

  • » [haiku-commits] r42759 - haiku/trunk/src/apps/drivesetup - superstippi