Skip to content

Commit

Permalink
allow changing amount of recent widgets displayed
Browse files Browse the repository at this point in the history
closes #7
  • Loading branch information
FluffierThanThou committed Aug 9, 2020
1 parent dd2ccd3 commit ef4e781
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Source/CommandPalette.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,9 @@ public override string SettingsCategory()
return "Command Palette";
}

public override void WriteSettings(){
base.WriteSettings();
PaletteWindow.Notify_SettingsChanged();
}
}
}
4 changes: 4 additions & 0 deletions Source/HistoryList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public HistoryList( int size )
this.size = size;
}

public void Resize( int size ){
this.size = size;
}

public void Add( T datum )
{
if ( data.Contains( datum ) )
Expand Down
7 changes: 5 additions & 2 deletions Source/PaletteWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,11 @@ public static IEnumerable<Designator> FilteredDesignators
return _filteredDesignators.Where( d => d.Visible );
}
}

private static HistoryList<Designator> _recentlyUsed = new HistoryList<Designator>( 10 );

public static void Notify_SettingsChanged(){
_recentlyUsed.Resize(CommandPalette.Settings.MaxRecentDesignators);
}
private static HistoryList<Designator> _recentlyUsed = new HistoryList<Designator>( CommandPalette.Settings.MaxRecentDesignators );
public static IEnumerable<Designator> VisibleRecentlyUsed => _recentlyUsed.Where( d => d.Visible );

public static float Similarity( Designator des )
Expand Down
11 changes: 11 additions & 0 deletions Source/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ namespace CommandPalette
public class Settings : ModSettings
{
public float PaletteScale = 1f;
public int MaxRecentDesignators = 10;
public bool OpenArchitect = true;
public int NumRows = 2;
public int NumCols = 4;
private KeyBind _keyBinding;
private string _numRows;
private string _numCols;
private string _maxRecent;

public KeyBind KeyBinding
{
Expand All @@ -31,13 +33,21 @@ public void DoWindowContents( Rect canvas )
PaletteScale = options.Slider( PaletteScale, 1 / 3f, 1 );
options.CheckboxLabeled( "Open Architect window when selecting command", ref OpenArchitect,
"If enabled, when selecting a command in the command palette, the corresponding tab is opened in the Architect menu." );

var rect = options.GetRect( 30 );
Widgets.Label( rect.LeftPart( 2 / 3f ), "Number of commands per row" );
Widgets.TextFieldNumeric( rect.RightPart( 1 / 3f ), ref NumCols, ref _numCols, 2, 10 );

rect = options.GetRect( 30 );
Widgets.Label( rect.LeftPart( 2 / 3f ), "Number of commands per column" );
Widgets.TextFieldNumeric( rect.RightPart( 1 / 3f ), ref NumRows, ref _numRows, 1, 10 );

KeyBinding.Draw( options.GetRect( 30 ) );

rect = options.GetRect(30);
Widgets.Label(rect.LeftPart(2 / 3f), "Maximum number of recently used designators shown");
Widgets.TextFieldNumeric(rect.RightPart(1 / 3f), ref MaxRecentDesignators, ref _maxRecent, 0, NumCols * NumRows);

options.End();
}

Expand All @@ -49,6 +59,7 @@ public override void ExposeData()
Scribe_Values.Look( ref OpenArchitect, "openArchitect", true );
Scribe_Values.Look( ref NumCols, "numCols", 4 );
Scribe_Values.Look( ref NumRows, "numRows", 2 );
Scribe_Values.Look(ref MaxRecentDesignators, "maxRecentDesignators", 10);
Scribe_Deep.Look( ref _keyBinding, "keybinding" );
}
}
Expand Down

0 comments on commit ef4e781

Please sign in to comment.