⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainwindow.cs

📁 c#精彩编程百例(源代码)
💻 CS
📖 第 1 页 / 共 2 页
字号:
			projectbrowser = new ProjectBrowser(this);
			filescout = new FileScout(this);
			TextLib textlib = new TextLib(this);
			
//			TabControl tabControl1 = new System.Windows.Forms.TabControl();
//			TabPage    page1       = new TabPage();
//			TabPage    page2       = new TabPage();
//			TabPage    page3       = new TabPage();
//			TabPage    page4       = new TabPage();
//			
//			Splitter   splitter1   = new Splitter();
//			
//			
//			
//			splitter1.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
//				splitter1.Cursor = System.Drawing.Cursors.VSplit;
//			splitter1.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
//			splitter1.Location = new System.Drawing.Point(160, 0);
//			splitter1.TabIndex = 2;
//			splitter1.TabStop = false;
//			splitter1.Size = new System.Drawing.Size(3, 273);
//			splitter1.Dock = DockStyle.Left;
//			
//			tabControl1.Size = new System.Drawing.Size(155, 273);
//			tabControl1.SelectedIndex = 0;
//			tabControl1.Dock = DockStyle.Left;
//			tabControl1.TabIndex = 1;
//			
//			classbrowser.Dock = DockStyle.Fill;
			
			
			ProjectBrowser.Dock = DockStyle.Fill;
			
			dockedproject = new DockableControlWrapper("Project Scout", "PS", projectbrowser);
			DockState state = (DockState)Option.GetProperty("SharpDevelop.Gui.MainWindow.DockingWindows.ProjectBrowser", new DockState());
			dockmanager.Add(dockedproject, state);
			
			dockedfilescout = new DockableControlWrapper("File Scout", "FS", filescout);
			state = (DockState)Option.GetProperty("SharpDevelop.Gui.MainWindow.DockingWindows.FileBrowser", new DockState());
			dockmanager.Add(dockedfilescout, state);

			dockedtextlib = new DockableControlWrapper("Text Lib", "TL", textlib);
			state = (DockState)Option.GetProperty("SharpDevelop.Gui.MainWindow.DockingWindows.TextLib", new DockState());
			dockmanager.Add(dockedtextlib, state);
			
//			page1.Dock = DockStyle.Fill;
//			page1.Controls.Add(projectbrowser);
//			page1.Text = "PS";
//			page1.ImageIndex   = 0;
//			page1.ToolTipText  = resources.GetString("ProjectScoutToolTip");
//			
//			page2.Dock = DockStyle.Fill;
//			page2.Controls.Add(classbrowser);
//			page2.Text = "CS";
//			page2.ImageIndex   = 1;
//			page2.ToolTipText  = resources.GetString("ClassBrowserToolTip");
//			page2.Dock = DockStyle.Fill;
//			
//			page3.Controls.Add(filescout);
//			page3.Text = "FS";
//			page3.ImageIndex   = 2;
//			page3.ToolTipText  = resources.GetString("FileScoutToolTip"); 
//				
//			page4.Controls.Add(textlib);
//			page4.Text = "TL";
//			page4.ImageIndex   = 3;
//			page3.ToolTipText  = resources.GetString("FileScoutToolTip"); 
//			
//			ImageList imglist = new ImageList();
//			imglist.ImageSize = new Size(18, 18);
//			imglist.Images.Add((Bitmap)resources.GetObject("ProjectScoutIcon"));
//			imglist.Images.Add((Bitmap)resources.GetObject("ClassBrowserIcon"));
//			imglist.Images.Add((Bitmap)resources.GetObject("FileScoutIcon"));
//			
//			tabControl1.ImageList = imglist;
//			
//			tabControl1.Controls.Add(page1);
//			tabControl1.Controls.Add(page2);
//			tabControl1.Controls.Add(page3);
//			tabControl1.Controls.Add(page4);
//			
//			Controls.Add(splitter1);
//			Controls.Add(tabControl1);
//			
		}
		
		void InitMainWindow()
		{
			Text = Resource.GetString("MainWindow.DialogName");
			Icon = Resource.GetIcon("Icons.SharpDevelopIcon");
			IsMdiContainer = true;
			
			// load recen open files/projects
			recentopen = (RecentOpen)Option.GetProperty("SharpDevelop.Gui.MainWindow.RecentOpen", new RecentOpen());
			
			// set the old form start position
			MainWindowState state = (MainWindowState)Option.GetProperty("SharpDevelop.Gui.MainWindow.WindowState", new MainWindowState());
			
			StartPosition = FormStartPosition.Manual;
			WindowState   = state.WindowState;
			DesktopBounds = state.Bounds;
			fullscreen    = state.FullScreen;
			if (fullscreen)
				FormBorderStyle = FormBorderStyle.None;
			
			MenuComplete += new EventHandler(StandardStatusBar);
			MdiChildActivate += new EventHandler(CaretChanged);
		}
		
		void InitMainMenu()
		{
			XmlDocument mainmenu = new XmlDocument();
			mainmenu.Load(Application.StartupPath + "\\options\\MainMenuItems.xml");
				
			MenuItem[] items = MenuCreator.CreateMenu(this, "SharpDevelop.Actions.Menu.", mainmenu.DocumentElement);	
			Menu = new MainMenu(items);
		}
		
		void InitToolBar()
		{
			sharptoolbar = new SharpToolBar(this);
			sharptoolbar.Dock = DockStyle.Top;
			string str = Option.GetProperty("SharpDevelop.Gui.MainWindow.Standardtoolbar", true).ToString();
			sharptoolbar.Visible = Boolean.Parse(str);
			
			Controls.Add(sharptoolbar);
		}
		
		void InitStatusBar()
		{
			txtStatusBarPanel.BorderStyle = StatusBarPanelBorderStyle.None;
			txtStatusBarPanel.Width = 500;
			txtStatusBarPanel.AutoSize = StatusBarPanelAutoSize.Spring;
			
			rowStatusBarPanel.BorderStyle = StatusBarPanelBorderStyle.Sunken;
			rowStatusBarPanel.Width = 50;
			rowStatusBarPanel.AutoSize = StatusBarPanelAutoSize.None;
			rowStatusBarPanel.Alignment = HorizontalAlignment.Right;
			
			colStatusBarPanel.BorderStyle = StatusBarPanelBorderStyle.Sunken;
			colStatusBarPanel.Width = 50;                      
			colStatusBarPanel.AutoSize = StatusBarPanelAutoSize.None;
			colStatusBarPanel.Alignment = HorizontalAlignment.Right;
			
			modeStatusBarPanel.BorderStyle = StatusBarPanelBorderStyle.Sunken;
			modeStatusBarPanel.Width = 30;
			modeStatusBarPanel.AutoSize = StatusBarPanelAutoSize.None;
			modeStatusBarPanel.Alignment = HorizontalAlignment.Right;
			
			loadCancelButton.Text     = "Cancel"; // TODO
			loadCancelButton.Size     = new Size(72, 20);
			loadCancelButton.Location = new Point(160 * 2, 0);
			loadCancelButton.Visible  = false;
			
			statusBar.Controls.Add(loadCancelButton);
			
			statusProgressBar.Width = 150;
			statusProgressBar.Location = new Point(160, 0);
			statusProgressBar.Minimum = 0;
			statusProgressBar.Maximum = 100;
			statusBar.Controls.Add(statusProgressBar);
			statusProgressBar.Visible = false;
			
			statusBar.ShowPanels = true;
			
			statusBar.Panels.Add(txtStatusBarPanel);
			statusBar.Panels.Add(rowStatusBarPanel);
			statusBar.Panels.Add(colStatusBarPanel);
			statusBar.Panels.Add(modeStatusBarPanel);
			
			Controls.Add(statusBar);
		}
		
		void CaretChanged(object sender, EventArgs e)
		{
			Debug.Assert(sender != null, "SharpDevelop.Gui.MainWindow.CaretChanged(object sender, CancelEventArgs e) : sender can't be null.");
			
			Caret caret = null;
			if (typeof(Caret).IsInstanceOfType(sender))
				caret = (Caret)sender;
			else {
				if (ActiveContentWindow == null || !ActiveContentWindow.HasTextArea) {
					if (ActiveContentWindow == null)
						statusBar.ShowPanels = false;
					else 
						rowStatusBarPanel.Text = colStatusBarPanel.Text = modeStatusBarPanel.Text = "";
					return;
				}
				caret = ActiveContentWindow.TextArea.Caret;
			}
			statusBar.ShowPanels = true;
			
			rowStatusBarPanel.Text = "ln " + caret.CaretPos.Y;
			colStatusBarPanel.Text = "col " + caret.PhysicalCaretPos.X;
			modeStatusBarPanel.Text = caret.InsertMode ? "INS" : "OVR";
		}
		
		public void WindowClosingEvt(object sender, CancelEventArgs e)
		{
			if (closewithoutask || sender == null || !typeof(ContentWindow).IsInstanceOfType(sender))
				return;
			
			ContentWindow window = (ContentWindow)sender;
			if (window.Dirty) {
				DialogResult dr = MessageBox.Show(this,
					Resource.GetString("MainWindow.SaveChangesMessage"),
					Resource.GetString("MainWindow.SaveChangesMessageHeader") + " " + window.Text + " ?",
					MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
				switch (dr) {
					case DialogResult.Yes:
						SharpDevelop.Actions.Menu.SaveFile safefile = new SharpDevelop.Actions.Menu.SaveFile();
						safefile.Execute(this);
					break;
					case DialogResult.No:
					break;
					case DialogResult.Cancel:
						e.Cancel = true;
					return;
				}
			}
		}
		
		void GotoError(object sender, System.EventArgs e)
		{
			CompilerResultListItem li = (CompilerResultListItem)CompilerResultView.FocusedItem;
			
			string filename   = li.FileName;
			
			if (filename == null || filename.Equals(""))
				return;
			
			if (File.Exists(filename)) {
				
				string directory  = Path.GetDirectoryName(filename);
				if (directory[directory.Length - 1] != '\\')
					directory += "\\";
				
				ContentWindow window = OpenWindow(filename);
				Point pos = window.TextArea.Caret.CaretPos;
				window.TextArea.Caret.CaretPos = li.Pos;
				window.TextArea.CenterCaret();
			}
		}
		
		protected override void OnClosing(CancelEventArgs e)
		{
			if (closewithoutask) {
				bool showdirtyfiles = false;
				foreach (ContentWindow window in MdiChildren) {
					if (window.Dirty) {
						showdirtyfiles = true;
						break;
					}
				}
				if (showdirtyfiles) {
					DirtyFilesDialog dialog = new DirtyFilesDialog(this);
					dialog.Owner = this;
					if (dialog.ShowDialog() == DialogResult.Cancel) {
						e.Cancel = true;
						return;
					}
				}
			}
			
			Option.SetProperty("SharpDevelop.Gui.MainWindow.Standardtoolbar", sharptoolbar.Visible);
			
			Option.SetProperty("SharpDevelop.Gui.MainWindow.DockingWindows.ProjectBrowser", dockedproject.DockState);
			Option.SetProperty("SharpDevelop.Gui.MainWindow.DockingWindows.FileBrowser", dockedfilescout.DockState);
			Option.SetProperty("SharpDevelop.Gui.MainWindow.DockingWindows.TextLib", dockedtextlib.DockState);
			Option.SetProperty("SharpDevelop.Gui.MainWindow.DockingWindows.OpenFileView", dockedopenfileview.DockState);
			Option.SetProperty("SharpDevelop.Gui.MainWindow.DockingWindows.CompilerResultView", dockedcompresview.DockState);
			Option.SetProperty("SharpDevelop.Gui.MainWindow.DockingWindows.DockManager", dockmanager.DockManagerState);
			
			Option.SetProperty("SharpDevelop.Gui.MainWindow.WindowState", new MainWindowState(this));
			Option.SetProperty("SharpDevelop.Gui.MainWindow.RecentOpen", recentopen);
			base.OnClosing(e);
		}
		
		public ContentWindow OpenWindow(string filename, WindowContent windowcontent, string language)
		{
				if (windowcontent != WindowContent.Browser && (filename == null || !FSTypeUtility.TestFileExists(filename)))
					return null;
				
				foreach (ContentWindow window in MdiChildren)
					if (filename == window.FileName) {
						window.Select();
						window.Focus();
						return window;
					}
				
				RecentOpen.AddLastFile(filename);
				ContentWindow newwindow = new ContentWindow(this, windowcontent, null, language);
				newwindow.ISdEditable.FileTransaction += new EventHandler(FileTransaction);
				newwindow.ISdEditable.FileTransactionProgress += new SharpDevelop.Gui.Edit.ProgressEventHandler(FileTransactionProgress);
				newwindow.ISdEditable.FileTransactionComplete += new EventHandler(FileTransactionComplete);
				newwindow.LoadContent(filename);
				newwindow.Show();
				newwindow.Select();
				newwindow.Closing += new CancelEventHandler(WindowClosingEvt);
				if (newwindow.HasTextArea) {
					newwindow.TextArea.Caret.Changed += new EventHandler(CaretChanged);
				}
				if (compilerresultview.CompilerResults != null)
					ShowErrors(compilerresultview.CompilerResults); 
				
				return newwindow;
		}
		
		public ContentWindow OpenWindow(string filename)
		{
			if (filename == null || !FSTypeUtility.TestFileExists(filename))
				return null;
			
			string        language      = null;
			WindowContent windowcontent = WindowContent.Text;
			Module info = ModuleManager.GetModulePerFileName(filename);
			
			if (info != null) {
				windowcontent = WindowContent.CSFile;
				language      = info.Language;
			}
			return OpenWindow(filename, windowcontent, language);
		}		
		
		public void ShowOutputWindow()
		{
			dockedcompresview.ShowDockedControl();
//			CompilerResultView.Show();
		}
		
		public void ShowErrors(CompilerResults res)
	    {
	    	foreach (ContentWindow window in MdiChildren) {
	    		if (window.HasTextArea && !window.Untitled) {
					foreach (CompilerError err in res.Errors) {
						string path = err.FileName;
						if (path == window.FileName) {
							int length = 1;
							while (err.Line - 1 > 0 && err.Line - 1 < window.TextArea.Buffer.Length &&
								   err.Column - 1 + length < window.TextArea.Buffer[err.Line - 1].Text.Length &&
								   !Char.IsWhiteSpace(window.TextArea.Buffer[err.Line - 1].Text[err.Column - 1 + length]))
								++length;
							if (window.TextArea.ErrorDrawer.AddError(new VisualError(err.Line - 1, err.Column - 1, length, err.ErrorText))) {
								window.TextArea.InvalidateLines(err.Column, 1, err.Line, err.Line);
							}
						}
					}
	    		}
	    	}
	    }
	    
		public void HideOutputWindow()
		{
			dockedcompresview.HideDockedControl();
//			CompilerResultView.Hide();
		}
	}
	
	
	public class IDEOptions
	{
		public string Culture {
			get {
				return Option.GetProperty("SharpDevelop.Gui.UILanguage", Thread.CurrentThread.CurrentUICulture.Name).ToString();
			}
			set {
				Option.SetProperty("SharpDevelop.Gui.UILanguage", value);
			}
		}
		public IconMenuStyle IconMenuStyle {
			get {
				return (IconMenuStyle)Enum.Parse(typeof(IconMenuStyle),Option.GetProperty("IconMenuItem.IconMenuStyle", IconMenuStyle.VSNet).ToString());
			}
			set {
				Option.SetProperty("IconMenuItem.IconMenuStyle", value.ToString());
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -