0:   //  CodeTemplatePanel.cs
1:   //  Copyright (C) 2000 Mike Krueger
2:   //
3:   //  This program is free software; you can redistribute it and/or modify
4:   //  it under the terms of the GNU General Public License as published by
5:   //  the Free Software Foundation; either version 2 of the License, or
6:   //  (at your option) any later version.
7:   //
8:   //  This program is distributed in the hope that it will be useful,
9:   //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10:   //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11:   //  GNU General Public License for more details.
12:   //
13:   //  You should have received a copy of the GNU General Public License
14:   //  along with this program; if not, write to the Free Software
15:   //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16:  
17:   using System;
18:   using System.Collections;
19:   using System.Windows.Forms;
20:  
21:   using SharpDevelop.Internal.ExternalTool;
22:   using SharpDevelop.Internal.Templates;
23:   using SharpDevelop.Gui.Edit.Text;
24:   using SharpDevelop.Tool.Data;
25:  
26:   namespace SharpDevelop.Gui.Dialogs.OptionPanels {
27:       public class CodeTemplatePane : AbstractOptionPanel
28:       {
29:           private System.ComponentModel.Container components;
30:           private System.Windows.Forms.Button editButton;
31:           private TextAreaControl TextBox;
32:           
33:           private System.Windows.Forms.Button removeButton;
34:           private System.Windows.Forms.Button addButton;
35:           private System.Windows.Forms.ColumnHeader Description;
36:           private System.Windows.Forms.ColumnHeader Template;
37:           
38:           private System.Windows.Forms.ListView listView1;
39:           private System.Windows.Forms.Panel    panel1;
40:           ArrayList templates;
41:           
42:           public override void Accept()
43:           {
44:               CodeTemplateLoader.Template templates;
45:           }
46:           
47:           /// <summary>
48:           /// Clean up any resources being used.
49:           /// </summary>
50:           protected override void Dispose(bool disposing)
51:           {
52:               if (disposing) {
53:                   if (components != null){
54:                       components.Dispose();
55:                   }
56:                   TextBox.Dispose();
57:                   components.Dispose();
58:               }
59:               base.Dispose(disposing);
60:           }
61:           
62:           int GetCurrentIndex()
63:           {
64:               if (listView1.SelectedItems.Count > 0) {
65:                   return listView1.SelectedItems[0].Index;
66:               }
67:               return -1;
68:           }
69:           
70:           void RemoveEvent(object senderSystem.EventArgs e)
71:           {
72:               int GetCurrentIndex();
73:               if (!= -1) {
74:                   templates.RemoveAt(i);
75:                   BuildListView();
76:               }
77:           }
78:           
79:           void AddEvent(object senderSystem.EventArgs e)
80:           {
81:               CodeTemplate t new CodeTemplate();
82:               EditTemplateDialog etd new EditTemplateDialog(t);
83:               if (etd.ShowDialog() == DialogResult.OK) {
84:                   templates.Add(t);
85:                   listView1.SelectedItems.Clear();
86:                   BuildListView();
87:   //           TODO TODO TODO TODO     
88:   //                listView1.SelectedItems.Add(listView1.Items[templates.Count-1]);
89:                   listView1.Select();
90:               }
91:               etd.Dispose();
92:           }
93:           
94:           void IndexChange(object senderSystem.EventArgs e)
95:           {
96:               int GetCurrentIndex();
97:               if (!= -1) {
98:                   TextBox.Enabled true;
99:                   TextBox.TextAreaPainter.Buffer.Text = ((CodeTemplate)templates[i]).Text;
100:               else {
101:                   TextBox.TextAreaPainter.Buffer.Text "";
102:                   TextBox.Enabled false;
103:               }
104:               TextBox.Refresh();
105:           }
106:           
107:           void TextChange(object senderEventArgs e)
108:           {
109:               int GetCurrentIndex();
110:               if (!= -1) {
111:                   ((CodeTemplate)templates[i]).Text TextBox.TextAreaPainter.Buffer.Text;
112:               }
113:           }
114:           
115:           void EditEvent(object senderSystem.EventArgs e)
116:           {
117:               int GetCurrentIndex();
118:               if (!= -1) {
119:                   CodeTemplate t = (CodeTemplate)templates[i];
120:                   t new CodeTemplate(t.Shortcutt.Descriptiont.Text);
121:                   EditTemplateDialog etd new EditTemplateDialog(t);
122:                   if (etd.ShowDialog() == DialogResult.OK) {
123:                       templates[i] = t;
124:                   }
125:                   etd.Dispose();
126:                   BuildListView();
127:               }
128:           }
129:           
130:           void BuildListView()
131:           {
132:               listView1.Items.Clear();
133:               foreach (CodeTemplate t in templates) {
134:                   listView1.Items.Add(new ListViewItem(new string[] { t.Shortcutt.Description }));
135:               }
136:           }
137:           
138:           public CodeTemplatePane(MainWindow windowbase(Resource.GetString("Dialog.Options.CodeTemplatesText"))
139:           {
140:               InitializeComponents();
141:               
142:               TextBox new TextAreaControl(window);
143:               
144:               TextBox.TextAreaPainter.Buffer.SetHighlightingTo("C#");
145:               TextBox.TextAreaPainter.Buffer.Text "";
146:               TextBox.TextAreaPainter.ContextMenu null// FIXME : Make better MenuAction execute structure.
147:               
148:               TextBox.Size new System.Drawing.Size(328136);
149:               TextBox.TabIndex   1;
150:               TextBox.Location   new System.Drawing.Point(8184);
151:               
152:               TextBox.Anchor AnchorStyles.Top AnchorStyles.Bottom AnchorStyles.Left AnchorStyles.Right;
153:               panel1.Controls.Add(TextBox);
154:                           
155:   //            AcceptButton = okButton;
156:   //            CancelButton = cancelButton;
157:               removeButton.Click += new System.EventHandler(RemoveEvent);
158:               addButton.Click += new System.EventHandler(AddEvent);
159:               editButton.Click += new System.EventHandler(EditEvent);
160:               listView1.Activation ItemActivation.Standard;
161:               listView1.ItemActivate += new System.EventHandler(EditEvent);
162:               listView1.SelectedIndexChanged += new System.EventHandler(IndexChange);
163:               TextBox.TextAreaPainter.Buffer.Changed += new EventHandler(TextChange);
164:               BuildListView();
165:               IndexChange(nullnull);
166:   //            StartPosition = FormStartPosition.CenterParent;
167:   //            MaximizeBox  = MinimizeBox = false;
168:                       
169:           }
170:           
171:           // TODO : remove this hack
172:           // hack is 4 the bug in the code template window, if you press a shortcut key
173:           // the shortcut is activated, no matter if the alt key is pressed.
174:           // That's why I filter out the shortcuts from the buttons.
175:           string RemoveCh(string str)
176:           {
177:               string back "";
178:               for (int 0< str.Length; ++i)
179:                   if (str[i] != '&')
180:                       back += str[i];
181:               return back;
182:           }
183:           
184:           void InitializeComponents()
185:           {
186:               templates = (ArrayList)CodeTemplateLoader.Template.Clone();
187:               this.components new System.ComponentModel.Container();
188:               this.removeButton new System.Windows.Forms.Button();
189:               this.panel1 new System.Windows.Forms.Panel();
190:               this.Description new System.Windows.Forms.ColumnHeader();
191:   //            this.richTextBox1 = new System.Windows.Forms.RichTextBox();
192:               this.listView1 new System.Windows.Forms.ListView();
193:               this.editButton new System.Windows.Forms.Button();
194:               this.addButton new System.Windows.Forms.Button();
195:               this.Template new System.Windows.Forms.ColumnHeader();
196:               
197:               removeButton.Location new System.Drawing.Point(152 20152);
198:               removeButton.Size new System.Drawing.Size(7424);
199:               removeButton.TabIndex 7;
200:               removeButton.Text RemoveCh(Resource.GetString("Global.RemoveButtonText"));
201:               removeButton.Anchor AnchorStyles.Top AnchorStyles.Left;
202:               
203:               panel1.Size new System.Drawing.Size(352328);
204:               panel1.TabIndex 0;
205:               panel1.Text "panel1";
206:               panel1.Anchor AnchorStyles.Top AnchorStyles.BottomAnchorStyles.Right |AnchorStyles.Left;
207:               
208:               Description.Text RemoveCh(Resource.GetString("Dialog.Options.CodeTemplate.Description"));
209:               Description.Width 175;
210:               Description.TextAlign System.Windows.Forms.HorizontalAlignment.Left;
211:               
212:               listView1.Text "listView1";
213:               listView1.MultiSelect false;
214:               listView1.Size new System.Drawing.Size(256 64 16136);
215:               listView1.View System.Windows.Forms.View.Details;
216:               listView1.ForeColor System.Drawing.SystemColors.WindowText;
217:               listView1.TabIndex 0;
218:               listView1.Location new System.Drawing.Point(88);
219:               listView1.FullRowSelect true;
220:               listView1.GridLines   true;
221:               listView1.HideSelection false;
222:               listView1.Anchor AnchorStyles.Top AnchorStyles.Left AnchorStyles.Right;
223:               
224:   //          listView1.Sorting = SortOrder.Ascending;
225:               
226:               listView1.Columns.Add(Template);
227:               listView1.Columns.Add(Description);
228:                   
229:               editButton.Location new System.Drawing.Point(80 10152);
230:               editButton.Size new System.Drawing.Size(7424);
231:               editButton.TabIndex 3;
232:               editButton.Text RemoveCh(Resource.GetString("Global.ChangeButtonText"));
233:               editButton.Anchor AnchorStyles.Top AnchorStyles.Left;
234:               
235:               addButton.Location new System.Drawing.Point(8152);
236:               addButton.Size new System.Drawing.Size(7424);
237:               addButton.TabIndex 2;
238:               addButton.Text RemoveCh(Resource.GetString("Global.AddButtonText"));
239:               addButton.Anchor AnchorStyles.Top AnchorStyles.Left;
240:               
241:   //            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
242:   //            //@design this.TrayLargeIcon = true;
243:   //            //@design this.TrayHeight = 0;
244:               this.ClientSize new System.Drawing.Size(344325);
245:               
246:               Template.Text RemoveCh(Resource.GetString("Dialog.Options.CodeTemplate.Template"));
247:               Template.Width 77;
248:               Template.TextAlign System.Windows.Forms.HorizontalAlignment.Left;
249:               
250:               this.Controls.Add(panel1);
251:               panel1.Controls.Add(editButton);
252:               panel1.Controls.Add(removeButton);
253:               panel1.Controls.Add(addButton);
254:               panel1.Controls.Add(listView1);
255:               
256:           }
257:       }
258:   }

This page was automatically generated by SharpDevelop.