Ejemplo n.º 1
0
static void
file_save (CeditTab    *tab,
	   CeditWindow *window)
{
	CeditDocument *doc;
	gchar *uri_for_display;

	cedit_debug (DEBUG_COMMANDS);

	g_return_if_fail (CEDIT_IS_TAB (tab));
	g_return_if_fail (CEDIT_IS_WINDOW (window));

	doc = cedit_tab_get_document (tab);
	g_return_if_fail (CEDIT_IS_DOCUMENT (doc));

	if (cedit_document_is_untitled (doc) || 
	    cedit_document_get_readonly (doc))
	{
		cedit_debug_message (DEBUG_COMMANDS, "Untitled or Readonly");

		file_save_as (tab, window);
		
		return;
	}

	uri_for_display = cedit_document_get_uri_for_display (doc);
	cedit_statusbar_flash_message (CEDIT_STATUSBAR (window->priv->statusbar),
				        window->priv->generic_message_cid,
				       _("Saving file '%s'\342\200\246"),
				       uri_for_display);

	g_free (uri_for_display);

	_cedit_tab_save (tab);
}
Ejemplo n.º 2
0
void file_save()
{
	if(!file_name)
	{
		file_save_as();
		return;
	}
	file_save_action();	
	file_saved = 1;
}
Ejemplo n.º 3
0
void
_cedit_cmd_file_save_as (GtkAction   *action,
			CeditWindow *window)
{
	CeditTab *tab;

	cedit_debug (DEBUG_COMMANDS);

	tab = cedit_window_get_active_tab (window);
	if (tab == NULL)
		return;

	file_save_as (tab, window);
}
Ejemplo n.º 4
0
/** Handle Ctrl-key combination. */
static void key_handle_ctrl(kbd_event_t const *ev)
{
	switch (ev->key) {
	case KC_Q:
		done = true;
		break;
	case KC_S:
		if (doc.file_name != NULL)
			file_save(doc.file_name);
		else
			file_save_as();
		break;
	case KC_E:
		file_save_as();
		break;
	case KC_C:
		selection_copy();
		break;
	case KC_V:
		selection_delete();
		insert_clipboard_data();
		pane.rflags |= REDRAW_TEXT;
		caret_update();
		break;
	case KC_X:
		selection_copy();
		selection_delete();
		pane.rflags |= REDRAW_TEXT;
		caret_update();
		break;
	case KC_A:
		selection_sel_all();
		break;
	default:
		break;
	}
}
QMenuBar *win_char_editor::setup_menuBar()
{
	file_new_Act = new QAction(tr("New"), this); 
    connect(file_new_Act, SIGNAL(triggered()), this, SLOT(file_new()));

	file_open_Act = new QAction(tr("Open"), this); 
    connect(file_open_Act, SIGNAL(triggered()), this, SLOT(file_open()));

	file_saveAct = new QAction(tr("Save"), this); 
	file_saveAct->setEnabled(FALSE);
    connect(file_saveAct, SIGNAL(triggered()), this, SLOT(file_save()));

	file_save_asAct = new QAction(tr("Save &As..."), this); 
	file_save_asAct->setEnabled(TRUE);
    connect(file_save_asAct, SIGNAL(triggered()), this, SLOT(file_save_as()));

	file_exitAct = new QAction(tr("Exit"), this); 
    connect(file_exitAct, SIGNAL(triggered()), this, SLOT(close()));

	edit_undoAct = new QAction(tr("Undo"), this); 
	edit_undoAct->setShortcut(tr("Ctrl+Z"));
	connect(edit_undoAct, SIGNAL(triggered()), this, SLOT(edit_undo()));
	edit_undoAct->setEnabled(FALSE);
    
	edit_redoAct = new QAction(tr("Redo"), this); 
	edit_redoAct->setShortcut(tr("Ctrl+Y"));
	connect(edit_redoAct, SIGNAL(triggered()), this, SLOT(edit_redo()));
	edit_redoAct->setEnabled(FALSE);

	fileMenu = new QMenu(tr("&File"));
	fileMenu->addAction(file_new_Act);
	fileMenu->addSeparator();
	fileMenu->addAction(file_open_Act);
	fileMenu->addSeparator();
	fileMenu->addAction(file_saveAct);
	fileMenu->addAction(file_save_asAct);
	fileMenu->addSeparator();
	fileMenu->addAction(file_exitAct);
	connect(fileMenu,SIGNAL(aboutToShow()),this,SLOT(menu_file_open()));
	editMenu = new QMenu(tr("&Edit"));
	editMenu->addAction(edit_undoAct);
	editMenu->addAction(edit_redoAct);
	
	mb = new QMenuBar(this);
	mb->clear();
	mb->addMenu(fileMenu);
	mb->addMenu(editMenu);
	return mb;
}
Ejemplo n.º 6
0
static void
are_you_sure_close_dialog_respond(GtkWidget *widget, /* the dialog */
                                  gint       response_id,
                                  gpointer   user_data) /* the display */
{
  DDisplay *ddisp = (DDisplay *)user_data;
  gboolean close_ddisp = TRUE;

  switch (response_id) {
  case GTK_RESPONSE_YES :  
    /* save changes */
    if (ddisp->diagram->unsaved) {
      /* we have to open the file dlg, close this one first */
      gtk_widget_destroy(widget);
      if (file_save_as(ddisp->diagram, ddisp))
        ddisp_destroy (ddisp);
      /* no way back */
      return;
    } else {
      DiaContext *ctx = dia_context_new (_("Save"));
      if (!diagram_save(ddisp->diagram, ddisp->diagram->filename, ctx))
        close_ddisp = FALSE;
      dia_context_release (ctx);
    }
    if (close_ddisp) /* saving succeeded */
      recent_file_history_add(ddisp->diagram->filename);

    if (ddisp->update_id && close_ddisp) {
      g_source_remove (ddisp->update_id);
      ddisp->update_id = 0;
    }
    /* fall through */
  case GTK_RESPONSE_NO :
    if (close_ddisp)
      ddisp_destroy (ddisp);
    /* fall through */
  case GTK_RESPONSE_CANCEL :
  case GTK_RESPONSE_NONE :
  case GTK_RESPONSE_DELETE_EVENT : /* closing via window manager */
    gtk_widget_destroy(widget);
    break;
  default :
    g_assert_not_reached();
  }
}
Ejemplo n.º 7
0
void MainWindow::file_save(void)
{
	const char *current_default;

	if (!existing_filename)
		return file_save_as();

	current_default = prefs.default_filename;
	if (strcmp(existing_filename, current_default) ==  0) {
		/* if we are using the default filename the directory
		 * that we are creating the file in may not exist */
		QDir current_def_dir = QFileInfo(current_default).absoluteDir();
		if (!current_def_dir.exists())
			current_def_dir.mkpath(current_def_dir.absolutePath());
	}
	save_dives(existing_filename);
	mark_divelist_changed(FALSE);
}
Ejemplo n.º 8
0
static void
save_as_and_close (CeditTab    *tab,
		   CeditWindow *window)
{
	cedit_debug (DEBUG_COMMANDS);

	g_object_set_data (G_OBJECT (tab),
			   CEDIT_IS_CLOSING_TAB,
			   NULL);

	/* Trace tab state changes */
	g_signal_connect (tab,
			  "notify::state",
			  G_CALLBACK (tab_state_changed_while_saving),
			  window);

	cedit_window_set_active_tab (window, tab);
	file_save_as (tab, window);
}
Ejemplo n.º 9
0
bool mainwnd::save_file()
{
    bool result = false;

    if (global_filename == "") {
        file_save_as();
        return true;
    }

    midifile f(global_filename);
    result = f.write(m_mainperf);

    if (!result) {
        Gtk::MessageDialog errdialog(*this,
                "Error writing file.", false,
                Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
        errdialog.run();
    }
    m_modified = !result;
    return result;
}
bool	win_char_editor::ask_if_save()
{
	if (!isWindowModified())
		return TRUE;
	
	switch (QMessageBox::warning(this, "Itecad", tr("The char has been modified. Do you want to save it now?"), tr("&Yes"), tr("&No"), tr("&Cancel"), 0, 1))
	{
	case 0:		// 0 = YES
		if (never_saved)
			{
			file_save_as();
			return TRUE;
			}
		else
			{
			file_save();
			return TRUE;
			}
	case 1:		// 1 = NO
		return TRUE;
	case 2:		// 2 = CANCEL
		return FALSE;
	}		
}
Ejemplo n.º 11
0
void MainWindow::on_actionSaveAs_triggered()
{
	file_save_as();
}
Ejemplo n.º 12
0
/*
 * The docs in the list must belong to the same CeditWindow.
 */
void
_cedit_cmd_file_save_documents_list (CeditWindow *window,
				     GList       *docs)
{
	GList *l;
	GSList *tabs_to_save_as = NULL;

	cedit_debug (DEBUG_COMMANDS);

	g_return_if_fail (!(cedit_window_get_state (window) & 
			    (CEDIT_WINDOW_STATE_PRINTING |
			     CEDIT_WINDOW_STATE_SAVING_SESSION)));

	l = docs;
	while (l != NULL)
	{
		CeditDocument *doc;
		CeditTab *t;
		CeditTabState state;

		g_return_if_fail (CEDIT_IS_DOCUMENT (l->data));
 
		doc = CEDIT_DOCUMENT (l->data);
		t = cedit_tab_get_from_document (doc);
		state = cedit_tab_get_state (t);

		g_return_if_fail (state != CEDIT_TAB_STATE_PRINTING);
		g_return_if_fail (state != CEDIT_TAB_STATE_PRINT_PREVIEWING);
		g_return_if_fail (state != CEDIT_TAB_STATE_CLOSING);

		if ((state == CEDIT_TAB_STATE_NORMAL) ||
		    (state == CEDIT_TAB_STATE_SHOWING_PRINT_PREVIEW) ||
		    (state == CEDIT_TAB_STATE_GENERIC_NOT_EDITABLE))
		{
			/* FIXME: manage the case of local readonly files owned by the
			   user is running cedit - Paolo (Dec. 8, 2005) */
			if (cedit_document_is_untitled (doc) || 
			    cedit_document_get_readonly (doc))
			{
				if (document_needs_saving (doc))
			     	{
				     	tabs_to_save_as = g_slist_prepend (tabs_to_save_as,
									   t);
			     	}
			}
			else
			{
				file_save (t, window);			
			}
		}
		else
		{
			/* If the state is:
			   - CEDIT_TAB_STATE_LOADING: we do not save since we are sure the file is unmodified
			   - CEDIT_TAB_STATE_REVERTING: we do not save since the user wants
			     to return back to the version of the file she previously saved
			   - CEDIT_TAB_STATE_SAVING: well, we are already saving (no need to save again)
			   - CEDIT_TAB_STATE_PRINTING, CEDIT_TAB_STATE_PRINT_PREVIEWING: there is not a
			     real reason for not saving in this case, we do not save to avoid to run
			     two operations using the message area at the same time (may be we can remove
			     this limitation in the future). Note that SaveAll, ClosAll
			     and Quit are unsensitive if the window state is PRINTING.
			   - CEDIT_TAB_STATE_GENERIC_ERROR: we do not save since the document contains
			     errors (I don't think this is a very frequent case, we should probably remove
			     this state)
			   - CEDIT_TAB_STATE_LOADING_ERROR: there is nothing to save
			   - CEDIT_TAB_STATE_REVERTING_ERROR: there is nothing to save and saving the current
			     document will overwrite the copy of the file the user wants to go back to
			   - CEDIT_TAB_STATE_SAVING_ERROR: we do not save since we just failed to save, so there is
			     no reason to automatically retry... we wait for user intervention
			   - CEDIT_TAB_STATE_CLOSING: this state is invalid in this case
			*/

			gchar *uri_for_display;

			uri_for_display = cedit_document_get_uri_for_display (doc);
			cedit_debug_message (DEBUG_COMMANDS,
					     "File '%s' not saved. State: %d",
					     uri_for_display,
					     state);
			g_free (uri_for_display);
		}

		l = g_list_next (l);
	}

	if (tabs_to_save_as != NULL)
	{
		CeditTab *tab;

		tabs_to_save_as = g_slist_reverse (tabs_to_save_as );

		g_return_if_fail (g_object_get_data (G_OBJECT (window),
						     CEDIT_LIST_OF_TABS_TO_SAVE_AS) == NULL);

		g_object_set_data (G_OBJECT (window),
				   CEDIT_LIST_OF_TABS_TO_SAVE_AS,
				   tabs_to_save_as);

		tab = CEDIT_TAB (tabs_to_save_as->data);

		cedit_window_set_active_tab (window, tab);
		file_save_as (tab, window);
	}
}
Ejemplo n.º 13
0
static void
save_dialog_response_cb (CeditFileChooserDialog *dialog,
                         gint                    response_id,
                         CeditWindow            *window)
{
	GFile *file;
	const CeditEncoding *encoding;
	CeditTab *tab;
	gpointer data;
	GSList *tabs_to_save_as;
	CeditDocumentNewlineType newline_type;

	cedit_debug (DEBUG_COMMANDS);

	tab = CEDIT_TAB (g_object_get_data (G_OBJECT (dialog),
					    CEDIT_TAB_TO_SAVE_AS));

	if (response_id != GTK_RESPONSE_OK)
	{
		gtk_widget_destroy (GTK_WIDGET (dialog));

		goto save_next_tab;
	}

	file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
	g_return_if_fail (file != NULL);

	encoding = cedit_file_chooser_dialog_get_encoding (dialog);
	newline_type = cedit_file_chooser_dialog_get_newline_type (dialog);

	gtk_widget_destroy (GTK_WIDGET (dialog));

	if (tab != NULL)
	{
		CeditDocument *doc;
		gchar *parse_name;
		gchar *uri;

		doc = cedit_tab_get_document (tab);
		g_return_if_fail (CEDIT_IS_DOCUMENT (doc));

		parse_name = g_file_get_parse_name (file);

		cedit_statusbar_flash_message (CEDIT_STATUSBAR (window->priv->statusbar),
					        window->priv->generic_message_cid,
					       _("Saving file '%s'\342\200\246"),
					       parse_name);

		g_free (parse_name);

		/* let's remember the dir we navigated too,
		 * even if the saving fails... */
		 _cedit_window_set_default_location (window, file);

		// FIXME: pass the GFile to tab when api is there
		uri = g_file_get_uri (file);
		_cedit_tab_save_as (tab, uri, encoding, newline_type);
		g_free (uri);
	}

	g_object_unref (file);

save_next_tab:

	data = g_object_get_data (G_OBJECT (window),
				  CEDIT_LIST_OF_TABS_TO_SAVE_AS);
	if (data == NULL)
		return;

	/* Save As the next tab of the list (we are Saving All files) */
	tabs_to_save_as = (GSList *)data;
	g_return_if_fail (tab == CEDIT_TAB (tabs_to_save_as->data));

	/* Remove the first item of the list */
	tabs_to_save_as = g_slist_delete_link (tabs_to_save_as,
					       tabs_to_save_as);

	g_object_set_data (G_OBJECT (window),
			   CEDIT_LIST_OF_TABS_TO_SAVE_AS,
			   tabs_to_save_as);

	if (tabs_to_save_as != NULL)
	{
		tab = CEDIT_TAB (tabs_to_save_as->data);

		if (GPOINTER_TO_BOOLEAN (g_object_get_data (G_OBJECT (tab),
							    CEDIT_IS_CLOSING_TAB)) == TRUE)
		{
			g_object_set_data (G_OBJECT (tab),
					   CEDIT_IS_CLOSING_TAB,
					   NULL);

			/* Trace tab state changes */
			g_signal_connect (tab,
					  "notify::state",
					  G_CALLBACK (tab_state_changed_while_saving),
					  window);
		}

		cedit_window_set_active_tab (window, tab);
		file_save_as (tab, window);
	}
}
Ejemplo n.º 14
0
int main(int argc, char *argv[])
{
//  debug_new::PrintTrace PrintingOn; // merely activates logging of new/delete

    //print arguments
    std::cout << "Argument list with "<<argc<<" arguments\n";
    for (int i=0; i<argc; i++)
    {
        std::cout << argv[i] <<"\n";
    }
    //first argument is the filename of this program containing the current working directory
    //second argument is *.mod filename which needs to be opened at startup


    //testmatrix();

    QApplication a( argc, argv );
    //a.QApplication::setGraphicsSystem("raster"); //important to fix a bug in QT with scaling of pen sizes

    //QTranslator tor( 0 );

    // set the location where your .qm files are in load() below as the last parameter instead of "."
    // for development, use "/" to use the english original as
    // .qm files are stored in the base project directory.

    //tor.load( QString("eelsmodel.") + QTextCodec::locale(), "." );

    //  a.installTranslator( &tor );
    /* uncomment the following line, if you want a Windows 95 look*/
    //a.setStyle(QApplication::WindowsStyle);

    //create menu, toolbar and init the workspace
    MenuEelsmodel* mymainwindow=new MenuEelsmodel();
    global_menueelsmodel=mymainwindow;
    //store the workspace
    global_workspaceptr=mymainwindow->getworkspaceptr();
    //init the eelsmodel class
    Eelsmodel* myeelsmodel=new Eelsmodel(global_workspaceptr,"version 4.1");
    //and store a global pointer
    global_eelsmodelptr=myeelsmodel;

    //show the window
    //a.setMainWidget( mymainwindow );
    mymainwindow->show();
    mymainwindow->showMaximized();

    //make connections between menu and eelsmodel program
    QObject::connect(mymainwindow, SIGNAL(file_new()),myeelsmodel, SLOT(newspectrum()) );
    QObject::connect(mymainwindow, SIGNAL(model_componentmaintenance()),myeelsmodel, SLOT(componentmaintenance()) );
    QObject::connect(mymainwindow, SIGNAL(model_newmodel()),myeelsmodel, SLOT(newmodel()) );
    QObject::connect(mymainwindow, SIGNAL(model_detector()),myeelsmodel, SLOT(slot_model_detector()) );

    QObject::connect(mymainwindow, SIGNAL(file_open_msa()),myeelsmodel, SLOT(openmsa()) );
    QObject::connect(mymainwindow, SIGNAL(file_open_DM()),myeelsmodel, SLOT(openDM()) );

    QObject::connect(mymainwindow, SIGNAL(model_iterativefit()),myeelsmodel, SLOT(iterativefit()) );
    QObject::connect(mymainwindow, SIGNAL(edit_undoselection()),myeelsmodel, SLOT(undoselection()) );
    QObject::connect(mymainwindow, SIGNAL(edit_exclude()),myeelsmodel, SLOT(exclude()) );
    QObject::connect(mymainwindow, SIGNAL(edit_resetexclude()),myeelsmodel, SLOT(resetexclude()) );

    QObject::connect(mymainwindow, SIGNAL(file_project_open()),myeelsmodel, SLOT(slot_open_project()) );
    QObject::connect(mymainwindow, SIGNAL(file_project_save()),myeelsmodel, SLOT(slot_save_project()) );
    QObject::connect(mymainwindow, SIGNAL(file_model_save()),myeelsmodel, SLOT(slot_save_model()) );
    QObject::connect(mymainwindow, SIGNAL(file_report_save()),myeelsmodel, SLOT((slot_save_report())) );
    QObject::connect(mymainwindow, SIGNAL(file_save_as()),myeelsmodel, SLOT(slot_save_as()) );
    QObject::connect(myeelsmodel, SIGNAL(enablemodel(bool)),mymainwindow, SLOT(slot_enable_model(bool)));




    Hello myhello;
    //=new Hello();
    //(void*) myhello;//supress unused warning
    if (argc>1) {
        //get a *.mod file from the arguments
        std::string arg1=argv[0]; //contains program directory+program name
        std::string arg2=argv[1]; //contains argument ideally a *.mod filename to open
        global_eelsmodelptr->slot_open_project_from_filename(arg2);
    }






    const int result=a.exec();
    //delete the pointers we have
    //if (myhello!=0) delete(myhello); //the hello window is deleted by itself when pressing done

    //if (mymainwindow!=0) delete(mymainwindow);
    //if (myeelsmodel!=0) delete(myeelsmodel);



    return result;
}