/*
  * Note: The ability to connect to PowerPivot from DAX Studio (or any third party application) is not
  * supported by Microsoft. Microsoft does not support connecting to PowerPivot models using the APIs
  * used here and as such the behaviour may change or stop working without notice in future releases.
  * This functionality is provided on an "as-is" basis.
  */
 private string BuildPowerPivotConnection()
 {
     return(Host.Proxy.GetPowerPivotConnection(GetApplicationName("Power Pivot"), string.Format("Location=\"{0}\";Extended Properties='Location=\"{1}\"';Workstation ID=\"{0}\"", WorkbookName, WorkbookName.Replace("'", "''"))).ConnectionString);
 }
Exemple #2
0
        public override bool DrawGUIList(EditorGUILayoutEx in_layout, bool in_showAll)
        {
            var ret = true;

            var spreadsheetVisibleString = "workbook" + WorkbookName.Replace(' ', '_') + "_Visible";

            SpreadsheetVisible = Google2uGUIUtil.GetBool(spreadsheetVisibleString, SpreadsheetVisible);
            if ((SpreadsheetVisible == false) && !in_showAll)
            {
                return(true);
            }

            ShowSpreadsheet = Google2uGUIUtil.GetBool("workbook" + WorkbookName.Replace(' ', '_') + "_Open",
                                                      ShowSpreadsheet);
            var mainFadeArea = in_layout.BeginFadeArea(ShowSpreadsheet, WorkbookName,
                                                       "workbook" + WorkbookName.Replace(' ', '_'), in_layout.OuterBox, in_layout.OuterBoxHeader,
                                                       spreadsheetVisibleString);

            ShowSpreadsheet = mainFadeArea.Open;
            Google2uGUIUtil.SetBool("workbook" + WorkbookName.Replace(' ', '_') + "_Open", ShowSpreadsheet);

            // We have to do this here. Otherwise there is a threading issue (Can't initialize from EditorPreferences outside the main thread)
            if (ExportOptions == null)
            {
                ExportOptions = new Google2uExportOptions("workbook" + WorkbookName.Replace(' ', '_') + "_Option_");
            }

            if (mainFadeArea.Show())
            {
                var showExport   = false;
                var exportsheets = new List <Google2uWorksheet>();

                switch (WorksheetQueryStatus)
                {
                case QueryStatus.Idle:
                {
                    WorksheetQueryStatus = QueryStatus.Uninitialized;
                }
                break;

                case QueryStatus.Querying:
                    EditorGUILayout.LabelField(
                        Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_MESSAGE_QUERYING_WORKSHEETS) +
                        Google2u.Ellipses);
                    break;

                case QueryStatus.QueryComplete:
                    if (WorksheetsDisplay.Length > 0)
                    {
                        foreach (var google2UWorksheet in WorksheetsDisplay)
                        {
                            if (google2UWorksheet.DrawGUIList(in_layout))
                            {
                                exportsheets.Add(google2UWorksheet);
                                showExport = true;
                            }
                        }

                        if (_OpenInvalidSheet)
                        {
                            var stillQuerying = false;
                            for (var i = 0; i < Worksheets.Count; ++i)
                            {
                                if (!exportsheets.Contains(Worksheets[i]))
                                {
                                    continue;
                                }

                                if (Worksheets[i].UpdateValidation || Worksheets[i].Validating)
                                {
                                    stillQuerying = true;
                                }


                                if (Worksheets[i].IsDataValid == false)
                                {
                                    var ed = EditorWindow.GetWindow <Google2uEditor>();
                                    Google2u.ActiveWorkbookWindow = ed;
                                    ed.Workbook = this;
                                    ed.Layout   = in_layout;


#if (UNITY_4)
                                    ed.title = WorkbookName;
#elif (UNITY_5_0)
                                    ed.title = WorkbookName;
#else
                                    ed.titleContent.text = WorkbookName;
#endif

                                    ed.wantsMouseMove    = true;
                                    ActiveWorksheetIndex = i;
                                    Worksheets[i].HighlightFirstInvalidCell();
                                    _OpenInvalidSheet = false;
                                    break;
                                }
                            }
                            if (!stillQuerying)
                            {
                                _OpenInvalidSheet = false;
                            }
                        }

                        EditorGUILayout.BeginHorizontal();
                        var content = new GUIContent(in_layout.RefreshButton,
                                                     Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_REFRESH_WORKBOOK));
                        if (GUILayout.Button(content, GUILayout.Height(EditorGUILayoutEx.ButtonHeight),
                                             GUILayout.Width(EditorGUILayoutEx.ButtonWidth)))
                        {
                            Worksheets.Clear();
                            WorksheetQueryStatus = QueryStatus.Uninitialized;
                        }


                        var querying            = false;
                        var bAllWorksheetsValid = true;
                        foreach (var google2UWorksheet in exportsheets)
                        {
                            if (google2UWorksheet.IsDataValid == false)
                            {
                                bAllWorksheetsValid = false;
                            }
                            if (google2UWorksheet.WorksheetQueryStatus != QueryStatus.Idle)
                            {
                                querying = true;
                            }
                        }
                        {
                            var guiEnabled = GUI.enabled;
                            if (querying)
                            {
                                GUI.enabled = false;
                            }

                            content = bAllWorksheetsValid
                                    ? new GUIContent(in_layout.ValidateButtonGreen,
                                                     Google2u.LocalizationInfo.Localize(
                                                         Localization.rowIds.ID_LABEL_VALIDATE_WORKBOOK))
                                    : new GUIContent(in_layout.ValidateButtonRed,
                                                     Google2u.LocalizationInfo.Localize(
                                                         Localization.rowIds.ID_LABEL_VALIDATE_WORKBOOK));

                            if (GUILayout.Button(content, GUILayout.Height(EditorGUILayoutEx.ButtonHeight),
                                                 GUILayout.Width(EditorGUILayoutEx.ButtonWidth)))
                            {
                                // Do Validation for the worksheets we will be exporting
                                foreach (var google2UWorksheet in exportsheets)
                                {
                                    google2UWorksheet.UpdateValidation = true;
                                    google2UWorksheet.Validating       = true;
                                }
                                _OpenInvalidSheet = true;
                            }
                            GUI.enabled = guiEnabled;
                        }

                        content = new GUIContent(in_layout.EditButton,
                                                 Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_EDIT_WORKBOOK));
                        if (GUILayout.Button(content, GUILayout.Height(EditorGUILayoutEx.ButtonHeight),
                                             GUILayout.Width(EditorGUILayoutEx.ButtonWidth)))
                        {
                            var ed = EditorWindow.GetWindow <Google2uEditor>();
                            Google2u.ActiveWorkbookWindow = ed;
                            ed.Workbook = this;
                            ed.Layout   = in_layout;
#if (UNITY_4)
                            ed.title = WorkbookName;
#elif (UNITY_5_0)
                            ed.title = WorkbookName;
#else
                            ed.titleContent.text = WorkbookName;
#endif
                            ed.wantsMouseMove = true;
                        }

                        GUILayout.FlexibleSpace();

                        if (showExport)
                        {
                            var oldEnabled = GUI.enabled;
                            if (bAllWorksheetsValid == false)
                            {
                                GUI.enabled = false;
                            }
                            content = new GUIContent(in_layout.SaveButton,
                                                     Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_EXPORT));
                            if (GUILayout.Button(content, GUILayout.Height(EditorGUILayoutEx.ButtonHeight),
                                                 GUILayout.Width(EditorGUILayoutEx.ButtonWidth)))
                            {
                                DoExport(exportsheets);
                            }
                            GUI.enabled = oldEnabled;
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                    else
                    {
                        EditorGUILayout.LabelField(
                            Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_MESSAGE_NO_WORKSHEETS));
                    }
                    break;
                }
            }
            in_layout.EndFadeArea();
            return(ret);
        }