1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
// Copyright 2008, 2010, Oracle and/or its affiliates. All rights reserved.
//
// MySQL Connector/NET is licensed under the terms of the GPLv2
// <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
// MySQL Connectors. There are special exceptions to the terms and
// conditions of the GPLv2 as it is applied to this software, see the
// FLOSS License Exception
// <http://www.mysql.com/about/legal/licensing/foss-exception.html>.
//
// 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; version 2 of the License.
//
// 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.,
// 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.Shell.Interop;
using System.Diagnostics;
using Microsoft.VisualStudio;
using System.Data.Common;
using System.Data;
using Microsoft.VisualStudio.Data;
using Microsoft.VisualStudio.TextManager.Interop;
using System.Windows.Forms;
using MySql.Data.VisualStudio.Properties;
using Microsoft.VisualStudio.OLE.Interop;
using Microsoft.VisualStudio.Package;
using MySql.Data.VisualStudio.Editors;
using Microsoft.VisualStudio.Shell;
namespace MySql.Data.VisualStudio
{
abstract class DocumentNode : BaseNode, IVsPersistDocData
{
public DocumentNode(DataViewHierarchyAccessor hierarchyAccessor, int id) :
base(hierarchyAccessor, id)
{
}
private uint DocumentCookie;
protected abstract void Load();
public abstract string GetSaveSql();
protected abstract string GetCurrentName();
protected virtual bool Save()
{
ExecuteSQL(GetSaveSql());
return true;
}
#region IVsPersistDocData Members
public int Close()
{
//throw new Exception("The method or operation is not implemented.");
return VSConstants.S_OK;
}
public int GetGuidEditorType(out Guid pClassID)
{
throw new Exception("The method or operation is not implemented.");
}
public int IsDocDataDirty(out int pfDirty)
{
pfDirty = Dirty ? 1 : 0;
return VSConstants.S_OK;
}
public int IsDocDataReloadable(out int pfReloadable)
{
throw new Exception("The method or operation is not implemented.");
}
public int LoadDocData(string pszMkDocument)
{
Debug.Assert(pszMkDocument == Moniker);
Load();
OnDataLoaded();
return VSConstants.S_OK;
}
public int OnRegisterDocData(uint docCookie, IVsHierarchy pHierNew, uint itemidNew)
{
DocumentCookie = docCookie;
Debug.Assert(HierarchyAccessor.Hierarchy == pHierNew, "Registration in wrong hierarchy");
return VSConstants.S_OK;
}
public int ReloadDocData(uint grfFlags)
{
throw new Exception("The method or operation is not implemented.");
}
public int RenameDocData(uint grfAttribs, IVsHierarchy pHierNew, uint itemidNew, string pszMkDocumentNew)
{
return VSConstants.S_OK;
}
public int SaveDocData(VSSAVEFLAGS dwSave, out string pbstrMkDocumentNew, out int pfSaveCanceled)
{
string oldMoniker = Moniker;
pfSaveCanceled = 1;
pbstrMkDocumentNew = null;
try
{
// Call out to the derived nodes to do the save work
if (Save())
pfSaveCanceled = 0;
}
catch (Exception ex)
{
MessageBox.Show("Unable to save object with error: " + ex.Message);
return VSConstants.S_OK;
}
if (pfSaveCanceled == 0)
{
// then mark the document has clean and unchanged
Dirty = false;
IsNew = false;
//notify any listeners that our save is done
OnDataSaved();
Name = GetCurrentName();
pbstrMkDocumentNew = String.Format("/Connection/{0}s/{1}", NodeId, Name);
VsShellUtilities.RenameDocument(MySqlDataProviderPackage.Instance, oldMoniker, Moniker);
// update server explorer
Refresh();
Load();
}
return VSConstants.S_OK;
}
public int SetUntitledDocPath(string pszDocDataPath)
{
throw new Exception("The method or operation is not implemented.");
}
#endregion
#region Events
public event EventHandler DataLoaded;
public event EventHandler DataChanged;
public event EventHandler DataSaved;
private void OnDataLoaded()
{
if (DataLoaded != null)
DataLoaded(this, null);
}
private void OnDataChanged()
{
if (DataChanged != null)
DataChanged(this, null);
}
private void OnDataSaved()
{
if (DataSaved != null)
DataSaved(this, null);
}
#endregion
}
}
|