Author: jreidinger
Date: Tue Mar 24 13:08:52 2009
New Revision: 56367
URL: http://svn.opensuse.org/viewcvs/yast?rev=56367&view=rev
Log:
add first validation and copy universal browse widget from global widgets
Modified:
branches/tmp/juhliarik/bootloader-UIrefactor/src/routines/section_widgets.ycp
Modified: branches/tmp/juhliarik/bootloader-UIrefactor/src/routines/section_widgets.ycp
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/juhliarik/bootloader-UIrefactor/src/routines/section_widgets.ycp?rev=56367&r1=56366&r2=56367&view=diff
==============================================================================
--- branches/tmp/juhliarik/bootloader-UIrefactor/src/routines/section_widgets.ycp (original)
+++ branches/tmp/juhliarik/bootloader-UIrefactor/src/routines/section_widgets.ycp Tue Mar 24 13:08:52 2009
@@ -11,6 +11,7 @@
* Authors:
* Jiri Srain
* Olaf Dabrunz
+ * Josef Reidinger
*
* $Id$
*
@@ -27,9 +28,9 @@
import "Mode";
import "Storage";
import "StorageDevices";
-import "TablePopup";
import "Bootloader";
import "Popup";
+import "FileUtils";
include "bootloader/routines/helps.ycp";
include "bootloader/grub/helps.ycp";
@@ -37,7 +38,26 @@
include "bootloader/zipl/helps.ycp";
include "bootloader/ppc/helps.ycp";
+boolean validate_image(string widget, map event){
+ string value = (string) UI::QueryWidget(`id(widget),`Value);
+ if (value == ""){
+ Popup::Error(_("Image section must have specified kernel image"));
+ UI::SetFocus(`id(widget));
+ return false;
+ }
+ if (!Mode::installation() && !Mode::repair()){
+ if (!FileUtils::Exists(value)){
+ if (!Popup::YesNo(_("Image file doesn't exist now. Do you really want use it?"))){
+ UI::SetFocus(`id(widget));
+ return false;
+ }
+ }
+ }
+}
+map validation_map = $[
+ "image" : validate_image,
+];
/**
* Init function for widget value
* @param widget any id of the widget
@@ -86,6 +106,55 @@
];
}
+
+/**
+ * Handle function of a widget (InputField + browse button)
+ * @param widget any widget key
+ * @param event map event description of event that occured
+ * @return symbol nil
+ */
+symbol HandleSectionBrowse (string widget, map event) {
+ string current = (string)UI::QueryWidget (`id (widget), `Value);
+ // file open popup caption
+ current = UI::AskForExistingFile (current, "*", _("Select File"));
+ if (current != nil)
+ UI::ChangeWidget (`id (widget), `Value, current);
+ return nil;
+}
+
+/**
+ * Generic widget of a inputfield + browse button
+ * Use validation function from validation_map
+ * if it is necessary create own definition of widget
+ * @param string lable of widget
+ * @param string help text for widget
+ * @param string id of widget
+ * @return map CWS widget
+ */
+map SectionInputFieldBrowseWidget(string label, string help, string id){
+ string browse = "browse" + id;
+ map ret = $[
+ "widget" : `custom,
+ "custom_widget" : `HBox(
+ `Left(`InputField(`id(id),`opt(`hstretch), label)),
+ `VBox(
+ `Label(""),
+ `PushButton(`id(browse),`opt(`notify), Label::BrowseButton())
+ )
+ ),
+ "init" : SectionOptionInit,
+ "store" : SectionOptionStore,
+ "handle" : HandleSectionBrowse,
+ "handle_events" : [browse],
+ "help" : help,
+ ];
+ if (haskey(validation_map,id)){
+ ret["validate_type"] = `function;
+ ret["validate_function"] = validation_map[id]:nil;//nil cannot happen
+ }
+
+ return ret;
+}
void InitSectionInt(string widget){
integer value = tointeger(BootCommon::current_section[widget]:"0");
UI::ChangeWidget (`id (widget), `Value, value);
@@ -489,28 +558,10 @@
"store" : SectionNameStore,
"help" : SectionNameHelp (),
],
- "image" : $[
- "widget" : `custom,
- "custom_widget" : Stage::initial ()
- ? `InputField (`id ("image"), `opt (`hstretch),
- // text entry
- grub_descriptions["image"]:"image")
- : `HBox (
- `ComboBox (`id ("image"), `opt (`editable, `hstretch),
- // combo box
- grub_descriptions["image"]:"image",
- []),
- `VBox (
- `Label (""),
- `PushButton (`id (`kernel_browse),
- Label::BrowseButton ())
- )
- ),
- "init" : KernelImageInit,
- "help" : grub_help_messages["image"]:"",
- "handle" : KernelImageHandle,
- "handle_events" : [ `kernel_browse ],
- ],
+ "image" : SectionInputFieldBrowseWidget(
+ grub_descriptions["image"]:"image",
+ grub_help_messages["image"]:"",
+ "image"),
"initrd" : $[
"widget" : `custom,
"custom_widget" : Stage::initial ()
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org