Esempio n. 1
0
        void OnGUI()
        {
            _enabled = EditorGUILayout.Toggle("Enable WakaTime", _enabled);
            _apiKey  = EditorGUILayout.TextField("API key", _apiKey);
            EditorGUILayout.LabelField("Project name", _projectName);

            if (GUILayout.Button("Change project name"))
            {
                ProjectEditWindow.Display();
                _needToReload = true;
            }

            _debug = EditorGUILayout.Toggle("Debug", _debug);

            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button("Save Preferences"))
            {
                EditorPrefs.SetString(Plugin.API_KEY_PREF, _apiKey);
                EditorPrefs.SetBool(Plugin.ENABLED_PREF, _enabled);
                EditorPrefs.SetBool(Plugin.DEBUG_PREF, _debug);
                Plugin.Initialize();
            }

            if (GUILayout.Button("Open Dashboard"))
            {
                Application.OpenURL(DASHBOARD_URL);
            }

            EditorGUILayout.EndHorizontal();
        }
        public static void Display()
        {
            if (_window)
            {
                FocusWindowIfItsOpen <ProjectEditWindow>();
            }
            else
            {
                _window = CreateInstance <ProjectEditWindow>();
                _window.ShowPopup();
            }

            // We need only first 2 lines from .wakatime-project
            _projectSettings = new[] { "", "" };
            var projectFile = Plugin.GetProjectFile();

            if (projectFile == null)
            {
                _isProjectFileMissed = true;
            }
            else
            {
                _isProjectFileMissed = false;
                projectFile.CopyTo(_projectSettings, 0);
            }

            _branch = string.IsNullOrEmpty(_projectSettings[1])
                ? "" // TODO: Read current git branch
                : _projectSettings[1];

            // If we need to display "project file missing" line, we are making different height
            // TODO: calculate height dynamically, if path is too long buttons may not fit
            _size.y = _isProjectFileMissed ? 170 : 138;

            // Display at screen center
            var pos = new Vector2(Screen.currentResolution.width, Screen.currentResolution.height) - _size;

            _window.position     = new Rect(pos / 2, _size);
            _window.titleContent = new GUIContent("Change project name");
        }
 /// <summary>
 /// Closes this window and erases instance
 /// </summary>
 private void CloseAndNull()
 {
     Close();
     _window = null;
 }