Changeset View
Changeset View
Standalone View
Standalone View
shell/documentcontroller.cpp
Show First 20 Lines • Show All 69 Lines • ▼ Show 20 Line(s) | |||||
70 | #include <vcs/vcspluginhelper.h> | 70 | #include <vcs/vcspluginhelper.h> | ||
71 | 71 | | |||
72 | #define EMPTY_DOCUMENT_URL i18n("Untitled") | 72 | #define EMPTY_DOCUMENT_URL i18n("Untitled") | ||
73 | 73 | | |||
74 | namespace KDevelop | 74 | namespace KDevelop | ||
75 | { | 75 | { | ||
76 | 76 | | |||
77 | 77 | | |||
78 | struct DocumentControllerPrivate { | 78 | struct DocumentControllerPrivate | ||
79 | { | ||||
80 | struct OpenFileResult | ||||
81 | { | ||||
82 | QList<QUrl> urls; | ||||
83 | QString encoding; | ||||
84 | }; | ||||
85 | | ||||
79 | DocumentControllerPrivate(DocumentController* c) | 86 | DocumentControllerPrivate(DocumentController* c) | ||
80 | : controller(c) | 87 | : controller(c) | ||
81 | , fileOpenRecent(0) | 88 | , fileOpenRecent(0) | ||
82 | , globalTextEditorInstance(0) | 89 | , globalTextEditorInstance(0) | ||
83 | { | 90 | { | ||
84 | } | 91 | } | ||
85 | 92 | | |||
86 | ~DocumentControllerPrivate() | 93 | ~DocumentControllerPrivate() | ||
Show All 24 Lines | 117 | { | |||
111 | QList<QUrl> urlsForDoc = documents.keys(dynamic_cast<KDevelop::IDocument*>(doc)); | 118 | QList<QUrl> urlsForDoc = documents.keys(dynamic_cast<KDevelop::IDocument*>(doc)); | ||
112 | foreach (const QUrl &url, urlsForDoc) | 119 | foreach (const QUrl &url, urlsForDoc) | ||
113 | { | 120 | { | ||
114 | qCDebug(SHELL) << "destroying document" << doc; | 121 | qCDebug(SHELL) << "destroying document" << doc; | ||
115 | documents.remove(url); | 122 | documents.remove(url); | ||
116 | } | 123 | } | ||
117 | } | 124 | } | ||
118 | 125 | | |||
119 | KEncodingFileDialog::Result showOpenFile() const | 126 | OpenFileResult showOpenFile() const | ||
120 | { | 127 | { | ||
121 | QUrl dir; | 128 | QUrl dir; | ||
122 | if ( controller->activeDocument() ) { | 129 | if ( controller->activeDocument() ) { | ||
123 | dir = controller->activeDocument()->url().adjusted(QUrl::RemoveFilename); | 130 | dir = controller->activeDocument()->url().adjusted(QUrl::RemoveFilename); | ||
124 | } else { | 131 | } else { | ||
125 | const auto cfg = KSharedConfig::openConfig()->group("Open File"); | 132 | const auto cfg = KSharedConfig::openConfig()->group("Open File"); | ||
126 | dir = cfg.readEntry( "Last Open File Directory", Core::self()->projectController()->projectsBaseDirectory() ); | 133 | dir = cfg.readEntry( "Last Open File Directory", Core::self()->projectController()->projectsBaseDirectory() ); | ||
127 | } | 134 | } | ||
128 | 135 | | |||
129 | return KEncodingFileDialog::getOpenUrlsAndEncoding( QString(), dir, i18n( "*|Text File\n" ), | 136 | const auto caption = i18n("Open File"); | ||
130 | Core::self()->uiControllerInternal()->defaultMainWindow(), | 137 | const auto filter = i18n("*|Text File\n"); | ||
131 | i18n( "Open File" ) ); | 138 | auto parent = Core::self()->uiControllerInternal()->defaultMainWindow(); | ||
139 | | ||||
140 | // use special dialogs in a KDE session, native dialogs elsewhere | ||||
141 | if (qEnvironmentVariableIsSet("KDE_FULL_SESSION")) { | ||||
142 | const auto result = KEncodingFileDialog::getOpenUrlsAndEncoding(QString(), dir, | ||||
143 | filter, parent, caption); | ||||
144 | return {result.URLs, result.encoding}; | ||||
145 | } | ||||
146 | | ||||
147 | // note: can't just filter on text files using the native dialog, just display all files | ||||
amccann: On OSX, having tried this patch, this QFileDialog::getOpenFileUrls() does succeed in presenting… | |||||
148 | // see https://phabricator.kde.org/D622#11679 | ||||
149 | const auto urls = QFileDialog::getOpenFileUrls(parent, caption, dir); | ||||
150 | return {urls, QString()}; | ||||
132 | } | 151 | } | ||
133 | 152 | | |||
134 | void chooseDocument() | 153 | void chooseDocument() | ||
135 | { | 154 | { | ||
136 | const auto res = showOpenFile(); | 155 | const auto res = showOpenFile(); | ||
137 | if( !res.URLs.isEmpty() ) { | 156 | if( !res.urls.isEmpty() ) { | ||
138 | QString encoding = res.encoding; | 157 | QString encoding = res.encoding; | ||
139 | foreach( const QUrl& u, res.URLs ) { | 158 | foreach( const QUrl& u, res.urls ) { | ||
140 | openDocumentInternal(u, QString(), KTextEditor::Range::invalid(), encoding ); | 159 | openDocumentInternal(u, QString(), KTextEditor::Range::invalid(), encoding ); | ||
141 | } | 160 | } | ||
142 | } | 161 | } | ||
143 | 162 | | |||
144 | } | 163 | } | ||
145 | 164 | | |||
146 | void changeDocumentUrl(KDevelop::IDocument* document) | 165 | void changeDocumentUrl(KDevelop::IDocument* document) | ||
147 | { | 166 | { | ||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Line(s) | 224 | { | |||
207 | Q_ASSERT(!inputUrl.fileName().isEmpty()); | 226 | Q_ASSERT(!inputUrl.fileName().isEmpty()); | ||
208 | QString _encoding = encoding; | 227 | QString _encoding = encoding; | ||
209 | 228 | | |||
210 | QUrl url = inputUrl; | 229 | QUrl url = inputUrl; | ||
211 | 230 | | |||
212 | if ( url.isEmpty() && (!activationParams.testFlag(IDocumentController::DoNotCreateView)) ) | 231 | if ( url.isEmpty() && (!activationParams.testFlag(IDocumentController::DoNotCreateView)) ) | ||
213 | { | 232 | { | ||
214 | const auto res = showOpenFile(); | 233 | const auto res = showOpenFile(); | ||
215 | if( !res.URLs.isEmpty() ) | 234 | if( !res.urls.isEmpty() ) | ||
216 | url = res.URLs.first(); | 235 | url = res.urls.first(); | ||
217 | _encoding = res.encoding; | 236 | _encoding = res.encoding; | ||
218 | if ( url.isEmpty() ) | 237 | if ( url.isEmpty() ) | ||
219 | //still no url | 238 | //still no url | ||
220 | return 0; | 239 | return 0; | ||
221 | } | 240 | } | ||
222 | 241 | | |||
223 | KSharedConfig::openConfig()->group("Open File").writeEntry( "Last Open File Directory", url.adjusted(QUrl::RemoveFilename) ); | 242 | KSharedConfig::openConfig()->group("Open File").writeEntry( "Last Open File Directory", url.adjusted(QUrl::RemoveFilename) ); | ||
224 | 243 | | |||
▲ Show 20 Lines • Show All 1001 Lines • Show Last 20 Lines |
On OSX, having tried this patch, this QFileDialog::getOpenFileUrls() does succeed in presenting a native 'open file' dialog.
However, the 'filter' argument doesn't work as desired. It just displays the raw "*|Text File" string, which looks out of place, and doesn't cause any filtering.
http://doc.qt.io/qt-5/qfiledialog.html#getOpenFileNames
QT documentation appears to want a different syntax for filters. I tried the following just to verify understanding:
It worked.
However, when it is reduced to:
Something it optimizing away the filter altogether, resulting in no filter functionality. (Which is probably fine).
Given this knowledge: It may make sense to not pass any filter at all, since it isn't actually filtering anything. It appears to simply be a placeholder for the Widget that is present on KDE dialog.