Re-enable search in gtk133

This commit is contained in:
daleclack 2022-07-06 16:06:50 +08:00
parent 20c06e5f66
commit fe34b0a13c
6 changed files with 164 additions and 34 deletions

View File

@ -0,0 +1,3 @@
{
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools"
}

View File

@ -31,7 +31,7 @@ set(SOURCE_FILE src/main.cc src/TextEditor.cc)
#Compile Resource #Compile Resource
set(RESOURCE_LIST set(RESOURCE_LIST
searchbar.ui texteditor.ui
text_menu.xml) text_menu.xml)
compile_gresources(RESOURCE_FILE compile_gresources(RESOURCE_FILE

View File

@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkImage" id="image1">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="icon-name">edit-find</property>
</object>
<object class="GtkPopover" id="popover1">
<property name="can-focus">False</property>
<child>
<placeholder/>
</child>
</object>
<object class="GtkApplicationWindow" id="editor_win">
<property name="can-focus">False</property>
<child>
<object class="GtkBox" id="main_box">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkSearchBar" id="searchbar">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="show-close-button">True</property>
<child>
<object class="GtkSearchEntry" id="searchentry">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="primary-icon-name">edit-find-symbolic</property>
<property name="primary-icon-activatable">False</property>
<property name="primary-icon-sensitive">False</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
<child type="titlebar">
<object class="GtkHeaderBar" id="header">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="title" translatable="yes">Simple Text Editor</property>
<property name="show-close-button">True</property>
<property name="decoration-layout">close,minimize,maximize:menu</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<placeholder/>
</child>
<child>
<object class="GtkToggleButton" id="searchbtn">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="image">image1</property>
<property name="always-show-image">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkMenuButton" id="editor_menu">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="focus-on-click">False</property>
<property name="receives-default">True</property>
<property name="popover">popover1</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="icon-name">open-menu</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="pack-type">end</property>
</packing>
</child>
</object>
</child>
</object>
</interface>

View File

@ -5,30 +5,38 @@
// Only for build in this repository // Only for build in this repository
#define text_globs supported_globs #define text_globs supported_globs
TextEditor::TextEditor() TextEditor::TextEditor(BaseObjectType *cobject,const Glib::RefPtr<Gtk::Builder> &ref_builder)
:vbox(Gtk::ORIENTATION_VERTICAL,5), :Gtk::ApplicationWindow(cobject),
hbox(Gtk::ORIENTATION_HORIZONTAL,5) main_builder(ref_builder)
{ {
//Initalize Window //Initalize Window
set_default_size(800,450); // set_default_size(800,450);
set_icon_name("my_textedit"); // set_icon_name("my_textedit");
//Initalize HeaderBar //Initalize HeaderBar
header.set_decoration_layout("close,minimize,maximize:menu"); // header.set_decoration_layout("close,minimize,maximize:menu");
header.set_show_close_button(); // header.set_show_close_button();
menubtn.set_image_from_icon_name("open-menu"); // menubtn.set_image_from_icon_name("open-menu");
search_button.set_image_from_icon_name("find"); // search_button.set_image_from_icon_name("find");
header.pack_end(menubtn); // header.pack_end(menubtn);
header.pack_end(search_button); // header.pack_end(search_button);
header.set_title("Simple Text Editor"); // header.set_title("Simple Text Editor");
set_titlebar(header); // set_titlebar(header);
// Get Widgets
main_builder->get_widget("popover1",popover);
main_builder->get_widget("searchbar",searchbar);
main_builder->get_widget("searchentry",search_entry);
main_builder->get_widget("searchbtn",search_button);
//Add a menu //Add a menu
menu_builder = Gtk::Builder::create_from_resource("/org/gtk/daleclack/text_menu.xml"); menu_builder = Gtk::Builder::create_from_resource("/org/gtk/daleclack/text_menu.xml");
auto object = menu_builder->get_object("text_menu"); auto object = menu_builder->get_object("text_menu");
auto gmenu = Glib::RefPtr<Gio::Menu>::cast_dynamic(object); auto gmenu = Glib::RefPtr<Gio::Menu>::cast_dynamic(object);
popover.bind_model(gmenu); popover->bind_model(gmenu);
menubtn.set_popover(popover); // menubtn.set_popover(*popover);
m_binding = Glib::Binding::bind_property(search_button->property_active(),searchbar->property_search_mode_enabled(),Glib::BINDING_BIDIRECTIONAL);
//Initalize Text Buffers //Initalize Text Buffers
buffer1=textview1.get_buffer(); buffer1=textview1.get_buffer();
@ -47,14 +55,14 @@ hbox(Gtk::ORIENTATION_HORIZONTAL,5)
add_action("text_clear",sigc::mem_fun(*this,&TextEditor::btnclear_clicked)); add_action("text_clear",sigc::mem_fun(*this,&TextEditor::btnclear_clicked));
//Add searchbar //Add searchbar
searchbar_builder = Gtk::Builder::create_from_resource("/org/gtk/daleclack/searchbar.ui"); // searchbar_builder = Gtk::Builder::create_from_resource("/org/gtk/daleclack/searchbar.ui");
searchbar_builder->get_widget("searchbar",searchbar); // searchbar_builder->get_widget("searchbar",searchbar);
searchbar_builder->get_widget("searchentry",search_entry); // searchbar_builder->get_widget("searchentry",search_entry);
searchbar_builder->get_widget("search_box",searchbox); // searchbar_builder->get_widget("search_box",searchbox);
Glib::Binding::bind_property(search_button.property_active(), // Glib::Binding::bind_property(search_button.property_active(),
searchbar->property_search_mode_enabled(), // searchbar->property_search_mode_enabled(),
Glib::BINDING_BIDIRECTIONAL); // Glib::BINDING_BIDIRECTIONAL);
vbox.pack_start(*searchbox); // vbox.pack_start(*searchbox);
//A InfoBar //A InfoBar
infobar.add_button("OK",Gtk::RESPONSE_OK); infobar.add_button("OK",Gtk::RESPONSE_OK);
@ -65,7 +73,7 @@ hbox(Gtk::ORIENTATION_HORIZONTAL,5)
//Show everything //Show everything
vbox.pack_start(hbox); vbox.pack_start(hbox);
add(vbox); // add(vbox);
show_all_children(); show_all_children();
infobar.hide(); infobar.hide();
} }
@ -205,3 +213,11 @@ void TextEditor::btnclear_clicked(){
void TextEditor::infobar_response(int response){ void TextEditor::infobar_response(int response){
infobar.hide(); infobar.hide();
} }
TextEditor * TextEditor::create(){
auto builder = Gtk::Builder::create_from_resource("/org/gtk/daleclack/texteditor.ui");
TextEditor *win = nullptr;
builder->get_widget_derived("editor_win",win);
return win;
}

View File

@ -4,17 +4,19 @@
class TextEditor : public Gtk::ApplicationWindow{ class TextEditor : public Gtk::ApplicationWindow{
public: public:
TextEditor(); TextEditor(BaseObjectType *cobject,const Glib::RefPtr<Gtk::Builder> &ref_builder);
static TextEditor * create();
private: private:
//Header widgets //Header widgets
Gtk::HeaderBar header; // Gtk::HeaderBar header;
Gtk::MenuButton menubtn; // Gtk::MenuButton menubtn;
Gtk::Popover popover; Gtk::Popover *popover;
Gtk::ToggleButton search_button; Gtk::ToggleButton *search_button;
Gtk::SearchBar *searchbar; Gtk::SearchBar *searchbar;
Gtk::SearchEntry *search_entry; Gtk::SearchEntry *search_entry;
Glib::RefPtr<Gtk::Builder> menu_builder, searchbar_builder; Glib::RefPtr<Gtk::Builder> menu_builder, main_builder;
Gtk::Box *searchbox; Glib::RefPtr<Glib::Binding> m_binding;
// Gtk::Box *searchbox;
//Window widgets //Window widgets
Gtk::Box vbox,hbox,*infobox; Gtk::Box vbox,hbox,*infobox;

View File

@ -2,6 +2,6 @@
int main(int argc,char **argv){ int main(int argc,char **argv){
auto app = Gtk::Application::create(argc,argv,"org.gtk.daleclack"); auto app = Gtk::Application::create(argc,argv,"org.gtk.daleclack");
TextEditor textwin; auto textwin = TextEditor::create();
return app->run(textwin); return app->run(*textwin);
} }