Skip to content

Commit

Permalink
Remove search flags
Browse files Browse the repository at this point in the history
Tracking the exact order of launchers in the recent and favorites
makes having a search flag redundant.
  • Loading branch information
gottcode committed Nov 8, 2023
1 parent 63c3fbb commit 10ed984
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 71 deletions.
16 changes: 0 additions & 16 deletions panel-plugin/favorites-page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ void FavoritesPage::add(Launcher* launcher)
return;
}

launcher->set_flag(Launcher::FavoriteFlag, true);

// Append to list of items
GtkListStore* store = GTK_LIST_STORE(get_view()->get_model());
gtk_list_store_insert_with_values(
Expand All @@ -85,11 +83,6 @@ void FavoritesPage::add(Launcher* launcher)

void FavoritesPage::remove(Launcher* launcher)
{
if (launcher)
{
launcher->set_flag(Launcher::FavoriteFlag, false);
}

GtkTreeModel* model = GTK_TREE_MODEL(get_view()->get_model());
GtkListStore* store = GTK_LIST_STORE(model);
GtkTreeIter iter;
Expand Down Expand Up @@ -134,15 +127,6 @@ void FavoritesPage::set_menu_items()
});

g_object_unref(model);

for (const auto& favorite : wm_settings->favorites)
{
Launcher* launcher = get_window()->get_applications()->find(favorite);
if (launcher)
{
launcher->set_flag(Launcher::FavoriteFlag, true);
}
}
}

//-----------------------------------------------------------------------------
Expand Down
29 changes: 6 additions & 23 deletions panel-plugin/launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,33 +353,30 @@ void Launcher::run(GdkScreen* screen, DesktopAction* action) const

unsigned int Launcher::search(const Query& query)
{
// Prioritize matches in favorites and recent, then favories, and then recent
const unsigned int flags = 3 - m_search_flags;

// Sort matches in names first
unsigned int match = query.match(m_search_name);
if (match != UINT_MAX)
{
return match | flags | 0x400;
return match | 0x400;
}

match = query.match_as_characters(m_search_name);
if (match != UINT_MAX)
{
return match | flags | 0x400;
return match | 0x400;
}

match = query.match(m_search_generic_name);
if (match != UINT_MAX)
{
return match | flags | 0x800;
return match | 0x800;
}

// Sort matches in comments next
match = query.match(m_search_comment);
if (match != UINT_MAX)
{
return match | flags | 0x1000;
return match | 0x1000;
}

// Sort matches in keywords next
Expand All @@ -388,32 +385,18 @@ unsigned int Launcher::search(const Query& query)
match = query.match(keyword);
if (match != UINT_MAX)
{
return match | flags | 0x2000;
return match | 0x2000;
}
}

// Sort matches in executables last
match = query.match(m_search_command);
if (match != UINT_MAX)
{
return match | flags | 0x4000;
return match | 0x4000;
}

return UINT_MAX;
}

//-----------------------------------------------------------------------------

void Launcher::set_flag(SearchFlag flag, bool enabled)
{
if (enabled)
{
m_search_flags |= flag;
}
else
{
m_search_flags &= ~flag;
}
}

//-----------------------------------------------------------------------------
7 changes: 0 additions & 7 deletions panel-plugin/launcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,6 @@ class Launcher : public Element

unsigned int search(const Query& query) override;

enum SearchFlag
{
RecentFlag = 0x1,
FavoriteFlag = 0x2
};
void set_flag(SearchFlag flag, bool enabled);

private:
GarconMenuItem* m_item;
const gchar* m_display_name;
Expand Down
24 changes: 0 additions & 24 deletions panel-plugin/recent-page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ void RecentPage::add(Launcher* launcher)
{
return;
}
launcher->set_flag(Launcher::RecentFlag, true);

std::string desktop_id = launcher->get_desktop_id();
if (!wm_settings->recent.empty())
Expand Down Expand Up @@ -111,12 +110,6 @@ void RecentPage::enforce_item_count()
GtkListStore* store = GTK_LIST_STORE(get_view()->get_model());
for (int i = wm_settings->recent.size() - 1, end = wm_settings->recent_items_max; i >= end; --i)
{
Launcher* launcher = get_window()->get_applications()->find(wm_settings->recent[i]);
if (launcher)
{
launcher->set_flag(Launcher::RecentFlag, false);
}

GtkTreeIter iter;
if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store), &iter, nullptr, i))
{
Expand All @@ -129,27 +122,11 @@ void RecentPage::enforce_item_count()

//-----------------------------------------------------------------------------

void RecentPage::flag_items(bool enabled)
{
for (const auto& recent : wm_settings->recent)
{
Launcher* launcher = get_window()->get_applications()->find(recent);
if (launcher)
{
launcher->set_flag(Launcher::RecentFlag, enabled);
}
}
}

//-----------------------------------------------------------------------------

void RecentPage::set_menu_items()
{
GtkTreeModel* model = get_window()->get_applications()->create_launcher_model(wm_settings->recent);
get_view()->set_model(model);
g_object_unref(model);

flag_items(true);
}

//-----------------------------------------------------------------------------
Expand All @@ -171,7 +148,6 @@ void RecentPage::extend_context_menu(GtkWidget* menu)
connect(menuitem, "activate",
[this](GtkMenuItem*)
{
flag_items(false);
gtk_list_store_clear(GTK_LIST_STORE(get_view()->get_model()));
wm_settings->recent.clear();
});
Expand Down
1 change: 0 additions & 1 deletion panel-plugin/recent-page.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class RecentPage : public Page

void add(Launcher* launcher);
void enforce_item_count();
void flag_items(bool enabled);
void set_menu_items();
void unset_menu_items();

Expand Down

0 comments on commit 10ed984

Please sign in to comment.