Browse Source

The entrybox is remade to be more general and easy to use. Search code to new entrybox will be finished next commit.

merge-requests/365/head
eidheim 11 years ago
parent
commit
bd42aca5b6
  1. 4
      juci/CMakeLists.txt
  2. 22
      juci/entry.h
  3. 47
      juci/entrybox.cc
  4. 42
      juci/entrybox.h
  5. 66
      juci/notebook.cc
  6. 4
      juci/notebook.h
  7. 2
      juci/selectiondialog.cc
  8. 13
      juci/window.cc

4
juci/CMakeLists.txt

@ -117,8 +117,8 @@ add_executable(${project_name}
api.cc
notebook.cc
notebook.h
entry.h
entry.cc
entrybox.h
entrybox.cc
directories.h
directories.cc
terminal.h

22
juci/entry.h

@ -1,22 +0,0 @@
#ifndef JUCI_ENTRY_H_
#define JUCI_ENTRY_H_
#include <iostream>
#include <functional>
#include "gtkmm.h"
class Entry: public Gtk::Box {
public:
Entry();
void show_set_filename();
void show_search(const std::string& current);
void hide();
std::string operator()();
Gtk::Entry entry;
Gtk::Button button_apply_set_filename, button_close, button_next, button_prev;
private:
bool on_key_press(GdkEventKey* key);
std::function<void()> activate;
};
#endif // JUCI_ENTRY_H_

47
juci/entry.cc → juci/entrybox.cc

@ -1,6 +1,47 @@
#include "entry.h"
#include "entrybox.h"
Entry::Entry() :
namespace sigc {
SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE
}
EntryBox::Entry::Entry(const std::string& content, std::function<void(const std::string& content)> on_activate, unsigned length) : Gtk::Entry(), on_activate(on_activate) {
set_max_length(length);
set_text(content);
signal_activate().connect([this](){
if(this->on_activate)
this->on_activate(get_text());
});
}
EntryBox::Button::Button(const std::string& label, std::function<void()> on_activate) : Gtk::Button(label), on_activate(on_activate) {
signal_clicked().connect([this](){
if(this->on_activate)
this->on_activate();
});
}
EntryBox::EntryBox() : Gtk::Box(Gtk::ORIENTATION_HORIZONTAL) {}
void EntryBox::clear() {
hide();
entries.clear();
buttons.clear();
}
void EntryBox::show() {
for(auto& entry: entries) {
pack_start(entry, Gtk::PACK_SHRINK);
}
for(auto& button: buttons)
pack_start(button, Gtk::PACK_SHRINK);
show_all();
if(entries.size()>0) {
entries.begin()->grab_focus();
entries.begin()->select_region(0, entries.begin()->get_text_length());
}
}
/*Entry::Entry() :
Gtk::Box(Gtk::ORIENTATION_HORIZONTAL),
button_apply_set_filename(Gtk::Stock::APPLY),
button_close(Gtk::Stock::CLOSE),
@ -58,4 +99,4 @@ void Entry::hide() {
std::string Entry::operator()() {
return entry.get_text();
}
}*/

42
juci/entrybox.h

@ -0,0 +1,42 @@
#ifndef JUCI_ENTRYBOX_H_
#define JUCI_ENTRYBOX_H_
#include <list>
#include <functional>
#include "gtkmm.h"
class EntryBox : public Gtk::Box {
public:
class Entry : public Gtk::Entry {
public:
Entry(const std::string& content="", std::function<void(const std::string& content)> on_activate=nullptr, unsigned length=50);
std::function<void(const std::string& content)> on_activate;
};
class Button : public Gtk::Button {
public:
Button(const std::string& label, std::function<void()> on_activate=nullptr);
std::function<void()> on_activate;
};
public:
EntryBox();
void clear();
void show();
std::list<Entry> entries;
std::list<Button> buttons;
};
/*class Entry: public Gtk::Box {
public:
Entry();
void show_set_filename();
void show_search(const std::string& current);
void hide();
std::string operator()();
Gtk::Entry entry;
Gtk::Button button_apply_set_filename, button_close, button_next, button_prev;
private:
bool on_key_press(GdkEventKey* key);
std::function<void()> activate;
};*/
#endif // JUCI_ENTRYBOX_H_

66
juci/notebook.cc

@ -4,9 +4,6 @@
#include "singletons.h"
#include <gtksourceview/gtksource.h> // c-library
#include <iostream> //TODO: remove
using namespace std; //TODO: remove
Notebook::View::View() {
pack2(notebook);
set_position(120);
@ -19,6 +16,10 @@ Notebook::Controller::Controller() :
clipboard = Gtk::Clipboard::get();
view.pack1(directories.widget(), true, true);
CreateKeybindings();
entry_box.signal_hide().connect([this]() {
if(CurrentPage()!=-1)
CurrentSourceView()->grab_focus();
});
INFO("Notebook Controller Success");
} // Constructor
@ -37,7 +38,7 @@ void Notebook::Controller::CreateKeybindings() {
OnCloseCurrentPage();
});
menu->action_group->add(Gtk::Action::create("EditFind", "Find"), Gtk::AccelKey(menu->key_map["edit_find"]), [this]() {
entry.show_search("");
//entry_box.show_search("");
});
menu->action_group->add(Gtk::Action::create("EditCopy", "Copy"), Gtk::AccelKey(menu->key_map["edit_copy"]), [this]() {
if (Pages() != 0) {
@ -95,8 +96,8 @@ void Notebook::Controller::CreateKeybindings() {
}
});
entry.button_apply_set_filename.signal_clicked().connect([this]() {
std::string filename=entry();
/*entry_box.button_apply_set_filename.signal_clicked().connect([this]() {
std::string filename=entry_box();
if(filename!="") {
if(project_path!="" && !boost::filesystem::path(filename).is_absolute())
filename=project_path+"/"+filename;
@ -117,23 +118,23 @@ void Notebook::Controller::CreateKeybindings() {
f.close();
}
}
entry.hide();
});
entry.button_close.signal_clicked().
entry_box.hide();
});*/
/*entry_box.button_close.signal_clicked().
connect(
[this]() {
entry.hide();
entry_box.hide();
});
entry.button_next.signal_clicked().
entry_box.button_next.signal_clicked().
connect(
[this]() {
search(true);
});
entry.button_prev.signal_clicked().
entry_box.button_prev.signal_clicked().
connect(
[this]() {
search(false);
});
});*/
INFO("Notebook signal handlers sucsess");
}
@ -183,7 +184,40 @@ void Notebook::Controller::OnCloseCurrentPage() {
}
}
void Notebook::Controller::OnFileNewFile() {
entry.show_set_filename();
entry_box.clear();
entry_box.entries.emplace_back("untitled", [this](const std::string& content){
std::string filename=content;
if(filename!="") {
if(project_path!="" && !boost::filesystem::path(filename).is_absolute())
filename=project_path+"/"+filename;
boost::filesystem::path p(filename);
if(boost::filesystem::exists(p)) {
Singleton::terminal()->print("Error: "+p.string()+" already exists.\n");
}
else {
std::ofstream f(p.string().c_str());
if(f) {
open_file(boost::filesystem::canonical(p).string());
Singleton::terminal()->print("New file "+p.string()+" created.\n");
if(project_path!="")
directories.open_folder(project_path); //TODO: Do refresh instead
}
else {
Singleton::terminal()->print("Error: could not create new file "+p.string()+".\n");
}
f.close();
}
}
entry_box.hide();
});
auto entry_it=entry_box.entries.begin();
entry_box.buttons.emplace_back("Create file", [this, entry_it](){
entry_it->activate();
});
entry_box.buttons.emplace_back("Cancel", [this](){
entry_box.hide();
});
entry_box.show();
}
void Notebook::Controller::search(bool forward) {
@ -193,8 +227,8 @@ void Notebook::Controller::search(bool forward) {
// fetch buffer and greate settings
auto buffer = CurrentSourceView()->get_source_buffer();
auto settings = gtk_source_search_settings_new();
// get search text from entry
gtk_source_search_settings_set_search_text(settings, entry().c_str());
// get search text from entry_box
//gtk_source_search_settings_set_search_text(settings, entry_box().c_str());
// make sure the search continues
gtk_source_search_settings_set_wrap_around(settings, true);
auto context = gtk_source_search_context_new(buffer->gobj(), settings);

4
juci/notebook.h

@ -3,7 +3,7 @@
#include <iostream>
#include "gtkmm.h"
#include "entry.h"
#include "entrybox.h"
#include "source.h"
#include "directories.h"
#include <boost/algorithm/string/case_conv.hpp>
@ -36,7 +36,7 @@ namespace Notebook {
std::string OnSaveFileAs();
std::string project_path;
Directories::Controller directories; //Todo: make private after creating open_directory()
Entry entry;
EntryBox entry_box;
std::vector<std::unique_ptr<Source> > source_views;
private:
void CreateKeybindings();

2
juci/selectiondialog.cc

@ -373,5 +373,7 @@ bool CompletionDialog::on_key_press(GdkEventKey* key) {
return true;
}
hide();
if(key->keyval==GDK_KEY_Escape)
return true;
return false;
}

13
juci/window.cc

@ -2,6 +2,10 @@
#include "logging.h"
#include "singletons.h"
namespace sigc {
SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE
}
Window::Window() :
window_box_(Gtk::ORIENTATION_VERTICAL) {
INFO("Create Window");
@ -69,12 +73,19 @@ Window::Window() :
window_box_.pack_start(menu->get_widget(), Gtk::PACK_SHRINK);
window_box_.pack_start(Singleton::notebook()->entry, Gtk::PACK_SHRINK);
window_box_.pack_start(Singleton::notebook()->entry_box, Gtk::PACK_SHRINK);
paned_.set_position(300);
paned_.pack1(Singleton::notebook()->view, true, false);
paned_.pack2(Singleton::terminal()->view, true, true);
window_box_.pack_end(paned_);
show_all_children();
signal_key_press_event().connect([this](GdkEventKey* key) {
if(key->keyval==GDK_KEY_Escape)
Singleton::notebook()->entry_box.hide();
return false;
});
INFO("Window created");
} // Window constructor

Loading…
Cancel
Save