Skip to content

Commit

Permalink
Skyline: Refactor OpenDataSourceDialog: Finish updates
Browse files Browse the repository at this point in the history
As part of previous commit and this commit:
Rename OpenDataSourceDialog to BaseFileDialogNE
Add new empty classes OpenFileDialogNE and OpenDataSourceDialog
New inheritance path: BaseFileDialogNE > OpenFileDialogNE > OpenDataSourceDialog
Move Open() method to class OpenFileDialogNE
  • Loading branch information
danjasuw committed Dec 11, 2024
1 parent 9b73b24 commit 25c56a4
Show file tree
Hide file tree
Showing 13 changed files with 1,278 additions and 1,097 deletions.
32 changes: 16 additions & 16 deletions pwiz_tools/Skyline/FileUI/BaseFileDialogNE.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

115 changes: 17 additions & 98 deletions pwiz_tools/Skyline/FileUI/BaseFileDialogNE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

namespace pwiz.Skyline.FileUI
{
public partial class OpenDataSourceDialog : FormEx
public partial class BaseFileDialogNE : FormEx
{
private readonly ListViewColumnSorter _listViewColumnSorter = new ListViewColumnSorter();
private readonly Stack<MsDataFileUri> _previousDirectories = new Stack<MsDataFileUri>();
Expand All @@ -46,38 +46,22 @@ public partial class OpenDataSourceDialog : FormEx
private readonly IList<RemoteAccount> _remoteAccounts;
private bool _waitingForData;
private readonly IList<string> _specificDataSourceFilter; // Specific data sources to look for

/// <summary>
/// File picker which is aware of mass spec "files" that are really directories
/// </summary>
/// <param name="sourceTypes"></param>
/// <param name="remoteAccounts">For UNIFI</param>
/// <param name="specificDataSourceFilter">Optional list of specific files the user needs to located, ignoring the rest</param>
public OpenDataSourceDialog(IList<RemoteAccount> remoteAccounts, IList<string> specificDataSourceFilter = null)
public BaseFileDialogNE(string[] sourceTypes, IList<RemoteAccount> remoteAccounts, IList<string> specificDataSourceFilter = null)
{
InitializeComponent();
_remoteAccounts = remoteAccounts;

listView.ListViewItemSorter = _listViewColumnSorter;

DialogResult = DialogResult.Cancel;

string[] sourceTypes =
{
FileUIResources.OpenDataSourceDialog_OpenDataSourceDialog_Any_spectra_format,
DataSourceUtil.TYPE_WIFF,
DataSourceUtil.TYPE_WIFF2,
DataSourceUtil.TYPE_AGILENT,
DataSourceUtil.TYPE_BRUKER,
DataSourceUtil.TYPE_MBI,
DataSourceUtil.TYPE_SHIMADZU,
DataSourceUtil.TYPE_THERMO_RAW,
DataSourceUtil.TYPE_WATERS_RAW,
DataSourceUtil.TYPE_MZML,
DataSourceUtil.TYPE_MZXML,
DataSourceUtil.TYPE_MZ5,
DataSourceUtil.TYPE_UIMF
};


sourceTypeComboBox.Items.AddRange(sourceTypes.Cast<object>().ToArray());
sourceTypeComboBox.SelectedIndex = 0;
// Create a new image list for the list view that is the default size (16x16)
Expand Down Expand Up @@ -240,12 +224,12 @@ private void AttachContentsAvailable(RemoteSession remoteSession)

public MsDataFileUri InitialDirectory { get; set; }

public MsDataFileUri DataSource
public MsDataFileUri FileName
{
get { return DataSources[0]; }
get { return FileNames[0]; }
}

public MsDataFileUri[] DataSources { get; private set; }
public MsDataFileUri[] FileNames { get; protected set; }

public void SelectAllFileType(string extension, Func<string, bool> accept = null)
{
Expand Down Expand Up @@ -369,7 +353,7 @@ private SourceInfo getSourceInfo(FileInfo fileInfo)
return null;
}

private bool _abortPopulateList;
protected bool _abortPopulateList;
private void populateListViewFromDirectory(MsDataFileUri directory)
{
_abortPopulateList = false;
Expand Down Expand Up @@ -757,18 +741,18 @@ private void listView_ItemActivate( object sender, EventArgs e )
}
else
{
DataSources = new[] { ((SourceInfo) item.Tag).MsDataFileUri, };
FileNames = new[] { ((SourceInfo) item.Tag).MsDataFileUri, };
DialogResult = DialogResult.OK;
Close();
}
}

private void OpenFolderItem(ListViewItem listViewItem)
protected void OpenFolderItem(ListViewItem listViewItem)
{
OpenFolder(((SourceInfo) listViewItem.Tag).MsDataFileUri);
}

private void OpenFolder(MsDataFileUri uri)
protected void OpenFolder(MsDataFileUri uri)
{
if (_currentDirectory != null)
_previousDirectories.Push(_currentDirectory);
Expand Down Expand Up @@ -800,77 +784,12 @@ public void SetListViewSort(int columnIndex, SortOrder order)

private void openButton_Click( object sender, EventArgs e )
{
Open();
DoMainAction();
}

public void Open()
protected virtual void DoMainAction()
{
List<MsDataFileUri> dataSourceList = new List<MsDataFileUri>();
foreach (ListViewItem item in listView.SelectedItems)
{
if (!DataSourceUtil.IsFolderType(item.SubItems[1].Text))
{
dataSourceList.Add(((SourceInfo)item.Tag).MsDataFileUri);
}
}
if (dataSourceList.Count > 0)
{
DataSources = dataSourceList.ToArray();
_abortPopulateList = true;
DialogResult = DialogResult.OK;
return;
}

// No files selected: see if there is a folder selected that we
// should navigate to
foreach (ListViewItem item in listView.SelectedItems)
{
if (DataSourceUtil.IsFolderType(item.SubItems[1].Text))
{
OpenFolderItem(item);
return;
}
}

try
{
// perhaps the user has typed an entire filename into the text box - or just garbage
var fileOrDirName = sourcePathTextBox.Text;
bool exists;
bool triedAddingDirectory = false;
while (!(exists = ((File.Exists(fileOrDirName) || Directory.Exists(fileOrDirName)))))
{
if (triedAddingDirectory)
break;
MsDataFilePath currentDirectoryPath = CurrentDirectory as MsDataFilePath;
if (null == currentDirectoryPath)
{
break;
}
fileOrDirName = Path.Combine(currentDirectoryPath.FilePath, fileOrDirName);
triedAddingDirectory = true;
}

if (exists)
{
if (DataSourceUtil.IsDataSource(fileOrDirName))
{
DataSources = new[] {MsDataFileUri.Parse(fileOrDirName)};
DialogResult = DialogResult.OK;
return;
}
else if (Directory.Exists(fileOrDirName))
{
OpenFolder(new MsDataFilePath(fileOrDirName));
return;
}
}
}
// ReSharper disable once EmptyGeneralCatchClause
catch {} // guard against user typed-in-garbage

// No files or folders selected: Show an error message.
MessageDlg.Show(this, FileUIResources.OpenDataSourceDialog_Open_Please_select_one_or_more_data_sources);
throw new Exception(@"method DoMainAction() MUST be overridden");
}

private void cancelButton_Click( object sender, EventArgs e )
Expand Down Expand Up @@ -1147,7 +1066,7 @@ private void lookInComboBox_SelectionChangeCommitted( object sender, EventArgs e
if(!Equals(prevDirectory, CurrentDirectory))
_previousDirectories.Push(prevDirectory);
}
class SourceInfo
protected class SourceInfo
{
public SourceInfo(MsDataFileUri msDataFileUri)
{
Expand Down Expand Up @@ -1205,7 +1124,7 @@ private string SizeLabel
}
}

private enum ImageIndex
protected enum ImageIndex
{
RecentDocuments,
Desktop,
Expand Down
20 changes: 10 additions & 10 deletions pwiz_tools/Skyline/FileUI/BaseFileDialogNE.ja.resx
Original file line number Diff line number Diff line change
Expand Up @@ -333,31 +333,31 @@
<data name="&gt;&gt;label1.ZOrder" xml:space="preserve">
<value>4</value>
</data>
<data name="openButton.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<data name="actionButton.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Bottom, Right</value>
</data>
<data name="openButton.Location" type="System.Drawing.Point, System.Drawing">
<data name="actionButton.Location" type="System.Drawing.Point, System.Drawing">
<value>504, 331</value>
</data>
<data name="openButton.Size" type="System.Drawing.Size, System.Drawing">
<data name="actionButton.Size" type="System.Drawing.Size, System.Drawing">
<value>66, 20</value>
</data>
<data name="openButton.TabIndex" type="System.Int32, mscorlib">
<data name="actionButton.TabIndex" type="System.Int32, mscorlib">
<value>8</value>
</data>
<data name="openButton.Text" xml:space="preserve">
<data name="actionButton.Text" xml:space="preserve">
<value>開く(&amp;O)</value>
</data>
<data name="&gt;&gt;openButton.Name" xml:space="preserve">
<value>openButton</value>
<data name="&gt;&gt;actionButton.Name" xml:space="preserve">
<value>actionButton</value>
</data>
<data name="&gt;&gt;openButton.Type" xml:space="preserve">
<data name="&gt;&gt;actionButton.Type" xml:space="preserve">
<value>System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;openButton.Parent" xml:space="preserve">
<data name="&gt;&gt;actionButton.Parent" xml:space="preserve">
<value>$this</value>
</data>
<data name="&gt;&gt;openButton.ZOrder" xml:space="preserve">
<data name="&gt;&gt;actionButton.ZOrder" xml:space="preserve">
<value>3</value>
</data>
<data name="cancelButton.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
Expand Down
Loading

0 comments on commit 25c56a4

Please sign in to comment.