Skip to content

Commit

Permalink
Hypertext 0.1.0 is ready with basic functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
thelinuxpoint committed Jan 21, 2022
1 parent c311943 commit e4f5f7b
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 42 deletions.
2 changes: 2 additions & 0 deletions src/component/hypertextapp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ void hyp::HypTextApp::on_startup(){
" <item>"
" <attribute name='label' translatable='yes'>Save _As</attribute>"
" <attribute name='action'>win.saveas</attribute>"
" <attribute name='accel'>&lt;ctrl&gt;&lt;shift&gt;s</attribute>"

" </item>"
" <item>"
" <attribute name='label' translatable='yes'>New _Window</attribute>"
Expand Down
18 changes: 10 additions & 8 deletions src/component/hyptextview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,18 @@ hyp::HypTextView::HypTextView(std::string name,std::string path,Gtk::Label *labe

bool hyp::HypTextView::on_key_press_event(GdkEventKey* key_event)
{
std::string x = Glib::file_get_contents(this->path);


this->View::on_key_press_event(key_event);

if(x != get_buffer()->get_text()){
l->set_label(this->file_name+" *");
}else{
l->set_label(this->file_name);

if (this->path != ""){
std::string x = Glib::file_get_contents(this->path);

if(x != get_buffer()->get_text()){
l->set_label(this->file_name+" *");
}else{
l->set_label(this->file_name);
}
}

return true;
}

Expand Down
154 changes: 120 additions & 34 deletions src/component/hypwindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ hyp::HypWindow::HypWindow(): Gtk::ApplicationWindow(), m_Box(Gtk::ORIENTATION_VE

add_action("save", sigc::mem_fun(*this, &hyp::HypWindow::on_save));

add_action("saveas", sigc::mem_fun(*this, &hyp::HypWindow::on_save_as));


//###########################################################################

Expand Down Expand Up @@ -167,27 +169,32 @@ hyp::HypWindow::HypWindow(): Gtk::ApplicationWindow(), m_Box(Gtk::ORIENTATION_VE
void hyp::HypWindow::insert_tab(){

std::cout<<"Inserting Tab -> Empty"<<std::endl;
Gtk::Label *d = new Gtk::Label("untitled");
vec_text.push_back(hyp::HypTextView("untitled","",d,count));

Gtk::Box *box = Gtk::manage(new Gtk::Box());
Gtk::Label *d = Gtk::manage(new Gtk::Label("untitled"));
Gtk::Button *but = Gtk::manage(new Gtk::Button());
vec_scroll.push_back(Gtk::ScrolledWindow());
vec_scroll[count].add(vec_text[count]);
//
Gtk::Box *box = new Gtk::Box();
Gtk::Button *but = new Gtk::Button();

but->signal_clicked().connect( sigc::bind(sigc::mem_fun(*this,&hyp::HypWindow::on_tab_closed),count,vec_text[count].path));
vec_text[count].set_show_line_numbers(true);
vec_text[count].set_monospace(true);


but->set_image_from_icon_name("window-close");
but->set_relief(Gtk::RELIEF_NONE);
box->pack_start(*d,true,true,2);
box->pack_end(*but,false,false,0);
box->show_all();

vec_text.push_back(hyp::HypTextView("untitled","",d,count));
but->signal_clicked().connect( sigc::bind(sigc::mem_fun(*this,&hyp::HypWindow::on_tab_closed),count,vec_text[count].path));

nb.append_page(vec_scroll[count],*box);
vec_scroll[count].add(vec_text[count-icount]);

vec_text[count-icount].set_show_line_numbers(true);
vec_text[count-icount].set_monospace(true);

but->signal_clicked().connect( sigc::bind(sigc::mem_fun(*this,&hyp::HypWindow::on_tab_closed),count,vec_text[count-icount].path));
// nb.append_page(vec_scroll[count-icount],*box);
nb.append_page(vec_scroll[count],*box);
(*text_track)[count]=(count-icount);
(*types)[count]="text";


tracker.insert(count);
count+=1;
Expand Down Expand Up @@ -234,36 +241,52 @@ void hyp::HypWindow::on_file_open(){
std::cout<<dialog->get_filename()<<std::endl;
std::cout<<"------------------------"<<std::endl;

std::string file = dialog->get_filename();

Gtk::Label *d = Gtk::manage(new Gtk::Label(std::filesystem::path(dialog->get_filename()).filename().string()));
vec_text.push_back(hyp::HypTextView(std::filesystem::path(dialog->get_filename()).filename(),dialog->get_filename(),d,count));
Gtk::Box *box = Gtk::manage(new Gtk::Box());
Gtk::Label *d = Gtk::manage(new Gtk::Label(std::filesystem::path(file).filename().string()));
Gtk::Button *but = Gtk::manage(new Gtk::Button());
vec_scroll.push_back(Gtk::ScrolledWindow());
// (vec_text[count].buffer)->set_text(Glib::file_get_contents(dialog->get_filename()));


vec_scroll[count].add(vec_text[count]);
//
Gtk::Box *box = new Gtk::Box();
Gtk::Button *but = new Gtk::Button();

but->signal_clicked().connect( sigc::bind(sigc::mem_fun(*this,&hyp::HypWindow::on_tab_closed),count,vec_text[count].path));
vec_text[count].set_show_line_numbers(true);
vec_text[count].set_monospace(true);


but->set_image_from_icon_name("window-close");
but->set_relief(Gtk::RELIEF_NONE);
box->pack_start(*d,true,true,2);
box->pack_end(*but,false,false,0);
box->show_all();

nb.append_page(vec_scroll[count],*box);
if(std::filesystem::path(file).filename().extension().string()==".png" or std::filesystem::path(file).filename().extension().string()==".jpg" or std::filesystem::path(file).filename().extension().string()==".jpeg" or std::filesystem::path(file).filename().extension().string()==".gif"){

vec_imge.push_back(hyp::HypImgView(std::filesystem::path(file).filename(),file,count));
but->signal_clicked().connect( sigc::bind(sigc::mem_fun(*this,&hyp::HypWindow::on_tab_closed),count,vec_imge[icount].path));
vec_scroll[count].add(vec_imge[icount]);

nb.append_page(vec_scroll[count],*box);
(*types)[count]="image";
(*img_track)[count]=icount;
icount+=1;

}else{

vec_text.push_back(hyp::HypTextView(std::filesystem::path(file).filename(),file,d,count));
vec_scroll[count].add(vec_text[count-icount]);
vec_text[count-icount].set_show_line_numbers(true);
vec_text[count-icount].set_monospace(true);
but->signal_clicked().connect( sigc::bind(sigc::mem_fun(*this,&hyp::HypWindow::on_tab_closed),count,vec_text[count-icount].path));
// nb.append_page(vec_scroll[count-icount],*box);
nb.append_page(vec_scroll[count],*box);
(*text_track)[count]=(count-icount);

(*types)[count]="text";
}

// (vec_text[count].buffer)->set_text(Glib::file_get_contents(file));
// (vec_text[count].buffer)->set_modified();

tracker.insert(count);
count+=1;

show_all();

}
//###############################################################################
/* activates when the tree column is clicked
Expand Down Expand Up @@ -380,9 +403,8 @@ void hyp::HypWindow::notify(){
*
*/
void hyp::HypWindow::on_save(){
// std::cout<<nb.get_current_page()<<std::endl;

auto itrs = tracker.begin();
// auto itre = tracker.find(page_number);
auto value=0;

for (std::set<int>::iterator i = tracker.begin(); i != tracker.end(); ++i){
Expand All @@ -392,14 +414,78 @@ void hyp::HypWindow::on_save(){
}
}
if ((*types)[value] != "image"){
std::cout<<"Saving ~> "<<vec_text[(*text_track)[value]].path<<std::endl;
Glib::file_set_contents(vec_text[(*text_track)[value]].path,vec_text[(*text_track)[value]].get_buffer()->get_text());
vec_text[(*text_track)[value]].l->set_label(vec_text[(*text_track)[value]].file_name);
// vec_text[(*text_track)[value]].get_buffer().get_text();
if (vec_text[(*text_track)[value]].path == ""){

start:

auto dialog = Gtk::FileChooserNative::create("Save New File",*this,Gtk::FILE_CHOOSER_ACTION_SAVE,"Save","Cancel");
dialog->run();

if (dialog->get_filename() == ""){ goto end; }

if(Glib::file_test(dialog->get_filename(), Glib::FileTest::FILE_TEST_EXISTS)){
Gtk::MessageDialog dialog(*this, "File Already Exists");
dialog.set_secondary_text("The file name you entered is currently present in the directory.");
dialog.run();
goto start;
}
vec_text[(*text_track)[value]].path = dialog->get_filename();
vec_text[(*text_track)[value]].file_name = std::filesystem::path(dialog->get_filename()).filename().string();
end:
std::cout<<"";
}
if(vec_text[(*text_track)[value]].path != ""){
std::cout<<"Saving ~> "<<vec_text[(*text_track)[value]].path<<std::endl;
Glib::file_set_contents(vec_text[(*text_track)[value]].path,vec_text[(*text_track)[value]].get_buffer()->get_text());
vec_text[(*text_track)[value]].l->set_label(vec_text[(*text_track)[value]].file_name);
}


}

}
//###############################################################################
/*
*
*
*
*/
void hyp::HypWindow::on_save_as(){

start:

auto dialog = Gtk::FileChooserNative::create("Save As",*this,Gtk::FILE_CHOOSER_ACTION_SAVE,"Save","Cancel");
dialog->run();
if (dialog->get_filename() == ""){ goto end; }

if(Glib::file_test(dialog->get_filename(), Glib::FileTest::FILE_TEST_EXISTS)){
Gtk::MessageDialog dialog(*this, "File Already Exists");
dialog.set_secondary_text("The file name you entered is currently present in the directory.");
dialog.run();
}else{
auto itrs = tracker.begin();
auto value=0;

for (std::set<int>::iterator i = tracker.begin(); i != tracker.end(); ++i){
if(std::distance(itrs,i)==nb.get_current_page()){
value = *i;
break;
}
}
if ((*types)[value] != "image"){
vec_text[(*text_track)[value]].path = dialog->get_filename();
vec_text[(*text_track)[value]].file_name = std::filesystem::path(dialog->get_filename()).filename().string();

std::cout<<"Saving as ~> "<<vec_text[(*text_track)[value]].path<<std::endl;
Glib::file_set_contents(vec_text[(*text_track)[value]].path,vec_text[(*text_track)[value]].get_buffer()->get_text());
vec_text[(*text_track)[value]].l->set_label(vec_text[(*text_track)[value]].file_name);
}

}
end:
std::cout<<"";
}

//###############################################################################
/* the function come in action when the "Open Folder" is clicked
*
Expand Down
2 changes: 2 additions & 0 deletions src/header/hypwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ namespace hyp{
//Signal handlers:
void on_save();

void on_save_as();

void on_menu_others();

void on_new_window();
Expand Down

0 comments on commit e4f5f7b

Please sign in to comment.