Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skyline: Improved Import Results Files form restoring UI from last use. #3199

Merged
merged 8 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion pwiz_tools/Skyline/FileUI/ImportResultsDlg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,22 +335,44 @@ public static MsDataFileUri[] GetDataSourcePaths(Control parent, string document
using (var dlgOpen = new OpenDataSourceDialog(Settings.Default.RemoteAccountList))
{
dlgOpen.Text = FileUIResources.ImportResultsDlg_GetDataSourcePathsFile_Import_Results_Files;
var dlgSize = Settings.Default.SrmResultsWindowSize;
if (!dlgSize.IsEmpty)
dlgOpen.Size = dlgSize;

string initialDir = Settings.Default.SrmResultsDirectory;
// If the saved initial directory is not for the same document, then start
// in the document folder. Always starting in the document folder is painful
// to watch, if the user is adding a single file at a time from a different
// directory.
if (string.IsNullOrEmpty(initialDir) || !Equals(Settings.Default.SrmResultsSavedForPath, documentSavedPath))
{
string docDir = Path.GetDirectoryName(documentSavedPath);
if (!string.IsNullOrEmpty(docDir))
initialDir = docDir;
}
// The dialog expects null to mean no directory was supplied, so don't assign
// an empty string.
string initialDir = Path.GetDirectoryName(documentSavedPath) ?? Settings.Default.SrmResultsDirectory;
if (string.IsNullOrEmpty(initialDir))
initialDir = null;
dlgOpen.InitialDirectory = new MsDataFilePath(initialDir);
// Use saved source type, if there is one.
string sourceType = Settings.Default.SrmResultsSourceType;
if (!string.IsNullOrEmpty(sourceType))
dlgOpen.SourceTypeName = sourceType;
dlgOpen.ListView = (View)Settings.Default.SrmResultsListView;
dlgOpen.SetListViewSort(Settings.Default.SrmResultsListColumnSortIndex,
(SortOrder) Settings.Default.SrmResultsListSortOrder);

if (dlgOpen.ShowDialog(parent) != DialogResult.OK)
return null;

Settings.Default.SrmResultsSavedForPath = documentSavedPath;
Settings.Default.SrmResultsDirectory = dlgOpen.CurrentDirectory.ToString();
Settings.Default.SrmResultsSourceType = dlgOpen.SourceTypeName;
Settings.Default.SrmResultsListView = (int)dlgOpen.ListView;
Settings.Default.SrmResultsListColumnSortIndex = dlgOpen.ListSortColumnIndex;
Settings.Default.SrmResultsListSortOrder = (int)dlgOpen.ListSortOrder;
Settings.Default.SrmResultsWindowSize = dlgOpen.Size;

var dataSources = dlgOpen.DataSources;

Expand Down
108 changes: 73 additions & 35 deletions pwiz_tools/Skyline/FileUI/OpenDataSourceDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,23 @@ public IEnumerable<string> SelectedFiles
}
}

public View ListView
{
get { return listView.View; }
set { SetListView(value); }
}

public int ListSortColumnIndex
{
get { return _listViewColumnSorter.SortColumn; }
}

public SortOrder ListSortOrder
{
get { return _listViewColumnSorter.Order; }
}


private string _sourceTypeName;
public string SourceTypeName
{
Expand Down Expand Up @@ -711,23 +728,24 @@ private void OpenFolder(MsDataFileUri uri)

private void listView_ColumnClick( object sender, ColumnClickEventArgs e )
{
// Determine if the clicked column is already the column that is being sorted.
if( e.Column == _listViewColumnSorter.SortColumn )
{
// Reverse the current sort direction for this column.
_listViewColumnSorter.Order = _listViewColumnSorter.Order == SortOrder.Ascending
? SortOrder.Descending
: SortOrder.Ascending;
}
else
{
// Set the column number that is to be sorted; default to ascending.
_listViewColumnSorter.SortColumn = e.Column;
_listViewColumnSorter.Order = SortOrder.Ascending;
}
ToggleListViewSort(e.Column);
}

// Perform the sort with these new sort options.
listView.Sort();
private void ToggleListViewSort(int columnIndex)
{
var order = SortOrder.Ascending;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the regular File Open dialog, the default initial sort order depends on the column.
It's SortOrder.Descending for the Date column.
I wonder whether we should be duplicating that logic here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for this PR

if (columnIndex == _listViewColumnSorter.SortColumn && order == _listViewColumnSorter.Order)
order = SortOrder.Descending;
SetListViewSort(columnIndex, order);
}

public void SetListViewSort(int columnIndex, SortOrder order)
{
_listViewColumnSorter.SortColumn = columnIndex;
_listViewColumnSorter.Order = order;

if (listView.IsHandleCreated)
listView.Sort();
}

private void openButton_Click( object sender, EventArgs e )
Expand Down Expand Up @@ -815,33 +833,53 @@ private void cancelButton_Click( object sender, EventArgs e )

private void tilesToolStripMenuItem_Click( object sender, EventArgs e )
{
foreach( ToolStripDropDownItem item in viewsDropDownButton.DropDownItems )
( (ToolStripMenuItem) item ).Checked = false;
( (ToolStripMenuItem) viewsDropDownButton.DropDownItems[0] ).Checked = true;
listView.BeginUpdate();
listView.View = View.Tile;
listView.EndUpdate();
SetListView(View.Tile);
}

private void listToolStripMenuItem_Click( object sender, EventArgs e )
{
foreach( ToolStripDropDownItem item in viewsDropDownButton.DropDownItems )
( (ToolStripMenuItem) item ).Checked = false;
( (ToolStripMenuItem) viewsDropDownButton.DropDownItems[1] ).Checked = true;
listView.View = View.List;
listView.Columns[0].Width = -1;
SetListView(View.List);
}

private void detailsToolStripMenuItem_Click(object sender, EventArgs e)
{
SetListView(View.Details);
}

private void SetListView(View view)
{
if (listView.View != view)
{
int menuIndex = GetMenuIndex(view);
var items = viewsDropDownButton.DropDownItems;
for (int i = 0; i < items.Count; i++)
((ToolStripMenuItem)items[i]).Checked = (i == menuIndex);

listView.BeginUpdate();
listView.View = view;
if (view == View.Details)
{
populateListViewFromDirectory(_currentDirectory);
listView.Columns[0].Width = 200;
}
else
{
listView.Columns[0].Width = -1;
}
listView.EndUpdate();
}
}

private void detailsToolStripMenuItem_Click( object sender, EventArgs e )
private int GetMenuIndex(View view)
{
if( listView.View != View.Details )
switch (view)
{
foreach( ToolStripDropDownItem item in viewsDropDownButton.DropDownItems )
( (ToolStripMenuItem) item ).Checked = false;
( (ToolStripMenuItem) viewsDropDownButton.DropDownItems[2] ).Checked = true;
listView.View = View.Details;
populateListViewFromDirectory( _currentDirectory );
listView.Columns[0].Width = 200;
case View.Details:
return 2;
case View.Tile:
return 0;
default:
return 1;
}
}

Expand Down
112 changes: 96 additions & 16 deletions pwiz_tools/Skyline/Properties/Settings.Designer.cs

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

17 changes: 16 additions & 1 deletion pwiz_tools/Skyline/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,21 @@
</Setting>
<Setting Name="RelativeAbundanceLogScale" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
</Setting>
<Setting Name="SrmResultsSavedForPath" Type="System.String" Scope="User">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be safe to rename "SrmResultsXxx" properties if we think a different naming scheme would be better ("ImportResultsXxx", or "OpenDataSourceXxx"?)
"SrmResultsDirectory" was never actually used in older versions of Skyline because it only applied if the document had never been saved, so we don't have to worry about backwards compatibility.
"SrmResultsSourceType" was the only SrmResultsXxx property that actually got used.

<Value Profile="(Default)" />
</Setting>
<Setting Name="SrmResultsListView" Type="System.Int32" Scope="User">
<Value Profile="(Default)">3</Value>
</Setting>
<Setting Name="SrmResultsListColumnSortIndex" Type="System.Int32" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
<Setting Name="SrmResultsListSortOrder" Type="System.Int32" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
<Setting Name="SrmResultsWindowSize" Type="System.Drawing.Size" Scope="User">
<Value Profile="(Default)">0, 0</Value>
</Setting>
</Settings>
</SettingsFile>
Loading