Example #1
0
 public void PopupInput(Toggl.TimeEntry te)
 {
     if (te.GUID == editForm.GUID)
     {
         if (editableEntry.GetType() == typeof(TimeEntryCell))
         {
             ((TimeEntryCell)editableEntry).opened = false;
         }
         editForm.CloseButton_Click(null, null);
         return;
     }
     if (editableEntry != null && editableEntry.GetType() == typeof(TimeEntryCell))
     {
         ((TimeEntryCell)editableEntry).opened = false;
     }
     editForm.reset();
     editableEntry = getSelectedEntryByGUID(te.GUID);
     if (null == editableEntry)
     {
         return;
     }
     setEditFormLocation(te.DurationInSeconds < 0);
     editForm.GUID = te.GUID;
     editForm.Show();
 }
Example #2
0
        void OnRunningTimerState(Toggl.TimeEntry te)
        {
            if (InvokeRequired)
            {
                Invoke((MethodInvoker) delegate { OnRunningTimerState(te); });
                return;
            }
            isTracking = true;
            enableMenuItems();
            updateStatusIcons(true);

            string newText = "Toggl Desktop";

            if (te.Description.Length > 0)
            {
                runningToolStripMenuItem.Text = te.Description.Replace("&", "&&");
                newText = te.Description + " - Toggl Desktop";
            }
            else
            {
                runningToolStripMenuItem.Text = "Timer is tracking";
            }
            if (newText.Length > 63)
            {
                newText = newText.Substring(0, 60) + "...";
            }
            Text = newText;
            if (trayIcon != null)
            {
                trayIcon.Text = Text;
            }
            updateResizeHandleBackground();
        }
Example #3
0
        private void renderTimeEntryList(List <Toggl.TimeEntry> list)
        {
            emptyLabel.Visible = (list.Count == 0);
            entries.SuspendLayout();

            // Hide entry list for initial loading to avoid crazy flicker
            if (entries.Controls.Count == 0)
            {
                entries.Visible = false;
            }

            for (int i = 0; i < list.Count; i++)
            {
                Toggl.TimeEntry te = list.ElementAt(i);

                TimeEntryCell cell = null;
                if (entries.Controls.Count > i)
                {
                    cell = entries.Controls[i] as TimeEntryCell;
                }

                if (cell == null)
                {
                    cell = new TimeEntryCell(this);
                    entries.Controls.Add(cell);
                    if (i == 0)
                    {
                        cell.Width = entries.Width;
                    }
                    else
                    {
                        cell.Dock = DockStyle.Top;
                    }
                }

                cell.Display(te);
                entries.Controls.SetChildIndex(cell, i);
            }

            while (entries.Controls.Count > list.Count)
            {
                entries.Controls.RemoveAt(list.Count);
            }

            entries.ResumeLayout();
            entries.PerformLayout();

            if (!entries.Visible)
            {
                entries.Visible = true;
            }
        }
Example #4
0
        void OnRunningTimerState(Toggl.TimeEntry te)
        {
            if (InvokeRequired)
            {
                Invoke((MethodInvoker) delegate { OnRunningTimerState(te); });
                return;
            }
            duration_in_seconds = te.DurationInSeconds;

            timerRunningDuration.Enabled = true;

            labelClearProject.Visible = false;

            buttonStart.Text      = "Stop";
            buttonStart.BackColor = ColorTranslator.FromHtml("#ff3d32");
            buttonStart.FlatAppearance.BorderColor = ColorTranslator.FromHtml("#ff3d32");
            if (te.ProjectAndTaskLabel.Length > 0)
            {
                linkLabelProject.Text    = te.ProjectAndTaskLabel;
                linkLabelProject.Visible = true;
                descriptionTextBox.Top   = projectDescriptionTop + 1;
            }
            else
            {
                linkLabelProject.Visible = false;
                descriptionTextBox.Top   = defaultDescriptionTop;
            }

            linkLabelDescription.Top  = descriptionTextBox.Top;
            linkLabelDescription.Left = descriptionTextBox.Left - 3;
            linkLabelDescription.Text = te.Description;
            if (linkLabelDescription.Text.Length == 0)
            {
                linkLabelDescription.Text = "(no description)";
            }
            linkLabelDescription.Visible = true;

            descriptionTextBox.Visible = false;
            descriptionTextBox.Text    = "";

            linkLabelDuration.Top     = textBoxDuration.Top;
            linkLabelDuration.Text    = te.Duration;
            linkLabelDuration.Visible = true;

            textBoxDuration.Visible = false;
            textBoxDuration.Text    = "";

            task_id    = 0;
            project_id = 0;
        }
Example #5
0
        internal void Display(Toggl.TimeEntry item)
        {
            GUID = item.GUID;
            string Color = (item.Color.Length > 0) ? item.Color : "#999999";

            if (item.Description.Length == 0)
            {
                labelDescription.Text = "(no description)";
            }
            else
            {
                labelDescription.Text = item.Description;
            }

            labelProject.ForeColor = ProjectColorPanel.BackColor = ColorTranslator.FromHtml(Color);
            labelProject.Text      = (item.ClientLabel.Length > 0) ? "• " + item.ProjectLabel : item.ProjectLabel;
            labelClient.Text       = item.ClientLabel;
            labelTask.Text         = item.TaskLabel;
            labelDuration.Text     = item.Duration;
            labelBillable.Visible  = item.Billable;
            labelTag.Visible       = (item.Tags != null && item.Tags.Length > 0);

            if (item.IsHeader)
            {
                labelFormattedDate.Text = item.DateHeader;
                labelDateDuration.Text  = item.DateDuration;
                Height    = headerPanel.Height + panel.Height;
                panel.Top = headerPanel.Bottom;
                header    = true;
            }
            else
            {
                Height    = panel.Height;
                panel.Top = 0;
                header    = false;
            }
            headerPanel.Visible = item.IsHeader;
            toolTip.SetToolTip(labelDescription, item.Description);
            toolTip.SetToolTip(labelTask, item.ProjectAndTaskLabel);
            toolTip.SetToolTip(labelProject, item.ProjectAndTaskLabel);
            toolTip.SetToolTip(labelClient, item.ProjectAndTaskLabel);
            if (!item.DurOnly)
            {
                toolTip.SetToolTip(labelDuration, item.StartTimeString + " - " + item.EndTimeString);
            }
            if (labelTag.Visible)
            {
                toolTip.SetToolTip(labelTag, item.Tags.Replace(Toggl.TagSeparator, ", "));
            }
        }
Example #6
0
 void OnTimeEntryEditor(
     bool open,
     Toggl.TimeEntry te,
     string focused_field_name)
 {
     if (InvokeRequired)
     {
         Invoke((MethodInvoker) delegate { OnTimeEntryEditor(open, te, focused_field_name); });
         return;
     }
     if (open)
     {
         contentPanel.Controls.Remove(loginViewController);
         MinimumSize = new Size(230, 86);
         timeEntryEditViewController.setupView(this, focused_field_name);
         PopupInput(te);
     }
 }
        private void setCheckedTags(Toggl.TimeEntry te)
        {
            if (te.Tags != null)
            {
                int      count = 0;
                string[] tags  = te.Tags.Split(Toggl.TagSeparator.ToCharArray());

                // Tick selected Tags
                for (int i = 0; i < tags.Length; i++)
                {
                    int index = checkedListBoxTags.Items.IndexOf(tags[i]);
                    if (index != -1)
                    {
                        checkedListBoxTags.Items.RemoveAt(index);
                        checkedListBoxTags.Items.Insert(count, tags[i]);
                        checkedListBoxTags.SetItemChecked(count, true);
                        count++;
                    }
                }
            }
        }
        private void onStoppedTimerState()
        {
            if (this.invoke(this.onStoppedTimerState))
                return;

            this.secondsTimer.IsEnabled = false;
            this.setUIToStoppedState();
            this.runningTimeEntry = default(Toggl.TimeEntry);
        }
        private void onRunningTimerState(Toggl.TimeEntry te)
        {
            if (this.invoke(() => this.onRunningTimerState(te)))
                return;

            this.runningTimeEntry = te;
            this.setUIToRunningState(te);
            this.secondsTimer.IsEnabled = true;
        }
        private void onStoppedTimerState()
        {
            if (!this.Dispatcher.CheckAccess())
            {
                this.Dispatcher.BeginInvoke(new Action(() => onStoppedTimerState()));
                return;
            }

            this.secondsTimer.IsEnabled = false;
            this.setUIToStoppedState();
            this.runningTimeEntry = default(Toggl.TimeEntry);
        }
        private void onRunningTimerState(Toggl.TimeEntry te)
        {
            if (!this.Dispatcher.CheckAccess())
            {
                this.Dispatcher.BeginInvoke(new Action(() => onRunningTimerState(te)));
                return;
            }

            this.runningTimeEntry = te;
            this.setUIToRunningState(te);
            this.secondsTimer.IsEnabled = true;
        }
        private void onTimeEntryEditor(bool open, Toggl.TimeEntry timeEntry, string focusedFieldName)
        {
            if (this.invoke(() => this.onTimeEntryEditor(open, timeEntry, focusedFieldName)))
                return;

            this.timeEntry = timeEntry;

            var isCurrentlyRunning = timeEntry.DurationInSeconds < 0;

            this.endTimeTextBox.IsEnabled = !isCurrentlyRunning;

            if (open)
            {
                this.descriptionTextBox.SetText(timeEntry.Description);
                this.durationTextBox.Text = timeEntry.Duration;
                setTime(this.startTimeTextBox, timeEntry.StartTimeString);
                setTime(this.endTimeTextBox, timeEntry.EndTimeString);
                this.projectTextBox.SetText(timeEntry.ProjectLabel);
                this.clientTextBox.SetText(timeEntry.ClientLabel);
                this.startDatePicker.SelectedDate = Toggl.DateTimeFromUnix(timeEntry.Started);
            }
            else
            {
                setTextIfUnfocused(this.descriptionTextBox, timeEntry.Description);
                setTextIfUnfocused(this.durationTextBox, timeEntry.Duration);
                setTimeIfUnfocused(this.startTimeTextBox, timeEntry.StartTimeString);
                setTimeIfUnfocused(this.endTimeTextBox, timeEntry.EndTimeString);
                setTextIfUnfocused(this.projectTextBox, timeEntry.ProjectLabel);

                if (!this.startDatePicker.IsFocused)
                    this.startDatePicker.SelectedDate = Toggl.DateTimeFromUnix(timeEntry.Started);
            }

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

            this.billableCheckBox.Visibility = timeEntry.CanSeeBillable ? Visibility.Visible : Visibility.Collapsed;
            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;
            }

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

            if (this.isInNewProjectMode)
                this.disableNewProjectMode();

            this.projectColorCircle.Background = new SolidColorBrush(getProjectColor(timeEntry.Color));

            this.selectedWorkspaceId = timeEntry.WID;
            this.selectedWorkspaceName = timeEntry.WorkspaceName;

            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;
            }
        }
 private void onLogin(bool open, ulong userId)
 {
     this.timeEntry = new Toggl.TimeEntry();
     this.projects = null;
     this.clients = null;
     this.workspaces = null;
 }
        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;
        }
 private void onLogin(bool open, ulong userId)
 {
     if (!this.Dispatcher.CheckAccess())
     {
         this.Dispatcher.BeginInvoke(new Action(() => this.onLogin(open, userId)));
         return;
     }
     this.timeEntry = new Toggl.TimeEntry();
     this.projects = null;
     this.clients = null;
     this.workspaces = null;
 }