| 0: | // OpenFileTabEventHandler.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.Resources; | |
| 24: | using System.ComponentModel; | |
| 25: | using System.Xml; | |
| 26: | ||
| 27: | using SharpDevelop.Gui.Components; | |
| 28: | using SharpDevelop.Gui.Navigation; | |
| 29: | using SharpDevelop.Gui.Navigation.ProjectBrowser; | |
| 30: | using SharpDevelop.Gui.Window; | |
| 31: | using SharpDevelop.Tool.Data; | |
| 32: | using SharpDevelop.Tool.Function; | |
| 33: | using SharpDevelop.Internal.Plugin; | |
| 34: | using SharpDevelop.Gui.Edit.Text; | |
| 35: | ||
| 36: | namespace SharpDevelop.Gui { | |
| 37: | ||
| 38: | /// <summary> | |
| 39: | /// This class handles the events and the context menu for the open file tab control | |
| 40: | /// </summary> | |
| 41: | public class OpenFileTabEventHandler | |
| 42: | { | |
| 43: | MainWindow mainwindow; | |
| 44: | int clickedtab = -1; | |
| 45: | ||
| 46: | MenuItem closeitem; | |
| 47: | MenuItem saveitem; | |
| 48: | ||
| 49: | public OpenFileTabEventHandler(MainWindow mainwindow) | |
| 50: | { | |
| 51: | this.mainwindow = mainwindow; | |
| 52: | ||
| 53: | closeitem = new IconMenuItem(mainwindow, Resource.GetString("OpenFileTabEventHandler.ContextMenu.Close"), new EventHandler(CloseFileEvent), ""); | |
| 54: | saveitem = new IconMenuItem(mainwindow, Resource.GetString("OpenFileTabEventHandler.ContextMenu.Save"), new EventHandler(SaveFileEvent), Resource.GetBitmap("Icons.16x16.SaveIcon")); | |
| 55: | ||
| 56: | mainwindow.OpenFileTab.ContextMenu = new ContextMenu(new MenuItem[] { | |
| 57: | closeitem, | |
| 58: | new IconMenuItem(mainwindow, "-", null, ""), | |
| 59: | saveitem, | |
| 60: | new IconMenuItem(mainwindow, Resource.GetString("OpenFileTabEventHandler.ContextMenu.SaveAs"), new EventHandler(SaveAsFileEvent), ""), | |
| 61: | new IconMenuItem(mainwindow, "-", null, ""), | |
| 62: | new IconMenuItem(mainwindow, Resource.GetString("OpenFileTabEventHandler.CopyPathName"), new EventHandler(CopyFileNameEvent), ""), | |
| 63: | new IconMenuItem(mainwindow, "-", null, ""), | |
| 64: | new IconMenuItem(mainwindow, Resource.GetString("OpenFileTabEventHandler.Restore"), new EventHandler(RestoreWindowEvent), ""), | |
| 65: | new IconMenuItem(mainwindow, Resource.GetString("OpenFileTabEventHandler.Minimize"), new EventHandler(MinimizeWindowEvent), ""), | |
| 66: | new IconMenuItem(mainwindow, Resource.GetString("OpenFileTabEventHandler.Maximize"), new EventHandler(MaximizeWindowEvent), ""), | |
| 67: | }); | |
| 68: | mainwindow.OpenFileTab.MouseDown += new MouseEventHandler(MouseDown); | |
| 69: | } | |
| 70: | ||
| 71: | void MouseDown(object sender, MouseEventArgs e) | |
| 72: | { | |
| 73: | closeitem.Enabled = false; | |
| 74: | saveitem.Enabled = false; | |
| 75: | for (int i = 0; i < mainwindow.OpenFileTab.TabCount; ++i) { | |
| 76: | if (mainwindow.OpenFileTab.GetTabRect(i).Contains(e.X, e.Y)) { | |
| 77: | clickedtab = i; | |
| 78: | ContentWindow window = GetClickedWindow(); | |
| 79: | if (window != null) { | |
| 80: | closeitem.Enabled = true; | |
| 81: | saveitem.Enabled = !window.Untitled && window.Dirty; | |
| 82: | } | |
| 83: | return; | |
| 84: | } | |
| 85: | } | |
| 86: | clickedtab = -1; | |
| 87: | } | |
| 88: | ||
| 89: | ContentWindow GetClickedWindow() | |
| 90: | { | |
| 91: | ||
| 92: | if (clickedtab == -1) | |
| 93: | return null; | |
| 94: | TabPage tabitem = mainwindow.OpenFileTab.TabPages[clickedtab]; | |
| 95: | ||
| 96: | foreach (ContentWindow window in mainwindow.MdiChildren) { | |
| 97: | if (window.TabItem == tabitem) { | |
| 98: | return window; | |
| 99: | } | |
| 100: | } | |
| 101: | return null; | |
| 102: | ||
| 103: | } | |
| 104: | ||
| 105: | void CloseFileEvent(object sender, EventArgs e) | |
| 106: | { | |
| 107: | TabPage selected = mainwindow.OpenFileTab.SelectedTab; | |
| 108: | ContentWindow window = GetClickedWindow(); | |
| 109: | if (window != null) { | |
| 110: | window.Close(); | |
| 111: | if (window.TabItem != selected) { | |
| 112: | mainwindow.OpenFileTab.SelectedTab = selected; | |
| 113: | } | |
| 114: | } | |
| 115: | } | |
| 116: | ||
| 117: | void SaveAsFileEvent(object sender, EventArgs e) | |
| 118: | { | |
| 119: | ContentWindow window = GetClickedWindow(); | |
| 120: | if (window != null) { | |
| 121: | window.SaveContentAs(); | |
| 122: | } | |
| 123: | } | |
| 124: | ||
| 125: | void SaveFileEvent(object sender, EventArgs e) | |
| 126: | { | |
| 127: | ContentWindow window = GetClickedWindow(); | |
| 128: | if (window != null) { | |
| 129: | window.SaveContent(); | |
| 130: | } | |
| 131: | } | |
| 132: | ||
| 133: | void MaximizeWindowEvent(object sender, EventArgs e) | |
| 134: | { | |
| 135: | ContentWindow window = GetClickedWindow(); | |
| 136: | if (window != null) { | |
| 137: | window.WindowState = FormWindowState.Maximized; | |
| 138: | } | |
| 139: | } | |
| 140: | ||
| 141: | void RestoreWindowEvent(object sender, EventArgs e) | |
| 142: | { | |
| 143: | ContentWindow window = GetClickedWindow(); | |
| 144: | if (window != null) { | |
| 145: | window.WindowState = FormWindowState.Normal; | |
| 146: | } | |
| 147: | } | |
| 148: | void MinimizeWindowEvent(object sender, EventArgs e) | |
| 149: | { | |
| 150: | ContentWindow window = GetClickedWindow(); | |
| 151: | if (window != null) { | |
| 152: | window.WindowState = FormWindowState.Minimized; | |
| 153: | } | |
| 154: | } | |
| 155: | ||
| 156: | void CopyFileNameEvent(object sender, EventArgs e) | |
| 157: | { | |
| 158: | ContentWindow window = GetClickedWindow(); | |
| 159: | if (window != null) { | |
| 160: | Clipboard.SetDataObject(new DataObject(DataFormats.Text, window.TextName)); | |
| 161: | } | |
| 162: | } | |
| 163: | } | |
| 164: | } |
This page was automatically generated by SharpDevelop.