示例#1
0
        private void saveDate()
        {
            if (!this.hasTimeEntry())
            {
                Console.WriteLine("Cannot apply date change: No time entry.");
                return;
            }
            if (!this.startDatePicker.SelectedDate.HasValue)
            {
                this.startDatePicker.SelectedDate = Toggl.DateTimeFromUnix(this.timeEntry.Started);
                return;
            }

            DateTime currentDate = Toggl.DateTimeFromUnix(timeEntry.Started);

            try {
                DateTime selected = Convert.ToDateTime(this.startDatePicker.Text);

                if (!currentDate.Date.Equals(selected.Date))
                {
                    currentDate = selected;
                    Toggl.SetTimeEntryDate(this.timeEntry.GUID, selected);
                }
            }
            catch (Exception e)
            {
                System.Console.WriteLine("Catched error: " + e.Message);
            }
        }
 private void applyDateChangeOrReset()
 {
     if (!this.hasTimeEntry())
     {
         Console.WriteLine("Cannot apply date change: No time entry.");
         return;
     }
     if (!this.startDatePicker.SelectedDate.HasValue)
     {
         this.startDatePicker.SelectedDate = Toggl.DateTimeFromUnix(this.timeEntry.Started);
         return;
     }
     Toggl.SetTimeEntryDate(this.timeEntry.GUID, this.startDatePicker.SelectedDate.Value);
 }
        private void saveDate()
        {
            if (!this.hasTimeEntry())
            {
                Console.WriteLine("Cannot apply date change: No time entry.");
                return;
            }
            if (!this.startDatePicker.SelectedDate.HasValue)
            {
                this.startDatePicker.SelectedDate = Toggl.DateTimeFromUnix(this.timeEntry.Started);
                return;
            }

            DateTime currentDate = Toggl.DateTimeFromUnix(timeEntry.Started);

            if (!currentDate.Equals(this.startDatePicker.SelectedDate.Value))
            {
                currentDate = this.startDatePicker.SelectedDate.Value;
                Toggl.SetTimeEntryDate(this.timeEntry.GUID, currentDate);
            }
        }
示例#4
0
        public void Display(List <Toggl.TogglTimeEntryView> items, Action <string, TimeEntryCell> registerCellByGUID)
        {
            var item = items[0];

            if (!item.IsHeader)
            {
                throw new InvalidDataException("Can only create day header from header time entry view.");
            }

            this.date = Toggl.DateTimeFromUnix(item.Started);

            if (this.labelFormattedDate.Text != item.DateHeader)
            {
                this.panel.Visibility = Visibility.Visible;
            }

            this.labelFormattedDate.Text = item.DateHeader;
            this.labelDateDuration.Text  = item.DateDuration;

            this.fillCells(items, registerCellByGUID);
        }
示例#5
0
 public static DateTime EndTime(this Toggl.TimelineChunkView chunk) => Toggl.DateTimeFromUnix(chunk.Ended);
示例#6
0
 public static DateTime StartTime(this Toggl.TimelineChunkView chunk) => Toggl.DateTimeFromUnix(chunk.Started);
示例#7
0
 public static DateTime EndTime(this Toggl.TogglTimeEntryView te) => Toggl.DateTimeFromUnix(te.Ended);
示例#8
0
 public static DateTime StartTime(this Toggl.TogglTimeEntryView te) => Toggl.DateTimeFromUnix(te.Started);
        private void onTimeEntryEditor(bool open, Toggl.TogglTimeEntryView timeEntry, string focusedFieldName)
        {
            if (this.TryBeginInvoke(this.onTimeEntryEditor, open, timeEntry, focusedFieldName))
            {
                return;
            }

            using (Performance.Measure("filling edit view from OnTimeEntryEditor"))
            {
                this.dateSet = false;
                if (timeEntry.Locked)
                {
                    open = true;
                    this.contentGrid.IsEnabled = false;
                    this.contentGrid.Opacity   = 0.75;
                }
                else
                {
                    this.contentGrid.IsEnabled = true;
                    this.contentGrid.Opacity   = 1;
                }

                var keepNewProjectModeOpen =
                    !open &&
                    this.isInNewProjectMode &&
                    this.hasTimeEntry() &&
                    this.timeEntry.GUID == timeEntry.GUID &&
                    this.timeEntry.PID == timeEntry.PID &&
                    this.timeEntry.WID == timeEntry.WID &&
                    timeEntry.CanAddProjects;

                if (!keepNewProjectModeOpen && this.hasTimeEntry() && this.isInNewProjectMode)
                {
                    this.confirmNewProject();
                }

                var isDifferentTimeEntry = this.timeEntry.GUID != timeEntry.GUID;

                this.timeEntry = timeEntry;

                var isCurrentlyRunning = timeEntry.DurationInSeconds < 0;

                this.endTimeTextBox.IsEnabled  = !isCurrentlyRunning;
                this.startDatePicker.IsEnabled = !isCurrentlyRunning;

                var startDateTime = Toggl.DateTimeFromUnix(timeEntry.Started);
                var endDateTime   = Toggl.DateTimeFromUnix(timeEntry.Ended);

                setText(this.descriptionTextBox, timeEntry.Description, open);
                setTime(this.durationTextBox, timeEntry.Duration, open);
                setTime(this.startTimeTextBox, timeEntry.StartTimeString, open);
                this.startTimeTextBox.ToolTip = startDateTime.ToString("T", CultureInfo.CurrentCulture);
                setTime(this.endTimeTextBox, timeEntry.EndTimeString, open);
                this.endTimeTextBox.ToolTip       = endDateTime.ToString("T", CultureInfo.CurrentCulture);
                this.startDatePicker.SelectedDate = startDateTime;
                if (isDifferentTimeEntry)
                {
                    this.clearUndoHistory();
                }

                if (isCurrentlyRunning)
                {
                    this.endTimeTextBox.Text = "";
                }

                this.billableCheckBox.ShowOnlyIf(timeEntry.CanSeeBillable);
                this.billableCheckBox.IsChecked = timeEntry.Billable;

                if (open || !this.tagList.IsKeyboardFocusWithin)
                {
                    this.tagList.Clear(open);
                    if (timeEntry.Tags != null)
                    {
                        this.tagList.AddTags(timeEntry.Tags.Split(new[] { Toggl.TagSeparator },
                                                                  StringSplitOptions.RemoveEmptyEntries));
                    }
                }

                if (!keepNewProjectModeOpen)
                {
                    if (this.isInNewProjectMode)
                    {
                        this.createProjectPopup.IsOpen = false;
                        this.disableNewProjectMode();
                    }

                    this.selectedProjectColorCircle.Background = Utils.AdaptedProjectColorBrushFromString(timeEntry.Color);

                    setText(this.projectTextBox, timeEntry.ProjectLabel, timeEntry.TaskLabel, open);
                    projectTextBox.DataContext = timeEntry.ToProjectLabelViewModel();

                    setText(this.clientTextBox, timeEntry.ClientLabel, open);

                    this.selectedWorkspaceId = timeEntry.WID;
                    this.reloadWorkspaceClients(timeEntry.WID);

                    this.projectAutoComplete.ActionButtonText =
                        timeEntry.CanAddProjects
                            ? "Create a new project"
                            : string.Empty;
                }
                this.dateSet = true;
            }
        }
示例#10
0
        private void onTimeEntryEditor(bool open, Toggl.TogglTimeEntryView timeEntry, string focusedFieldName)
        {
            if (this.TryBeginInvoke(this.onTimeEntryEditor, open, timeEntry, focusedFieldName))
            {
                return;
            }

            using (Performance.Measure("filling edit view from OnTimeEntryEditor"))
            {
                this.dateSet = false;
                if (timeEntry.Locked)
                {
                    open = true;
                    this.contentGrid.IsEnabled = false;
                    this.contentGrid.Opacity   = 0.75;
                }
                else
                {
                    this.contentGrid.IsEnabled = true;
                    this.contentGrid.Opacity   = 1;
                }

                var keepNewProjectModeOpen =
                    !open &&
                    this.isInNewProjectMode &&
                    this.hasTimeEntry() &&
                    this.timeEntry.GUID == timeEntry.GUID &&
                    this.timeEntry.PID == timeEntry.PID &&
                    this.timeEntry.WID == timeEntry.WID &&
                    timeEntry.CanAddProjects;

                if (!keepNewProjectModeOpen && this.hasTimeEntry() && this.isInNewProjectMode)
                {
                    this.confirmNewProject();
                }

                var isDifferentTimeEntry = this.timeEntry.GUID != timeEntry.GUID;

                this.timeEntry = timeEntry;

                var isCurrentlyRunning = timeEntry.DurationInSeconds < 0;

                this.endTimeTextBox.IsEnabled  = !isCurrentlyRunning;
                this.startDatePicker.IsEnabled = !isCurrentlyRunning;

                setText(this.descriptionTextBox, timeEntry.Description, open);
                setTime(this.durationTextBox, timeEntry.Duration, open);
                setTime(this.startTimeTextBox, timeEntry.StartTimeString, open);
                setTime(this.endTimeTextBox, timeEntry.EndTimeString, open);
                this.startDatePicker.SelectedDate = Toggl.DateTimeFromUnix(timeEntry.Started);
                if (isDifferentTimeEntry)
                {
                    this.clearUndoHistory();
                }

                if (isCurrentlyRunning)
                {
                    this.endTimeTextBox.Text = "";
                }

                this.billableCheckBox.ShowOnlyIf(timeEntry.CanSeeBillable);
                this.billableCheckBox.IsChecked = timeEntry.Billable;

                if (timeEntry.UpdatedAt > 0)
                {
                    var updatedAt = Toggl.DateTimeFromUnix(timeEntry.UpdatedAt);
                    this.lastUpdatedText.Text = "Last update " + updatedAt.ToShortDateString() + " at " +
                                                updatedAt.ToLongTimeString();
                    this.lastUpdatedText.Visibility = Visibility.Visible;
                }
                else
                {
                    this.lastUpdatedText.Visibility = Visibility.Collapsed;
                }

                if (open || !this.tagList.IsKeyboardFocusWithin)
                {
                    this.tagList.Clear(open);
                    if (timeEntry.Tags != null)
                    {
                        this.tagList.AddTags(timeEntry.Tags.Split(new[] { Toggl.TagSeparator },
                                                                  StringSplitOptions.RemoveEmptyEntries));
                    }
                    this.updateTagListEmptyText();
                }

                if (!keepNewProjectModeOpen)
                {
                    if (this.isInNewProjectMode)
                    {
                        this.disableNewProjectMode();
                    }

                    this.projectColorSelector.SelectedColor = timeEntry.Color;

                    setText(this.projectTextBox, timeEntry.ProjectLabel, timeEntry.TaskLabel, open);
                    setText(this.clientTextBox, timeEntry.ClientLabel, open);

                    this.selectedWorkspaceId   = timeEntry.WID;
                    this.selectedWorkspaceName = timeEntry.WorkspaceName;
                    this.reloadWorkspaceClients(timeEntry.WID);

                    if (timeEntry.CanAddProjects)
                    {
                        this.newProjectButton.Visibility            = Visibility.Visible;
                        this.projectAddButtonColumn.Width           = GridLength.Auto;
                        this.projectAddButtonColumn.SharedSizeGroup = "AddButtons";
                    }
                    else
                    {
                        this.newProjectButton.Visibility            = Visibility.Hidden;
                        this.projectAddButtonColumn.Width           = new GridLength(0);
                        this.projectAddButtonColumn.SharedSizeGroup = null;
                    }
                }
                this.dateSet = true;
            }
        }
        void OnTimeEntryEditor(
            bool open,
            Toggl.TimeEntry te,
            string focused_field_name)
        {
            if (InvokeRequired)
            {
                Invoke((MethodInvoker) delegate { OnTimeEntryEditor(open, te, focused_field_name); });
                return;
            }
            //
            // Custom Combobox Buttons
            //
            projectButton.Height  = projectButton.Width = descriptionButton.Height = descriptionButton.Width = comboBoxDescription.Height;
            projectButton.Left    = descriptionButton.Left = comboBoxProject.Left + comboBoxProject.Width - 1;
            descriptionButton.Top = comboBoxDescription.Top;
            projectButton.Top     = comboBoxProject.Top;

            timeEntry = te;

            panelBillable.Visible = te.CanSeeBillable;

            checkBoxBillable.Tag = this;
            try
            {
                checkBoxBillable.Checked = te.Billable;
            }
            finally
            {
                checkBoxBillable.Tag = null;
            }

            if (!te.CanAddProjects)
            {
                linkAddProject.Visible = !te.CanAddProjects;
            }

            if (open)
            {
                comboBoxDescription.ResetListBox();
                comboBoxProject.ResetListBox();
                comboBoxDescription.Text = te.Description;
                comboBoxProject.Text     = te.ProjectAndTaskLabel;
                textBoxDuration.Text     = te.Duration;
                setTimeValue(textBoxStartTime, te.StartTimeString);
                setTimeValue(textBoxEndTime, te.EndTimeString);
                dateTimePickerStartDate.Value = Toggl.DateTimeFromUnix(te.Started);
                resetTagFilter();
            }
            else
            {
                if (!comboBoxDescription.Focused)
                {
                    comboBoxDescription.Text = te.Description;
                }
                if (!comboBoxProject.Focused)
                {
                    comboBoxProject.Text = te.ProjectAndTaskLabel;
                }
                if (!textBoxDuration.Focused)
                {
                    textBoxDuration.Text = te.Duration;
                }
                if (!textBoxStartTime.Focused)
                {
                    setTimeValue(textBoxStartTime, te.StartTimeString);
                }
                if (!textBoxEndTime.Focused)
                {
                    setTimeValue(textBoxEndTime, te.EndTimeString);
                }
                if (!dateTimePickerStartDate.Focused)
                {
                    dateTimePickerStartDate.Value = Toggl.DateTimeFromUnix(te.Started);
                }
            }

            panelStartEndTime.Visible = !timeEntry.DurOnly;

            if (timeEntry.DurOnly)
            {
                panelDateTag.Top = panelDuration.Top + panelDuration.Height;
            }
            else
            {
                panelDateTag.Top = panelStartEndTime.Top + panelStartEndTime.Height;
            }
            panelDateTag.Height = panelBottom.Height - panelDateTag.Top;

            if (te.UpdatedAt > 0)
            {
                DateTime updatedAt = Toggl.DateTimeFromUnix(te.UpdatedAt);
                toolStripStatusLabelLastUpdate.Text    = "Last update: " + updatedAt.ToString();
                toolStripStatusLabelLastUpdate.Visible = true;
            }
            else
            {
                toolStripStatusLabelLastUpdate.Visible = false;
            }
            textBoxEndTime.Enabled = (te.DurationInSeconds >= 0);

            if (!checkedListBoxTags.Focused || open)
            {
                for (int i = 0; i < checkedListBoxTags.Items.Count; i++)
                {
                    checkedListBoxTags.SetItemChecked(i, false);
                }
                setCheckedTags(te);
            }

            workspaceNameLabel.Text = te.WorkspaceName;
        }