Source

KPDataSave / KPDataSave / Forms / States / SelectFolder.cs

Full commit
HexRx ec9fdfc 

















































































/*
    KPDataSave - KeePass plugin which saves database in Dropbox service
    Copyright (C) 2011-2012 HexRx

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using DropboxAPI.Models;
using KPDataSave.Controls;

namespace KPDataSave.Forms.States
{
    public class SelectFolder : AbstractForm
    {
        private readonly StateControl _stateControl;
        private readonly TreeViewFiles _tvwFiles;

        public SelectFolder(StateControl stateControl)
        {
            _stateControl = stateControl;
            // Устанавливаем заголовок окна
            base.Text = "Select save folder. Step 3/3";
            // Событие отображения формы
            Shown += (sender, args) => _tvwFiles.ShowRootFiles();
            // Скрываем разметку для кнопок
            tableLayout.Hide();

            // Кнопка подтверждения
            Button btnApply = new Button();
            btnApply.Location = new System.Drawing.Point(197, 79);
            btnApply.Size = new System.Drawing.Size(75, 23);
            btnApply.TabIndex = 1;
            btnApply.Text = "Apply";
            btnApply.UseVisualStyleBackColor = true;
            btnApply.Click += new System.EventHandler(BtnApplyClick);
            Controls.Add(btnApply);

            // Список изображений для дерева
            ImageList imlFileType = new ImageList();
            imlFileType.TransparentColor = System.Drawing.Color.Transparent;
            imlFileType.ColorDepth = ColorDepth.Depth32Bit;
            imlFileType.Images.Add(Properties.Resources.folder_16x16);

            // Дерево файлов
            _tvwFiles = new TreeViewFiles(_stateControl.DropboxClient);
            _tvwFiles.ImageIndex = 0;
            _tvwFiles.SelectedImageIndex = 0;
            _tvwFiles.ImageList = imlFileType;
            _tvwFiles.Location = new System.Drawing.Point(12, 79);
            _tvwFiles.Size = new System.Drawing.Size(179, 173);
            _tvwFiles.TabIndex = 0;

            Controls.Add(_tvwFiles);
        }

        // Кнопка сохранения изменений
        private void BtnApplyClick(object sender, EventArgs e)
        {
            AccessToken token = _stateControl.DropboxClient.AccessToken;
            AccountState accountState = new AccountState { Path = _tvwFiles.SelectedPath, Secret = token.TokenSecret, Token = token.Token};
            // Сохраняем конфигурацию
            accountState.Serialize(_stateControl.PluginHost);
            MessageBox.Show("Configuration complete!", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
            // Закрываем окно
            Close();
        }
    }
}