Sunday, April 05, 2009

The company where I work uses discussion lists quite religiously, and I’m sure other companies do as well. A discussion list or group allows you to subscribe to emails about a particular subject, for instance ‘silverlight’. People can send email to the group and everyone that has subscribed will receive it.

The problem is that this can become chaotic pretty quickly. Of course, everyone will setup a rule in Outlook to move incoming mail from a group to a particular folder, but I’m interested in creating a workflow that will help me stay on top of all of those emails, all the time. That is hard, mainly because you will keep getting email from conversations that you do not care about. Some of these conversations take days to come to a conclusion, making you manually wade through all of that over and over again.

There are many systems devised to deal with email stress and organizing your life inside Outlook. One important system is GTD (Getting Things Done). I find that those do not directly apply to email received from discussion lists.

What is needed, is some way to kill a thread and not be bothered with it again. There are programs that will allow you to do that and I’ve played around with all of them.
However, none quite suited me, maybe because I don’t trust programs to delete email. There is one that is called ThreadKiller, which did not install for me. I believe it does the same as I’m describing here.

I am interested in the following workflow:

  1. email comes, either new threads or replies to old threads
  2. I will look at the new threads and decide if I’m interested in them or not
  3. Threads that I no longer want, should be moved to a folder
  4. When I have time to actually read whole conversations, of the threads that remain, I will first make sure that new replies to threads are removed

Basically it boils down to finding some way to easily find and delete mail that belongs to threads I don’t want any more. Easier said than done! I ended up having to drop to VB macros, which I really wanted to avoid.

Here is a description of my current setup.

Step 1: searchfolder to manage new threads

Each discussion list I am on will have a searchfolder that only shows me ‘new’ mail. You can create one by adding a search folder, and using the ‘advanced’ tab to setup these two criteria:

1. In Folder is (exactly) –the name of the folder that has the mail from the group -
2. Subject doesn’t contain RE:

Step 2: setup a delete staging folder

Create a folder called Delete staging. It will contain the start of threads that you are no longer interested in. Basically I will have a macro later on, that will look in this folder and remove all the mail that belong to the same subject.

Step 3: easily move new threads to the delete staging folder

I’m a keyboard junkie, and I want to easily move emails to that folder.
I dropped into the VB Macro editor and used this code:

Sub MoveToDeleteStaging()
    Dim objItem As Outlook.MailItem
    Set objItem = Application.ActiveExplorer.Selection.Item(1)
        Dim objNamespace As NameSpace
    Dim objInboxFolder As Outlook.MAPIFolder
        Set objNamespace = Application.GetNamespace("MAPI")
    Set objInboxFolder = objNamespace.GetDefaultFolder(olFolderInbox)
    Set deleteFolder = objInboxFolder.Folders("Delete staging")
    
    objItem.Move (deleteFolder)
End Sub

Even though I despise VB, this code is quite simple indeed. You can see that I hard coded the folder “Delete staging” in there.

Now, customize the toolbar to add this macro there. Rename it to something like ‘&Delete Thread’, using the ampersand to indicate the shortcut key.

When you select a mail item and you execute the macro, it will move the item to the delete staging folder.

Step 4: scrub your folder

The real work is to make sure that mail you receive gets deleted. The best way might be to create a rule to do that as the mail comes in. I don’t like that, because I get a kick out of seeing how much mail was removed. So for now I use a manual process. The code can be easily adjusted to run as a rule when new mail arrives.

So, being a VB newbie, I’ve written code that is vey inefficient but luckily very useful. The macro below will iterate through all the items in the delete staging folder and remove any mail it finds in the folder that you are scrubbing.

Sub DeleteMessagesThatAreInDeleteStagingFolder()
    Dim deleteFolder As Outlook.Folder
    Dim currentFolder As Outlook.Folder
    Dim runningItem As Outlook.MailItem
    Dim threadItems As Outlook.Items
    Dim itemToDelete As Outlook.MailItem
    Dim objNamespace As NameSpace
    Dim objInboxFolder As Outlook.MAPIFolder
    Dim Filter As String
        
    Set objNamespace = Application.GetNamespace("MAPI")
    Set objInboxFolder = objNamespace.GetDefaultFolder(olFolderInbox)
    Set deleteFolder = objInboxFolder.Folders("Delete staging")
        
    Set currentFolder = Application.ActiveExplorer.currentFolder
    
    For Each runningItem In deleteFolder.Items
        Filter = "@SQL=" & Chr(34) & _
            "urn:schemas:httpmail:thread-topic" & _
            Chr(34) & "= '" & Replace(runningItem.ConversationTopic, "'", "''") & "'"
        Set threadItems = currentFolder.Items.Restrict(Filter)
        For Each itemToDelete In threadItems
            itemToDelete.Delete
        Next
    Next
    
End Sub

The code uses a filter in the dsal language (some sort of SQL wannabe language used by Outlook) to filter the email in the folder so it can then delete it.

Again, I created a toolbar shortcut for it.

Usage:

Just go to your search folder and quickly triage all the mail that is there by either reading the mail or moving it to the delete staging folder. Then go to the actual folder and scrub it using the second macro. This will remove all the threads that you were not interested in, leaving you with threads to you do want to read!!

I hope that is useful to someone.

Sunday, April 05, 2009 12:45:09 AM (Romance Standard Time, UTC+01:00)  #    Comments [18]  |  Trackback
 Sunday, March 29, 2009

We continue our exploration of Accordion. This time we’ll take a look at some of the template parts, namely ExpandableContentControl. See part 1 and part 2 if you didn’t yet.

ExpandableContentControl

This control is part of AccordionItem and is used to display the content of an accordionItem. It sits in the Primitives namespace, which means it will be used primarily as a part of a template. It solves an important problem: being able to resize (expand/contract) a piece of content, without triggering resize actions on the content itself. With that I mean: if your AccordionItem would use a Grid or a DockPanel as it’s content and I would just be animating the width or the height, you would see the panel changing as it tries to keep up with the new sizes. Ofcourse, that would not be the case if you had set an explicit width or height to the panel, but AccordionItem does not force you to do so.So, during the resize of our AccordionItem, I don’t want the content to have to resize.

Furthermore, it would be nice to make it really easy for you to determine how the animation should look like. Do you want a gradual easein/out, a bump or something different altogether? I want to be able to design my animation in Blend, using the nifty keyspline features!

I accomplish the above goals by throwing in a ScrollViewer and defining a DependencyProperty: Percentage.

ScrollViewer allows Accordion to just determine the size the item will eventually be (after expand action) and set it only once. At that moment the content of the scrollviewer is going to resize itself accordingly. Then, as we animate the width or height of the scrollviewer, its content is none-the-wiser. Hence, no ugly resize actions going on.

Making the actual animation be easily defined inside of Blend, is done by the above-mentioned Percentage DP.
Accordion only determines the size the AccordionItem will eventually be, I call it the TargetSize. ExpandableContentControl will calculate and set its actual size using to the following simple function: actualsize = percentage * TargetSize.

Accordion also triggers a visualstate called either Expanded or Contracted on AccordionItem. Those animate the percentage property on ExpandableContentControl. See this Xaml in the template of AccordionItem:

   62 <vsm:VisualState x:Name="Collapsed">

   63     <Storyboard>

   64         <DoubleAnimationUsingKeyFrames

   65             BeginTime="00:00:00"

   66             Storyboard.TargetName="ExpandSite"

   67             Storyboard.TargetProperty="(ExpandableContentControl.Percentage)">

   68             <SplineDoubleKeyFrame

   69                 KeyTime="00:00:00.3"

   70                 KeySpline="0.2,0,0,1"

   71                 Value="0" />

   72         </DoubleAnimationUsingKeyFrames>

   73     </Storyboard>

   74 </vsm:VisualState>

   75 <vsm:VisualState x:Name="Expanded">

   76     <Storyboard>

   77         <DoubleAnimationUsingKeyFrames

   78             BeginTime="00:00:00"

   79             Storyboard.TargetName="ExpandSite"

   80             Storyboard.TargetProperty="(ExpandableContentControl.Percentage)">

   81             <SplineDoubleKeyFrame

   82                 KeyTime="00:00:00.3"

   83                 KeySpline="0.2,0,0,1"

   84                 Value="1" />

   85         </DoubleAnimationUsingKeyFrames>

   86     </Storyboard>

   87 </vsm:VisualState>

This makes it possible to design your animation at the correct level (AccordionItem) and makes it a very design friendly experience, because Blend allows you to edit keysplines as follows:

image

(SL3 is adding a nice collection of other spline types that makes elastic AccordionItems even easier!)

I’ll discuss the remaining points of interest.

RevealMode

Since I expose one property (Percentage) for you to animate, the control needs to know whether that responds to the vertical or horizontal direction. Thus, AccordionItem will set the correct RevealMode, corresponding to its own ExpandDirection.

TargetSize

Already mentioned, setting the TargetSize will set the size of the ScrollViewer. It will also recalculate the percentage. Let’s say I have an item that has a height of 100. Now another item is collapsed, so the Accordion decides the remaining items should have a height of 160. The percentage that was once at 1 is recalculated to be 0.625.
This way we don’t have to restart the full animation, but we can just resize nicely.


I hope that helps understanding this vital piece of the template. In the future, I will either remove it (if the outlined problems can be solved more gracefully in another way) or expose the style of ExpandableContentControl in AccordionItem, so it can be more easily styled.

Sunday, March 29, 2009 1:01:18 AM (Romance Standard Time, UTC+01:00)  #    Comments [63]  |  Trackback
 Saturday, March 28, 2009

Completely unrelated to anything on this site, I wanted to talk about IE8 for a minute. It looks like a great browser, but on my home machine, just spinning up a tab took about 3 seconds. When I noticed that other people did not have this problem, I started to investigate. These are the two tips that I’ve found:

The first is by Ed Bot and basically tells you to execute ‘regsvr32 actxprxy.dll’ from an elevated command prompt. That registers a dll that in certain configurations is not registered. It can make a huge difference.

The second on is the the one that saved me. I don’t know the source, but there are several blogs telling you to look at your restricted sites (Tools/InternetOptions/Security/Restricted Sites, press the button labeled ‘sites’ ).
I had used spybot long ago, which had added a huge list of sites there. Apparently this can really slow down outlook and ie!
Remove them by resetting your settings to default (Advanced tab, button labeled ‘reset’).

Now I have a blindingly fast internet explorer, and I must admit, I do love this browser now. Switching back!

Saturday, March 28, 2009 11:08:28 PM (Romance Standard Time, UTC+01:00)  #    Comments [29]  |  Trackback
 Thursday, March 26, 2009

I’m glad to see accordion getting the excitement that it’s getting. I’ve gotten great feedback, keep it coming!

Part 1 was concerned with Accordion itself, we will now focus on the individual parts of Accordion.

AccordionItem

AccordionItem is to Accordion as is ListboxItem to Listbox. Accordion will only work with AccordionItems, and that is why, if you feed Accordion an item that is not of type AccordionItem, it will wrap it inside of one.

AccordionItem has several important jobs:

  • It needs to display a header and content.
  • It needs to be able to ‘open’ and ‘close’
  • It needs to be able to work in several ExpandDirections (Left, Right, Top, Bottom)

AccordionItem mimicks Expander in many ways (although I changed the template considerably) but inherits from HeaderedContentControl. Therefore, it has two important properties it gains from HeaderedContentControl: HeaderTemplate and ContentTemplate.
These templates are used to allow you to customize the header and content.

I will use KeyValue pairs to easily create a few AccordionItems:

            acc.ItemsSource = new[]
                                  {
                                          new KeyValuePair<string, string>("A header", "And the content of the accordion item"),
                                          new KeyValuePair<string, string>("Hello", "World")
                                   };

Let’s take a look at an Accordion and it’s Xaml:

image

ExpandDirection

An AccordionItem has the same ExpandDirection property as Accordion. When contained within an Accordion, AccordionItem will get the correct ExpandDirection from Accordion and will not allow you to change it individually.

ExpandDirection may only be set by Accordion, to prevent from weird mixes of ExpandDirections. Unfortunately, that does limit a few scenario’s (as in horizontal Accordion layout with vertical AccordionItems). If this turns out to be a common featurerequest, I’ll look into opening this up.

Accordion.ItemContainerGenerator

Accordion exposes an ItemContainerGenerator which has very helpful methods, such as ‘ContainerFromItem’ and even ContainerFromIndex’. So it is really easy to go from AccordionItem, to Item and vice versa.
This code might make you happy:

            for (int i = 0; i < acc.Items.Count; i++)
            {
                AccordionItem item = acc.ItemContainerGenerator.ContainerFromIndex(i) as AccordionItem;
             }
Locking mechanism

In certain SelectionModes, Accordion must make sure that at least one item is selected. It does so by locking an item if it is the last one open. If you somehow force it to close (through code), Accordion will just open the first AccordionItem in the list. However, that is not that simple, since an AccordionItem may not be unselected, while it is locked.

Since AccordionItem will actually throw an exception when it is unselected while locked, I expose a boolean ‘IsLocked’ that you can use to make sure you don’t accidently do this.
I expose a VisualState that allows you to visualize the lock if you’d like.

The best way to unselect the AccordionItem while in such a mode, is to select a different item.

ExpandableContentControl and AccordionButton

These are two template parts on the AccordionItem. The first takes care of opening and closing in a nice fashion and the latter makes it easier to template the header. It is not necessary, but adds a nice touch. I will talk more about templating them in a follow up post.
In the meantime, it is noteworthy that there is a property AccordionButtonStyle that you can use to style the button more easily.

Selected and Unselected events

Subscribe to these events to know when the user has selected an AccordionItem. Alternatively, you can use the SelectionChanged event on Accordion.

Layout

Under the covers, there is a lot of layout action going on! The item needs to know how to open itself, and also needs to be told _when_ to do so. The actual opening and closing does not correspond to the IsSelected state. In other words: IsSelected will be set whenever an item is selected, which could mean the AccordionItem is still closed. Accordion will instruct AccordionItem to actually open to visualize the new IsSelected state.

Templating

The most important part of the template is:

  1           <Border x:Name="Background" 
  2 			      Padding="{TemplateBinding Padding}" 
  3 			      BorderBrush="{TemplateBinding BorderBrush}" 
  4 			      BorderThickness="{TemplateBinding BorderThickness}" 
  5 			      CornerRadius="1,1,1,1">
  6               <Grid>
  7                   <Grid.RowDefinitions>
  8                       <RowDefinition Height="Auto" x:Name="rd0"/>
  9                       <RowDefinition Height="Auto" x:Name="rd1"/>
 10                   </Grid.RowDefinitions>
 11                   <Grid.ColumnDefinitions>
 12                       <ColumnDefinition Width="Auto" x:Name="cd0"/>
 13                       <ColumnDefinition Width="Auto" x:Name="cd1"/>
 14                   </Grid.ColumnDefinitions>
 15 
 16                   <layoutPrimitivesToolkit:AccordionButton
 17 					          x:Name="ExpanderButton"
 18                     Style="{TemplateBinding AccordionButtonStyle}"
 19 					          Content="{TemplateBinding Header}"
 20 					          ContentTemplate="{TemplateBinding HeaderTemplate}"
 21 					          IsChecked="{TemplateBinding IsSelected}"
 22 					          IsTabStop="True"
 23 					          Grid.Row="0"
 24 					          Padding="0,0,0,0"
 25 					          Margin="0,0,0,0"
 26 					          FontFamily="{TemplateBinding FontFamily}"
 27 					          FontSize="{TemplateBinding FontSize}"
 28 					          FontStretch="{TemplateBinding FontStretch}"
 29 					          FontStyle="{TemplateBinding FontStyle}"
 30 					          FontWeight="{TemplateBinding FontWeight}"
 31 					          Foreground="{TemplateBinding Foreground}"
 32 					          VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" 
 33 					          HorizontalAlignment="Stretch"
 34 					          VerticalAlignment="Stretch" 
 35                     HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
 36                     Background="{TemplateBinding Background}" />
 37 
 38                   <layoutPrimitivesToolkit:ExpandableContentControl
 39 					          x:Name="ExpandSite"
 40 					          Grid.Row="1"
 41 					          IsTabStop="False"
 42 					          Percentage="0"
 43 					          RevealMode="{TemplateBinding ExpandDirection}"
 44 					          Content="{TemplateBinding Content}"
 45 					          ContentTemplate="{TemplateBinding ContentTemplate}"
 46 					          Margin="0,0,0,0"
 47 					          FontFamily="{TemplateBinding FontFamily}"
 48 					          FontSize="{TemplateBinding FontSize}"
 49 					          FontStretch="{TemplateBinding FontStretch}"
 50 					          FontStyle="{TemplateBinding FontStyle}"
 51 					          FontWeight="{TemplateBinding FontWeight}"
 52 					          Foreground="{TemplateBinding Foreground}"
 53 					          HorizontalContentAlignment="Left"
 54 					          VerticalContentAlignment="Top" 
 55 					          HorizontalAlignment="Stretch"
 56 					          VerticalAlignment="Stretch"/>
 57               </Grid>
58 </Border>

Lines 7 through 14 create a grid with 2 columns and 2 rows.
Line 16 shows the AccordionButton, which is the little arrow + header.The arrow always points to the content and is in different locations, depending on the ExpandDirection.
Line 38 is the ExpandableContentControl, which takes care of the content.

An AccordionItem has, amongst others, 4 visual states for ExpandDirection. I will show the ExpandLeft state:

  1                   <vsm:VisualState x:Name="ExpandLeft">
  2                       <Storyboard>
  3                           <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="ExpanderButton" Storyboard.TargetProperty="(Grid.ColumnSpan)">
  4                               <DiscreteObjectKeyFrame KeyTime="0" Value="1"/>
  5                           </ObjectAnimationUsingKeyFrames>
  6                           <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="ExpandSite" Storyboard.TargetProperty="(Grid.ColumnSpan)">
  7                               <DiscreteObjectKeyFrame KeyTime="0" Value="1"/>
  8                           </ObjectAnimationUsingKeyFrames>
  9                           <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="ExpanderButton" Storyboard.TargetProperty="(Grid.RowSpan)">
 10                               <DiscreteObjectKeyFrame KeyTime="0" Value="2"/>
 11                           </ObjectAnimationUsingKeyFrames>
 12                           <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="ExpandSite" Storyboard.TargetProperty="(Grid.RowSpan)">
 13                               <DiscreteObjectKeyFrame KeyTime="0" Value="2"/>
 14                           </ObjectAnimationUsingKeyFrames>
 15 
 16                           <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="ExpanderButton" Storyboard.TargetProperty="(Grid.Column)">
 17                               <DiscreteObjectKeyFrame KeyTime="0" Value="1"/>
 18                           </ObjectAnimationUsingKeyFrames>
 19                           <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="ExpandSite" Storyboard.TargetProperty="(Grid.Row)">
 20                               <DiscreteObjectKeyFrame KeyTime="0" Value="0"/>
 21                           </ObjectAnimationUsingKeyFrames>
 22                           <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="rd0" Storyboard.TargetProperty="Height">
 23                               <DiscreteObjectKeyFrame KeyTime="0" Value="*"/>
 24                           </ObjectAnimationUsingKeyFrames>
 25                           <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="cd0" Storyboard.TargetProperty="Width">
 26                               <DiscreteObjectKeyFrame KeyTime="0" Value="*"/>
 27                           </ObjectAnimationUsingKeyFrames>
 28                       </Storyboard>
29 </vsm:VisualState>

Everything in there is actually repositioning the AccordionButton (header) and the ExpandableContentControl (content) inside different grid cells.

In this case, you can imagine the header being in column 1 and the content taking up column 2.

You should not need to have to style an accordionItem itself that much. Most of the template is just about positioning the Header versus the Content. The only reason I see for restyling accordionItem is if you are unhappy with the defaults (easily changed) or with the position of the header and content. All the other styling would be done in either AccordionButton or ExpandableContentControl. Let me know if this is not the case for your scenario.

Thursday, March 26, 2009 6:05:36 AM (Romance Standard Time, UTC+01:00)  #    Comments [33]  |  Trackback