#!/usr/bin/env python

# Moleskine: a source code editor for the GNOME desktop
#
# Copyright (c) 2000 - 2002  Michele Campeotto <micampe@micampe.it>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

import sys

nofiles = 0
deleted = 0
for i in range(len(sys.argv)):
    if sys.argv[i][:4] == '--sm' or (deleted and sys.argv[i][:2] != '--'):
        nofiles = 1
        deleted = 1
        del(sys.argv[i])
        if (i + 1) >= len(sys.argv):
            break
    else:
        deleted = 0

import gnome.ui
import gtk

import Moleskine
from Moleskine.MoleskineApp import *

def save_yourself(client, phase, save_style, is_shutdown, interact_style, is_fast, client_data = None):
    client.set_clone_command([sys.argv[0]])
    client.set_restart_command([sys.argv[0]])

app = Moleskine.app = MoleskineApp()

client = gnome.ui.master_client
client.connect_after('save_yourself', save_yourself)
client.connect_after('die', menu.exit)

if len(sys.argv) == 1 or nofiles:
    app.load_session()
    if len(Moleskine.app.documents) == 0:
        app.new_document()
else:
    app.session = Config('Moleskine/Session')
    app.switch = 0
    for i in sys.argv[1:]:
        app.open_document(i)
    app.switch = 1
    app.update_title()
    app.notebook.set_page(0)

gtk.mainloop()
