[mapguide-commits] r5422 - in sandbox/maestro-3.0/Maestro.Editors:
Common FeatureSource/Providers/Shp
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Wed Dec 1 03:59:55 EST 2010
Author: jng
Date: 2010-12-01 00:59:54 -0800 (Wed, 01 Dec 2010)
New Revision: 5422
Modified:
sandbox/maestro-3.0/Maestro.Editors/Common/ResourceDataCtrl.cs
sandbox/maestro-3.0/Maestro.Editors/FeatureSource/Providers/Shp/ShpFileCtrl.cs
Log:
3.0 sandbox changes:
- Fix #1531: Add support for uploading multiple files at once. Modify the SHP feature source editor to automatically upload related files
Modified: sandbox/maestro-3.0/Maestro.Editors/Common/ResourceDataCtrl.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Editors/Common/ResourceDataCtrl.cs 2010-12-01 08:29:04 UTC (rev 5421)
+++ sandbox/maestro-3.0/Maestro.Editors/Common/ResourceDataCtrl.cs 2010-12-01 08:59:54 UTC (rev 5422)
@@ -141,23 +141,27 @@
BindResourceList();
}
+ public delegate void ResourceUploadEventHandler(string dataName, string origPath);
+
+ public event ResourceUploadEventHandler ResourceDataUploaded;
+
private void btnAdd_Click(object sender, EventArgs e)
{
using (var open = DialogFactory.OpenFile())
{
+ open.Multiselect = true;
if (open.ShowDialog() == DialogResult.OK)
{
using (new WaitCursor(this))
{
try
{
- using (var fs = new FileStream(open.FileName, FileMode.Open))
+ foreach (var fileName in open.FileNames)
{
- //_edSvc.AddResourceData(Path.GetFileName(open.FileName), ResourceDataType.File, fs);
- IResource res = _edSvc.GetEditedResource();
- res.SetResourceData(Path.GetFileName(open.FileName), ResourceDataType.File, fs);
- LoadResourceData();
- OnDataListChanged();
+ UploadFile(fileName);
+ var handler = this.ResourceDataUploaded;
+ if (handler != null)
+ handler(Path.GetFileName(fileName), fileName);
}
}
catch (Exception ex)
@@ -169,6 +173,18 @@
}
}
+ public void UploadFile(string fileName)
+ {
+ using (var fs = new FileStream(fileName, FileMode.Open))
+ {
+ //_edSvc.AddResourceData(Path.GetFileName(open.FileName), ResourceDataType.File, fs);
+ IResource res = _edSvc.GetEditedResource();
+ res.SetResourceData(Path.GetFileName(fileName), ResourceDataType.File, fs);
+ LoadResourceData();
+ OnDataListChanged();
+ }
+ }
+
private void OnDataListChanged()
{
var handler = this.DataListChanged;
Modified: sandbox/maestro-3.0/Maestro.Editors/FeatureSource/Providers/Shp/ShpFileCtrl.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Editors/FeatureSource/Providers/Shp/ShpFileCtrl.cs 2010-12-01 08:29:04 UTC (rev 5421)
+++ sandbox/maestro-3.0/Maestro.Editors/FeatureSource/Providers/Shp/ShpFileCtrl.cs 2010-12-01 08:59:54 UTC (rev 5422)
@@ -26,6 +26,7 @@
using System.Windows.Forms;
using OSGeo.MapGuide.ObjectModels.FeatureSource;
using System.Diagnostics;
+using System.IO;
namespace Maestro.Editors.FeatureSource.Providers.Shp
{
@@ -43,10 +44,34 @@
base.Bind(service);
_fs = service.GetEditedResource() as IFeatureSource;
Debug.Assert(_fs != null);
-
MarkSelected();
+ resDataCtrl.ResourceDataUploaded += new Maestro.Editors.Common.ResourceDataCtrl.ResourceUploadEventHandler(OnResourceDataUploaded);
}
+ static readonly string[] SHP_RELATED_EXTENSIONS = { ".shx", ".dbf", ".idx", ".prj", ".cpg" };
+
+ void OnResourceDataUploaded(string dataName, string origPath)
+ {
+ //If a SHP file was loaded, we want all of its buddies too
+ if (origPath.ToLower().EndsWith(".shp"))
+ {
+ var pathPrefix = origPath.Substring(0, origPath.Length - 4);
+ foreach (string ext in SHP_RELATED_EXTENSIONS)
+ {
+ string path = pathPrefix + ext;
+ //Can't upload something that doesn't exist
+ if (File.Exists(path))
+ {
+ //This can cause this method to be called again,
+ //as UploadFile() raises ResourceDataUploaded
+ //but there isn't a scenario I can think of where
+ //this would reach StackOverflowException proportions
+ resDataCtrl.UploadFile(path);
+ }
+ }
+ }
+ }
+
private void MarkSelected()
{
var file = _fs.GetConnectionProperty("DefaultFileLocation");
More information about the mapguide-commits
mailing list