Browse Source

Made SelectionDialog more general, now receiving Gtk::TextView& instead. Minor cleanup in source.*.

merge-requests/365/head
eidheim 11 years ago
parent
commit
832ef8881c
  1. 16
      juci/selectiondialog.cc
  2. 4
      juci/selectiondialog.h
  3. 86
      juci/source.cc
  4. 23
      juci/source.h

16
juci/selectiondialog.cc

@ -1,6 +1,6 @@
#include "selectiondialog.h" #include "selectiondialog.h"
SelectionDialog::SelectionDialog(Source::View& view): Gtk::Dialog(), view(view), SelectionDialog::SelectionDialog(Gtk::TextView& text_view): Gtk::Dialog(), text_view(text_view),
list_view_text(1, false, Gtk::SelectionMode::SELECTION_SINGLE) { list_view_text(1, false, Gtk::SelectionMode::SELECTION_SINGLE) {
scrolled_window.set_policy(Gtk::PolicyType::POLICY_NEVER, Gtk::PolicyType::POLICY_NEVER); scrolled_window.set_policy(Gtk::PolicyType::POLICY_NEVER, Gtk::PolicyType::POLICY_NEVER);
list_view_text.set_enable_search(true); list_view_text.set_enable_search(true);
@ -15,7 +15,7 @@ void SelectionDialog::show(const std::map<std::string, std::string>& rows) {
} }
scrolled_window.add(list_view_text); scrolled_window.add(list_view_text);
get_vbox()->pack_start(scrolled_window); get_vbox()->pack_start(scrolled_window);
set_transient_for((Gtk::Window&)(*view.get_toplevel())); set_transient_for((Gtk::Window&)(*text_view.get_toplevel()));
show_all(); show_all();
int popup_x = get_width(); int popup_x = get_width();
int popup_y = rows.size() * 20; int popup_y = rows.size() * 20;
@ -39,7 +39,7 @@ bool SelectionDialog::close(GdkEventFocus*) {
void SelectionDialog::adjust(int current_x, int current_y) { void SelectionDialog::adjust(int current_x, int current_y) {
INFO("SelectionDialog set size"); INFO("SelectionDialog set size");
int view_x = view.get_width(); int view_x = text_view.get_width();
int view_y = 150; int view_y = 150;
bool is_never_scroll_x = true; bool is_never_scroll_x = true;
bool is_never_scroll_y = true; bool is_never_scroll_y = true;
@ -62,22 +62,22 @@ void SelectionDialog::adjust(int current_x, int current_y) {
INFO("SelectionDialog set position"); INFO("SelectionDialog set position");
Gdk::Rectangle temp1, temp2; Gdk::Rectangle temp1, temp2;
view.get_cursor_locations(view.get_source_buffer()->get_insert()->get_iter(), temp1, temp2); text_view.get_cursor_locations(text_view.get_buffer()->get_insert()->get_iter(), temp1, temp2);
int view_edge_x = 0; int view_edge_x = 0;
int view_edge_y = 0; int view_edge_y = 0;
int x, y; int x, y;
view.buffer_to_window_coords(Gtk::TextWindowType::TEXT_WINDOW_WIDGET, text_view.buffer_to_window_coords(Gtk::TextWindowType::TEXT_WINDOW_WIDGET,
temp1.get_x(), temp1.get_y(), x, y); temp1.get_x(), temp1.get_y(), x, y);
Glib::RefPtr<Gdk::Window> gdkw = view.get_window(Gtk::TextWindowType::TEXT_WINDOW_WIDGET); Glib::RefPtr<Gdk::Window> gdkw = text_view.get_window(Gtk::TextWindowType::TEXT_WINDOW_WIDGET);
gdkw->get_origin(view_edge_x, view_edge_y); gdkw->get_origin(view_edge_x, view_edge_y);
x += view_edge_x; x += view_edge_x;
y += view_edge_y; y += view_edge_y;
if ((view_edge_x-x)*-1 > view.get_width()-current_x) { if ((view_edge_x-x)*-1 > text_view.get_width()-current_x) {
x -= current_x; x -= current_x;
if (x < view_edge_x) x = view_edge_x; if (x < view_edge_x) x = view_edge_x;
} }
if ((view_edge_y-y)*-1 > view.get_height()-current_y) { if ((view_edge_y-y)*-1 > text_view.get_height()-current_y) {
y -= (current_y+14) + 15; y -= (current_y+14) + 15;
if (x < view_edge_y) y = view_edge_y +15; if (x < view_edge_y) y = view_edge_y +15;
} }

4
juci/selectiondialog.h

@ -4,7 +4,7 @@
class SelectionDialog : public Gtk::Dialog { class SelectionDialog : public Gtk::Dialog {
public: public:
SelectionDialog(Source::View& view); SelectionDialog(Gtk::TextView& text_view);
void show(const std::map<std::string, std::string>& rows); void show(const std::map<std::string, std::string>& rows);
bool close(GdkEventFocus*); bool close(GdkEventFocus*);
@ -13,7 +13,7 @@ public:
private: private:
void adjust(int current_x, int current_y); void adjust(int current_x, int current_y);
Source::View& view; Gtk::TextView& text_view;
Gtk::ScrolledWindow scrolled_window; Gtk::ScrolledWindow scrolled_window;
Gtk::ListViewText list_view_text; Gtk::ListViewText list_view_text;
}; };

86
juci/source.cc

@ -21,7 +21,7 @@ bool Source::Config::legal_extension(std::string e) const {
////////////// //////////////
//// View //// //// View ////
////////////// //////////////
Source::View::View(const Config& config, const std::string& file_path, const std::string& project_path): Source::View::View(const Source::Config& config, const std::string& file_path, const std::string& project_path):
config(config), file_path(file_path), project_path(project_path) { config(config), file_path(file_path), project_path(project_path) {
Gsv::init(); Gsv::init();
set_smart_home_end(Gsv::SMART_HOME_END_BEFORE); set_smart_home_end(Gsv::SMART_HOME_END_BEFORE);
@ -50,13 +50,52 @@ string Source::View::get_line_before_insert() {
return line; return line;
} }
bool Source::View::on_key_press(GdkEventKey* key) {
//Indent right when clicking tab, no matter where in the line the cursor is. Also works on selected text.
if(key->keyval==GDK_KEY_Tab && key->state==0) {
Gtk::TextIter selection_start, selection_end;
get_source_buffer()->get_selection_bounds(selection_start, selection_end);
int line_start=selection_start.get_line();
int line_end=selection_end.get_line();
for(int line=line_start;line<=line_end;line++) {
Gtk::TextIter line_it = get_source_buffer()->get_iter_at_line(line);
get_source_buffer()->insert(line_it, config.tab);
}
return true;
}
//Indent left when clicking shift-tab, no matter where in the line the cursor is. Also works on selected text.
else if((key->keyval==GDK_KEY_ISO_Left_Tab || key->keyval==GDK_KEY_Tab) && key->state==GDK_SHIFT_MASK) {
Gtk::TextIter selection_start, selection_end;
get_source_buffer()->get_selection_bounds(selection_start, selection_end);
int line_start=selection_start.get_line();
int line_end=selection_end.get_line();
for(int line_nr=line_start;line_nr<=line_end;line_nr++) {
string line=get_line(line_nr);
if(!(line.size()>=config.tab_size && line.substr(0, config.tab_size)==config.tab))
return true;
}
for(int line_nr=line_start;line_nr<=line_end;line_nr++) {
Gtk::TextIter line_it = get_source_buffer()->get_iter_at_line(line_nr);
Gtk::TextIter line_plus_it=line_it;
for(unsigned c=0;c<config.tab_size;c++)
line_plus_it++;
get_source_buffer()->erase(line_it, line_plus_it);
}
return true;
}
return false;
}
////////////////// //////////////////
//// ClangView /// //// ClangView ///
////////////////// //////////////////
clang::Index Source::ClangView::clang_index(0, 1); clang::Index Source::ClangView::clang_index(0, 1);
Source::ClangView::ClangView(const Config& config, const std::string& file_path, const std::string& project_path): Source::ClangView::ClangView(const Source::Config& config, const std::string& file_path, const std::string& project_path):
Source::View::View(config, file_path, project_path), Source::View(config, file_path, project_path),
parse_thread_go(true), parse_thread_mapped(false), parse_thread_stop(false) { parse_thread_go(true), parse_thread_mapped(false), parse_thread_stop(false) {
override_font(Pango::FontDescription(config.font)); override_font(Pango::FontDescription(config.font));
override_background_color(Gdk::RGBA(config.background)); override_background_color(Gdk::RGBA(config.background));
@ -410,41 +449,6 @@ bool Source::ClangView::on_key_press(GdkEventKey* key) {
} }
return true; return true;
} }
//Indent right when clicking tab, no matter where in the line the cursor is. Also works on selected text.
if(key->keyval==GDK_KEY_Tab && key->state==0) {
Gtk::TextIter selection_start, selection_end;
get_source_buffer()->get_selection_bounds(selection_start, selection_end);
int line_start=selection_start.get_line();
int line_end=selection_end.get_line();
for(int line=line_start;line<=line_end;line++) {
Gtk::TextIter line_it = get_source_buffer()->get_iter_at_line(line);
get_source_buffer()->insert(line_it, config.tab);
}
return true;
}
//Indent left when clicking shift-tab, no matter where in the line the cursor is. Also works on selected text.
else if((key->keyval==GDK_KEY_ISO_Left_Tab || key->keyval==GDK_KEY_Tab) && key->state==GDK_SHIFT_MASK) {
Gtk::TextIter selection_start, selection_end;
get_source_buffer()->get_selection_bounds(selection_start, selection_end);
int line_start=selection_start.get_line();
int line_end=selection_end.get_line();
for(int line_nr=line_start;line_nr<=line_end;line_nr++) {
string line=get_line(line_nr);
if(!(line.size()>=config.tab_size && line.substr(0, config.tab_size)==config.tab))
return true;
}
for(int line_nr=line_start;line_nr<=line_end;line_nr++) {
Gtk::TextIter line_it = get_source_buffer()->get_iter_at_line(line_nr);
Gtk::TextIter line_plus_it=line_it;
for(unsigned c=0;c<config.tab_size;c++)
line_plus_it++;
get_source_buffer()->erase(line_it, line_plus_it);
}
return true;
}
//Indent left when writing } on a new line //Indent left when writing } on a new line
else if(key->keyval==GDK_KEY_braceright) { else if(key->keyval==GDK_KEY_braceright) {
string line=get_line_before_insert(); string line=get_line_before_insert();
@ -479,7 +483,8 @@ bool Source::ClangView::on_key_press(GdkEventKey* key) {
} }
} }
} }
return false;
return Source::View::on_key_press(key);
} }
//////////////////// ////////////////////
@ -489,8 +494,7 @@ bool Source::ClangView::on_key_press(GdkEventKey* key) {
// Source::Controller::Controller() // Source::Controller::Controller()
// Constructor for Controller // Constructor for Controller
Source::Controller::Controller(const Source::Config &config, Source::Controller::Controller(const Source::Config &config,
const std::string& file_path, std::string project_path) : const std::string& file_path, std::string project_path) {
config(config) {
if(project_path=="") { if(project_path=="") {
project_path=boost::filesystem::path(file_path).parent_path().string(); project_path=boost::filesystem::path(file_path).parent_path().string();
} }

23
juci/source.h

@ -60,25 +60,31 @@ namespace Source {
class View : public Gsv::View { class View : public Gsv::View {
public: public:
View(const Config& config, const std::string& file_path, const std::string& project_path); View(const Source::Config& config, const std::string& file_path, const std::string& project_path);
std::string get_line(size_t line_number); std::string get_line(size_t line_number);
std::string get_line_before_insert(); std::string get_line_before_insert();
virtual std::vector<Source::AutoCompleteData> get_autocomplete_suggestions(int line_number, int column) {return std::vector<Source::AutoCompleteData>();}
std::string file_path; std::string file_path;
std::string project_path; std::string project_path;
protected: protected:
const Config& config; const Source::Config& config;
bool on_key_press(GdkEventKey* key);
}; // class View }; // class View
class GenericView : public View { class GenericView : public View {
public: public:
GenericView(const Config& config, const std::string& file_path, const std::string& project_path): GenericView(const Source::Config& config, const std::string& file_path, const std::string& project_path):
View(config, file_path, project_path) {} View(config, file_path, project_path) {
signal_key_press_event().connect(sigc::mem_fun(*this, &Source::GenericView::on_key_press), false);
}
private:
bool on_key_press(GdkEventKey* key) {
return Source::View::on_key_press(key);
}
}; };
class ClangView : public View { class ClangView : public View {
public: public:
ClangView(const Config& config, const std::string& file_path, const std::string& project_path); ClangView(const Source::Config& config, const std::string& file_path, const std::string& project_path);
~ClangView(); ~ClangView();
// inits the syntax highligthing on file open // inits the syntax highligthing on file open
void init_syntax_highlighting(const std::map<std::string, std::string> void init_syntax_highlighting(const std::map<std::string, std::string>
@ -123,10 +129,7 @@ namespace Source {
bool is_saved = true; bool is_saved = true;
std::unique_ptr<View> view; std::unique_ptr<Source::View> view;
private:
const Config& config;
}; // class Controller }; // class Controller
} // namespace Source } // namespace Source
#endif // JUCI_SOURCE_H_ #endif // JUCI_SOURCE_H_

Loading…
Cancel
Save