| 0: | // MainWindow.cs | |
| 1: | // Copyright (C) 2001 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.IO; | |
| 19: | using System.Collections; | |
| 20: | using System.Drawing; | |
| 21: | using System.Diagnostics; | |
| 22: | using System.Windows.Forms; | |
| 23: | using System.CodeDom.Compiler; | |
| 24: | using System.Resources; | |
| 25: | using System.Threading; | |
| 26: | using System.ComponentModel; | |
| 27: | using System.Xml; | |
| 28: | ||
| 29: | using SharpDevelop.Gui.Components; | |
| 30: | using SharpDevelop.Gui.Navigation; | |
| 31: | using SharpDevelop.Gui.Navigation.ProjectBrowser; | |
| 32: | using SharpDevelop.Gui.Window; | |
| 33: | using SharpDevelop.Tool.Data; | |
| 34: | using SharpDevelop.Tool.Function; | |
| 35: | using SharpDevelop.Internal.Modules; | |
| 36: | using SharpDevelop.Internal.Plugin; | |
| 37: | using SharpDevelop.Internal.Project; | |
| 38: | using SharpDevelop.Gui.Edit.Text; | |
| 39: | using SharpDevelop.Actions; | |
| 40: | using SharpDevelop.Gui.Docking; | |
| 41: | using SharpDevelop.Gui.Dialogs; | |
| 42: | using SharpDevelop.Tool.Text; | |
| 43: | ||
| 44: | using AxSHDocVw; | |
| 45: | ||
| 46: | using TimeSprint.Alexandria.UI.StatusBar; | |
| 47: | ||
| 48: | namespace SharpDevelop.Gui { | |
| 49: | ||
| 50: | /// <summary> | |
| 51: | /// This is the SharpDevelop main class, in this class the actions | |
| 52: | /// can find ANYTHING they need. | |
| 53: | /// </summary> | |
| 54: | public class MainWindow : Form, ISdPluginExecutor | |
| 55: | { | |
| 56: | public static MainWindow Window; | |
| 57: | ||
| 58: | DockManager dockmanager = null; | |
| 59: | ProjectBrowser projectbrowser = null; | |
| 60: | FileScout filescout; | |
| 61: | OpenTaskView compilerresultview = new OpenTaskView(); | |
| 62: | CompilerMessageView compilerMessageView = new CompilerMessageView(); | |
| 63: | public SharpToolBar sharptoolbar = null; | |
| 64: | ClassBrowser classBrowser; | |
| 65: | SideBarView sideBarView; | |
| 66: | ||
| 67: | ProgressBar statusProgressBar = new ProgressBar(); | |
| 68: | AxStatusBar statusBar = new AxStatusBar(); | |
| 69: | AxStatusBarPanel txtStatusBarPanel = new AxStatusBarPanel(); | |
| 70: | AxStatusBarPanel colStatusBarPanel = new AxStatusBarPanel(); | |
| 71: | AxStatusBarPanel rowStatusBarPanel = new AxStatusBarPanel(); | |
| 72: | AxStatusBarPanel modeStatusBarPanel = new AxStatusBarPanel(); | |
| 73: | ||
| 74: | TabControl openfiletab = new TabControl(); | |
| 75: | ||
| 76: | PluginManager pluginmanager = null; | |
| 77: | RecentOpen recentopen = null; // initialized later | |
| 78: | ||
| 79: | public DockableControlWrapper dockedsidebar; | |
| 80: | public DockableControlWrapper dockedproject; | |
| 81: | public DockableControlWrapper dockedfilescout; | |
| 82: | public DockableControlWrapper dockedcompresview; | |
| 83: | public DockableControlWrapper dockedcompmsgview; | |
| 84: | public DockableControlWrapper dockedopenfileview; | |
| 85: | public DockableControlWrapper dockedclassbrowser; | |
| 86: | ||
| 87: | public event EventHandler ProjectModeChanged; | |
| 88: | ||
| 89: | bool closewithoutask = false; | |
| 90: | bool projectmode = false; | |
| 91: | bool recompile = true; | |
| 92: | bool fullscreen = false; | |
| 93: | ||
| 94: | public SideBarView SideBarView { | |
| 95: | get { | |
| 96: | return sideBarView; | |
| 97: | } | |
| 98: | } | |
| 99: | ||
| 100: | /// <summary> | |
| 101: | /// Returns the full name of the current assembly which will be generated | |
| 102: | /// when the project is compiling. | |
| 103: | /// TODO : Get assembly name of single file. | |
| 104: | /// </summary> | |
| 105: | public string CurrentOutputAssembly { | |
| 106: | get { | |
| 107: | IProject project = ProjectBrowser.CurrentProject; | |
| 108: | if (project == null) { | |
| 109: | return null; | |
| 110: | } | |
| 111: | if (!(project.ActiveConfiguration is SdProjectConfigurationAdapter)) { | |
| 112: | throw new ApplicationException("Projectconfiguration must inherit from SdProjectConfigurationAdapter"); | |
| 113: | } | |
| 114: | SdProjectConfigurationAdapter spca = (SdProjectConfigurationAdapter)project.ActiveConfiguration; | |
| 115: | string[] files = Directory.GetFiles(spca.OutputDirectory, spca.OutputAssembly + ".*"); | |
| 116: | string filename = null; | |
| 117: | if (files.Length == 1) | |
| 118: | filename = files[0]; | |
| 119: | else { | |
| 120: | foreach (string fname in files) { | |
| 121: | switch (Path.GetExtension(fname).ToUpper()) { | |
| 122: | case ".DLL": | |
| 123: | filename = fname; | |
| 124: | break; | |
| 125: | case ".EXE": | |
| 126: | filename = fname; | |
| 127: | break; | |
| 128: | } | |
| 129: | } | |
| 130: | if (filename == null) { | |
| 131: | return null; | |
| 132: | } | |
| 133: | } | |
| 134: | return filename; | |
| 135: | } | |
| 136: | } | |
| 137: | ||
| 138: | ||
| 139: | ||
| 140: | public ClassBrowser ClassBrowser { | |
| 141: | get { | |
| 142: | return classBrowser; | |
| 143: | } | |
| 144: | } | |
| 145: | ||
| 146: | public MainWindow Main { | |
| 147: | get { | |
| 148: | return this; | |
| 149: | } | |
| 150: | } | |
| 151: | ||
| 152: | public bool CloseWithoutAsk { | |
| 153: | get { | |
| 154: | return closewithoutask; | |
| 155: | } | |
| 156: | set { | |
| 157: | closewithoutask = value; | |
| 158: | } | |
| 159: | } | |
| 160: | ||
| 161: | public PluginManager PluginManager { | |
| 162: | get { | |
| 163: | return pluginmanager; | |
| 164: | } | |
| 165: | } | |
| 166: | ||
| 167: | public string StatusBarText { | |
| 168: | get { | |
| 169: | return txtStatusBarPanel.Text; | |
| 170: | } | |
| 171: | set { | |
| 172: | txtStatusBarPanel.Text = StringParser.Parse(value, new string [,] {}); | |
| 173: | } | |
| 174: | } | |
| 175: | ||
| 176: | public RecentOpen RecentOpen { | |
| 177: | get { | |
| 178: | return recentopen; | |
| 179: | } | |
| 180: | } | |
| 181: | ||
| 182: | public TabControl OpenFileTab { | |
| 183: | get { | |
| 184: | return openfiletab; | |
| 185: | } | |
| 186: | } | |
| 187: | ||
| 188: | public OpenTaskView OpenTaskView { | |
| 189: | get { | |
| 190: | return compilerresultview; | |
| 191: | } | |
| 192: | } | |
| 193: | ||
| 194: | public ProjectBrowser ProjectBrowser { | |
| 195: | get { | |
| 196: | return projectbrowser; | |
| 197: | } | |
| 198: | } | |
| 199: | ||
| 200: | public CompilerMessageView CompilerMessageView { | |
| 201: | get { | |
| 202: | return compilerMessageView; | |
| 203: | } | |
| 204: | } | |
| 205: | ||
| 206: | public bool FullScreen { | |
| 207: | get { | |
| 208: | return fullscreen; | |
| 209: | } | |
| 210: | set { | |
| 211: | fullscreen = value; | |
| 212: | } | |
| 213: | } | |
| 214: | ||
| 215: | public bool ShouldRecompile { | |
| 216: | get { | |
| 217: | foreach (ContentWindow window in MdiChildren) { | |
| 218: | if (window.Dirty) | |
| 219: | return true; | |
| 220: | } | |
| 221: | if (recompile) | |
| 222: | return true; | |
| 223: | recompile = false; | |
| 224: | return false; | |
| 225: | } | |
| 226: | set { | |
| 227: | recompile = value; | |
| 228: | } | |
| 229: | } | |
| 230: | ||
| 231: | public virtual bool ProjectMode { | |
| 232: | get { | |
| 233: | return projectmode; | |
| 234: | } | |
| 235: | set { | |
| 236: | projectmode = value; | |
| 237: | OnProjectModeChanged(); | |
| 238: | } | |
| 239: | } | |
| 240: | ||
| 241: | public ContentWindow ActiveContentWindow { | |
| 242: | get { | |
| 243: | return (ContentWindow)ActiveMdiChild; | |
| 244: | } | |
| 245: | } | |
| 246: | ||
| 247: | public MainWindow() | |
| 248: | { | |
| 249: | Window = this; | |
| 250: | pluginmanager = new PluginManager(this); | |
| 251: | dockmanager = new DockManager(this); | |
| 252: | dockmanager.DockManagerState = (DockManagerState)Options.GetProperty("SharpDevelop.Gui.MainWindow.DockingWindows.DockManager", new DockManagerState()); | |
| 253: | InitMainWindow(); | |
| 254: | InitMainMenu(); | |
| 255: | InitOpenFileTab(); | |
| 256: | InitResultView(); | |
| 257: | InitNavigators(); | |
| 258: | InitStatusBar(); | |
| 259: | InitToolBar(); | |
| 260: | ||
| 261: | StandardStatusBar(null, null); | |
| 262: | ||
| 263: | AllowDrop = true; | |
| 264: | ||
| 265: | DragEnter += new DragEventHandler(DragEnterEvent); | |
| 266: | // DragOver += new DragEventHandler(DragOverEvent); | |
| 267: | DragDrop += new DragEventHandler(DragDropEvent); | |
| 268: | ||
| 269: | if (SharpDevelopMain.InitComplete != null) | |
| 270: | SharpDevelopMain.InitComplete(this, null); | |
| 271: | ||
| 272: | // new TestWindow().Show(); | |
| 273: | } | |
| 274: | ||
| 275: | void DragEnterEvent(object sender, DragEventArgs e) | |
| 276: | { | |
| 277: | if (e.Data != null && e.Data.GetDataPresent(DataFormats.FileDrop)) { | |
| 278: | e.Effect = DragDropEffects.Copy; | |
| 279: | } | |
| 280: | } | |
| 281: | ||
| 282: | void DragOverEvent(object sender, DragEventArgs e) | |
| 283: | { | |
| 284: | if (ClientRectangle.Contains(new Point(e.X, e.Y))) { | |
| 285: | e.Effect = DragDropEffects.Copy; | |
| 286: | } | |
| 287: | } | |
| 288: | ||
| 289: | void DragDropEvent(object sender, DragEventArgs e) | |
| 290: | { | |
| 291: | if (e.Data != null && e.Data.GetDataPresent(DataFormats.FileDrop)) { | |
| 292: | string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); | |
| 293: | foreach (string file in files) { | |
| 294: | if (!FSTypeUtility.IsDirectory(file)) { | |
| 295: | OpenWindow(file); | |
| 296: | } | |
| 297: | } | |
| 298: | openfiletab.SelectedIndex = openfiletab.TabPages.Count - 1; | |
| 299: | } | |
| 300: | } | |
| 301: | ||
| 302: | void OnProjectModeChanged() | |
| 303: | { | |
| 304: | if (ProjectModeChanged != null) { | |
| 305: | ProjectModeChanged(this, null); | |
| 306: | } | |
| 307: | } | |
| 308: | ||
| 309: | void FileTransaction(object message, EventArgs e) | |
| 310: | { | |
| 311: | statusProgressBar.Visible = true; | |
| 312: | StatusBarText = message.ToString(); | |
| 313: | } | |
| 314: | ||
| 315: | void FileTransactionProgress(object sender, int percent) | |
| 316: | { | |
| 317: | if (percent < 0 || percent > 100) { | |
| 318: | statusProgressBar.Visible = false; | |
| 319: | } | |
| 320: | ||
| 321: | if (statusProgressBar.Visible) | |
| 322: | statusProgressBar.Value = percent; | |
| 323: | } | |
| 324: | void FileTransactionComplete(object message, EventArgs e) | |
| 325: | { | |
| 326: | statusProgressBar.Visible = false; | |
| 327: | StatusBarText = message.ToString(); | |
| 328: | } | |
| 329: | ||
| 330: | void StandardStatusBar(object sender, EventArgs e) | |
| 331: | { | |
| 332: | StatusBarText = Resource.GetString("MainWindow.StatusBar.ReadyMessage"); | |
| 333: | } | |
| 334: | ||
| 335: | void SelectedTabIndexChange(object sender, System.EventArgs e) | |
| 336: | { | |
| 337: | TabPage item = openfiletab.SelectedTab; | |
| 338: | foreach (ContentWindow window in MdiChildren) { | |
| 339: | if (window.TabItem == item) { | |
| 340: | window.Select(); | |
| 341: | break; | |
| 342: | } | |
| 343: | } | |
| 344: | } | |
| 345: | ||
| 346: | void InitOpenFileTab() | |
| 347: | { | |
| 348: | openfiletab.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right; | |
| 349: | openfiletab.Size = new System.Drawing.Size(100, 26); | |
| 350: | openfiletab.Dock = DockStyle.Top; | |
| 351: | openfiletab.SelectedIndexChanged += new EventHandler(SelectedTabIndexChange); | |
| 352: | ||
| 353: | dockedopenfileview = new DockableControlWrapper(Resource.GetString("MainWindow.Windows.OpenFiles"), null, openfiletab); | |
| 354: | DockState state = (DockState)Options.GetProperty("SharpDevelop.Gui.MainWindow.DockingWindows.OpenFileView", new DockState()); | |
| 355: | dockmanager.Add(dockedopenfileview, state); | |
| 356: | ||
| 357: | // Controls.Add(openfiletab); | |
| 358: | new OpenFileTabEventHandler(this); | |
| 359: | } | |
| 360: | ||
| 361: | void InitResultView() | |
| 362: | { | |
| 363: | // splitter2.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D; | |
| 364: | // splitter2.Cursor = System.Drawing.Cursors.HSplit; | |
| 365: | // splitter2.RightToLeft = System.Windows.Forms.RightToLeft.Yes; | |
| 366: | // splitter2.Location = new System.Drawing.Point(0, 200); | |
| 367: | // splitter2.TabIndex = 5; | |
| 368: | // splitter2.TabStop = false; | |
| 369: | // splitter2.Size = new System.Drawing.Size(3, 273); | |
| 370: | // splitter2.Dock = DockStyle.Bottom; | |
| 371: | // | |
| 372: | compilerresultview.Dock = DockStyle.Bottom; | |
| 373: | ||
| 374: | compilerresultview.ItemActivate += new EventHandler(GotoError); | |
| 375: | ||
| 376: | dockedcompresview = new DockableControlWrapper(Resource.GetString("MainWindow.Windows.TaskList"), Resource.GetBitmap("Icons.16x16.TaskListIcon"), compilerresultview); | |
| 377: | DockState state = (DockState)Options.GetProperty("SharpDevelop.Gui.MainWindow.DockingWindows.CompilerResultView", new DockState()); | |
| 378: | state.Visible = true; | |
| 379: | dockmanager.Add(dockedcompresview, state); | |
| 380: | ||
| 381: | dockedcompmsgview = new DockableControlWrapper(Resource.GetString("MainWindow.Windows.OutputWindow"), Resource.GetBitmap("Icons.16x16.OutputIcon"), compilerMessageView); | |
| 382: | state = (DockState)Options.GetProperty("SharpDevelop.Gui.MainWindow.DockingWindows.CompilerMessageView", new DockState()); | |
| 383: | state.Visible = true; | |
| 384: | dockmanager.Add(dockedcompmsgview, state); | |
| 385: | ||
| 386: | // Controls.Add(splitter2); | |
| 387: | // Controls.Add(compilerresultview); | |
| 388: | HideOutputWindow(); | |
| 389: | } | |
| 390: | ||
| 391: | void InitNavigators() | |
| 392: | { | |
| 393: | projectbrowser = new ProjectBrowser(this); | |
| 394: | filescout = new FileScout(this); | |
| 395: | classBrowser = new ClassBrowser(this); | |
| 396: | sideBarView = new SideBarView(this); | |
| 397: | ||
| 398: | // TabControl tabControl1 = new System.Windows.Forms.TabControl(); | |
| 399: | // TabPage page1 = new TabPage(); | |
| 400: | // TabPage page2 = new TabPage(); | |
| 401: | // TabPage page3 = new TabPage(); | |
| 402: | // TabPage page4 = new TabPage(); | |
| 403: | // | |
| 404: | // Splitter splitter1 = new Splitter(); | |
| 405: | // | |
| 406: | // | |
| 407: | // | |
| 408: | // splitter1.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D; | |
| 409: | // splitter1.Cursor = System.Drawing.Cursors.VSplit; | |
| 410: | // splitter1.RightToLeft = System.Windows.Forms.RightToLeft.Yes; | |
| 411: | // splitter1.Location = new System.Drawing.Point(160, 0); | |
| 412: | // splitter1.TabIndex = 2; | |
| 413: | // splitter1.TabStop = false; | |
| 414: | // splitter1.Size = new System.Drawing.Size(3, 273); | |
| 415: | // splitter1.Dock = DockStyle.Left; | |
| 416: | // | |
| 417: | // tabControl1.Size = new System.Drawing.Size(155, 273); | |
| 418: | // tabControl1.SelectedIndex = 0; | |
| 419: | // tabControl1.Dock = DockStyle.Left; | |
| 420: | // tabControl1.TabIndex = 1; | |
| 421: | // | |
| 422: | classBrowser.Dock = DockStyle.Fill; | |
| 423: | ||
| 424: | ||
| 425: | ProjectBrowser.Dock = DockStyle.Fill; | |
| 426: | ||
| 427: | dockedproject = new DockableControlWrapper(Resource.GetString("MainWindow.Windows.ProjectScoutLabel"), Resource.GetBitmap("Icons.16x16.CombineIcon"), projectbrowser); | |
| 428: | DockState state = (DockState)Options.GetProperty("SharpDevelop.Gui.MainWindow.DockingWindows.ProjectBrowser", new DockState()); | |
| 429: | dockmanager.Add(dockedproject, state); | |
| 430: | ||
| 431: | dockedclassbrowser = new DockableControlWrapper(Resource.GetString("MainWindow.Windows.ClassScoutLabel"), Resource.GetBitmap("Icons.16x16.Class"), ClassBrowser); | |
| 432: | state = (DockState)Options.GetProperty("SharpDevelop.Gui.MainWindow.DockingWindows.ProjectBrowser", new DockState()); | |
| 433: | dockmanager.Add(dockedclassbrowser, state); | |
| 434: | ||
| 435: | ||
| 436: | dockedfilescout = new DockableControlWrapper(Resource.GetString("MainWindow.Windows.FileScoutLabel"), Resource.GetBitmap("Icons.16x16.OpenFolderBitmap"), filescout); | |
| 437: | state = (DockState)Options.GetProperty("SharpDevelop.Gui.MainWindow.DockingWindows.FileBrowser", new DockState()); | |
| 438: | dockmanager.Add(dockedfilescout, state); | |
| 439: | ||
| 440: | ||
| 441: | // TODO: side bar docking control. | |
| 442: | dockedsidebar = new DockableControlWrapper(Resource.GetString("MainWindow.Windows.ToolbarLabel"), Resource.GetBitmap("Icons.16x16.ToolBar"), sideBarView); | |
| 443: | state = (DockState)Options.GetProperty("SharpDevelop.Gui.MainWindow.DockingWindows.ToolBar", state); | |
| 444: | dockmanager.Add(dockedsidebar, state); | |
| 445: | ||
| 446: | // page1.Dock = DockStyle.Fill; | |
| 447: | // page1.Controls.Add(projectbrowser); | |
| 448: | // page1.Text = "PS"; | |
| 449: | // page1.ImageIndex = 0; | |
| 450: | // page1.ToolTipText = resources.GetString("ProjectScoutToolTip"); | |
| 451: | // | |
| 452: | // page2.Dock = DockStyle.Fill; | |
| 453: | // page2.Controls.Add(classbrowser); | |
| 454: | // page2.Text = "CS"; | |
| 455: | // page2.ImageIndex = 1; | |
| 456: | // page2.ToolTipText = resources.GetString("ClassBrowserToolTip"); | |
| 457: | // page2.Dock = DockStyle.Fill; | |
| 458: | // | |
| 459: | // page3.Controls.Add(filescout); | |
| 460: | // page3.Text = "FS"; | |
| 461: | // page3.ImageIndex = 2; | |
| 462: | // page3.ToolTipText = resources.GetString("FileScoutToolTip"); | |
| 463: | // | |
| 464: | // page4.Controls.Add(textlib); | |
| 465: | // page4.Text = "TL"; | |
| 466: | // page4.ImageIndex = 3; | |
| 467: | // page3.ToolTipText = resources.GetString("FileScoutToolTip"); | |
| 468: | // | |
| 469: | // ImageList imglist = new ImageList(); | |
| 470: | // imglist.ImageSize = new Size(18, 18); | |
| 471: | // imglist.Images.Add((Bitmap)resources.GetObject("ProjectScoutIcon")); | |
| 472: | // imglist.Images.Add((Bitmap)resources.GetObject("ClassBrowserIcon")); | |
| 473: | // imglist.Images.Add((Bitmap)resources.GetObject("FileScoutIcon")); | |
| 474: | // | |
| 475: | // tabControl1.ImageList = imglist; | |
| 476: | // | |
| 477: | // tabControl1.Controls.Add(page1); | |
| 478: | // tabControl1.Controls.Add(page2); | |
| 479: | // tabControl1.Controls.Add(page3); | |
| 480: | // tabControl1.Controls.Add(page4); | |
| 481: | // | |
| 482: | // Controls.Add(splitter1); | |
| 483: | // Controls.Add(tabControl1); | |
| 484: | // | |
| 485: | } | |
| 486: | ||
| 487: | void InitMainWindow() | |
| 488: | { | |
| 489: | Text = Resource.GetString("MainWindow.DialogName"); | |
| 490: | Icon = Resource.GetIcon("Icons.SharpDevelopIcon"); | |
| 491: | IsMdiContainer = true; | |
| 492: | ||
| 493: | // load recen open files/projects | |
| 494: | recentopen = (RecentOpen)Options.GetProperty("SharpDevelop.Gui.MainWindow.RecentOpen", new RecentOpen()); | |
| 495: | ||
| 496: | // set the old form start position | |
| 497: | MainWindowState state = (MainWindowState)Options.GetProperty("SharpDevelop.Gui.MainWindow.WindowState", new MainWindowState()); | |
| 498: | ||
| 499: | StartPosition = FormStartPosition.Manual; | |
| 500: | Bounds = state.Bounds; | |
| 501: | fullscreen = state.FullScreen; | |
| 502: | WindowState = state.WindowState; | |
| 503: | ||
| 504: | if (fullscreen) { | |
| 505: | FormBorderStyle = FormBorderStyle.None; | |
| 506: | } | |
| 507: | ||
| 508: | MenuComplete += new EventHandler(StandardStatusBar); | |
| 509: | MdiChildActivate += new EventHandler(CaretChanged); | |
| 510: | } | |
| 511: | ||
| 512: | void InitMainMenu() | |
| 513: | { | |
| 514: | XmlDocument mainmenu = new XmlDocument(); | |
| 515: | mainmenu.Load(Application.StartupPath + | |
| 516: | Path.DirectorySeparatorChar + ".." + | |
| 517: | Path.DirectorySeparatorChar + "data" + | |
| 518: | Path.DirectorySeparatorChar + "options" + | |
| 519: | Path.DirectorySeparatorChar + "MainMenuItems.xml"); | |
| 520: | ||
| 521: | MenuItem[] items = MenuCreator.CreateMenu(this, "SharpDevelop.Actions.Menu.", mainmenu.DocumentElement); | |
| 522: | Menu = new MainMenu(items); | |
| 523: | } | |
| 524: | ||
| 525: | void InitToolBar() | |
| 526: | { | |
| 527: | sharptoolbar = new SharpToolBar(this); | |
| 528: | sharptoolbar.Dock = DockStyle.Top; | |
| 529: | string str = Options.GetProperty("SharpDevelop.Gui.MainWindow.Standardtoolbar", true).ToString(); | |
| 530: | sharptoolbar.Visible = Boolean.Parse(str); | |
| 531: | ||
| 532: | Controls.Add(sharptoolbar); | |
| 533: | } | |
| 534: | ||
| 535: | void InitStatusBar() | |
| 536: | { | |
| 537: | // txtStatusBarPanel.BorderStyle = StatusBarPanelBorderStyle.None; | |
| 538: | txtStatusBarPanel.Width = 500; | |
| 539: | txtStatusBarPanel.AutoSize = StatusBarPanelAutoSize.Spring; | |
| 540: | ||
| 541: | // rowStatusBarPanel.BorderStyle = StatusBarPanelBorderStyle.Sunken; | |
| 542: | rowStatusBarPanel.Width = 50; | |
| 543: | rowStatusBarPanel.AutoSize = StatusBarPanelAutoSize.None; | |
| 544: | rowStatusBarPanel.Alignment = HorizontalAlignment.Right; | |
| 545: | ||
| 546: | // colStatusBarPanel.BorderStyle = StatusBarPanelBorderStyle.Sunken; | |
| 547: | colStatusBarPanel.Width = 50; | |
| 548: | colStatusBarPanel.AutoSize = StatusBarPanelAutoSize.None; | |
| 549: | colStatusBarPanel.Alignment = HorizontalAlignment.Right; | |
| 550: | ||
| 551: | // modeStatusBarPanel.BorderStyle = StatusBarPanelBorderStyle.Sunken; | |
| 552: | modeStatusBarPanel.Width = 35; | |
| 553: | modeStatusBarPanel.AutoSize = StatusBarPanelAutoSize.None; | |
| 554: | modeStatusBarPanel.Alignment = HorizontalAlignment.Right; | |
| 555: | ||
| 556: | statusProgressBar.Width = 150; | |
| 557: | statusProgressBar.Location = new Point(160, 0); | |
| 558: | statusProgressBar.Minimum = 0; | |
| 559: | statusProgressBar.Maximum = 100; | |
| 560: | statusBar.Controls.Add(statusProgressBar); | |
| 561: | statusProgressBar.Visible = false; | |
| 562: | ||
| 563: | statusBar.ShowPanels = true; | |
| 564: | ||
| 565: | statusBar.Panels.Add(txtStatusBarPanel); | |
| 566: | statusBar.Panels.Add(rowStatusBarPanel); | |
| 567: | statusBar.Panels.Add(colStatusBarPanel); | |
| 568: | statusBar.Panels.Add(modeStatusBarPanel); | |
| 569: | ||
| 570: | Controls.Add(statusBar); | |
| 571: | } | |
| 572: | ||
| 573: | void CaretChanged(object sender, EventArgs e) | |
| 574: | { | |
| 575: | Debug.Assert(sender != null, "SharpDevelop.Gui.MainWindow.CaretChanged(object sender, CancelEventArgs e) : sender can't be null."); | |
| 576: | ||
| 577: | Caret caret = null; | |
| 578: | if (typeof(Caret).IsInstanceOfType(sender)) | |
| 579: | caret = (Caret)sender; | |
| 580: | else { | |
| 581: | if (ActiveContentWindow == null || !ActiveContentWindow.HasTextArea) { | |
| 582: | if (ActiveContentWindow == null) | |
| 583: | statusBar.ShowPanels = false; | |
| 584: | else | |
| 585: | rowStatusBarPanel.Text = colStatusBarPanel.Text = modeStatusBarPanel.Text = ""; | |
| 586: | return; | |
| 587: | } | |
| 588: | caret = ActiveContentWindow.TextArea.Caret; | |
| 589: | } | |
| 590: | statusBar.ShowPanels = true; | |
| 591: | ||
| 592: | rowStatusBarPanel.Text = "ln " + (caret.CaretPos.Y + 1); | |
| 593: | colStatusBarPanel.Text = "col " + (caret.PhysicalCaretPos.X + 1); | |
| 594: | modeStatusBarPanel.Text = caret.InsertMode ? "INS" : "OVR"; | |
| 595: | } | |
| 596: | ||
| 597: | public void WindowClosingEvt(object sender, CancelEventArgs e) | |
| 598: | { | |
| 599: | if (closewithoutask || sender == null || !typeof(ContentWindow).IsInstanceOfType(sender)) | |
| 600: | return; | |
| 601: | ||
| 602: | ContentWindow window = (ContentWindow)sender; | |
| 603: | if (window.Dirty) { | |
| 604: | DialogResult dr = MessageBox.Show(this, | |
| 605: | Resource.GetString("MainWindow.SaveChangesMessage"), | |
| 606: | Resource.GetString("MainWindow.SaveChangesMessageHeader") + " " + window.Text + " ?", | |
| 607: | MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); | |
| 608: | switch (dr) { | |
| 609: | case DialogResult.Yes: | |
| 610: | SharpDevelop.Actions.Menu.SaveFile safefile = new SharpDevelop.Actions.Menu.SaveFile(); | |
| 611: | safefile.Execute(this); | |
| 612: | break; | |
| 613: | case DialogResult.No: | |
| 614: | break; | |
| 615: | case DialogResult.Cancel: | |
| 616: | e.Cancel = true; | |
| 617: | return; | |
| 618: | } | |
| 619: | } | |
| 620: | } | |
| 621: | ||
| 622: | void GotoError(object sender, System.EventArgs e) | |
| 623: | { | |
| 624: | CompilerResultListItem li = (CompilerResultListItem)OpenTaskView.FocusedItem; | |
| 625: | ||
| 626: | string filename = li.FileName; | |
| 627: | ||
| 628: | if (filename == null || filename.Equals("")) | |
| 629: | return; | |
| 630: | ||
| 631: | if (File.Exists(filename)) { | |
| 632: | ||
| 633: | string directory = Path.GetDirectoryName(filename); | |
| 634: | if (directory[directory.Length - 1] != Path.DirectorySeparatorChar) | |
| 635: | directory += Path.DirectorySeparatorChar; | |
| 636: | ||
| 637: | ContentWindow window = OpenWindow(filename); | |
| 638: | Point pos = window.TextArea.Caret.CaretPos; | |
| 639: | window.TextArea.Caret.CaretPos = li.Pos; | |
| 640: | window.TextArea.CenterCaret(); | |
| 641: | } | |
| 642: | } | |
| 643: | ||
| 644: | protected override void OnClosing(CancelEventArgs e) | |
| 645: | { | |
| 646: | if (ProjectMode) { | |
| 647: | projectbrowser.SaveProject(); | |
| 648: | } | |
| 649: | ||
| 650: | if (closewithoutask) { | |
| 651: | bool showdirtyfiles = false; | |
| 652: | foreach (ContentWindow window in MdiChildren) { | |
| 653: | if (window.Dirty) { | |
| 654: | showdirtyfiles = true; | |
| 655: | break; | |
| 656: | } | |
| 657: | } | |
| 658: | if (showdirtyfiles) { | |
| 659: | DirtyFilesDialog dialog = new DirtyFilesDialog(this); | |
| 660: | dialog.Owner = this; | |
| 661: | if (dialog.ShowDialog() == DialogResult.Cancel) { | |
| 662: | e.Cancel = true; | |
| 663: | return; | |
| 664: | } | |
| 665: | } | |
| 666: | } | |
| 667: | ||
| 668: | Options.SetProperty("SharpDevelop.Gui.MainWindow.Standardtoolbar", sharptoolbar.Visible); | |
| 669: | ||
| 670: | Options.SetProperty("SharpDevelop.Gui.MainWindow.DockingWindows.ProjectBrowser", dockedproject.DockState); | |
| 671: | Options.SetProperty("SharpDevelop.Gui.MainWindow.DockingWindows.FileBrowser", dockedfilescout.DockState); | |
| 672: | Options.SetProperty("SharpDevelop.Gui.MainWindow.DockingWindows.Toolbar", dockedsidebar.DockState); | |
| 673: | Options.SetProperty("SharpDevelop.Gui.MainWindow.DockingWindows.OpenFileView", dockedopenfileview.DockState); | |
| 674: | Options.SetProperty("SharpDevelop.Gui.MainWindow.DockingWindows.CompilerResultView", dockedcompresview.DockState); | |
| 675: | Options.SetProperty("SharpDevelop.Gui.MainWindow.DockingWindows.CompilerMessageView", dockedcompmsgview.DockState); | |
| 676: | Options.SetProperty("SharpDevelop.Gui.MainWindow.DockingWindows.DockManager", dockmanager.DockManagerState); | |
| 677: | ||
| 678: | Options.SetProperty("SharpDevelop.Gui.MainWindow.WindowState", new MainWindowState(this)); | |
| 679: | Options.SetProperty("SharpDevelop.Gui.MainWindow.RecentOpen", recentopen); | |
| 680: | sideBarView.SaveSideBarViewConfig(); | |
| 681: | base.OnClosing(e); | |
| 682: | } | |
| 683: | ||
| 684: | public ContentWindow OpenWindow(string filename, WindowContent windowcontent, string language) | |
| 685: | { | |
| 686: | if (windowcontent != WindowContent.Browser && (filename == null || !FSTypeUtility.TestFileExists(filename))) { | |
| 687: | return null; | |
| 688: | } | |
| 689: | ||
| 690: | foreach (ContentWindow window in MdiChildren) | |
| 691: | if (filename == window.FileName) { | |
| 692: | window.Select(); | |
| 693: | window.Focus(); | |
| 694: | return window; | |
| 695: | } | |
| 696: | ||
| 697: | RecentOpen.AddLastFile(filename); | |
| 698: | ContentWindow newwindow = new ContentWindow(this, windowcontent, null, language); | |
| 699: | newwindow.ISdEditable.FileTransaction += new EventHandler(FileTransaction); | |
| 700: | newwindow.ISdEditable.FileTransactionProgress += new SharpDevelop.Gui.Edit.ProgressEventHandler(FileTransactionProgress); | |
| 701: | newwindow.ISdEditable.FileTransactionComplete += new EventHandler(FileTransactionComplete); | |
| 702: | newwindow.LoadContent(filename); | |
| 703: | newwindow.Closing += new CancelEventHandler(WindowClosingEvt); | |
| 704: | if (newwindow.HasTextArea) { | |
| 705: | newwindow.TextArea.Caret.Changed += new EventHandler(CaretChanged); | |
| 706: | } | |
| 707: | if (compilerresultview.CompilerResults != null) { | |
| 708: | ShowErrors(compilerresultview.CompilerResults); | |
| 709: | } | |
| 710: | ||
| 711: | newwindow.Show(); | |
| 712: | newwindow.Select(); | |
| 713: | return newwindow; | |
| 714: | } | |
| 715: | ||
| 716: | public ContentWindow OpenWindow(string filename) | |
| 717: | { | |
| 718: | if (filename == null || !FSTypeUtility.TestFileExists(filename)) { | |
| 719: | return null; | |
| 720: | } | |
| 721: | ||
| 722: | string language = null; | |
| 723: | WindowContent windowcontent = WindowContent.Text; | |
| 724: | Module info = ModuleManager.GetModulePerFileName(filename); | |
| 725: | ||
| 726: | if (info != null) { | |
| 727: | windowcontent = WindowContent.CSFile; | |
| 728: | language = info.Language; | |
| 729: | } | |
| 730: | return OpenWindow(filename, windowcontent, language); | |
| 731: | } | |
| 732: | ||
| 733: | public void ShowOutputWindow() | |
| 734: | { | |
| 735: | if (!dockedcompresview.DockState.Visible) { | |
| 736: | dockedcompresview.ShowDockedControl(); | |
| 737: | dockedcompmsgview.ShowDockedControl(); | |
| 738: | } | |
| 739: | // CompilerResultView.Show(); | |
| 740: | } | |
| 741: | ||
| 742: | public void ShowErrors(CompilerResults res) | |
| 743: | { | |
| 744: | foreach (ContentWindow window in MdiChildren) { | |
| 745: | if (window.HasTextArea && !window.Untitled) { | |
| 746: | foreach (CompilerError err in res.Errors) { | |
| 747: | string path = err.FileName; | |
| 748: | if (path == window.FileName) { | |
| 749: | int length = 1; | |
| 750: | while (err.Line - 1 > 0 && err.Line - 1 < window.TextArea.Buffer.Length && | |
| 751: | err.Column - 1 + length < window.TextArea.Buffer[err.Line - 1].Text.Length && | |
| 752: | !Char.IsWhiteSpace(window.TextArea.Buffer[err.Line - 1].Text[err.Column - 1 + length])) | |
| 753: | ++length; | |
| 754: | if (window.TextArea.ErrorDrawer.AddError(new VisualError(err.Line - 1, err.Column - 1, length, err.ErrorText))) { | |
| 755: | window.TextArea.InvalidateLines(err.Column, 1, err.Line, err.Line); | |
| 756: | } | |
| 757: | } | |
| 758: | } | |
| 759: | } | |
| 760: | } | |
| 761: | } | |
| 762: | ||
| 763: | public void HideOutputWindow() | |
| 764: | { | |
| 765: | dockedcompmsgview.HideDockedControl(); | |
| 766: | dockedcompresview.HideDockedControl(); | |
| 767: | // CompilerResultView.Hide(); | |
| 768: | } | |
| 769: | } | |
| 770: | ||
| 771: | ||
| 772: | public class IDEOptions | |
| 773: | { | |
| 774: | public string Culture { | |
| 775: | get { | |
| 776: | return Options.GetProperty("SharpDevelop.Gui.UILanguage", Thread.CurrentThread.CurrentUICulture.Name).ToString(); | |
| 777: | } | |
| 778: | set { | |
| 779: | Options.SetProperty("SharpDevelop.Gui.UILanguage", value); | |
| 780: | } | |
| 781: | } | |
| 782: | public IconMenuStyle IconMenuStyle { | |
| 783: | get { | |
| 784: | return (IconMenuStyle)Enum.Parse(typeof(IconMenuStyle),Options.GetProperty("IconMenuItem.IconMenuStyle", IconMenuStyle.VSNet).ToString()); | |
| 785: | } | |
| 786: | set { | |
| 787: | Options.SetProperty("IconMenuItem.IconMenuStyle", value.ToString()); | |
| 788: | } | |
| 789: | } | |
| 790: | } | |
| 791: | } |
This page was automatically generated by SharpDevelop.