private void onProjectDeleted(object sender, EventArgs e)
 {
     onTextFieldInfoChanged(
         TextFieldInfo
         .RemoveProjectInfo()
         .WithTextAndCursor(TextFieldInfo.Text, TextFieldInfo.Text.Length));
 }
        private void selectSuggestion(AutocompleteSuggestion suggestion)
        {
            switch (suggestion)
            {
            case QuerySymbolSuggestion querySymbolSuggestion:
                TextFieldInfo = TextFieldInfo.WithTextAndCursor(querySymbolSuggestion.Symbol, 1);
                break;

            case TimeEntrySuggestion timeEntrySuggestion:

                TextFieldInfo = TextFieldInfo.WithTextAndCursor(
                    timeEntrySuggestion.Description,
                    timeEntrySuggestion.Description.Length);

                if (!timeEntrySuggestion.ProjectId.HasValue)
                {
                    TextFieldInfo = TextFieldInfo.RemoveProjectInfo();
                    return;
                }

                if (timeEntrySuggestion.TaskId == null)
                {
                    TextFieldInfo = TextFieldInfo.WithProjectInfo(
                        timeEntrySuggestion.ProjectId.Value,
                        timeEntrySuggestion.ProjectName,
                        timeEntrySuggestion.ProjectColor);
                    break;
                }

                TextFieldInfo = TextFieldInfo.WithProjectAndTaskInfo(
                    timeEntrySuggestion.ProjectId.Value,
                    timeEntrySuggestion.ProjectName,
                    timeEntrySuggestion.ProjectColor,
                    timeEntrySuggestion.TaskId.Value,
                    timeEntrySuggestion.TaskName);
                break;

            case ProjectSuggestion projectSuggestion:

                TextFieldInfo = TextFieldInfo
                                .RemoveProjectQueryFromDescriptionIfNeeded()
                                .WithProjectInfo(
                    projectSuggestion.ProjectId,
                    projectSuggestion.ProjectName,
                    projectSuggestion.ProjectColor);
                break;

            case TaskSuggestion taskSuggestion:

                TextFieldInfo = TextFieldInfo
                                .RemoveProjectQueryFromDescriptionIfNeeded()
                                .WithProjectAndTaskInfo(
                    taskSuggestion.ProjectId,
                    taskSuggestion.ProjectName,
                    taskSuggestion.ProjectColor,
                    taskSuggestion.TaskId,
                    taskSuggestion.Name
                    );
                break;

            case TagSuggestion tagSuggestion:

                TextFieldInfo = TextFieldInfo
                                .RemoveTagQueryFromDescriptionIfNeeded()
                                .AddTag(tagSuggestion);
                break;
            }
        }
예제 #3
0
        private async Task selectSuggestion(AutocompleteSuggestion suggestion)
        {
            switch (suggestion)
            {
            case QuerySymbolSuggestion querySymbolSuggestion:
                TextFieldInfo = TextFieldInfo.WithTextAndCursor(querySymbolSuggestion.Symbol, 1);
                break;

            case TimeEntrySuggestion timeEntrySuggestion:

                TextFieldInfo = TextFieldInfo.WithTextAndCursor(
                    timeEntrySuggestion.Description,
                    timeEntrySuggestion.Description.Length);

                if (!timeEntrySuggestion.ProjectId.HasValue)
                {
                    TextFieldInfo = TextFieldInfo.RemoveProjectInfo();
                    return;
                }

                if (timeEntrySuggestion.TaskId == null)
                {
                    TextFieldInfo = TextFieldInfo.WithProjectInfo(
                        timeEntrySuggestion.WorkspaceId,
                        timeEntrySuggestion.ProjectId.Value,
                        timeEntrySuggestion.ProjectName,
                        timeEntrySuggestion.ProjectColor);
                    break;
                }

                TextFieldInfo = TextFieldInfo.WithProjectAndTaskInfo(
                    timeEntrySuggestion.WorkspaceId,
                    timeEntrySuggestion.ProjectId.Value,
                    timeEntrySuggestion.ProjectName,
                    timeEntrySuggestion.ProjectColor,
                    timeEntrySuggestion.TaskId.Value,
                    timeEntrySuggestion.TaskName);
                break;

            case ProjectSuggestion projectSuggestion:

                if (TextFieldInfo.WorkspaceId == projectSuggestion.WorkspaceId)
                {
                    setProject(projectSuggestion);
                    break;
                }

                var shouldChangeProject = await dialogService.Confirm(
                    Resources.DifferentWorkspaceAlertTitle,
                    Resources.DifferentWorkspaceAlertMessage,
                    Resources.Ok,
                    Resources.Cancel);

                if (!shouldChangeProject)
                {
                    break;
                }

                setProject(projectSuggestion);

                break;

            case TaskSuggestion taskSuggestion:

                if (TextFieldInfo.WorkspaceId == taskSuggestion.WorkspaceId)
                {
                    setTask(taskSuggestion);
                    break;
                }

                var shouldChangeTask = await dialogService.Confirm(
                    Resources.DifferentWorkspaceAlertTitle,
                    Resources.DifferentWorkspaceAlertMessage,
                    Resources.Ok,
                    Resources.Cancel);

                if (!shouldChangeTask)
                {
                    break;
                }

                setTask(taskSuggestion);

                break;

            case TagSuggestion tagSuggestion:

                TextFieldInfo = TextFieldInfo
                                .RemoveTagQueryFromDescriptionIfNeeded()
                                .AddTag(tagSuggestion);
                break;
            }
        }