~ubuntu-branches/ubuntu/saucy/monodevelop/saucy-proposed

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/MonoDevelopStatusBar.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2010-09-10 16:54:48 UTC
  • mfrom: (19.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20100910165448-0rybfk25zd4o9431
Tags: 2.4+dfsg-2
* debian/patches/inject_Mono.Debugger.Soft_source.patch,
  debian/patches/use_system_Mono.Debugger.Soft.patch,
  debian/control:
  + Build against system Soft Debugger, since we now have a new
    enough Mono to match MonoDevelop's required API

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
using System;
30
30
using MonoDevelop.Core;
31
 
using MonoDevelop.Core.Gui;
32
31
using Gtk;
 
32
using MonoDevelop.Ide.CodeCompletion;
 
33
using MonoDevelop.Ide.Gui;
 
34
using System.Collections.Generic;
 
35
using MonoDevelop.Components.Docking;
33
36
 
34
37
namespace MonoDevelop.Ide
35
38
{
36
 
        public class MonoDevelopStatusBar : Gtk.Statusbar
 
39
        class MonoDevelopStatusBar : Gtk.Statusbar, StatusBar, IShadedWidget
37
40
        {
38
41
                ProgressBar progressBar = new ProgressBar ();
39
42
                Frame textStatusBarPanel = new Frame ();
40
43
                
41
 
                
42
44
                Label statusLabel;
43
45
                Label modeLabel;
44
46
                Label cursorLabel;
45
47
                
46
48
                HBox statusBox;
 
49
                HBox messageBox;
47
50
                Image currentStatusImage;
48
 
                EventBox eventBox;
 
51
                
 
52
                HBox statusIconBox;
 
53
                
 
54
                List<StatusBarContextImpl> contexts = new List<StatusBarContextImpl> ();
 
55
                MainStatusBarContextImpl mainContext;
 
56
                StatusBarContextImpl activeContext;
 
57
                Pad sourcePad;
 
58
                uint autoPulseTimeoutId;
 
59
                
 
60
                public StatusBar MainContext {
 
61
                        get { return mainContext; }
 
62
                }
 
63
                
49
64
                internal MonoDevelopStatusBar()
50
65
                {
 
66
                        mainContext = new MainStatusBarContextImpl (this);
 
67
                        activeContext = mainContext;
 
68
                        contexts.Add (mainContext);
 
69
                        
51
70
                        Frame originalFrame = (Frame)Children[0];
52
71
//                      originalFrame.WidthRequest = 8;
53
72
//                      originalFrame.Shadow = ShadowType.In;
55
74
                        
56
75
                        BorderWidth = 0;
57
76
                        
 
77
                        DefaultWorkbench wb = (DefaultWorkbench) IdeApp.Workbench.RootWindow;
 
78
                        wb.DockFrame.ShadedContainer.Add (this);
 
79
                        Gtk.Widget dockBar = wb.DockFrame.ExtractDockBar (PositionType.Bottom);
 
80
                        dockBar.NoShowAll = true;
 
81
                        PackStart (dockBar, false, false, 0);
 
82
                        
58
83
                        progressBar = new ProgressBar ();
59
 
                        progressBar.PulseStep = 0.3;
 
84
                        progressBar.PulseStep = 0.1;
60
85
                        progressBar.SizeRequest ();
61
86
                        progressBar.HeightRequest = 1;
62
87
                        
71
96
                        statusLabel.HeightRequest = h;
72
97
                        statusLabel.SetPadding (0, 0);
73
98
                        
74
 
                        statusBox.PackStart (progressBar, false, false, 0);
75
 
                        statusBox.PackStart (statusLabel, true, true, 0);
 
99
                        EventBox eventMessageBox = new EventBox ();
 
100
                        messageBox = new HBox ();
 
101
                        messageBox.PackStart (progressBar, false, false, 0);
 
102
                        messageBox.PackStart (statusLabel, true, true, 0);
 
103
                        eventMessageBox.Add (messageBox);
 
104
                        statusBox.PackStart (eventMessageBox, true, true, 0);
 
105
                        eventMessageBox.ButtonPressEvent += HandleEventMessageBoxButtonPressEvent;
76
106
                        
77
107
                        textStatusBarPanel.BorderWidth = 0;
78
108
                        textStatusBarPanel.ShadowType = ShadowType.None;
87
117
                        cursorLabel = new Label (" ");
88
118
                        statusBox.PackEnd (cursorLabel, false, false, 0);
89
119
                        
90
 
                        eventBox = new EventBox ();
91
 
                        eventBox.BorderWidth = 0;
92
 
                        statusBox.PackEnd (eventBox, false, false, 4);
 
120
                        statusIconBox = new HBox ();
 
121
                        statusIconBox.BorderWidth = 0;
 
122
                        statusIconBox.Spacing = 3;
 
123
                        statusBox.PackEnd (statusIconBox, false, false, 4);
93
124
                        
94
125
                        this.PackStart (textStatusBarPanel, true, true, 0);
95
126
                        
104
135
                        
105
136
                        this.progressBar.Fraction = 0.0;
106
137
                        this.ShowAll ();
107
 
                        eventBox.HideAll ();
 
138
                        statusIconBox.HideAll ();
108
139
                        
109
140
                        originalFrame.HideAll ();
110
141
                        progressBar.Visible = false;
111
142
                        
112
 
                        // the Mac has a resize grip by default, and the GTK+ one breaks it
113
 
                        if (MonoDevelop.Core.PropertyService.IsMac)
114
 
                                HasResizeGrip = false;
 
143
                        StatusBarContext completionStatus = null;
 
144
                        
 
145
                        // todo: Move this to the CompletionWindowManager when it's possible.
 
146
                        CompletionWindowManager.WindowShown += delegate {
 
147
                                CompletionListWindow wnd = CompletionWindowManager.Wnd;
 
148
                                if (wnd != null && wnd.List != null && wnd.List.CategoryCount > 1) {
 
149
                                        if (completionStatus == null)
 
150
                                                completionStatus = CreateContext ();
 
151
                                        completionStatus.ShowMessage (string.Format (GettextCatalog.GetString ("To toggle categorized completion mode press {0}."), IdeApp.CommandService.GetCommandInfo (Commands.TextEditorCommands.ShowCompletionWindow).AccelKey));
 
152
                                }
 
153
                        };
 
154
                        
 
155
                        CompletionWindowManager.WindowClosed += delegate {
 
156
                                if (completionStatus != null) {
 
157
                                        completionStatus.Dispose ();
 
158
                                        completionStatus = null;
 
159
                                }
 
160
                        };
 
161
                }
 
162
 
 
163
                void HandleEventMessageBoxButtonPressEvent (object o, ButtonPressEventArgs args)
 
164
                {
 
165
                        if (sourcePad != null)
 
166
                                sourcePad.BringToFront (true);
 
167
                }
 
168
                
 
169
                internal bool IsCurrentContext (StatusBarContextImpl ctx)
 
170
                {
 
171
                        return ctx == activeContext;
 
172
                }
 
173
                
 
174
                internal void Remove (StatusBarContextImpl ctx)
 
175
                {
 
176
                        if (ctx == mainContext)
 
177
                                return;
 
178
                        
 
179
                        StatusBarContextImpl oldActive = activeContext;
 
180
                        contexts.Remove (ctx);
 
181
                        UpdateActiveContext ();
 
182
                        if (oldActive != activeContext) {
 
183
                                // Removed the active context. Update the status bar.
 
184
                                activeContext.Update ();
 
185
                        }
 
186
                }
 
187
                
 
188
                internal void UpdateActiveContext ()
 
189
                {
 
190
                        for (int n = contexts.Count - 1; n >= 0; n--) {
 
191
                                StatusBarContextImpl ctx = contexts [n];
 
192
                                if (ctx.StatusChanged) {
 
193
                                        if (ctx != activeContext) {
 
194
                                                activeContext = ctx;
 
195
                                                activeContext.Update ();
 
196
                                        }
 
197
                                        return;
 
198
                                }
 
199
                        }
 
200
                        throw new InvalidOperationException (); // There must be at least the main context
 
201
                }
 
202
                
 
203
                public StatusBarContext CreateContext ()
 
204
                {
 
205
                        StatusBarContextImpl ctx = new StatusBarContextImpl (this);
 
206
                        contexts.Add (ctx);
 
207
                        return ctx;
115
208
                }
116
209
                
117
210
                public void ShowCaretState (int line, int column, int selectedChars, bool isInInsertMode)
129
222
                
130
223
                public void ClearCaretState ()
131
224
                {
132
 
                        cursorLabel.Text = "";
133
 
                        modeLabel.Text = "";
 
225
                        if (cursorLabel.Text != "")
 
226
                                cursorLabel.Text = "";
 
227
                        if (modeLabel.Text != "")
 
228
                                modeLabel.Text = "";
134
229
                }
135
230
                
136
231
                public void ShowReady ()
140
235
                
141
236
                public void ShowError (string error)
142
237
                {
143
 
                        ShowMessage (new Image (MonoDevelop.Core.Gui.Stock.Error, IconSize.Menu), error);
 
238
                        ShowMessage (new Image (MonoDevelop.Ide.Gui.Stock.Error, IconSize.Menu), error);
144
239
                }
145
240
                
146
241
                public void ShowWarning (string warning)
147
242
                {
148
243
                        DispatchService.AssertGuiThread ();
149
 
                        ShowMessage (new Gtk.Image (MonoDevelop.Core.Gui.Stock.Warning, IconSize.Menu), warning);
 
244
                        ShowMessage (new Gtk.Image (MonoDevelop.Ide.Gui.Stock.Warning, IconSize.Menu), warning);
150
245
                }
151
246
                
152
247
                public void ShowMessage (string message)
163
258
                {
164
259
                        ShowMessage (image, message, false);
165
260
                }
166
 
                
167
 
                void ShowMessage (Image image, string message, bool isMarkup)
 
261
                string lastText = null;
 
262
                public void ShowMessage (Image image, string message, bool isMarkup)
168
263
                {
 
264
                        if (message == lastText)
 
265
                                return;
 
266
                        sourcePad = null;
 
267
                        lastText = message;
169
268
                        DispatchService.AssertGuiThread ();
170
269
                        if (currentStatusImage != image) {
171
270
                                if (currentStatusImage != null) 
172
 
                                        statusBox.Remove (currentStatusImage);
 
271
                                        messageBox.Remove (currentStatusImage);
173
272
                                currentStatusImage = image;
174
273
                                if (image != null) {
175
274
                                        image.SetPadding (0, 0);
176
 
                                        statusBox.PackStart (image, false, false, 3);
177
 
                                        statusBox.ReorderChild (image, 1);
 
275
                                        messageBox.PackStart (image, false, false, 3);
 
276
                                        messageBox.ReorderChild (image, 1);
178
277
                                        image.Show ();
179
278
                                }
180
279
                        }
187
286
                        }
188
287
                }
189
288
                
190
 
                public StatusIcon ShowStatusIcon (Gdk.Pixbuf pixbuf)
 
289
                public void SetMessageSourcePad (Pad pad)
 
290
                {
 
291
                        sourcePad = pad;
 
292
                }
 
293
                
 
294
                public StatusBarIcon ShowStatusIcon (Gdk.Pixbuf pixbuf)
191
295
                {
192
296
                        DispatchService.AssertGuiThread ();
193
 
                        
194
 
                        Gtk.Image image = new Gtk.Image (pixbuf);
195
 
                        image.SetPadding (0, 0);
196
 
                        if (eventBox.Child != null)
197
 
                                eventBox.Remove (eventBox.Child);
198
 
                        eventBox.Child = image;
199
 
                        
200
 
                        eventBox.ShowAll ();
201
 
                        return new StatusIcon (this, eventBox, pixbuf);
 
297
                        StatusIcon icon = new StatusIcon (this, pixbuf);
 
298
                        statusIconBox.PackEnd (icon.box);
 
299
                        statusIconBox.ShowAll ();
 
300
                        return icon;
202
301
                }
203
302
                
204
303
                void HideStatusIcon (StatusIcon icon)
205
304
                {
206
 
                        Widget child = icon.EventBox.Child; 
207
 
                        if (child != null) {
208
 
                                icon.EventBox.Remove (child);
209
 
                                child.Destroy ();
210
 
                        }
211
 
                        eventBox.HideAll ();
 
305
                        statusIconBox.Remove (icon.EventBox);
 
306
                        icon.EventBox.Destroy ();
212
307
                }
213
308
                
214
309
                #region Progress Monitor implementation
235
330
                        ShowMessage ("");
236
331
                        this.progressBar.Fraction = 0.0;
237
332
                        this.progressBar.Visible = false;
 
333
                        AutoPulse = false;
238
334
                }
239
335
 
240
336
                public void Pulse ()
242
338
                        DispatchService.AssertGuiThread ();
243
339
                        this.progressBar.Visible = true;
244
340
                        this.progressBar.Pulse ();
245
 
                }               
 
341
                }
 
342
 
 
343
                public bool AutoPulse {
 
344
                        get { return autoPulseTimeoutId != 0; }
 
345
                        set {
 
346
                                DispatchService.AssertGuiThread ();
 
347
                                if (value) {
 
348
                                        this.progressBar.Visible = true;
 
349
                                        if (autoPulseTimeoutId == 0) {
 
350
                                                autoPulseTimeoutId = GLib.Timeout.Add (100, delegate {
 
351
                                                        this.progressBar.Pulse ();
 
352
                                                        return true;
 
353
                                                });
 
354
                                        }
 
355
                                } else {
 
356
                                        if (autoPulseTimeoutId != 0) {
 
357
                                                GLib.Source.Remove (autoPulseTimeoutId);
 
358
                                                autoPulseTimeoutId = 0;
 
359
                                        }
 
360
                                }
 
361
                        }
 
362
                }
246
363
                #endregion
247
364
                
248
 
                public class StatusIcon : IDisposable
 
365
                public class StatusIcon : StatusBarIcon
249
366
                {
250
367
                        MonoDevelopStatusBar statusBar;
251
368
                        internal EventBox box;
252
369
                        string tip;
253
370
                        DateTime alertEnd;
254
371
                        Gdk.Pixbuf icon;
 
372
                        uint animation;
 
373
                        Gtk.Image image;
255
374
                        
256
375
                        int astep;
257
 
                        Gtk.Image[] images;
 
376
                        Gdk.Pixbuf[] images;
258
377
                        
259
 
                        public StatusIcon (MonoDevelopStatusBar statusBar, EventBox box, Gdk.Pixbuf icon)
 
378
                        public StatusIcon (MonoDevelopStatusBar statusBar, Gdk.Pixbuf icon)
260
379
                        {
261
380
                                this.statusBar = statusBar;
262
 
                                this.box = box;
263
381
                                this.icon = icon;
 
382
                                box = new EventBox ();
 
383
                                image = new Image (icon);
 
384
                                image.SetPadding (0, 0);
 
385
                                box.Child = image;
264
386
                        }
265
387
                        
266
388
                        public void Dispose ()
267
389
                        {
268
390
                                statusBar.HideStatusIcon (this);
269
391
                                if (images != null) {
270
 
                                        foreach (Gtk.Image img in images) {
 
392
                                        foreach (Gdk.Pixbuf img in images) {
271
393
                                                img.Dispose ();
272
394
                                        }
273
395
                                }
 
396
                                if (animation != 0) {
 
397
                                        GLib.Source.Remove (animation);
 
398
                                        animation = 0;
 
399
                                }
274
400
                        }
275
401
                        
276
402
                        public string ToolTip {
288
414
                                get { return icon; }
289
415
                                set {
290
416
                                        icon = value;
291
 
                                        Gtk.Image i = new Gtk.Image (icon);
292
 
                                        i.SetPadding (0, 0);
293
 
                                        box.Child = i;
 
417
                                        image.Pixbuf = icon;
294
418
                                }
295
419
                        }
296
420
                        
299
423
                                astep = 0;
300
424
                                alertEnd = DateTime.Now.AddSeconds (seconds);
301
425
                                
302
 
                                if (images == null)
303
 
                                        GLib.Timeout.Add (60, new GLib.TimeoutHandler (AnimateIcon));
304
 
                                
305
 
                                images = new Gtk.Image [10];
306
 
                                for (int n=0; n<10; n++) {
307
 
                                        images [n] = new Image (ImageService.MakeTransparent (icon, ((double)(9-n))/10.0));
308
 
                                        images [n].SetPadding (0, 0);
309
 
                                        images [n].Show ();
 
426
                                if (animation != 0)
 
427
                                        GLib.Source.Remove (animation);
 
428
                                
 
429
                                animation = GLib.Timeout.Add (60, new GLib.TimeoutHandler (AnimateIcon));
 
430
                                
 
431
                                if (images == null) {
 
432
                                        images = new Gdk.Pixbuf [10];
 
433
                                        for (int n=0; n<10; n++)
 
434
                                                images [n] = ImageService.MakeTransparent (icon, ((double)(9-n))/10.0);
310
435
                                }
311
436
                        }
312
437
                        
313
 
                        public bool AnimateIcon ()
 
438
                        bool AnimateIcon ()
314
439
                        {
315
 
                                box.Remove (box.Child);
316
 
                                
317
440
                                if (DateTime.Now >= alertEnd && astep == 0) {
318
 
                                        Gtk.Image i = new Gtk.Image (icon);
319
 
                                        i.SetPadding (0, 0);
320
 
                                        box.Child = i;
321
 
                                        images = null;
322
 
                                        box.Child.Show ();
 
441
                                        image.Pixbuf = icon;
 
442
                                        animation = 0;
323
443
                                        return false;
324
444
                                }
325
445
                                if (astep < 10)
326
 
                                        box.Child = images [astep];
 
446
                                        image.Pixbuf = images [astep];
327
447
                                else
328
 
                                        box.Child = images [20 - astep - 1];
 
448
                                        image.Pixbuf = images [20 - astep - 1];
329
449
                                        
330
450
                                astep = (astep + 1) % 20;
331
451
                                return true;
332
452
                        }
333
453
                }
 
454
                
 
455
                Gdk.Rectangle GetGripRect ()
 
456
                {
 
457
                        Gdk.Rectangle rect = new Gdk.Rectangle (0, 0, 18, Allocation.Height);
 
458
                        if (rect.Width > Allocation.Width)
 
459
                                rect.Width = Allocation.Width;
 
460
                        rect.Y = Allocation.Y + Allocation.Height - rect.Height;
 
461
                        if (Direction == TextDirection.Ltr)
 
462
                                rect.X = Allocation.X + Allocation.Width - rect.Width;
 
463
                        else
 
464
                                rect.X = Allocation.X + Style.XThickness;
 
465
                        return rect;
 
466
                }
 
467
                
 
468
                protected override bool OnExposeEvent (Gdk.EventExpose evnt)
 
469
                {
 
470
                        bool ret = base.OnExposeEvent (evnt);
 
471
                        if (HasResizeGrip) {
 
472
                                DefaultWorkbench wb = (DefaultWorkbench) IdeApp.Workbench.RootWindow;
 
473
                                wb.DockFrame.ShadedContainer.DrawBackground (this, GetGripRect ());
 
474
                                Gdk.Rectangle rect = GetGripRect ();
 
475
                                int w = rect.Width - Style.Xthickness;
 
476
                                int h = Allocation.Height - Style.YThickness;
 
477
                                if (h < 18 - Style.YThickness) h = 18 - Style.YThickness;
 
478
                                Gdk.WindowEdge edge = Direction == TextDirection.Ltr ? Gdk.WindowEdge.SouthEast : Gdk.WindowEdge.SouthWest;
 
479
                                Gtk.Style.PaintResizeGrip (Style, GdkWindow, State, evnt.Area, this, "statusbar", edge, rect.X, rect.Y, w, h);
 
480
                        }
 
481
                        return ret;
 
482
                }
 
483
                
 
484
                public void NotifyShadedAreasChanged ()
 
485
                {
 
486
                        if (AreasChanged != null)
 
487
                                AreasChanged (this, EventArgs.Empty);
 
488
                }
 
489
                
 
490
                public IEnumerable<Gdk.Rectangle> GetShadedAreas ()
 
491
                {
 
492
                        if (HasResizeGrip)
 
493
                                yield return GetGripRect ();
 
494
                }
 
495
                
 
496
                public event EventHandler AreasChanged;
 
497
        }
 
498
        
 
499
        /// <summary>
 
500
        /// The MonoDevelop status bar.
 
501
        /// </summary>
 
502
        public interface StatusBar: StatusBarContextBase
 
503
        {
 
504
                /// <summary>
 
505
                /// Show caret state information
 
506
                /// </summary>
 
507
                void ShowCaretState (int line, int column, int selectedChars, bool isInInsertMode);
 
508
                
 
509
                /// <summary>
 
510
                /// Hides the caret state information
 
511
                /// </summary>
 
512
                void ClearCaretState ();
 
513
                
 
514
                /// <summary>
 
515
                /// Shows a status icon in the toolbar. The icon can be removed by disposing
 
516
                /// the StatusBarIcon instance.
 
517
                /// </summary>
 
518
                StatusBarIcon ShowStatusIcon (Gdk.Pixbuf pixbuf);
 
519
                
 
520
                /// <summary>
 
521
                /// Creates a status bar context. The returned context can be used to show status information
 
522
                /// which will be cleared when the context is disposed. When several contexts are created,
 
523
                /// the status bar will show the status of the latest created context.
 
524
                /// </summary>
 
525
                StatusBarContext CreateContext ();
 
526
                
 
527
                // Clears the status bar information
 
528
                void ShowReady ();
 
529
                
 
530
                /// <summary>
 
531
                /// Sets a pad which has detailed information about the status message. When clicking on the
 
532
                /// status bar, this pad will be activated. This source pad is reset at every ShowMessage call.
 
533
                /// </summary>
 
534
                void SetMessageSourcePad (Pad pad);
 
535
                
 
536
                /// <summary>
 
537
                /// When set to true, the resize grip is shown
 
538
                /// </summary>
 
539
                bool HasResizeGrip { get; set; }
 
540
        }
 
541
        
 
542
        public interface StatusBarContextBase: IDisposable
 
543
        {
 
544
                /// <summary>
 
545
                /// Shows a message with an error icon
 
546
                /// </summary>
 
547
                void ShowError (string error);
 
548
                
 
549
                /// <summary>
 
550
                /// Shows a message with a warning icon
 
551
                /// </summary>
 
552
                void ShowWarning (string warning);
 
553
                
 
554
                /// <summary>
 
555
                /// Shows a message in the status bar
 
556
                /// </summary>
 
557
                void ShowMessage (string message);
 
558
                
 
559
                /// <summary>
 
560
                /// Shows a message in the status bar
 
561
                /// </summary>
 
562
                void ShowMessage (string message, bool isMarkup);
 
563
                
 
564
                /// <summary>
 
565
                /// Shows a message in the status bar
 
566
                /// </summary>
 
567
                void ShowMessage (Image image, string message);
 
568
                
 
569
                /// <summary>
 
570
                /// Shows a progress bar, with the provided label next to it
 
571
                /// </summary>
 
572
                void BeginProgress (string name);
 
573
                
 
574
                /// <summary>
 
575
                /// Shows a progress bar, with the provided label and icon next to it
 
576
                /// </summary>
 
577
                void BeginProgress (Image image, string name);
 
578
                
 
579
                /// <summary>
 
580
                /// Sets the progress fraction. It can only be used after calling BeginProgress.
 
581
                /// </summary>
 
582
                void SetProgressFraction (double work);
 
583
 
 
584
                /// <summary>
 
585
                /// Hides the progress bar shown with BeginProgress
 
586
                /// </summary>
 
587
                void EndProgress ();
 
588
                
 
589
                /// <summary>
 
590
                /// Pulses the progress bar shown with BeginProgress
 
591
                /// </summary>
 
592
                void Pulse ();
 
593
                
 
594
                /// <summary>
 
595
                /// When set, the status bar progress will be automatically pulsed at short intervals
 
596
                /// </summary>
 
597
                bool AutoPulse { get; set; }
 
598
        }
 
599
        
 
600
        public interface StatusBarContext: StatusBarContextBase
 
601
        {
 
602
                Pad StatusSourcePad { get; set; }
 
603
        }
 
604
        
 
605
        public interface StatusBarIcon : IDisposable
 
606
        {
 
607
                /// <summary>
 
608
                /// Tooltip of the status icon
 
609
                /// </summary>
 
610
                string ToolTip { get; set; }
 
611
                
 
612
                /// <summary>
 
613
                /// Event box which can be used to subscribe mouse events on the icon
 
614
                /// </summary>
 
615
                EventBox EventBox { get; }
 
616
                
 
617
                /// <summary>
 
618
                /// The icon
 
619
                /// </summary>
 
620
                Gdk.Pixbuf Image { get; set; }
 
621
                
 
622
                /// <summary>
 
623
                /// Sets alert mode. The icon will flash for the provided number of seconds.
 
624
                /// </summary>
 
625
                void SetAlertMode (int seconds);
 
626
        }
 
627
        
 
628
        class StatusBarContextImpl: StatusBarContext
 
629
        {
 
630
                Image image;
 
631
                string message;
 
632
                bool isMarkup;
 
633
                double progressFraction;
 
634
                bool showProgress;
 
635
                Pad sourcePad;
 
636
                bool autoPulse;
 
637
                protected MonoDevelopStatusBar statusBar;
 
638
                
 
639
                internal bool StatusChanged { get; set; }
 
640
                
 
641
                internal StatusBarContextImpl (MonoDevelopStatusBar statusBar)
 
642
                {
 
643
                        this.statusBar = statusBar;
 
644
                }
 
645
                
 
646
                public void Dispose ()
 
647
                {
 
648
                        statusBar.Remove (this);
 
649
                }
 
650
                
 
651
                public void ShowError (string error)
 
652
                {
 
653
                        ShowMessage (new Image (MonoDevelop.Ide.Gui.Stock.Error, IconSize.Menu), error);
 
654
                }
 
655
                
 
656
                public void ShowWarning (string warning)
 
657
                {
 
658
                        ShowMessage (new Gtk.Image (MonoDevelop.Ide.Gui.Stock.Warning, IconSize.Menu), warning);
 
659
                }
 
660
                
 
661
                public void ShowMessage (string message)
 
662
                {
 
663
                        ShowMessage (null, message, false);
 
664
                }
 
665
                
 
666
                public void ShowMessage (string message, bool isMarkup)
 
667
                {
 
668
                        ShowMessage (null, message, isMarkup);
 
669
                }
 
670
                
 
671
                public void ShowMessage (Image image, string message)
 
672
                {
 
673
                        ShowMessage (image, message, false);
 
674
                }
 
675
                
 
676
                bool InitialSetup ()
 
677
                {
 
678
                        if (!StatusChanged) {
 
679
                                StatusChanged = true;
 
680
                                statusBar.UpdateActiveContext ();
 
681
                                return true;
 
682
                        } else
 
683
                                return false;
 
684
                }
 
685
                
 
686
                public void ShowMessage (Image image, string message, bool isMarkup)
 
687
                {
 
688
                        this.image = image;
 
689
                        this.message = message;
 
690
                        this.isMarkup = isMarkup;
 
691
                        if (InitialSetup ())
 
692
                                return;
 
693
                        if (statusBar.IsCurrentContext (this)) {
 
694
                                OnMessageChanged ();
 
695
                                statusBar.ShowMessage (image, message, isMarkup);
 
696
                                statusBar.SetMessageSourcePad (sourcePad);
 
697
                        }
 
698
                }
 
699
                
 
700
                public void BeginProgress (string name)
 
701
                {
 
702
                        image = null;
 
703
                        isMarkup = false;
 
704
                        progressFraction = 0;
 
705
                        message = name;
 
706
                        showProgress = true;
 
707
                        if (InitialSetup ())
 
708
                                return;
 
709
                        if (statusBar.IsCurrentContext (this)) {
 
710
                                OnMessageChanged ();
 
711
                                statusBar.BeginProgress (name);
 
712
                                statusBar.SetMessageSourcePad (sourcePad);
 
713
                        }
 
714
                }
 
715
                
 
716
                public void BeginProgress (Image image, string name)
 
717
                {
 
718
                        this.image = image;
 
719
                        isMarkup = false;
 
720
                        progressFraction = 0;
 
721
                        message = name;
 
722
                        showProgress = true;
 
723
                        if (InitialSetup ())
 
724
                                return;
 
725
                        if (statusBar.IsCurrentContext (this)) {
 
726
                                OnMessageChanged ();
 
727
                                statusBar.BeginProgress (name);
 
728
                                statusBar.SetMessageSourcePad (sourcePad);
 
729
                        }
 
730
                }
 
731
                
 
732
                public void SetProgressFraction (double work)
 
733
                {
 
734
                        progressFraction = work;
 
735
                        if (InitialSetup ())
 
736
                                return;
 
737
                        if (statusBar.IsCurrentContext (this))
 
738
                                statusBar.SetProgressFraction (work);
 
739
                }
 
740
                
 
741
                public void EndProgress ()
 
742
                {
 
743
                        showProgress = false;
 
744
                        message = string.Empty;
 
745
                        progressFraction = 0;
 
746
                        if (InitialSetup ())
 
747
                                return;
 
748
                        if (statusBar.IsCurrentContext (this))
 
749
                                statusBar.EndProgress ();
 
750
                }
 
751
                
 
752
                public void Pulse ()
 
753
                {
 
754
                        showProgress = true;
 
755
                        if (InitialSetup ())
 
756
                                return;
 
757
                        if (statusBar.IsCurrentContext (this))
 
758
                                statusBar.Pulse ();
 
759
                }
 
760
                
 
761
                public bool AutoPulse {
 
762
                        get {
 
763
                                return autoPulse;
 
764
                        }
 
765
                        set {
 
766
                                if (value)
 
767
                                        showProgress = true;
 
768
                                autoPulse = value;
 
769
                                if (InitialSetup ())
 
770
                                        return;
 
771
                                if (statusBar.IsCurrentContext (this))
 
772
                                        statusBar.AutoPulse = value;
 
773
                        }
 
774
                }
 
775
                
 
776
                
 
777
                internal void Update ()
 
778
                {
 
779
                        if (showProgress) {
 
780
                                statusBar.BeginProgress (image, message);
 
781
                                statusBar.SetProgressFraction (progressFraction);
 
782
                                statusBar.AutoPulse = autoPulse;
 
783
                                statusBar.SetMessageSourcePad (sourcePad);
 
784
                        } else {
 
785
                                statusBar.EndProgress ();
 
786
                                statusBar.ShowMessage (image, message, isMarkup);
 
787
                                statusBar.SetMessageSourcePad (sourcePad);
 
788
                        }
 
789
                }
 
790
                
 
791
                public Pad StatusSourcePad {
 
792
                        get {
 
793
                                return sourcePad;
 
794
                        }
 
795
                        set {
 
796
                                sourcePad = value;
 
797
                        }
 
798
                }
 
799
                
 
800
                protected virtual void OnMessageChanged ()
 
801
                {
 
802
                }
 
803
        }
 
804
        
 
805
        class MainStatusBarContextImpl: StatusBarContextImpl, StatusBar
 
806
        {
 
807
                public MainStatusBarContextImpl (MonoDevelopStatusBar statusBar): base (statusBar)
 
808
                {
 
809
                        StatusChanged = true;
 
810
                }
 
811
                
 
812
                public void ShowCaretState (int line, int column, int selectedChars, bool isInInsertMode)
 
813
                {
 
814
                        statusBar.ShowCaretState (line, column, selectedChars, isInInsertMode);
 
815
                }
 
816
                
 
817
                public void ClearCaretState ()
 
818
                {
 
819
                        statusBar.ClearCaretState ();
 
820
                }
 
821
                
 
822
                public StatusBarIcon ShowStatusIcon (Gdk.Pixbuf pixbuf)
 
823
                {
 
824
                        return statusBar.ShowStatusIcon (pixbuf);
 
825
                }
 
826
                
 
827
                public StatusBarContext CreateContext ()
 
828
                {
 
829
                        return statusBar.CreateContext ();
 
830
                }
 
831
                
 
832
                public void ShowReady ()
 
833
                {
 
834
                        statusBar.ShowReady ();
 
835
                }
 
836
                
 
837
                public void SetMessageSourcePad (Pad pad)
 
838
                {
 
839
                        StatusSourcePad = pad;
 
840
                        if (statusBar.IsCurrentContext (this))
 
841
                                statusBar.SetMessageSourcePad (pad);
 
842
                }
 
843
                
 
844
                protected override void OnMessageChanged ()
 
845
                {
 
846
                        StatusSourcePad = null;
 
847
                }
 
848
                
 
849
                public bool HasResizeGrip {
 
850
                        get {
 
851
                                return statusBar.HasResizeGrip;
 
852
                        }
 
853
                        set {
 
854
                                statusBar.HasResizeGrip = value;
 
855
                                statusBar.NotifyShadedAreasChanged ();
 
856
                        }
 
857
                }
 
858
                
334
859
        }
335
860
}