Skip to content

Commit

Permalink
Show read-only advanced command properties for internal commands
Browse files Browse the repository at this point in the history
This is helpful so that the command itself can be copied.
  • Loading branch information
hluk committed Mar 3, 2024
1 parent 54a648d commit 1667e0c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/gui/commandedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ bool CommandEdit::isEmpty() const
return ui->plainTextEditCommand->document()->characterCount() == 0;
}

void CommandEdit::setReadOnly(bool readOnly)
{
ui->plainTextEditCommand->setReadOnly(readOnly);
}

void CommandEdit::onPlainTextEditCommandTextChanged()
{
// TODO: Highlight syntax errors!
Expand Down
2 changes: 2 additions & 0 deletions src/gui/commandedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class CommandEdit final : public QWidget

bool isEmpty() const;

void setReadOnly(bool readOnly);

signals:
void changed();
void commandTextChanged(const QString &command);
Expand Down
12 changes: 6 additions & 6 deletions src/gui/commandwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,11 @@ Command CommandWidget::command() const
void CommandWidget::setCommand(const Command &c)
{
m_internalId = c.internalId;
m_isEditable = m_internalId.startsWith(QLatin1String("copyq_"));
const bool isEditable = !m_internalId.startsWith(QLatin1String("copyq_"));

ui->lineEditName->setReadOnly(m_isEditable);
ui->scrollAreaWidgetContents->setEnabled(isEditable);
ui->commandEdit->setReadOnly(!isEditable);
ui->lineEditName->setReadOnly(!isEditable);
ui->lineEditName->setText(c.name);
ui->lineEditMatch->setText( c.re.pattern() );
ui->lineEditWindow->setText( c.wndre.pattern() );
Expand Down Expand Up @@ -251,10 +253,8 @@ void CommandWidget::updateWidgets()

void CommandWidget::updateShowAdvanced()
{
const bool canEditAdvanced = m_showAdvanced && !m_isEditable;
ui->widgetCommandType->setVisible(canEditAdvanced);
ui->tabWidget->setVisible(canEditAdvanced);

ui->widgetCommandType->setVisible(m_showAdvanced);
ui->tabWidget->setVisible(m_showAdvanced);
ui->labelDescription->setVisible(m_showAdvanced);

// Hide the Advanced tab if there are no visible widgets.
Expand Down
1 change: 0 additions & 1 deletion src/gui/commandwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class CommandWidget final : public QWidget
Ui::CommandWidget *ui;
bool m_showAdvanced = true;
QString m_internalId;
bool m_isEditable = true;
};

#endif // COMMANDWIDGET_H

0 comments on commit 1667e0c

Please sign in to comment.