Subversion Repositories SoapBoxCore

Rev

Rev 7 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7 Rev 17
Line 1... Line 1...
1
//Copyright (c) 2007-2009, Adolfo Marinucci
1
//Copyright (c) 2007-2010, Adolfo Marinucci
2
//All rights reserved.
2
//All rights reserved.
3
 
3
 
4
//Redistribution and use in source and binary forms, with or without modification, 
4
//Redistribution and use in source and binary forms, with or without modification, 
5
//are permitted provided that the following conditions are met:
5
//are permitted provided that the following conditions are met:
6
//
6
//
Line 50... Line 50...
50
    public class DocumentContent : ManagedContent
50
    public class DocumentContent : ManagedContent
51
    {
51
    {
52
 
52
 
53
        static DocumentContent()
53
        static DocumentContent()
54
        {
54
        {
55
            //DefaultStyleKeyProperty.OverrideMetadata(typeof(DocumentContent), new FrameworkPropertyMetadata(typeof(DocumentContent)));
55
            DefaultStyleKeyProperty.OverrideMetadata(typeof(DocumentContent), new FrameworkPropertyMetadata(typeof(DocumentContent)));
56
 
56
 
57
            //Control.WidthProperty.OverrideMetadata(typeof(DocumentContent),
57
            //Control.WidthProperty.OverrideMetadata(typeof(DocumentContent),
58
            //    new FrameworkPropertyMetadata(new PropertyChangedCallback(OnSizePropertyChanged), new CoerceValueCallback(CourceSizeToNaN)));
58
            //    new FrameworkPropertyMetadata(new PropertyChangedCallback(OnSizePropertyChanged), new CoerceValueCallback(CourceSizeToNaN)));
59
            //Control.HeightProperty.OverrideMetadata(typeof(DocumentContent),
59
            //Control.HeightProperty.OverrideMetadata(typeof(DocumentContent),
60
            //    new FrameworkPropertyMetadata(new PropertyChangedCallback(OnSizePropertyChanged), new CoerceValueCallback(CourceSizeToNaN)));
60
            //    new FrameworkPropertyMetadata(new PropertyChangedCallback(OnSizePropertyChanged), new CoerceValueCallback(CourceSizeToNaN)));
61
        }
61
        }
62
 
62
 
63
        public DocumentContent()
63
        public DocumentContent()
64
        {
64
        {
65
            base.PropertyChanged += new PropertyChangedEventHandler(DocumentContent_PropertyChanged);
65
            //base.PropertyChanged += new PropertyChangedEventHandler(DocumentContent_PropertyChanged);
66
        }
66
        }
67
 
67
 
-
 
68
        protected override void OnContentLoaded()
-
 
69
        {
-
 
70
            //now the logical tree is up
-
 
71
            DockingManager manager = GetParentManager(null);
68
 
72
 
-
 
73
            //if can't find the manager there is a problem
-
 
74
            //if (manager == null)
-
 
75
            //    throw new InvalidOperationException(string.Format(
-
 
76
            //        "Unable to find DockingManager object in the logical tree of document '{0}'", Title));
69
 
77
 
70
        DateTime _lastActivation = DateTime.MinValue;
78
            //manager.Documents.Add(this);
71
 
79
 
72
        internal DateTime LastActivation
-
 
73
        {
-
 
74
            get { return _lastActivation; }
80
            base.OnContentLoaded();
75
        }
81
        }
76
 
82
 
77
        void DocumentContent_PropertyChanged(object sender, PropertyChangedEventArgs e)
83
        protected override void OnContentUnloaded()
78
        {
84
        {
79
            if (e.PropertyName == "IsActiveContent")
85
            //if (Manager != null)
80
            {
-
 
81
                if (IsActiveContent)
86
            //    Manager.Documents.Remove(this);
-
 
87
 
82
                    _lastActivation = DateTime.Now;
88
            base.OnContentUnloaded();
83
            }
-
 
84
        }
89
        }
85
 
90
 
86
        static void OnSizePropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
-
 
87
        { }
91
        #region InfoTip
88
 
92
 
89
        static object CourceSizeToNaN(DependencyObject sender, object value)
-
 
90
        {
93
        /// <summary>
91
            //return double.NaN;
94
        /// InfoTip Dependency Property
92
            return value;
95
        /// </summary>
-
 
96
        public static readonly DependencyProperty InfoTipProperty =
-
 
97
            DependencyProperty.Register("InfoTip", typeof(string), typeof(DocumentContent),
93
        }
98
                new FrameworkPropertyMetadata(null));
94
 
99
 
95
        string _infoTip;
-
 
96
       
-
 
97
        /// <summary>
100
        /// <summary>
-
 
101
        /// Gets or sets the InfoTip property.  This dependency property 
98
        /// Gets or sets the information text attached to the document content.
102
        /// indicates information text attached to the document content.
99
        /// </summary>
103
        /// </summary>
100
        /// <remarks>This text is usually displayed when users switch between documents and helps them to choose the right one.</remarks>
104
        /// <remarks>This text is usually displayed when users switch between documents and helps them to choose the right one.</remarks>
101
        public string InfoTip
105
        public string InfoTip
102
        {
106
        {
103
            get { return _infoTip; }
107
            get { return (string)GetValue(InfoTipProperty); }
104
            set
-
 
105
            {
-
 
106
                _infoTip = value;
108
            set { SetValue(InfoTipProperty, value); }
107
                NotifyPropertyChanged("InfoTip");
-
 
108
            }
-
 
109
        }
109
        }
110
 
110
 
-
 
111
        #endregion
-
 
112
 
111
        string _contentTypeDescription;
113
        #region ContentTypeDescription
112
 
114
 
113
        /// <summary>
115
        /// <summary>
-
 
116
        /// ContentTypeDescription Dependency Property
-
 
117
        /// </summary>
-
 
118
        public static readonly DependencyProperty ContentTypeDescriptionProperty =
-
 
119
            DependencyProperty.Register("ContentTypeDescription", typeof(string), typeof(DocumentContent),
-
 
120
                new FrameworkPropertyMetadata((string)string.Empty));
-
 
121
 
-
 
122
        /// <summary>
-
 
123
        /// Gets or sets the ContentTypeDescription property.  This dependency property 
114
        /// Gets or sets a text which describes the type of content contained in this document.
124
        /// indicates a text which describes the type of content contained in this document.
115
        /// </summary>
125
        /// </summary>
116
        public string ContentTypeDescription
126
        public string ContentTypeDescription
117
        {
127
        {
118
            get { return _contentTypeDescription; }
128
            get { return (string)GetValue(ContentTypeDescriptionProperty); }
119
            set
-
 
120
            {
-
 
121
                _contentTypeDescription = value;
129
            set { SetValue(ContentTypeDescriptionProperty, value); }
122
                NotifyPropertyChanged("ContentTypeDescription");
-
 
123
            }
-
 
124
        }
130
        }
125
 
131
 
126
        bool _isFloatingAllowed;
132
        #endregion
127
 
133
 
128
        /// <summary>
134
        /// <summary>
129
        /// Gets or sets a value indicating if this document can float over main window (VS2010 Feature).
135
        /// Gets or sets a value indicating if this document can float over main window (VS2010 Feature).
130
        /// </summary>
136
        /// </summary>
131
        public bool IsFloatingAllowed
137
        public bool IsFloatingAllowed
132
        {
138
        {
133
            get { return _isFloatingAllowed; }
139
            get { return (bool)GetValue(IsFloatingAllowedProperty); }
134
            set
-
 
135
            {
-
 
136
                _isFloatingAllowed = value;
140
            set { SetValue(IsFloatingAllowedProperty, value); }
137
                NotifyPropertyChanged("IsFloatingAllowed");
-
 
138
            }
-
 
139
        }
141
        }
140
 
142
 
-
 
143
        // Using a DependencyProperty as the backing store for IsFloatingAllowed.  This enables animation, styling, binding, etc...
-
 
144
        public static readonly DependencyProperty IsFloatingAllowedProperty =
-
 
145
            DependencyProperty.Register("IsFloatingAllowed", typeof(bool), typeof(DocumentContent), new PropertyMetadata(true));
-
 
146
 
-
 
147
 
-
 
148
        #region IsFloating
-
 
149
 
-
 
150
        /// <summary>
-
 
151
        /// IsFloating Read-Only Dependency Property
-
 
152
        /// </summary>
141
        protected override void OnDragStart(Point ptMouse, Point ptRelativeMouse)
153
        private static readonly DependencyPropertyKey IsFloatingPropertyKey
-
 
154
            = DependencyProperty.RegisterReadOnly("IsFloating", typeof(bool), typeof(DocumentContent),
-
 
155
                new FrameworkPropertyMetadata((bool)false));
-
 
156
 
-
 
157
        public static readonly DependencyProperty IsFloatingProperty
-
 
158
            = IsFloatingPropertyKey.DependencyProperty;
-
 
159
 
-
 
160
        /// <summary>
-
 
161
        /// Gets the IsFloating property.  This dependency property 
-
 
162
        /// indicates if the DocumentContent is floating inside an external window.
-
 
163
        /// </summary>
-
 
164
        public bool IsFloating
142
        {
165
        {
143
            //Manager.Drag(this, this.PointToScreenDPI(ptMouse), ptRelativeMouse);
166
            get { return (bool)GetValue(IsFloatingProperty); }
144
            Manager.Drag(this, HelperFunc.PointToScreenWithoutFlowDirection(this, ptMouse), ptRelativeMouse);                
-
 
-
 
167
        }
145
 
168
 
-
 
169
        /// <summary>
-
 
170
        /// Provides a secure method for setting the IsFloating property.  
-
 
171
        /// This dependency property indicates if the DocumentContent is floating inside an external window.
-
 
172
        /// </summary>
-
 
173
        /// <param name="value">The new value for the property.</param>
-
 
174
        internal void SetIsFloating(bool value)
-
 
175
        {
-
 
176
            SetValue(IsFloatingPropertyKey, value);
-
 
177
        }
-
 
178
 
-
 
179
        #endregion
-
 
180
 
-
 
181
 
-
 
182
        protected override void OnDragStart(Point ptMouse, Point ptRelativeMouse)
-
 
183
        {
-
 
184
            if (IsFloatingAllowed)
-
 
185
            {
-
 
186
                Manager.Drag(this, HelperFunc.PointToScreenWithoutFlowDirection(this, ptMouse), ptRelativeMouse);
-
 
187
            }
146
 
188
 
147
            base.OnDragStart(ptMouse, ptRelativeMouse);
189
            base.OnDragStart(ptMouse, ptRelativeMouse);
148
        }
190
        }
149
 
191
 
150
        protected override void OnDragMouseMove(object sender, MouseEventArgs e)
192
        protected override void OnDragMouseMove(object sender, MouseEventArgs e)
Line 162... Line 204...
162
        {
204
        {
163
            base.OnApplyTemplate();
205
            base.OnApplyTemplate();
164
 
206
 
165
            if (DragEnabledArea != null)
207
            if (DragEnabledArea != null)
166
            {
208
            {
167
                DragEnabledArea.InputBindings.Add(new InputBinding(ApplicationCommands.Close, new MouseGesture(MouseAction.MiddleClick)));
209
                if (string.IsNullOrEmpty((string)DragEnabledArea.ToolTip))
-
 
210
                    DragEnabledArea.ToolTip = InfoTip;
168
            }
211
            }
-
 
212
        }
-
 
213
 
-
 
214
        protected override void OnInitialized(EventArgs e)
-
 
215
        {
-
 
216
            base.OnInitialized(e);
-
 
217
 
-
 
218
            this.CommandBindings.Add(
-
 
219
                new CommandBinding(DocumentContentCommands.FloatingDocument, this.OnExecuteCommand, this.OnCanExecuteCommand));
-
 
220
            this.CommandBindings.Add(
-
 
221
                new CommandBinding(DocumentContentCommands.TabbedDocument, this.OnExecuteCommand, this.OnCanExecuteCommand));
-
 
222
        }
-
 
223
 
-
 
224
        void OnExecuteCommand(object sender, ExecutedRoutedEventArgs e)
-
 
225
        {
-
 
226
            if (!e.Handled && e.Command == DocumentContentCommands.FloatingDocument)
-
 
227
            {
-
 
228
                this.Show(true);
-
 
229
 
-
 
230
                e.Handled = true;
-
 
231
            }
-
 
232
            else if (!e.Handled && e.Command == DocumentContentCommands.TabbedDocument)
-
 
233
            {
-
 
234
                this.Show(false);
-
 
235
 
-
 
236
                e.Handled = true;
-
 
237
            }
-
 
238
        }
-
 
239
 
-
 
240
        void OnCanExecuteCommand(object sender, CanExecuteRoutedEventArgs e)
-
 
241
        {
-
 
242
            e.CanExecute = CanExecuteCommand(e.Command);
169
        }
243
        }
170
 
244
 
171
        /// <summary>
245
        /// <summary>
172
        /// Event fired when the document is about to be closed
246
        /// Show <see cref="DocumentContent"/> as tabbed document
173
        /// </summary>
247
        /// </summary>
174
        public event EventHandler<CancelEventArgs> Closing;
248
        public override void Show()
-
 
249
        {
-
 
250
            Show(false);
-
 
251
        }
175
 
252
 
176
        /// <summary>
253
        /// <summary>
177
        /// Event fired when the document has been closed
254
        /// Show <see cref="DocumentContent"/> as tabbed document inside the provided <see cref="DockingManager"/>
178
        /// </summary>
255
        /// </summary>
179
        /// <remarks>Note that when a document is closed property like <see cref="ManagedContent.ContainerPane"/> or <see cref="ManagedContent.Manager"/> returns null.</remarks>
256
        /// <param name="manager">Docking manager target</param>
-
 
257
        public override void Show(DockingManager manager)
-
 
258
        {
180
        public event EventHandler Closed;
259
            Show(manager, false);
-
 
260
        }
181
 
261
 
182
        /// <summary>
262
        /// <summary>
183
        /// Ovveride this method to handle <see cref="DocumentContent.OnClosing"/> event.
263
        /// Show <see cref="DocumentContent"/> as tabbed document or inside a floating window
184
        /// </summary>
264
        /// </summary>
185
        protected virtual void OnClosing(CancelEventArgs e)
265
        public void Show(bool showAsFloatingWindow)
186
        {
266
        {
-
 
267
            if (!CanExecuteCommand(ManagedContentCommands.Show))
-
 
268
                throw new InvalidOperationException("This operation can be executed in this state");
-
 
269
 
-
 
270
            Manager.Show(this, showAsFloatingWindow);
-
 
271
        }
-
 
272
 
-
 
273
        /// <summary>
-
 
274
        /// Show <see cref="DocumentContent"/> as tabbed document inside the provided <see cref="DockingManager"/>
-
 
275
        /// </summary>
-
 
276
        /// <param name="manager">Docking manager target</param>
-
 
277
        /// <param name="showAsFloatingWindow">True if document should be shown inside a floating window (<see cref="DocumentFloatingWindow"/>)</param>
-
 
278
        public void Show(DockingManager manager, bool showAsFloatingWindow)
-
 
279
        {
187
            if (Closing != null && !e.Cancel)
280
            if (Manager != null && Manager != manager)
-
 
281
                throw new InvalidOperationException("Please remove the content from previous DockingManager (using the Close method)");
-
 
282
 
-
 
283
            if (!CanExecuteCommand(ManagedContentCommands.Show))
-
 
284
                throw new InvalidOperationException("This operation can be executed in this state");
-
 
285
 
-
 
286
            manager.Show(this, showAsFloatingWindow);
-
 
287
 
-
 
288
            manager.Documents.Add(this);
-
 
289
        }
-
 
290
 
-
 
291
        /// <summary>
-
 
292
        /// Activate the document showing its header if it's not visible
-
 
293
        /// </summary>
-
 
294
        public override void Activate()
-
 
295
        {
-
 
296
            base.Activate();
-
 
297
 
-
 
298
            if (!DocumentTabPanel.GetIsHeaderVisible(this))
188
            {
299
            {
-
 
300
                DocumentPane parentPane = this.ContainerPane as DocumentPane;
189
                Closing(this, e);
301
                if (parentPane != null &&
-
 
302
                    parentPane.GetManager() != null &&
-
 
303
                    parentPane.Items.IndexOf(this) != 0)
-
 
304
                {
-
 
305
                    parentPane.Items.Remove(this);
-
 
306
                    parentPane.Items.Insert(0, this);
-
 
307
                    parentPane.SelectedIndex = 0;
-
 
308
                }
190
            }
309
            }
191
        }
310
        }
192
 
311
 
193
        /// <summary>
312
        /// <summary>
194
        /// Ovveride this method to handle <see cref="DocumentContent.OnClose"/> event.
313
        /// Retrive a value indicating if the command can be executed based to the dockable content state
195
        /// </summary>
314
        /// </summary>
-
 
315
        /// <param name="command"></param>
-
 
316
        /// <returns></returns>
196
        protected virtual void OnClosed()
317
        protected override bool CanExecuteCommand(ICommand command)
197
        {
318
        {
-
 
319
            if (command == DocumentContentCommands.FloatingDocument)
-
 
320
            {
-
 
321
                return !IsFloating && IsFloatingAllowed;
-
 
322
            }
-
 
323
            else if (command == DocumentContentCommands.TabbedDocument)
-
 
324
            {
198
            if (Closed != null)
325
                return IsFloating;
-
 
326
            }
-
 
327
 
199
                Closed(this, EventArgs.Empty);
328
            return true;
200
        }
329
        }
201
 
330
 
202
        /// <summary>
331
        /// <summary>
203
        /// Close this content without notifications
332
        /// Close this content without notifications
204
        /// </summary>
333
        /// </summary>
205
        internal void InternalClose()
334
        internal void InternalClose()
206
        {
335
        {
207
 
-
 
208
 
-
 
209
            DocumentPane parentPane = ContainerPane as DocumentPane;
-
 
210
            DockingManager manager = Manager;
336
            DockingManager manager = Manager;
211
 
337
 
212
            if (manager != null)
338
            if (manager != null)
213
            {
339
            {
214
                if (manager.ActiveContent == this)
340
                if (manager.ActiveContent == this)
Line 216... Line 342...
216
 
342
 
217
                if (manager.ActiveDocument == this)
343
                if (manager.ActiveDocument == this)
218
                    manager.ActiveDocument = null;
344
                    manager.ActiveDocument = null;
219
            }          
345
            }          
220
           
346
           
-
 
347
            DocumentPane parentPane = ContainerPane as DocumentPane;
-
 
348
            FloatingDocumentPane floatingParentPane = ContainerPane as FloatingDocumentPane;
-
 
349
 
-
 
350
            if (floatingParentPane != null)
-
 
351
            {
-
 
352
                floatingParentPane.RemoveContent(0);
-
 
353
                if (floatingParentPane.FloatingWindow != null &&
-
 
354
                    !floatingParentPane.FloatingWindow.IsClosing)
-
 
355
                    floatingParentPane.FloatingWindow.Close();
-
 
356
            }
221
            if (parentPane != null)
357
            else if (parentPane != null)
222
            {
358
            {
223
                parentPane.Items.Remove(this);
359
                parentPane.Items.Remove(this);
224
 
360
 
225
                parentPane.CheckContentsEmpty();
361
                parentPane.CheckContentsEmpty();
226
            }
362
            }
227
            else
-
 
228
            {
-
 
229
                FloatingDockablePane floatingParentPane = ContainerPane as FloatingDockablePane;
-
 
230
                if (floatingParentPane != null)
-
 
231
                {
-
 
232
                    floatingParentPane.RemoveContent(0);
-
 
233
                    if (floatingParentPane.FloatingWindow != null &&
-
 
234
                        !floatingParentPane.FloatingWindow.IsClosing)
-
 
235
                        floatingParentPane.FloatingWindow.Close();
-
 
236
                }
-
 
237
            }
-
 
238
 
-
 
239
 
-
 
240
 
-
 
241
 
-
 
242
        }
363
        }
243
 
364
 
244
        /// <summary>
365
        /// <summary>
245
        /// Close this document removing it from its parent container
366
        /// Close this document removing it from its parent container
246
        /// </summary>
367
        /// </summary>
247
        /// <remarks>Use this function to close a document and remove it from its parent container. Please note
368
        /// <remarks>Use this function to close a document and remove it from its parent container. Please note
248
        /// that if you simply remove it from its parent <see cref="DocumentPane"/> without call this method, events like
369
        /// that if you simply remove it from its parent <see cref="DocumentPane"/> without call this method, events like
249
        /// <see cref="OnClosing"/>/<see cref="OnClosed"/> are not called.
370
        /// <see cref="OnClosing"/>/<see cref="OnClosed"/> are not called.
250
        /// <para>
-
 
251
        /// Note:<see cref="DockableContent"/> cannot be closed: AvalonDock simply hide a <see cref="DockableContent"/> removing all the reference to it.
-
 
252
        /// </para>
-
 
253
        /// </remarks>
371
        /// </remarks>
254
        public bool Close()
372
        public override bool Close()
255
        {
373
        {
256
            if (!IsCloseable)
374
            if (!IsCloseable)
257
                return false;
375
                return false;
258
 
376
 
259
            //if documents are attached to an external source via DockingManager.DocumentsSource
377
            ////if documents are attached to an external source via DockingManager.DocumentsSource
260
            //let application host handle the document closing by itself
378
            ////let application host handle the document closing by itself
261
            if (Manager.DocumentsSource != null)
379
            //if (Manager.DocumentsSource != null)
262
            {
380
            //{
263
                return Manager.FireRequestDocumentCloseEvent(this);
381
            //    //return Manager.FireRequestDocumentCloseEvent(this);
-
 
382
            //    Manager.HandleDocumentClose(this);
264
            }
383
            //}
265
 
384
 
266
 
385
 
267
            CancelEventArgs e = new CancelEventArgs(false);
386
            CancelEventArgs e = new CancelEventArgs(false);
268
            OnClosing(e);
387
            OnClosing(e);
269
           
388
           
Line 279... Line 398...
279
                return false;
398
                return false;
280
 
399
 
281
            InternalClose();
400
            InternalClose();
282
 
401
 
283
            OnClosed();
402
            OnClosed();
-
 
403
 
-
 
404
            //if documents are attached to an external source via DockingManager.DocumentsSource
-
 
405
            //let application host handle the document closing by itself
-
 
406
            if (Manager.DocumentsSource != null)
-
 
407
            {
-
 
408
                Manager.HandleDocumentClose(this);
-
 
409
            }
284
 
410
 
285
            if (oldManager != null)
411
            if (oldManager != null)
286
                oldManager.FireDocumentClosedEvent();
412
                oldManager.FireDocumentClosedEvent();
287
 
413
 
288
 
414
 
289
            //if (Parent != null)
-
 
290
            //    throw new InvalidOperationException();
-
 
291
            Debug.Assert(Parent == null, "Parent MUST bu null after Doc is closed");
415
            Debug.Assert(Parent == null, "Parent MUST bu null after Doc is closed");
292
            return true;
416
            return true;
293
        }
417
        }
294
     
-
 
295
   
-
 
296
 
418
 
-
 
419
        /// <summary>
-
 
420
        /// Hide the <see cref="DocumentContent"/> (Close the document)
-
 
421
        /// </summary>
-
 
422
        /// <returns></returns>
-
 
423
        public override bool Hide()
-
 
424
        {
-
 
425
            return Close();
-
 
426
        }
-
 
427
 
-
 
428
 
-
 
429
 
-
 
430
        #region Save/RestoreLayout
-
 
431
        public override void SaveLayout(System.Xml.XmlWriter storeWriter)
-
 
432
        {
-
 
433
            base.SaveLayout(storeWriter);
-
 
434
        }
-
 
435
 
-
 
436
        public override void RestoreLayout(System.Xml.XmlElement contentElement)
-
 
437
        {
-
 
438
            base.RestoreLayout(contentElement);
-
 
439
        }
-
 
440
        #endregion
297
    }
441
    }
298
}
442
}
299
 
443