Browse Source

Bug 1634: Edit found found files

https://winscp.net/tracker/1634

Source commit: 48f9baae7215366f1aafa2bf584aaac354565abc
Martin Prikryl 7 years ago
parent
commit
4b329f722a

+ 31 - 13
source/forms/CustomScpExplorer.cpp

@@ -8982,23 +8982,24 @@ void __fastcall TCustomScpExplorerForm::DoFocusRemotePath(TTerminal * ATerminal,
   }
 }
 //---------------------------------------------------------------------------
+bool __fastcall TCustomScpExplorerForm::CanOperateOnFoundFiles(TTerminal * ATerminal)
+{
+  bool Result = !NonVisualDataModule->Busy;
+  if (Result)
+  {
+    TTerminalManager::Instance()->ActiveTerminal = ATerminal;
+  }
+  return Result;
+}
+//---------------------------------------------------------------------------
 void __fastcall TCustomScpExplorerForm::DoOperationOnFoundFiles(
   TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
 {
-  if (!NonVisualDataModule->Busy)
+  if (CanOperateOnFoundFiles(ATerminal))
   {
-    TTerminalManager::Instance()->ActiveTerminal = ATerminal;
-
-    DebugAssert(FOnFileOperationFinished == NULL);
+    TValueRestorer<TFileOperationFinishedEvent> OnFileOperationFinishedRestorer(FOnFileOperationFinished);
     FOnFileOperationFinished = OnFileOperationFinished;
-    try
-    {
-      ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
-    }
-    __finally
-    {
-      FOnFileOperationFinished = NULL;
-    }
+    ExecuteFileOperation(Operation, osRemote, FileList, false, NULL);
   }
 }
 //---------------------------------------------------------------------------
@@ -9014,10 +9015,27 @@ void __fastcall TCustomScpExplorerForm::DoDownloadFoundFiles(
   DoOperationOnFoundFiles(foCopy, ATerminal, FileList, OnFileOperationFinished);
 }
 //---------------------------------------------------------------------------
+void __fastcall TCustomScpExplorerForm::DoEditFoundFiles(
+  TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished)
+{
+  if (CanOperateOnFoundFiles(ATerminal))
+  {
+    for (int Index = 0; Index < FileList->Count; Index++)
+    {
+      UnicodeString FileName = FileList->Strings[Index];
+      TRemoteFile * File = static_cast<TRemoteFile *>(FileList->Objects[Index]);
+      ExecuteRemoteFile(FileName, File, efDefaultEditor);
+      OnFileOperationFinished(FileName, true);
+    }
+  }
+}
+//---------------------------------------------------------------------------
 void __fastcall TCustomScpExplorerForm::RemoteFindFiles()
 {
   FFileFindTerminal = Terminal;
-  ShowFileFindDialog(Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles, DoDownloadFoundFiles);
+  ShowFileFindDialog(
+    Terminal, RemoteDirView->Path, DoFindFiles, DoFocusRemotePath, DoDeleteFoundFiles,
+    DoDownloadFoundFiles, DoEditFoundFiles);
 }
 //---------------------------------------------------------------------------
 void __fastcall TCustomScpExplorerForm::UpdateTaskbarList(ITaskbarList3 * TaskbarList)

+ 2 - 0
source/forms/CustomScpExplorer.h

@@ -539,10 +539,12 @@ protected:
   void __fastcall DoFindFiles(TTerminal * Terminal, UnicodeString Directory, const TFileMasks & FileMask,
     TFileFoundEvent OnFileFound, TFindingFileEvent OnFindingFile);
   virtual void __fastcall DoFocusRemotePath(TTerminal * Terminal, const UnicodeString & Path);
+  bool __fastcall CanOperateOnFoundFiles(TTerminal * ATerminal);
   void __fastcall DoOperationOnFoundFiles(
     TFileOperation Operation, TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished);
   void __fastcall DoDeleteFoundFiles(TTerminal * Terminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished);
   void __fastcall DoDownloadFoundFiles(TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished);
+  void __fastcall DoEditFoundFiles(TTerminal * ATerminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished);
   bool __fastcall ExecuteFileOperation(TFileOperation Operation, TOperationSide Side,
     bool OnFocused, bool NoConfirmation = false, void * Param = NULL);
   void __fastcall UpdateCopyParamCounters(const TCopyParamType & CopyParam);

+ 10 - 3
source/forms/FileFind.cpp

@@ -26,13 +26,13 @@ TFileFindDialog * FileFindDialog = NULL;
 //---------------------------------------------------------------------------
 void __fastcall ShowFileFindDialog(
   TTerminal * Terminal, UnicodeString Directory, TFindEvent OnFind, TFocusFileEvent OnFocusFile,
-  TFileListOperationEvent OnDeleteFiles, TFileListOperationEvent OnDownloadFiles)
+  TFileListOperationEvent OnDeleteFiles, TFileListOperationEvent OnDownloadFiles, TFileListOperationEvent OnEditFiles)
 {
   if (FileFindDialog == NULL)
   {
     FileFindDialog = new TFileFindDialog(Application);
   }
-  FileFindDialog->Init(Terminal, Directory, OnFind, OnFocusFile, OnDeleteFiles, OnDownloadFiles);
+  FileFindDialog->Init(Terminal, Directory, OnFind, OnFocusFile, OnDeleteFiles, OnDownloadFiles, OnEditFiles);
   FileFindDialog->Show();
 }
 //---------------------------------------------------------------------------
@@ -117,6 +117,7 @@ void __fastcall TFileFindDialog::UpdateControls()
   bool EnableFileOperations = !Finding && (FileView->SelCount > 0);
   DeleteAction->Enabled = EnableFileOperations;
   DownloadAction->Enabled = EnableFileOperations;
+  EditAction->Enabled = EnableFileOperations;
   CopyAction->Enabled = (FileView->Items->Count > 0);
   SelectAllAction->Enabled = (FileView->SelCount < FileView->Items->Count);
 
@@ -162,7 +163,7 @@ void __fastcall TFileFindDialog::ControlChange(TObject * /*Sender*/)
 //---------------------------------------------------------------------------
 void __fastcall TFileFindDialog::Init(
   TTerminal * Terminal, UnicodeString Directory, TFindEvent OnFind, TFocusFileEvent OnFocusFile,
-  TFileListOperationEvent OnDeleteFiles, TFileListOperationEvent OnDownloadFiles)
+  TFileListOperationEvent OnDeleteFiles, TFileListOperationEvent OnDownloadFiles, TFileListOperationEvent OnEditFiles)
 {
   if (FTerminal != Terminal)
   {
@@ -177,6 +178,7 @@ void __fastcall TFileFindDialog::Init(
   FOnFocusFile = OnFocusFile;
   FOnDeleteFiles = OnDeleteFiles;
   FOnDownloadFiles = OnDownloadFiles;
+  FOnEditFiles = OnEditFiles;
 
   MaskEdit->Text = WinConfiguration->SelectMask;
   RemoteDirectoryEdit->Text = UnixExcludeTrailingBackslash(Directory);
@@ -637,3 +639,8 @@ void __fastcall TFileFindDialog::DownloadActionExecute(TObject * /*Sender*/)
   FileListOperation(FOnDownloadFiles, FileDownloadFinished);
 }
 //---------------------------------------------------------------------------
+void __fastcall TFileFindDialog::EditActionExecute(TObject * /*Sender*/)
+{
+  FileListOperation(FOnEditFiles, FileDownloadFinished);
+}
+//---------------------------------------------------------------------------

+ 28 - 8
source/forms/FileFind.dfm

@@ -1532,29 +1532,39 @@ object FileFindDialog: TFileFindDialog
     Height = 25
     Action = CopyAction
     Anchors = [akRight, akBottom]
-    TabOrder = 7
+    TabOrder = 8
   end
   object DeleteButton: TButton
     Left = 448
-    Top = 204
+    Top = 235
     Width = 108
     Height = 25
     Action = DeleteAction
     Anchors = [akTop, akRight]
-    TabOrder = 6
+    TabOrder = 7
   end
   object DownloadButton: TButton
     Left = 448
-    Top = 173
+    Top = 204
     Width = 108
     Height = 25
     Action = DownloadAction
     Anchors = [akTop, akRight]
+    TabOrder = 6
+  end
+  object EditButton: TButton
+    Left = 448
+    Top = 173
+    Width = 108
+    Height = 25
+    Action = EditAction
+    Anchors = [akTop, akRight]
+    Caption = 'Edi&t'
     TabOrder = 5
   end
   object FileViewPopupMenu: TPopupMenu
-    Left = 478
-    Top = 237
+    Left = 486
+    Top = 269
     object Focus1: TMenuItem
       Action = FocusAction
       Default = True
@@ -1562,6 +1572,9 @@ object FileFindDialog: TFileFindDialog
     object N1: TMenuItem
       Caption = '-'
     end
+    object Edit1: TMenuItem
+      Action = EditAction
+    end
     object Download1: TMenuItem
       Action = DownloadAction
     end
@@ -1582,8 +1595,8 @@ object FileFindDialog: TFileFindDialog
     end
   end
   object ActionList: TActionList
-    Left = 478
-    Top = 293
+    Left = 486
+    Top = 317
     object DeleteAction: TAction
       Caption = '&Delete'
       SecondaryShortCuts.Strings = (
@@ -1610,5 +1623,12 @@ object FileFindDialog: TFileFindDialog
       ShortCut = 116
       OnExecute = DownloadActionExecute
     end
+    object EditAction: TAction
+      Caption = '&Edit'
+      SecondaryShortCuts.Strings = (
+        'Ctrl+E')
+      ShortCut = 115
+      OnExecute = EditActionExecute
+    end
   end
 end

+ 7 - 1
source/forms/FileFind.h

@@ -55,6 +55,9 @@ __published:
   TButton *DownloadButton;
   TAction *DownloadAction;
   TMenuItem *Download1;
+  TAction *EditAction;
+  TButton *EditButton;
+  TMenuItem *Edit1;
   void __fastcall ControlChange(TObject *Sender);
   void __fastcall StartStopButtonClick(TObject *Sender);
   void __fastcall StopButtonClick(TObject *Sender);
@@ -75,6 +78,7 @@ __published:
   void __fastcall FocusActionExecute(TObject *Sender);
   void __fastcall SelectAllActionExecute(TObject *Sender);
   void __fastcall DownloadActionExecute(TObject *Sender);
+  void __fastcall EditActionExecute(TObject *Sender);
 
 public:
   __fastcall TFileFindDialog(TComponent * Owner);
@@ -82,7 +86,8 @@ public:
 
   void __fastcall Init(
     TTerminal * Terminal, UnicodeString Directory, TFindEvent OnFind, TFocusFileEvent OnFocusFile,
-    TFileListOperationEvent OnDeleteFiles, TFileListOperationEvent OnDownloadFiles);
+    TFileListOperationEvent OnDeleteFiles, TFileListOperationEvent OnDownloadFiles,
+    TFileListOperationEvent OnEditFiles);
 
 protected:
   void __fastcall Clear();
@@ -109,6 +114,7 @@ private:
   TFocusFileEvent FOnFocusFile;
   TFileListOperationEvent FOnDeleteFiles;
   TFileListOperationEvent FOnDownloadFiles;
+  TFileListOperationEvent FOnEditFiles;
   TFrameAnimation FFrameAnimation;
   UnicodeString FFocusPath;
   typedef std::map<UnicodeString, TListItem *> TFileItemMap;

+ 2 - 1
source/windows/WinInterface.h

@@ -422,7 +422,8 @@ typedef void __fastcall (__closure *TFileListOperationEvent)
   (TTerminal * Terminal, TStrings * FileList, TFileOperationFinishedEvent OnFileOperationFinished);
 void __fastcall ShowFileFindDialog(
   TTerminal * Terminal, UnicodeString Directory, TFindEvent OnFind, TFocusFileEvent OnFocusFile,
-  TFileListOperationEvent OnDeleteFiles, TFileListOperationEvent OnDownloadFiles);
+  TFileListOperationEvent OnDeleteFiles, TFileListOperationEvent OnDownloadFiles,
+  TFileListOperationEvent OnEditFiles);
 void __fastcall HideFileFindDialog();
 
 // forms\GenerateUrl.cpp