mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
Qt: generic add_copy_menu method for MyTreeView lists
This commit is contained in:
parent
0a6ac7c61a
commit
c721e880d0
7 changed files with 21 additions and 36 deletions
|
@ -217,20 +217,13 @@ class AddressList(MyTreeView):
|
||||||
idx = self.indexAt(position)
|
idx = self.indexAt(position)
|
||||||
if not idx.isValid():
|
if not idx.isValid():
|
||||||
return
|
return
|
||||||
col = idx.column()
|
|
||||||
item = self.model().itemFromIndex(idx)
|
item = self.model().itemFromIndex(idx)
|
||||||
if not item:
|
if not item:
|
||||||
return
|
return
|
||||||
addr = addrs[0]
|
addr = addrs[0]
|
||||||
|
|
||||||
addr_column_title = self.model().horizontalHeaderItem(self.Columns.LABEL).text()
|
addr_column_title = self.model().horizontalHeaderItem(self.Columns.LABEL).text()
|
||||||
addr_idx = idx.sibling(idx.row(), self.Columns.LABEL)
|
addr_idx = idx.sibling(idx.row(), self.Columns.LABEL)
|
||||||
|
self.add_copy_menu(menu, idx)
|
||||||
column_title = self.model().horizontalHeaderItem(col).text()
|
|
||||||
copy_text = self.model().itemFromIndex(idx).text()
|
|
||||||
if col == self.Columns.COIN_BALANCE or col == self.Columns.FIAT_BALANCE:
|
|
||||||
copy_text = copy_text.strip()
|
|
||||||
menu.addAction(_("Copy {}").format(column_title), lambda: self.place_text_on_clipboard(copy_text))
|
|
||||||
menu.addAction(_('Details'), lambda: self.parent.show_address(addr))
|
menu.addAction(_('Details'), lambda: self.parent.show_address(addr))
|
||||||
persistent = QPersistentModelIndex(addr_idx)
|
persistent = QPersistentModelIndex(addr_idx)
|
||||||
menu.addAction(_("Edit {}").format(addr_column_title), lambda p=persistent: self.edit(QModelIndex(p)))
|
menu.addAction(_("Edit {}").format(addr_column_title), lambda p=persistent: self.edit(QModelIndex(p)))
|
||||||
|
|
|
@ -103,6 +103,7 @@ class ChannelsList(MyTreeView):
|
||||||
channel_id = idx.sibling(idx.row(), self.Columns.NODE_ID).data(ROLE_CHANNEL_ID)
|
channel_id = idx.sibling(idx.row(), self.Columns.NODE_ID).data(ROLE_CHANNEL_ID)
|
||||||
chan = self.lnworker.channels[channel_id]
|
chan = self.lnworker.channels[channel_id]
|
||||||
menu.addAction(_("Details..."), lambda: self.details(channel_id))
|
menu.addAction(_("Details..."), lambda: self.details(channel_id))
|
||||||
|
self.add_copy_menu(menu, idx)
|
||||||
if not chan.is_closed():
|
if not chan.is_closed():
|
||||||
menu.addAction(_("Close channel"), lambda: self.close_channel(channel_id))
|
menu.addAction(_("Close channel"), lambda: self.close_channel(channel_id))
|
||||||
menu.addAction(_("Force-close channel"), lambda: self.force_close(channel_id))
|
menu.addAction(_("Force-close channel"), lambda: self.force_close(channel_id))
|
||||||
|
|
|
@ -589,6 +589,14 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
|
||||||
label = self.wallet.get_label(tx_hash) or None # prefer 'None' if not defined (force tx dialog to hide Description field if missing)
|
label = self.wallet.get_label(tx_hash) or None # prefer 'None' if not defined (force tx dialog to hide Description field if missing)
|
||||||
self.parent.show_transaction(tx, label)
|
self.parent.show_transaction(tx, label)
|
||||||
|
|
||||||
|
def add_copy_menu(self, menu, idx):
|
||||||
|
cc = menu.addMenu(_("Copy column"))
|
||||||
|
for column in HistoryColumns:
|
||||||
|
column_title = self.hm.headerData(column, Qt.Horizontal, Qt.DisplayRole)
|
||||||
|
idx2 = idx.sibling(idx.row(), column)
|
||||||
|
column_data = (self.hm.data(idx2, Qt.DisplayRole).value() or '').strip()
|
||||||
|
cc.addAction(column_title, lambda t=column_data: self.parent.app.clipboard().setText(t))
|
||||||
|
|
||||||
def create_menu(self, position: QPoint):
|
def create_menu(self, position: QPoint):
|
||||||
org_idx: QModelIndex = self.indexAt(position)
|
org_idx: QModelIndex = self.indexAt(position)
|
||||||
idx = self.proxy.mapToSource(org_idx)
|
idx = self.proxy.mapToSource(org_idx)
|
||||||
|
@ -596,9 +604,6 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
|
||||||
# can happen e.g. before list is populated for the first time
|
# can happen e.g. before list is populated for the first time
|
||||||
return
|
return
|
||||||
tx_item = self.hm.transactions.value_from_pos(idx.row())
|
tx_item = self.hm.transactions.value_from_pos(idx.row())
|
||||||
column = idx.column()
|
|
||||||
column_title = self.hm.headerData(column, Qt.Horizontal, Qt.DisplayRole)
|
|
||||||
column_data = self.hm.data(idx, Qt.DisplayRole).value()
|
|
||||||
if tx_item.get('lightning'):
|
if tx_item.get('lightning'):
|
||||||
return
|
return
|
||||||
tx_hash = tx_item['txid']
|
tx_hash = tx_item['txid']
|
||||||
|
@ -614,12 +619,7 @@ class HistoryList(MyTreeView, AcceptFileDragDrop):
|
||||||
if height in [TX_HEIGHT_FUTURE, TX_HEIGHT_LOCAL]:
|
if height in [TX_HEIGHT_FUTURE, TX_HEIGHT_LOCAL]:
|
||||||
menu.addAction(_("Remove"), lambda: self.remove_local_tx(tx_hash))
|
menu.addAction(_("Remove"), lambda: self.remove_local_tx(tx_hash))
|
||||||
menu.addAction(_("Copy Transaction ID"), lambda: self.parent.app.clipboard().setText(tx_hash))
|
menu.addAction(_("Copy Transaction ID"), lambda: self.parent.app.clipboard().setText(tx_hash))
|
||||||
|
self.add_copy_menu(menu, idx)
|
||||||
amount_columns = [HistoryColumns.AMOUNT, HistoryColumns.BALANCE,
|
|
||||||
HistoryColumns.FIAT_VALUE, HistoryColumns.FIAT_ACQ_PRICE, HistoryColumns.FIAT_CAP_GAINS]
|
|
||||||
if column in amount_columns:
|
|
||||||
column_data = column_data.strip()
|
|
||||||
menu.addAction(_("Copy {}").format(column_title), lambda: self.parent.app.clipboard().setText(column_data))
|
|
||||||
for c in self.editable_columns:
|
for c in self.editable_columns:
|
||||||
if self.isColumnHidden(c): continue
|
if self.isColumnHidden(c): continue
|
||||||
label = self.hm.headerData(c, Qt.Horizontal, Qt.DisplayRole)
|
label = self.hm.headerData(c, Qt.Horizontal, Qt.DisplayRole)
|
||||||
|
|
|
@ -151,14 +151,8 @@ class InvoiceList(MyTreeView):
|
||||||
return
|
return
|
||||||
key = item_col0.data(ROLE_REQUEST_ID)
|
key = item_col0.data(ROLE_REQUEST_ID)
|
||||||
request_type = item_col0.data(ROLE_REQUEST_TYPE)
|
request_type = item_col0.data(ROLE_REQUEST_TYPE)
|
||||||
column = idx.column()
|
|
||||||
column_title = self.model().horizontalHeaderItem(column).text()
|
|
||||||
column_data = item.text()
|
|
||||||
menu = QMenu(self)
|
menu = QMenu(self)
|
||||||
if column_data:
|
self.add_copy_menu(menu, idx)
|
||||||
if column == self.Columns.AMOUNT:
|
|
||||||
column_data = column_data.strip()
|
|
||||||
menu.addAction(_("Copy {}").format(column_title), lambda: self.parent.app.clipboard().setText(column_data))
|
|
||||||
invoice = self.parent.wallet.get_invoice(key)
|
invoice = self.parent.wallet.get_invoice(key)
|
||||||
menu.addAction(_("Details"), lambda: self.parent.show_invoice(key))
|
menu.addAction(_("Details"), lambda: self.parent.show_invoice(key))
|
||||||
if invoice['status'] == PR_UNPAID:
|
if invoice['status'] == PR_UNPAID:
|
||||||
|
|
|
@ -165,13 +165,8 @@ class RequestList(MyTreeView):
|
||||||
if req is None:
|
if req is None:
|
||||||
self.update()
|
self.update()
|
||||||
return
|
return
|
||||||
column = idx.column()
|
|
||||||
column_title = self.model().horizontalHeaderItem(column).text()
|
|
||||||
column_data = self.model().itemFromIndex(idx).text()
|
|
||||||
menu = QMenu(self)
|
menu = QMenu(self)
|
||||||
if column == self.Columns.AMOUNT:
|
self.add_copy_menu(menu, idx)
|
||||||
column_data = column_data.strip()
|
|
||||||
menu.addAction(_("Copy {}").format(column_title), lambda: self.parent.do_copy(column_title, column_data))
|
|
||||||
if request_type == PR_TYPE_LN:
|
if request_type == PR_TYPE_LN:
|
||||||
menu.addAction(_("Copy Request"), lambda: self.parent.do_copy('Lightning Request', req['invoice']))
|
menu.addAction(_("Copy Request"), lambda: self.parent.do_copy('Lightning Request', req['invoice']))
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -626,6 +626,13 @@ class MyTreeView(QTreeView):
|
||||||
def toggle_toolbar(self, config=None):
|
def toggle_toolbar(self, config=None):
|
||||||
self.show_toolbar(not self.toolbar_shown, config)
|
self.show_toolbar(not self.toolbar_shown, config)
|
||||||
|
|
||||||
|
def add_copy_menu(self, menu, idx):
|
||||||
|
cc = menu.addMenu(_("Copy column"))
|
||||||
|
for column in self.Columns:
|
||||||
|
column_title = self.model().horizontalHeaderItem(column).text()
|
||||||
|
item_col = self.model().itemFromIndex(idx.sibling(idx.row(), column))
|
||||||
|
column_data = item_col.text().strip()
|
||||||
|
cc.addAction(column_title, lambda t=column_data: self.parent.app.clipboard().setText(t))
|
||||||
|
|
||||||
class ButtonsWidget(QWidget):
|
class ButtonsWidget(QWidget):
|
||||||
|
|
||||||
|
|
|
@ -126,12 +126,7 @@ class UTXOList(MyTreeView):
|
||||||
idx = self.indexAt(position)
|
idx = self.indexAt(position)
|
||||||
if not idx.isValid():
|
if not idx.isValid():
|
||||||
return
|
return
|
||||||
col = idx.column()
|
self.add_copy_menu(menu, idx)
|
||||||
column_title = self.model().horizontalHeaderItem(col).text()
|
|
||||||
copy_text = self.model().itemFromIndex(idx).text() if col != self.Columns.OUTPOINT else selected[0]
|
|
||||||
if col == self.Columns.AMOUNT:
|
|
||||||
copy_text = copy_text.strip()
|
|
||||||
menu.addAction(_("Copy {}").format(column_title), lambda: self.parent.app.clipboard().setText(copy_text))
|
|
||||||
# "Freeze coin"
|
# "Freeze coin"
|
||||||
if not self.wallet.is_frozen_coin(utxo_dict):
|
if not self.wallet.is_frozen_coin(utxo_dict):
|
||||||
menu.addAction(_("Freeze Coin"), lambda: self.parent.set_frozen_state_of_coins([utxo_dict], True))
|
menu.addAction(_("Freeze Coin"), lambda: self.parent.set_frozen_state_of_coins([utxo_dict], True))
|
||||||
|
|
Loading…
Add table
Reference in a new issue