//******************************************************************* // QBtFileEditor CONSTRUCTOR //******************************************************************* QBtFileEditor::QBtFileEditor( QWidget* const in_parent, const QString& in_path ) : QDialog( in_parent ) , path_ ( QString() ) , editor_ ( new QTextEdit ) , reload_ ( new QPushButton( tr( RELOAD ) ) ) , save_ ( new QPushButton( tr( SAVE ) ) ) , cancel_ ( new QPushButton( tr( CANCEL ) ) ) { setWindowTitle( tr( CAPTION ) ); path_ = QFile::symLinkTarget( in_path ); if( path_.isEmpty() ) path_ = in_path; static const QString my_font = "Monospace,9,-1,5,50,0,0,0,0,0"; QFont fnt; fnt.fromString( my_font ); editor_->setFont( fnt ); QHBoxLayout* const btn_layout = new QHBoxLayout; btn_layout->addStretch(); btn_layout->addWidget( reload_ ); btn_layout->addWidget( save_ ); btn_layout->addWidget( cancel_ ); QVBoxLayout* const main_layout = new QVBoxLayout; main_layout->addWidget( editor_ ); main_layout->addLayout( btn_layout ); setLayout( main_layout ); connect( reload_, SIGNAL( clicked() ), this, SLOT( reload_file() ) ); connect( save_ , SIGNAL( clicked() ), this, SLOT( save_file () ) ); connect( cancel_, SIGNAL( clicked() ), this, SLOT( accept () ) ); cancel_->setDefault( true ); }
void reloading_file(GtkWidget *widget, gpointer user_data) { if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(gui->editor_notebook)) <= 0) { return ; } /** Retrieve the stored filepath: **/ gpointer filepath = g_object_get_data(G_OBJECT(current_editor.current_buffer), "filepath") ; File_Editor *file_editor = g_object_get_data(G_OBJECT(current_editor.current_textview), "file_editor") ; reload_file(GTK_SOURCE_BUFFER(current_editor.current_buffer), filepath, file_editor) ; /** We mark the TextBuffer as not modified. **/ gtk_text_buffer_set_modified(current_editor.current_buffer, FALSE) ; }
//******************************************************************* // load_file PRIVATE //******************************************************************* void QBtFileEditor::load_file() { static const QString cmd = "file -b -i \"%1\""; QApplication::setOverrideCursor( Qt::WaitCursor ); QBtSystemCall syscall; syscall.run( cmd.arg( path_ ) ); const QString marker = syscall.result(); const bool is_text = marker.startsWith( "text" ) || marker.contains( "script" ) || marker.contains( "perl" ); if( is_text ) reload_file(); QApplication::restoreOverrideCursor(); if( !is_text ) { QMessageBox::information( this, tr( CAPTION ), tr( NOTEXT_FILE ).arg( path_ ) ); } }