diff --git a/Assets/QuickSheet/GDataPlugin/Editor/GDataDB/GDataDB/DatabaseClient.cs b/Assets/QuickSheet/GDataPlugin/Editor/GDataDB/GDataDB/DatabaseClient.cs
index ac6d19c..be5be0a 100644
--- a/Assets/QuickSheet/GDataPlugin/Editor/GDataDB/GDataDB/DatabaseClient.cs
+++ b/Assets/QuickSheet/GDataPlugin/Editor/GDataDB/GDataDB/DatabaseClient.cs
@@ -28,15 +28,10 @@ public DatabaseClient(string username, string password) {
var docService = new DocumentsService("database");
docService.RequestFactory = requestFactory;
- //@kims
- //docService.setUserCredentials(username, password);
documentService = docService;
var ssService = new SpreadsheetsService("database");
- //@kims
- //ssService.setUserCredentials(username, password);
-
ssService.RequestFactory = requestFactory;
spreadsheetService = ssService;
}
@@ -51,26 +46,25 @@ public IDatabase CreateDatabase(string name) {
}
}
- public IDatabase GetDatabase(string name) {
- /*
- var feed = DocumentService.Query(new SpreadsheetQuery {TitleExact = true, Title = name });
- if (feed.Entries.Count == 0)
- return null;
- return new Database(this, feed.Entries[0]);
- */
+ ///
+ /// @kims 2016.08.09. Added second parameter to pass error message by reference.
+ ///
+ /// Null, if any error has been occured.
+ public IDatabase GetDatabase(string name, ref string error) {
+
Google.GData.Spreadsheets.SpreadsheetQuery query = new Google.GData.Spreadsheets.SpreadsheetQuery();
// Make a request to the API and get all spreadsheets.
SpreadsheetsService service = spreadsheetService as SpreadsheetsService;
+
SpreadsheetFeed feed = service.Query(query);
if (feed.Entries.Count == 0)
{
- //Debug.Log("There are no spreadsheets in your docs.");
+ error = @"There are no spreadsheets in your docs.";
return null;
}
- //SpreadsheetEntry spreadsheet = null;
AtomEntry spreadsheet = null;
foreach (AtomEntry sf in feed.Entries)
{
@@ -80,7 +74,7 @@ public IDatabase GetDatabase(string name) {
if (spreadsheet == null)
{
- //Debug.Log("There is no such spreadsheet with such title in your docs.");
+ error = @"There is no such spreadsheet with such title in your docs.";
return null;
}
diff --git a/Assets/QuickSheet/GDataPlugin/Editor/GDataDB/GDataDB/IDatabaseClient.cs b/Assets/QuickSheet/GDataPlugin/Editor/GDataDB/GDataDB/IDatabaseClient.cs
index 17dae7e..d83a313 100644
--- a/Assets/QuickSheet/GDataPlugin/Editor/GDataDB/GDataDB/IDatabaseClient.cs
+++ b/Assets/QuickSheet/GDataPlugin/Editor/GDataDB/GDataDB/IDatabaseClient.cs
@@ -21,6 +21,6 @@ public interface IDatabaseClient {
///
///
/// IDocument instance or null if not found
- IDatabase GetDatabase(string name);
+ IDatabase GetDatabase(string name, ref string error);
}
}
\ No newline at end of file
diff --git a/Assets/QuickSheet/GDataPlugin/Editor/GoogleMachineEditor.cs b/Assets/QuickSheet/GDataPlugin/Editor/GoogleMachineEditor.cs
index a262eb9..21f25e1 100644
--- a/Assets/QuickSheet/GDataPlugin/Editor/GoogleMachineEditor.cs
+++ b/Assets/QuickSheet/GDataPlugin/Editor/GoogleMachineEditor.cs
@@ -137,8 +137,10 @@ public override void OnInspectorGUI()
if (GUILayout.Button("Generate"))
{
- if (Generate(this.machine) == null)
- Debug.LogError("Failed to create a script from Google.");
+ if (Generate(this.machine) != null)
+ Debug.Log("Successfully generated!");
+ else
+ Debug.LogError("Failed to create a script from Google Spreadsheet.");
}
}
@@ -162,11 +164,15 @@ private void DoCellQuery(OnEachCell onCell)
if (string.IsNullOrEmpty(machine.WorkSheetName))
return;
- var db = client.GetDatabase(machine.SpreadSheetName);
+ string error = string.Empty;
+ var db = client.GetDatabase(machine.SpreadSheetName, ref error);
if (db == null)
{
- string message = string.Format(@"The given spreadsheet '{0}' or worksheet '{1}' does not exist. Note that the name is case sensitive.",
- machine.SpreadSheetName, machine.WorkSheetName);
+ string message = string.Empty;
+ if (string.IsNullOrEmpty(error))
+ message = @"Unknown error.";
+ else
+ message = string.Format(@"{0}", error);
EditorUtility.DisplayDialog("Error", message, "OK");
return;
}
@@ -201,6 +207,9 @@ protected override void Import(bool reimport = false)
else
headerDic = machine.HeaderColumnList.ToDictionary(k => k.name);
+ List tmpColumnList = new List();
+
+ // query the first columns only.
DoCellQuery((cell) =>
{
@@ -211,19 +220,29 @@ protected override void Import(bool reimport = false)
if (int.Parse(m.Value) > 1)
return;
- if (machine.HasHeadColumn() && reimport == false)
+ HeaderColumn column = new HeaderColumn();
+ column.name = cell.Value;
+ if (headerDic != null && headerDic.ContainsKey(cell.Value))
{
- if (headerDic != null && headerDic.ContainsKey(cell.Value))
- machine.HeaderColumnList.Add(new HeaderColumn { name = cell.Value, type = headerDic[cell.Value].type });
+ // if the column is already exist, copy its name and type from the exist one.
+ HeaderColumn h = machine.HeaderColumnList.Find(x => x.name == column.name);
+ if (h != null)
+ {
+ column.type = h.type;
+ column.isArray = h.isArray;
+ }
else
- machine.HeaderColumnList.Add(new HeaderColumn { name = cell.Value, type = CellType.Undefined });
+ column.type = CellType.Undefined;
}
else
- {
- machine.HeaderColumnList.Add(new HeaderColumn { name = cell.Value, type = CellType.Undefined });
- }
+ column.type = CellType.Undefined;
+
+ tmpColumnList.Add(column);
});
+ // update (all of settings are reset when it reimports)
+ machine.HeaderColumnList = tmpColumnList;
+
EditorUtility.SetDirty(machine);
AssetDatabase.SaveAssets();
}
diff --git a/Assets/QuickSheet/GDataPlugin/Templates/ScriptableObjectEditorClass.txt b/Assets/QuickSheet/GDataPlugin/Templates/ScriptableObjectEditorClass.txt
index 61907d8..84c786a 100644
--- a/Assets/QuickSheet/GDataPlugin/Templates/ScriptableObjectEditorClass.txt
+++ b/Assets/QuickSheet/GDataPlugin/Templates/ScriptableObjectEditorClass.txt
@@ -59,7 +59,8 @@ public class $ClassName : BaseGoogleEditor<$WorkSheetClassName>
$WorkSheetClassName targetData = target as $WorkSheetClassName;
var client = new DatabaseClient("", "");
- var db = client.GetDatabase(targetData.SheetName) ?? client.CreateDatabase(targetData.SheetName);
+ string error = string.Empty;
+ var db = client.GetDatabase(targetData.SheetName, ref error);
var table = db.GetTable<$DataClassName>(targetData.WorksheetName) ?? db.CreateTable<$DataClassName>(targetData.WorksheetName);
List<$DataClassName> myDataList = new List<$DataClassName>();