Add help window, adjust window sizes, add error handling for when Transit is down master
authorunknown <chip@.(none)>
Mon, 7 Dec 2009 22:16:59 +0000 (16:16 -0600)
committerunknown <chip@.(none)>
Mon, 7 Dec 2009 22:16:59 +0000 (16:16 -0600)
SnapShooter/HelpWindow.xaml [new file with mode: 0644]
SnapShooter/HelpWindow.xaml.cs [new file with mode: 0644]
SnapShooter/MainWindow.xaml
SnapShooter/MainWindow.xaml.cs
SnapShooter/SnapShooter.csproj

diff --git a/SnapShooter/HelpWindow.xaml b/SnapShooter/HelpWindow.xaml
new file mode 100644 (file)
index 0000000..27793ef
--- /dev/null
@@ -0,0 +1,45 @@
+<Window x:Class="SnapShooter.HelpWindow"
+    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+    Title="Help" Height="320" Width="460">
+    <Grid>
+        <Button HorizontalAlignment="Right" Margin="0,0,12,12" Name="button1" VerticalAlignment="Bottom" Width="75" Height="30" Click="button1_Click">OK</Button>
+        <FlowDocumentScrollViewer Margin="12,12,12,48" Name="textBlock1">
+            <FlowDocument FontSize="10pt" FontFamily="sans-serif">
+                <Paragraph FontSize="12pt" FontWeight="Bold" Margin="0">Operation</Paragraph>
+                <Paragraph Margin="0,6pt,0,10pt">
+                    SnapShooter automatically grabs images off of the clipboard and uploads them
+                    for easy sharing with friends.
+                </Paragraph>
+                <Paragraph>
+                    While the "enable" box is checked, SnapShooter will check periodically
+                    for image data on the clipboard. When SnapShooter finds image data, it
+                    converts it to JPEG, then uploads it to
+                    <Hyperlink Click="TransitLink_Click">Transit</Hyperlink>. After uploading,
+                    SnapShooter copies the Transit URL to the clipboard so that you can immediately
+                    paste the result into a conversation, blog, or other communication.
+                </Paragraph>
+                <Paragraph>
+                    A log is kept in the SnapShooter window of recent uploads.  Each
+                    item shows a timestamp, a handy link to the Transit URL, and a button
+                    to copy the Transit URL to the clipboard.
+                </Paragraph>
+                <Paragraph FontSize="12pt" FontWeight="Bold" Margin="0">Notes</Paragraph>
+                <List>
+                    <ListItem>
+                        <Paragraph>
+                            Be careful &#8211; while enabled, SnapShooter will upload and then destroy
+                            any image data on the clipboard. Other kinds of data will not be affected.
+                        </Paragraph>
+                    </ListItem>
+                    <ListItem>
+                        <Paragraph>
+                            SnapShooter does not (yet) save the output list on exit. Save any links
+                            you want to keep before you exit the program.
+                        </Paragraph>
+                    </ListItem>
+                </List>
+            </FlowDocument>
+        </FlowDocumentScrollViewer>
+    </Grid>
+</Window>
diff --git a/SnapShooter/HelpWindow.xaml.cs b/SnapShooter/HelpWindow.xaml.cs
new file mode 100644 (file)
index 0000000..3d3183d
--- /dev/null
@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
+
+namespace SnapShooter {
+    /// <summary>
+    /// Interaction logic for HelpWindow.xaml
+    /// </summary>
+    public partial class HelpWindow : Window {
+        public HelpWindow() {
+            InitializeComponent();
+        }
+
+        private void button1_Click(object sender, RoutedEventArgs e) {
+            Close();
+        }
+
+        private void TransitLink_Click(object sender, RoutedEventArgs e) {
+            System.Diagnostics.Process.Start("http://dominionofawesome.com/transit/");
+        }
+    }
+}
index da80cf1..96f4fee 100644 (file)
@@ -1,7 +1,7 @@
 <Window x:Class="SnapShooter.MainWindow"
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-    Title="SnapShooter" Height="300" Width="600"
+    Title="SnapShooter" Height="300" Width="350"
     Loaded="Window_Loaded">
     <Grid>
         <Grid.RowDefinitions>
@@ -11,7 +11,7 @@
         <StackPanel Name="Menu" HorizontalAlignment="Right" Orientation="Horizontal">
             <CheckBox Margin="4" Name="Enabled" Checked="Enabled_Checked" Unchecked="Enabled_Unchecked" IsChecked="True">Enabled</CheckBox>
             <TextBlock Margin="4">
-                <Hyperlink>Help</Hyperlink>
+                <Hyperlink Click="Help_Click">Help</Hyperlink>
             </TextBlock>
         </StackPanel>
         <ListBox Name="SnapShots" Grid.Row="1" HorizontalContentAlignment="Stretch" />
index ea5aca5..45d8d83 100644 (file)
@@ -2,7 +2,9 @@
 using System.IO;
 using System.Collections.Generic;
 using System.Linq;
+using System.Net;
 using System.Text;
+using System.Net;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Data;
@@ -28,7 +30,7 @@ namespace SnapShooter {
         public MainWindow() {
             InitializeComponent();
             dt = new DispatcherTimer();
-            foundstuff = new StockIcon(StockIconIdentifier.ImageFiles, StockIconSizes.ShellSize, false, false);
+            foundstuff = new StockIcon(StockIconIdentifier.Info, StockIconSizes.ShellSize, false, false);
         }
 
         private void Window_Loaded(object sender, RoutedEventArgs e) {
@@ -46,8 +48,12 @@ namespace SnapShooter {
                     "SnapShoot.jpg"
                 );
 
+                Action localCleanup = new Action(delegate {
+                    File.Delete(filename);
+                    TaskbarManager.Instance.SetOverlayIcon(null, "");
+                });
+
                 BitmapSource b = Clipboard.GetImage();
-                System.Console.WriteLine(b.GetHashCode());
                 FileStream s = new FileStream(filename, FileMode.Create);
                 JpegBitmapEncoder j = new JpegBitmapEncoder();
                 j.QualityLevel = 85;
@@ -56,22 +62,27 @@ namespace SnapShooter {
                 s.Close();
 
                 Transit t = new Transit();
-                t.Create();
+                try {
+                    t.Create();
+                } catch (WebException we) {
+                    MessageBox.Show("Could not connect to Transit: " + we.Message + "\nThe Clipboard has been cleared.", "FFFFFFFUUUUUUUUUUUUUU-");
+                    Clipboard.Clear();
+                    localCleanup();
+                    return;
+                }
+
                 t.TransferProgress += delegate(object sender2, TransferProgressArgs tpe) {
                     TaskbarManager.Instance.SetProgressValue((int)tpe.PercentComplete, 100);
                 };
                 t.TransferComplete += delegate {
                     TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.NoProgress);
                     Dispatcher.Invoke(new Action(delegate {
-                        File.Delete(filename);
-
                         Clipboard.SetText(t.Url);
+                        localCleanup();
 
                         SnapShotItem i = new SnapShotItem();
                         i.TransitURL = t.Url;
                         SnapShots.Items.Add(i);
-
-                        TaskbarManager.Instance.SetOverlayIcon(null, "");
                     }), null);
                 };
                 t.UploadAsync(filename);
@@ -83,15 +94,18 @@ namespace SnapShooter {
         private void Enabled_Checked(object sender, RoutedEventArgs e) {
             if (dt == null) return;
 
-            System.Console.WriteLine("Enabled");
             dt.Start();
         }
 
         private void Enabled_Unchecked(object sender, RoutedEventArgs e) {
             if (dt == null) return;
 
-            System.Console.WriteLine("Disabled");
             dt.Stop();
         }
+
+        private void Help_Click(object sender, RoutedEventArgs e) {
+            HelpWindow helpWindow = new HelpWindow();
+            helpWindow.ShowDialog();
+        }
     }
 }
index 790474b..2cffca2 100644 (file)
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </ApplicationDefinition>
+    <Page Include="HelpWindow.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="MainWindow.xaml">
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
@@ -88,6 +92,9 @@
     </Compile>
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="HelpWindow.xaml.cs">
+      <DependentUpon>HelpWindow.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Properties\AssemblyInfo.cs">
       <SubType>Code</SubType>
     </Compile>