void PopulateColourCombo() { int index = 0; cmbColour.Items.Clear(); cmbColour.ImageList.Images.Clear(); cmbColour.ImageList.ColorDepth = ColorDepth.Depth32Bit; foreach (Task t in Todomoo.Tasks) { cmbColour.ImageList.Images.Add(IconColoured.GetSquared(t.Colour)); ImageComboItem item = new ImageComboItem(Lang.Get("colour_as") + " " + t.Name, index); item.Tag = t.Colour; cmbColour.Items.Add(item); index++; } if (cmbColour.Items.Count == 0) { cmbColour.ImageList.Images.Add(IconColoured.GetSquared(Color.Gray)); ImageComboItem item = new ImageComboItem(Lang.Get("default"), index); item.Tag = Color.Gray; cmbColour.Items.Add(item); index++; } cmbColour.SelectedIndex = 0; }
void PopulateCategoryCombo(int select_category) { int index = 0; cmbCategory.Items.Clear(); cmbCategory.ImageList.Images.Clear(); cmbCategory.ImageList.ColorDepth = ColorDepth.Depth32Bit; foreach (Category c in Todomoo.Categories) { cmbCategory.ImageList.Images.Add(IconColoured.GetSquared(c.Colour)); ImageComboItem item = new ImageComboItem(c.Name, index); item.Tag = c.Id; cmbCategory.Items.Add(item); index++; } if (cmbCategory.Items.Count == 0) { cmbCategory.Enabled = false; cmbCategory.Items.Add(new ImageComboItem(Lang.Get("category_must_create"))); } cmbCategory.SelectedIndex = 0; if (select_category != 0) { foreach (ImageComboItem item in cmbCategory.Items) { if ((int)item.Tag == select_category) { cmbCategory.SelectedItem = item; } } } }
void BtnChooseColourClick(object sender, EventArgs e) { if (colorDialog.ShowDialog() == DialogResult.OK) { Color col = colorDialog.Color; cmbColour.ImageList.Images.Add(IconColoured.GetSquared(col)); ImageComboItem item = new ImageComboItem("RGB [" + col.R + ", " + col.G + ", " + col.B + "]", cmbColour.Items.Count); item.Tag = col; cmbColour.Items.Add(item); cmbColour.SelectedIndex = cmbColour.Items.Count - 1; } }
/// <summary> /// Edit a Category object. /// </summary> /// <param name="category">Category to edit</param> public CategoryForm(Languages.Language language, Category category) { // Windows Forms designer support. InitializeComponent(); // Setup task this.category = category; // Create form icon this.Icon = IconColoured.GetSquaredIcon(category.Colour); // Setup language Lang = language; Text = Lang.Get((category.Id == 0) ? "category_add" : "category_edit"); btnOk.Text = " " + Lang.Get((category.Id == 0) ? "add" : "edit"); btnCancel.Text = Lang.Get("cancel"); btnChooseColour.Text = " " + Lang.Get("colour_choose"); lblName.Text = Lang.Get("name") + ":"; lblColour.Text = Lang.Get("colour") + ":"; // Populate colours combo int index = 0; cmbColour.ImageList.ColorDepth = ColorDepth.Depth32Bit; foreach (Category cat in Todomoo.Categories) { cmbColour.ImageList.Images.Add(IconColoured.GetSquared(cat.Colour)); ImageComboItem item = new ImageComboItem(Lang.Get("colour_as") + " " + cat.Name, index); item.Tag = cat.Colour; cmbColour.Items.Add(item); index++; } if (cmbColour.Items.Count == 0) { cmbColour.ImageList.Images.Add(IconColoured.GetSquared(Color.Gray)); ImageComboItem item = new ImageComboItem(Lang.Get("default"), index); item.Tag = Color.Gray; cmbColour.Items.Add(item); } cmbColour.SelectedIndex = 0; // Fill in GUI fields txtName.Text = category.Name; foreach (ImageComboItem item in cmbColour.Items) { if (item.Text == Lang.Get("colour_as") + " " + category.Name) { cmbColour.SelectedItem = item; } } }
/// <summary> /// Edit a Task object showing a specific section. /// </summary> /// <param name="task">Task to edit</param> /// <param name="start_tab">The forst section to show</param> public TaskForm(Languages.Language language, Utils.AppSettings settings, Task task, StartingTab start_tab) { // Windows Forms designer support. InitializeComponent(); // Setup task this.task = task; // Form icon System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(TaskForm)); Icon = (task.Id == 0) ? ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))) : ((System.Drawing.Icon)(resources.GetObject("$this.Icon2"))); // Language Lang = language; Text = Lang.Get((task.Id == 0) ? "task_add" : "task_edit"); btnOk.Text = " " + Lang.Get((task.Id == 0) ? "add" : "edit"); btnCancel.Text = Lang.Get("cancel"); ApplyLanguage(); // Settings Settings = settings; lblCurrency.Text = Settings.Get("currency").ToString(); // Starting tab switch (start_tab) { case StartingTab.DatesTime: tabs.SelectedTab = tabDatesTime; break; case StartingTab.Payment: tabs.SelectedTab = tabPayment; break; case StartingTab.Notes: tabs.SelectedTab = tabNotes; break; } // Populate combos PopulateColourCombo(); PopulatePriorityCombo(); PopulatePaymentCombo(); if (task.IsRoot()) { PopulateCategoryCombo(task.CategoryId); // Category combo also for root tasks } // Fill in GUI fields (general) txtName.Text = task.Name; try { txtDescription.Text = task.Description; } catch { txtDescription.Text = ""; } foreach (ImageComboItem item in cmbColour.Items) { if (item.Text == Lang.Get("colour_as") + " " + task.Name) { cmbColour.SelectedItem = item; } } cmbPriority.SelectedIndex = task.Priority % 3; // Fill in GUI fields (dates and time) dtCreationDate.Value = task.CreationDate; try { dtDueDate.Value = task.DueDate; chkDueDateNot.Checked = false; } catch { chkDueDateNot.Checked = true; } try { dtCompleted.Value = task.Completed; chkCompletedNot.Checked = false; } catch { chkCompletedNot.Checked = true; } try { int t = task.Timer; chkUseTimer.Checked = true; } catch { chkUseTimer.Checked = false; } try { numTimerS.Value = task.Timer % 60; numTimerM.Value = ((task.Timer - numTimerS.Value) / 60) % 60; numTimerH.Value = (task.Timer - numTimerS.Value - numTimerM.Value * 60) / (60 * 60); } catch { } // If the timer is running, disable timer fields. if (task.IsTimerRunning()) { chkUseTimer.Enabled = false; lblTimer.Visible = btnTimerReset.Visible = btnSumTimers.Visible = false; numTimerS.Visible = numTimerM.Visible = numTimerH.Visible = false; lblTimerS.Visible = lblTimerM.Visible = lblTimerH.Visible = false; panCannotEditTimer.Visible = true; lblCannotEditTimer.Text = Lang.Get("task_timer_is_running"); } // Fill in GUI fields (payment) try { chkPerHour.Checked = task.PricingByHour; if (task.PricingByHour) { numPrice.Value = (Decimal)task.PriceByHour; } else { numPrice.Value = (Decimal)task.Price; } chkPriceNot.Checked = false; } catch { chkPriceNot.Checked = true; } try { dtPaid.Value = task.Paid; chkPaidNot.Checked = false; } catch { chkPaidNot.Checked = true; } try { cmbPaymentType.Text = task.Payment; } catch { } try { txtPaymentNote.Text = task.PaymentNote; } catch { txtPaymentNote.Text = ""; } chkPerHour.Enabled = !chkPriceNot.Checked; // Show/hide task parent if (task.ParentId != 0) { cmbCategory.Hide(); } lblCategory.Visible = btnAddCategory.Visible = (task.ParentId == 0); btnAddCategory.Enabled = (task.ParentId == 0); lblSubTaskOf.Visible = panParent.Visible = (task.ParentId != 0); // Setup task parent if (!task.IsRoot()) { try { Task parent = new Task(task.ParentId); lblParentName.Text = parent.Name; boxParentIcon.Image = IconColoured.GetSquared(parent.Colour); task.CategoryId = parent.CategoryId; // Same category of the parent! if (task.Id == 0) { foreach (ImageComboItem item in cmbColour.Items) { if (item.Text == Lang.Get("colour_as") + " " + parent.Name) { cmbColour.SelectedItem = item; } } } } catch { lblParentName.Text = Lang.Get("task_loading_error"); boxParentIcon.Image = IconColoured.GetSquared(Color.Gray); } } // Notes settings (this is not so good, calling MainForm in this way...) try { notes_monospace_font = new FontFamily("Consolas"); } catch { } chkMonospace.Checked = (Todomoo.mainForm.Settings.Get("note_monospace").ToString() == "1"); chkWordWrap.Checked = (Todomoo.mainForm.Settings.Get("note_word_wrap").ToString() == "1"); // Draw note accordion DrawNotesAccordion(); // Form size and "sizeability" TabsSelectedIndexChanged(); TaskFormResize(); }