Show icon in external editor button when disabled

This commit is contained in:
Lawrence Lee
2023-08-05 10:11:54 -07:00
parent 7ad414aa63
commit c82369843e
3 changed files with 26 additions and 2 deletions

View File

@@ -904,6 +904,7 @@ EditorPanel::EditorPanel (FilePanel* filePanel)
send_to_external = Gtk::manage(new PopUpButton("", false)); send_to_external = Gtk::manage(new PopUpButton("", false));
send_to_external->set_tooltip_text(M("MAIN_BUTTON_SENDTOEDITOR_TOOLTIP")); send_to_external->set_tooltip_text(M("MAIN_BUTTON_SENDTOEDITOR_TOOLTIP"));
send_to_external->setEmptyImage("palette-brush.png");
setExpandAlignProperties(send_to_external->buttonGroup, false, false, Gtk::ALIGN_CENTER, Gtk::ALIGN_FILL); setExpandAlignProperties(send_to_external->buttonGroup, false, false, Gtk::ALIGN_CENTER, Gtk::ALIGN_FILL);
updateExternalEditorWidget( updateExternalEditorWidget(
options.externalEditorIndex >= 0 ? options.externalEditorIndex : options.externalEditors.size(), options.externalEditorIndex >= 0 ? options.externalEditorIndex : options.externalEditors.size(),

View File

@@ -136,6 +136,21 @@ bool PopUpCommon::insertEntryImpl(int position, const Glib::ustring& fileName, c
return true; return true;
} }
void PopUpCommon::setEmptyImage(const Glib::ustring &fileName)
{
emptyImageFilename = fileName;
if (getEntryCount()) {
return;
}
if (fileName.empty()) {
buttonImage->hide();
} else {
changeImage(emptyImageFilename, Glib::RefPtr<const Gio::Icon>());
buttonImage->show();
}
}
void PopUpCommon::removeEntry(int position) void PopUpCommon::removeEntry(int position)
{ {
if (position < 0 || position >= getEntryCount()) { if (position < 0 || position >= getEntryCount()) {
@@ -147,8 +162,13 @@ void PopUpCommon::removeEntry(int position)
button->get_style_context()->remove_class("Left"); button->get_style_context()->remove_class("Left");
arrowButton->hide(); arrowButton->hide();
hasMenu = false; hasMenu = false;
// Remove the button image. if (emptyImageFilename.empty()) {
buttonImage->hide(); // Remove the button image.
buttonImage->hide();
} else {
// Show the empty icon.
changeImage(emptyImageFilename, Glib::RefPtr<const Gio::Icon>());
}
selected = -1; selected = -1;
} }
else if (position < selected) { else if (position < selected) {

View File

@@ -64,6 +64,8 @@ public:
bool addEntry (const Glib::ustring& fileName, const Glib::ustring& label, Gtk::RadioButtonGroup* radioGroup = nullptr); bool addEntry (const Glib::ustring& fileName, const Glib::ustring& label, Gtk::RadioButtonGroup* radioGroup = nullptr);
bool insertEntry(int position, const Glib::ustring& fileName, const Glib::ustring& label, Gtk::RadioButtonGroup* radioGroup = nullptr); bool insertEntry(int position, const Glib::ustring& fileName, const Glib::ustring& label, Gtk::RadioButtonGroup* radioGroup = nullptr);
bool insertEntry(int position, const Glib::RefPtr<const Gio::Icon>& gIcon, const Glib::ustring& label, Gtk::RadioButtonGroup* radioGroup = nullptr); bool insertEntry(int position, const Glib::RefPtr<const Gio::Icon>& gIcon, const Glib::ustring& label, Gtk::RadioButtonGroup* radioGroup = nullptr);
/// Sets the button image to show when there are no entries.
void setEmptyImage(const Glib::ustring &fileName);
int getEntryCount () const; int getEntryCount () const;
bool setSelected (int entryNum); bool setSelected (int entryNum);
int getSelected () const; int getSelected () const;
@@ -77,6 +79,7 @@ private:
type_signal_changed messageChanged; type_signal_changed messageChanged;
type_signal_item_selected messageItemSelected; type_signal_item_selected messageItemSelected;
Glib::ustring emptyImageFilename;
std::vector<Glib::RefPtr<const Gio::Icon>> imageIcons; std::vector<Glib::RefPtr<const Gio::Icon>> imageIcons;
std::vector<Glib::ustring> imageFilenames; std::vector<Glib::ustring> imageFilenames;
std::vector<const RTImage*> images; std::vector<const RTImage*> images;