private List<string> availableCategories;
public bool ExportAll { get; private set; } = true;
public bool ExportByCategory => !ExportAll;
public List<string> SelectedCategories { get; private set; } = new List<string>();
public bool KeepContentAsHtml { get; private set; } = false; // Yeni özellik
public ExportSettingsForm(List<string> categories)
{
availableCategories = categories;
InitializeComponent();
}
private void InitializeComponent()
{
// Pencereyi modern ve şık hale getirmek için genel ayarlar
this.Text = "Export Options";
this.Size = new Size(500, 640); // Genişlik artırıldı, yükseklik sabitlendi
this.Font = new System.Drawing.Font("Segoe UI", 10);
this.FormBorderStyle = FormBorderStyle.FixedDialog;
this.StartPosition = FormStartPosition.CenterParent;
this.BackColor = Color.White;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.AutoScaleMode = AutoScaleMode.None;
int leftMargin = 20;
int rightMargin = 20;
int currentTop = 20;
int controlWidth = this.ClientSize.Width - leftMargin - rightMargin;
// Select Fields Label
Label lblSelectFields = new Label
{
Text = "Select fields to export:",
Left = leftMargin,
Top = currentTop,
Width = controlWidth,
ForeColor = Color.DarkSlateGray
};
this.Controls.Add(lblSelectFields);
currentTop += lblSelectFields.Height + 10;
// Fields CheckedListBox
clbFields = new CheckedListBox
{
Left = leftMargin,
Top = currentTop,
Width = controlWidth,
Height = 200, // Yükseklik artırıldı
BackColor = Color.White,
BorderStyle = BorderStyle.FixedSingle
};
clbFields.Items.AddRange(new object[]
{
"id",
"category",
"title",
"content",
"favorite",
"pinned",
"backgroundColor",
"timestamp",
"updatedAt",
"hashtags"
});
this.Controls.Add(clbFields);
currentTop += clbFields.Height + 5;
// Select All Fields CheckBox
chkSelectAllFields = new CheckBox
{
Text = "Select All Fields",
Left = leftMargin,
Top = currentTop,
Width = 200,
ForeColor = Color.DarkSlateGray
};
chkSelectAllFields.CheckedChanged += ChkSelectAllFields_CheckedChanged;
this.Controls.Add(chkSelectAllFields);
currentTop += chkSelectAllFields.Height + 20;
// Export Options GroupBox
grpExportOptions = new GroupBox
{
Text = "Export Options",
Left = leftMargin,
Top = currentTop,
Width = controlWidth,
Height = 100, // Yükseklik ayarlandı
ForeColor = Color.DarkSlateGray
};
this.Controls.Add(grpExportOptions);
// Export Options RadioButtons
rdbExportAll = new RadioButton
{
Text = "All Flashcards",
Left = 15,
Top = 25,
Checked = true,
ForeColor = Color.DarkSlateGray
};
rdbExportAll.CheckedChanged += RdbExportOptions_CheckedChanged;
grpExportOptions.Controls.Add(rdbExportAll);
rdbExportByCategory = new RadioButton
{
Text = "Export by Category",
Left = 15,
Top = 55,
Checked = false,
ForeColor = Color.DarkSlateGray
};
rdbExportByCategory.CheckedChanged += RdbExportOptions_CheckedChanged;
grpExportOptions.Controls.Add(rdbExportByCategory);
currentTop += grpExportOptions.Height + 10;
// Content Format GroupBox
grpContentFormat = new GroupBox
{
Text = "Content Format",
Left = leftMargin,
Top = currentTop,
Width = controlWidth,
Height = 100, // Yükseklik ayarlandı
ForeColor = Color.DarkSlateGray
};
this.Controls.Add(grpContentFormat);
// Content Format RadioButtons
rdbConvertToText = new RadioButton
{
Text = "Plain Text (Default)",
Left = 15,
Top = 30,
Checked = true,
ForeColor = Color.DarkSlateGray
};
grpContentFormat.Controls.Add(rdbConvertToText);
rdbKeepHtml = new RadioButton
{
Text = "Keep as HTML",
Left = 15,
Top = 60,
Checked = false,
ForeColor = Color.DarkSlateGray
};
grpContentFormat.Controls.Add(rdbKeepHtml);
currentTop += grpContentFormat.Height + 10;
// OK and Cancel Buttons
int buttonWidth = 100;
int buttonHeight = 35;
int buttonSpacing = 20;
int totalButtonWidth = (buttonWidth * 2) + buttonSpacing;
int buttonsLeft = (this.ClientSize.Width - totalButtonWidth) / 2;
int buttonsTop = currentTop;
btnOK = new Button
{
Text = "OK",
Width = buttonWidth,
Height = buttonHeight,
Left = buttonsLeft,
Top = buttonsTop,
BackColor = Color.LightSlateGray,
ForeColor = Color.White,
FlatStyle = FlatStyle.Flat,
TabIndex = 0
};
btnOK.FlatAppearance.BorderSize = 0;
btnOK.Click += BtnOK_Click;
this.Controls.Add(btnOK);
btnCancel = new Button
{
Text = "Cancel",
Width = buttonWidth,
Height = buttonHeight,
Left = buttonsLeft + buttonWidth + buttonSpacing,
Top = buttonsTop,
BackColor = Color.LightSlateGray,
ForeColor = Color.White,
FlatStyle = FlatStyle.Flat,
TabIndex = 1
};
btnCancel.FlatAppearance.BorderSize = 0;
btnCancel.Click += (s, e) => this.Close();
this.Controls.Add(btnCancel);
// Accept and Cancel buttons at form level
this.AcceptButton = btnOK;
this.CancelButton = btnCancel;
currentTop += buttonHeight + 20;
// Categories Selection Label
Label lblSelectCategories = new Label
{
Text = "Select categories to export:",
Left = leftMargin,
Top = currentTop,
Width = controlWidth,
Visible = false,
ForeColor = Color.DarkSlateGray
};
this.Controls.Add(lblSelectCategories);
currentTop += lblSelectCategories.Height + 10;
// Categories CheckedListBox
clbCategories = new CheckedListBox
{
Left = leftMargin,
Top = currentTop,
Width = controlWidth,
Height = 150, // Yükseklik artırıldı
Visible = false,
BackColor = Color.White,
BorderStyle = BorderStyle.FixedSingle
};
clbCategories.Items.AddRange(availableCategories.ToArray());
this.Controls.Add(clbCategories);
currentTop += clbCategories.Height + 5;
// Select All Categories CheckBox
chkSelectAllCategories = new CheckBox
{
Text = "Select All Categories",
Left = leftMargin,
Top = currentTop,
Width = 200,
Visible = false,
ForeColor = Color.DarkSlateGray
};
chkSelectAllCategories.CheckedChanged += ChkSelectAllCategories_CheckedChanged;
this.Controls.Add(chkSelectAllCategories);
// Güncellenmiş Form Yüksekliği
// Belirli bir maksimum boyut belirlemek yerine, sabit bir boyut tutturup kontrolleri buna göre yerleştirmek daha sağlıklı olur
// Ancak, formun yüksekliği ayarlanırken, en alt kontrollerin görünür olduğundan emin olun
// Eğer gerekirse toplam yükseklik hesaplanabilir. Ancak, mevcut düzenleme için aşağıdaki form yüksekliği yeterli olmalıdır
this.ClientSize = new Size(this.ClientSize.Width, currentTop + chkSelectAllCategories.Height + 20);
}
private void ChkSelectAllFields_CheckedChanged(object sender, EventArgs e)
{
for (int i = 0; i < clbFields.Items.Count; i++)
{
clbFields.SetItemChecked(i, chkSelectAllFields.Checked);
}
}
private void ChkSelectAllCategories_CheckedChanged(object sender, EventArgs e)
{
for (int i = 0; i < clbCategories.Items.Count; i++)
{
clbCategories.SetItemChecked(i, chkSelectAllCategories.Checked);
}
}
private void RdbExportOptions_CheckedChanged(object sender, EventArgs e)
{
if (rdbExportAll.Checked)
{
ExportAll = true;
}
else if (rdbExportByCategory.Checked)
{
ExportAll = false;
}
// Kategori seçimlerinin görünürlüğünü ayarla
bool isByCategory = rdbExportByCategory.Checked;
foreach (Control ctrl in this.Controls)
{
if (ctrl is Label lbl && lbl.Text == "Select categories to export:")
{
lbl.Visible = isByCategory;
break;
}
}
clbCategories.Visible = isByCategory;
chkSelectAllCategories.Visible = isByCategory;
}
private void BtnOK_Click(object sender, EventArgs e)
{
// Ensure at least one field is selected
if (clbFields.CheckedItems.Count == 0)
{
MessageBox.Show("Please select at least one field to export.", "No Fields Selected", MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.DialogResult = DialogResult.None; // Prevent the dialog from closing
return;
}
if (ExportByCategory)
{
// Ensure at least one category is selected
if (clbCategories.CheckedItems.Count == 0)
{
MessageBox.Show("Please select at least one category to export.", "No Categories Selected", MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.DialogResult = DialogResult.None; // Prevent the dialog from closing
return;
}
// Collect selected categories
SelectedCategories = clbCategories.CheckedItems.Cast<string>().ToList();
}
// Collect content format selection
KeepContentAsHtml = rdbKeepHtml.Checked;
this.DialogResult = DialogResult.OK;
this.Close();
}
/// <summary>
/// Retrieves the list of selected fields.
/// </summary>
public List<string> GetSelectedFields()
{
return clbFields.CheckedItems.Cast<string>().ToList();
}
/// <summary>
/// Retrieves the list of selected categories.
/// </summary>
public List<string> GetSelectedCategories()
{
return SelectedCategories;
}
/// <summary>
/// Selects all fields by checking all items.
/// </summary>
public void SelectAllFields()
{
chkSelectAllFields.Checked = true;
}
/// <summary>
/// Selects all categories by checking all items.
/// </summary>
public void SelectAllCategories()
{
chkSelectAllCategories.Checked = true;
}
}
partial class ExportSettingsForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
// Define controls
private System.Windows.Forms.Label lblSelectFields;
private System.Windows.Forms.CheckedListBox clbFields;
private System.Windows.Forms.CheckBox chkSelectAllFields;
private System.Windows.Forms.GroupBox grpExportOptions;
private System.Windows.Forms.RadioButton rdbExportAll;
private System.Windows.Forms.RadioButton rdbExportByCategory;
private System.Windows.Forms.GroupBox grpContentFormat;
private System.Windows.Forms.RadioButton rdbConvertToText;
private System.Windows.Forms.RadioButton rdbKeepHtml;
private System.Windows.Forms.Label lblSelectCategories;
private System.Windows.Forms.CheckedListBox clbCategories;
private System.Windows.Forms.CheckBox chkSelectAllCategories;
private System.Windows.Forms.Button btnOK;
private System.Windows.Forms.Button btnCancel;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.lblSelectFields = new System.Windows.Forms.Label();
this.clbFields = new System.Windows.Forms.CheckedListBox();
this.chkSelectAllFields = new System.Windows.Forms.CheckBox();
this.grpExportOptions = new System.Windows.Forms.GroupBox();
this.rdbExportAll = new System.Windows.Forms.RadioButton();
this.rdbExportByCategory = new System.Windows.Forms.RadioButton();
this.grpContentFormat = new System.Windows.Forms.GroupBox();
this.rdbConvertToText = new System.Windows.Forms.RadioButton();
this.rdbKeepHtml = new System.Windows.Forms.RadioButton();
this.lblSelectCategories = new System.Windows.Forms.Label();
this.clbCategories = new System.Windows.Forms.CheckedListBox();
this.chkSelectAllCategories = new System.Windows.Forms.CheckBox();
this.btnOK = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.grpExportOptions.SuspendLayout();
this.grpContentFormat.SuspendLayout();
this.SuspendLayout();
//
// lblSelectFields
//
this.lblSelectFields.AutoSize = true;
this.lblSelectFields.ForeColor = System.Drawing.Color.DarkSlateGray;
this.lblSelectFields.Location = new System.Drawing.Point(20, 20);
this.lblSelectFields.Name = "lblSelectFields";
this.lblSelectFields.Size = new System.Drawing.Size(146, 19);
this.lblSelectFields.TabIndex = 0;
this.lblSelectFields.Text = "Select fields to export:";
//
// clbFields
//
this.clbFields.FormattingEnabled = true;
this.clbFields.Items.AddRange(new object[] {
"id",
"category",
"title",
"content",
"favorite",
"pinned",
"backgroundColor",
"timestamp",
"updatedAt",
"hashtags"});
this.clbFields.Location = new System.Drawing.Point(20, 50);
this.clbFields.Name = "clbFields";
this.clbFields.Size = new System.Drawing.Size(460, 200);
this.clbFields.TabIndex = 1;
//
// chkSelectAllFields
//
this.chkSelectAllFields.AutoSize = true;
this.chkSelectAllFields.ForeColor = System.Drawing.Color.DarkSlateGray;
this.chkSelectAllFields.Location = new System.Drawing.Point(20, 260);
this.chkSelectAllFields.Name = "chkSelectAllFields";
this.chkSelectAllFields.Size = new System.Drawing.Size(150, 23);
this.chkSelectAllFields.TabIndex = 2;
this.chkSelectAllFields.Text = "Select All Fields";
this.chkSelectAllFields.UseVisualStyleBackColor = true;
this.chkSelectAllFields.CheckedChanged += new System.EventHandler(this.chkSelectAllFields_CheckedChanged);
//
// grpExportOptions
//
this.grpExportOptions.Controls.Add(this.rdbExportAll);
this.grpExportOptions.Controls.Add(this.rdbExportByCategory);
this.grpExportOptions.ForeColor = System.Drawing.Color.DarkSlateGray;
this.grpExportOptions.Location = new System.Drawing.Point(20, 300);
this.grpExportOptions.Name = "grpExportOptions";
this.grpExportOptions.Size = new System.Drawing.Size(460, 100);
this.grpExportOptions.TabIndex = 3;
this.grpExportOptions.TabStop = false;
this.grpExportOptions.Text = "Export Options";
//
// rdbExportAll
//
this.rdbExportAll.AutoSize = true;
this.rdbExportAll.Checked = true;
this.rdbExportAll.ForeColor = System.Drawing.Color.DarkSlateGray;
this.rdbExportAll.Location = new System.Drawing.Point(15, 40);
this.rdbExportAll.Name = "rdbExportAll";
this.rdbExportAll.Size = new System.Drawing.Size(143, 23);
this.rdbExportAll.TabIndex = 0;
this.rdbExportAll.TabStop = true;
this.rdbExportAll.Text = "All Flashcards";
this.rdbExportAll.UseVisualStyleBackColor = true;
this.rdbExportAll.CheckedChanged += new System.EventHandler(this.rdbExportOptions_CheckedChanged);
//
// rdbExportByCategory
//
this.rdbExportByCategory.AutoSize = true;
this.rdbExportByCategory.ForeColor = System.Drawing.Color.DarkSlateGray;
this.rdbExportByCategory.Location = new System.Drawing.Point(15, 70);
this.rdbExportByCategory.Name = "rdbExportByCategory";
this.rdbExportByCategory.Size = new System.Drawing.Size(174, 23);
this.rdbExportByCategory.TabIndex = 1;
this.rdbExportByCategory.Text = "Export by Category";
this.rdbExportByCategory.UseVisualStyleBackColor = true;
this.rdbExportByCategory.CheckedChanged += new System.EventHandler(this.rdbExportOptions_CheckedChanged);
//
// grpContentFormat
//
this.grpContentFormat.Controls.Add(this.rdbConvertToText);
this.grpContentFormat.Controls.Add(this.rdbKeepHtml);
this.grpContentFormat.ForeColor = System.Drawing.Color.DarkSlateGray;
this.grpContentFormat.Location = new System.Drawing.Point(20, 420);
this.grpContentFormat.Name = "grpContentFormat";
this.grpContentFormat.Size = new System.Drawing.Size(460, 100);
this.grpContentFormat.TabIndex = 4;
this.grpContentFormat.TabStop = false;
this.grpContentFormat.Text = "Content Format";
//
// rdbConvertToText
//
this.rdbConvertToText.AutoSize = true;
this.rdbConvertToText.Checked = true;
this.rdbConvertToText.ForeColor = System.Drawing.Color.DarkSlateGray;
this.rdbConvertToText.Location = new System.Drawing.Point(15, 40);
this.rdbConvertToText.Name = "rdbConvertToText";
this.rdbConvertToText.Size = new System.Drawing.Size(165, 23);
this.rdbConvertToText.TabIndex = 0;
this.rdbConvertToText.TabStop = true;
this.rdbConvertToText.Text = "Plain Text (Default)";
this.rdbConvertToText.UseVisualStyleBackColor = true;
//
// rdbKeepHtml
//
this.rdbKeepHtml.AutoSize = true;
this.rdbKeepHtml.ForeColor = System.Drawing.Color.DarkSlateGray;
this.rdbKeepHtml.Location = new System.Drawing.Point(15, 70);
this.rdbKeepHtml.Name = "rdbKeepHtml";
this.rdbKeepHtml.Size = new System.Drawing.Size(123, 23);
this.rdbKeepHtml.TabIndex = 1;
this.rdbKeepHtml.Text = "Keep as HTML";
this.rdbKeepHtml.UseVisualStyleBackColor = true;
//
// lblSelectCategories
//
this.lblSelectCategories.AutoSize = true;
this.lblSelectCategories.ForeColor = System.Drawing.Color.DarkSlateGray;
this.lblSelectCategories.Location = new System.Drawing.Point(20, 540);
this.lblSelectCategories.Name = "lblSelectCategories";
this.lblSelectCategories.Size = new System.Drawing.Size(189, 19);
this.lblSelectCategories.TabIndex = 5;
this.lblSelectCategories.Text = "Select categories to export:";
this.lblSelectCategories.Visible = false;
//
// clbCategories
//
this.clbCategories.FormattingEnabled = true;
this.clbCategories.Location = new System.Drawing.Point(20, 570);
this.clbCategories.Name = "clbCategories";
this.clbCategories.Size = new System.Drawing.Size(460, 150);
this.clbCategories.TabIndex = 6;
this.clbCategories.Visible = false;
//
// chkSelectAllCategories
//
this.chkSelectAllCategories.AutoSize = true;
this.chkSelectAllCategories.ForeColor = System.Drawing.Color.DarkSlateGray;
this.chkSelectAllCategories.Location = new System.Drawing.Point(20, 730);
this.chkSelectAllCategories.Name = "chkSelectAllCategories";
this.chkSelectAllCategories.Size = new System.Drawing.Size(201, 23);
this.chkSelectAllCategories.TabIndex = 7;
this.chkSelectAllCategories.Text = "Select All Categories";
this.chkSelectAllCategories.UseVisualStyleBackColor = true;
this.chkSelectAllCategories.Visible = false;
this.chkSelectAllCategories.CheckedChanged += new System.EventHandler(this.chkSelectAllCategories_CheckedChanged);
//
// btnOK
//
this.btnOK.BackColor = System.Drawing.Color.LightSlateGray;
this.btnOK.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnOK.ForeColor = System.Drawing.Color.White;
this.btnOK.Location = new System.Drawing.Point(120, 780);
this.btnOK.Name = "btnOK";
this.btnOK.Size = new System.Drawing.Size(100, 35);
this.btnOK.TabIndex = 8;
this.btnOK.Text = "OK";
this.btnOK.UseVisualStyleBackColor = false;
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
//
// btnCancel
//
this.btnCancel.BackColor = System.Drawing.Color.LightSlateGray;
this.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnCancel.ForeColor = System.Drawing.Color.White;
this.btnCancel.Location = new System.Drawing.Point(260, 780);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(100, 35);
this.btnCancel.TabIndex = 9;
this.btnCancel.Text = "Cancel";
this.btnCancel.UseVisualStyleBackColor = false;
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// ExportSettingsForm
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(500, 840);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnOK);
this.Controls.Add(this.chkSelectAllCategories);
this.Controls.Add(this.clbCategories);
this.Controls.Add(this.lblSelectCategories);
this.Controls.Add(this.grpContentFormat);
this.Controls.Add(this.grpExportOptions);
this.Controls.Add(this.chkSelectAllFields);
this.Controls.Add(this.clbFields);
this.Controls.Add(this.lblSelectFields);
this.Font = new System.Drawing.Font("Segoe UI", 10F);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "ExportSettingsForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Export Options";
this.grpExportOptions.ResumeLayout(false);
this.grpExportOptions.PerformLayout();
this.grpContentFormat.ResumeLayout(false);
this.grpContentFormat.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
}