Skip to content

Commit

Permalink
Added functionality to remove a recipe or package
Browse files Browse the repository at this point in the history
  • Loading branch information
afri-bit committed Nov 28, 2021
1 parent 2fc37ca commit 29977d2
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 20 deletions.
25 changes: 23 additions & 2 deletions conanguide/ui/controller/tab/cache/conan_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,26 @@ def update(self, package_name: str):
item_package.setEditable(False)
self.model.appendRow(item_package)

def get_selected_item(self) -> str:
return self.view.selectedIndexes()[0].data()
def get_selected_item(self) -> str or None:
list_selected_items = self.view.selectedIndexes()

# Checking the list of selected index
# Currently only supporting single selection of items
if len(list_selected_items) > 0: # Only pick the first item in the list
return self.view.selectedIndexes()[0].data()
else: # Empty list will return None
return None

def remove_package(self, recipe_id: str, package_id: str):
self.conan_api.remove(recipe_id, packages=[package_id], force=True)

self.model.removeRow(self.view.currentIndex().row())

def remove_selected_package(self, recipe_id: str):
selected_pkg_id = self.get_selected_item()

self.remove_package(recipe_id, selected_pkg_id)

def clear(self):
self.model.clear()

4 changes: 2 additions & 2 deletions conanguide/ui/controller/tab/cache/conan_package_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def __init__(self, view: QtWidgets.QTreeView, conan_api: ConanApi):
def inspect(self, recipe_id: str, package_id: str):
"""
Method to show the detail information about the recipe
:param recipe_id: Name of the recipe to be inspected
:param recipe_id: Name of the recipe to search for the packages
:param package_id: Package id to be inspected
:return: -
"""

Expand All @@ -48,7 +49,6 @@ def inspect(self, recipe_id: str, package_id: str):
item_value.setEditable(False)
self.model.appendRow([item_key, item_value])


# ========== Options section
item_key = QStandardItem("options")
item_value = QStandardItem("")
Expand Down
19 changes: 17 additions & 2 deletions conanguide/ui/controller/tab/cache/conan_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,20 @@ def sort_ascending(self):
def sort_descending(self):
self.proxy_model.sort(1, QtCore.Qt.DescendingOrder)

def get_selected_item(self) -> str:
return self.view.selectedIndexes()[1].data()
def get_selected_item(self) -> str or None:
list_selected_items = self.view.selectedIndexes()

# Checking the list of selected index
# Currently only supporting single selection of items
if len(list_selected_items) > 0: # Only pick the first item in the list
return self.view.selectedIndexes()[1].data()
else: # Empty list will return None
return None

def remove_recipe(self, recipe_id: str):
self.conan_api.remove(recipe_id, force=True)

# Remove filter to avoid removing the wrong index
# This is kinda workaround currently
self.filter("")
self.model.removeRow(self.view.currentIndex().row())
19 changes: 11 additions & 8 deletions conanguide/ui/controller/tab/cache/conan_recipe_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,7 @@ def inspect(self, recipe_id: str):
:return: -
"""

# Store the current column width before deleting the model
self.__store_column_width()

# Init the model with the header
self.model.clear()
self.model.setColumnCount(2)
self.model.setHeaderData(0, QtCore.Qt.Horizontal, "Property")
self.model.setHeaderData(1, QtCore.Qt.Horizontal, "Value")
self.initialize()

inspect_info = self.conan_api.inspect(recipe_id, None)

Expand Down Expand Up @@ -67,6 +60,16 @@ def inspect(self, recipe_id: str):
# Set the column width with the previous value
self.__set_column_width()

def initialize(self):
# Store the current column width before deleting the model
self.__store_column_width()

# Init the model with the header
self.model.clear()
self.model.setColumnCount(2)
self.model.setHeaderData(0, QtCore.Qt.Horizontal, "Property")
self.model.setHeaderData(1, QtCore.Qt.Horizontal, "Value")

def __store_column_width(self):
"""
Store current column width to the class variable
Expand Down
55 changes: 49 additions & 6 deletions conanguide/ui/widget/tab/cache/tab_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,21 @@ def on_listViewPackage_doubleClicked(self):
def on_btnCopyCachePath_pressed(self):
if self.lineEditConanPath.text() != "":
pyperclip.copy(self.lineEditConanPath.text())
# self.statusBar.showMessage("Conan cache path is copied to clipboard!", 2000)

@Slot()
def on_btnCopyDataPath_pressed(self):
if self.lineEditDataPath.text() != "":
pyperclip.copy(self.lineEditDataPath.text())
# self.statusBar.showMessage("Conan package data path is copied to clipboard!", 2000)

@Slot()
def on_btnCopyRealPath_pressed(self):
if self.lineEditRealPath.text() != "":
pyperclip.copy(self.lineEditRealPath.text())
# self.statusBar.showMessage("Conan package real path is copied to clipboard!", 2000)

@Slot()
def on_btnCopyPackagePath_pressed(self):
if self.lineEditPackagePath.text() != "":
pyperclip.copy(self.lineEditPackagePath.text())
# self.statusBar.showMessage("Conan package path is copied to clipboard!", 2000)

@Slot()
def on_btnOpenCachePath_pressed(self):
Expand Down Expand Up @@ -152,6 +148,53 @@ def on_toolButtonSortDescending_clicked(self):

self.ctrl_treeview_conan_recipe.sort_descending()

@Slot()
def on_toolButtonRemoveRecipe_clicked(self):
recipe_id = self.ctrl_treeview_conan_recipe.get_selected_item()
if recipe_id is not None:
reply = QtWidgets.QMessageBox.question(self, f"Delete Recipe",
f"Are you sure to delete the recipe '{recipe_id}'",
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
QtWidgets.QMessageBox.No)

if reply == QtWidgets.QMessageBox.Yes:
self.ctrl_treeview_conan_recipe.remove_recipe(recipe_id)

# Refiltered if the filter is applied
# During removing process the filter was reseted to empty, now apply the filter again cover the user
# experience. This is kinda of workaround.
self.ctrl_treeview_conan_recipe.filter(self.lineEditSearchRecipe.text())

self.ctrl_treeview_conan_recipe_inspect.initialize()

self.ctrl_listview_conan_package.clear()
self.ctrl_treeview_conan_package_inspect.initialize()



@Slot()
def on_toolButtonRemovePackage_clicked(self):
package_id = self.ctrl_listview_conan_package.get_selected_item()
if package_id is not None:
recipe_id = self.ctrl_treeview_conan_recipe.get_selected_item()

reply = QtWidgets.QMessageBox.question(self, f"Delete Package - {recipe_id}",
f"Are you sure to delete the package {package_id}",
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
QtWidgets.QMessageBox.No)

if reply == QtWidgets.QMessageBox.Yes:
self.ctrl_listview_conan_package.remove_selected_package(recipe_id)
self.ctrl_treeview_conan_package_inspect.initialize()
self.refresh()

@Slot()
def on_toolButtonRefresh_clicked(self):
self.refresh()

def refresh(self):
# TODO: Implement the refresh function and the button
pass
self.ctrl_treeview_conan_recipe.update()

self.ctrl_treeview_conan_recipe_inspect.initialize()
self.ctrl_listview_conan_package.clear()
self.ctrl_treeview_conan_package_inspect.initialize()

0 comments on commit 29977d2

Please sign in to comment.