| 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 |