Example #1
0
        protected override void internal_command_proc()
        {
            var e = new QueryPanelInfoEventArgs();

            OnQueryCurrentPanel(e);

            if (e.FocusedIndex == -1)
            {
                return;
            }

            var group_mode  = false;
            var sel_indices = e.SelectedIndices;

            //we not need cache selection
            //becouse e.ItemsCollection must not change (DirectoryList not sort on attributes)
            group_mode = (sel_indices.Length > 1);
            var dl     = (DirectoryList)e.ItemCollection;
            var f_data = new WIN32_FIND_DATA();

            var target_file = string.Empty;

            if (!group_mode)
            {
                if (sel_indices.Length == 0)
                {
                    target_file = Path.Combine(dl.DirectoryPath, dl.GetItemDisplayNameLong(e.FocusedIndex));
                }
                else
                {
                    target_file = Path.Combine(dl.DirectoryPath, dl.GetItemDisplayNameLong(sel_indices[0]));
                }
                if (target_file.EndsWith(".."))
                {
                    target_file = dl.DirectoryPath;
                }
                if (!WinAPiFSwrapper.GetFileInfo(target_file, ref f_data))
                {
                    return;
                }
            }



            var dialog = new FileAttributesEditDialog();

            if (!group_mode)
            {
                dialog.buttonClear.Enabled = false;
                set_attributes_to_dialog(dialog, f_data.dwFileAttributes);
                dialog.Text = String.Format
                                  (Options.GetLiteral(Options.LANG_FILE_ATTRIBUTES) + " [{0}]", target_file);
            }
            else
            {
                dialog.buttonClear.Enabled = true;
                dialog.buttonOK.Text       = Options.GetLiteral(Options.LANG_ADD);
                dialog.Text = string.Format
                                  (Options.GetLiteral(Options.LANG_FILE_ATTRIBUTES) + " [{0} " + Options.GetLiteral(Options.LANG_ENTRIES) + "]", sel_indices.Length);
            }
            set_readonly_attributes(dialog);

            var d_res = dialog.ShowDialog();

            switch (d_res)
            {
            case DialogResult.OK:
                //group mode = add attributes
                //single mode = set attributes
                if (!group_mode)
                {
                    try
                    {
                        set_attributes_file(target_file, get_attributes_from_dialog(dialog));
                    }
                    catch (Exception ex)
                    {
                        Messages.ShowException(ex);
                    }
                }
                else
                {
                    //group mode
                    var add_fa = get_attributes_from_dialog(dialog);
                    foreach (var one_index in sel_indices)
                    {
                        target_file = Path.Combine(dl.DirectoryPath, dl.GetItemDisplayNameLong(one_index));
                        try
                        {
                            add_attributes_file(target_file, add_fa);
                            OnItemProcessDone(new ItemEventArs(one_index));
                        }
                        catch (Exception ex)
                        {
                            Messages.ShowException(ex);
                        }
                    }
                }
                break;

            case DialogResult.Yes:
                //group mode only = clear attributes
                var clear_fa = get_attributes_from_dialog(dialog);
                foreach (var one_index in sel_indices)
                {
                    target_file = Path.Combine(dl.DirectoryPath, dl.GetItemDisplayNameLong(one_index));
                    try
                    {
                        clear_attributes_file(target_file, clear_fa);
                        OnItemProcessDone(new ItemEventArs(one_index));
                    }
                    catch (Exception ex)
                    {
                        Messages.ShowException(ex);
                    }
                }
                break;
            }
        }