~haowenl/vorg-windows

0e8f8d9ca1bb62324d493719b49228a4bee7b68a — Haowen Liu 11 months ago 25de067
Implement autocomplete
M libvorg => libvorg +1 -1
@@ 1,1 1,1 @@
Subproject commit c3c6e8bd5a331e390cf47e831faacc5eb51c8ba2
Subproject commit a3888800b021c15524cb7185fca28f59ae8c154a

M vorg-windows/App.xaml.cpp => vorg-windows/App.xaml.cpp +54 -1
@@ 48,7 48,10 @@ bool App::OpenRepo(const hstring &path)
{
    std::string pathUTF8 = to_string(path);
    mRepo = std::make_unique<Vorg::VorgRepo>(pathUTF8);
    return mRepo->initRepo();
    if (!mRepo->initRepo())
        return false;
    mRepo->updateAutocompleteData();
    return true;
}

bool App::SetImportFile(const hstring &path)


@@ 109,6 112,56 @@ void App::PopulateVideoData(
    }
}

Windows::Foundation::Collections::IVector<Windows::Foundation::IInspectable> App::CompleteStudios(
    const hstring &studio) const
{
    Windows::Foundation::Collections::IVector<Windows::Foundation::IInspectable> result =
        single_threaded_observable_vector<Windows::Foundation::IInspectable>();
    if (studio.empty())
        return result;
    std::string studioUTF8 = to_string(studio);
    auto resultUTF8 = mRepo->completeStudios(studioUTF8, 3);
    for (auto &suggestUFT8 : resultUTF8)
    {
        hstring suggest = to_hstring(suggestUFT8);
        result.Append(box_value(suggest));
    }
    return result;
}

Windows::Foundation::Collections::IVector<Windows::Foundation::IInspectable> App::CompleteActors(
    const hstring &actor) const
{
    Windows::Foundation::Collections::IVector<Windows::Foundation::IInspectable> result =
        single_threaded_observable_vector<Windows::Foundation::IInspectable>();
    if (actor.empty())
        return result;
    std::string actorUTF8 = to_string(actor);
    auto resultUTF8 = mRepo->completeActors(actorUTF8, 3);
    for (auto &suggestUFT8 : resultUTF8)
    {
        hstring suggest = to_hstring(suggestUFT8);
        result.Append(box_value(suggest));
    }
    return result;
}

Windows::Foundation::Collections::IVector<Windows::Foundation::IInspectable> App::CompleteTags(const hstring &tag) const
{
    Windows::Foundation::Collections::IVector<Windows::Foundation::IInspectable> result =
        single_threaded_observable_vector<Windows::Foundation::IInspectable>();
    if (tag.empty())
        return result;
    std::string tagUTF8 = to_string(tag);
    auto resultUTF8 = mRepo->completeTags(tagUTF8, 3);
    for (auto &suggestUFT8 : resultUTF8)
    {
        hstring suggest = to_hstring(suggestUFT8);
        result.Append(box_value(suggest));
    }
    return result;
}

hstring App::GetVorgError() const
{
    if (mRepo == nullptr)

M vorg-windows/App.xaml.h => vorg-windows/App.xaml.h +5 -0
@@ 23,6 23,11 @@ struct App : AppT<App>
                    const Windows::Foundation::Collections::IObservableVector<hstring> &tags);
    void PopulateVideoData(
        Windows::Foundation::Collections::IObservableVector<Windows::Foundation::IInspectable> &resultData) const;
    Windows::Foundation::Collections::IVector<Windows::Foundation::IInspectable> CompleteStudios(
        const hstring &studio) const;
    Windows::Foundation::Collections::IVector<Windows::Foundation::IInspectable> CompleteActors(
        const hstring &actor) const;
    Windows::Foundation::Collections::IVector<Windows::Foundation::IInspectable> CompleteTags(const hstring &tag) const;

    // Error handling
    hstring GetVorgError() const;

M vorg-windows/ImportEditPage.xaml => vorg-windows/ImportEditPage.xaml +6 -3
@@ 48,7 48,8 @@
            <AutoSuggestBox
                x:Name="StudioInput"
                Grid.Row="1"
                Grid.Column="1" />
                Grid.Column="1"
                TextChanged="StudioInput_TextChanged" />
        </Grid>

        <Grid


@@ 79,7 80,8 @@
                    x:Name="ActorNameInput"
                    Grid.Column="0"
                    HorizontalAlignment="Stretch"
                    KeyUp="ActorNameInput_KeyUp" />
                    KeyUp="ActorNameInput_KeyUp"
                    TextChanged="ActorNameInput_TextChanged" />
                <Button
                    x:Name="ActorsSubmitButton"
                    Grid.Column="1"


@@ 148,7 150,8 @@
                    x:Name="TagNameInput"
                    Grid.Column="0"
                    HorizontalAlignment="Stretch"
                    KeyUp="TagNameInput_KeyUp" />
                    KeyUp="TagNameInput_KeyUp"
                    TextChanged="TagNameInput_TextChanged" />
                <Button
                    x:Name="TagsSubmitButton"
                    Grid.Column="1"

M vorg-windows/ImportEditPage.xaml.cpp => vorg-windows/ImportEditPage.xaml.cpp +21 -0
@@ 124,6 124,27 @@ void ImportEditPage::SubmitButton_Click(const Windows::Foundation::IInspectable 
    mEditFinishedEvent(*this, nullptr);
}

void ImportEditPage::StudioInput_TextChanged(
    const winrt::Microsoft::UI::Xaml::Controls::AutoSuggestBox &sender,
    const winrt::Microsoft::UI::Xaml::Controls::AutoSuggestBoxTextChangedEventArgs &)
{
    sender.ItemsSource(mApp->CompleteStudios(sender.Text()));
}

void ImportEditPage::ActorNameInput_TextChanged(
    const winrt::Microsoft::UI::Xaml::Controls::AutoSuggestBox &sender,
    const winrt::Microsoft::UI::Xaml::Controls::AutoSuggestBoxTextChangedEventArgs &)
{
    sender.ItemsSource(mApp->CompleteActors(sender.Text()));
}

void ImportEditPage::TagNameInput_TextChanged(
    const winrt::Microsoft::UI::Xaml::Controls::AutoSuggestBox &sender,
    const winrt::Microsoft::UI::Xaml::Controls::AutoSuggestBoxTextChangedEventArgs &)
{
    sender.ItemsSource(mApp->CompleteTags(sender.Text()));
}

event_token ImportEditPage::EditFinished(
    const Windows::Foundation::TypedEventHandler<vorg_windows::ImportEditPage, Windows::Foundation::IInspectable>
        &handler)

M vorg-windows/ImportEditPage.xaml.h => vorg-windows/ImportEditPage.xaml.h +7 -0
@@ 40,6 40,13 @@ struct ImportEditPage : ImportEditPageT<ImportEditPage>

    void SubmitButton_Click(const Windows::Foundation::IInspectable &, const Microsoft::UI::Xaml::RoutedEventArgs &);

    void StudioInput_TextChanged(const Microsoft::UI::Xaml::Controls::AutoSuggestBox &sender,
                                 const Microsoft::UI::Xaml::Controls::AutoSuggestBoxTextChangedEventArgs &);
    void ActorNameInput_TextChanged(const Microsoft::UI::Xaml::Controls::AutoSuggestBox &sender,
                                    const Microsoft::UI::Xaml::Controls::AutoSuggestBoxTextChangedEventArgs &);
    void TagNameInput_TextChanged(const Microsoft::UI::Xaml::Controls::AutoSuggestBox &sender,
                                  const Microsoft::UI::Xaml::Controls::AutoSuggestBoxTextChangedEventArgs &);

    event_token EditFinished(const Windows::Foundation::TypedEventHandler<vorg_windows::ImportEditPage,
                                                                          Windows::Foundation::IInspectable> &handler);
    void EditFinished(const event_token &token);