-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOutlookFolder.xaml.cs
136 lines (122 loc) · 4.88 KB
/
OutlookFolder.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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;
using Outlook = Microsoft.Office.Interop.Outlook;
namespace Worksly
{
/// <summary>
/// Interaction logic for OutlookFolder.xaml
/// </summary>
public partial class OutlookFolder : Window
{
public static RoutedCommand taskSubmit = new RoutedCommand();
public static RoutedCommand closeApp = new RoutedCommand();
public OutlookFolder(int type) // 1=tasks, 2=follow up, 3=feedback
{
InitializeComponent();
CreateFolderGrid();
CommandBinding cb = new CommandBinding(taskSubmit, SubmitExecuted, SubmitCanExecute);
this.CommandBindings.Add(cb);
CommandBinding cb1 = new CommandBinding(closeApp, CloseExecuted, CloseCanExecute);
this.CommandBindings.Add(cb1);
submitButton.Command = taskSubmit;
submitButton.CommandParameter = type;
CloseButton.Command = closeApp;
KeyGesture kg = new KeyGesture(Key.Enter);
InputBinding ib = new InputBinding(taskSubmit, kg);
this.InputBindings.Add(ib);
KeyGesture kg1 = new KeyGesture(Key.Escape);
InputBinding ib1 = new InputBinding(closeApp, kg1);
this.InputBindings.Add(ib1);
foldersListBox.SelectedIndex = 0;
}
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.DragMove();
}
private void CreateFolderGrid()
{
Outlook.ApplicationClass oApp = new Outlook.ApplicationClass();
Outlook.MAPIFolder oDefaultTaskFolder = oApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks);
if (oDefaultTaskFolder != null)
{
List<FolderListing> folderList = new List<FolderListing>();
FolderListing folder;
int cnt = 0;
folder = new FolderListing(oDefaultTaskFolder.Name, "/Icons/lineArrow-White.png", oDefaultTaskFolder.FolderPath);
folderList.Add(folder);
foreach (Outlook.MAPIFolder subfolder in oDefaultTaskFolder.Folders)
{
cnt ++;
if (cnt == oDefaultTaskFolder.Folders.Count)
{
folder = new FolderListing(subfolder.Name, "/Icons/endArrow-White.png", subfolder.FolderPath);
}
else
{
folder = new FolderListing(subfolder.Name, "/Icons/lineArrow-White.png", subfolder.FolderPath);
}
folderList.Add(folder);
}
foldersListBox.ItemsSource = folderList;
}
}
private void SubmitCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = (foldersListBox.SelectedItem != null);
}
private void SubmitExecuted(object sender, ExecutedRoutedEventArgs e)
{
FolderListing selFolder = (FolderListing)foldersListBox.SelectedItem;
string selString = selFolder.FolderPath;
#if DEBUG
Console.WriteLine(selString);
#endif
submitButton.Style = (Style)Application.Current.Resources["submitBtnPressed"];
switch (e.Parameter) // 1=tasks, 2=follow up, 3=feedback
{
case 2: Settings1.Default.fuFolder = selString; break;
case 3: Settings1.Default.feedbackFolder = selString; break;
default: Settings1.Default.tasksFolder = selString; break;
}
Settings1.Default.Save();
submitButton.Style = (Style)Application.Current.Resources["submitBtn"];
e.Handled = true;
Close();
}
private void CloseCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
}
private void CloseExecuted(object sender, ExecutedRoutedEventArgs e)
{
e.Handled = true;
this.Close();
}
private void foldersListBox_Selected(object sender, RoutedEventArgs e)
{
submitButton.Focus();
}
}
class FolderListing
{
public string FolderName { get; set; }
public string IconName { get; set; }
public string FolderPath { get; set; }
public FolderListing(string folderName, string iconName, string folderPath)
{
FolderName = folderName; IconName = iconName; FolderPath = folderPath;
}
}
}