private bool validWorksheetName(string val) { if (!char.IsLetter(val[0])) { return(false); } if (!Google2uCell.ValidStart(val)) { return(false); } if (!Google2uCell.ContainsInvalidChars(val)) { return(false); } if (Google2uCell.ContainsKeyword(val)) { return(false); } return(true); }
public Google2uCell DrawGUI(EditorGUILayoutEx in_layout, Rect in_rect, Google2uCell in_activeEntry) { if (in_activeEntry == this) { GUI.Label(in_rect, _MyCell.Value, in_layout.CellButtonActive); } else if (!SkipValidation && !string.IsNullOrEmpty(Tooltip)) { var content = new GUIContent(_MyCell.Value, Tooltip); if (GUI.Button(in_rect, content, in_layout.CellInvalidButton)) { return(this); } } else { if (GUI.Button(in_rect, _MyCell.Value, in_layout.CellButton)) { return(this); } } return(null); }
public void DrawGUIFull(EditorGUILayoutEx in_layout) { if (!_Initialized) { _Initialized = true; UseTypeRow = Google2uGUIUtil.GetBool(Prefix + "UseTypeRow", UseTypeRow); WorksheetExportType = Google2uGUIUtil.GetEnum(Prefix + "ExportType", WorksheetExportType); } if (WorksheetQueryStatus != QueryStatus.QueryComplete && WorksheetQueryStatus != QueryStatus.Idle && RowsDisplay.Length == 0) { EditorGUILayout.LabelField( Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_MESSAGE_QUERYING_CELLS) + Google2u.Ellipses); } else if (RowsDisplay.Length == 0) { if (WorksheetQueryStatus == QueryStatus.QueryComplete || WorksheetQueryStatus == QueryStatus.Idle) { EditorGUILayout.LabelField( Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_MESSAGE_EMPTY_WORKSHEET)); } } else { if (DoInitialSizeCheck) { DoInitialSizeCheck = false; for (var i = 0; i < ColOptions.Count; ++i) { CalculateColumnWidth(i, this); } } if ((DateTime.Now - LastUpdateTime).TotalSeconds > 15) { DoUpdateQuery = true; } if (ActiveCell != null) { if (!ActiveCell.SkipValidation && !string.IsNullOrEmpty(ActiveCell.Tooltip)) { EditorGUILayoutEx.SetColor(Color.red); GUILayout.Label(ActiveCell.Tooltip); EditorGUILayoutEx.ResetColor(); } if (ActiveCell.DrawCellValue(in_layout)) { WorksheetQueryStatus = QueryStatus.Idle; LastUpdateTime = DateTime.MinValue; DoUpdateQuery = true; UpdateValidation = true; } } else { var old = GUI.enabled; GUI.enabled = false; EditorGUILayout.TextField(string.Empty); GUI.enabled = old; } // Calculate the total width and height of the scroll area var totalHeight = Math.Max(120, 22 + (24 * RowsDisplay.Length)); var totalWidth = 40 + ColOptions.Sum(in_colOption => in_colOption.Width); EditorGUILayout.Separator(); if (Event.current.type == EventType.Repaint) { _LastRect = GUILayoutUtility.GetLastRect(); } var scrollHeight = Screen.height - _LastRect.y - 30; var screenRect = new Rect(0f, _LastRect.y, Screen.width, scrollHeight); var viewRect = new Rect(0f, 0f, totalWidth, totalHeight); _MyScrollPos = GUI.BeginScrollView(screenRect, _MyScrollPos, viewRect); var curRect = new Rect(0.0f, 0.0f, 40.0f, 22.0f); // Blank GUI.Label(curRect, string.Empty, in_layout.CellHeader); // Column Letters (Resizable Columns) for (var i = 0; i < RowsDisplay[0].Count; i++) { var label = GetColumnName(i + 1); curRect.x += curRect.width; curRect.width = ColOptions[i].Width; GUI.Label(curRect, label, in_layout.CellHeader); ColOptions[i].ColumnRect = curRect; ColOptions[i].ColumnRect.width = ColOptions[i].Width; if (ColOptions[i].ColumnRect.Contains(Event.current.mousePosition)) { ColOptions[i].HasMouse = true; } if (!ColOptions[i].HasMouse) { continue; } if ((Event.current.type == EventType.MouseDown) && (Event.current.clickCount >= 2)) { // Doubleclick CalculateColumnWidth(i, this); } if (Event.current.type == EventType.MouseDrag) { ColOptions[i].CurPos = Event.current.mousePosition; if (!ColOptions[i].Dragging) { ColOptions[i].Dragging = true; ColOptions[i].StartPos = ColOptions[i].CurPos; } } if (Event.current.type == EventType.MouseUp) { ColOptions[i].Dragging = false; ColOptions[i].HasMouse = false; } if (!ColOptions[i].Dragging) { continue; } if (Event.current.isMouse) { Event.current.Use(); } ColOptions[i].Width += Convert.ToInt32((ColOptions[i].CurPos.x - ColOptions[i].StartPos.x)); ColOptions[i].StartPos = ColOptions[i].CurPos; ColOptions[i].Width = Math.Max(26, ColOptions[i].Width); } curRect = new Rect(0.0f, 22.0f, 40.0f, 24.0f); // The rest of the rows for (var i = 0; i < RowsDisplay.Length; i++) { if (i == 1) { // Could be type row if (GUI.Button(curRect, UseTypeRow ? "Type" : "2", in_layout.CellTypeButton)) { if (UseTypeRow == false) { if (EditorUtility.DisplayDialog(Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_TYPEROWBOX_HEADER), Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_TYPEROWBOX_MESSAGE), "OK", "Cancel")) { UseTypeRow = !UseTypeRow; UpdateCellTypes = true; } } else { UseTypeRow = !UseTypeRow; UpdateCellTypes = true; } } } else { // Row Number GUI.Label(curRect, Convert.ToString(i + 1), in_layout.CellHeader); } // Cell Values if (i == 1 && UseTypeRow) { for (var j = 0; j < RowsDisplay[i].Count; j++) { curRect.x += curRect.width; curRect.width = ColOptions[j].Width; var myCell = RowsDisplay[i][j]; if (myCell.MyType == SupportedType.Unrecognized) { myCell.SetTypeFromValue(); } var cellType = myCell.MyType; var curSelected = 0; foreach (var guiContent in _ComboBoxList) { if (guiContent.text.Equals(Convert.ToString(cellType))) { break; } curSelected++; } if (curSelected >= _ComboBoxList.Length) { curSelected = 0; } Google2uGUIUtil.ComboBox comboBoxControl; if (!_ComboBoxes.ContainsKey(j)) { comboBoxControl = new Google2uGUIUtil.ComboBox(curRect, _ComboBoxList[curSelected], _ComboBoxList, in_layout.CellTypeButton, in_layout.OuterBox, in_layout.CellHeader); _ComboBoxes.Add(j, comboBoxControl); } else { comboBoxControl = _ComboBoxes[j]; } comboBoxControl.width = curRect.width; comboBoxControl.height = curRect.height; comboBoxControl.x = curRect.x; comboBoxControl.y = curRect.y; var newSelected = comboBoxControl.Show(); if (newSelected != curSelected) { var newType = (SupportedType) Enum.Parse(typeof(SupportedType), _ComboBoxList[newSelected].text, true); myCell.MyType = newType; myCell.SetValueFromType(); UpdateCellTypes = true; UpdateValidation = true; } } } else { for (var j = 0; j < RowsDisplay[i].Count; j++) { curRect.x += curRect.width; curRect.width = ColOptions[j].Width; if (curRect.x + curRect.width > _MyScrollPos.x && curRect.x < _MyScrollPos.x + Screen.width && curRect.y + curRect.height > _MyScrollPos.y && curRect.y < _MyScrollPos.y + scrollHeight) { if (i < 2 || i > 5 || !_ComboBoxes.ContainsKey(j) || _ComboBoxes[j].IsShown == false) { var newCell = RowsDisplay[i][j].DrawGUI(in_layout, curRect, ActiveCell); if (newCell != null) { GUI.FocusControl("Blank"); ActiveCell = newCell; } } } } } curRect.x = 0.0f; curRect.width = 40.0f; curRect.y += curRect.height; } GUI.EndScrollView(); } }
public Google2uCell DrawGUI(EditorGUILayoutEx in_layout, Rect in_rect, Google2uCell in_activeEntry) { if (in_activeEntry == this) { GUI.Label(in_rect, _MyCell.Value, in_layout.CellButtonActive); } else if (!SkipValidation && !string.IsNullOrEmpty(Tooltip)) { var content = new GUIContent(_MyCell.Value, Tooltip); if (GUI.Button(in_rect, content, in_layout.CellInvalidButton)) { return this; } } else { if (GUI.Button(in_rect, _MyCell.Value, in_layout.CellButton)) { return this; } } return null; }
public void DrawGUIFull(EditorGUILayoutEx in_layout) { if (!_Initialized) { _Initialized = true; UseTypeRow = Google2uGUIUtil.GetBool(Prefix + "UseTypeRow", UseTypeRow); WorksheetExportType = Google2uGUIUtil.GetEnum(Prefix + "ExportType", WorksheetExportType); } if (WorksheetQueryStatus != QueryStatus.QueryComplete && WorksheetQueryStatus != QueryStatus.Idle && RowsDisplay.Length == 0) { EditorGUILayout.LabelField( Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_MESSAGE_QUERYING_CELLS) + Google2u.Ellipses); } else if (RowsDisplay.Length == 0) { if (WorksheetQueryStatus == QueryStatus.QueryComplete || WorksheetQueryStatus == QueryStatus.Idle) EditorGUILayout.LabelField( Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_MESSAGE_EMPTY_WORKSHEET)); } else { if (DoInitialSizeCheck) { DoInitialSizeCheck = false; for (var i = 0; i < ColOptions.Count; ++i) { CalculateColumnWidth(i, this); } } if ((DateTime.Now - LastUpdateTime).TotalSeconds > 15) { DoUpdateQuery = true; } if (ActiveCell != null) { if (!ActiveCell.SkipValidation && !string.IsNullOrEmpty(ActiveCell.Tooltip)) { EditorGUILayoutEx.SetColor(Color.red); GUILayout.Label(ActiveCell.Tooltip); EditorGUILayoutEx.ResetColor(); } if (ActiveCell.DrawCellValue(in_layout)) { WorksheetQueryStatus = QueryStatus.Idle; LastUpdateTime = DateTime.MinValue; DoUpdateQuery = true; UpdateValidation = true; } } else { var old = GUI.enabled; GUI.enabled = false; EditorGUILayout.TextField(string.Empty); GUI.enabled = old; } // Calculate the total width and height of the scroll area var totalHeight = Math.Max(120, 22 + (24*RowsDisplay.Length)); var totalWidth = 40 + ColOptions.Sum(in_colOption => in_colOption.Width); EditorGUILayout.Separator(); if (Event.current.type == EventType.Repaint) _LastRect = GUILayoutUtility.GetLastRect(); var scrollHeight = Screen.height - _LastRect.y - 30; var screenRect = new Rect(0f, _LastRect.y, Screen.width, scrollHeight); var viewRect = new Rect(0f, 0f, totalWidth, totalHeight); _MyScrollPos = GUI.BeginScrollView(screenRect, _MyScrollPos, viewRect); var curRect = new Rect(0.0f, 0.0f, 40.0f, 22.0f); // Blank GUI.Label(curRect, string.Empty, in_layout.CellHeader); // Column Letters (Resizable Columns) for (var i = 0; i < RowsDisplay[0].Count; i++) { var label = GetColumnName(i + 1); curRect.x += curRect.width; curRect.width = ColOptions[i].Width; GUI.Label(curRect, label, in_layout.CellHeader); ColOptions[i].ColumnRect = curRect; ColOptions[i].ColumnRect.width = ColOptions[i].Width; if (ColOptions[i].ColumnRect.Contains(Event.current.mousePosition)) ColOptions[i].HasMouse = true; if (!ColOptions[i].HasMouse) continue; if ((Event.current.type == EventType.mouseDown) && (Event.current.clickCount >= 2)) { // Doubleclick CalculateColumnWidth(i, this); } if (Event.current.type == EventType.mouseDrag) { ColOptions[i].CurPos = Event.current.mousePosition; if (!ColOptions[i].Dragging) { ColOptions[i].Dragging = true; ColOptions[i].StartPos = ColOptions[i].CurPos; } } if (Event.current.type == EventType.mouseUp) { ColOptions[i].Dragging = false; ColOptions[i].HasMouse = false; } if (!ColOptions[i].Dragging) continue; if (Event.current.isMouse) Event.current.Use(); ColOptions[i].Width += Convert.ToInt32((ColOptions[i].CurPos.x - ColOptions[i].StartPos.x)); ColOptions[i].StartPos = ColOptions[i].CurPos; ColOptions[i].Width = Math.Max(26, ColOptions[i].Width); } curRect = new Rect(0.0f, 22.0f, 40.0f, 24.0f); // The rest of the rows for (var i = 0; i < RowsDisplay.Length; i++) { if (i == 1) { // Could be type row if (GUI.Button(curRect, UseTypeRow ? "Type" : "2", in_layout.CellTypeButton)) { if (UseTypeRow == false) { if (EditorUtility.DisplayDialog(Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_TYPEROWBOX_HEADER), Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_TYPEROWBOX_MESSAGE), "OK", "Cancel")) { UseTypeRow = !UseTypeRow; UpdateCellTypes = true; } } else { UseTypeRow = !UseTypeRow; UpdateCellTypes = true; } } } else { // Row Number GUI.Label(curRect, Convert.ToString(i + 1), in_layout.CellHeader); } // Cell Values if (i == 1 && UseTypeRow) { for (var j = 0; j < RowsDisplay[i].Count; j++) { curRect.x += curRect.width; curRect.width = ColOptions[j].Width; var myCell = RowsDisplay[i][j]; if (myCell.MyType == SupportedType.Unrecognized) { myCell.SetTypeFromValue(); } var cellType = myCell.MyType; var curSelected = 0; foreach (var guiContent in _ComboBoxList) { if (guiContent.text.Equals(Convert.ToString(cellType))) break; curSelected++; } if (curSelected >= _ComboBoxList.Length) curSelected = 0; Google2uGUIUtil.ComboBox comboBoxControl; if (!_ComboBoxes.ContainsKey(j)) { comboBoxControl = new Google2uGUIUtil.ComboBox(curRect, _ComboBoxList[curSelected], _ComboBoxList, in_layout.CellTypeButton, in_layout.OuterBox, in_layout.CellHeader); _ComboBoxes.Add(j, comboBoxControl); } else { comboBoxControl = _ComboBoxes[j]; } comboBoxControl.width = curRect.width; comboBoxControl.height = curRect.height; comboBoxControl.x = curRect.x; comboBoxControl.y = curRect.y; var newSelected = comboBoxControl.Show(); if (newSelected != curSelected) { var newType = (SupportedType) Enum.Parse(typeof (SupportedType), _ComboBoxList[newSelected].text, true); myCell.MyType = newType; myCell.SetValueFromType(); UpdateCellTypes = true; UpdateValidation = true; } } } else { for (var j = 0; j < RowsDisplay[i].Count; j++) { curRect.x += curRect.width; curRect.width = ColOptions[j].Width; if (curRect.x + curRect.width > _MyScrollPos.x && curRect.x < _MyScrollPos.x + Screen.width && curRect.y + curRect.height > _MyScrollPos.y && curRect.y < _MyScrollPos.y + scrollHeight) { if (i < 2 || i > 5 || !_ComboBoxes.ContainsKey(j) || _ComboBoxes[j].IsShown == false) { var newCell = RowsDisplay[i][j].DrawGUI(in_layout, curRect, ActiveCell); if (newCell != null) { GUI.FocusControl("Blank"); ActiveCell = newCell; } } } } } curRect.x = 0.0f; curRect.width = 40.0f; curRect.y += curRect.height; } GUI.EndScrollView(); } }