Support editing

This commit is contained in:
Devin Stiert 2015-05-02 10:17:42 -04:00
parent 485afcfa6e
commit 40f58d7054
3 changed files with 43 additions and 34 deletions

View File

@ -8,28 +8,20 @@
Height="180"
WindowStartupLocation="CenterScreen"
d:DesignHeight="400" d:DesignWidth="300">
<Grid Margin="10,10,10,0" VerticalAlignment="Top" Height="129" >
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<Label Content="Directory:"/>
<TextBox Name="Directory" VerticalAlignment="Center" Width="238" Margin="0,7" />
<Button Name="BrowseButton" Content="Browse" HorizontalAlignment="Left" VerticalAlignment="Center" Width="75" Click="BrowseButton_Click" />
</StackPanel>
<StackPanel Grid.Row="1" Orientation="Horizontal">
<StackPanel Orientation="Horizontal">
<Label Content="File Suffixes:" />
<TextBox x:Name="Suffixes" VerticalAlignment="Center" Width="297" Margin="0,7" />
</StackPanel>
<StackPanel Grid.Row="2" Orientation="Horizontal">
<StackPanel Orientation="Horizontal">
<Label Content="Maximum Search Depth (-1 is unlimited):" />
<TextBox Name="MaxDepth" Text="-1" VerticalAlignment="Center" Width="146" Margin="0,7" />
</StackPanel>
<StackPanel Grid.Row="3" Orientation="Horizontal">
<Button VerticalAlignment="Center" Height="20" Width="70" Click="ButtonAdd_OnClick" Content="{DynamicResource wox_plugin_program_update}" Margin="300,0" />
</StackPanel>
</Grid>
<Button VerticalAlignment="Center" HorizontalAlignment="Right" Margin="10" Height="20" Width="70" Click="ButtonAdd_OnClick" Content="{DynamicResource wox_plugin_program_update}" />
</StackPanel>
</Window>

View File

@ -19,14 +19,21 @@ namespace Wox.Plugin.Program
/// </summary>
public partial class AddProgramSource
{
private Action reindex;
private ProgramSource _editing;
public AddProgramSource(Action reindex)
public AddProgramSource()
{
this.reindex = reindex;
InitializeComponent();
}
public AddProgramSource(ProgramSource edit) : this()
{
this._editing = edit;
this.Directory.Text = this._editing.Location;
this.MaxDepth.Text = this._editing.MaxDepth.ToString();
this.Suffixes.Text = this._editing.Suffixes;
}
private void BrowseButton_Click(object sender, RoutedEventArgs e)
{
var dialog = new System.Windows.Forms.FolderBrowserDialog();
@ -44,16 +51,27 @@ namespace Wox.Plugin.Program
{
max = -1;
}
ProgramStorage.Instance.ProgramSources.Add(new ProgramSource()
if(this._editing == null)
{
Location = this.Directory.Text,
MaxDepth = max,
Suffixes = this.Suffixes.Text,
Type = "FileSystemProgramSource",
Enabled = true
});
ProgramStorage.Instance.ProgramSources.Add(new ProgramSource()
{
Location = this.Directory.Text,
MaxDepth = max,
Suffixes = this.Suffixes.Text,
Type = "FileSystemProgramSource",
Enabled = true
});
}
else
{
this._editing.Location = this.Directory.Text;
this._editing.MaxDepth = max;
this._editing.Suffixes = this.Suffixes.Text;
}
ProgramStorage.Instance.Save();
reindex();
this.DialogResult = true;
this.Close();
}
}

View File

@ -39,8 +39,11 @@ namespace Wox.Plugin.Program
private void btnAddProgramSource_OnClick(object sender, RoutedEventArgs e)
{
var add = new AddProgramSource(this.ReIndexing);
add.Show();
var add = new AddProgramSource();
if(add.ShowDialog() ?? false)
{
this.ReIndexing();
}
}
private void btnDeleteProgramSource_OnClick(object sender, RoutedEventArgs e)
@ -69,14 +72,10 @@ namespace Wox.Plugin.Program
ProgramSource selectedProgramSource = programSourceView.SelectedItem as ProgramSource;
if (selectedProgramSource != null)
{
//todo: update
var folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();
if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
var add = new AddProgramSource(selectedProgramSource);
if (add.ShowDialog() ?? false)
{
string path = folderBrowserDialog.SelectedPath;
selectedProgramSource.Location = path;
ProgramStorage.Instance.Save();
ReIndexing();
this.ReIndexing();
}
}
else