@@ -30,6 +30,77 @@ def url_exists(path):
3030 return True
3131 return False
3232
33+ class ExistingProjectDialog (QtGui .QDialog ):
34+ def __init__ (self , recent_projects , directory_callback , parent = None ):
35+ super (ExistingProjectDialog , self ).__init__ (parent )
36+ self .setWindowTitle ('Open Project Folder' )
37+ self .setMinimumWidth (500 )
38+ self .parent ().menuBar ().hide ()
39+
40+ group_box = QtGui .QGroupBox ('Existing Projects' )
41+ gbox_layout = QtGui .QVBoxLayout ()
42+ self .project_list = QtGui .QListWidget ()
43+
44+ gbox_layout .addWidget (self .project_list )
45+ group_box .setLayout (gbox_layout )
46+
47+ self .callback = directory_callback
48+
49+ self .projects = recent_projects
50+
51+ for i in xrange (len (recent_projects )):
52+ project = recent_projects [i ]
53+ text = u'{} - {}' .format (os .path .basename (project ), project )
54+ self .project_list .addItem (text )
55+
56+ self .project_list .itemClicked .connect (self .project_clicked )
57+
58+ self .cancel = QtGui .QPushButton ('Cancel' )
59+ self .open = QtGui .QPushButton ('Open Selected' )
60+ self .browse = QtGui .QPushButton ('Browse...' )
61+
62+ self .open .setEnabled (False )
63+ self .open .clicked .connect (self .open_clicked )
64+
65+ self .browse .clicked .connect (self .browse_clicked )
66+
67+ buttons = QtGui .QWidget ()
68+
69+ button_layout = QtGui .QHBoxLayout ()
70+ button_layout .addWidget (self .cancel )
71+ button_layout .addWidget (QtGui .QWidget ())
72+ button_layout .addWidget (self .browse )
73+ button_layout .addWidget (self .open )
74+
75+ buttons .setLayout (button_layout )
76+
77+ layout = QtGui .QVBoxLayout ()
78+ layout .addWidget (group_box )
79+ layout .addWidget (buttons )
80+
81+ self .setLayout (layout )
82+ self .cancel .clicked .connect (self .cancelled )
83+
84+ def browse_clicked (self ):
85+
86+ directory = QtGui .QFileDialog .getExistingDirectory (self , 'Find Project Directory' ,
87+ self .parent ().project_dir () or self .parent ().last_project_dir )
88+
89+ if directory :
90+ self .callback (directory )
91+ self .close ()
92+
93+ def open_clicked (self ):
94+ pos = self .project_list .currentRow ()
95+ self .callback (self .projects [pos ])
96+ self .close ()
97+
98+ def project_clicked (self , item ):
99+ self .open .setEnabled (True )
100+
101+ def cancelled (self ):
102+ self .close ()
103+
33104class Validator (QtGui .QRegExpValidator ):
34105 def __init__ (self , regex , action , parent = None ):
35106 self .exp = regex
@@ -124,6 +195,15 @@ def __init__(self, width, height, app, parent=None):
124195 super (MainWindow , self ).__init__ (parent )
125196 CommandBase .__init__ (self )
126197
198+ recent_projects = self .load_recent_projects ()
199+
200+ existing_dialog = ExistingProjectDialog (recent_projects , self .load_project , parent = self )
201+ existing_dialog .show ()
202+
203+ drect = QtGui .QApplication .desktop ().availableGeometry (self )
204+ center = drect .center ()
205+ self .move (center .x () - self .width () * 0.5 , center .y () - self .height ()* 0.5 )
206+
127207 self .icon_style = 'width:48px;height:48px;background-color:white;border-radius:5px;border:1px solid rgb(50,50,50);'
128208
129209 self .last_project_dir = self .load_last_project_path ()
0 commit comments