Subversion Repositories SoapBoxCore

Rev

Rev 8 | Rev 17 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8 scott 1
#region "SoapBox.Core License"
2
/// <header module="SoapBox.Core"> 
3
/// Copyright (C) 2009 SoapBox Automation Inc., All Rights Reserved.
4
/// Contact: SoapBox Automation Licencing (license@soapboxautomation.com)
5
/// 
6
/// This file is part of SoapBox Core.
7
/// 
8
/// Commercial Usage
9
/// Licensees holding valid SoapBox Automation Commercial licenses may use  
10
/// this file in accordance with the SoapBox Automation Commercial License
11
/// Agreement provided with the Software or, alternatively, in accordance 
12
/// with the terms contained in a written agreement between you and
13
/// SoapBox Automation Inc.
14
/// 
15
/// GNU Lesser General Public License Usage
16
/// SoapBox Core is free software: you can redistribute it and/or modify 
17
/// it under the terms of the GNU Lesser General Public License
18
/// as published by the Free Software Foundation, either version 3 of the
19
/// License, or (at your option) any later version.
20
/// 
21
/// SoapBox Core is distributed in the hope that it will be useful, 
22
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
23
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
/// GNU Lesser General Public License for more details.
25
/// 
26
/// You should have received a copy of the GNU Lesser General Public License 
27
/// along with SoapBox Core. If not, see <http://www.gnu.org/licenses/>.
28
/// </header>
29
#endregion
30
 
31
using System;
32
using System.Collections.Generic;
33
using System.Linq;
34
using System.Text;
35
using System.Windows;
36
using System.ComponentModel.Composition;
37
 
38
namespace SoapBox.Core.Options
39
{
40
    /// <summary>
41
    /// ViewModel for the Options Dialog
42
    /// Inheriting from AbstractOptionsItem is just a hack
43
    /// because it makes it easy to set the Items property.
44
    /// </summary>
12 scott 45
    [Export(CompositionPoints.Options.OptionsDialog, typeof(OptionsDialog))]
46
    class OptionsDialog : AbstractOptionsItem, IPartImportsSatisfiedNotification
8 scott 47
    {
12 scott 48
        public OptionsDialog()
8 scott 49
        {
50
            OptionChanged += new EventHandler(OptionsDialog_OptionChanged);
51
        }
52
 
53
        void OptionsDialog_OptionChanged(object sender, EventArgs e)
54
        {
55
            m_dirtyCondition.SetCondition(true);
56
        }
57
 
12 scott 58
        [Import(Services.Logging.LoggingService, typeof(ILoggingService))]
8 scott 59
        private ILoggingService logger { get; set; }
60
 
12 scott 61
        [Import(Services.Host.ExtensionService)]
62
        private IExtensionService extensionService { get; set; }
63
 
64
        [ImportMany(ExtensionPoints.Options.OptionsDialog.OptionsItems, typeof(IOptionsItem), AllowRecomposition=true)]
65
        private IEnumerable<IOptionsItem> items { get; set; }
66
 
67
        public void OnImportsSatisfied()
68
        {
69
            Items = extensionService.Sort(items);
70
        }
71
 
72
        [Import(CompositionPoints.Host.MainWindow)]
8 scott 73
        private Lazy<Window> mainWindowExport { get; set; }
74
 
75
        /// <summary>
76
        /// Displays the Options Dialog as modal
77
        /// </summary>
78
        public void ShowDialog()
79
        {
80
            Window mainWindow = mainWindowExport.Value;
81
            Window optionsDialog = new OptionsDialogView();
82
            optionsDialog.Owner = mainWindow;
83
            optionsDialog.DataContext = this;
84
            logger.Info("Showing options dialog...");
85
            m_dirtyCondition.SetCondition(false);
86
            optionsDialog.ShowDialog();
87
            ReloadSavedValues();
88
            logger.Info("Options dialog closed.");
89
        }
90
 
91
        private ICondition dirtyCondition
92
        {
93
            get
94
            {
95
                return m_dirtyCondition;
96
            }
97
        }
98
        private ConcreteCondition m_dirtyCondition = new ConcreteCondition(false);
99
 
100
        #region " OK Button "
101
        public IControl OKButton
102
        {
103
            get
104
            {
105
                if (m_OKButton == null)
106
                {
107
                    m_OKButton = new CommitChangesButton(this);
108
                }
109
                return m_OKButton;
110
            }
111
        }
112
        private IControl m_OKButton = null;
113
 
114
        private class CommitChangesButton : AbstractButton
115
        {
116
            public CommitChangesButton(OptionsDialog dlg)
117
            {
118
                m_OptionsDialog = dlg;
119
                EnableCondition = dlg.dirtyCondition;
120
            }
121
 
122
            private OptionsDialog m_OptionsDialog = null;
123
 
124
            protected override void Run()
125
            {
126
                foreach (IOptionsItem item in m_OptionsDialog.Items)
127
                {
128
                    item.CommitChanges();
129
                }
130
            }
131
        }
132
        #endregion
133
 
134
        #region " Cancel Button "
135
        public IControl CancelButton
136
        {
137
            get
138
            {
139
                if (m_CancelButton == null)
140
                {
141
                    m_CancelButton = new CancelChangesButton(this);
142
                }
143
                return m_CancelButton;
144
            }
145
        }
146
        private IControl m_CancelButton = null;
147
 
148
        private class CancelChangesButton : AbstractButton
149
        {
150
            public CancelChangesButton(OptionsDialog dlg)
151
            {
152
                m_OptionsDialog = dlg;
153
            }
154
 
155
            private OptionsDialog m_OptionsDialog = null;
156
 
157
            protected override void Run()
158
            {
159
                foreach (IOptionsItem item in m_OptionsDialog.Items)
160
                {
161
                    item.CancelChanges();
162
                }
163
            }
164
        }
165
        #endregion
166
 
167
        private void ReloadSavedValues()
168
        {
169
            foreach (IOptionsItem item in Items)
170
            {
171
                item.CancelChanges();
172
            }
173
        }
174
 
175
    }
176
}