Skip to content

Commit fdf11ca

Browse files
Add original source code downloaded from http://www.ookii.org/Software/Dialogs/
1 parent b644e93 commit fdf11ca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+9603
-0
lines changed

LICENSE

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
License agreement for Ookii.Dialogs.
2+
3+
Copyright (c) Sven Groot (Ookii.org) 2009
4+
All rights reserved.
5+
6+
7+
Redistribution and use in source and binary forms, with or without
8+
modification, are permitted provided that the following conditions are met:
9+
10+
1) Redistributions of source code must retain the above copyright notice,
11+
this list of conditions and the following disclaimer.
12+
2) Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
3) Neither the name of the ORGANIZATION nor the names of its contributors
16+
may be used to endorse or promote products derived from this software
17+
without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29+
THE POSSIBILITY OF SUCH DAMAGE.

src/Ookii.Dialogs.Wpf.Sample/App.xaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Application x:Class="Ookii.Dialogs.Wpf.Sample.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
StartupUri="MainWindow.xaml">
5+
<Application.Resources>
6+
7+
</Application.Resources>
8+
</Application>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Data;
5+
using System.Linq;
6+
using System.Windows;
7+
8+
namespace Ookii.Dialogs.Wpf.Sample
9+
{
10+
/// <summary>
11+
/// Interaction logic for App.xaml
12+
/// </summary>
13+
public partial class App : Application
14+
{
15+
}
16+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<Window x:Class="Ookii.Dialogs.Wpf.Sample.MainWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
Title="Ookii.Dialogs.Wpf sample" Height="79" Width="421" MinHeight="79" MinWidth="421" MaxHeight="79" Background="{x:Static SystemColors.ControlBrush}">
5+
<Grid>
6+
<Grid.ColumnDefinitions>
7+
<ColumnDefinition Width="Auto"/>
8+
<ColumnDefinition Width="*" />
9+
<ColumnDefinition Width="Auto" />
10+
</Grid.ColumnDefinitions>
11+
<Label Grid.Column="0" Margin="8,8,4,0" Name="_dialogLabel" VerticalAlignment="Top" HorizontalAlignment="Left">_Dialog:</Label>
12+
<ComboBox Grid.Column="1" SelectedIndex="0" Margin="4,8,4,0" Height="23" Name="_dialogComboBox" VerticalAlignment="Top">
13+
<ComboBox.Items>
14+
<ComboBoxItem>Task Dialog</ComboBoxItem>
15+
<ComboBoxItem>Task Dialog with command links</ComboBoxItem>
16+
<ComboBoxItem>Progress Dialog</ComboBoxItem>
17+
<ComboBoxItem>Credential Dialog</ComboBoxItem>
18+
<ComboBoxItem>Vista-style Folder Browser Dialog</ComboBoxItem>
19+
<ComboBoxItem>Vista-style Open File Dialog</ComboBoxItem>
20+
<ComboBoxItem>Vista-style Save File Dialog</ComboBoxItem>
21+
</ComboBox.Items>
22+
</ComboBox>
23+
<Button Grid.Column="2" Height="23" Margin="4,8,8,0" Padding="8,0" HorizontalAlignment="Right" Name="_showDialogButton" VerticalAlignment="Top" IsDefault="True" Click="_showDialogButton_Click">_Show dialog</Button>
24+
</Grid>
25+
</Window>
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Windows;
6+
using System.Windows.Controls;
7+
using System.Windows.Data;
8+
using System.Windows.Documents;
9+
using System.Windows.Input;
10+
using System.Windows.Media;
11+
using System.Windows.Media.Imaging;
12+
using System.Windows.Navigation;
13+
using System.Windows.Shapes;
14+
using System.Threading;
15+
using System.ComponentModel;
16+
17+
namespace Ookii.Dialogs.Wpf.Sample
18+
{
19+
/// <summary>
20+
/// Interaction logic for Window1.xaml
21+
/// </summary>
22+
public partial class MainWindow : Window
23+
{
24+
private ProgressDialog _sampleProgressDialog = new ProgressDialog()
25+
{
26+
WindowTitle = "Progress dialog sample",
27+
Text = "This is a sample progress dialog...",
28+
Description = "Processing...",
29+
ShowTimeRemaining = true,
30+
};
31+
32+
public MainWindow()
33+
{
34+
InitializeComponent();
35+
36+
_sampleProgressDialog.DoWork += new System.ComponentModel.DoWorkEventHandler(_sampleProgressDialog_DoWork);
37+
}
38+
39+
40+
private void _showDialogButton_Click(object sender, RoutedEventArgs e)
41+
{
42+
switch( _dialogComboBox.SelectedIndex )
43+
{
44+
case 0:
45+
ShowTaskDialog();
46+
break;
47+
case 1:
48+
ShowTaskDialogWithCommandLinks();
49+
break;
50+
case 2:
51+
ShowProgressDialog();
52+
break;
53+
case 3:
54+
ShowCredentialDialog();
55+
break;
56+
case 4:
57+
ShowFolderBrowserDialog();
58+
break;
59+
case 5:
60+
ShowOpenFileDialog();
61+
break;
62+
case 6:
63+
ShowSaveFileDialog();
64+
break;
65+
}
66+
}
67+
68+
private void ShowTaskDialog()
69+
{
70+
if( TaskDialog.OSSupportsTaskDialogs )
71+
{
72+
using( TaskDialog dialog = new TaskDialog() )
73+
{
74+
dialog.WindowTitle = "Task dialog sample";
75+
dialog.MainInstruction = "This is an example task dialog.";
76+
dialog.Content = "Task dialogs are a more flexible type of message box. Among other things, task dialogs support custom buttons, command links, scroll bars, expandable sections, radio buttons, a check box (useful for e.g. \"don't show this again\"), custom icons, and a footer. Some of those things are demonstrated here.";
77+
dialog.ExpandedInformation = "Ookii.org's Task Dialog doesn't just provide a wrapper for the native Task Dialog API; it is designed to provide a programming interface that is natural to .Net developers.";
78+
dialog.Footer = "Task Dialogs support footers and can even include <a href=\"http://www.ookii.org\">hyperlinks</a>.";
79+
dialog.FooterIcon = TaskDialogIcon.Information;
80+
dialog.EnableHyperlinks = true;
81+
TaskDialogButton customButton = new TaskDialogButton("A custom button");
82+
TaskDialogButton okButton = new TaskDialogButton(ButtonType.Ok);
83+
TaskDialogButton cancelButton = new TaskDialogButton(ButtonType.Cancel);
84+
dialog.Buttons.Add(customButton);
85+
dialog.Buttons.Add(okButton);
86+
dialog.Buttons.Add(cancelButton);
87+
dialog.HyperlinkClicked += new EventHandler<HyperlinkClickedEventArgs>(TaskDialog_HyperLinkClicked);
88+
TaskDialogButton button = dialog.ShowDialog(this);
89+
if( button == customButton )
90+
MessageBox.Show(this, "You clicked the custom button", "Task Dialog Sample");
91+
else if( button == okButton )
92+
MessageBox.Show(this, "You clicked the OK button.", "Task Dialog Sample");
93+
}
94+
}
95+
else
96+
{
97+
MessageBox.Show(this, "This operating system does not support task dialogs.", "Task Dialog Sample");
98+
}
99+
}
100+
101+
private void ShowTaskDialogWithCommandLinks()
102+
{
103+
if( TaskDialog.OSSupportsTaskDialogs )
104+
{
105+
using( TaskDialog dialog = new TaskDialog() )
106+
{
107+
dialog.WindowTitle = "Task dialog sample";
108+
dialog.MainInstruction = "This is a sample task dialog with command links.";
109+
dialog.Content = "Besides regular buttons, task dialogs also support command links. Only custom buttons are shown as command links; standard buttons remain regular buttons.";
110+
dialog.ButtonStyle = TaskDialogButtonStyle.CommandLinks;
111+
TaskDialogButton elevatedButton = new TaskDialogButton("An action requiring elevation");
112+
elevatedButton.CommandLinkNote = "Both regular buttons and command links can show the shield icon to indicate that the action they perform requires elevation. It is up to the application to actually perform the elevation.";
113+
elevatedButton.ElevationRequired = true;
114+
TaskDialogButton otherButton = new TaskDialogButton("Some other action");
115+
TaskDialogButton cancelButton = new TaskDialogButton(ButtonType.Cancel);
116+
dialog.Buttons.Add(elevatedButton);
117+
dialog.Buttons.Add(otherButton);
118+
dialog.Buttons.Add(cancelButton);
119+
dialog.ShowDialog(this);
120+
}
121+
}
122+
else
123+
{
124+
MessageBox.Show(this, "This operating system does not support task dialogs.", "Task Dialog Sample");
125+
}
126+
}
127+
128+
private void ShowProgressDialog()
129+
{
130+
if( _sampleProgressDialog.IsBusy )
131+
MessageBox.Show(this, "The progress dialog is already displayed.", "Progress dialog sample");
132+
else
133+
_sampleProgressDialog.Show(); // Show a modeless dialog; this is the recommended mode of operation for a progress dialog.
134+
}
135+
136+
private void ShowCredentialDialog()
137+
{
138+
using( CredentialDialog dialog = new CredentialDialog() )
139+
{
140+
// The window title will not be used on Vista and later; there the title will always be "Windows Security".
141+
dialog.WindowTitle = "Credential dialog sample";
142+
dialog.MainInstruction = "Please enter your username and password.";
143+
dialog.Content = "Since this is a sample the credentials won't be used for anything, so you can enter anything you like.";
144+
dialog.ShowSaveCheckBox = true;
145+
dialog.ShowUIForSavedCredentials = true;
146+
// The target is the key under which the credentials will be stored.
147+
// It is recommended to set the target to something following the "Company_Application_Server" pattern.
148+
// Targets are per user, not per application, so using such a pattern will ensure uniqueness.
149+
dialog.Target = "Ookii_DialogsWpfSample_www.example.com";
150+
if( dialog.ShowDialog(this) )
151+
{
152+
MessageBox.Show(this, string.Format("You entered the following information:\nUser name: {0}\nPassword: {1}", dialog.Credentials.UserName, dialog.Credentials.Password), "Credential dialog sample");
153+
// Normally, you should verify if the credentials are correct before calling ConfirmCredentials.
154+
// ConfirmCredentials will save the credentials if and only if the user checked the save checkbox.
155+
dialog.ConfirmCredentials(true);
156+
}
157+
}
158+
}
159+
160+
private void ShowFolderBrowserDialog()
161+
{
162+
VistaFolderBrowserDialog dialog = new VistaFolderBrowserDialog();
163+
dialog.Description = "Please select a folder.";
164+
dialog.UseDescriptionForTitle = true; // This applies to the Vista style dialog only, not the old dialog.
165+
if( !VistaFolderBrowserDialog.IsVistaFolderDialogSupported )
166+
MessageBox.Show(this, "Because you are not using Windows Vista or later, the regular folder browser dialog will be used. Please use Windows Vista to see the new dialog.", "Sample folder browser dialog");
167+
if( (bool)dialog.ShowDialog(this) )
168+
MessageBox.Show(this, "The selected folder was: " + dialog.SelectedPath, "Sample folder browser dialog");
169+
}
170+
171+
private void ShowOpenFileDialog()
172+
{
173+
// As of .Net 3.5 SP1, WPF's Microsoft.Win32.OpenFileDialog class still uses the old style
174+
VistaOpenFileDialog dialog = new VistaOpenFileDialog();
175+
dialog.Filter = "All files (*.*)|*.*";
176+
if( !VistaFileDialog.IsVistaFileDialogSupported )
177+
MessageBox.Show(this, "Because you are not using Windows Vista or later, the regular open file dialog will be used. Please use Windows Vista to see the new dialog.", "Sample open file dialog");
178+
if( (bool)dialog.ShowDialog(this) )
179+
MessageBox.Show(this, "The selected file was: " + dialog.FileName, "Sample open file dialog");
180+
}
181+
182+
private void ShowSaveFileDialog()
183+
{
184+
VistaSaveFileDialog dialog = new VistaSaveFileDialog();
185+
dialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
186+
dialog.DefaultExt = "txt";
187+
// As of .Net 3.5 SP1, WPF's Microsoft.Win32.SaveFileDialog class still uses the old style
188+
if( !VistaFileDialog.IsVistaFileDialogSupported )
189+
MessageBox.Show(this, "Because you are not using Windows Vista or later, the regular save file dialog will be used. Please use Windows Vista to see the new dialog.", "Sample save file dialog");
190+
if( (bool)dialog.ShowDialog(this) )
191+
MessageBox.Show(this, "The selected file was: " + dialog.FileName, "Sample save file dialog");
192+
}
193+
194+
private void TaskDialog_HyperLinkClicked(object sender, HyperlinkClickedEventArgs e)
195+
{
196+
System.Diagnostics.Process.Start(e.Href);
197+
}
198+
199+
private void _sampleProgressDialog_DoWork(object sender, DoWorkEventArgs e)
200+
{
201+
// Implement the operation that the progress bar is showing progress of here, same as you would do with a background worker.
202+
for( int x = 0; x <= 100; ++x )
203+
{
204+
Thread.Sleep(500);
205+
// Periodically check CancellationPending and abort the operation if required.
206+
if( _sampleProgressDialog.CancellationPending )
207+
return;
208+
// ReportProgress can also modify the main text and description; pass null to leave them unchanged.
209+
// If _sampleProgressDialog.ShowTimeRemaining is set to true, the time will automatically be calculated based on
210+
// the frequency of the calls to ReportProgress.
211+
_sampleProgressDialog.ReportProgress(x, null, string.Format(System.Globalization.CultureInfo.CurrentCulture, "Processing: {0}%", x));
212+
}
213+
}
214+
}
215+
}

0 commit comments

Comments
 (0)