diff --git a/juci/config.json b/juci/config.json index e4ff1f5..e4ab5e7 100644 --- a/juci/config.json +++ b/juci/config.json @@ -23,7 +23,8 @@ "new_h_file": "h", "new_cc_file": "c", "close_tab": "w", - "open_folder": "o" + "open_folder": "o", + "save_as": "s" }, "directoryfilter": { "ignore": [ diff --git a/juci/menu.xml b/juci/menu.xml index 930c460..e5ad384 100644 --- a/juci/menu.xml +++ b/juci/menu.xml @@ -7,7 +7,8 @@ - + + diff --git a/juci/notebook.cc b/juci/notebook.cc index 695591b..0e11dbb 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -1,4 +1,6 @@ #include "notebook.h" +#include + Notebook::Model::Model() { cc_extension_ = ".cc"; @@ -18,9 +20,11 @@ Notebook::Controller::Controller(Keybindings::Controller& keybindings, directories_(dir_cfg) { OnNewPage("juCi++"); refClipboard_ = Gtk::Clipboard::get(); - view().pack1(directories_.widget(), true, true); - CreateKeybindings(keybindings); - } // Constructor + ispopup = false; + view().pack1(directories_.widget(),true,true); + CreateKeybindings(keybindings); +}// Constructor + void Notebook::Controller::CreateKeybindings(Keybindings::Controller &keybindings) { @@ -93,13 +97,7 @@ void Notebook::Controller::CreateKeybindings(Keybindings::Controller [this]() { OnEditPaste(); }); - keybindings.action_group_hidden()-> - add(Gtk::Action::create("EditPaste", - Gtk::Stock::PASTE), - [this]() { - OnEditPaste(); - }); - entry_.view_.entry().signal_activate(). + entry_.view_.entry().signal_activate(). connect( [this]() { if (is_new_file_) { @@ -132,53 +130,57 @@ void Notebook::Controller::CreateKeybindings(Keybindings::Controller }); } -void Notebook::Controller::GeneratePopup(std::vector items) { +bool Notebook::Controller:: OnMouseRelease(GdkEventButton* button){ + if(button->button == 1 && ispopup){ + popup_.response(Gtk::RESPONSE_DELETE_EVENT); + return true; + } + return false; +} + +bool Notebook::Controller::GeneratePopup(Gtk::Window* window){ + // Get function to fill popup with suggests item vector under is for testing + std::vector items; + items.push_back("toString(std::string& string) -> void"); + items.push_back("toLower(std::string& string) -> void"); + items.push_back("toUpper(std::string& string) -> void"); + items.push_back("fuckOFF(const std::string string) -> bool"); + items.push_back("fuckOFF(const std::string string) -> bool"); + items.push_back("toString(std::string& string) -> void"); + items.push_back("toLower(std::string& string) -> void"); + items.push_back("toUpper(std::string& string) -> void"); + items.push_back("fuckOFF(const std::string string) -> bool"); + items.push_back("fuckOFF(const std::string string) -> bool"); + + // Replace over with get suggestions from zalox! OVER IS JUST FOR TESTING + Gtk::ScrolledWindow popup_scroll_; - Gtk::ListViewText listview_(1, false, Gtk::SelectionMode::SELECTION_SINGLE); - Gtk::Dialog popup_("", true); + Gtk::ListViewText listview_(1,false,Gtk::SelectionMode::SELECTION_SINGLE); + + popup_scroll_.set_policy(Gtk::PolicyType::POLICY_NEVER, + Gtk::PolicyType::POLICY_NEVER); listview_.set_enable_search(false); + listview_.set_headers_visible(false); listview_.set_hscroll_policy(Gtk::ScrollablePolicy::SCROLL_NATURAL); listview_.set_activate_on_single_click(true); - listview_.signal_row_activated(). - connect([this, &listview_, &popup_](const Gtk::TreeModel::Path& path, - Gtk::TreeViewColumn*) { - std::string t = listview_.get_text(listview_.get_selected()[0]); - CurrentTextView().get_buffer()->insert_at_cursor(t); - popup_.response(Gtk::RESPONSE_DELETE_EVENT); - }); for (auto &i : items) listview_.append(i); - listview_.set_headers_visible(false); - popup_scroll_.add(listview_); + popup_scroll_.add(listview_); popup_.get_vbox()->pack_start(popup_scroll_); - popup_.set_size_request(80, 80); + popup_.set_transient_for(*window); popup_.show_all(); - Gdk::Rectangle temp1, temp2; - CurrentTextView(). - get_cursor_locations( - CurrentTextView(). - get_buffer()->get_insert()-> - get_iter(), temp1, temp2); - - - int x = temp1.get_x(); - int y = temp1.get_y(); - text_vec_.at(CurrentPage())-> - view().buffer_to_window_coords( - Gtk::TextWindowType::TEXT_WINDOW_WIDGET, - temp2.get_x(), - temp2.get_y(), - x, y); - - - int widht = Notebook().get_width()-88; - int height = Notebook().get_height()-180; - if (x > widht) { - x = widht; } - if (y > height) { - y = height; - } - popup_.move(x, y+88); + + int popup_x = popup_.get_width(); + int popup_y = items.size()*20; + PopupSetSize(popup_scroll_,popup_x,popup_y); + int x,y; + FindPopupPosition(CurrentTextView(),popup_x,popup_y,x,y); + popup_.move(x, y+15); + PopupSelectHandler(popup_, listview_); + ispopup = true; popup_.run(); + popup_.hide(); + ispopup = false; + return true; } bool Notebook::Controller::ScrollEventCallback(GdkEventScroll* scroll_event) { @@ -251,7 +253,7 @@ void Notebook::Controller::OnCreatePage() { linenumbers_vec_.back()->view().set_sensitive(false); editor_vec_.back()->pack_start(*scrolledline_vec_.back(), false, false); editor_vec_.back()->pack_start(*scrolledtext_vec_.back(), true, true); - BufferChangeHandler(text_vec_.back()->view().get_buffer()); + TextViewHandlers(text_vec_.back()->view()); } void Notebook::Controller::OnCloseCurrentPage() { @@ -382,22 +384,6 @@ void Notebook::Controller::OnBufferChange() { ScrollEventCallback(scroll); delete scroll; } - Gtk::TextIter start, end; - std::string word; - start = Buffer(text_vec_.at(page))->get_insert()->get_iter(); - end = Buffer(text_vec_.at(page))->get_insert()->get_iter(); - start.backward_char(); - word = Buffer(text_vec_.at(page))->get_text(start, end); - if (word == ".") { - // TODO(Forgie) Zalox,Forgie) Remove TEST - std::vector TEST; - TEST.push_back("toString()"); - TEST.push_back("toLower()"); - TEST.push_back("toUpper()"); - TEST.push_back("fuckOFF()"); - TEST.push_back("fuckOFF()"); - GeneratePopup(TEST); - } } void Notebook::Controller ::OnDirectoryNavigation(const Gtk::TreeModel::Path& path, @@ -440,11 +426,88 @@ Gtk::Notebook& Notebook::Controller::Notebook() { return view_.notebook(); } -void Notebook::Controller::BufferChangeHandler(Glib::RefPtr - buffer) { - buffer->signal_changed().connect( - [this]() { - OnBufferChange(); - }); +void Notebook::Controller::TextViewHandlers(Gtk::TextView& textview) { + textview.get_buffer()->signal_changed().connect( + [this]() { + OnBufferChange(); + }); + + textview.signal_button_release_event(). + connect(sigc::mem_fun(*this,&Notebook::Controller::OnMouseRelease),false); +} +void Notebook::Controller::PopupSelectHandler(Gtk::Dialog &popup, + Gtk::ListViewText &listview){ + listview.signal_row_activated(). + connect([this, &listview, &popup](const Gtk::TreeModel::Path& path, + Gtk::TreeViewColumn*) { + std::string selected = + listview.get_text(listview.get_selected()[0]); + CurrentTextView().get_buffer()->insert_at_cursor(selected); + popup.response(Gtk::RESPONSE_DELETE_EVENT); + }); +} +void Notebook::Controller::PopupSetSize(Gtk::ScrolledWindow &scroll, + int ¤t_x, + int ¤t_y) { + int textview_x = CurrentTextView().get_width(); + int textview_y = 150; + bool is_never_scroll_x = true; + bool is_never_scroll_y = true; + if (current_x > textview_x) { + current_x = textview_x; + is_never_scroll_x = false; + } + if (current_y > textview_y) { + current_y = textview_y; + is_never_scroll_y = false; + } + scroll.set_size_request(current_x,current_y); + if (!is_never_scroll_x && !is_never_scroll_y) { + scroll.set_policy(Gtk::PolicyType::POLICY_AUTOMATIC, + Gtk::PolicyType::POLICY_AUTOMATIC); + } else if (!is_never_scroll_x && is_never_scroll_y) { + scroll.set_policy(Gtk::PolicyType::POLICY_AUTOMATIC, + Gtk::PolicyType::POLICY_NEVER); + } else if (is_never_scroll_x && !is_never_scroll_y) { + scroll.set_policy(Gtk::PolicyType::POLICY_NEVER, + Gtk::PolicyType::POLICY_AUTOMATIC); + } +} + +void Notebook::Controller::FindPopupPosition(Gtk::TextView& textview, + int popup_x, + int popup_y, + int &x, + int &y){ + Gdk::Rectangle temp1, temp2; + textview.get_cursor_locations( + CurrentTextView(). + get_buffer()->get_insert()-> + get_iter(), temp1,temp2); + int textview_edge_x = 0; + int textview_edge_y = 0; + textview.buffer_to_window_coords( + Gtk::TextWindowType::TEXT_WINDOW_WIDGET, + temp1.get_x(), + temp1.get_y(), + x, y); + Glib::RefPtr gdkw = + CurrentTextView().get_window(Gtk::TextWindowType::TEXT_WINDOW_WIDGET); + gdkw->get_origin(textview_edge_x, textview_edge_y); + + x+=textview_edge_x; + y+=textview_edge_y; + if ((textview_edge_x-x)*-1 > textview.get_width()-popup_x) { + x -= popup_x; + } + if ((textview_edge_y-y)*-1 > textview.get_height()-popup_y) { + y -= (popup_y+14) + 15; + } } +void Notebook::Controller:: OnSaveFile(std::string path){ + std::ofstream file; + file.open (path); + file << CurrentTextView().get_buffer()->get_text(); + file.close(); +} diff --git a/juci/notebook.h b/juci/notebook.h index 4a657fe..35c9a13 100644 --- a/juci/notebook.h +++ b/juci/notebook.h @@ -49,6 +49,7 @@ namespace Notebook { void OnFileNewEmptyfile(); void OnFileNewHeaderFile(); void OnFileOpenFolder(); + void OnSaveFile(std::string path); void OnDirectoryNavigation(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column); void OnNewPage(std::string name); @@ -56,21 +57,26 @@ namespace Notebook { void OnCreatePage(); bool ScrollEventCallback(GdkEventScroll* scroll_event); int Pages(); - - Directories::Controller& directories() { return directories_; } + Directories::Controller& directories() { return directories_; } Gtk::Paned& view(); - - void GeneratePopup(std::vector items); - // Gtk::HBox& view(); - + bool GeneratePopup(Gtk::Window* window); void Search(bool forward); const Source::Config& source_config() { return source_config_; } - + bool OnMouseRelease(GdkEventButton* button); protected: - void BufferChangeHandler(Glib::RefPtr buffer); - - private: + void TextViewHandlers(Gtk::TextView& textview); + void PopupSelectHandler(Gtk::Dialog &popup, + Gtk::ListViewText &listview); + private: void CreateKeybindings(Keybindings::Controller& keybindings); + void FindPopupPosition(Gtk::TextView& textview, + int popup_x, + int popup_y, + int &x, + int &y); + void PopupSetSize(Gtk::ScrolledWindow& scroll, + int ¤t_x, + int ¤t_y); Glib::RefPtr m_refBuilder; Glib::RefPtr refActionGroup; Source::Config source_config_; @@ -86,6 +92,8 @@ namespace Notebook { Gtk::TextIter search_match_end_; Gtk::TextIter search_match_start_; Glib::RefPtr refClipboard_; + bool ispopup; + Gtk::Dialog popup_; }; // class controller } // namespace Notebook #endif // JUCI_NOTEBOOK_H_ diff --git a/juci/terminal.cc b/juci/terminal.cc index 001cc29..d81ff11 100644 --- a/juci/terminal.cc +++ b/juci/terminal.cc @@ -1,9 +1,70 @@ #include "terminal.h" +#include Terminal::View::View(){ - textview_.add(buffer_); - view_.add(textview_); + scrolledwindow_.add(textview_); + scrolledwindow_.set_size_request(-1,150); + view_.add(scrolledwindow_); +} + + +Terminal::Controller::Controller() { + root = ""; + Terminal().signal_key_release_event(). + connect(sigc::mem_fun(*this,&Terminal::Controller::OnButtonRealeaseEvenet),false); +} + +bool Terminal::Controller::OnButtonRealeaseEvenet(GdkEventKey *key) { + if(key->keyval == 65421 || key->keyval == 65293){ + ExecuteCommand(); + } + return false; +} +void Terminal::Controller::ExecuteCommand() { + + std::cout << "EXECUTE COMMAND ALGORITHM "<< std::endl; + std::string temp = getCommand(); + if(temp != ""){ + std::cout << "EXECUTE COMMAND: "<insert(Terminal().get_buffer()->end(),"Command Failed\n"); + + } else{ + char buffer[1028]; + + while (fgets(buffer, 1028, p) != NULL) + { + Terminal().get_buffer()->insert(Terminal().get_buffer()->end(),buffer); + } + pclose(p); + + + } + Terminal().get_buffer()->insert(Terminal().get_buffer()->end(),"Command Executed\n"); + }else{ + std::cout << "NO COMMAND TO RUN"<< std::endl; + } + +} + +std::string Terminal::Controller::getCommand(){ + std::string command = ""; + Gtk::TextIter start,end; + int a = Terminal().get_buffer()->get_insert()->get_iter().get_line()-1; + if(a==-1)a=0; + start = Terminal().get_buffer()->get_iter_at_line(a); + end =Terminal().get_buffer()->get_iter_at_line(a); + while(!end.ends_line()) { + end++; + } + while(!start.starts_line()) { + start--; + } + + command = Terminal().get_buffer()->get_text(start,end); + return command; } - diff --git a/juci/terminal.h b/juci/terminal.h index c4bb4c9..d91876c 100644 --- a/juci/terminal.h +++ b/juci/terminal.h @@ -1,8 +1,6 @@ - -#ifndef JUCI_NOTEBOOK_H_ -#define JUCI_NOTEBOOK_H_ +#ifndef JUCI_TERMINAL_H_ +#define JUCI_TERMINAL_H_ -#include #include "gtkmm.h" namespace Terminal { @@ -11,18 +9,27 @@ namespace Terminal { public: View(); Gtk::HBox& view() {return view_;} + Gtk::TextView& textview() {return textview_;} private: Gtk::HBox view_; - Glib::RefPtr buffer_; Gtk::TextView textview_; + Gtk::ScrolledWindow scrolledwindow_; }; // class view - class Controller { + class Controller { public: - + Controller(); + Gtk::HBox& view() {return view_.view();} + Gtk::TextView& Terminal(){return view_.textview();} + private: + void ExecuteCommand(); + std::string getCommand(); + bool OnButtonRealeaseEvenet(GdkEventKey* key); + Terminal::View view_; + std::string root; }; // class controller } // namespace Terminal -#endif // JUCI_NOTEBOOK_H_ +#endif // JUCI_TERMINAL_H_ diff --git a/juci/window.cc b/juci/window.cc index 1097e52..cf6e5c6 100644 --- a/juci/window.cc +++ b/juci/window.cc @@ -26,6 +26,22 @@ Window::Window() : [this]() { OnFileOpenFolder(); }); + + keybindings_.action_group_menu()->add(Gtk::Action::create("FileSaveAs", + "Save as"), + Gtk::AccelKey(keybindings_.config_ + .key_map()["save_as"]), + [this]() { + OnSaveFileAs(); + }); + + notebook_.CurrentTextView().signal_key_release_event(). + connect(sigc::mem_fun(*this,&Window::OnKeyRelease),false); + this->signal_button_release_event(). + connect(sigc::mem_fun(*this,&Window::OnMouseRelease),false); + terminal_.Terminal().signal_button_release_event(). + connect(sigc::mem_fun(*this,&Window::OnMouseRelease),false); + PluginApi::menu_ = &menu_; PluginApi::notebook_ = ¬ebook_; PluginApi::InitPlugins(); @@ -37,6 +53,7 @@ Window::Window() : window_box_.pack_start(menu_.view(), Gtk::PACK_SHRINK); window_box_.pack_start(notebook_.entry_view(), Gtk::PACK_SHRINK); window_box_.pack_start(notebook_.view()); + window_box_.pack_end(terminal_.view(),Gtk::PACK_SHRINK); show_all_children(); } // Window constructor @@ -112,6 +129,7 @@ void Window::OnOpenFile() { case(Gtk::RESPONSE_OK): { std::cout << "Open clicked." << std::endl; std::string path = dialog.get_filename(); + std::cout << "File selected: " << path << std::endl; notebook_.OnOpenFile(path); break; @@ -126,3 +144,38 @@ void Window::OnOpenFile() { } } } +void Window::OnSaveFileAs(){ + Gtk::FileChooserDialog dialog("Please choose a file", + Gtk::FILE_CHOOSER_ACTION_SAVE); + dialog.set_transient_for(*this); + dialog.set_position(Gtk::WindowPosition::WIN_POS_CENTER_ALWAYS); + dialog.add_button("_Cancel", Gtk::RESPONSE_CANCEL); + dialog.add_button("_Save", Gtk::RESPONSE_OK); + int result = dialog.run(); + switch (result) { + case(Gtk::RESPONSE_OK): { + std::string path = dialog.get_filename(); + unsigned pos = path.find_last_of("/\\"); + std::cout << path<< std::endl; + notebook_.OnSaveFile(path); + break; + } + case(Gtk::RESPONSE_CANCEL): { + break; + } + default: { + std::cout << "Unexpected button clicked." << std::endl; + break; + } + } +} +bool Window::OnKeyRelease(GdkEventKey* key){ + if(key->keyval==46){ + return notebook_.GeneratePopup(this); + } + return false; +} +bool Window::OnMouseRelease(GdkEventButton *button){ + return notebook_.OnMouseRelease(button); +} + diff --git a/juci/window.h b/juci/window.h index a0b810f..88297da 100644 --- a/juci/window.h +++ b/juci/window.h @@ -3,6 +3,7 @@ #include "api.h" #include "config.h" +#include "terminal.h" #include @@ -19,8 +20,7 @@ public: Keybindings::Controller keybindings_; Menu::Controller menu_; Notebook::Controller notebook_; - - + Terminal::Controller terminal_; Keybindings::Controller& keybindings() { return keybindings_; } private: @@ -28,6 +28,9 @@ public: void OnWindowHide(); void OnOpenFile(); void OnFileOpenFolder(); + void OnSaveFileAs(); + bool OnKeyRelease(GdkEventKey* key); + bool OnMouseRelease(GdkEventButton* button); };