Subversion Repositories spk

Rev

Rev 197 | Blame | Compare with Previous | Last modification | View Log | RSS feed

#pragma once

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

#include <spk.h>

#define CLOSESIZE       120
#define OPENSIZE        300

namespace SpkExplorer {

        /// <summary>
        /// Summary for DropFileDialog
        ///
        /// WARNING: If you change the name of this class, you will need to change the
        ///          'Resource File Name' property for the managed resource compiler tool
        ///          associated with all .resx files this class depends on.  Otherwise,
        ///          the designers will not be able to interact properly with localized
        ///          resources associated with this form.
        /// </summary>
        public ref class DropFileDialog : public System::Windows::Forms::Form
        {
        public:
                DropFileDialog(Utils::WStringList *files)
                {
                        InitializeComponent();

                        this->AddFileTypes();

                        m_bOpen = false;
                        m_lFiles = files;
                        m_iOriginalSize = CLOSESIZE;
                        this->Height = CLOSESIZE;

                        this->UpdateFiles();
                        this->UpdateDisplay();
                }

        protected:
                /// <summary>
                /// Clean up any resources being used.
                /// </summary>
                ~DropFileDialog()
                {
                        if (components)
                        {
                                delete components;
                        }
                }
        private: System::Windows::Forms::Label^  label1;
        private: System::Windows::Forms::ComboBox^  ComboType;
        private: System::Windows::Forms::Label^  LabUnsure;
        protected: 


        private: System::Windows::Forms::ComboBox^  ComboUnsure;
        private: System::Windows::Forms::Button^  button1;
        private: System::Windows::Forms::Button^  button2;
        private: System::Windows::Forms::Button^  button3;


        private:
                int                     m_iOriginalSize;
        private: System::Windows::Forms::GroupBox^  groupBox1;
        private: System::Windows::Forms::ListView^  listView1;
        private: System::Windows::Forms::ColumnHeader^  ColumnFile;
        private: System::Windows::Forms::ColumnHeader^  ColumnType;
                         bool                    m_bOpen;
        private: System::Windows::Forms::Panel^  panel1;
                         Utils::WStringList     *m_lFiles;

                void AddFileTypes()
                {
                        this->ComboType->Items->Add("- Automatic -");
                        this->ComboUnsure->Items->Add("- Dont Add -");
                        for ( int i = 0; i < FILETYPE_MAX; i++ )
                        {
                                this->ComboType->Items->Add(_US(GetFileTypeString(i)));
                                this->ComboUnsure->Items->Add(_US(GetFileTypeString(i)));
                        }

                        this->ComboType->SelectedIndex = 0;
                        this->ComboUnsure->SelectedIndex = FILETYPE_EXTRA + 1;
                }

                void UpdateFiles()
                {
                        this->listView1->Items->Clear();
                        for(auto itr = m_lFiles->begin(); itr != m_lFiles->end(); itr++)
                        {
                                ListViewItem ^item = gcnew ListViewItem(_US((*itr)->str));
                                int type = (*itr)->data.token(L" ", 1).toInt();
                                if ( type == -1 )
                                        item->SubItems->Add("Unsure");
                                else
                                        item->SubItems->Add(_US(GetFileTypeString(type)));
                                this->listView1->Items->Add(item);
                                item->Checked = true;
                        }
                        this->listView1->AutoResizeColumns(ColumnHeaderAutoResizeStyle::HeaderSize);
                }

                void UpdateDisplay()
                {
                         if ( !m_bOpen )
                         {
                                 this->button1->Text = "Details >>>";
                                 this->groupBox1->Hide();
                                 this->Height = CLOSESIZE;
                         }
                         else
                         {
                                 this->button1->Text = "Details <<<";
                                 this->groupBox1->Show();
                                 this->Height = OPENSIZE;
                         }
                }

                void RemoveUncheckedFiles()
                {
                        for ( int i = 0; i < this->listView1->Items->Count; i++ )
                        {
                                ListViewItem ^item = this->listView1->Items[i];
                                if ( !item->Checked )
                                        m_lFiles->remove(_WS(item->Text), false);
                        }
                }

                void ApplyTypes()
                {
                        if ( this->ComboType->SelectedIndex == 0 )
                        {
                                auto itr = m_lFiles->begin();
                                while (itr != m_lFiles->end())
                                {
                                        int type = (*itr)->data.token(L" ", 1).toInt();
                                        if (type == -1) // unsure
                                        {
                                                if (this->ComboUnsure->SelectedIndex == 0)
                                                {
                                                        itr = m_lFiles->remove(itr);
                                                        continue;
                                                }
                                                else
                                                        (*itr)->data = Utils::WString::Number(this->ComboUnsure->SelectedIndex - 1);
                                        }

                                        itr++;

                                }
                        }
                        else
                        {
                                for(auto itr = m_lFiles->begin(); itr != m_lFiles->end(); itr++)
                                        (*itr)->data = Utils::WString::Number(this->ComboType->SelectedIndex - 1);
                        }
                }

                /// <summary>
                /// Required designer variable.
                /// </summary>
                System::ComponentModel::Container ^components;

#pragma 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>
                void InitializeComponent(void)
                {
                        this->label1 = (gcnew System::Windows::Forms::Label());
                        this->ComboType = (gcnew System::Windows::Forms::ComboBox());
                        this->LabUnsure = (gcnew System::Windows::Forms::Label());
                        this->ComboUnsure = (gcnew System::Windows::Forms::ComboBox());
                        this->button1 = (gcnew System::Windows::Forms::Button());
                        this->button2 = (gcnew System::Windows::Forms::Button());
                        this->button3 = (gcnew System::Windows::Forms::Button());
                        this->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
                        this->listView1 = (gcnew System::Windows::Forms::ListView());
                        this->ColumnFile = (gcnew System::Windows::Forms::ColumnHeader());
                        this->ColumnType = (gcnew System::Windows::Forms::ColumnHeader());
                        this->panel1 = (gcnew System::Windows::Forms::Panel());
                        this->groupBox1->SuspendLayout();
                        this->panel1->SuspendLayout();
                        this->SuspendLayout();
                        // 
                        // label1
                        // 
                        this->label1->AutoSize = true;
                        this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 9.75F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
                                static_cast<System::Byte>(0)));
                        this->label1->Location = System::Drawing::Point(12, 4);
                        this->label1->Name = L"label1";
                        this->label1->Size = System::Drawing::Size(78, 16);
                        this->label1->TabIndex = 0;
                        this->label1->Text = L"File Type:";
                        // 
                        // ComboType
                        // 
                        this->ComboType->DropDownStyle = System::Windows::Forms::ComboBoxStyle::DropDownList;
                        this->ComboType->FormattingEnabled = true;
                        this->ComboType->Location = System::Drawing::Point(123, 3);
                        this->ComboType->MaxDropDownItems = 20;
                        this->ComboType->Name = L"ComboType";
                        this->ComboType->Size = System::Drawing::Size(371, 21);
                        this->ComboType->TabIndex = 1;
                        this->ComboType->SelectedIndexChanged += gcnew System::EventHandler(this, &DropFileDialog::ComboType_SelectedIndexChanged);
                        // 
                        // LabUnsure
                        // 
                        this->LabUnsure->AutoSize = true;
                        this->LabUnsure->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 9.75F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
                                static_cast<System::Byte>(0)));
                        this->LabUnsure->Location = System::Drawing::Point(12, 31);
                        this->LabUnsure->Name = L"LabUnsure";
                        this->LabUnsure->Size = System::Drawing::Size(103, 16);
                        this->LabUnsure->TabIndex = 2;
                        this->LabUnsure->Text = L"If unsure, use:";
                        // 
                        // ComboUnsure
                        // 
                        this->ComboUnsure->DropDownStyle = System::Windows::Forms::ComboBoxStyle::DropDownList;
                        this->ComboUnsure->FormattingEnabled = true;
                        this->ComboUnsure->Location = System::Drawing::Point(123, 28);
                        this->ComboUnsure->MaxDropDownItems = 20;
                        this->ComboUnsure->Name = L"ComboUnsure";
                        this->ComboUnsure->Size = System::Drawing::Size(371, 21);
                        this->ComboUnsure->TabIndex = 3;
                        // 
                        // button1
                        // 
                        this->button1->Location = System::Drawing::Point(12, 59);
                        this->button1->Name = L"button1";
                        this->button1->Size = System::Drawing::Size(103, 23);
                        this->button1->TabIndex = 4;
                        this->button1->Text = L"Details >>>";
                        this->button1->UseVisualStyleBackColor = true;
                        this->button1->Click += gcnew System::EventHandler(this, &DropFileDialog::button1_Click);
                        // 
                        // button2
                        // 
                        this->button2->DialogResult = System::Windows::Forms::DialogResult::OK;
                        this->button2->Location = System::Drawing::Point(405, 59);
                        this->button2->Name = L"button2";
                        this->button2->Size = System::Drawing::Size(89, 23);
                        this->button2->TabIndex = 5;
                        this->button2->Text = L"Add File(s)";
                        this->button2->UseVisualStyleBackColor = true;
                        // 
                        // button3
                        // 
                        this->button3->DialogResult = System::Windows::Forms::DialogResult::Cancel;
                        this->button3->Location = System::Drawing::Point(324, 59);
                        this->button3->Name = L"button3";
                        this->button3->Size = System::Drawing::Size(75, 23);
                        this->button3->TabIndex = 6;
                        this->button3->Text = L"Cancel";
                        this->button3->UseVisualStyleBackColor = true;
                        // 
                        // groupBox1
                        // 
                        this->groupBox1->AutoSizeMode = System::Windows::Forms::AutoSizeMode::GrowAndShrink;
                        this->groupBox1->Controls->Add(this->listView1);
                        this->groupBox1->Dock = System::Windows::Forms::DockStyle::Fill;
                        this->groupBox1->Location = System::Drawing::Point(0, 90);
                        this->groupBox1->Name = L"groupBox1";
                        this->groupBox1->Size = System::Drawing::Size(506, 150);
                        this->groupBox1->TabIndex = 7;
                        this->groupBox1->TabStop = false;
                        this->groupBox1->Text = L"Files";
                        // 
                        // listView1
                        // 
                        this->listView1->CheckBoxes = true;
                        this->listView1->Columns->AddRange(gcnew cli::array< System::Windows::Forms::ColumnHeader^  >(2) {this->ColumnFile, this->ColumnType});
                        this->listView1->Dock = System::Windows::Forms::DockStyle::Fill;
                        this->listView1->FullRowSelect = true;
                        this->listView1->Location = System::Drawing::Point(3, 16);
                        this->listView1->Name = L"listView1";
                        this->listView1->Size = System::Drawing::Size(500, 131);
                        this->listView1->TabIndex = 0;
                        this->listView1->UseCompatibleStateImageBehavior = false;
                        this->listView1->View = System::Windows::Forms::View::Details;
                        // 
                        // ColumnFile
                        // 
                        this->ColumnFile->Text = L"File";
                        // 
                        // ColumnType
                        // 
                        this->ColumnType->Text = L"Type";
                        // 
                        // panel1
                        // 
                        this->panel1->Controls->Add(this->button3);
                        this->panel1->Controls->Add(this->button2);
                        this->panel1->Controls->Add(this->button1);
                        this->panel1->Controls->Add(this->ComboUnsure);
                        this->panel1->Controls->Add(this->LabUnsure);
                        this->panel1->Controls->Add(this->ComboType);
                        this->panel1->Controls->Add(this->label1);
                        this->panel1->Dock = System::Windows::Forms::DockStyle::Top;
                        this->panel1->Location = System::Drawing::Point(0, 0);
                        this->panel1->Name = L"panel1";
                        this->panel1->Size = System::Drawing::Size(506, 90);
                        this->panel1->TabIndex = 8;
                        // 
                        // DropFileDialog
                        // 
                        this->AcceptButton = this->button2;
                        this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
                        this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
                        this->CancelButton = this->button3;
                        this->ClientSize = System::Drawing::Size(506, 240);
                        this->ControlBox = false;
                        this->Controls->Add(this->groupBox1);
                        this->Controls->Add(this->panel1);
                        this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedDialog;
                        this->Name = L"DropFileDialog";
                        this->ShowIcon = false;
                        this->ShowInTaskbar = false;
                        this->SizeGripStyle = System::Windows::Forms::SizeGripStyle::Hide;
                        this->StartPosition = System::Windows::Forms::FormStartPosition::CenterParent;
                        this->Text = L"Add Dropped Files";
                        this->FormClosing += gcnew System::Windows::Forms::FormClosingEventHandler(this, &DropFileDialog::DropFileDialog_FormClosing);
                        this->groupBox1->ResumeLayout(false);
                        this->panel1->ResumeLayout(false);
                        this->panel1->PerformLayout();
                        this->ResumeLayout(false);

                }
#pragma endregion
        private: System::Void ComboType_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {
                                 if ( this->ComboType->SelectedIndex == 0 )
                                         this->ComboUnsure->Enabled = true;
                                 else
                                         this->ComboUnsure->Enabled = false;
                         }
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
                         m_bOpen = !m_bOpen;
                         this->UpdateDisplay();
                 }
private: System::Void DropFileDialog_FormClosing(System::Object^  sender, System::Windows::Forms::FormClosingEventArgs^  e) {
                         this->RemoveUncheckedFiles();
                         this->ApplyTypes();
                 }
};
}