📄 mainwindow.cs
字号:
// MainWindow.cs
// Copyright (C) 2001 Mike Krueger
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using System;
using System.IO;
using System.Collections;
using System.Drawing;
using System.Diagnostics;
using System.Windows.Forms;
using System.CodeDom.Compiler;
using System.Resources;
using System.Threading;
using System.ComponentModel;
using System.Xml;
using SharpDevelop.Gui.Components;
using SharpDevelop.Gui.Navigation;
using SharpDevelop.Gui.Navigation.ProjectBrowser;
using SharpDevelop.Gui.Window;
using SharpDevelop.Tool.Data;
using SharpDevelop.Tool.Function;
using SharpDevelop.Internal.Modules;
using SharpDevelop.Internal.Plugin;
using SharpDevelop.Internal.Project;
using SharpDevelop.Gui.Edit.Text;
using SharpDevelop.Actions;
using SharpDevelop.Gui.Docking;
using SharpDevelop.Gui.Dialogs;
using SharpDevelop.Tool.Text;
using AxSHDocVw;
namespace SharpDevelop.Gui {
// public class TestWindow : Form
// {
// public AxWebBrowser AxWebBrowser1 = null;
//
// public override void Dispose()
// {
// base.Dispose();
// AxWebBrowser1.Dispose();
// }
//
// public TestWindow()
// {
// AxWebBrowser1 = new AxSHDocVw.AxWebBrowser();
// AxWebBrowser1.Location = new Point(0, 0);
// AxWebBrowser1.Size = new Size(100, 100);
// AxWebBrowser1.Dock = DockStyle.Fill;
//
// AxWebBrowser1.HandleCreated += new EventHandler(this.AxWebBrowser1_Created);
//
// Controls.Add(AxWebBrowser1);
// }
//
//
// public void AxWebBrowser1_Created(object sender, EventArgs evArgs)
// {
// AxWebBrowser1.HandleCreated -= new EventHandler(this.AxWebBrowser1_Created);
// Navigate("C:\\aufg1.cc");
// Thread t = new Thread(new ThreadStart(start));
// t.Start();
// }
//
// void start()
// {
// while (true) {
// IHTMLDocument2 document = (IHTMLDocument2)AxWebBrowser1.Document;
// if (document != null) {
// IHTMLElement body = document.GetBody();
// if (body != null) {
// body.SetInnerText("Hello World");
// }
// break;
// }
// }
// }
// public void Navigate(string name)
// {
// object arg1 = 0;
// object arg2 = "";
// object arg3 = "";
// object arg4 = "";
// try {
// AxWebBrowser1.Navigate(name, ref arg1, ref arg2, ref arg3, ref arg4);
// } catch (Exception e) {
// Console.WriteLine(e.ToString());
// }
// }
// }
/// <summary>
/// This is the SharpDevelop main class, in this class the actions
/// can find ANYTHING they need.
/// </summary>
public class MainWindow : Form, ISdPluginExecutor
{
DockManager dockmanager = null;
ProjectBrowser projectbrowser = null;
// ClassBrowser classbrowser = new ClassBrowser();
FileScout filescout;
CompilerResultView compilerresultview = new CompilerResultView();
public SharpToolBar sharptoolbar = null;
Button loadCancelButton = new Button();
ProgressBar statusProgressBar = new ProgressBar();
StatusBar statusBar = new StatusBar();
StatusBarPanel txtStatusBarPanel = new StatusBarPanel();
StatusBarPanel colStatusBarPanel = new StatusBarPanel();
StatusBarPanel rowStatusBarPanel = new StatusBarPanel();
StatusBarPanel modeStatusBarPanel = new StatusBarPanel();
TabControl openfiletab = new TabControl();
PluginManager pluginmanager = null;
RecentOpen recentopen = null; // initialized later
public DockableControlWrapper dockedproject;
public DockableControlWrapper dockedfilescout;
public DockableControlWrapper dockedtextlib;
public DockableControlWrapper dockedcompresview;
public DockableControlWrapper dockedopenfileview;
public event EventHandler ProjectModeChanged;
bool closewithoutask = false;
bool projectmode = false;
bool recompile = true;
bool fullscreen = false;
public MainWindow Main {
get {
return this;
}
}
public bool CloseWithoutAsk {
get {
return closewithoutask;
}
set {
closewithoutask = value;
}
}
public PluginManager PluginManager {
get {
return pluginmanager;
}
}
public string StatusBarText {
get {
return txtStatusBarPanel.Text;
}
set {
txtStatusBarPanel.Text = StringParser.Parse(value, new string [,] {});
}
}
public RecentOpen RecentOpen {
get {
return recentopen;
}
}
public TabControl OpenFileTab {
get {
return openfiletab;
}
}
public CompilerResultView CompilerResultView {
get {
return compilerresultview;
}
}
public ProjectBrowser ProjectBrowser {
get {
return projectbrowser;
}
}
public bool FullScreen {
get {
return fullscreen;
}
set {
fullscreen = value;
}
}
public bool ShouldRecompile {
get {
foreach (ContentWindow window in MdiChildren) {
if (window.Dirty)
return true;
}
if (recompile)
return true;
recompile = false;
return false;
}
set {
recompile = value;
}
}
public virtual bool ProjectMode {
get {
return projectmode;
}
set {
projectmode = value;
OnProjectModeChanged();
}
}
public ContentWindow ActiveContentWindow {
get {
return (ContentWindow)ActiveMdiChild;
}
}
public MainWindow()
{
pluginmanager = new PluginManager(this);
dockmanager = new DockManager(this);
dockmanager.DockManagerState = (DockManagerState)Option.GetProperty("SharpDevelop.Gui.MainWindow.DockingWindows.DockManager", new DockManagerState());
InitMainWindow();
InitMainMenu();
InitOpenFileTab();
InitResultView();
InitNavigators();
InitStatusBar();
InitToolBar();
StandardStatusBar(null, null);
AllowDrop = true;
DragEnter += new DragEventHandler(DragEnterEvent);
// DragOver += new DragEventHandler(DragOverEvent);
DragDrop += new DragEventHandler(DragDropEvent);
if (SharpDevelopMain.InitComplete != null)
SharpDevelopMain.InitComplete(this, null);
// new TestWindow().Show();
}
void DragEnterEvent(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
void DragOverEvent(object sender, DragEventArgs e)
{
if (ClientRectangle.Contains(new Point(e.X, e.Y))) {
e.Effect = DragDropEffects.Copy;
}
}
void DragDropEvent(object sender, DragEventArgs e)
{
if (e.Data != null && e.Data.GetDataPresent(DataFormats.FileDrop)) {
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (string file in files) {
if (!FSTypeUtility.IsDirectory(file)) {
OpenWindow(file);
}
}
}
}
void OnProjectModeChanged()
{
if (ProjectModeChanged != null) {
ProjectModeChanged(this, null);
}
}
void FileTransaction(object message, EventArgs e)
{
statusProgressBar.Visible = true;
loadCancelButton.Show();
StatusBarText = message.ToString();
}
void FileTransactionProgress(object sender, int percent)
{
if (percent < 0 || percent > 100) {
loadCancelButton.Hide();
statusProgressBar.Visible = false;
}
if (statusProgressBar.Visible)
statusProgressBar.Value = percent;
}
void FileTransactionComplete(object message, EventArgs e)
{
loadCancelButton.Hide();
statusProgressBar.Visible = false;
StatusBarText = message.ToString();
}
void StandardStatusBar(object sender, EventArgs e)
{
StatusBarText = "Ready";
}
void SelectedTabIndexChange(object sender, System.EventArgs e)
{
TabPage item = openfiletab.SelectedTab;
foreach (ContentWindow window in MdiChildren) {
if (window.TabItem == item) {
window.Select();
break;
}
}
}
void InitOpenFileTab()
{
openfiletab.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right;
openfiletab.Size = new System.Drawing.Size(100, 26);
openfiletab.Dock = DockStyle.Top;
openfiletab.SelectedIndexChanged += new EventHandler(SelectedTabIndexChange);
dockedopenfileview = new DockableControlWrapper("Open Files", "OF", openfiletab);
DockState state = (DockState)Option.GetProperty("SharpDevelop.Gui.MainWindow.DockingWindows.OpenFileView", new DockState());
dockmanager.Add(dockedopenfileview, state);
// Controls.Add(openfiletab);
new OpenFileTabEventHandler(this);
}
void InitResultView()
{
// splitter2.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
// splitter2.Cursor = System.Drawing.Cursors.HSplit;
// splitter2.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
// splitter2.Location = new System.Drawing.Point(0, 200);
// splitter2.TabIndex = 5;
// splitter2.TabStop = false;
// splitter2.Size = new System.Drawing.Size(3, 273);
// splitter2.Dock = DockStyle.Bottom;
//
compilerresultview.Dock = DockStyle.Bottom;
compilerresultview.ItemActivate += new EventHandler(GotoError);
dockedcompresview = new DockableControlWrapper("Compiler Results", "CR", compilerresultview);
DockState state = (DockState)Option.GetProperty("SharpDevelop.Gui.MainWindow.DockingWindows.CompilerResultView", new DockState());
dockmanager.Add(dockedcompresview, state);
// Controls.Add(splitter2);
// Controls.Add(compilerresultview);
// HideOutputWindow();
}
void InitNavigators()
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -