Using DialogFactory for Common UI Tasks: File Selection, Color Pickers & More
Modern desktop applications rely on a wide range of dialog interactions—file selection, confirmation prompts, color pickers, font selectors, and input forms. Implementing these dialogs from scratch can be time-consuming and repetitive.
SavvyUI simplifies this process through a powerful utility component called DialogFactory. This component centralizes the creation of common dialogs and ensures consistent behavior and styling across your application. Instead of manually building dialogs each time, developers can call a single function to display them instantly. :contentReference[oaicite:0]{index=0}
In this article, we’ll explore how to use DialogFactory to implement common desktop interactions such as:
- Alert and notification dialogs
- File open and save dialogs
- Folder selection dialogs
- Color and font pickers
- Printer selection and setup
- User input dialogs
What is DialogFactory?
DialogFactory is a helper utility that allows developers to generate frequently used dialog windows with minimal code. It encapsulates the logic for constructing dialogs, handling events, and returning user selections to the application.
This approach improves code reuse, reduces boilerplate code, and ensures UI consistency across the entire application. :contentReference[oaicite:1]{index=1}
Basic DialogFactory Setup
The following example demonstrates a demo panel that triggers multiple DialogFactory dialogs using buttons. Each button calls a different dialog method.
class DialogFactoryDemo : public FluidPanel, public ActionListener
{
Component* _parent;
Button _buttonError;
Button _buttonWarning;
Button _buttonInfo;
Button _buttonSuccess;
Button _buttonConfirm;
public:
DialogFactoryDemo()
{
_parent = NULL;
_buttonError.setButtonType(ButtonType::DANGER);
_buttonError.setText(L"showError");
_buttonError.addActionListener(this);
_buttonWarning.setButtonType(ButtonType::WARN);
_buttonWarning.setText(L"showWarning");
_buttonWarning.addActionListener(this);
_buttonInfo.setButtonType(ButtonType::INFO);
_buttonInfo.setText(L"showInfo");
_buttonInfo.addActionListener(this);
_buttonSuccess.setButtonType(ButtonType::SUCCESS);
_buttonSuccess.setText(L"showSuccess");
_buttonSuccess.addActionListener(this);
_buttonConfirm.setButtonType(ButtonType::GRAY);
_buttonConfirm.setText(L"showConfirmDialog");
_buttonConfirm.addActionListener(this);
}
};
Each button triggers a different dialog method inside the event handler.
Showing Alert Dialogs
DialogFactory includes built-in alert dialogs commonly used to display system messages or application feedback.
Available alert dialogs include:
- Error dialogs
- Warning dialogs
- Information dialogs
- Success notifications
- Confirmation dialogs
Example
DialogFactory::showError(parent, L"Operation failed", L"Error"); DialogFactory::showWarning(parent, L"Unsaved changes detected", L"Warning"); DialogFactory::showInfo(parent, L"Task completed successfully", L"Information"); DialogFactory::showSuccess(parent, L"Record saved", L"Success"); DialogFactory::showConfirmDialog(parent, L"Delete this item?", L"Confirm");
These dialogs help guide users through application workflows and provide immediate feedback for their actions.
File Selection Dialogs
File dialogs allow users to select files or specify save locations for documents. DialogFactory includes built-in methods for both opening and saving files.
Open File Dialog
wstring selection; DialogFactory::showOpenFileDialog(parent, selection);
Save File Dialog
wstring selection; DialogFactory::showSaveFileDialog(parent, selection);
After the dialog closes, the selected file path is stored in the selection
variable.
Folder Selection Dialog
Applications often require users to select directories rather than individual files. DialogFactory includes a dedicated folder selection dialog.
wstring folderPath; DialogFactory::showFolderSelectionDialog(parent, folderPath);
This is useful when users need to choose export folders, backup locations, or project directories.
Color Picker Dialog
Many desktop applications allow users to customize colors—for themes, charts, text formatting, and drawing tools. DialogFactory includes a built-in color selection dialog.
COLORREF selectedColor; DialogFactory::showColorSelectionDialog(parent, selectedColor);
The selected color value is returned to the application after the dialog closes.
Font Selection Dialog
Font selection dialogs are commonly used in editors and document applications. DialogFactory supports selecting fonts along with style attributes.
wstring fontName; long fontHeight; long fontWeight; BOOL isItalic; COLORREF selectedColor; DialogFactory::showFontSelectionDialog( parent, fontName, fontHeight, fontWeight, isItalic, selectedColor );
This allows applications to provide rich text customization features.
Printer Selection and Setup
For applications that generate reports or documents, printer configuration dialogs are essential. DialogFactory provides two built-in methods:
- Printer selection dialog
- Printer setup dialog
Printer Selection
DialogFactory::showPrinterSelectionDialog(parent);
Printer Setup
long leftMargin, topMargin, rightMargin, bottomMargin; DialogFactory::showPrinterSetupDialog( parent, leftMargin, topMargin, rightMargin, bottomMargin );
These dialogs help configure print settings directly from the application.
Input Dialogs
Input dialogs allow applications to gather structured data from users through simple forms.
Example
vectorvalues; DialogFactory::showInputDialog( parent, { L"Name:", L"Address", L"City", L"State", L"Zipcode" }, values );
Each field entered by the user is returned through the values array.
Best Practices for DialogFactory Usage
- Use dialogs only for important interactions.
- Provide clear and concise titles.
- Use confirmation dialogs for destructive actions.
- Keep input dialogs short and focused.
- Always validate user input after dialogs close.
Following these practices improves usability and keeps the user interface clean and intuitive.
Conclusion
DialogFactory dramatically simplifies the implementation of common UI interactions in Windows desktop applications. Instead of writing custom dialog code for every feature, developers can rely on prebuilt dialogs for alerts, file selection, color picking, printing, and user input.
This design reduces development time while maintaining a consistent user experience throughout the application.
To explore more components and examples, visit the official SavvyUI homepage.