Example #1
0
 public void ChangeDisk(string diskName, int fieldIndex, MainForm mainForm)
 {
     if (fieldIndex == 1)
         Field1.ChangeDisk(diskName);
     else
         Field2.ChangeDisk(diskName);
     RefreshAll(mainForm);
 }
Example #2
0
 public FileManager(ListView field1View, ListView field2View, TextBox field1Path, TextBox field2Path,
     ToolStrip disksView1, ToolStrip disksView2, Timer refresher, MainForm mainForm)
 {
     UpdateDisks();
     Field1 = new Field(field1View, field1Path, disksView1, Disks);
     Field2 = new Field(field2View, field2Path, disksView2, Disks);
     RefreshAll(mainForm);
     CurrentField = Field1;
     refresher.Enabled = true;
 }
Example #3
0
 public void ReplaceSelected(MainForm mainForm)
 {
     CurrentField.ReplaceSelected(CurrentField == Field1 ? Field2.OpenedElement.Path : Field1.OpenedElement.Path);
     RefreshAll(mainForm);
 }
Example #4
0
 public void RenameSelected(string newName, MainForm mainForm)
 {
     CurrentField.RenameSelected(newName);
     RefreshAll(mainForm);
 }
Example #5
0
 public void RemoveSelected(MainForm mainForm)
 {
     CurrentField.RemoveSelected();
     RefreshAll(mainForm);
 }
Example #6
0
 public void RefreshAll(MainForm mainForm)
 {
     UpdateDisks();
     mainForm.UpdateDisksView(Field1, Disks);
     mainForm.UpdateDisksView(Field2, Disks);
     if (!Field1.UpdateField(Field1.OpenedElement))
         Field1.SetDisk(Disks);
     if (!Field2.UpdateField(Field2.OpenedElement))
         Field2.SetDisk(Disks);
     mainForm.UpdateFieldView(Field1);
     mainForm.UpdateFieldView(Field2);
 }
Example #7
0
 public void PasteFromClipboard(MainForm mainForm)
 {
     if (!Clipboard.ContainsFileDropList())
         return;
     IDataObject data = Clipboard.GetDataObject();
     string[] files = data.GetData(DataFormats.FileDrop) as string[];
     MemoryStream stream = data.GetData("Preferred DropEffect", true) as MemoryStream;
     if (stream == null)
         return;
     int flag = stream.ReadByte();
     if (flag != 2 && flag != 5)
         return;
     bool cut = (flag == 2);
     if (files != null)
     {
         if (cut)
             CurrentField.ReplaceClipboard(files, CurrentField.OpenedElement.Path);
         else
             CurrentField.CopyClipboard(files, CurrentField.OpenedElement.Path);
     }
     RefreshAll(mainForm);
 }
Example #8
0
 /*
  * Відкрити елемент з індексом itemIndex у списку FieldElementList
  */
 public void OpenElement(MainForm mainForm)
 {
     if (CurrentField.FieldView.SelectedItems.Count == 0)
         return;
     int itemIndex = CurrentField.FieldView.Items.IndexOf(CurrentField.FieldView.SelectedItems[0]);
     bool needToUpdateFieldView = CurrentField.OpenElement(itemIndex);
     if (needToUpdateFieldView)
         mainForm.UpdateFieldView(CurrentField);
 }
Example #9
0
 public void MargeSelectedHTMLFiles(MainForm mainForm)
 {
     if (CurrentField.FieldView.SelectedItems.Count != 2)
         return;
     int firstFileIndex = CurrentField.FieldView.Items.IndexOf(CurrentField.FieldView.SelectedItems[0]);
     int secondFileIndex = CurrentField.FieldView.Items.IndexOf(CurrentField.FieldView.SelectedItems[1]);
     var firstFile = new FileInfo(CurrentField.FieldElementList[firstFileIndex].Path);
     var secondFile = new FileInfo(CurrentField.FieldElementList[secondFileIndex].Path);
     if (!firstFile.Exists || !secondFile.Exists ||
         (!String.Equals(firstFile.Extension, ".htm") && !String.Equals(firstFile.Extension, ".html")) ||
         (!String.Equals(secondFile.Extension, ".htm") && !String.Equals(secondFile.Extension, ".html")))
         return;
     StreamReader firstFileStream = new StreamReader(firstFile.FullName, Encoding.Default);
     StreamReader secondFileStream = new StreamReader(secondFile.FullName, Encoding.Default);
     string outputFile = firstFile.DirectoryName + @"\" + Path.GetFileNameWithoutExtension(firstFile.Name) +
                         Path.GetFileNameWithoutExtension(secondFile.Name);
     while (System.IO.File.Exists(outputFile + @".html"))
         outputFile += @"1";
     outputFile += @".html";
     StreamWriter outputFileStream = new StreamWriter(outputFile, false, Encoding.Default);
     StringBuilder style = new StringBuilder();
     int isGetStyle = 0;
     string buffer = null;
     while ((buffer = firstFileStream.ReadLine()) != null)
     {
         outputFileStream.WriteLine(buffer);
         if (isGetStyle == 0)
         {
             int startIndex = buffer.IndexOf(@"<style"), finishIndex = buffer.IndexOf(@"</style");
             if (startIndex != -1 && finishIndex != -1)
             {
                 style.Append(buffer.Substring(startIndex, finishIndex - startIndex + 1));
                 isGetStyle = 2;
             }
             else if (startIndex != -1)
             {
                 style.AppendLine(buffer.Substring(startIndex));
                 isGetStyle = 1;
             }
         }
         else if (isGetStyle == 1)
         {
             int finishIndex = buffer.IndexOf(@"</style>");
             if (finishIndex != -1)
             {
                 style.Append(buffer.Substring(0, finishIndex));
                 isGetStyle = 2;
             }
             else
                 style.AppendLine(buffer);
         }
     }
     buffer = null;
     isGetStyle = 0;
     while ((buffer = secondFileStream.ReadLine()) != null)
     {
         if (isGetStyle == 0)
         {
             int startIndex = buffer.IndexOf(@"<style"), finishIndex = buffer.IndexOf(@"</style");
             if (startIndex != -1 && finishIndex != -1)
             {
                 outputFileStream.WriteLine(buffer.Substring(0, startIndex) + style + buffer.Substring(finishIndex));
                 isGetStyle = 2;
             }
             else if (startIndex != -1)
             {
                 outputFileStream.Write(buffer.Substring(0, startIndex) + style);
                 isGetStyle = 1;
             }
             else
                 outputFileStream.WriteLine(buffer);
         }
         else if (isGetStyle == 1)
         {
             int finishIndex = buffer.IndexOf(@"</style>");
             if (finishIndex != -1)
             {
                 outputFileStream.WriteLine(buffer.Substring(finishIndex));
                 isGetStyle = 2;
             }
         }
         else
             outputFileStream.WriteLine(buffer);
     }
     firstFileStream.Close();
     secondFileStream.Close();
     outputFileStream.Close();
 }
Example #10
0
 /*
  * Значення fieldNum = 1, якщо змінюється шлях першого поля,
  * значення fieldNum = 2, якщо змінюється шлях другого поля,
  */
 public void GoPath(string path, int fieldNum, MainForm mainForm)
 {
     switch (fieldNum)
     {
         case 1:
             Field1.GoPath(path);
             break;
         case 2:
             Field2.GoPath(path);
             break;
     }
     RefreshAll(mainForm);
 }
Example #11
0
 public void GoForward(MainForm mainForm)
 {
     if(CurrentField.GoForward())
         RefreshAll(mainForm);
 }
Example #12
0
 public void GoBack(MainForm mainForm)
 {
     if (CurrentField.GoBack())
         RefreshAll(mainForm);
 }
Example #13
0
 /*
  * Створити нову папку чи дерево папок.
  * У разі існування папки чи неможливості створення виводяться відповідні повідомлення.
  */
 public void CreateFolder(MainForm mainForm)
 {
     CreateFileFolderForm createFolderForm = new CreateFileFolderForm(0);
     createFolderForm.ShowDialog(mainForm);
     string name = createFolderForm.GetFileFolderName();
     if (name == null)
         return;
     string path = CurrentField.OpenedElement.Path + @"\" + name;
     if (Directory.Exists(path))
     {
         MessageView.FolderExistError();
         return;
     }
     try
     {
         Directory.CreateDirectory(path);
     }
     catch
     {
         MessageView.FolderCreateError();
     }
     RefreshAll(mainForm);
 }
Example #14
0
 /*
  * Створити новий пустий файл.
  * У разі існування файлу чи неможливості створення виводяться відповідні повідомлення.
  */
 public void CreateEmptyFile(MainForm mainForm)
 {
     CreateFileFolderForm createFolderForm = new CreateFileFolderForm(1);
     createFolderForm.ShowDialog(mainForm);
     string name = createFolderForm.GetFileFolderName();
     if (name == null)
         return;
     string Path = CurrentField.OpenedElement.Path + @"\" + name;
     if (System.IO.File.Exists(Path))
     {
         MessageView.FileExistError();
         return;
     }
     try
     {
         var newFile = new StreamWriter(Path);
         newFile.Close();
     }
     catch
     {
         MessageView.FileCreateError();
         return;
     }
     RefreshAll(mainForm);
 }
Example #15
0
 public void CopySelected(MainForm mainForm)
 {
     if(CurrentField == Field1)
         CurrentField.CopySelected(Field2.OpenedElement.Path);
     else
         CurrentField.CopySelected(Field1.OpenedElement.Path);
     RefreshAll(mainForm);
 }