~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/mono-addins/Samples/TextEditorSWF/TextEditorSWF/TextEditor.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
Import upstream version 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using System;
 
2
using System.Collections.Generic;
 
3
using System.ComponentModel;
 
4
using System.Data;
 
5
using System.Drawing;
 
6
using System.Linq;
 
7
using System.Text;
 
8
using System.Windows.Forms;
 
9
using TextEditorSWF.ExtensionModel;
 
10
using Mono.Addins;
 
11
using System.IO;
 
12
 
 
13
namespace TextEditorSWF
 
14
{
 
15
        public partial class TextEditor : Form
 
16
        {
 
17
                string currentFile;
 
18
 
 
19
                public TextEditor ()
 
20
                {
 
21
                        InitializeComponent ();
 
22
 
 
23
                        // Create the main menu and the toolbar
 
24
 
 
25
                        foreach (ToolStripItem item in CommandManager.GetMainMenuItems ())
 
26
                                menuStrip.Items.Add (item);
 
27
                        foreach (ToolStripItem item in CommandManager.GetToolbarItems ())
 
28
                                toolStrip.Items.Add (item);
 
29
                }
 
30
 
 
31
                internal void Initialize ()
 
32
                {
 
33
                        // Initialize the editor extensions. Must be done after setting Program.MainWindow since
 
34
                        // extensions may use it
 
35
                        foreach (EditorExtension ext in AddinManager.GetExtensionObjects<EditorExtension> ())
 
36
                                ext.Initialize ();
 
37
                }
 
38
 
 
39
                /// <summary>
 
40
                /// The editor box
 
41
                /// </summary>
 
42
                public RichTextBox Editor
 
43
                {
 
44
                        get { return richTextBox; }
 
45
                }
 
46
 
 
47
                /// <summary>
 
48
                /// Saves the file to disk, asking for location if the file is unsaved
 
49
                /// </summary>
 
50
                public void SaveFile ()
 
51
                {
 
52
                        if (currentFile == null) {
 
53
                                SaveFileDialog dlg = new SaveFileDialog ();
 
54
                                if (dlg.ShowDialog (this) != DialogResult.OK)
 
55
                                        return;
 
56
                                currentFile = dlg.FileName;
 
57
                                dlg.Dispose ();
 
58
                        }
 
59
                        SaveFile (currentFile);
 
60
                }
 
61
 
 
62
                /// <summary>
 
63
                /// Saves the file to the specified location
 
64
                /// </summary>
 
65
                public void SaveFile (string file)
 
66
                {
 
67
                        File.WriteAllText (file, richTextBox.Text);
 
68
 
 
69
                        // Notify editor extensions
 
70
                        foreach (EditorExtension ext in AddinManager.GetExtensionObjects<EditorExtension> ())
 
71
                                ext.OnSaveFile (file);
 
72
                }
 
73
 
 
74
                /// <summary>
 
75
                /// Create a new file
 
76
                /// </summary>
 
77
                public void NewFile ()
 
78
                {
 
79
                        richTextBox.Text = "";
 
80
                        currentFile = null;
 
81
 
 
82
                        // Notify editor extensions
 
83
                        foreach (EditorExtension ext in AddinManager.GetExtensionObjects<EditorExtension> ())
 
84
                                ext.OnCreateFile ();
 
85
                }
 
86
 
 
87
                /// <summary>
 
88
                /// Open a new file. Will ask for the file name in a dialog.
 
89
                /// </summary>
 
90
                public void OpenFile ()
 
91
                {
 
92
                        OpenFileDialog dlg = new OpenFileDialog ();
 
93
                        if (dlg.ShowDialog () == DialogResult.OK)
 
94
                                OpenFile (dlg.FileName);
 
95
                        dlg.Dispose ();
 
96
                }
 
97
 
 
98
                /// <summary>
 
99
                /// Open the specified file in the text editor
 
100
                /// </summary>
 
101
                public void OpenFile (string file)
 
102
                {
 
103
                        richTextBox.Text = File.ReadAllText (file);
 
104
                        currentFile = file;
 
105
 
 
106
                        // Notify editor extensions
 
107
                        foreach (EditorExtension ext in AddinManager.GetExtensionObjects<EditorExtension> ())
 
108
                                ext.OnLoadFile (file);
 
109
                }
 
110
        }
 
111
}