Changeset 11467


Ignore:
Timestamp:
10/15/14 19:40:51 (5 years ago)
Author:
bburlacu
Message:

#2265: Added drag&drop file loading support. To avoid confusion between files and all the other data types that can be dragged and dropped in HeuristicLab, the drop area for loading files is restricted to the toolbar and menubar of the HL window.

Location:
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/MainForms
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/MainForms/MainForm.Designer.cs

    r11171 r11467  
    5757      this.menuStrip.TabIndex = 0;
    5858      this.menuStrip.Text = "menuStrip";
     59      this.menuStrip.AllowDrop = true;
     60      this.menuStrip.DragEnter += MainFormBase_DragEnter;
     61      this.menuStrip.DragDrop += MainFormBase_DragDrop;
    5962      //
    6063      // toolStrip
     
    6467      this.toolStrip.Size = new System.Drawing.Size(624, 25);
    6568      this.toolStrip.TabIndex = 1;
     69      this.toolStrip.AllowDrop = true;
     70      this.toolStrip.DragEnter += MainFormBase_DragEnter;
     71      this.toolStrip.DragDrop += MainFormBase_DragDrop;
    6672      //
    6773      // statusStrip
     
    7379      this.statusStrip.Text = "statusStrip";
    7480      //
    75       // MainFormBase
     81      // MainForm
    7682      //
    7783      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/MainForms/MainForm.cs

    r11171 r11467  
    555555      try {
    556556        ((IActionUserInterfaceItem)item.Tag).Execute();
    557       } catch (Exception ex) {
     557      }
     558      catch (Exception ex) {
    558559        ErrorHandling.ShowErrorDialog((Control)MainFormManager.MainForm, ex);
    559560      }
     
    600601    }
    601602    #endregion
     603
     604    private void MainFormBase_DragEnter(object sender, DragEventArgs e) {
     605      // perform type checking to ensure that the data being dragged is of an acceptable type
     606      e.Effect = e.Data.GetDataPresent(DataFormats.FileDrop) ? DragDropEffects.Copy : DragDropEffects.None;
     607    }
     608
     609    private void MainFormBase_DragDrop(object sender, DragEventArgs e) {
     610      if (e.Data.GetDataPresent(DataFormats.FileDrop)) {
     611        string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
     612        foreach (var path in files) {
     613          SetAppStartingCursor();
     614          ContentManager.LoadAsync(path, LoadingCompleted);
     615        }
     616      }
     617    }
     618
     619    private static void LoadingCompleted(IStorableContent content, Exception error) {
     620      try {
     621        if (error != null) throw error;
     622        IView view = MainFormManager.MainForm.ShowContent(content);
     623        if (view == null)
     624          ErrorHandling.ShowErrorDialog("There is no view for the loaded item. It cannot be displayed.", new InvalidOperationException("No View Available"));
     625      }
     626      catch (Exception ex) {
     627        ErrorHandling.ShowErrorDialog((Control)MainFormManager.MainForm, "Cannot open file.", ex);
     628      }
     629      finally {
     630        ((MainForm)MainFormManager.MainForm).ResetAppStartingCursor();
     631      }
     632    }
    602633  }
    603634}
Note: See TracChangeset for help on using the changeset viewer.