DEADSOFTWARE

Main: Allow drop files
authorbinarymaster <x86corez@gmail.com>
Fri, 29 Sep 2017 20:17:35 +0000 (23:17 +0300)
committerbinarymaster <x86corez@gmail.com>
Fri, 29 Sep 2017 20:17:35 +0000 (23:17 +0300)
http://doom2d.org/forum/viewtopic.php?f=12&t=1588

src/editor/f_main.lfm
src/editor/f_main.pas

index ade3a7fc534c7949a6752a2e0096dca0e2879810..0a7bf85a18f92d62b20f50899da3ae527afe6f60 100644 (file)
@@ -3,6 +3,7 @@ object MainForm: TMainForm
   Height = 480
   Top = 255
   Width = 672
+  AllowDropFiles = True
   Caption = '2'
   ClientHeight = 460
   ClientWidth = 672
@@ -18,6 +19,7 @@ object MainForm: TMainForm
   OnCloseQuery = FormCloseQuery
   OnCreate = FormCreate
   OnDestroy = FormDestroy
+  OnDropFiles = FormDropFiles
   OnKeyDown = FormKeyDown
   OnKeyUp = FormKeyUp
   OnResize = FormResize
index 63f31f4a83d7edc3aaa77513e34b171e75e1f2e1..c5821c4fb5608f62e0321fdbe65fa418501d2e69 100644 (file)
@@ -204,6 +204,7 @@ type
     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
     procedure FormCreate(Sender: TObject);
     procedure FormDestroy(Sender: TObject);
+    procedure FormDropFiles(Sender: TObject; const FileNames: array of String);
     procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
     procedure FormResize(Sender: TObject);
     procedure lbTextureListClick(Sender: TObject);
@@ -262,6 +263,7 @@ type
     procedure OnIdle(Sender: TObject; var Done: Boolean);
   public
     procedure RefreshRecentMenu();
+    procedure OpenMapFile(FileName: String);
   end;
 
 const
@@ -4111,6 +4113,15 @@ begin
   slInvalidTextures.Free;
 end;
 
+procedure TMainForm.FormDropFiles(Sender: TObject;
+  const FileNames: array of String);
+begin
+  if Length(FileNames) <> 1 then
+    Exit;
+
+  OpenMapFile(FileNames[0]);
+end;
+
 procedure TMainForm.RenderPanelResize(Sender: TObject);
 begin
   if MainForm.Visible then
@@ -5841,31 +5852,35 @@ begin
 
   if OpenDialog.Execute() then
   begin
-    if (Pos('.ini', LowerCase(ExtractFileName(OpenDialog.FileName))) > 0) then
-      begin // INI карты:
-        FullClear();
+    OpenMapFile(OpenDialog.FileName);
+    OpenDialog.InitialDir := ExtractFileDir(OpenDialog.FileName);
+  end;
+end;
 
-        pLoadProgress.Left := (RenderPanel.Width div 2)-(pLoadProgress.Width div 2);
-        pLoadProgress.Top := (RenderPanel.Height div 2)-(pLoadProgress.Height div 2);
-        pLoadProgress.Show();
+procedure TMainForm.OpenMapFile(FileName: String);
+begin
+  if (Pos('.ini', LowerCase(ExtractFileName(FileName))) > 0) then
+    begin // INI карты:
+      FullClear();
 
-        OpenedMap := '';
-        OpenedWAD := '';
+      pLoadProgress.Left := (RenderPanel.Width div 2)-(pLoadProgress.Width div 2);
+      pLoadProgress.Top := (RenderPanel.Height div 2)-(pLoadProgress.Height div 2);
+      pLoadProgress.Show();
 
-        LoadMapOld(OpenDialog.FileName);
+      OpenedMap := '';
+      OpenedWAD := '';
 
-        MainForm.Caption := Format('%s - %s', [FormCaption, ExtractFileName(OpenDialog.FileName)]);
+      LoadMapOld(FileName);
 
-        pLoadProgress.Hide();
-        MainForm.FormResize(Self);
-      end
-    else // Карты из WAD:
-      begin
-        OpenMap(OpenDialog.FileName, '');
-      end;
+      MainForm.Caption := Format('%s - %s', [FormCaption, ExtractFileName(FileName)]);
 
-    OpenDialog.InitialDir := ExtractFileDir(OpenDialog.FileName);
-  end;
+      pLoadProgress.Hide();
+      MainForm.FormResize(Self);
+    end
+  else // Карты из WAD:
+    begin
+      OpenMap(FileName, '');
+    end;
 end;
 
 procedure TMainForm.FormActivate(Sender: TObject);