Browse Source

New right click context menu

features include rename, toggle comments, etc.
merge-requests/365/head
Jørgen Lien Sellæg 9 years ago
parent
commit
13c35a254f
  1. 2
      src/CMakeLists.txt
  2. 97
      src/menu.cc
  3. 6
      src/menu.h
  4. 15
      src/source.cc
  5. 3
      src/window.cc

2
src/CMakeLists.txt

@ -10,7 +10,6 @@ set(project_files
entrybox.cc entrybox.cc
info.cc info.cc
juci.cc juci.cc
menu.cc
notebook.cc notebook.cc
project.cc project.cc
selectiondialog.cc selectiondialog.cc
@ -27,6 +26,7 @@ set(project_shared_files
dispatcher.cc dispatcher.cc
filesystem.cc filesystem.cc
git.cc git.cc
menu.cc
meson.cc meson.cc
project_build.cc project_build.cc
source.cc source.cc

97
src/menu.cc

@ -3,9 +3,85 @@
#include <string> #include <string>
#include <iostream> #include <iostream>
Menu::Menu() { const Glib::ustring menu_xml= R"RAW(<interface>
ui_xml = R"RAW( <menu id='right-click-line-menu'>
<interface> <section>
<item>
<attribute name='label' translatable='yes'>_Undo</attribute>
<attribute name='action'>app.edit_undo</attribute>
</item>
<item>
<attribute name='label' translatable='yes'>_Redo</attribute>
<attribute name='action'>app.edit_redo</attribute>
</item>
</section>
<section>
<item>
<attribute name='label' translatable='yes'>_Paste</attribute>
<attribute name='action'>app.edit_paste</attribute>
</item>
</section>
<section>
<item>
<attribute name='label' translatable='yes'>_Reload _File</attribute>
<attribute name='action'>app.reload_file</attribute>
</item>
</section>
<section>
<item>
<attribute name='label' translatable='yes'>_Go _to _Declaration</attribute>
<attribute name='action'>app.source_goto_declaration</attribute>
</item>
<item>
<attribute name='label' translatable='yes'>_Go _to _Method</attribute>
<attribute name='action'>app.source_goto_method</attribute>
</item>
<item>
<attribute name='label' translatable='yes'>_Go _to _Usage</attribute>
<attribute name='action'>app.source_goto_usage</attribute>
</item>
<item>
<attribute name='label' translatable='yes'>_Rename</attribute>
<attribute name='action'>app.source_rename</attribute>
</item>
<item>
<attribute name='label' translatable='yes'>_Toggle _Line _Comment</attribute>
<attribute name='action'>app.source_comments_toggle</attribute>
</item>
</section>
</menu>
<menu id='right-click-selected-menu'>
<section>
<item>
<attribute name='label' translatable='yes'>_Undo</attribute>
<attribute name='action'>app.edit_undo</attribute>
</item>
<item>
<attribute name='label' translatable='yes'>_Redo</attribute>
<attribute name='action'>app.edit_redo</attribute>
</item>
</section>
<section>
<item>
<attribute name='label' translatable='yes'>_Cut</attribute>
<attribute name='action'>app.edit_cut</attribute>
</item>
<item>
<attribute name='label' translatable='yes'>_Copy</attribute>
<attribute name='action'>app.edit_copy</attribute>
</item>
<item>
<attribute name='label' translatable='yes'>_Paste</attribute>
<attribute name='action'>app.edit_paste</attribute>
</item>
</section>
<section>
<item>
<attribute name='label' translatable='yes'>_Toggle _Line _Comment</attribute>
<attribute name='action'>app.source_comments_toggle</attribute>
</item>
</section>
</menu>
<menu id='juci-menu'> <menu id='juci-menu'>
<section> <section>
<item> <item>
@ -378,7 +454,6 @@ Menu::Menu() {
</menu> </menu>
</interface> </interface>
)RAW"; )RAW";
}
void Menu::add_action(const std::string &name, std::function<void()> action) { void Menu::add_action(const std::string &name, std::function<void()> action) {
auto g_application=g_application_get_default(); auto g_application=g_application_get_default();
@ -400,14 +475,18 @@ void Menu::set_keys() {
} }
void Menu::build() { void Menu::build() {
builder = Gtk::Builder::create();
try { try {
builder->add_from_string(ui_xml); builder = Gtk::Builder::create_from_string(menu_xml);
auto object = Menu::get().builder->get_object("juci-menu"); auto object = builder->get_object("juci-menu");
juci_menu = Glib::RefPtr<Gio::Menu>::cast_dynamic(object); juci_menu = Glib::RefPtr<Gio::Menu>::cast_dynamic(object);
object = Menu::get().builder->get_object("window-menu"); object = builder->get_object("window-menu");
window_menu = Glib::RefPtr<Gio::Menu>::cast_dynamic(object); window_menu = Glib::RefPtr<Gio::Menu>::cast_dynamic(object);
object = builder->get_object("right-click-line-menu");
auto ptr = Glib::RefPtr<Gio::Menu>::cast_dynamic(object);
right_click_line_menu = std::make_unique<Gtk::Menu>(ptr);
object = builder->get_object("right-click-selected-menu");
ptr = Glib::RefPtr<Gio::Menu>::cast_dynamic(object);
right_click_selected_menu = std::make_unique<Gtk::Menu>(ptr);
} }
catch (const Glib::Error &ex) { catch (const Glib::Error &ex) {
std::cerr << "building menu failed: " << ex.what(); std::cerr << "building menu failed: " << ex.what();

6
src/menu.h

@ -6,8 +6,6 @@
#include <gtkmm.h> #include <gtkmm.h>
class Menu { class Menu {
private:
Menu();
public: public:
static Menu &get() { static Menu &get() {
static Menu singleton; static Menu singleton;
@ -22,9 +20,9 @@ public:
Glib::RefPtr<Gio::Menu> juci_menu; Glib::RefPtr<Gio::Menu> juci_menu;
Glib::RefPtr<Gio::Menu> window_menu; Glib::RefPtr<Gio::Menu> window_menu;
std::unique_ptr<Gtk::Menu> right_click_line_menu;
std::unique_ptr<Gtk::Menu> right_click_selected_menu;
private: private:
Glib::RefPtr<Gtk::Builder> builder; Glib::RefPtr<Gtk::Builder> builder;
std::string ui_xml;
}; };
#endif // JUCI_MENU_H_ #endif // JUCI_MENU_H_

15
src/source.cc

@ -4,6 +4,7 @@
#include "terminal.h" #include "terminal.h"
#include "info.h" #include "info.h"
#include "directories.h" #include "directories.h"
#include "menu.h"
#include <gtksourceview/gtksource.h> #include <gtksourceview/gtksource.h>
#include <boost/property_tree/json_parser.hpp> #include <boost/property_tree/json_parser.hpp>
#include <boost/spirit/home/qi/char.hpp> #include <boost/spirit/home/qi/char.hpp>
@ -2123,6 +2124,20 @@ bool Source::View::on_button_press_event(GdkEventButton *event) {
return true; return true;
} }
if((event->type == GDK_BUTTON_PRESS) && (event->button == 3)){
if(!get_buffer()->get_has_selection()){
int x,y;
window_to_buffer_coords(Gtk::TextWindowType::TEXT_WINDOW_TEXT,event->x,event->y,x,y);
Gtk::TextIter iter;
get_iter_at_location(iter,x,y);
if(iter)
get_buffer()->place_cursor(iter);
Menu::get().right_click_line_menu->popup(event->button,event->time);
} else {
Menu::get().right_click_selected_menu->popup(event->button,event->time);
}
return true;
}
return Gsv::View::on_button_press_event(event); return Gsv::View::on_button_press_event(event);
} }

3
src/window.cc

@ -32,6 +32,9 @@ Window::Window() {
configure(); configure();
activate_menu_items(); activate_menu_items();
Menu::get().right_click_line_menu->attach_to_widget(*this);
Menu::get().right_click_selected_menu->attach_to_widget(*this);
set_default_size(Config::get().window.default_size.first, Config::get().window.default_size.second); set_default_size(Config::get().window.default_size.first, Config::get().window.default_size.second);
auto directories_scrolled_window=Gtk::manage(new Gtk::ScrolledWindow()); auto directories_scrolled_window=Gtk::manage(new Gtk::ScrolledWindow());

Loading…
Cancel
Save